Re: [PATCH] net: hns: dereference ppe_cb->ppe_common_cb if it is non-null

2016-08-25 Thread Yisen Zhuang


在 2016/8/25 14:51, Colin King 写道:
> From: Colin Ian King <colin.k...@canonical.com>
> 
> ppe_cb->ppe_common_cb is being dereferenced before a null check is
> being made on it.  If ppe_cb->ppe_common_cb is null then we end up
> with a null pointer dereference when assigning dsaf_dev.  Fix this
> by moving the initialisation of dsaf_dev once we know
> ppe_cb->ppe_common_cb is OK to dereference.
> 
> Signed-off-by: Colin Ian King <colin.k...@canonical.com>

Acked-by: Yisen Zhuang <yisen.zhu...@huawei.com>



Re: [PATCH 1/1 linux-next] net: hns: fix typo in g_gmac_stats_string[]

2016-08-10 Thread Yisen Zhuang
Hi Fabian,

This patch is fine to me, many thanks.

Yisen

在 2016/8/10 23:48, Fabian Frederick 写道:
> s/gamc/gmac/
> 
> Signed-off-by: Fabian Frederick 
> ---
>  drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c 
> b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
> index 1235c7f..1e1eb92 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
> @@ -17,7 +17,7 @@ static const struct mac_stats_string g_gmac_stats_string[] 
> = {
>   {"gmac_rx_octets_total_ok", MAC_STATS_FIELD_OFF(rx_good_bytes)},
>   {"gmac_rx_octets_bad", MAC_STATS_FIELD_OFF(rx_bad_bytes)},
>   {"gmac_rx_uc_pkts", MAC_STATS_FIELD_OFF(rx_uc_pkts)},
> - {"gamc_rx_mc_pkts", MAC_STATS_FIELD_OFF(rx_mc_pkts)},
> + {"gmac_rx_mc_pkts", MAC_STATS_FIELD_OFF(rx_mc_pkts)},
>   {"gmac_rx_bc_pkts", MAC_STATS_FIELD_OFF(rx_bc_pkts)},
>   {"gmac_rx_pkts_64octets", MAC_STATS_FIELD_OFF(rx_64bytes)},
>   {"gmac_rx_pkts_65to127", MAC_STATS_FIELD_OFF(rx_65to127)},
> 



Re: [PATCH 06/15] ethernet: hisilicon: hns: hns_dsaf_mac: add missing of_node_put after calling of_parse_phandle

2016-07-27 Thread Yisen Zhuang


在 2016/7/27 10:20, Peter Chen 写道:
> of_node_put needs to be called when the device node which is got
> from of_parse_phandle has finished using.
> 
> Signed-off-by: Peter Chen 
> ---
>  drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 9 ++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
> b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
> index 3fb87e2..18d72ea 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
> @@ -786,6 +786,7 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
>   np = of_parse_phandle(mac_cb->dev->of_node, "phy-handle",
> mac_cb->mac_id);
>   mac_cb->phy_dev = of_phy_find_device(np);
> + of_node_put(np);
>   if (mac_cb->phy_dev) {
>   /* refcount is held by of_phy_find_device()
>* if the phy_dev is found

np is accessed in case of of_phy_find_device() returns a no null value, so it 
has to be
moved after the dev_dbg log.

> @@ -804,6 +805,7 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
>   np = of_parse_phandle(to_of_node(mac_cb->fw_port),
> "phy-handle", 0);
>   mac_cb->phy_dev = of_phy_find_device(np);
> + of_node_put(np);
>   if (mac_cb->phy_dev) {
>   /* refcount is held by of_phy_find_device()
>* if the phy_dev is found

np is accessed in case of of_phy_find_device() returns a no null value, so it 
has to be
moved after the dev_dbg log.

Thanks,

Yisen

> @@ -813,9 +815,10 @@ 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));
> + np = of_parse_phandle(to_of_node(mac_cb->fw_port),
> + "serdes-syscon", 0);
> + syscon = syscon_node_to_regmap(np);
> + of_node_put(np);
>   if (IS_ERR_OR_NULL(syscon)) {
>   dev_err(mac_cb->dev, "serdes-syscon is needed!\n");
>   return -EINVAL;
> 



[PATCH v3 net-next 4/9] net: hns: delete redundant parenthese

2016-07-01 Thread Yisen Zhuang
From: Daode Huang <huangda...@hisilicon.com>

According to the previous review comments from Andy, this patch
deletes the redundant parens in the patch.

Signed-off-by: Daode Huang <huangda...@hisilicon.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index b9d01ea..e36ee22 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -2565,7 +2565,7 @@ static char *hns_dsaf_get_node_stats_strings(char *data, 
int node,
buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_stp_drop_pkts", node);
buff += ETH_GSTRING_LEN;
-   if ((node < DSAF_SERVICE_NW_NUM) && (!is_ver1)) {
+   if (node < DSAF_SERVICE_NW_NUM && !is_ver1) {
for (i = 0; i < DSAF_PRIO_NR; i++) {
snprintf(buff, ETH_GSTRING_LEN,
 "inod%d_pfc_prio%d_pkts", node, i);
@@ -2604,7 +2604,7 @@ static u64 *hns_dsaf_get_node_stats(struct dsaf_device 
*ddev, u64 *data,
p[10] = hw_stats->local_addr_false;
p[11] = hw_stats->vlan_drop;
p[12] = hw_stats->stp_drop;
-   if ((node_num < DSAF_SERVICE_NW_NUM) && (!is_ver1)) {
+   if (node_num < DSAF_SERVICE_NW_NUM && !is_ver1) {
for (i = 0; i < DSAF_PRIO_NR; i++) {
p[13 + i] = hw_stats->rx_pfc[i];
p[13 + i + DSAF_PRIO_NR] = hw_stats->tx_pfc[i];
-- 
1.9.1



[PATCH v3 net-next 1/9] MAINTAINERS: add maintainers for hns driver

2016-07-01 Thread Yisen Zhuang
From: Daode Huang <huangda...@hisilicon.com>

This patch adds maintainers for hisilicon network subsystem driver

Signed-off-by: Daode Huang <huangda...@hisilicon.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
change log:
 v3: match all files in and below drivers/net/ethernet/hisilicon/

 v2: the same as v1

 v1: first submit
  Link: https://lkml.org/lkml/2016/6/27/184
---
 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index d8c0784..772c9ff 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5437,6 +5437,15 @@ F:   include/uapi/linux/if_hippi.h
 F: net/802/hippi.c
 F: drivers/net/hippi/
 
+HISILICON NETWORK SUBSYSTEM DRIVER
+M: Yisen Zhuang <yisen.zhu...@huawei.com>
+M: Salil Mehta <salil.me...@huawei.com>
+L: netdev@vger.kernel.org
+W: http://www.hisilicon.com
+S: Maintained
+F: drivers/net/ethernet/hisilicon/
+F: Documentation/devicetree/bindings/net/hisilicon*.txt
+
 HISILICON SAS Controller
 M: John Garry <john.ga...@huawei.com>
 W: http://www.hisilicon.com
-- 
1.9.1



[PATCH v3 net-next 6/9] net: hns: normalize two different loop

2016-07-01 Thread Yisen Zhuang
From: Daode Huang <huangda...@hisilicon.com>

There are two approaches to assign data, one does 2 loops, another
does 1 loop. This patch normalize the different methods to 1 loop.

Signed-off-by: Daode Huang <huangda...@hisilicon.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index e36ee22..86ce28a 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -2567,15 +2567,15 @@ static char *hns_dsaf_get_node_stats_strings(char 
*data, int node,
buff += ETH_GSTRING_LEN;
if (node < DSAF_SERVICE_NW_NUM && !is_ver1) {
for (i = 0; i < DSAF_PRIO_NR; i++) {
-   snprintf(buff, ETH_GSTRING_LEN,
-"inod%d_pfc_prio%d_pkts", node, i);
-   buff += ETH_GSTRING_LEN;
-   }
-   for (i = 0; i < DSAF_PRIO_NR; i++) {
-   snprintf(buff, ETH_GSTRING_LEN,
-"onod%d_pfc_prio%d_pkts", node, i);
+   snprintf(buff + 0 * ETH_GSTRING_LEN * DSAF_PRIO_NR,
+ETH_GSTRING_LEN, "inod%d_pfc_prio%d_pkts",
+node, i);
+   snprintf(buff + 1 * ETH_GSTRING_LEN * DSAF_PRIO_NR,
+ETH_GSTRING_LEN, "onod%d_pfc_prio%d_pkts",
+node, i);
buff += ETH_GSTRING_LEN;
}
+   buff += 1 * DSAF_PRIO_NR * ETH_GSTRING_LEN;
}
snprintf(buff, ETH_GSTRING_LEN, "onnod%d_tx_pkts", node);
buff += ETH_GSTRING_LEN;
@@ -2606,8 +2606,8 @@ static u64 *hns_dsaf_get_node_stats(struct dsaf_device 
*ddev, u64 *data,
p[12] = hw_stats->stp_drop;
if (node_num < DSAF_SERVICE_NW_NUM && !is_ver1) {
for (i = 0; i < DSAF_PRIO_NR; i++) {
-   p[13 + i] = hw_stats->rx_pfc[i];
-   p[13 + i + DSAF_PRIO_NR] = hw_stats->tx_pfc[i];
+   p[13 + i + 0 * DSAF_PRIO_NR] = hw_stats->rx_pfc[i];
+   p[13 + i + 1 * DSAF_PRIO_NR] = hw_stats->tx_pfc[i];
}
p[29] = hw_stats->tx_pkts;
return [30];
-- 
1.9.1



[PATCH v3 net-next 0/9] net: hns: fix the typo of hns

2016-07-01 Thread Yisen Zhuang
This series includes typo fixes which review by Andy, adding
the hns maintainer to MAINTAINERS, as below:

 > from Daode: adds the maintainer for hns driver;

 > from Daode: fix the typo of hns reviewed by Andy Shevchenko;

 > from Kejian: one remove redundant function and two fix to get 
configuration from DT.

changlog:
 v2 -> v3:
  match all files in and below drivers/net/ethernet/hisilicon/

 v1 -> v2:
  fix the indentations reviewed by David.

Daode Huang (6):
  MAINTAINERS: add maintainers for hns driver
  net: hns: fix code style about hns driver
  net: hns: change code style from a = a + x to a += x
  net: hns: delete redundant parenthese
  net: hns: add a space before "*/"
  net: hns: normalize two different loop

Kejian Yan (3):
  net: hns: remove redundant hns_mac_dev_to_enet_if()
  net: hns: add media-type property for hns
  net: hns: get reset registers from DT

 MAINTAINERS|  9 +++
 drivers/net/ethernet/hisilicon/hns/hnae.h  |  9 +++
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 41 +++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 52 +++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 16 ++---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c  |  4 +-
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   | 14 +++-
 drivers/net/ethernet/hisilicon/hns_mdio.c  | 80 ++
 10 files changed, 158 insertions(+), 69 deletions(-)

-- 
1.9.1



[PATCH v3 net-next 7/9] net: hns: remove redundant hns_mac_dev_to_enet_if()

2016-07-01 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

The sequence of hns_mac_dev_to_enet_if() is the same as
hns_get_enet_interface(), and hns_get_enet_interface() is called
by initialization to get the mac mode. And the mode is not changed
anywhere. Thus add hns_mac_dev_to_enet_if() function to get the mac
mode is obviously redundant.

Reported-by: Jinchuan Tian <tianjinchu...@huawei.com>
Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index c526558..d2effcc 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -56,20 +56,6 @@ static const enum mac_mode g_mac_mode_1000[] = {
[PHY_INTERFACE_MODE_RTBI]   = MAC_MODE_RTBI_1000
 };
 
-static enum mac_mode hns_mac_dev_to_enet_if(const struct hns_mac_cb *mac_cb)
-{
-   switch (mac_cb->max_speed) {
-   case MAC_SPEED_100:
-   return g_mac_mode_100[mac_cb->phy_if];
-   case MAC_SPEED_1000:
-   return g_mac_mode_1000[mac_cb->phy_if];
-   case MAC_SPEED_1:
-   return MAC_MODE_XGMII_1;
-   default:
-   return MAC_MODE_MII_100;
-   }
-}
-
 static enum mac_mode hns_get_enet_interface(const struct hns_mac_cb *mac_cb)
 {
switch (mac_cb->max_speed) {
@@ -134,7 +120,6 @@ void hns_mac_adjust_link(struct hns_mac_cb *mac_cb, int 
speed, int duplex)
 
mac_cb->speed = speed;
mac_cb->half_duplex = !duplex;
-   mac_ctrl_drv->mac_mode = hns_mac_dev_to_enet_if(mac_cb);
 
if (mac_ctrl_drv->adjust_link) {
ret = mac_ctrl_drv->adjust_link(mac_ctrl_drv,
-- 
1.9.1



[PATCH v3 net-next 2/9] net: hns: fix code style about hns driver

2016-07-01 Thread Yisen Zhuang
From: Daode Huang <huangda...@hisilicon.com>

This patch fixes code sytle of hns driver to make it
simple.

Signed-off-by: Daode Huang <huangda...@hisilicon.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
index 8473287..611b67b 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
@@ -253,10 +253,9 @@ static void hns_dsaf_ge_srst_by_port(struct dsaf_device 
*dsaf_dev, u32 port,
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;
+   reg_val_2 = AE_IS_VER1(dsaf_dev->dsaf_ver) ?
+   0x1041041 : 0x2082082;
+   reg_val_2 <<= port_rst_off;
 
if (!dereset) {
dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_REQ1_REG,
@@ -272,12 +271,11 @@ static void hns_dsaf_ge_srst_by_port(struct dsaf_device 
*dsaf_dev, u32 port,
   reg_val_1);
}
} else {
-   reg_val_1 = 0x15540 << dsaf_dev->reset_offset;
+   reg_val_1 = 0x15540;
+   reg_val_2 = AE_IS_VER1(dsaf_dev->dsaf_ver) ? 0x100 : 0x40;
 
-   if (AE_IS_VER1(dsaf_dev->dsaf_ver))
-   reg_val_2 = 0x100 << dsaf_dev->reset_offset;
-   else
-   reg_val_2 = 0x40 << dsaf_dev->reset_offset;
+   reg_val_1 <<= dsaf_dev->reset_offset;
+   reg_val_2 <<= dsaf_dev->reset_offset;
 
if (!dereset) {
dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_REQ1_REG,
-- 
1.9.1



[PATCH v3 net-next 5/9] net: hns: add a space before "*/"

2016-07-01 Thread Yisen Zhuang
From: Daode Huang <huangda...@hisilicon.com>

In comment line, some time miss a space before */, so this
patch adds a space before */.

Signed-off-by: Daode Huang <huangda...@hisilicon.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index d5297ec..d7e1f8c 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -762,13 +762,13 @@ static int hns_nic_rx_poll_one(struct hns_nic_ring_data 
*ring_data,
recv_pkts = 0, recv_bds = 0, clean_count = 0;
 recv:
while (recv_pkts < budget && recv_bds < num) {
-   /* reuse or realloc buffers*/
+   /* reuse or realloc buffers */
if (clean_count >= RCB_NOF_ALLOC_RX_BUFF_ONCE) {
hns_nic_alloc_rx_buffers(ring_data, clean_count);
clean_count = 0;
}
 
-   /* poll one pkt*/
+   /* poll one pkt */
err = hns_nic_poll_rx_skb(ring_data, , );
if (unlikely(!skb)) /* this fault cannot be repaired */
goto out;
-- 
1.9.1



[PATCH v3 net-next 9/9] net: hns: get reset registers from DT

2016-07-01 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

Since the registers of subctrl may be different, it is better to
mv the registers from hns mdio driver routine to device tree node.

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
change log:
 v2: fix the wrong indentations

 v1: first submit
  link: https://lkml.org/lkml/2016/6/27/182
---
 drivers/net/ethernet/hisilicon/hns_mdio.c | 80 +--
 1 file changed, 66 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c 
b/drivers/net/ethernet/hisilicon/hns_mdio.c
index 761a32f..33f4c48 100644
--- a/drivers/net/ethernet/hisilicon/hns_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns_mdio.c
@@ -37,9 +37,19 @@
 
 #define MDIO_TIMEOUT   100
 
+struct hns_mdio_sc_reg {
+   u16 mdio_clk_en;
+   u16 mdio_clk_dis;
+   u16 mdio_reset_req;
+   u16 mdio_reset_dreq;
+   u16 mdio_clk_st;
+   u16 mdio_reset_st;
+};
+
 struct hns_mdio_device {
void *vbase;/* mdio reg base address */
struct regmap *subctrl_vbase;
+   struct hns_mdio_sc_reg sc_reg;
 };
 
 /* mdio reg */
@@ -93,7 +103,6 @@ enum mdio_c45_op_seq {
 #define MDIO_SC_CLK_DIS0x33C
 #define MDIO_SC_RESET_REQ  0xA38
 #define MDIO_SC_RESET_DREQ 0xA3C
-#define MDIO_SC_CTRL   0x2010
 #define MDIO_SC_CLK_ST 0x531C
 #define MDIO_SC_RESET_ST   0x5A1C
 
@@ -353,6 +362,7 @@ static int hns_mdio_read(struct mii_bus *bus, int phy_id, 
int regnum)
 static int hns_mdio_reset(struct mii_bus *bus)
 {
struct hns_mdio_device *mdio_dev = (struct hns_mdio_device *)bus->priv;
+   const struct hns_mdio_sc_reg *sc_reg;
int ret;
 
if (dev_of_node(bus->parent)) {
@@ -361,9 +371,10 @@ static int hns_mdio_reset(struct mii_bus *bus)
return -ENODEV;
}
 
+   sc_reg = _dev->sc_reg;
/* 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,
+   ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_reset_req,
+   0x1, sc_reg->mdio_reset_st, 0x1,
MDIO_CHECK_SET_ST);
if (ret) {
dev_err(>dev, "MDIO reset fail\n");
@@ -371,8 +382,8 @@ static int hns_mdio_reset(struct mii_bus *bus)
}
 
/* 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,
+   ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_clk_dis,
+   0x1, sc_reg->mdio_clk_st, 0x1,
MDIO_CHECK_CLR_ST);
if (ret) {
dev_err(>dev, "MDIO dis clk fail\n");
@@ -380,8 +391,8 @@ static int hns_mdio_reset(struct mii_bus *bus)
}
 
/* 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,
+   ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_reset_dreq,
+   0x1, sc_reg->mdio_reset_st, 0x1,
MDIO_CHECK_CLR_ST);
if (ret) {
dev_err(>dev, "MDIO dis clk fail\n");
@@ -389,8 +400,8 @@ static int hns_mdio_reset(struct mii_bus *bus)
}
 
/* 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,
+   ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_clk_en,
+   0x1, sc_reg->mdio_clk_st, 0x1,
MDIO_CHECK_SET_ST);
if (ret)
dev_err(>dev, "MDIO en clk fail\n");
@@ -458,13 +469,54 @@ static int hns_mdio_probe(struct platform_device *pdev)
snprintf(new_bus->id, MII_BUS_ID_SIZE, "%s-%s", "Mii",
 dev_name(>dev));
if (dev_of_node(>dev)) {
-   mdio_dev->subctrl_vbase = syscon_node_to_regmap(
-   of_parse_phandle(pdev->dev.of_node,
-"subctrl-vbase", 0));
-   if (IS_ERR(mdio_dev->subctrl_vbase)) {
-   dev_warn(>dev, "no syscon 
hisilicon,peri-c-subctrl\n");
+   struct of_phan

[PATCH v3 net-next 3/9] net: hns: change code style from a = a + x to a += x

2016-07-01 Thread Yisen Zhuang
From: Daode Huang <huangda...@hisilicon.com>

This patch fixes the code style in hns driver. Change it from
"buff = buff + xxx" to "buff += xxx". The reveiw comments is
from andy.

Reviewed-by: Andriy Shevchenko <andriy.shevche...@linux.intel.com>
Signed-off-by: Daode Huang <huangda...@hisilicon.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 32 +++---
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index 67e8e13..b9d01ea 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -2540,45 +2540,45 @@ static char *hns_dsaf_get_node_stats_strings(char 
*data, int node,
bool is_ver1 = AE_IS_VER1(dsaf_dev->dsaf_ver);
 
snprintf(buff, ETH_GSTRING_LEN, "innod%d_pad_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_manage_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pkt_id", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pause_frame", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_release_buf_num", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_sbm_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_crc_false_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_bp_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_lookup_rslt_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_local_rslt_fail_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_vlan_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_stp_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
if ((node < DSAF_SERVICE_NW_NUM) && (!is_ver1)) {
for (i = 0; i < DSAF_PRIO_NR; i++) {
snprintf(buff, ETH_GSTRING_LEN,
 "inod%d_pfc_prio%d_pkts", node, i);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
}
for (i = 0; i < DSAF_PRIO_NR; i++) {
snprintf(buff, ETH_GSTRING_LEN,
 "onod%d_pfc_prio%d_pkts", node, i);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
}
}
snprintf(buff, ETH_GSTRING_LEN, "onnod%d_tx_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
 
return buff;
 }
-- 
1.9.1



[PATCH v3 net-next 8/9] net: hns: add media-type property for hns

2016-07-01 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

It is PORT_TP type if the service port is GE mode. It is wrong to
judge the port type by using if it is service port. Adding the media
type to know port type.

Reported-by: Jinchuan Tian <tianjinchu...@huawei.com>
Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hnae.h |  9 
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 26 +++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c  | 14 +---
 5 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.h 
b/drivers/net/ethernet/hisilicon/hns/hnae.h
index 3869322..e093cbf 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.h
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.h
@@ -363,6 +363,14 @@ enum hnae_port_type {
HNAE_PORT_DEBUG
 };
 
+/* mac media type */
+enum hnae_media_type {
+   HNAE_MEDIA_TYPE_UNKNOWN = 0,
+   HNAE_MEDIA_TYPE_FIBER,
+   HNAE_MEDIA_TYPE_COPPER,
+   HNAE_MEDIA_TYPE_BACKPLANE,
+};
+
 /* This struct defines the operation on the handle.
  *
  * get_handle(): (mandatory)
@@ -525,6 +533,7 @@ struct hnae_handle {
u32 eport_id;
u32 dport_id;   /* v2 tx bd should fill the dport_id */
enum hnae_port_type port_type;
+   enum hnae_media_type media_type;
struct list_head node;/* list to hnae_ae_dev->handle_list */
struct hnae_buf_ops *bops; /* operation for the buffer */
struct hnae_queue **qs;  /* array base of all queues */
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
index 835521b..e28d960 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
@@ -134,6 +134,7 @@ struct hnae_handle *hns_ae_get_handle(struct hnae_ae_dev 
*dev,
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->media_type = vf_cb->mac_cb->media_type;
ae_handle->dport_id = port_id;
 
return ae_handle;
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index d2effcc..3fb87e2 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -733,6 +733,18 @@ static void hns_mac_register_phy(struct hns_mac_cb *mac_cb)
mac_cb->mac_id, addr);
 }
 
+#define MAC_MEDIA_TYPE_MAX_LEN 16
+
+static const struct {
+   enum hnae_media_type value;
+   const char *name;
+} media_type_defs[] = {
+   {HNAE_MEDIA_TYPE_UNKNOWN,   "unknown" },
+   {HNAE_MEDIA_TYPE_FIBER, "fiber" },
+   {HNAE_MEDIA_TYPE_COPPER,"copper" },
+   {HNAE_MEDIA_TYPE_BACKPLANE, "backplane" },
+};
+
 /**
  *hns_mac_get_info  - get mac information from device node
  *@mac_cb: mac device
@@ -744,10 +756,13 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
struct device_node *np;
struct regmap *syscon;
struct of_phandle_args cpld_args;
+   const char *media_type;
+   u32 i;
u32 ret;
 
mac_cb->link = false;
mac_cb->half_duplex = false;
+   mac_cb->media_type = HNAE_MEDIA_TYPE_UNKNOWN;
mac_cb->speed = mac_phy_to_speed[mac_cb->phy_if];
mac_cb->max_speed = mac_cb->speed;
 
@@ -849,6 +864,17 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
mac_cb->mac_id);
}
 
+   if (!fwnode_property_read_string(mac_cb->fw_port, "media-type",
+_type)) {
+   for (i = 0; i < ARRAY_SIZE(media_type_defs); i++) {
+   if (!strncmp(media_type_defs[i].name, media_type,
+MAC_MEDIA_TYPE_MAX_LEN)) {
+   mac_cb->media_type = media_type_defs[i].value;
+   break;
+   }
+   }
+   }
+
return 0;
 }
 
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
index 05a6e8f..4cbdf14 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
@@ -335,6 +335,7 @@ struct hns_mac_cb {
u64 txpkt_for_led;
u64 rxpkt_for_led;
enum hnae_port_type mac_type;
+   enum hnae_media_type media_type;
phy_interface_t phy_if;
enum hnae_loop loop

[PATCH v2 net-next 9/9] net: hns: get reset registers from DT

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

Since the registers of subctrl may be different, it is better to
mv the registers from hns mdio driver routine to device tree node.

Signed-off-by: Kejian Yan 
---
change log:
 v2: fix the wrong indentations

 v1: first submit
  link: https://lkml.org/lkml/2016/6/27/182
---
 drivers/net/ethernet/hisilicon/hns_mdio.c | 80 +--
 1 file changed, 66 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c 
b/drivers/net/ethernet/hisilicon/hns_mdio.c
index 761a32f..33f4c48 100644
--- a/drivers/net/ethernet/hisilicon/hns_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns_mdio.c
@@ -37,9 +37,19 @@
 
 #define MDIO_TIMEOUT   100
 
+struct hns_mdio_sc_reg {
+   u16 mdio_clk_en;
+   u16 mdio_clk_dis;
+   u16 mdio_reset_req;
+   u16 mdio_reset_dreq;
+   u16 mdio_clk_st;
+   u16 mdio_reset_st;
+};
+
 struct hns_mdio_device {
void *vbase;/* mdio reg base address */
struct regmap *subctrl_vbase;
+   struct hns_mdio_sc_reg sc_reg;
 };
 
 /* mdio reg */
@@ -93,7 +103,6 @@ enum mdio_c45_op_seq {
 #define MDIO_SC_CLK_DIS0x33C
 #define MDIO_SC_RESET_REQ  0xA38
 #define MDIO_SC_RESET_DREQ 0xA3C
-#define MDIO_SC_CTRL   0x2010
 #define MDIO_SC_CLK_ST 0x531C
 #define MDIO_SC_RESET_ST   0x5A1C
 
@@ -353,6 +362,7 @@ static int hns_mdio_read(struct mii_bus *bus, int phy_id, 
int regnum)
 static int hns_mdio_reset(struct mii_bus *bus)
 {
struct hns_mdio_device *mdio_dev = (struct hns_mdio_device *)bus->priv;
+   const struct hns_mdio_sc_reg *sc_reg;
int ret;
 
if (dev_of_node(bus->parent)) {
@@ -361,9 +371,10 @@ static int hns_mdio_reset(struct mii_bus *bus)
return -ENODEV;
}
 
+   sc_reg = _dev->sc_reg;
/* 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,
+   ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_reset_req,
+   0x1, sc_reg->mdio_reset_st, 0x1,
MDIO_CHECK_SET_ST);
if (ret) {
dev_err(>dev, "MDIO reset fail\n");
@@ -371,8 +382,8 @@ static int hns_mdio_reset(struct mii_bus *bus)
}
 
/* 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,
+   ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_clk_dis,
+   0x1, sc_reg->mdio_clk_st, 0x1,
MDIO_CHECK_CLR_ST);
if (ret) {
dev_err(>dev, "MDIO dis clk fail\n");
@@ -380,8 +391,8 @@ static int hns_mdio_reset(struct mii_bus *bus)
}
 
/* 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,
+   ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_reset_dreq,
+   0x1, sc_reg->mdio_reset_st, 0x1,
MDIO_CHECK_CLR_ST);
if (ret) {
dev_err(>dev, "MDIO dis clk fail\n");
@@ -389,8 +400,8 @@ static int hns_mdio_reset(struct mii_bus *bus)
}
 
/* 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,
+   ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_clk_en,
+   0x1, sc_reg->mdio_clk_st, 0x1,
MDIO_CHECK_SET_ST);
if (ret)
dev_err(>dev, "MDIO en clk fail\n");
@@ -458,13 +469,54 @@ static int hns_mdio_probe(struct platform_device *pdev)
snprintf(new_bus->id, MII_BUS_ID_SIZE, "%s-%s", "Mii",
 dev_name(>dev));
if (dev_of_node(>dev)) {
-   mdio_dev->subctrl_vbase = syscon_node_to_regmap(
-   of_parse_phandle(pdev->dev.of_node,
-"subctrl-vbase", 0));
-   if (IS_ERR(mdio_dev->subctrl_vbase)) {
-   dev_warn(>dev, "no syscon 
hisilicon,peri-c-subctrl\n");
+   struct of_phandle_args reg_args;
+
+   ret = of_parse_phandle_with_fixed_args(pdev->dev.of_node,
+  "subctrl-vbase",
+  4,
+  

[PATCH v2 net-next 8/9] net: hns: add media-type property for hns

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

It is PORT_TP type if the service port is GE mode. It is wrong to
judge the port type by using if it is service port. Adding the media
type to know port type.

Reported-by: Jinchuan Tian 
Signed-off-by: Kejian Yan 
---
 drivers/net/ethernet/hisilicon/hns/hnae.h |  9 
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 26 +++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c  | 14 +---
 5 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.h 
b/drivers/net/ethernet/hisilicon/hns/hnae.h
index 3869322..e093cbf 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.h
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.h
@@ -363,6 +363,14 @@ enum hnae_port_type {
HNAE_PORT_DEBUG
 };
 
+/* mac media type */
+enum hnae_media_type {
+   HNAE_MEDIA_TYPE_UNKNOWN = 0,
+   HNAE_MEDIA_TYPE_FIBER,
+   HNAE_MEDIA_TYPE_COPPER,
+   HNAE_MEDIA_TYPE_BACKPLANE,
+};
+
 /* This struct defines the operation on the handle.
  *
  * get_handle(): (mandatory)
@@ -525,6 +533,7 @@ struct hnae_handle {
u32 eport_id;
u32 dport_id;   /* v2 tx bd should fill the dport_id */
enum hnae_port_type port_type;
+   enum hnae_media_type media_type;
struct list_head node;/* list to hnae_ae_dev->handle_list */
struct hnae_buf_ops *bops; /* operation for the buffer */
struct hnae_queue **qs;  /* array base of all queues */
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
index 835521b..e28d960 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
@@ -134,6 +134,7 @@ struct hnae_handle *hns_ae_get_handle(struct hnae_ae_dev 
*dev,
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->media_type = vf_cb->mac_cb->media_type;
ae_handle->dport_id = port_id;
 
return ae_handle;
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index d2effcc..3fb87e2 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -733,6 +733,18 @@ static void hns_mac_register_phy(struct hns_mac_cb *mac_cb)
mac_cb->mac_id, addr);
 }
 
+#define MAC_MEDIA_TYPE_MAX_LEN 16
+
+static const struct {
+   enum hnae_media_type value;
+   const char *name;
+} media_type_defs[] = {
+   {HNAE_MEDIA_TYPE_UNKNOWN,   "unknown" },
+   {HNAE_MEDIA_TYPE_FIBER, "fiber" },
+   {HNAE_MEDIA_TYPE_COPPER,"copper" },
+   {HNAE_MEDIA_TYPE_BACKPLANE, "backplane" },
+};
+
 /**
  *hns_mac_get_info  - get mac information from device node
  *@mac_cb: mac device
@@ -744,10 +756,13 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
struct device_node *np;
struct regmap *syscon;
struct of_phandle_args cpld_args;
+   const char *media_type;
+   u32 i;
u32 ret;
 
mac_cb->link = false;
mac_cb->half_duplex = false;
+   mac_cb->media_type = HNAE_MEDIA_TYPE_UNKNOWN;
mac_cb->speed = mac_phy_to_speed[mac_cb->phy_if];
mac_cb->max_speed = mac_cb->speed;
 
@@ -849,6 +864,17 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
mac_cb->mac_id);
}
 
+   if (!fwnode_property_read_string(mac_cb->fw_port, "media-type",
+_type)) {
+   for (i = 0; i < ARRAY_SIZE(media_type_defs); i++) {
+   if (!strncmp(media_type_defs[i].name, media_type,
+MAC_MEDIA_TYPE_MAX_LEN)) {
+   mac_cb->media_type = media_type_defs[i].value;
+   break;
+   }
+   }
+   }
+
return 0;
 }
 
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
index 05a6e8f..4cbdf14 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
@@ -335,6 +335,7 @@ struct hns_mac_cb {
u64 txpkt_for_led;
u64 rxpkt_for_led;
enum hnae_port_type mac_type;
+   enum hnae_media_type media_type;
phy_interface_t phy_if;
enum hnae_loop loop_mode;
 
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
index a395ca1..ab33487 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
+++ 

[PATCH v2 net-next 2/9] net: hns: fix code style about hns driver

2016-06-30 Thread Yisen Zhuang
From: Daode Huang 

This patch fixes code sytle of hns driver to make it
simple.

Signed-off-by: Daode Huang 
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
index 8473287..611b67b 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
@@ -253,10 +253,9 @@ static void hns_dsaf_ge_srst_by_port(struct dsaf_device 
*dsaf_dev, u32 port,
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;
+   reg_val_2 = AE_IS_VER1(dsaf_dev->dsaf_ver) ?
+   0x1041041 : 0x2082082;
+   reg_val_2 <<= port_rst_off;
 
if (!dereset) {
dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_REQ1_REG,
@@ -272,12 +271,11 @@ static void hns_dsaf_ge_srst_by_port(struct dsaf_device 
*dsaf_dev, u32 port,
   reg_val_1);
}
} else {
-   reg_val_1 = 0x15540 << dsaf_dev->reset_offset;
+   reg_val_1 = 0x15540;
+   reg_val_2 = AE_IS_VER1(dsaf_dev->dsaf_ver) ? 0x100 : 0x40;
 
-   if (AE_IS_VER1(dsaf_dev->dsaf_ver))
-   reg_val_2 = 0x100 << dsaf_dev->reset_offset;
-   else
-   reg_val_2 = 0x40 << dsaf_dev->reset_offset;
+   reg_val_1 <<= dsaf_dev->reset_offset;
+   reg_val_2 <<= dsaf_dev->reset_offset;
 
if (!dereset) {
dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_REQ1_REG,
-- 
1.9.1



[PATCH v2 net-next 5/9] net: hns: add a space before "*/"

2016-06-30 Thread Yisen Zhuang
From: Daode Huang 

In comment line, some time miss a space before */, so this
patch adds a space before */.

Signed-off-by: Daode Huang 
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index d5297ec..d7e1f8c 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -762,13 +762,13 @@ static int hns_nic_rx_poll_one(struct hns_nic_ring_data 
*ring_data,
recv_pkts = 0, recv_bds = 0, clean_count = 0;
 recv:
while (recv_pkts < budget && recv_bds < num) {
-   /* reuse or realloc buffers*/
+   /* reuse or realloc buffers */
if (clean_count >= RCB_NOF_ALLOC_RX_BUFF_ONCE) {
hns_nic_alloc_rx_buffers(ring_data, clean_count);
clean_count = 0;
}
 
-   /* poll one pkt*/
+   /* poll one pkt */
err = hns_nic_poll_rx_skb(ring_data, , );
if (unlikely(!skb)) /* this fault cannot be repaired */
goto out;
-- 
1.9.1



[PATCH v2 net-next 3/9] net: hns: change code style from a = a + x to a += x

2016-06-30 Thread Yisen Zhuang
From: Daode Huang 

This patch fixes the code style in hns driver. Change it from
"buff = buff + xxx" to "buff += xxx". The reveiw comments is
from andy.

Reviewed-by: Andriy Shevchenko 
Signed-off-by: Daode Huang 
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 32 +++---
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index 67e8e13..b9d01ea 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -2540,45 +2540,45 @@ static char *hns_dsaf_get_node_stats_strings(char 
*data, int node,
bool is_ver1 = AE_IS_VER1(dsaf_dev->dsaf_ver);
 
snprintf(buff, ETH_GSTRING_LEN, "innod%d_pad_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_manage_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pkt_id", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pause_frame", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_release_buf_num", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_sbm_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_crc_false_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_bp_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_lookup_rslt_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_local_rslt_fail_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_vlan_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_stp_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
if ((node < DSAF_SERVICE_NW_NUM) && (!is_ver1)) {
for (i = 0; i < DSAF_PRIO_NR; i++) {
snprintf(buff, ETH_GSTRING_LEN,
 "inod%d_pfc_prio%d_pkts", node, i);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
}
for (i = 0; i < DSAF_PRIO_NR; i++) {
snprintf(buff, ETH_GSTRING_LEN,
 "onod%d_pfc_prio%d_pkts", node, i);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
}
}
snprintf(buff, ETH_GSTRING_LEN, "onnod%d_tx_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
 
return buff;
 }
-- 
1.9.1



[PATCH v2 net-next 1/9] MAINTAINERS: add maintainers for hns driver

2016-06-30 Thread Yisen Zhuang
From: Daode Huang <huangda...@hisilicon.com>

This patch adds maintainers for hisilicon network subsystem driver

Signed-off-by: Daode Huang <huangda...@hisilicon.com>
---
 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 3a171a9..c819659 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5421,6 +5421,15 @@ F:   include/uapi/linux/if_hippi.h
 F: net/802/hippi.c
 F: drivers/net/hippi/
 
+HISILICON NETWORK SUBSYSTEM DRIVER
+M: Yisen Zhuang <yisen.zhu...@huawei.com>
+M: Salil Mehta <salil.me...@huawei.com>
+L: netdev@vger.kernel.org
+W: http://www.hisilicon.com
+S: Maintained
+F: drivers/net/ethernet/hisilicon/*
+F: Documentation/devicetree/bindings/net/hisilicon*.txt
+
 HISILICON SAS Controller
 M: John Garry <john.ga...@huawei.com>
 W: http://www.hisilicon.com
-- 
1.9.1



[PATCH v2 net-next 0/9] net: hns: fix the typo of hns

2016-06-30 Thread Yisen Zhuang
This series includes typo fixes which review by Andy, adding
the hns maintainer to MAINTAINERS, as below:

 > from Daode: adds the maintainer for hns driver;

 > from Daode: fix the typo of hns reviewed by Andy Shevchenko;

 > from Kejian: one remove redundant function and two fix to get 
configuration from DT.

changlog:
 v1 -> v2:
  fix the indentations reviewed by David.

Daode Huang (6):
  MAINTAINERS: add maintainers for hns driver
  net: hns: fix code style about hns driver
  net: hns: change code style from a = a + x to a += x
  net: hns: delete redundant parens
  net: hns: add a space before "*/"
  net: hns: normalize two different loop

Kejian Yan (3):
  net: hns: remove redundant hns_mac_dev_to_enet_if()
  net: hns: add media-type property for hns
  net: hns: get reset registers from DT

 MAINTAINERS|  9 +++
 drivers/net/ethernet/hisilicon/hns/hnae.h  |  9 +++
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 41 +++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 52 +++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 16 ++---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c  |  4 +-
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   | 14 +++-
 drivers/net/ethernet/hisilicon/hns_mdio.c  | 80 ++
 10 files changed, 158 insertions(+), 69 deletions(-)

-- 
1.9.1



[PATCH v2 net-next 6/9] net: hns: normalize two different loop

2016-06-30 Thread Yisen Zhuang
From: Daode Huang 

There are two approaches to assign data, one does 2 loops, another
does 1 loop. This patch normalize the different methods to 1 loop.

Signed-off-by: Daode Huang 
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index e36ee22..86ce28a 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -2567,15 +2567,15 @@ static char *hns_dsaf_get_node_stats_strings(char 
*data, int node,
buff += ETH_GSTRING_LEN;
if (node < DSAF_SERVICE_NW_NUM && !is_ver1) {
for (i = 0; i < DSAF_PRIO_NR; i++) {
-   snprintf(buff, ETH_GSTRING_LEN,
-"inod%d_pfc_prio%d_pkts", node, i);
-   buff += ETH_GSTRING_LEN;
-   }
-   for (i = 0; i < DSAF_PRIO_NR; i++) {
-   snprintf(buff, ETH_GSTRING_LEN,
-"onod%d_pfc_prio%d_pkts", node, i);
+   snprintf(buff + 0 * ETH_GSTRING_LEN * DSAF_PRIO_NR,
+ETH_GSTRING_LEN, "inod%d_pfc_prio%d_pkts",
+node, i);
+   snprintf(buff + 1 * ETH_GSTRING_LEN * DSAF_PRIO_NR,
+ETH_GSTRING_LEN, "onod%d_pfc_prio%d_pkts",
+node, i);
buff += ETH_GSTRING_LEN;
}
+   buff += 1 * DSAF_PRIO_NR * ETH_GSTRING_LEN;
}
snprintf(buff, ETH_GSTRING_LEN, "onnod%d_tx_pkts", node);
buff += ETH_GSTRING_LEN;
@@ -2606,8 +2606,8 @@ static u64 *hns_dsaf_get_node_stats(struct dsaf_device 
*ddev, u64 *data,
p[12] = hw_stats->stp_drop;
if (node_num < DSAF_SERVICE_NW_NUM && !is_ver1) {
for (i = 0; i < DSAF_PRIO_NR; i++) {
-   p[13 + i] = hw_stats->rx_pfc[i];
-   p[13 + i + DSAF_PRIO_NR] = hw_stats->tx_pfc[i];
+   p[13 + i + 0 * DSAF_PRIO_NR] = hw_stats->rx_pfc[i];
+   p[13 + i + 1 * DSAF_PRIO_NR] = hw_stats->tx_pfc[i];
}
p[29] = hw_stats->tx_pkts;
return [30];
-- 
1.9.1



[PATCH v2 net-next 4/9] net: hns: delete redundant parenthese

2016-06-30 Thread Yisen Zhuang
From: Daode Huang 

According to the previous review comments from Andy, this patch
deletes the redundant parens in the patch.

Signed-off-by: Daode Huang 
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index b9d01ea..e36ee22 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -2565,7 +2565,7 @@ static char *hns_dsaf_get_node_stats_strings(char *data, 
int node,
buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_stp_drop_pkts", node);
buff += ETH_GSTRING_LEN;
-   if ((node < DSAF_SERVICE_NW_NUM) && (!is_ver1)) {
+   if (node < DSAF_SERVICE_NW_NUM && !is_ver1) {
for (i = 0; i < DSAF_PRIO_NR; i++) {
snprintf(buff, ETH_GSTRING_LEN,
 "inod%d_pfc_prio%d_pkts", node, i);
@@ -2604,7 +2604,7 @@ static u64 *hns_dsaf_get_node_stats(struct dsaf_device 
*ddev, u64 *data,
p[10] = hw_stats->local_addr_false;
p[11] = hw_stats->vlan_drop;
p[12] = hw_stats->stp_drop;
-   if ((node_num < DSAF_SERVICE_NW_NUM) && (!is_ver1)) {
+   if (node_num < DSAF_SERVICE_NW_NUM && !is_ver1) {
for (i = 0; i < DSAF_PRIO_NR; i++) {
p[13 + i] = hw_stats->rx_pfc[i];
p[13 + i + DSAF_PRIO_NR] = hw_stats->tx_pfc[i];
-- 
1.9.1



[PATCH v2 net-next 7/9] net: hns: remove redundant hns_mac_dev_to_enet_if()

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

The sequence of hns_mac_dev_to_enet_if() is the same as
hns_get_enet_interface(), and hns_get_enet_interface() is called
by initialization to get the mac mode. And the mode is not changed
anywhere. Thus add hns_mac_dev_to_enet_if() function to get the mac
mode is obviously redundant.

Reported-by: Jinchuan Tian 
Signed-off-by: Kejian Yan 
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index c526558..d2effcc 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -56,20 +56,6 @@ static const enum mac_mode g_mac_mode_1000[] = {
[PHY_INTERFACE_MODE_RTBI]   = MAC_MODE_RTBI_1000
 };
 
-static enum mac_mode hns_mac_dev_to_enet_if(const struct hns_mac_cb *mac_cb)
-{
-   switch (mac_cb->max_speed) {
-   case MAC_SPEED_100:
-   return g_mac_mode_100[mac_cb->phy_if];
-   case MAC_SPEED_1000:
-   return g_mac_mode_1000[mac_cb->phy_if];
-   case MAC_SPEED_1:
-   return MAC_MODE_XGMII_1;
-   default:
-   return MAC_MODE_MII_100;
-   }
-}
-
 static enum mac_mode hns_get_enet_interface(const struct hns_mac_cb *mac_cb)
 {
switch (mac_cb->max_speed) {
@@ -134,7 +120,6 @@ void hns_mac_adjust_link(struct hns_mac_cb *mac_cb, int 
speed, int duplex)
 
mac_cb->speed = speed;
mac_cb->half_duplex = !duplex;
-   mac_ctrl_drv->mac_mode = hns_mac_dev_to_enet_if(mac_cb);
 
if (mac_ctrl_drv->adjust_link) {
ret = mac_ctrl_drv->adjust_link(mac_ctrl_drv,
-- 
1.9.1



[PATCH net-next 7/9] net: hns: remove redundant hns_mac_dev_to_enet_if()

2016-06-27 Thread Yisen Zhuang
From: Kejian Yan 

The sequence of hns_mac_dev_to_enet_if() is the same as
hns_get_enet_interface(), and hns_get_enet_interface() is called
by initialization to get the mac mode. And the mode is not changed
anywhere. Thus add hns_mac_dev_to_enet_if() function to get the mac
mode is obviously redundant.

Reported-by: Jinchuan Tian 
Signed-off-by: Kejian Yan 
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index c526558..d2effcc 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -56,20 +56,6 @@ static const enum mac_mode g_mac_mode_1000[] = {
[PHY_INTERFACE_MODE_RTBI]   = MAC_MODE_RTBI_1000
 };
 
-static enum mac_mode hns_mac_dev_to_enet_if(const struct hns_mac_cb *mac_cb)
-{
-   switch (mac_cb->max_speed) {
-   case MAC_SPEED_100:
-   return g_mac_mode_100[mac_cb->phy_if];
-   case MAC_SPEED_1000:
-   return g_mac_mode_1000[mac_cb->phy_if];
-   case MAC_SPEED_1:
-   return MAC_MODE_XGMII_1;
-   default:
-   return MAC_MODE_MII_100;
-   }
-}
-
 static enum mac_mode hns_get_enet_interface(const struct hns_mac_cb *mac_cb)
 {
switch (mac_cb->max_speed) {
@@ -134,7 +120,6 @@ void hns_mac_adjust_link(struct hns_mac_cb *mac_cb, int 
speed, int duplex)
 
mac_cb->speed = speed;
mac_cb->half_duplex = !duplex;
-   mac_ctrl_drv->mac_mode = hns_mac_dev_to_enet_if(mac_cb);
 
if (mac_ctrl_drv->adjust_link) {
ret = mac_ctrl_drv->adjust_link(mac_ctrl_drv,
-- 
1.9.1



[PATCH net-next 1/9] MAINTAINERS: add maintainers for hns driver

2016-06-27 Thread Yisen Zhuang
From: Daode Huang <huangda...@hisilicon.com>

This patch adds maintainers for hisilicon network subsystem driver

Signed-off-by: Daode Huang <huangda...@hisilicon.com>
---
 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 3a171a9..c819659 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5421,6 +5421,15 @@ F:   include/uapi/linux/if_hippi.h
 F: net/802/hippi.c
 F: drivers/net/hippi/
 
+HISILICON NETWORK SUBSYSTEM DRIVER
+M: Yisen Zhuang <yisen.zhu...@huawei.com>
+M: Salil Mehta <salil.me...@huawei.com>
+L: netdev@vger.kernel.org
+W: http://www.hisilicon.com
+S: Maintained
+F: drivers/net/ethernet/hisilicon/*
+F: Documentation/devicetree/bindings/net/hisilicon*.txt
+
 HISILICON SAS Controller
 M: John Garry <john.ga...@huawei.com>
 W: http://www.hisilicon.com
-- 
1.9.1



[PATCH net-next 3/9] net: hns: change code style from a = a + x to a += x

2016-06-27 Thread Yisen Zhuang
From: Daode Huang 

This patch fixes the code style in hns driver. Change it from
"buff = buff + xxx" to "buff += xxx". The reveiw comments is
from andy.

Reviewed-by: Andriy Shevchenko 
Signed-off-by: Daode Huang 
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 32 +++---
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index 67e8e13..b9d01ea 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -2540,45 +2540,45 @@ static char *hns_dsaf_get_node_stats_strings(char 
*data, int node,
bool is_ver1 = AE_IS_VER1(dsaf_dev->dsaf_ver);
 
snprintf(buff, ETH_GSTRING_LEN, "innod%d_pad_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_manage_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pkt_id", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pause_frame", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_release_buf_num", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_sbm_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_crc_false_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_bp_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_lookup_rslt_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_local_rslt_fail_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_vlan_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_stp_drop_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
if ((node < DSAF_SERVICE_NW_NUM) && (!is_ver1)) {
for (i = 0; i < DSAF_PRIO_NR; i++) {
snprintf(buff, ETH_GSTRING_LEN,
 "inod%d_pfc_prio%d_pkts", node, i);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
}
for (i = 0; i < DSAF_PRIO_NR; i++) {
snprintf(buff, ETH_GSTRING_LEN,
 "onod%d_pfc_prio%d_pkts", node, i);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
}
}
snprintf(buff, ETH_GSTRING_LEN, "onnod%d_tx_pkts", node);
-   buff = buff + ETH_GSTRING_LEN;
+   buff += ETH_GSTRING_LEN;
 
return buff;
 }
-- 
1.9.1



[PATCH net-next 4/9] net: hns: delete redundant parens

2016-06-27 Thread Yisen Zhuang
From: Daode Huang 

According to the previous review comments from Andy, this patch
deletes the redundant parens in the patch.

Signed-off-by: Daode Huang 
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index b9d01ea..e36ee22 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -2565,7 +2565,7 @@ static char *hns_dsaf_get_node_stats_strings(char *data, 
int node,
buff += ETH_GSTRING_LEN;
snprintf(buff, ETH_GSTRING_LEN, "innod%d_stp_drop_pkts", node);
buff += ETH_GSTRING_LEN;
-   if ((node < DSAF_SERVICE_NW_NUM) && (!is_ver1)) {
+   if (node < DSAF_SERVICE_NW_NUM && !is_ver1) {
for (i = 0; i < DSAF_PRIO_NR; i++) {
snprintf(buff, ETH_GSTRING_LEN,
 "inod%d_pfc_prio%d_pkts", node, i);
@@ -2604,7 +2604,7 @@ static u64 *hns_dsaf_get_node_stats(struct dsaf_device 
*ddev, u64 *data,
p[10] = hw_stats->local_addr_false;
p[11] = hw_stats->vlan_drop;
p[12] = hw_stats->stp_drop;
-   if ((node_num < DSAF_SERVICE_NW_NUM) && (!is_ver1)) {
+   if (node_num < DSAF_SERVICE_NW_NUM && !is_ver1) {
for (i = 0; i < DSAF_PRIO_NR; i++) {
p[13 + i] = hw_stats->rx_pfc[i];
p[13 + i + DSAF_PRIO_NR] = hw_stats->tx_pfc[i];
-- 
1.9.1



[PATCH net-next 9/9] net: hns: get reset registers from DT

2016-06-27 Thread Yisen Zhuang
From: Kejian Yan 

Since the registers of subctrl may be different, it is better to
mv the registers from hns mdio driver routine to device tree node.

Signed-off-by: Kejian Yan 
---
 drivers/net/ethernet/hisilicon/hns_mdio.c | 80 +--
 1 file changed, 66 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c 
b/drivers/net/ethernet/hisilicon/hns_mdio.c
index 761a32f..988ad69 100644
--- a/drivers/net/ethernet/hisilicon/hns_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns_mdio.c
@@ -37,9 +37,19 @@
 
 #define MDIO_TIMEOUT   100
 
+struct hns_mdio_sc_reg {
+   u16 mdio_clk_en;
+   u16 mdio_clk_dis;
+   u16 mdio_reset_req;
+   u16 mdio_reset_dreq;
+   u16 mdio_clk_st;
+   u16 mdio_reset_st;
+};
+
 struct hns_mdio_device {
void *vbase;/* mdio reg base address */
struct regmap *subctrl_vbase;
+   struct hns_mdio_sc_reg sc_reg;
 };
 
 /* mdio reg */
@@ -93,7 +103,6 @@ enum mdio_c45_op_seq {
 #define MDIO_SC_CLK_DIS0x33C
 #define MDIO_SC_RESET_REQ  0xA38
 #define MDIO_SC_RESET_DREQ 0xA3C
-#define MDIO_SC_CTRL   0x2010
 #define MDIO_SC_CLK_ST 0x531C
 #define MDIO_SC_RESET_ST   0x5A1C
 
@@ -353,6 +362,7 @@ static int hns_mdio_read(struct mii_bus *bus, int phy_id, 
int regnum)
 static int hns_mdio_reset(struct mii_bus *bus)
 {
struct hns_mdio_device *mdio_dev = (struct hns_mdio_device *)bus->priv;
+   const struct hns_mdio_sc_reg *sc_reg;
int ret;
 
if (dev_of_node(bus->parent)) {
@@ -361,9 +371,10 @@ static int hns_mdio_reset(struct mii_bus *bus)
return -ENODEV;
}
 
+   sc_reg = _dev->sc_reg;
/* 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,
+   ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_reset_req, 0x1,
+   sc_reg->mdio_reset_st, 0x1,
MDIO_CHECK_SET_ST);
if (ret) {
dev_err(>dev, "MDIO reset fail\n");
@@ -371,8 +382,8 @@ static int hns_mdio_reset(struct mii_bus *bus)
}
 
/* 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,
+   ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_clk_dis,
+   0x1, sc_reg->mdio_clk_st, 0x1,
MDIO_CHECK_CLR_ST);
if (ret) {
dev_err(>dev, "MDIO dis clk fail\n");
@@ -380,8 +391,8 @@ static int hns_mdio_reset(struct mii_bus *bus)
}
 
/* 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,
+   ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_reset_dreq, 0x1,
+   sc_reg->mdio_reset_st, 0x1,
MDIO_CHECK_CLR_ST);
if (ret) {
dev_err(>dev, "MDIO dis clk fail\n");
@@ -389,8 +400,8 @@ static int hns_mdio_reset(struct mii_bus *bus)
}
 
/* 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,
+   ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_clk_en,
+   0x1, sc_reg->mdio_clk_st, 0x1,
MDIO_CHECK_SET_ST);
if (ret)
dev_err(>dev, "MDIO en clk fail\n");
@@ -458,13 +469,54 @@ static int hns_mdio_probe(struct platform_device *pdev)
snprintf(new_bus->id, MII_BUS_ID_SIZE, "%s-%s", "Mii",
 dev_name(>dev));
if (dev_of_node(>dev)) {
-   mdio_dev->subctrl_vbase = syscon_node_to_regmap(
-   of_parse_phandle(pdev->dev.of_node,
-"subctrl-vbase", 0));
-   if (IS_ERR(mdio_dev->subctrl_vbase)) {
-   dev_warn(>dev, "no syscon 
hisilicon,peri-c-subctrl\n");
+   struct of_phandle_args reg_args;
+
+   ret = of_parse_phandle_with_fixed_args(pdev->dev.of_node,
+  "subctrl-vbase",
+  4,
+  0,
+  _args);
+   if (!ret) {
+   

[PATCH net-next 2/9] net: hns: fix code style about hns driver

2016-06-27 Thread Yisen Zhuang
From: Daode Huang 

This patch fixes code sytle of hns driver to make it
simple.

Signed-off-by: Daode Huang 
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
index 8473287..611b67b 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
@@ -253,10 +253,9 @@ static void hns_dsaf_ge_srst_by_port(struct dsaf_device 
*dsaf_dev, u32 port,
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;
+   reg_val_2 = AE_IS_VER1(dsaf_dev->dsaf_ver) ?
+   0x1041041 : 0x2082082;
+   reg_val_2 <<= port_rst_off;
 
if (!dereset) {
dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_REQ1_REG,
@@ -272,12 +271,11 @@ static void hns_dsaf_ge_srst_by_port(struct dsaf_device 
*dsaf_dev, u32 port,
   reg_val_1);
}
} else {
-   reg_val_1 = 0x15540 << dsaf_dev->reset_offset;
+   reg_val_1 = 0x15540;
+   reg_val_2 = AE_IS_VER1(dsaf_dev->dsaf_ver) ? 0x100 : 0x40;
 
-   if (AE_IS_VER1(dsaf_dev->dsaf_ver))
-   reg_val_2 = 0x100 << dsaf_dev->reset_offset;
-   else
-   reg_val_2 = 0x40 << dsaf_dev->reset_offset;
+   reg_val_1 <<= dsaf_dev->reset_offset;
+   reg_val_2 <<= dsaf_dev->reset_offset;
 
if (!dereset) {
dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_REQ1_REG,
-- 
1.9.1



[PATCH net-next 5/9] net: hns: add a space before "*/"

2016-06-27 Thread Yisen Zhuang
From: Daode Huang 

In comment line, some time miss a space before */, so this
patch adds a space before */.

Signed-off-by: Daode Huang 
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index d5297ec..d7e1f8c 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -762,13 +762,13 @@ static int hns_nic_rx_poll_one(struct hns_nic_ring_data 
*ring_data,
recv_pkts = 0, recv_bds = 0, clean_count = 0;
 recv:
while (recv_pkts < budget && recv_bds < num) {
-   /* reuse or realloc buffers*/
+   /* reuse or realloc buffers */
if (clean_count >= RCB_NOF_ALLOC_RX_BUFF_ONCE) {
hns_nic_alloc_rx_buffers(ring_data, clean_count);
clean_count = 0;
}
 
-   /* poll one pkt*/
+   /* poll one pkt */
err = hns_nic_poll_rx_skb(ring_data, , );
if (unlikely(!skb)) /* this fault cannot be repaired */
goto out;
-- 
1.9.1



[PATCH net-next 6/9] net: hns: normalize two different loop

2016-06-27 Thread Yisen Zhuang
From: Daode Huang 

There are two approaches to assign data, one does 2 loops, another
does 1 loop. This patch normalize the different methods to 1 loop.

Signed-off-by: Daode Huang 
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index e36ee22..86ce28a 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -2567,15 +2567,15 @@ static char *hns_dsaf_get_node_stats_strings(char 
*data, int node,
buff += ETH_GSTRING_LEN;
if (node < DSAF_SERVICE_NW_NUM && !is_ver1) {
for (i = 0; i < DSAF_PRIO_NR; i++) {
-   snprintf(buff, ETH_GSTRING_LEN,
-"inod%d_pfc_prio%d_pkts", node, i);
-   buff += ETH_GSTRING_LEN;
-   }
-   for (i = 0; i < DSAF_PRIO_NR; i++) {
-   snprintf(buff, ETH_GSTRING_LEN,
-"onod%d_pfc_prio%d_pkts", node, i);
+   snprintf(buff + 0 * ETH_GSTRING_LEN * DSAF_PRIO_NR,
+ETH_GSTRING_LEN, "inod%d_pfc_prio%d_pkts",
+node, i);
+   snprintf(buff + 1 * ETH_GSTRING_LEN * DSAF_PRIO_NR,
+ETH_GSTRING_LEN, "onod%d_pfc_prio%d_pkts",
+node, i);
buff += ETH_GSTRING_LEN;
}
+   buff += 1 * DSAF_PRIO_NR * ETH_GSTRING_LEN;
}
snprintf(buff, ETH_GSTRING_LEN, "onnod%d_tx_pkts", node);
buff += ETH_GSTRING_LEN;
@@ -2606,8 +2606,8 @@ static u64 *hns_dsaf_get_node_stats(struct dsaf_device 
*ddev, u64 *data,
p[12] = hw_stats->stp_drop;
if (node_num < DSAF_SERVICE_NW_NUM && !is_ver1) {
for (i = 0; i < DSAF_PRIO_NR; i++) {
-   p[13 + i] = hw_stats->rx_pfc[i];
-   p[13 + i + DSAF_PRIO_NR] = hw_stats->tx_pfc[i];
+   p[13 + i + 0 * DSAF_PRIO_NR] = hw_stats->rx_pfc[i];
+   p[13 + i + 1 * DSAF_PRIO_NR] = hw_stats->tx_pfc[i];
}
p[29] = hw_stats->tx_pkts;
return [30];
-- 
1.9.1



[PATCH net-next 8/9] net: hns: add media-type property for hns

2016-06-27 Thread Yisen Zhuang
From: Kejian Yan 

It is PORT_TP type if the service port is GE mode. It is wrong to
judge the port type by using if it is service port. Adding the media
type to know port type.

Reported-by: Jinchuan Tian 
Signed-off-by: Kejian Yan 
---
 drivers/net/ethernet/hisilicon/hns/hnae.h |  9 
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 26 +++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c  | 14 +---
 5 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.h 
b/drivers/net/ethernet/hisilicon/hns/hnae.h
index 3869322..e093cbf 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.h
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.h
@@ -363,6 +363,14 @@ enum hnae_port_type {
HNAE_PORT_DEBUG
 };
 
+/* mac media type */
+enum hnae_media_type {
+   HNAE_MEDIA_TYPE_UNKNOWN = 0,
+   HNAE_MEDIA_TYPE_FIBER,
+   HNAE_MEDIA_TYPE_COPPER,
+   HNAE_MEDIA_TYPE_BACKPLANE,
+};
+
 /* This struct defines the operation on the handle.
  *
  * get_handle(): (mandatory)
@@ -525,6 +533,7 @@ struct hnae_handle {
u32 eport_id;
u32 dport_id;   /* v2 tx bd should fill the dport_id */
enum hnae_port_type port_type;
+   enum hnae_media_type media_type;
struct list_head node;/* list to hnae_ae_dev->handle_list */
struct hnae_buf_ops *bops; /* operation for the buffer */
struct hnae_queue **qs;  /* array base of all queues */
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
index 835521b..e28d960 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
@@ -134,6 +134,7 @@ struct hnae_handle *hns_ae_get_handle(struct hnae_ae_dev 
*dev,
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->media_type = vf_cb->mac_cb->media_type;
ae_handle->dport_id = port_id;
 
return ae_handle;
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index d2effcc..3fb87e2 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -733,6 +733,18 @@ static void hns_mac_register_phy(struct hns_mac_cb *mac_cb)
mac_cb->mac_id, addr);
 }
 
+#define MAC_MEDIA_TYPE_MAX_LEN 16
+
+static const struct {
+   enum hnae_media_type value;
+   const char *name;
+} media_type_defs[] = {
+   {HNAE_MEDIA_TYPE_UNKNOWN,   "unknown" },
+   {HNAE_MEDIA_TYPE_FIBER, "fiber" },
+   {HNAE_MEDIA_TYPE_COPPER,"copper" },
+   {HNAE_MEDIA_TYPE_BACKPLANE, "backplane" },
+};
+
 /**
  *hns_mac_get_info  - get mac information from device node
  *@mac_cb: mac device
@@ -744,10 +756,13 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
struct device_node *np;
struct regmap *syscon;
struct of_phandle_args cpld_args;
+   const char *media_type;
+   u32 i;
u32 ret;
 
mac_cb->link = false;
mac_cb->half_duplex = false;
+   mac_cb->media_type = HNAE_MEDIA_TYPE_UNKNOWN;
mac_cb->speed = mac_phy_to_speed[mac_cb->phy_if];
mac_cb->max_speed = mac_cb->speed;
 
@@ -849,6 +864,17 @@ static int  hns_mac_get_info(struct hns_mac_cb *mac_cb)
mac_cb->mac_id);
}
 
+   if (!fwnode_property_read_string(mac_cb->fw_port, "media-type",
+_type)) {
+   for (i = 0; i < ARRAY_SIZE(media_type_defs); i++) {
+   if (!strncmp(media_type_defs[i].name, media_type,
+MAC_MEDIA_TYPE_MAX_LEN)) {
+   mac_cb->media_type = media_type_defs[i].value;
+   break;
+   }
+   }
+   }
+
return 0;
 }
 
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
index 05a6e8f..4cbdf14 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
@@ -335,6 +335,7 @@ struct hns_mac_cb {
u64 txpkt_for_led;
u64 rxpkt_for_led;
enum hnae_port_type mac_type;
+   enum hnae_media_type media_type;
phy_interface_t phy_if;
enum hnae_loop loop_mode;
 
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
index a395ca1..ab33487 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
+++ 

[PATCH net-next 0/9] net: hns: fix the typo of hns

2016-06-27 Thread Yisen Zhuang
This series includes typo fixes which review by Andy, adding
the hns maintainer to MAINTAINERS,

 > adds the maintainer for hns driver from Daode;

 > from Daode: fix the typo of hns reviewed by Andy Shevchenko;

 > from Kejian: one remove redundant function and two fix to get 
configuration from DT.

Daode Huang (6):
  MAINTAINERS: add maintainers for hns driver
  net: hns: fix code style about hns driver
  net: hns: change code style from a = a + x to a += x
  net: hns: delete redundant parens
  net: hns: add a space before "*/"
  net: hns: normalize two different loop

Kejian Yan (3):
  net: hns: remove redundant hns_mac_dev_to_enet_if()
  net: hns: add media-type property for hns
  net: hns: get reset registers from DT

 MAINTAINERS|  9 +++
 drivers/net/ethernet/hisilicon/hns/hnae.h  |  9 +++
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 41 +++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 52 +++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 16 ++---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c  |  4 +-
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   | 14 +++-
 drivers/net/ethernet/hisilicon/hns_mdio.c  | 80 ++
 10 files changed, 158 insertions(+), 69 deletions(-)

-- 
1.9.1



Re: [PATCH net-next 10/19] net: hns: bugfix about pfc pause frame statistics

2016-06-22 Thread Yisen Zhuang


在 2016/6/22 17:41, Andy Shevchenko 写道:
> On Wed, 2016-06-22 at 09:43 +0800, Yisen Zhuang wrote:
>>
>> 在 2016/6/21 18:32, Andy Shevchenko 写道:
>>> On Tue, 2016-06-21 at 11:56 +0800, Yisen Zhuang wrote:
>>>> From: Daode Huang <huangda...@hisilicon.com>
>>>>
>>>> For SoC hip06, PFC pause handled in dsaf, while hip05 in XGMAC,
>>>> so change the statistics of pfc pause in dsaf and remove the old
>>>> pfc pause frame statistics.
>>>>
>>>  
>>>
>>>> +static char *hns_dsaf_get_node_stats_strings(char *data, int
>>>> node,
>>>> +   struct dsaf_device
>>>> *dsaf_dev)
>>>>  {
>>>>char *buff = data;
>>>> +  int i;
>>>> +  bool is_ver1 = AE_IS_VER1(dsaf_dev->dsaf_ver);
>>>>  
>>>>snprintf(buff, ETH_GSTRING_LEN, "innod%d_pad_drop_pkts",
>>>> node);
>>>>buff = buff + ETH_GSTRING_LEN;
>>>> @@ -2502,6 +2530,18 @@ static char
>>>> *hns_dsaf_get_node_stats_strings(char *data, int node)
>>>>buff = buff + ETH_GSTRING_LEN;
>>>>snprintf(buff, ETH_GSTRING_LEN, "innod%d_stp_drop_pkts",
>>>> node);
>>>>buff = buff + ETH_GSTRING_LEN;
>>>> +  if ((node < DSAF_SERVICE_NW_NUM) && (!is_ver1)) {
>>>
>>> Redundant parens.
>>>
>>>> +  for (i = 0; i < DSAF_PRIO_NR; i++) {
>>>> +  snprintf(buff, ETH_GSTRING_LEN,
>>>> +   "inod%d_pfc_prio%d_pkts", node,
>>>> i);
>>>> +  buff = buff + ETH_GSTRING_LEN;
>>>
>>> buff += ...
>>>
>>>> +  }
>>>> +  for (i = 0; i < DSAF_PRIO_NR; i++) {
>>>> +  snprintf(buff, ETH_GSTRING_LEN,
>>>> +   "onod%d_pfc_prio%d_pkts", node,
>>>> i);
>>>> +  buff = buff + ETH_GSTRING_LEN;
>>>
>>> Ditto.
>>>
>>>>  {
>>>>u64 *p = data;
>>>> +  int i;
>>>>struct dsaf_hw_stats *hw_stats = 
>>>>> hw_stats[node_num];
>>>> +  bool is_ver1 = AE_IS_VER1(ddev->dsaf_ver);
>>>>  
>>>>p[0] = hw_stats->pad_drop;
>>>>p[1] = hw_stats->man_pkts;
>>>> @@ -2527,8 +2569,16 @@ static u64 *hns_dsaf_get_node_stats(struct
>>>> dsaf_device *ddev, u64 *data,
>>>>p[10] = hw_stats->local_addr_false;
>>>>p[11] = hw_stats->vlan_drop;
>>>>p[12] = hw_stats->stp_drop;
>>>> -  p[13] = hw_stats->tx_pkts;
>>>> +  if ((node_num < DSAF_SERVICE_NW_NUM) && (!is_ver1)) {
>>>> +  for (i = 0; i < DSAF_PRIO_NR; i++) {
>>>> +  p[13 + i] = hw_stats->rx_pfc[i];
>>>> +  p[13 + i + DSAF_PRIO_NR] = hw_stats-
>>>>> tx_pfc[i];
>>>> +  }
>>>
>>> Two different approaches how to assign data. Above uses 2 for-loops,
>>> here you put everything to one.
>>
>> Above cann't be merged to 1 for-loop, because lenght of the string is
>> unknowable.
> 
> It doesn't matter since you are incrementing start position by
> constant. 
> 
> snprintf(buff, ETH_GSTRING_LEN, "inod%d_pfc_prio%d_pkts", node, i);
> snprintf(buff, ETH_GSTRING_LEN, "onod%d_pfc_prio%d_pkts", node, i);
> 
> Same approach as below can be used
> 
> snprintf(buff + 0 * ETH_GSTRING_LEN * DSAF_PRIO_NR, ETH_GSTRING_LEN, ...
> snprintf(buff + 1 * ETH_GSTRING_LEN * DSAF_PRIO_NR, ETH_GSTRING_LEN, ...
> 
> Of course to make it less verbose you may add new definition(s) and/ or
> variable(s).
> 
>>
>> And here we put everything to one to reduce codes.
>>
> 
> I would suggest to use following pattern for such lines
> p[13 + i + 0 * DSAF_PRIO_NR] = hw_stats->rx_pfc[i];
> p[13 + i + 1 * DSAF_PRIO_NR] = hw_stats->tx_pfc[i];
> 
> That's allow reader to see what are you doing here.
> 
> P.S. This is for the future patches since current is already applied.

Hi Andy,

Many thanks for you suggestions. I will fix it with a new patch.

Thanks,

Yisen

> 



Re: [PATCH net-next 16/19] net: hns: fix bug that alloc skb fail lead to port unavailable

2016-06-21 Thread Yisen Zhuang


在 2016/6/21 21:25, Sergei Shtylyov 写道:
> Hello.
> 
> On 6/21/2016 6:56 AM, Yisen Zhuang wrote:
> 
>> From: Jun He <hjat2...@huawei.com>
>>
>> When hns_nic_poll_rx_skb alloc skb fail, it will break receive cycle and
>> read new fbd_num to start new receive cycle. It recomputes cycle num is
>> fbd_num minus clean_count, actually this cycle num is too big because
>> it drop out receive cycle. It brings about the port unavailable.
>>
>> So we will goto out when alloc skb fail to fix this bug.
>>
>> Signed-off-by: Jun He <hjat2...@huawei.com>
>> Signed-off-by: Ding Tianhong <dingtianh...@huawei.com>
>> Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
>> ---
>>  drivers/net/ethernet/hisilicon/hns/hns_enet.c | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
>> b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
>> index f49246d..c0ce37b 100644
>> --- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
>> +++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
>> @@ -768,10 +768,10 @@ recv:
>>  clean_count = 0;
>>  }
>>
>> -/* poll one pkg*/
>> +/* poll one pkt*/

I will fix it with a new patch.

Thanks,

Yisen

> 
>How about adding a space before */?
> 
> [...]
> 
> MBR, Sergei
> 
> 
> .
> 



Re: [PATCH net-next 10/19] net: hns: bugfix about pfc pause frame statistics

2016-06-21 Thread Yisen Zhuang


在 2016/6/21 18:32, Andy Shevchenko 写道:
> On Tue, 2016-06-21 at 11:56 +0800, Yisen Zhuang wrote:
>> From: Daode Huang <huangda...@hisilicon.com>
>>
>> For SoC hip06, PFC pause handled in dsaf, while hip05 in XGMAC,
>> so change the statistics of pfc pause in dsaf and remove the old
>> pfc pause frame statistics.
>>
> 
> 
>> +static char *hns_dsaf_get_node_stats_strings(char *data, int node,
>> + struct dsaf_device
>> *dsaf_dev)
>>  {
>>  char *buff = data;
>> +int i;
>> +bool is_ver1 = AE_IS_VER1(dsaf_dev->dsaf_ver);
>>  
>>  snprintf(buff, ETH_GSTRING_LEN, "innod%d_pad_drop_pkts",
>> node);
>>  buff = buff + ETH_GSTRING_LEN;
>> @@ -2502,6 +2530,18 @@ static char
>> *hns_dsaf_get_node_stats_strings(char *data, int node)
>>  buff = buff + ETH_GSTRING_LEN;
>>  snprintf(buff, ETH_GSTRING_LEN, "innod%d_stp_drop_pkts",
>> node);
>>  buff = buff + ETH_GSTRING_LEN;
>> +if ((node < DSAF_SERVICE_NW_NUM) && (!is_ver1)) {
> 
> Redundant parens.
> 
>> +for (i = 0; i < DSAF_PRIO_NR; i++) {
>> +snprintf(buff, ETH_GSTRING_LEN,
>> + "inod%d_pfc_prio%d_pkts", node, i);
>> +buff = buff + ETH_GSTRING_LEN;
> 
> buff += ...
> 
>> +}
>> +for (i = 0; i < DSAF_PRIO_NR; i++) {
>> +snprintf(buff, ETH_GSTRING_LEN,
>> + "onod%d_pfc_prio%d_pkts", node, i);
>> +buff = buff + ETH_GSTRING_LEN;
> 
> Ditto.
> 
>>  {
>>  u64 *p = data;
>> +int i;
>>  struct dsaf_hw_stats *hw_stats = >hw_stats[node_num];
>> +bool is_ver1 = AE_IS_VER1(ddev->dsaf_ver);
>>  
>>  p[0] = hw_stats->pad_drop;
>>  p[1] = hw_stats->man_pkts;
>> @@ -2527,8 +2569,16 @@ static u64 *hns_dsaf_get_node_stats(struct
>> dsaf_device *ddev, u64 *data,
>>  p[10] = hw_stats->local_addr_false;
>>  p[11] = hw_stats->vlan_drop;
>>  p[12] = hw_stats->stp_drop;
>> -p[13] = hw_stats->tx_pkts;
>> +if ((node_num < DSAF_SERVICE_NW_NUM) && (!is_ver1)) {
>> +for (i = 0; i < DSAF_PRIO_NR; i++) {
>> +p[13 + i] = hw_stats->rx_pfc[i];
>> +p[13 + i + DSAF_PRIO_NR] = hw_stats-
>>> tx_pfc[i];
>> +}
> 
> Two different approaches how to assign data. Above uses 2 for-loops,
> here you put everything to one.

Above cann't be merged to 1 for-loop, because lenght of the string is 
unknowable.

And here we put everything to one to reduce codes.

I will generate a new patch to fix other comments.

Thanks,

Yisen

> 
>> +p[29] = hw_stats->tx_pkts;
>> +return [30];
>> +}
>>  
>> +p[13] = hw_stats->tx_pkts;
>>  return [14];
>>  }
> 



Re: [PATCH net-next 01/19] net: hns: bug fix of ge reset sequence

2016-06-21 Thread Yisen Zhuang


在 2016/6/21 18:35, Andy Shevchenko 写道:
> On Tue, 2016-06-21 at 11:56 +0800, Yisen Zhuang wrote:
>> From: Qianqian Xie <xieqianq...@huawei.com>
>>
>> The bit fileds of PPE reset register are different between HNS v1 and
>> HNS v2, but the current procedure just only match HNS v1. Here is a
>> patch to fix it.
>>
>> Signed-off-by: Kejian Yan <yankej...@huawei.com>
>> Signed-off-by: Qianqian Xie <xieqianq...@huawei.com>
>> Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
>> ---
>>  drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 6 +-
>>  1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
>> b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
>> index 96cb628..09e60d6 100644
>> --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
>> +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
>> @@ -271,7 +271,11 @@ static void hns_dsaf_ge_srst_by_port(struct
>> dsaf_device *dsaf_dev, u32 port,
>>  }
>>  } else {
>>  reg_val_1 = 0x15540 << dsaf_dev->reset_offset;
>> -reg_val_2 = 0x100 << dsaf_dev->reset_offset;
>> +
>> +if (AE_IS_VER1(dsaf_dev->dsaf_ver))
>> +reg_val_2 = 0x100 << dsaf_dev->reset_offset;
>> +else
>> +reg_val_2 = 0x40 << dsaf_dev->reset_offset;
> 
> reg_val_1 = 0x15540;
> reg_val_2 = AE_IS_VER1(dsaf_dev->dsaf_ver) ? 0x100 : 0x40;
> 
> reg_val_1 <<= dsaf_dev->reset_offset;
> reg_val_2 <<= dsaf_dev-

I will fix it with a new patch.

Thanks,

Yisen

>> reset_offset;
> 
> 
>>  
>>  if (!dereset) {
>>  dsaf_write_sub(dsaf_dev,
>> DSAF_SUB_SC_GE_RESET_REQ1_REG,
> 



[PATCH net-next 05/19] net: hns: Remove unnecessary device resource free

2016-06-20 Thread Yisen Zhuang
From: Qianqian Xie <xieqianq...@huawei.com>

The driver uses devm_ioremap_resource, it will unmap the map
automatically, remove the unnecessary the resource free.

Signed-off-by: Qianqian Xie <xieqianq...@huawei.com>
Reported-by: Kefeng Wang <wangkefeng.w...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 39 +++---
 1 file changed, 4 insertions(+), 35 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index 422f97d..b8b2ff9 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -176,7 +176,7 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
desc_num > HNS_DSAF_MAX_DESC_CNT) {
dev_err(dsaf_dev->dev, "get desc-num(%d) fail, ret=%d!\n",
desc_num, ret);
-   goto unmap_base_addr;
+   return -EINVAL;
}
dsaf_dev->desc_num = desc_num;
 
@@ -192,7 +192,7 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
if (ret < 0) {
dev_err(dsaf_dev->dev,
"get buf-size fail, ret=%d!\r\n", ret);
-   goto unmap_base_addr;
+   return ret;
}
dsaf_dev->buf_size = buf_size;
 
@@ -200,7 +200,7 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
if (dsaf_dev->buf_size_type < 0) {
dev_err(dsaf_dev->dev,
"buf_size(%d) is wrong!\n", buf_size);
-   goto unmap_base_addr;
+   return -EINVAL;
}
 
dsaf_dev->misc_op = hns_misc_op_get(dsaf_dev);
@@ -213,32 +213,6 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
dev_err(dsaf_dev->dev, "set mask to 64bit fail!\n");
 
return 0;
-
-unmap_base_addr:
-   if (dsaf_dev->io_base)
-   iounmap(dsaf_dev->io_base);
-   if (dsaf_dev->ppe_base)
-   iounmap(dsaf_dev->ppe_base);
-   if (dsaf_dev->sds_base)
-   iounmap(dsaf_dev->sds_base);
-   if (dsaf_dev->sc_base)
-   iounmap(dsaf_dev->sc_base);
-   return ret;
-}
-
-static void hns_dsaf_free_cfg(struct dsaf_device *dsaf_dev)
-{
-   if (dsaf_dev->io_base)
-   iounmap(dsaf_dev->io_base);
-
-   if (dsaf_dev->ppe_base)
-   iounmap(dsaf_dev->ppe_base);
-
-   if (dsaf_dev->sds_base)
-   iounmap(dsaf_dev->sds_base);
-
-   if (dsaf_dev->sc_base)
-   iounmap(dsaf_dev->sc_base);
 }
 
 /**
@@ -2645,7 +2619,7 @@ static int hns_dsaf_probe(struct platform_device *pdev)
 
ret = hns_dsaf_init(dsaf_dev);
if (ret)
-   goto free_cfg;
+   goto free_dev;
 
ret = hns_mac_init(dsaf_dev);
if (ret)
@@ -2670,9 +2644,6 @@ uninit_mac:
 uninit_dsaf:
hns_dsaf_free(dsaf_dev);
 
-free_cfg:
-   hns_dsaf_free_cfg(dsaf_dev);
-
 free_dev:
hns_dsaf_free_dev(dsaf_dev);
 
@@ -2695,8 +2666,6 @@ static int hns_dsaf_remove(struct platform_device *pdev)
 
hns_dsaf_free(dsaf_dev);
 
-   hns_dsaf_free_cfg(dsaf_dev);
-
hns_dsaf_free_dev(dsaf_dev);
 
return 0;
-- 
1.9.1



[PATCH net-next 06/19] net: hns: fix the error info when dma_set_mask_and_coherent fail

2016-06-20 Thread Yisen Zhuang
From: Qianqian Xie <xieqianq...@huawei.com>

The error info should be printed as "set mask to 64bit fail!" instead of
"set mask to 32bit fail!" in dma_set_mask_and_coherent().

Signed-off-by: Qianqian Xie <xieqianq...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index b978db4..00e529f 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -1972,7 +1972,7 @@ static int hns_nic_dev_probe(struct platform_device *pdev)
if (!dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)))
dev_dbg(dev, "set mask to 64bit\n");
else
-   dev_err(dev, "set mask to 32bit fail!\n");
+   dev_err(dev, "set mask to 64bit fail!\n");
 
/* carrier off reporting is important to ethtool even BEFORE open */
netif_carrier_off(ndev);
-- 
1.9.1



[PATCH net-next 16/19] net: hns: fix bug that alloc skb fail lead to port unavailable

2016-06-20 Thread Yisen Zhuang
From: Jun He <hjat2...@huawei.com>

When hns_nic_poll_rx_skb alloc skb fail, it will break receive cycle and
read new fbd_num to start new receive cycle. It recomputes cycle num is
fbd_num minus clean_count, actually this cycle num is too big because
it drop out receive cycle. It brings about the port unavailable.

So we will goto out when alloc skb fail to fix this bug.

Signed-off-by: Jun He <hjat2...@huawei.com>
Signed-off-by: Ding Tianhong <dingtianh...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index f49246d..c0ce37b 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -768,10 +768,10 @@ recv:
clean_count = 0;
}
 
-   /* poll one pkg*/
+   /* poll one pkt*/
err = hns_nic_poll_rx_skb(ring_data, , );
if (unlikely(!skb)) /* this fault cannot be repaired */
-   break;
+   goto out;
 
recv_bds += bnum;
clean_count += bnum;
@@ -797,6 +797,7 @@ recv:
}
}
 
+out:
/* make all data has been write before submit */
if (clean_count > 0)
hns_nic_alloc_rx_buffers(ring_data, clean_count);
-- 
1.9.1



[PATCH net-next 04/19] net: hns: typo fix of annotation info for hns_nic_reset_subtask()

2016-06-20 Thread Yisen Zhuang
From: Qianqian Xie <xieqianq...@huawei.com>

The annotation info for hns_nic_reset_subtask() should be
"for resetting subtask" instead of "for resetting suntask".

Signed-off-by: Qianqian Xie <xieqianq...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index 15200e4..b978db4 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -1633,7 +1633,7 @@ static void hns_nic_dump(struct hns_nic_priv *priv)
}
 }
 
-/* for resetting suntask*/
+/* for resetting subtask */
 static void hns_nic_reset_subtask(struct hns_nic_priv *priv)
 {
enum hnae_port_type type = priv->ae_handle->port_type;
-- 
1.9.1



[PATCH net-next 08/19] net: hns: fix ethtool loopback fail bug

2016-06-20 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

When run ethtool cmd(ethtool -t ethx) again and again for a long
time, it will be probabilistically fail. The PHYs' registers may
be on different pages, so it must be switch to the right page
before setting PHYs' registers.
And __lb_up() calls phy_start() to startup the PHYs device, but
this function may change Copper Control Register(Page 0, Register 0)
to an other value. It would cause phy loopback test fail. if we
remove phy_start(), we have to remove the relative phy_stop(),
phy_disconnect() when doing phy loopback to keep the phy stay in
right status.

Reported-by: hejun <hjat2...@huawei.com>
Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 35 ++--
 1 file changed, 14 insertions(+), 21 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
index a809f52..5b3dccb 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
@@ -242,6 +242,7 @@ static const char hns_nic_test_strs[][ETH_GSTRING_LEN] = {
 static int hns_nic_config_phy_loopback(struct phy_device *phy_dev, u8 en)
 {
 #define COPPER_CONTROL_REG 0
+#define PHY_POWER_DOWN BIT(11)
 #define PHY_LOOP_BACK BIT(14)
u16 val = 0;
 
@@ -252,33 +253,40 @@ static int hns_nic_config_phy_loopback(struct phy_device 
*phy_dev, u8 en)
/* speed : 1000M */
phy_write(phy_dev, HNS_PHY_PAGE_REG, 2);
phy_write(phy_dev, 21, 0x1046);
+
+   phy_write(phy_dev, HNS_PHY_PAGE_REG, 0);
/* Force Master */
phy_write(phy_dev, 9, 0x1F00);
+
/* Soft-reset */
phy_write(phy_dev, 0, 0x9140);
/* If autoneg disabled,two soft-reset operations */
phy_write(phy_dev, 0, 0x9140);
-   phy_write(phy_dev, 22, 0xFA);
+
+   phy_write(phy_dev, HNS_PHY_PAGE_REG, 0xFA);
 
/* Default is 0x0400 */
phy_write(phy_dev, 1, 0x418);
 
/* Force 1000M Link, Default is 0x0200 */
phy_write(phy_dev, 7, 0x20C);
-   phy_write(phy_dev, 22, 0);
+   phy_write(phy_dev, HNS_PHY_PAGE_REG, 0);
 
-   /* Enable MAC loop-back */
+   /* Enable PHY loop-back */
val = phy_read(phy_dev, COPPER_CONTROL_REG);
val |= PHY_LOOP_BACK;
+   val &= ~PHY_POWER_DOWN;
phy_write(phy_dev, COPPER_CONTROL_REG, val);
} else {
-   phy_write(phy_dev, 22, 0xFA);
+   phy_write(phy_dev, HNS_PHY_PAGE_REG, 0xFA);
phy_write(phy_dev, 1, 0x400);
phy_write(phy_dev, 7, 0x200);
-   phy_write(phy_dev, 22, 0);
+   phy_write(phy_dev, HNS_PHY_PAGE_REG, 0);
+   phy_write(phy_dev, 9, 0xF00);
 
val = phy_read(phy_dev, COPPER_CONTROL_REG);
val &= ~PHY_LOOP_BACK;
+   val |= PHY_POWER_DOWN;
phy_write(phy_dev, COPPER_CONTROL_REG, val);
}
return 0;
@@ -339,28 +347,16 @@ static int __lb_up(struct net_device *ndev,
 
hns_nic_net_reset(ndev);
 
-   if (priv->phy) {
-   phy_disconnect(priv->phy);
-   msleep(100);
-
-   ret = hns_nic_init_phy(ndev, h);
-   if (ret)
-   return ret;
-   }
-
ret = __lb_setup(ndev, loop_mode);
if (ret)
return ret;
 
-   msleep(100);
+   msleep(200);
 
ret = h->dev->ops->start ? h->dev->ops->start(h) : 0;
if (ret)
return ret;
 
-   if (priv->phy)
-   phy_start(priv->phy);
-
/* link adjust duplex*/
if (priv->ae_handle->phy_if != PHY_INTERFACE_MODE_XGMII)
speed = 1000;
@@ -561,9 +557,6 @@ static int __lb_down(struct net_device *ndev)
   __func__,
   ret);
 
-   if (priv->phy)
-   phy_stop(priv->phy);
-
if (h->dev->ops->stop)
h->dev->ops->stop(h);
 
-- 
1.9.1



[PATCH net-next 19/19] net: hns: bug fix about TSO on|off when there is traffic

2016-06-20 Thread Yisen Zhuang
From: Daode Huang <huangda...@hisilicon.com>

When enable/disable tso, the driver tries to access the hardware register,
but this operation will cause the port unavalible when there is traffic.
This patch tries to enable TSO when initialize, then control tso through
TSE bit in transmit descriptor.

Signed-off-by: Daode Huang <huangda...@hisilicon.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index c0ce37b..d5297ec 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -1441,7 +1441,6 @@ static int hns_nic_set_features(struct net_device *netdev,
netdev_features_t features)
 {
struct hns_nic_priv *priv = netdev_priv(netdev);
-   struct hnae_handle *h = priv->ae_handle;
 
switch (priv->enet_ver) {
case AE_VERSION_1:
@@ -1454,11 +1453,9 @@ static int hns_nic_set_features(struct net_device 
*netdev,
priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tso;
/* The chip only support 7*4096 */
netif_set_gso_max_size(netdev, 7 * 4096);
-   h->dev->ops->set_tso_stats(h, 1);
} else {
priv->ops.fill_desc = fill_v2_desc;
priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tx;
-   h->dev->ops->set_tso_stats(h, 0);
}
break;
}
@@ -1804,11 +1801,14 @@ static void hns_nic_set_priv_ops(struct net_device 
*netdev)
priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tso;
/* This chip only support 7*4096 */
netif_set_gso_max_size(netdev, 7 * 4096);
-   h->dev->ops->set_tso_stats(h, 1);
} else {
priv->ops.fill_desc = fill_v2_desc;
priv->ops.maybe_stop_tx = hns_nic_maybe_stop_tx;
}
+   /* enable tso when init
+* control tso on/off through TSE bit in bd
+*/
+   h->dev->ops->set_tso_stats(h, 1);
}
 }
 
-- 
1.9.1



[PATCH net-next 03/19] net: hns: add skb_reset_mac_header() after skb being alloc

2016-06-20 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

HNS receives a packet without doing anything, but it should call
skb_reset_mac_header() to initialize the header before using
eth_hdr().

Fixes: 0d6b425a3773c3445b0f51b2f333821beaacb619
Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index ad742a6..15200e4 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -600,6 +600,7 @@ static int hns_nic_poll_rx_skb(struct hns_nic_ring_data 
*ring_data,
ring->stats.sw_err_cnt++;
return -ENOMEM;
}
+   skb_reset_mac_header(skb);
 
prefetchw(skb->data);
length = le16_to_cpu(desc->rx.pkt_len);
-- 
1.9.1



[PATCH net-next 02/19] net: hns: fix hns dsaf v1 dont support tx_pause close

2016-06-20 Thread Yisen Zhuang
From: Qianqian Xie <xieqiaq...@huawei.com>

For service port, hns dsaf v1 support to close tx_pause.
However, the port will be invalid when it run command
ethtool to close tx_pause. This patch will fix it.

Signed-off-by: Qianqian Xie <xieqiaq...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index ac03c4a..422f97d 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -1114,10 +1114,10 @@ int hns_dsaf_set_rx_mac_pause_en(struct dsaf_device 
*dsaf_dev, int mac_id,
 u32 en)
 {
if (AE_IS_VER1(dsaf_dev->dsaf_ver)) {
-   if (!en)
+   if (!en) {
dev_err(dsaf_dev->dev, "dsafv1 can't close 
rx_pause!\n");
-
-   return -EINVAL;
+   return -EINVAL;
+   }
}
 
dsaf_set_dev_bit(dsaf_dev, DSAF_PAUSE_CFG_REG + mac_id * 4,
-- 
1.9.1



[PATCH net-next 17/19] net: hns: fix sbm default parameters config error

2016-06-20 Thread Yisen Zhuang
From: Daode Huang <huangda...@hisilicon.com>

The default sbm config parameter leaves little buffer when there is heavy
traffic, which will cause packets drop. This patch changes them to make
enough buffers for handling packets.

Signed-off-by: Daode Huang <huangda...@hisilicon.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 40 ++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h  | 16 +++--
 2 files changed, 39 insertions(+), 17 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index 7f5c248..67e8e13 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -516,10 +516,10 @@ static void hns_dsafv2_sbm_bp_wl_cfg(struct dsaf_device 
*dsaf_dev)
o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
dsaf_set_field(o_sbm_bp_cfg,
   DSAFV2_SBM_CFG3_SET_BUF_NUM_NO_PFC_M,
-  DSAFV2_SBM_CFG3_SET_BUF_NUM_NO_PFC_S, 110);
+  DSAFV2_SBM_CFG3_SET_BUF_NUM_NO_PFC_S, 48);
dsaf_set_field(o_sbm_bp_cfg,
   DSAFV2_SBM_CFG3_RESET_BUF_NUM_NO_PFC_M,
-  DSAFV2_SBM_CFG3_RESET_BUF_NUM_NO_PFC_S, 160);
+  DSAFV2_SBM_CFG3_RESET_BUF_NUM_NO_PFC_S, 80);
dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
 
/* for no enable pfc mode */
@@ -527,29 +527,39 @@ static void hns_dsafv2_sbm_bp_wl_cfg(struct dsaf_device 
*dsaf_dev)
o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
dsaf_set_field(o_sbm_bp_cfg,
   DSAFV2_SBM_CFG4_SET_BUF_NUM_NO_PFC_M,
-  DSAFV2_SBM_CFG4_SET_BUF_NUM_NO_PFC_S, 128);
+  DSAFV2_SBM_CFG4_SET_BUF_NUM_NO_PFC_S, 192);
dsaf_set_field(o_sbm_bp_cfg,
   DSAFV2_SBM_CFG4_RESET_BUF_NUM_NO_PFC_M,
-  DSAFV2_SBM_CFG4_RESET_BUF_NUM_NO_PFC_S, 192);
+  DSAFV2_SBM_CFG4_RESET_BUF_NUM_NO_PFC_S, 240);
dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
}
 
/* PPE */
-   reg = DSAF_SBM_BP_CFG_2_PPE_REG_0_REG + 0x80 * i;
-   o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
-   dsaf_set_field(o_sbm_bp_cfg, DSAFV2_SBM_CFG2_SET_BUF_NUM_M,
-  DSAFV2_SBM_CFG2_SET_BUF_NUM_S, 10);
-   dsaf_set_field(o_sbm_bp_cfg, DSAFV2_SBM_CFG2_RESET_BUF_NUM_M,
-  DSAFV2_SBM_CFG2_RESET_BUF_NUM_S, 12);
-   dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
+   for (i = 0; i < DSAFV2_SBM_PPE_CHN; i++) {
+   reg = DSAF_SBM_BP_CFG_2_PPE_REG_0_REG + 0x80 * i;
+   o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
+   dsaf_set_field(o_sbm_bp_cfg,
+  DSAFV2_SBM_CFG2_PPE_SET_BUF_NUM_M,
+  DSAFV2_SBM_CFG2_PPE_SET_BUF_NUM_S, 2);
+   dsaf_set_field(o_sbm_bp_cfg,
+  DSAFV2_SBM_CFG2_PPE_RESET_BUF_NUM_M,
+  DSAFV2_SBM_CFG2_PPE_RESET_BUF_NUM_S, 3);
+   dsaf_set_field(o_sbm_bp_cfg,
+  DSAFV2_SBM_CFG2_PPE_CFG_USEFUL_NUM_M,
+  DSAFV2_SBM_CFG2_PPE_CFG_USEFUL_NUM_S, 52);
+   dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
+   }
+
/* RoCEE */
for (i = 0; i < DASFV2_ROCEE_CRD_NUM; i++) {
reg = DSAFV2_SBM_BP_CFG_2_ROCEE_REG_0_REG + 0x80 * i;
o_sbm_bp_cfg = dsaf_read_dev(dsaf_dev, reg);
-   dsaf_set_field(o_sbm_bp_cfg, DSAFV2_SBM_CFG2_SET_BUF_NUM_M,
-  DSAFV2_SBM_CFG2_SET_BUF_NUM_S, 2);
-   dsaf_set_field(o_sbm_bp_cfg, DSAFV2_SBM_CFG2_RESET_BUF_NUM_M,
-  DSAFV2_SBM_CFG2_RESET_BUF_NUM_S, 4);
+   dsaf_set_field(o_sbm_bp_cfg,
+  DSAFV2_SBM_CFG2_ROCEE_SET_BUF_NUM_M,
+  DSAFV2_SBM_CFG2_ROCEE_SET_BUF_NUM_S, 2);
+   dsaf_set_field(o_sbm_bp_cfg,
+  DSAFV2_SBM_CFG2_ROCEE_RESET_BUF_NUM_M,
+  DSAFV2_SBM_CFG2_ROCEE_RESET_BUF_NUM_S, 4);
dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg);
}
 }
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h
index e35d0cb..235f744 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h
@@ -32,7 +32,7 @@
 #define DSAFV2_SBM_NUM 8
 #define DSAFV2_SBM_XGE_CHN6
 #define DSAFV2_SBM_PPE_CHN1
-#define DASFV2_ROCEE_CRD_NUM  8
+#define DASFV2_ROC

[PATCH net-next 15/19] net: hns: bug fix about led control logic when link down

2016-06-20 Thread Yisen Zhuang
From: Daode Huang <huangda...@hisilicon.com>

The default driver sets anchor led bit to 0 when link down,
actually, the anchor bit should be set to 1, so fixes it when
link status is down.
Secondly, change the return value of cpld_set_led_id to 0, which
means leave the cpld to control led blink frequece other than the
driver itself.

Signed-off-by: Daode Huang <huangda...@hisilicon.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
index aff9d77..8473287 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
@@ -86,9 +86,10 @@ static void hns_cpld_set_led(struct hns_mac_cb *mac_cb, int 
link_status,
mac_cb->cpld_led_value = value;
}
} else {
-   dsaf_write_syscon(mac_cb->cpld_ctrl, mac_cb->cpld_ctrl_reg,
- CPLD_LED_DEFAULT_VALUE);
-   mac_cb->cpld_led_value = CPLD_LED_DEFAULT_VALUE;
+   value = (mac_cb->cpld_led_value) & (0x1 << DSAF_LED_ANCHOR_B);
+   dsaf_write_syscon(mac_cb->cpld_ctrl,
+ mac_cb->cpld_ctrl_reg, value);
+   mac_cb->cpld_led_value = value;
}
 }
 
@@ -114,7 +115,7 @@ static int cpld_set_led_id(struct hns_mac_cb *mac_cb,
 CPLD_LED_ON_VALUE);
dsaf_write_syscon(mac_cb->cpld_ctrl, mac_cb->cpld_ctrl_reg,
  mac_cb->cpld_led_value);
-   return 2;
+   break;
case HNAE_LED_INACTIVE:
dsaf_set_bit(mac_cb->cpld_led_value, DSAF_LED_ANCHOR_B,
 CPLD_LED_DEFAULT_VALUE);
@@ -122,7 +123,8 @@ static int cpld_set_led_id(struct hns_mac_cb *mac_cb,
  mac_cb->cpld_led_value);
break;
default:
-   break;
+   dev_err(mac_cb->dev, "invalid led state: %d!", status);
+   return -EINVAL;
}
 
return 0;
-- 
1.9.1



[PATCH net-next 12/19] net: hns: fix bug of getting the wrong tcam data

2016-06-20 Thread Yisen Zhuang
From: Daode Huang <huangda...@hisilicon.com>

The current driver stores the high bit value of tcam data register
to the tcam data low element, stores the low bit value of tcam data
register to tcam data high element, this patch fixes this bug.

Signed-off-by: Daode Huang <huangda...@hisilicon.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index 0958ceb..7f5c248 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -975,9 +975,9 @@ static void hns_dsaf_tcam_uc_get(
 
/*read tcam data*/
ptbl_tcam_data->tbl_tcam_data_high
-   = dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RDATA_LOW_0_REG);
-   ptbl_tcam_data->tbl_tcam_data_low
= dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RDATA_HIGH_0_REG);
+   ptbl_tcam_data->tbl_tcam_data_low
+   = dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RDATA_LOW_0_REG);
 
/*read tcam mcast*/
tcam_read_data0 = dsaf_read_dev(dsaf_dev,
@@ -1027,9 +1027,9 @@ static void hns_dsaf_tcam_mc_get(
 
/*read tcam data*/
ptbl_tcam_data->tbl_tcam_data_high =
-   dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RDATA_LOW_0_REG);
-   ptbl_tcam_data->tbl_tcam_data_low =
dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RDATA_HIGH_0_REG);
+   ptbl_tcam_data->tbl_tcam_data_low =
+   dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RDATA_LOW_0_REG);
 
/*read tcam mcast*/
ptbl_tcam_mcast->tbl_mcast_port_msk[0] =
-- 
1.9.1



[PATCH net-next 14/19] net: hns: delete redundancy ring enable operations

2016-06-20 Thread Yisen Zhuang
From: Daode Huang <huangda...@hisilicon.com>

When network interface is enabled, the ring enable operation is
conducted twice. This patch deletes the redundancy code of ring enable,
and integrates hnae_ae_ops.toggle_queue_status other functions to
hns_ae_start.

Signed-off-by: Daode Huang <huangda...@hisilicon.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hnae.c |  1 -
 drivers/net/ethernet/hisilicon/hns/hnae.h |  1 -
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c | 22 +-
 drivers/net/ethernet/hisilicon/hns/hns_enet.c |  7 +--
 4 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.c 
b/drivers/net/ethernet/hisilicon/hns/hnae.c
index 5d3047c..c54c6fa 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.c
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.c
@@ -400,7 +400,6 @@ int hnae_ae_register(struct hnae_ae_dev *hdev, struct 
module *owner)
 
if (!hdev->ops || !hdev->ops->get_handle ||
!hdev->ops->toggle_ring_irq ||
-   !hdev->ops->toggle_queue_status ||
!hdev->ops->get_status || !hdev->ops->adjust_link)
return -EINVAL;
 
diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.h 
b/drivers/net/ethernet/hisilicon/hns/hnae.h
index 962e445..3869322 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.h
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.h
@@ -454,7 +454,6 @@ struct hnae_ae_ops {
int (*get_info)(struct hnae_handle *handle,
u8 *auto_neg, u16 *speed, u8 *duplex);
void (*toggle_ring_irq)(struct hnae_ring *ring, u32 val);
-   void (*toggle_queue_status)(struct hnae_queue *queue, u32 val);
void (*adjust_link)(struct hnae_handle *handle, int speed, int duplex);
int (*set_loopback)(struct hnae_handle *handle,
enum hnae_loop loop_mode, int en);
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
index 6b3796f..835521b 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
@@ -247,12 +247,21 @@ static void hns_ae_set_tso_stats(struct hnae_handle 
*handle, int enable)
 static int hns_ae_start(struct hnae_handle *handle)
 {
int ret;
+   int k;
struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
 
ret = hns_mac_vm_config_bc_en(mac_cb, 0, true);
if (ret)
return ret;
 
+   for (k = 0; k < handle->q_num; k++) {
+   if (AE_IS_VER1(mac_cb->dsaf_dev->dsaf_ver))
+   hns_rcb_int_clr_hw(handle->qs[k],
+  RCB_INT_FLAG_TX | RCB_INT_FLAG_RX);
+   else
+   hns_rcbv2_int_clr_hw(handle->qs[k],
+RCB_INT_FLAG_TX | RCB_INT_FLAG_RX);
+   }
hns_ae_ring_enable_all(handle, 1);
msleep(100);
 
@@ -313,18 +322,6 @@ static void hns_aev2_toggle_ring_irq(struct hnae_ring 
*ring, u32 mask)
hns_rcbv2_int_ctrl_hw(ring->q, flag, mask);
 }
 
-static void hns_ae_toggle_queue_status(struct hnae_queue *queue, u32 val)
-{
-   struct dsaf_device *dsaf_dev = hns_ae_get_dsaf_dev(queue->dev);
-
-   if (AE_IS_VER1(dsaf_dev->dsaf_ver))
-   hns_rcb_int_clr_hw(queue, RCB_INT_FLAG_TX | RCB_INT_FLAG_RX);
-   else
-   hns_rcbv2_int_clr_hw(queue, RCB_INT_FLAG_TX | RCB_INT_FLAG_RX);
-
-   hns_rcb_start(queue, val);
-}
-
 static int hns_ae_get_link_status(struct hnae_handle *handle)
 {
u32 link_status;
@@ -808,7 +805,6 @@ static struct hnae_ae_ops hns_dsaf_ops = {
.stop = hns_ae_stop,
.reset = hns_ae_reset,
.toggle_ring_irq = hns_ae_toggle_ring_irq,
-   .toggle_queue_status = hns_ae_toggle_queue_status,
.get_status = hns_ae_get_link_status,
.get_info = hns_ae_get_mac_info,
.adjust_link = hns_ae_adjust_link,
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index cef9d12..f49246d 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -1200,7 +1200,7 @@ static int hns_nic_net_up(struct net_device *ndev)
 {
struct hns_nic_priv *priv = netdev_priv(ndev);
struct hnae_handle *h = priv->ae_handle;
-   int i, j, k;
+   int i, j;
int ret;
 
ret = hns_nic_init_irq(priv);
@@ -1215,9 +1215,6 @@ static int hns_nic_net_up(struct net_device *ndev)
goto out_has_some_queues;
}
 
-   for (k = 0; k < h->q_num; k++)
-   h->dev->ops->toggle_queue_status(h->qs[k], 1);
-
ret = h->dev->ops->set_mac_addr(h, ndev->dev_addr);
   

[PATCH net-next 00/19] net: hns: fix some bugs in hns driver

2016-06-20 Thread Yisen Zhuang
This series includes some bugs fixed. All these patches needs to be
applied after the patchset about ACPI support, so this series is 
floated to net-next list.

The patches are:
 > from Daode, fixes about pfc pause frame, getting coaslesce, led 
control logic, TSO on|off and tcam table configuration.

 > from Jun He, fix the potential leak to port unavailable

 > from Kejian, fix bug of loopback and failing to test ping6

 > from Qianqian, fix the several typo in hns driver

For more details, please see individual patches.

MBR.

Daode Huang (9):
  net: hns: bugfix about pfc pause frame statistics
  net: hns: add spin lock for tcam table operation
  net: hns: fix bug of getting the wrong tcam data
  net: hns: add get_coalesce_range api for hns
  net: hns: delete redundancy ring enable operations
  net: hns: bug fix about led control logic when link down
  net: hns: fix sbm default parameters config error
  net: hns: change the default coalesce usecs
  net: hns: bug fix about TSO on|off when there is traffic

Jun He (1):
  net: hns: fix bug that alloc skb fail lead to port unavailable

Kejian Yan (3):
  net: hns: add skb_reset_mac_header() after skb being alloc
  net: hns: select Hilink before serdes loopback for HNS V2
  net: hns: fix ethtool loopback fail bug

Qianqian Xie (6):
  net: hns: bug fix of ge reset sequence
  net: hns: fix hns dsaf v1 dont support tx_pause close
  net: hns: typo fix of annotation info for hns_nic_reset_subtask()
  net: hns: Remove unnecessary device resource free
  net: hns: fix the error info when dma_set_mask_and_coherent fail
  net: hns: fix the wrong speed for bond

 drivers/net/ethernet/hisilicon/hns/hnae.c  |   1 -
 drivers/net/ethernet/hisilicon/hns/hnae.h  |   6 +-
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  |  53 --
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 190 ++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h |  12 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c |  44 +++--
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c  |   2 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.h  |   2 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h  |  21 ++-
 drivers/net/ethernet/hisilicon/hns/hns_enet.c  |  68 
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   |  47 ++---
 11 files changed, 291 insertions(+), 155 deletions(-)

-- 
1.9.1



[PATCH net-next 10/19] net: hns: bugfix about pfc pause frame statistics

2016-06-20 Thread Yisen Zhuang
From: Daode Huang <huangda...@hisilicon.com>

For SoC hip06, PFC pause handled in dsaf, while hip05 in XGMAC,
so change the statistics of pfc pause in dsaf and remove the old
pfc pause frame statistics.

Signed-off-by: Daode Huang <huangda...@hisilicon.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  |  6 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 72 +++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h | 10 ++-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h  |  5 ++
 4 files changed, 81 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
index d37b778..b97cc75 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
@@ -587,6 +587,7 @@ void hns_ae_get_strings(struct hnae_handle *handle,
int idx;
struct hns_mac_cb *mac_cb;
struct hns_ppe_cb *ppe_cb;
+   struct dsaf_device *dsaf_dev = hns_ae_get_dsaf_dev(handle->dev);
u8 *p = data;
struct  hnae_vf_cb *vf_cb;
 
@@ -609,13 +610,14 @@ void hns_ae_get_strings(struct hnae_handle *handle,
p += ETH_GSTRING_LEN * hns_mac_get_sset_count(mac_cb, stringset);
 
if (mac_cb->mac_type == HNAE_PORT_SERVICE)
-   hns_dsaf_get_strings(stringset, p, port);
+   hns_dsaf_get_strings(stringset, p, port, dsaf_dev);
 }
 
 int hns_ae_get_sset_count(struct hnae_handle *handle, int stringset)
 {
u32 sset_count = 0;
struct hns_mac_cb *mac_cb;
+   struct dsaf_device *dsaf_dev = hns_ae_get_dsaf_dev(handle->dev);
 
assert(handle);
 
@@ -626,7 +628,7 @@ int hns_ae_get_sset_count(struct hnae_handle *handle, int 
stringset)
sset_count += hns_mac_get_sset_count(mac_cb, stringset);
 
if (mac_cb->mac_type == HNAE_PORT_SERVICE)
-   sset_count += hns_dsaf_get_sset_count(stringset);
+   sset_count += hns_dsaf_get_sset_count(dsaf_dev, stringset);
 
return sset_count;
 }
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index b8b2ff9..0edea9c 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -2096,11 +2096,24 @@ void hns_dsaf_fix_mac_mode(struct hns_mac_cb *mac_cb)
hns_dsaf_port_work_rate_cfg(dsaf_dev, mac_id, mode);
 }
 
+static u32 hns_dsaf_get_inode_prio_reg(int index)
+{
+   int base_index, offset;
+   u32 base_addr = DSAF_INODE_IN_PRIO_PAUSE_BASE_REG;
+
+   base_index = (index + 1) / DSAF_REG_PER_ZONE;
+   offset = (index + 1) % DSAF_REG_PER_ZONE;
+
+   return base_addr + DSAF_INODE_IN_PRIO_PAUSE_BASE_OFFSET * base_index +
+   DSAF_INODE_IN_PRIO_PAUSE_OFFSET * offset;
+}
+
 void hns_dsaf_update_stats(struct dsaf_device *dsaf_dev, u32 node_num)
 {
struct dsaf_hw_stats *hw_stats
= _dev->hw_stats[node_num];
bool is_ver1 = AE_IS_VER1(dsaf_dev->dsaf_ver);
+   int i;
u32 reg_tmp;
 
hw_stats->pad_drop += dsaf_read_dev(dsaf_dev,
@@ -2135,6 +2148,18 @@ void hns_dsaf_update_stats(struct dsaf_device *dsaf_dev, 
u32 node_num)
hw_stats->stp_drop += dsaf_read_dev(dsaf_dev,
DSAF_INODE_IN_DATA_STP_DISC_0_REG + 0x80 * (u64)node_num);
 
+   /* pfc pause frame statistics stored in dsaf inode*/
+   if ((node_num < DSAF_SERVICE_NW_NUM) && !is_ver1) {
+   for (i = 0; i < DSAF_PRIO_NR; i++) {
+   reg_tmp = hns_dsaf_get_inode_prio_reg(i);
+   hw_stats->rx_pfc[i] += dsaf_read_dev(dsaf_dev,
+   reg_tmp + 0x4 * (u64)node_num);
+   hw_stats->tx_pfc[i] += dsaf_read_dev(dsaf_dev,
+   DSAF_XOD_XGE_PFC_PRIO_CNT_BASE_REG +
+   DSAF_XOD_XGE_PFC_PRIO_CNT_OFFSET * i +
+   0xF0 * (u64)node_num);
+   }
+   }
hw_stats->tx_pkts += dsaf_read_dev(dsaf_dev,
DSAF_XOD_RCVPKT_CNT_0_REG + 0x90 * (u64)node_num);
 }
@@ -2472,9 +2497,12 @@ void hns_dsaf_get_regs(struct dsaf_device *ddev, u32 
port, void *data)
p[i] = 0x;
 }
 
-static char *hns_dsaf_get_node_stats_strings(char *data, int node)
+static char *hns_dsaf_get_node_stats_strings(char *data, int node,
+struct dsaf_device *dsaf_dev)
 {
char *buff = data;
+   int i;
+   bool is_ver1 = AE_IS_VER1(dsaf_dev->dsaf_ver);
 
snprintf(buff, ETH_GSTRING_LEN, "innod%d_pad_drop_pkts", node);
buff = buff + ETH_GSTRING_LEN;
@@ -2502,6 +2530,18 @@ static char *hns_dsaf_get_node_stats_strings(char *data, 
int node)
   

[PATCH net-next 13/19] net: hns: add get_coalesce_range api for hns

2016-06-20 Thread Yisen Zhuang
From: Daode Huang <huangda...@hisilicon.com>

This patch adds get_coalesce_range api for hns, it shows
range of coalesce usecs and frames that can be set on
this interface.

Signed-off-by: Daode Huang <huangda...@hisilicon.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hnae.h |  5 +
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c | 25 +++
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c  | 10 +
 3 files changed, 40 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.h 
b/drivers/net/ethernet/hisilicon/hns/hnae.h
index 529cb13..962e445 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.h
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.h
@@ -473,6 +473,11 @@ struct hnae_ae_ops {
int (*set_coalesce_usecs)(struct hnae_handle *handle, u32 timeout);
int (*set_coalesce_frames)(struct hnae_handle *handle,
   u32 coalesce_frames);
+   void (*get_coalesce_range)(struct hnae_handle *handle,
+  u32 *tx_frames_low, u32 *rx_frames_low,
+  u32 *tx_frames_high, u32 *rx_frames_high,
+  u32 *tx_usecs_low, u32 *rx_usecs_low,
+  u32 *tx_usecs_high, u32 *rx_usecs_high);
void (*set_promisc_mode)(struct hnae_handle *handle, u32 en);
int (*get_mac_addr)(struct hnae_handle *handle, void **p);
int (*set_mac_addr)(struct hnae_handle *handle, void *p);
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
index b97cc75..6b3796f 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
@@ -465,6 +465,30 @@ static int  hns_ae_set_coalesce_frames(struct hnae_handle 
*handle,
ring_pair->port_id_in_comm, coalesce_frames);
 }
 
+static void hns_ae_get_coalesce_range(struct hnae_handle *handle,
+ u32 *tx_frames_low, u32 *rx_frames_low,
+ u32 *tx_frames_high, u32 *rx_frames_high,
+ u32 *tx_usecs_low, u32 *rx_usecs_low,
+ u32 *tx_usecs_high, u32 *rx_usecs_high)
+{
+   struct dsaf_device *dsaf_dev;
+
+   dsaf_dev = hns_ae_get_dsaf_dev(handle->dev);
+
+   *tx_frames_low  = HNS_RCB_MIN_COALESCED_FRAMES;
+   *rx_frames_low  = HNS_RCB_MIN_COALESCED_FRAMES;
+   *tx_frames_high =
+   (dsaf_dev->desc_num - 1 > HNS_RCB_MAX_COALESCED_FRAMES) ?
+   HNS_RCB_MAX_COALESCED_FRAMES : dsaf_dev->desc_num - 1;
+   *rx_frames_high =
+   (dsaf_dev->desc_num - 1 > HNS_RCB_MAX_COALESCED_FRAMES) ?
+HNS_RCB_MAX_COALESCED_FRAMES : dsaf_dev->desc_num - 1;
+   *tx_usecs_low   = 0;
+   *rx_usecs_low   = 0;
+   *tx_usecs_high  = HNS_RCB_MAX_COALESCED_USECS;
+   *rx_usecs_high  = HNS_RCB_MAX_COALESCED_USECS;
+}
+
 void hns_ae_update_stats(struct hnae_handle *handle,
 struct net_device_stats *net_stats)
 {
@@ -798,6 +822,7 @@ static struct hnae_ae_ops hns_dsaf_ops = {
.get_rx_max_coalesced_frames = hns_ae_get_rx_max_coalesced_frames,
.set_coalesce_usecs = hns_ae_set_coalesce_usecs,
.set_coalesce_frames = hns_ae_set_coalesce_frames,
+   .get_coalesce_range = hns_ae_get_coalesce_range,
.set_promisc_mode = hns_ae_set_promisc_mode,
.set_mac_addr = hns_ae_set_mac_address,
.set_mc_addr = hns_ae_set_multicast_one,
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
index 564ae1e..a395ca1 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
@@ -751,6 +751,16 @@ static int hns_get_coalesce(struct net_device *net_dev,
>tx_max_coalesced_frames,
>rx_max_coalesced_frames);
 
+   ops->get_coalesce_range(priv->ae_handle,
+   >tx_max_coalesced_frames_low,
+   >rx_max_coalesced_frames_low,
+   >tx_max_coalesced_frames_high,
+   >rx_max_coalesced_frames_high,
+   >tx_coalesce_usecs_low,
+   >rx_coalesce_usecs_low,
+   >tx_coalesce_usecs_high,
+   >rx_coalesce_usecs_high);
+
return 0;
 }
 
-- 
1.9.1



[PATCH net-next 09/19] net: hns: fix the wrong speed for bond

2016-06-20 Thread Yisen Zhuang
From: Qianqian Xie <xieqianq...@huawei.com>

For debug-ports,there are two non-synchronized processes:
Speed-Auto-Negotiation and Link-Update-Status. The two
processes are towed by two different state machines.
Bond reads the speed when link up, but the speed maybe
not update the right value at that time.That make for bond's
wrong speed. Thus only one state machine should be used and
if phy_state_machine is used, it does not need to do
hns_nic_update_link_status().

Signed-off-by: Qianqian Xie <xieqianq...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c| 43 +---
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c |  2 +-
 2 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index 00e529f..cef9d12 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -991,8 +991,26 @@ static void hns_nic_adjust_link(struct net_device *ndev)
 {
struct hns_nic_priv *priv = netdev_priv(ndev);
struct hnae_handle *h = priv->ae_handle;
+   int state = 1;
+
+   if (priv->phy) {
+   h->dev->ops->adjust_link(h, ndev->phydev->speed,
+ndev->phydev->duplex);
+   state = priv->phy->link;
+   }
+   state = state && h->dev->ops->get_status(h);
 
-   h->dev->ops->adjust_link(h, ndev->phydev->speed, ndev->phydev->duplex);
+   if (state != priv->link) {
+   if (state) {
+   netif_carrier_on(ndev);
+   netif_tx_wake_all_queues(ndev);
+   netdev_info(ndev, "link up\n");
+   } else {
+   netif_carrier_off(ndev);
+   netdev_info(ndev, "link down\n");
+   }
+   priv->link = state;
+   }
 }
 
 /**
@@ -1577,27 +1595,14 @@ static void hns_nic_update_link_status(struct 
net_device *netdev)
struct hns_nic_priv *priv = netdev_priv(netdev);
 
struct hnae_handle *h = priv->ae_handle;
-   int state = 1;
 
-   if (priv->phy) {
-   if (!genphy_update_link(priv->phy))
-   state = priv->phy->link;
-   else
-   state = 0;
-   }
-   state = state && h->dev->ops->get_status(h);
+   if (h->phy_dev) {
+   if (h->phy_if != PHY_INTERFACE_MODE_XGMII)
+   return;
 
-   if (state != priv->link) {
-   if (state) {
-   netif_carrier_on(netdev);
-   netif_tx_wake_all_queues(netdev);
-   netdev_info(netdev, "link up\n");
-   } else {
-   netif_carrier_off(netdev);
-   netdev_info(netdev, "link down\n");
-   }
-   priv->link = state;
+   (void)genphy_read_status(h->phy_dev);
}
+   hns_nic_adjust_link(netdev);
 }
 
 /* for dumping key regs*/
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
index 5b3dccb..564ae1e 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
@@ -49,7 +49,7 @@ static u32 hns_nic_get_link(struct net_device *net_dev)
h = priv->ae_handle;
 
if (priv->phy) {
-   if (!genphy_update_link(priv->phy))
+   if (!genphy_read_status(priv->phy))
link_stat = priv->phy->link;
else
link_stat = 0;
-- 
1.9.1



[PATCH net-next 18/19] net: hns: change the default coalesce usecs

2016-06-20 Thread Yisen Zhuang
From: Daode Huang <huangda...@hisilicon.com>

The default coalesce timeout is 3us, which is will cause CPU
usage is too high. This patch change it to 50us in order to reduce
CPU usage and the value makes sure network latency also meets requirement.

Signed-off-by: Daode Huang <huangda...@hisilicon.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c | 2 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c
index 3ce2409..ef11077 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c
@@ -540,7 +540,7 @@ int hns_rcb_set_coalesce_usecs(
}
if (timeout > HNS_RCB_MAX_COALESCED_USECS) {
dev_err(rcb_common->dsaf_dev->dev,
-   "error: not support coalesce %dus!\n", timeout);
+   "error: coalesce_usecs setting supports 0~1023us\n");
return -EINVAL;
}
hns_rcb_set_port_timeout(rcb_common, port_idx, timeout);
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.h 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.h
index bd54dac..99b4e1b 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.h
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.h
@@ -40,7 +40,7 @@ struct rcb_common_cb;
 #define HNS_RCB_DEF_COALESCED_FRAMES   50
 #define HNS_RCB_CLK_FREQ_MHZ   350
 #define HNS_RCB_MAX_COALESCED_USECS0x3ff
-#define HNS_RCB_DEF_COALESCED_USECS3
+#define HNS_RCB_DEF_COALESCED_USECS50
 
 #define HNS_RCB_COMMON_ENDIAN  1
 
-- 
1.9.1



[PATCH net-next 01/19] net: hns: bug fix of ge reset sequence

2016-06-20 Thread Yisen Zhuang
From: Qianqian Xie <xieqianq...@huawei.com>

The bit fileds of PPE reset register are different between HNS v1 and
HNS v2, but the current procedure just only match HNS v1. Here is a
patch to fix it.

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Qianqian Xie <xieqianq...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
index 96cb628..09e60d6 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
@@ -271,7 +271,11 @@ static void hns_dsaf_ge_srst_by_port(struct dsaf_device 
*dsaf_dev, u32 port,
}
} else {
reg_val_1 = 0x15540 << dsaf_dev->reset_offset;
-   reg_val_2 = 0x100 << dsaf_dev->reset_offset;
+
+   if (AE_IS_VER1(dsaf_dev->dsaf_ver))
+   reg_val_2 = 0x100 << dsaf_dev->reset_offset;
+   else
+   reg_val_2 = 0x40 << dsaf_dev->reset_offset;
 
if (!dereset) {
dsaf_write_sub(dsaf_dev, DSAF_SUB_SC_GE_RESET_REQ1_REG,
-- 
1.9.1



[PATCH net-next 11/19] net: hns: add spin lock for tcam table operation

2016-06-20 Thread Yisen Zhuang
From: Daode Huang <huangda...@hisilicon.com>

This patch adds spin lock for tcam table operation,
there maybe a race condition happens when more than
one thread try to change the tcam talbe entries.

Signed-off-by: Daode Huang <huangda...@hisilicon.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 25 ++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h |  2 ++
 2 files changed, 27 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index 0edea9c..0958ceb 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -860,6 +860,8 @@ static void hns_dsaf_single_line_tbl_cfg(
struct dsaf_device *dsaf_dev,
u32 address, struct dsaf_tbl_line_cfg *ptbl_line)
 {
+   spin_lock_bh(_dev->tcam_lock);
+
/*Write Addr*/
hns_dsaf_tbl_line_addr_cfg(dsaf_dev, address);
 
@@ -868,6 +870,8 @@ static void hns_dsaf_single_line_tbl_cfg(
 
/*Write Plus*/
hns_dsaf_tbl_line_pul(dsaf_dev);
+
+   spin_unlock_bh(_dev->tcam_lock);
 }
 
 /**
@@ -881,6 +885,8 @@ static void hns_dsaf_tcam_uc_cfg(
struct dsaf_tbl_tcam_data *ptbl_tcam_data,
struct dsaf_tbl_tcam_ucast_cfg *ptbl_tcam_ucast)
 {
+   spin_lock_bh(_dev->tcam_lock);
+
/*Write Addr*/
hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
/*Write Tcam Data*/
@@ -889,6 +895,8 @@ static void hns_dsaf_tcam_uc_cfg(
hns_dsaf_tbl_tcam_ucast_cfg(dsaf_dev, ptbl_tcam_ucast);
/*Write Plus*/
hns_dsaf_tbl_tcam_data_ucast_pul(dsaf_dev);
+
+   spin_unlock_bh(_dev->tcam_lock);
 }
 
 /**
@@ -903,6 +911,8 @@ static void hns_dsaf_tcam_mc_cfg(
struct dsaf_tbl_tcam_data *ptbl_tcam_data,
struct dsaf_tbl_tcam_mcast_cfg *ptbl_tcam_mcast)
 {
+   spin_lock_bh(_dev->tcam_lock);
+
/*Write Addr*/
hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
/*Write Tcam Data*/
@@ -911,6 +921,8 @@ static void hns_dsaf_tcam_mc_cfg(
hns_dsaf_tbl_tcam_mcast_cfg(dsaf_dev, ptbl_tcam_mcast);
/*Write Plus*/
hns_dsaf_tbl_tcam_data_mcast_pul(dsaf_dev);
+
+   spin_unlock_bh(_dev->tcam_lock);
 }
 
 /**
@@ -920,6 +932,8 @@ static void hns_dsaf_tcam_mc_cfg(
  */
 static void hns_dsaf_tcam_mc_invld(struct dsaf_device *dsaf_dev, u32 address)
 {
+   spin_lock_bh(_dev->tcam_lock);
+
/*Write Addr*/
hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
 
@@ -932,6 +946,8 @@ static void hns_dsaf_tcam_mc_invld(struct dsaf_device 
*dsaf_dev, u32 address)
 
/*Write Plus*/
hns_dsaf_tbl_tcam_mcast_pul(dsaf_dev);
+
+   spin_unlock_bh(_dev->tcam_lock);
 }
 
 /**
@@ -949,6 +965,8 @@ static void hns_dsaf_tcam_uc_get(
u32 tcam_read_data0;
u32 tcam_read_data4;
 
+   spin_lock_bh(_dev->tcam_lock);
+
/*Write Addr*/
hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
 
@@ -981,6 +999,8 @@ static void hns_dsaf_tcam_uc_get(
 DSAF_TBL_UCAST_CFG1_OUT_PORT_S);
ptbl_tcam_ucast->tbl_ucast_dvc
= dsaf_get_bit(tcam_read_data0, DSAF_TBL_UCAST_CFG1_DVC_S);
+
+   spin_unlock_bh(_dev->tcam_lock);
 }
 
 /**
@@ -997,6 +1017,8 @@ static void hns_dsaf_tcam_mc_get(
 {
u32 data_tmp;
 
+   spin_lock_bh(_dev->tcam_lock);
+
/*Write Addr*/
hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
 
@@ -1027,6 +1049,8 @@ static void hns_dsaf_tcam_mc_get(
ptbl_tcam_mcast->tbl_mcast_port_msk[4] =
dsaf_get_field(data_tmp, DSAF_TBL_MCAST_CFG4_VM128_112_M,
   DSAF_TBL_MCAST_CFG4_VM128_112_S);
+
+   spin_unlock_bh(_dev->tcam_lock);
 }
 
 /**
@@ -1351,6 +1375,7 @@ static int hns_dsaf_init(struct dsaf_device *dsaf_dev)
if (HNS_DSAF_IS_DEBUG(dsaf_dev))
return 0;
 
+   spin_lock_init(_dev->tcam_lock);
ret = hns_dsaf_init_hw(dsaf_dev);
if (ret)
return ret;
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h
index 00a13de..1daf018 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h
@@ -322,6 +322,8 @@ struct dsaf_device {
 
struct dsaf_hw_stats hw_stats[DSAF_NODE_NUM];
struct dsaf_int_stat int_stat;
+   /* make sure tcam table config spinlock */
+   spinlock_t tcam_lock;
 };
 
 static inline void *hns_dsaf_dev_priv(const struct dsaf_device *dsaf_dev)
-- 
1.9.1



[PATCH net-next 07/19] net: hns: select Hilink before serdes loopback for HNS V2

2016-06-20 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

As Hilink3 and Hilink4 use the same xge training and xge u adaptor for
HNSv2, it needs to select which Hilink to be set before relative serdes
being configed. The hilink_access_sel is the register to do that.

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 26 +-
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
index 09e60d6..aff9d77 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
@@ -435,11 +435,6 @@ int hns_mac_get_sfp_prsnt(struct hns_mac_cb *mac_cb, int 
*sfp_prsnt)
  */
 static int hns_mac_config_sds_loopback(struct hns_mac_cb *mac_cb, bool en)
 {
-   /* port 0-3 hilink4 base is serdes_vaddr + 0x0028
-* port 4-7 hilink3 base is serdes_vaddr + 0x0020
-*/
-   u8 *base_addr = (u8 *)mac_cb->serdes_vaddr +
-  (mac_cb->mac_id <= 3 ? 0x0028 : 0x0020);
const u8 lane_id[] = {
0,  /* mac 0 -> lane 0 */
1,  /* mac 1 -> lane 1 */
@@ -465,11 +460,30 @@ static int hns_mac_config_sds_loopback(struct hns_mac_cb 
*mac_cb, bool en)
}
 
if (mac_cb->serdes_ctrl) {
-   u32 origin = dsaf_read_syscon(mac_cb->serdes_ctrl, reg_offset);
+   u32 origin;
+
+   if (!AE_IS_VER1(mac_cb->dsaf_dev->dsaf_ver)) {
+#define HILINK_ACCESS_SEL_CFG  0x40008
+   /* hilink4 & hilink3 use the same xge training and
+* xge u adaptor. There is a hilink access sel cfg
+* register to select which one to be configed
+*/
+   if ((!HNS_DSAF_IS_DEBUG(mac_cb->dsaf_dev)) &&
+   (mac_cb->mac_id <= 3))
+   dsaf_write_syscon(mac_cb->serdes_ctrl,
+ HILINK_ACCESS_SEL_CFG, 0);
+   else
+   dsaf_write_syscon(mac_cb->serdes_ctrl,
+ HILINK_ACCESS_SEL_CFG, 3);
+   }
+
+   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 {
+   u8 *base_addr = (u8 *)mac_cb->serdes_vaddr +
+   (mac_cb->mac_id <= 3 ? 0x0028 : 0x0020);
dsaf_set_reg_field(base_addr, reg_offset, 1ull << 10, 10, en);
}
 
-- 
1.9.1



Re: [patch net-next] net: hns: add skb_reset_mac_header() after skb being alloc

2016-06-20 Thread Yisen Zhuang


在 2016/6/15 18:30, Yisen Zhuang 写道:
> Hi David,
> 
> Thanks for your suggestions.
> 
> Please see my comments below.
> 
> Thanks,
> 
> Yisen
> 
> 在 2016/6/15 13:41, David Miller 写道:
>> From: Yisen Zhuang <yisen.zhu...@huawei.com>
>> Date: Mon, 13 Jun 2016 20:41:22 +0800
>>
>>> From: Kejian Yan <yankej...@huawei.com>
>>>
>>> HNS receives a packet without doing anything, but it should call
>>> skb_reset_mac_header() to initialize the header before using
>>> eth_hdr().
>>>
>>> Fixes: 0d6b425a3773c3445b0f51b2f333821beaacb619
>>> Signed-off-by: Kejian Yan <yankej...@huawei.com>
>>> Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
>>
>> Well, this patch made me look at this function.
>>
>> You really shouldn't be filtering packets looped back, that is
>> the stack's job.  It shouldn't be happening in the driver.
> 
> If we use ping6 to test if it is connected to network, CPUs would send out 
> the NS packets
> and these packets will be looped back to CPUs. If driver does not drop these 
> packets,
> they will be sent to protocol stack and protocol stack consider that there is 
> a device
> with the same address and it is not available address. It will show us the 
> log like
> "connect: Cannot assign requested address". Then it can not connect to the 
> network enviroment.
> Thus, we drop these packets looped back in HNS driver.
> 

Hi David,

What is the opinion about this issue? We need this patch to resolve the issue.

Hoping for your suggestions.

Many thanks,

Yisen

>>
>> And once you remove that code, this patch here is no longer
>> necessary.
>>
>> Second of all, unless you card supports every protocol that
>> exists in the past, present, and _future_ you cannot set
>> skb->ip_summed to CHECKSUM_UNNECSSARY unconditionally like
>> that.
>>
>> You can only set that for protocols your chip actually supports.
> 
> Thanks for your suggestions. I will prepare a new patch to fix it.
> 
>>
>> .
>>
> 
> ___
> linuxarm mailing list
> linux...@huawei.com
> http://rnd-openeuler.huawei.com/mailman/listinfo/linuxarm
> 



Re: [patch net-next] net: hns: add skb_reset_mac_header() after skb being alloc

2016-06-15 Thread Yisen Zhuang
Hi David,

Thanks for your suggestions.

Please see my comments below.

Thanks,

Yisen

在 2016/6/15 13:41, David Miller 写道:
> From: Yisen Zhuang <yisen.zhu...@huawei.com>
> Date: Mon, 13 Jun 2016 20:41:22 +0800
> 
>> From: Kejian Yan <yankej...@huawei.com>
>>
>> HNS receives a packet without doing anything, but it should call
>> skb_reset_mac_header() to initialize the header before using
>> eth_hdr().
>>
>> Fixes: 0d6b425a3773c3445b0f51b2f333821beaacb619
>> Signed-off-by: Kejian Yan <yankej...@huawei.com>
>> Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
> 
> Well, this patch made me look at this function.
> 
> You really shouldn't be filtering packets looped back, that is
> the stack's job.  It shouldn't be happening in the driver.

If we use ping6 to test if it is connected to network, CPUs would send out the 
NS packets
and these packets will be looped back to CPUs. If driver does not drop these 
packets,
they will be sent to protocol stack and protocol stack consider that there is a 
device
with the same address and it is not available address. It will show us the log 
like
"connect: Cannot assign requested address". Then it can not connect to the 
network enviroment.
Thus, we drop these packets looped back in HNS driver.

> 
> And once you remove that code, this patch here is no longer
> necessary.
> 
> Second of all, unless you card supports every protocol that
> exists in the past, present, and _future_ you cannot set
> skb->ip_summed to CHECKSUM_UNNECSSARY unconditionally like
> that.
> 
> You can only set that for protocols your chip actually supports.

Thanks for your suggestions. I will prepare a new patch to fix it.

> 
> .
> 



Re: [PATCH] net: hns: update the dependency

2016-06-15 Thread Yisen Zhuang
Hi David,

I'm really sorry for this.

Because i didn't receive the first two emails, i resented it a few times.

I will pay more attention next time.

Thanks,

Yisen

在 2016/6/15 14:24, David Miller 写道:
> From: Yisen Zhuang <yisen.zhu...@huawei.com>
> Date: Wed, 15 Jun 2016 14:03:33 +0800
> 
>> Hi David,
>>
>> You mean that i send this patch 3 times?
>>
>> I am sorry for this.
>>
>> I don't know why you can receive 3 times. I can only receive an email for 
>> this patch.
> 
> I got three copies, each with a different Date: field.
> 
> patchwork saw all 3 copies as well:
> 
> http://patchwork.ozlabs.org/patch/634452/
> http://patchwork.ozlabs.org/patch/634559/
> http://patchwork.ozlabs.org/patch/634586/
> 
> .
> 



Re: [PATCH] net: hns: update the dependency

2016-06-15 Thread Yisen Zhuang
Hi David,

You mean that i send this patch 3 times?

I am sorry for this.

I don't know why you can receive 3 times. I can only receive an email for this 
patch.

Thanks,

Yisen

在 2016/6/15 13:26, David Miller 写道:
> From: Yisen Zhuang <yisen.zhu...@huawei.com>
> Date: Mon, 13 Jun 2016 19:56:27 +0800
> 
>> From: Kejian Yan <yankej...@huawei.com>
>>
>> After the patchset about adding support of ACPI (commit id is 6343488)
>> being applied, HNS does not depend on OF. It depends on OF or ACPI, so
>> the Kconfig file needs to be updated.
>>
>> Signed-off-by: Kejian Yan <yankej...@huawei.com>
>> Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
> 
> Why did you submit this same exact patch 3 times?
> 
> .
> 



[patch net-next] net: hns: add skb_reset_mac_header() after skb being alloc

2016-06-13 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

HNS receives a packet without doing anything, but it should call
skb_reset_mac_header() to initialize the header before using
eth_hdr().

Fixes: 0d6b425a3773c3445b0f51b2f333821beaacb619
Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index ad742a6..15200e4 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -600,6 +600,7 @@ static int hns_nic_poll_rx_skb(struct hns_nic_ring_data 
*ring_data,
ring->stats.sw_err_cnt++;
return -ENOMEM;
}
+   skb_reset_mac_header(skb);
 
prefetchw(skb->data);
length = le16_to_cpu(desc->rx.pkt_len);
-- 
1.9.1



[PATCH] net: hns: update the dependency

2016-06-13 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

After the patchset about adding support of ACPI (commit id is 6343488)
being applied, HNS does not depend on OF. It depends on OF or ACPI, so
the Kconfig file needs to be updated.

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/Kconfig 
b/drivers/net/ethernet/hisilicon/Kconfig
index 4ccc032..2e25662 100644
--- a/drivers/net/ethernet/hisilicon/Kconfig
+++ b/drivers/net/ethernet/hisilicon/Kconfig
@@ -5,7 +5,7 @@
 config NET_VENDOR_HISILICON
bool "Hisilicon devices"
default y
-   depends on OF && HAS_DMA
+   depends on (OF || ACPI) && HAS_DMA
depends on ARM || ARM64 || COMPILE_TEST
---help---
  If you have a network (Ethernet) card belonging to this class, say Y.
-- 
1.9.1



[PATCH] net: hns: update the dependency

2016-06-13 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

After the patchset about adding support of ACPI (commit id is 6343488)
being applied, HNS does not depend on OF. It depends on OF or ACPI, so
the Kconfig file needs to be updated.

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/Kconfig 
b/drivers/net/ethernet/hisilicon/Kconfig
index 4ccc032..2e25662 100644
--- a/drivers/net/ethernet/hisilicon/Kconfig
+++ b/drivers/net/ethernet/hisilicon/Kconfig
@@ -5,7 +5,7 @@
 config NET_VENDOR_HISILICON
bool "Hisilicon devices"
default y
-   depends on OF && HAS_DMA
+   depends on (OF || ACPI) && HAS_DMA
depends on ARM || ARM64 || COMPILE_TEST
---help---
  If you have a network (Ethernet) card belonging to this class, say Y.
-- 
1.9.1



[PATCH] net: hns: update the dependency

2016-06-13 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

After the patchset about adding support of ACPI (commit id is 6343488)
being applied, HNS does not depend on OF. It depends on OF or ACPI, so
the Kconfig file needs to be updated.

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/Kconfig 
b/drivers/net/ethernet/hisilicon/Kconfig
index 4ccc032..2e25662 100644
--- a/drivers/net/ethernet/hisilicon/Kconfig
+++ b/drivers/net/ethernet/hisilicon/Kconfig
@@ -5,7 +5,7 @@
 config NET_VENDOR_HISILICON
bool "Hisilicon devices"
default y
-   depends on OF && HAS_DMA
+   depends on (OF || ACPI) && HAS_DMA
depends on ARM || ARM64 || COMPILE_TEST
---help---
  If you have a network (Ethernet) card belonging to this class, say Y.
-- 
1.9.1



[PATCH v4 net-next 06/13] net: hns: use platform_get_irq instead of irq_of_parse_and_map

2016-06-02 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

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

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@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



[PATCH v4 net-next 09/13] net: hns: add dsaf misc operation method

2016-06-02 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

The misc operation for different hw platform may be different, if using
current implementation, it will add a new branch on each function for
every new hw platform, so we add a method for this operation.

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  |  4 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c |  6 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 14 ++--
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h  |  2 -
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 11 ++-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h | 33 ++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 79 +++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.h |  7 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c  | 15 ++--
 .../net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c| 10 +--
 10 files changed, 111 insertions(+), 70 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
index 8e009f4..d37b778 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
@@ -637,13 +637,15 @@ static int hns_ae_config_loopback(struct hnae_handle 
*handle,
int ret;
struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle);
struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
+   struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
 
switch (loop) {
case MAC_INTERNALLOOP_PHY:
ret = 0;
break;
case MAC_INTERNALLOOP_SERDES:
-   ret = hns_mac_config_sds_loopback(vf_cb->mac_cb, en);
+   ret = dsaf_dev->misc_op->cfg_serdes_loopback(vf_cb->mac_cb,
+!!en);
break;
case MAC_INTERNALLOOP_MAC:
ret = hns_mac_config_mac_loopback(vf_cb->mac_cb, loop, en);
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
index 44abb08..1235c7f 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
@@ -110,7 +110,7 @@ static void hns_gmac_free(void *mac_drv)
 
u32 mac_id = drv->mac_id;
 
-   hns_dsaf_ge_srst_by_port(dsaf_dev, mac_id, 0);
+   dsaf_dev->misc_op->ge_srst(dsaf_dev, mac_id, 0);
 }
 
 static void hns_gmac_set_tx_auto_pause_frames(void *mac_drv, u16 newval)
@@ -317,9 +317,9 @@ static void hns_gmac_init(void *mac_drv)
 
port = drv->mac_id;
 
-   hns_dsaf_ge_srst_by_port(dsaf_dev, port, 0);
+   dsaf_dev->misc_op->ge_srst(dsaf_dev, port, 0);
mdelay(10);
-   hns_dsaf_ge_srst_by_port(dsaf_dev, port, 1);
+   dsaf_dev->misc_op->ge_srst(dsaf_dev, port, 1);
mdelay(10);
hns_gmac_disable(mac_drv, MAC_COMM_MODE_RX_AND_TX);
hns_gmac_tx_loop_pkt_dis(mac_drv);
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 527b49d..2ebf14a 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -95,7 +95,7 @@ void hns_mac_get_link_status(struct hns_mac_cb *mac_cb, u32 
*link_status)
else
*link_status = 0;
 
-   ret = hns_mac_get_sfp_prsnt(mac_cb, _prsnt);
+   ret = mac_cb->dsaf_dev->misc_op->get_sfp_prsnt(mac_cb, _prsnt);
if (!ret)
*link_status = *link_status && sfp_prsnt;
 
@@ -512,7 +512,7 @@ void hns_mac_stop(struct hns_mac_cb *mac_cb)
 
mac_ctrl_drv->mac_en_flg = 0;
mac_cb->link = 0;
-   cpld_led_reset(mac_cb);
+   mac_cb->dsaf_dev->misc_op->cpld_reset_led(mac_cb);
 }
 
 /**
@@ -804,7 +804,7 @@ int hns_mac_get_cfg(struct dsaf_device *dsaf_dev, struct 
hns_mac_cb *mac_cb)
else
mac_cb->mac_type = HNAE_PORT_DEBUG;
 
-   mac_cb->phy_if = hns_mac_get_phy_if(mac_cb);
+   mac_cb->phy_if = dsaf_dev->misc_op->get_phy_if(mac_cb);
 
ret = hns_mac_get_mode(mac_cb->phy_if);
if (ret < 0) {
@@ -819,7 +819,7 @@ int hns_mac_get_cfg(struct dsaf_device *dsaf_dev, struct 
hns_mac_cb *mac_cb)
if (ret)
return ret;
 
-   cpld_led_reset(mac_cb);
+   mac_cb->dsaf_dev->misc_op->cpld_reset_led(mac_cb);
mac_cb->vaddr = hns_mac_get_vaddr(dsaf_dev, mac_cb, mac_mode_idx);
 
return 0;
@@ -906,7 +906,7 @@ void hns_mac_uninit(struct dsaf_device *dsaf_dev)
int max_port_num = hns_mac_get_max_port_num(dsaf_dev);
 
for (i = 0; i < max_port_num; i++) {
-   cpld_led_reset(dsaf_dev->mac_cb[i]);
+   dsaf_d

[PATCH v4 net-next 08/13] net: hns: add uniform interface for phy connection

2016-06-02 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

As device_node is only used by DT case, HNS needs to treat the other
cases including ACPI. It needs to use uniform ways to handle both of
DT and ACPI. This patch chooses phy_device, and of_phy_connect and
of_phy_attach are only used by DT case. It needs to use uniform interface
to handle that sequence by both DT and ACPI.

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
change log:
 v2:
  1. remove the redundant functions, and
  2. adds fwnode match method beside DT and ACPI.

 v1: first submit
  link: https://lkml.org/lkml/2016/5/13/100
---
 drivers/net/ethernet/hisilicon/hns/hnae.c  |  8 -
 drivers/net/ethernet/hisilicon/hns/hnae.h  |  3 +-
 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  | 21 +++--
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   |  2 +-
 8 files changed, 49 insertions(+), 25 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.c 
b/drivers/net/ethernet/hisilicon/hns/hnae.c
index d630acd..5d3047c 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.c
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.c
@@ -96,7 +96,13 @@ static int __ae_match(struct device *dev, const void *data)
 {
struct hnae_ae_dev *hdev = cls_to_ae_dev(dev);
 
-   return (data == >dev->of_node->fwnode);
+   if (dev_of_node(hdev->dev))
+   return (data == >dev->of_node->fwnode);
+   else if (is_acpi_node(hdev->dev->fwnode))
+   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 fwnode_handle *fwnode)
diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.h 
b/drivers/net/ethernet/hisilicon/hns/hnae.h
index f5f8140..529cb13 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 
 #include 
 #include 
 #include 
@@ -512,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 
 #include 
 #include 
-#include 
+#include 
+#include 
 #include 
 
 #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(_cb->phy_dev->

[PATCH v4 net-next 00/13] net: hns: add support of ACPI

2016-06-02 Thread Yisen Zhuang
From: Kejian Yan 

This series adds HNS support of acpi. The routine will call some ACPI
helper functions, like acpi_dev_found() 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. And we use device property functions instead
of serial helper functions to suport both DT and ACPI cases. And then
add the supports of ACPI for HNS.

change log:
 v3->v4:
  mii-id gets from dev-name instead of address

 v2->v3:
 1. add Review-by: Andy Shevchenko
 2. fix the potential memory leak

 v1 -> v2:
 1. use acpi_dev_found() instead of acpi_match_device_ids() to check if
it is a acpi node.
 2. use is_of_node() instead of IS_ENABLED() to check if it is a DT node.
 3. split the patch("add support of acpi for hns-mdio") into two patches:
3.1 Move to use fwnode_handle
3.2 Add ACPI
 4. add the patch which subject is dsaf misc operation method
 5. fix the comments by Andy Shevchenko

Kejian Yan (13):
  ACPI: bus: add stub acpi_dev_found() to linux/acpi.h
  ACPI: bus: add stub acpi_evaluate_dsm() to linux/acpi.h
  net: hisilicon: cleanup to prepare for other cases
  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: add dsaf misc operation method
  net: hns: dsaf adds support of acpi
  net: hns: register phy device in each mac initial sequence
  net: hns: implement the miscellaneous operation by asl
  net: hns: 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  |   6 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c |   6 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 247 +++-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h  |   4 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 105 ++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h |  33 ++-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 250 ++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.h |   7 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c  |  15 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c  |   5 +-
 .../net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c|  10 +-
 drivers/net/ethernet/hisilicon/hns/hns_enet.c  |  90 +---
 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  | 150 +++--
 include/linux/acpi.h   |  13 ++
 18 files changed, 706 insertions(+), 262 deletions(-)

-- 
1.9.1



[PATCH v4 net-next 01/13] ACPI: bus: add stub acpi_dev_found() to linux/acpi.h

2016-06-02 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

acpi_dev_found() will be used to detect if a given ACPI device is in the
system. 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 <r...@rjwysocki.net>
Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 include/linux/acpi.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 288fac5..3025d19 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -543,6 +543,11 @@ struct platform_device *acpi_create_platform_device(struct 
acpi_device *);
 
 struct fwnode_handle;
 
+static inline bool acpi_dev_found(const char *hid)
+{
+   return false;
+}
+
 static inline bool is_acpi_node(struct fwnode_handle *fwnode)
 {
return false;
-- 
1.9.1



[PATCH v4 net-next 12/13] net: hns: implement the miscellaneous operation by asl

2016-06-02 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

The miscellaneous operation 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 <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
change log:
 v2: use a serial function to implement the reset sequence

 v1: first submit
  link: https://lkml.org/lkml/2016/5/13/94
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 167 +
 1 file changed, 167 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
index f21177b..96cb628 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 @@ static 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, );
+   if (!obj) {
+   dev_warn(dsaf_dev->dev, "reset port_type%d port%d fail!",
+port_type, port);
+   return;
+   }
+
+   ACPI_FREE(obj);
+}
+
 static void hns_dsaf_rst(struct dsaf_device *dsaf_dev, bool dereset)
 {
u32 xbar_reg_addr;
@@ -126,6 +175,13 @@ static void hns_dsaf_rst(struct dsaf_device *dsaf_dev, 
bool dereset)
dsaf_write_sub(dsaf_dev, nt_reg_addr, RESET_REQ_OR_DREQ);
 }
 
+static void hns_dsaf_rst_acpi(struct dsaf_device *dsaf_dev, bool dereset)
+{
+   hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
+  HNS_DSAF_RESET_FUNC,
+  0, dereset);
+}
+
 static void hns_dsaf_xge_srst_by_port(struct dsaf_device *dsaf_dev, u32 port,
  bool dereset)
 {
@@ -146,6 +202,13 @@ static void hns_dsaf_xge_srst_by_port(struct dsaf_device 
*dsaf_dev, u32 port,
dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
 }
 
+static void hns_dsaf_xge_srst_by_port_acpi(struct dsaf_device *dsaf_dev,
+  u32 port, bool dereset)
+{
+   hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
+  HNS_XGE_RESET_FUNC, port, dereset);
+}
+
 static void hns_dsaf_xge_core_srst_by_port(struct dsaf_device *dsaf_dev,
   u32 port, bool dereset)
 {
@@ -166,6 +229,14 @@ static void hns_dsaf_xge_core_srst_by_port(struct 
dsaf_device *dsaf_dev,
dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
 }
 
+static void
+hns_dsaf_xge_core_srst_by_port_acpi(struct dsaf_device *dsaf_dev,
+   u32 port, bool dereset)
+{
+   hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
+  HNS_XGE_CORE_RESET_FUNC, port, dereset);
+}
+
 static void hns_dsaf_ge_srst_by_port(struct dsaf_device *dsaf_dev, u32 port,
 bool dereset)
 {
@@ -218,6 +289,13 @@ static void hns_dsaf_ge_srst_by_port(struct dsaf_device 
*dsaf_dev, u32 port,
}
 }
 
+static void hns_dsaf_ge_srst_by_port_acpi(struct dsaf_device *dsaf_dev,
+ u32 port, bool dereset)
+{
+   hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
+  HNS_GE_RESET_FUNC, port, dereset);

[PATCH v4 net-next 04/13] net: hisilicon: add support of acpi for hns-mdio

2016-06-02 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

hns-mdio needs to register itself to mii-bus. The info of the device can
be read by both DT 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 _RST method in DSDT in ACPI
case.

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
change log:
 v2:
1. use dev_of_node instead of IS_ENABLED macro
2. Add ACPI bits
 v1: first submit
Link: https://lkml.org/lkml/2016/5/13/93
---
 drivers/net/ethernet/hisilicon/hns_mdio.c | 106 +++---
 1 file changed, 69 insertions(+), 37 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c 
b/drivers/net/ethernet/hisilicon/hns_mdio.c
index 297edc4..761a32f 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 
 #include 
 #include 
 #include 
@@ -354,48 +355,60 @@ static int hns_mdio_reset(struct mii_bus *bus)
struct hns_mdio_device *mdio_dev = (struct hns_mdio_device *)bus->priv;
int ret;
 
-   if (!dev_of_node(bus->parent))
-   return -ENOTSUPP;
+   if (dev_of_node(bus->parent)) {
+   if (!mdio_dev->subctrl_vbase) {
+   dev_err(>dev, "mdio sys ctl reg has not maped\n");
+   return -ENODEV;
+   }
 
-   if (!mdio_dev->subctrl_vbase) {
-   dev_err(>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(>dev, "MDIO reset 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(>dev, "MDIO reset 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(>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(>dev, "MDIO dis clk 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(>dev, "MDIO dis clk 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(>dev, "MDIO dis clk fail\n");
- 

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

2016-06-02 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

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

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
change log:
 v4:
  mii-id gets from dev_name instead of address

 v3:
  first submit
  Link: https://lkml.org/lkml/2016/5/30/298
---
 drivers/net/ethernet/hisilicon/hns_mdio.c | 48 ---
 1 file changed, 18 insertions(+), 30 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c 
b/drivers/net/ethernet/hisilicon/hns_mdio.c
index 765ddb3..297edc4 100644
--- a/drivers/net/ethernet/hisilicon/hns_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns_mdio.c
@@ -354,6 +354,9 @@ static int hns_mdio_reset(struct mii_bus *bus)
struct hns_mdio_device *mdio_dev = (struct hns_mdio_device *)bus->priv;
int ret;
 
+   if (!dev_of_node(bus->parent))
+   return -ENOTSUPP;
+
if (!mdio_dev->subctrl_vbase) {
dev_err(>dev, "mdio sys ctl reg has not maped\n");
return -ENODEV;
@@ -397,24 +400,6 @@ static int hns_mdio_reset(struct mii_bus *bus)
 }
 
 /**
- * hns_mdio_bus_name - get mdio bus name
- * @name: mdio bus name
- * @np: mdio device node pointer
- */
-static void hns_mdio_bus_name(char *name, struct device_node *np)
-{
-   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);
-}
-
-/**
  * hns_mdio_probe - probe mdio device
  * @pdev: mdio platform device
  *
@@ -422,17 +407,16 @@ static void hns_mdio_bus_name(char *name, struct 
device_node *np)
  */
 static int hns_mdio_probe(struct platform_device *pdev)
 {
-   struct device_node *np;
struct hns_mdio_device *mdio_dev;
struct mii_bus *new_bus;
struct resource *res;
-   int ret;
+   int ret = -ENODEV;
 
if (!pdev) {
dev_err(NULL, "pdev is NULL!\r\n");
return -ENODEV;
}
-   np = pdev->dev.of_node;
+
mdio_dev = devm_kzalloc(>dev, sizeof(*mdio_dev), GFP_KERNEL);
if (!mdio_dev)
return -ENOMEM;
@@ -448,7 +432,7 @@ static int hns_mdio_probe(struct platform_device *pdev)
new_bus->write = hns_mdio_write;
new_bus->reset = hns_mdio_reset;
new_bus->priv = mdio_dev;
-   hns_mdio_bus_name(new_bus->id, np);
+   new_bus->parent = >dev;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
mdio_dev->vbase = devm_ioremap_resource(>dev, res);
@@ -457,16 +441,20 @@ static int hns_mdio_probe(struct platform_device *pdev)
return ret;
}
 
-   mdio_dev->subctrl_vbase =
-   syscon_node_to_regmap(of_parse_phandle(np, "subctrl-vbase", 0));
-   if (IS_ERR(mdio_dev->subctrl_vbase)) {
-   dev_warn(>dev, "no syscon hisilicon,peri-c-subctrl\n");
-   mdio_dev->subctrl_vbase = NULL;
-   }
-   new_bus->parent = >dev;
platform_set_drvdata(pdev, new_bus);
+   snprintf(new_bus->id, MII_BUS_ID_SIZE, "%s-%s", "Mii",
+dev_name(>dev));
+   if (dev_of_node(>dev)) {
+   mdio_dev->subctrl_vbase = syscon_node_to_regmap(
+   of_parse_phandle(pdev->dev.of_node,
+"subctrl-vbase", 0));
+   if (IS_ERR(mdio_dev->subctrl_vbase)) {
+   dev_warn(>dev, "no syscon 
hisilicon,peri-c-subctrl\n");
+   mdio_dev->subctrl_vbase = NULL;
+   }
+   ret = of_mdiobus_register(new_bus, pdev->dev.of_node);
+   }
 
-   ret = of_mdiobus_register(new_bus, np);
if (ret) {
dev_err(>dev, "Cannot register as MDIO bus!\n");
platform_set_drvdata(pdev, NULL);
-- 
1.9.1



[PATCH v4 net-next 07/13] net: hns: enet specify a reference to dsaf by fwnode_handle

2016-06-02 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

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

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
change log:
 v2: remove the redundant line

 v1: first submit
 link: https://lkml.org/lkml/2016/5/13/98
---
 drivers/net/ethernet/hisilicon/hns/hnae.c | 12 ++--
 drivers/net/ethernet/hisilicon/hns/hnae.h |  2 +-
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 14 --
 drivers/net/ethernet/hisilicon/hns/hns_enet.h |  2 +-
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.c 
b/drivers/net/ethernet/hisilicon/hns/hnae.c
index 3bfe36f..d630acd 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.c
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.c
@@ -96,16 +96,16 @@ 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;
+   return (data == >dev->of_node->fwnode);
 }
 
-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 +312,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 +321,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..f5f8140 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.h
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.h
@@ -528,7 +528,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..93f6ccb 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(>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 = >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,17 +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;
}
+   priv->fwnode = _node->fwnode;
+
/* try to find port-idx-in-ae first */
ret = device_property_read_u32(dev, "port-idx-in-ae", _id);
if (ret) {
diff --git a/drivers/net/ethern

[PATCH v4 net-next 13/13] net: hns: net: hns: enet adds support of acpi

2016-06-02 Thread Yisen Zhuang
From: Kejian Yan <yankej...@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 <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
change log:
 v2:
 1. use acpi_dev_found() instead of acpi_match_device_ids()
 2. use is_acpi_node() to check if it works by ACPI case
 3. use dev_of_node() to check if it works by DT case

 v1: first submit
  link: https://lkml.org/lkml/2016/5/13/99
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 56 +--
 1 file changed, 44 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index 3ec3c27..ad742a6 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)
@@ -1870,7 +1877,6 @@ static int hns_nic_dev_probe(struct platform_device *pdev)
struct device *dev = >dev;
struct net_device *ndev;
struct hns_nic_priv *priv;
-   struct device_node *ae_node;
u32 port_id;
int ret;
 
@@ -1884,20 +1890,45 @@ 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 (dev_of_node(dev)) {
+   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;
+   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 = _node->fwnode;
+   } else if (is_acpi_node(dev->fwnode)) {
+   struct acpi_reference_args args;
+
+   if (acpi_dev_found(hns_enet_acpi_match[0].id))
+   priv->enet_ver = AE_VERSION_1;
+   else if (acpi_dev_found(hns_enet_acpi_match[1].id))
+   priv->enet_ver = AE_VERSION_2;
+   else
+   return -ENXIO;
+
+   /* try to find port-idx-in-ae first */
+   ret = acpi_node_get_property_reference(dev->fwnode,
+  "ae-handle", 0, );
+   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;
}
-   priv->fwnode = _node->fwnode;
 
-   /* try to find port-idx-in-ae first */
ret = device_property_read_u32(dev, "port-idx-in-ae", _id);
if (ret) {
/* only for old code compatible */
@@ -2014,6 +2045,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



[PATCH v4 net-next 10/13] net: hns: dsaf adds support of acpi

2016-06-02 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

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

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
change log:
 v2:
  1. use dev_of_node() instead of IS_ENABLED() to check if it is in
DT case,
  2. split a new patch to implement misc operation method,
  3. use acpi_dev_found() instead of acpi_match_device_ids() to
check which hw version it is,
  4. use is_acpi_node instead of ACPI_COMPANION to check if it is
work in ACPI case.

 v1: first submit
  link: https://lkml.org/lkml/2016/5/13/108
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 80 ++--
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 85 +++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 32 
 3 files changed, 114 insertions(+), 83 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 2ebf14a..3ef0c9b 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",
-  _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",
-  _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",
+  _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, _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",
+  _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_n

[PATCH v4 net-next 11/13] net: hns: register phy device in each mac initial sequence

2016-06-02 Thread Yisen Zhuang
From: Kejian Yan <yankej...@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 <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
change log:
 v2: fix the build error by kbuild test robot

 v1: first submit
  link: https://lkml.org/lkml/2016/5/13/97
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 133 --
 1 file changed, 126 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 3ef0c9b..c526558 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 
 #include 
 #include 
 #include 
@@ -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", );
+   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(_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", _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(>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, );
+   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_reg

[PATCH v4 net-next 02/13] ACPI: bus: add stub acpi_evaluate_dsm() to linux/acpi.h

2016-06-02 Thread Yisen Zhuang
From: Kejian Yan <yankej...@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 <r...@rjwysocki.net>
Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@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 3025d19..4d4bb49 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -659,6 +659,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



[PATCH v4 net-next 05/13] net: hns: use device_* APIs instead of of_* APIs

2016-06-02 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

OF series functions can be used only for DT case. Use unified
device property function instead to support both DT and ACPI.

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@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", _str);
+   ret = device_property_read_string(dsaf_dev->dev, "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", _num);
+   ret = device_property_read_u32(dsaf_dev->dev, "desc-num", _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", _offset);
+   ret = device_property_read_u32(dsaf_dev->dev, "reset-field-offset",
+  _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", _size);
+   ret = device_property_read_u32(dsaf_dev->dev, "buf-size", _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", _id);
+   ret = device_property_read_u32(dev, "port-idx-in-ae", _id);
if (ret) {
/* only for old code compatible */
-   ret = of_property_read_u32(node, "port-id", _id);
+   ret = device_property_read_u32(dev, "port-id", _id);
if (ret)
goto out_read_prop_fail;
/* for old dts, we need to caculate the port offset */
-- 
1.9.1



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

2016-06-02 Thread Yisen Zhuang
Hi David,

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

Thanks,

Yisen

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



[PATCH v3 net-next 10/13] net: hns: dsaf adds support of acpi

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

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

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Reviewed-by: Andy Shevchenko <andriy.shevche...@linux.intel.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
change log:
 v3:
  add Reviewed-by: Andy Shevchenko

 v2:
  1. use dev_of_node() instead of IS_ENABLED() to check if it is in
DT case,
  2. split a new patch to implement misc operation method,
  3. use acpi_dev_found() instead of acpi_match_device_ids() to
check which hw version it is,
  4. use is_acpi_node instead of ACPI_COMPANION to check if it is
work in ACPI case.
  link: https://lkml.org/lkml/2016/5/29/181

 v1: first submit
  link: https://lkml.org/lkml/2016/5/13/108
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 80 ++--
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 85 +++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 32 
 3 files changed, 114 insertions(+), 83 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 2ebf14a..3ef0c9b 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",
-  _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",
-  _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",
+  _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, _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",
+  _cb->port_mode_off);
+   if (ret) {
+   dev_dbg(mac_cb->dev,
+   "mac%d port-mode-offset not found, use default 
value.\n",
+

[PATCH v3 net-next 00/13] net: hns: add support of ACPI

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

This series adds HNS support of acpi. The routine will call some ACPI
helper functions, like acpi_dev_found() 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. And we use device property functions instead
of serial helper functions to suport both DT and ACPI cases. And then
add the supports of ACPI for HNS.

change log:
 v2->v3:
 1. add Review-by: Andy Shevchenko
 2. fix the potential memory leak

 v1 -> v2:
 1. use acpi_dev_found() instead of acpi_match_device_ids() to check if
it is a acpi node.
 2. use is_of_node() instead of IS_ENABLED() to check if it is a DT node.
 3. split the patch("add support of acpi for hns-mdio") into two patches:
3.1 Move to use fwnode_handle
3.2 Add ACPI
 4. add the patch which subject is dsaf misc operation method
 5. fix the comments by Andy Shevchenko

Kejian Yan (13):
  ACPI: bus: add stub acpi_dev_found() to linux/acpi.h
  ACPI: bus: add stub acpi_evaluate_dsm() to linux/acpi.h
  net: hisilicon: cleanup to prepare for other cases
  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: add dsaf misc operation method
  net: hns: dsaf adds support of acpi
  net: hns: register phy device in each mac initial sequence
  net: hns: implement the miscellaneous operation by asl
  net: hns: 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  |   6 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c |   6 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 247 +++-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h  |   4 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 105 ++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h |  33 ++-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 254 ++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.h |   7 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c  |  15 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c  |   5 +-
 .../net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c|  10 +-
 drivers/net/ethernet/hisilicon/hns/hns_enet.c  |  90 +---
 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  | 147 +++-
 include/linux/acpi.h   |  13 ++
 18 files changed, 714 insertions(+), 255 deletions(-)

-- 
1.9.1



[PATCH v3 net-next 01/13] ACPI: bus: add stub acpi_dev_found() to linux/acpi.h

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

acpi_dev_found() will be used to detect if a given ACPI device is in the
system. 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 <r...@rjwysocki.net>
Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 include/linux/acpi.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 288fac5..3025d19 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -543,6 +543,11 @@ struct platform_device *acpi_create_platform_device(struct 
acpi_device *);
 
 struct fwnode_handle;
 
+static inline bool acpi_dev_found(const char *hid)
+{
+   return false;
+}
+
 static inline bool is_acpi_node(struct fwnode_handle *fwnode)
 {
return false;
-- 
1.9.1



[PATCH v3 net-next 08/13] net: hns: add uniform interface for phy connection

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

As device_node is only used by DT case, HNS needs to treat the other
cases including ACPI. It needs to use uniform ways to handle both of
DT and ACPI. This patch chooses phy_device, and of_phy_connect and
of_phy_attach are only used by DT case. It needs to use uniform interface
to handle that sequence by both DT and ACPI.

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Reviewed-by: Andy Shevchenko <andriy.shevche...@linux.intel.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
change log:
 v3:
   add Reviewed-by: Andy Shevchenko

 v2:
  1. remove the redundant functions, and
  2. adds fwnode match method beside DT and ACPI.
  link: https://lkml.org/lkml/2016/5/29/175

 v1: first submit
  link: https://lkml.org/lkml/2016/5/13/100
---
 drivers/net/ethernet/hisilicon/hns/hnae.c  |  8 -
 drivers/net/ethernet/hisilicon/hns/hnae.h  |  3 +-
 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  | 21 +++--
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   |  2 +-
 8 files changed, 49 insertions(+), 25 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.c 
b/drivers/net/ethernet/hisilicon/hns/hnae.c
index d630acd..5d3047c 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.c
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.c
@@ -96,7 +96,13 @@ static int __ae_match(struct device *dev, const void *data)
 {
struct hnae_ae_dev *hdev = cls_to_ae_dev(dev);
 
-   return (data == >dev->of_node->fwnode);
+   if (dev_of_node(hdev->dev))
+   return (data == >dev->of_node->fwnode);
+   else if (is_acpi_node(hdev->dev->fwnode))
+   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 fwnode_handle *fwnode)
diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.h 
b/drivers/net/ethernet/hisilicon/hns/hnae.h
index f5f8140..529cb13 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 
 #include 
 #include 
 #include 
@@ -512,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 
 #include 
 #include 
-#include 
+#include 
+#include 
 #include 
 
 #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

[PATCH v3 net-next 02/13] ACPI: bus: add stub acpi_evaluate_dsm() to linux/acpi.h

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan <yankej...@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 <r...@rjwysocki.net>
Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@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 3025d19..4d4bb49 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -659,6 +659,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



[PATCH v3 net-next 06/13] net: hns: use platform_get_irq instead of irq_of_parse_and_map

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

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

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@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



[PATCH v3 net-next 04/13] net: hisilicon: add support of acpi for hns-mdio

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

hns-mdio needs to register itself to mii-bus. The info of the device can
be read by both DT 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 _RST method in DSDT in ACPI
case.

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Reviewed-by: Andy Shevchenko <andriy.shevche...@linux.intel.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
change log:
 v3:
add Reviewed-by: Andy Shevchenko
 v2:
1. use dev_of_node instead of IS_ENABLED macro
2. Add ACPI bits
Link: https://lkml.org/lkml/2016/5/29/185

 v1: first submit
Link: https://lkml.org/lkml/2016/5/13/93
---
 drivers/net/ethernet/hisilicon/hns_mdio.c | 107 +++---
 1 file changed, 69 insertions(+), 38 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c 
b/drivers/net/ethernet/hisilicon/hns_mdio.c
index 381cf0a..f78286c 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 
 #include 
 #include 
 #include 
@@ -354,48 +355,60 @@ static int hns_mdio_reset(struct mii_bus *bus)
struct hns_mdio_device *mdio_dev = (struct hns_mdio_device *)bus->priv;
int ret;
 
-   if (!dev_of_node(bus->parent))
-   return -ENOTSUPP;
+   if (dev_of_node(bus->parent)) {
+   if (!mdio_dev->subctrl_vbase) {
+   dev_err(>dev, "mdio sys ctl reg has not maped\n");
+   return -ENODEV;
+   }
 
-   if (!mdio_dev->subctrl_vbase) {
-   dev_err(>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(>dev, "MDIO reset 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(>dev, "MDIO reset 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(>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(>dev, "MDIO dis clk 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(>dev, "MDIO dis clk 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,
-

[PATCH v3 net-next 11/13] net: hns: register phy device in each mac initial sequence

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan <yankej...@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 <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
change log:
 v2: fix the build error by kbuild test robot

 v1: first submit
  link: https://lkml.org/lkml/2016/5/13/97
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 133 --
 1 file changed, 126 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 3ef0c9b..c526558 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 
 #include 
 #include 
 #include 
@@ -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", );
+   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(_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", _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(>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, );
+   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_reg

[PATCH v3 net-next 05/13] net: hns: use device_* APIs instead of of_* APIs

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

OF series functions can be used only for DT case. Use unified
device property function instead to support both DT and ACPI.

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@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", _str);
+   ret = device_property_read_string(dsaf_dev->dev, "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", _num);
+   ret = device_property_read_u32(dsaf_dev->dev, "desc-num", _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", _offset);
+   ret = device_property_read_u32(dsaf_dev->dev, "reset-field-offset",
+  _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", _size);
+   ret = device_property_read_u32(dsaf_dev->dev, "buf-size", _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", _id);
+   ret = device_property_read_u32(dev, "port-idx-in-ae", _id);
if (ret) {
/* only for old code compatible */
-   ret = of_property_read_u32(node, "port-id", _id);
+   ret = device_property_read_u32(dev, "port-id", _id);
if (ret)
goto out_read_prop_fail;
/* for old dts, we need to caculate the port offset */
-- 
1.9.1



[PATCH v3 net-next 13/13] net: hns: net: hns: enet adds support of acpi

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan <yankej...@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 <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
change log:
 v2:
 1. use acpi_dev_found() instead of acpi_match_device_ids()
 2. use is_acpi_node() to check if it works by ACPI case
 3. use dev_of_node() to check if it works by DT case

 v1: first submit
  link: https://lkml.org/lkml/2016/5/13/99
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 56 +--
 1 file changed, 44 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index 3ec3c27..ad742a6 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)
@@ -1870,7 +1877,6 @@ static int hns_nic_dev_probe(struct platform_device *pdev)
struct device *dev = >dev;
struct net_device *ndev;
struct hns_nic_priv *priv;
-   struct device_node *ae_node;
u32 port_id;
int ret;
 
@@ -1884,20 +1890,45 @@ 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 (dev_of_node(dev)) {
+   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;
+   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 = _node->fwnode;
+   } else if (is_acpi_node(dev->fwnode)) {
+   struct acpi_reference_args args;
+
+   if (acpi_dev_found(hns_enet_acpi_match[0].id))
+   priv->enet_ver = AE_VERSION_1;
+   else if (acpi_dev_found(hns_enet_acpi_match[1].id))
+   priv->enet_ver = AE_VERSION_2;
+   else
+   return -ENXIO;
+
+   /* try to find port-idx-in-ae first */
+   ret = acpi_node_get_property_reference(dev->fwnode,
+  "ae-handle", 0, );
+   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;
}
-   priv->fwnode = _node->fwnode;
 
-   /* try to find port-idx-in-ae first */
ret = device_property_read_u32(dev, "port-idx-in-ae", _id);
if (ret) {
/* only for old code compatible */
@@ -2014,6 +2045,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



[PATCH v3 net-next 07/13] net: hns: enet specify a reference to dsaf by fwnode_handle

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

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

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Reviewed-by: Andy Shevchenko <andriy.shevche...@linux.intel.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
change log:
 v3: add Reviewed-by: Andy Shevchenko

 v2: remove the redundant line
  Link: https://lkml.org/lkml/2016/5/29/178

 v1: first submit
 link: https://lkml.org/lkml/2016/5/13/98
---
 drivers/net/ethernet/hisilicon/hns/hnae.c | 12 ++--
 drivers/net/ethernet/hisilicon/hns/hnae.h |  2 +-
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 14 --
 drivers/net/ethernet/hisilicon/hns/hns_enet.h |  2 +-
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.c 
b/drivers/net/ethernet/hisilicon/hns/hnae.c
index 3bfe36f..d630acd 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.c
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.c
@@ -96,16 +96,16 @@ 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;
+   return (data == >dev->of_node->fwnode);
 }
 
-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 +312,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 +321,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..f5f8140 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.h
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.h
@@ -528,7 +528,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..93f6ccb 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(>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 = >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,17 +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;
}
+   priv->fwnode = _node->fwnode;
+
/* tr

[PATCH v3 net-next 12/13] net: hns: implement the miscellaneous operation by asl

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

The miscellaneous operation 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 <yankej...@huawei.com>
Reviewed-by: Andy Shevchenko <andriy.shevche...@linux.intel.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
change log:
 v3: fix potential memory leak
 add Reviewed-by: Andy Shevchenko

 v2: use a serial function to implement the reset sequence
  link: https://lkml.org/lkml/2016/5/29/186

 v1: first submit
  link: https://lkml.org/lkml/2016/5/13/94
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 171 +
 1 file changed, 171 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c
index f21177b..6a75d81 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 @@ static 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, );
+   if (!obj) {
+   dev_warn(dsaf_dev->dev, "reset port_type%d port%d fail!",
+port_type, port);
+   return;
+   }
+
+   ACPI_FREE(obj);
+}
+
 static void hns_dsaf_rst(struct dsaf_device *dsaf_dev, bool dereset)
 {
u32 xbar_reg_addr;
@@ -126,6 +175,13 @@ static void hns_dsaf_rst(struct dsaf_device *dsaf_dev, 
bool dereset)
dsaf_write_sub(dsaf_dev, nt_reg_addr, RESET_REQ_OR_DREQ);
 }
 
+static void hns_dsaf_rst_acpi(struct dsaf_device *dsaf_dev, bool dereset)
+{
+   hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
+  HNS_DSAF_RESET_FUNC,
+  0, dereset);
+}
+
 static void hns_dsaf_xge_srst_by_port(struct dsaf_device *dsaf_dev, u32 port,
  bool dereset)
 {
@@ -146,6 +202,13 @@ static void hns_dsaf_xge_srst_by_port(struct dsaf_device 
*dsaf_dev, u32 port,
dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
 }
 
+static void hns_dsaf_xge_srst_by_port_acpi(struct dsaf_device *dsaf_dev,
+  u32 port, bool dereset)
+{
+   hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
+  HNS_XGE_RESET_FUNC, port, dereset);
+}
+
 static void hns_dsaf_xge_core_srst_by_port(struct dsaf_device *dsaf_dev,
   u32 port, bool dereset)
 {
@@ -166,6 +229,14 @@ static void hns_dsaf_xge_core_srst_by_port(struct 
dsaf_device *dsaf_dev,
dsaf_write_sub(dsaf_dev, reg_addr, reg_val);
 }
 
+static void
+hns_dsaf_xge_core_srst_by_port_acpi(struct dsaf_device *dsaf_dev,
+   u32 port, bool dereset)
+{
+   hns_dsaf_acpi_srst_by_port(dsaf_dev, HNS_OP_RESET_FUNC,
+  HNS_XGE_CORE_RESET_FUNC, port, dereset);
+}
+
 static void hns_dsaf_ge_srst_by_port(struct dsaf_device *dsaf_dev, u32 port,
 bool dereset)
 {
@@ -218,6 +289,13 @@ static void hns_dsaf_ge_srst_by_port(struct dsaf_device 
*dsaf_dev, u32 port,
}
 }
 
+static void hns_dsaf_ge_srst_by_port_acpi(struct dsaf_device *dsaf_dev,
+

[PATCH v3 net-next 09/13] net: hns: add dsaf misc operation method

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

The misc operation for different hw platform may be different, if using
current implementation, it will add a new branch on each function for
every new hw platform, so we add a method for this operation.

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  |  4 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c |  6 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 14 ++--
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h  |  2 -
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 11 ++-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h | 33 ++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.c | 79 +++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_misc.h |  7 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c  | 15 ++--
 .../net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c| 10 +--
 10 files changed, 111 insertions(+), 70 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
index 8e009f4..d37b778 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
@@ -637,13 +637,15 @@ static int hns_ae_config_loopback(struct hnae_handle 
*handle,
int ret;
struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle);
struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
+   struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
 
switch (loop) {
case MAC_INTERNALLOOP_PHY:
ret = 0;
break;
case MAC_INTERNALLOOP_SERDES:
-   ret = hns_mac_config_sds_loopback(vf_cb->mac_cb, en);
+   ret = dsaf_dev->misc_op->cfg_serdes_loopback(vf_cb->mac_cb,
+!!en);
break;
case MAC_INTERNALLOOP_MAC:
ret = hns_mac_config_mac_loopback(vf_cb->mac_cb, loop, en);
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
index 44abb08..1235c7f 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
@@ -110,7 +110,7 @@ static void hns_gmac_free(void *mac_drv)
 
u32 mac_id = drv->mac_id;
 
-   hns_dsaf_ge_srst_by_port(dsaf_dev, mac_id, 0);
+   dsaf_dev->misc_op->ge_srst(dsaf_dev, mac_id, 0);
 }
 
 static void hns_gmac_set_tx_auto_pause_frames(void *mac_drv, u16 newval)
@@ -317,9 +317,9 @@ static void hns_gmac_init(void *mac_drv)
 
port = drv->mac_id;
 
-   hns_dsaf_ge_srst_by_port(dsaf_dev, port, 0);
+   dsaf_dev->misc_op->ge_srst(dsaf_dev, port, 0);
mdelay(10);
-   hns_dsaf_ge_srst_by_port(dsaf_dev, port, 1);
+   dsaf_dev->misc_op->ge_srst(dsaf_dev, port, 1);
mdelay(10);
hns_gmac_disable(mac_drv, MAC_COMM_MODE_RX_AND_TX);
hns_gmac_tx_loop_pkt_dis(mac_drv);
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 527b49d..2ebf14a 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -95,7 +95,7 @@ void hns_mac_get_link_status(struct hns_mac_cb *mac_cb, u32 
*link_status)
else
*link_status = 0;
 
-   ret = hns_mac_get_sfp_prsnt(mac_cb, _prsnt);
+   ret = mac_cb->dsaf_dev->misc_op->get_sfp_prsnt(mac_cb, _prsnt);
if (!ret)
*link_status = *link_status && sfp_prsnt;
 
@@ -512,7 +512,7 @@ void hns_mac_stop(struct hns_mac_cb *mac_cb)
 
mac_ctrl_drv->mac_en_flg = 0;
mac_cb->link = 0;
-   cpld_led_reset(mac_cb);
+   mac_cb->dsaf_dev->misc_op->cpld_reset_led(mac_cb);
 }
 
 /**
@@ -804,7 +804,7 @@ int hns_mac_get_cfg(struct dsaf_device *dsaf_dev, struct 
hns_mac_cb *mac_cb)
else
mac_cb->mac_type = HNAE_PORT_DEBUG;
 
-   mac_cb->phy_if = hns_mac_get_phy_if(mac_cb);
+   mac_cb->phy_if = dsaf_dev->misc_op->get_phy_if(mac_cb);
 
ret = hns_mac_get_mode(mac_cb->phy_if);
if (ret < 0) {
@@ -819,7 +819,7 @@ int hns_mac_get_cfg(struct dsaf_device *dsaf_dev, struct 
hns_mac_cb *mac_cb)
if (ret)
return ret;
 
-   cpld_led_reset(mac_cb);
+   mac_cb->dsaf_dev->misc_op->cpld_reset_led(mac_cb);
mac_cb->vaddr = hns_mac_get_vaddr(dsaf_dev, mac_cb, mac_mode_idx);
 
return 0;
@@ -906,7 +906,7 @@ void hns_mac_uninit(struct dsaf_device *dsaf_dev)
int max_port_num = hns_mac_get_max_port_num(dsaf_dev);
 
for (i = 0; i < max_port_num; i++) {
-   cpld_led_reset(dsaf_dev->mac_cb[i]);
+   dsaf_d

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

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

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

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns_mdio.c | 46 +++
 1 file changed, 23 insertions(+), 23 deletions(-)

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



Re: [PATCH 1/1] net: hns: avoid null pointer dereference

2016-05-17 Thread Yisen Zhuang
Hi Heinrich,

This patch is fine to me.

Thanks,

Yisen

在 2016/5/18 4:01, Heinrich Schuchardt 写道:
> In the statement
>   assert(priv || priv->ae_handle);
> the right side of || is only evaluated if priv is null.
> 
> Signed-off-by: Heinrich Schuchardt 
> ---
>  drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c 
> b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> index 3d746c8..834a50a 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> @@ -720,7 +720,7 @@ static int hns_set_pauseparam(struct net_device *net_dev,
>   struct hnae_handle *h;
>   struct hnae_ae_ops *ops;
>  
> - assert(priv || priv->ae_handle);
> + assert(priv && priv->ae_handle);
>  
>   h = priv->ae_handle;
>   ops = h->dev->ops;
> @@ -780,7 +780,7 @@ static int hns_set_coalesce(struct net_device *net_dev,
>   struct hnae_ae_ops *ops;
>   int ret;
>  
> - assert(priv || priv->ae_handle);
> + assert(priv && priv->ae_handle);
>  
>   ops = priv->ae_handle->dev->ops;
>  
> @@ -,7 +,7 @@ void hns_get_regs(struct net_device *net_dev, struct 
> ethtool_regs *cmd,
>   struct hns_nic_priv *priv = netdev_priv(net_dev);
>   struct hnae_ae_ops *ops;
>  
> - assert(priv || priv->ae_handle);
> + assert(priv && priv->ae_handle);
>  
>   ops = priv->ae_handle->dev->ops;
>  
> @@ -1135,7 +1135,7 @@ static int hns_get_regs_len(struct net_device *net_dev)
>   struct hns_nic_priv *priv = netdev_priv(net_dev);
>   struct hnae_ae_ops *ops;
>  
> - assert(priv || priv->ae_handle);
> + assert(priv && priv->ae_handle);
>  
>   ops = priv->ae_handle->dev->ops;
>   if (!ops->get_regs_len) {
> 



[patch net-next 07/11] net: hns: dsaf adds support of acpi

2016-05-13 Thread Yisen Zhuang
From: Kejian Yan <yankej...@huawei.com>

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

Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@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",
-  _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",
-  _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",
+  _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, _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",
+  _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,
+   _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;
-   

[patch net-next 03/11] net: hns: use platform_get_irq instead of irq_of_parse_and_map

2016-05-13 Thread Yisen Zhuang
From: Kejian Yan <yankej...@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 <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@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



[patch net-next 05/11] net: hns: add uniform interface for phy connection

2016-05-13 Thread Yisen Zhuang
From: Kejian Yan <yankej...@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 <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@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 
 #include 
 #include 
-#include 
+#include 
+#include 
 #include 
 
 #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(_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(_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_n

[patch net-next 09/11] ACPI: bus: add stub acpi_evaluate_dsm() to linux/acpi.h

2016-05-13 Thread Yisen Zhuang
From: Kejian Yan <yankej...@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 <r...@rjwysocki.net>
Signed-off-by: Kejian Yan <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@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



[patch net-next 08/11] net: hns: register phy device in each mac initial sequence

2016-05-13 Thread Yisen Zhuang
From: Kejian Yan <yankej...@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 <yankej...@huawei.com>
Signed-off-by: Yisen Zhuang <yisen.zhu...@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 
 #include 
 #include 
 #include 
@@ -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", );
+   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(_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", _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(>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, );
+   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 

  1   2   >