[PATCH net 3/3] net: hns: Fix wrong read accesses via Clause 45 MDIO protocol

2019-01-26 Thread Peng Li
From: Yonglong Liu 

When reading phy registers via Clause 45 MDIO protocol, after write
address operation, the driver use another write address operation, so
can not read the right value of any phy registers. This patch fixes it.

Signed-off-by: Yonglong Liu 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns_mdio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c 
b/drivers/net/ethernet/hisilicon/hns_mdio.c
index 017e084..baf5cc2 100644
--- a/drivers/net/ethernet/hisilicon/hns_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns_mdio.c
@@ -321,7 +321,7 @@ static int hns_mdio_read(struct mii_bus *bus, int phy_id, 
int regnum)
}
 
hns_mdio_cmd_write(mdio_dev, is_c45,
-  MDIO_C45_WRITE_ADDR, phy_id, devad);
+  MDIO_C45_READ, phy_id, devad);
}
 
/* Step 5: waitting for MDIO_COMMAND_REG 's mdio_start==0,*/
-- 
1.9.1



[PATCH net 2/3] net: hns: Restart autoneg need return failed when autoneg off

2019-01-26 Thread Peng Li
From: Yonglong Liu 

The hns driver of earlier devices, when autoneg off, restart autoneg
will return -EINVAL, so make the hns driver for the latest devices
do the same.

Signed-off-by: Yonglong Liu 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
index 8e9b958..ce15d23 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
@@ -1157,16 +1157,18 @@ static int hns_get_regs_len(struct net_device *net_dev)
  */
 static int hns_nic_nway_reset(struct net_device *netdev)
 {
-   int ret = 0;
struct phy_device *phy = netdev->phydev;
 
-   if (netif_running(netdev)) {
-   /* if autoneg is disabled, don't restart auto-negotiation */
-   if (phy && phy->autoneg == AUTONEG_ENABLE)
-   ret = genphy_restart_aneg(phy);
-   }
+   if (!netif_running(netdev))
+   return 0;
 
-   return ret;
+   if (!phy)
+   return -EOPNOTSUPP;
+
+   if (phy->autoneg != AUTONEG_ENABLE)
+   return -EINVAL;
+
+   return genphy_restart_aneg(phy);
 }
 
 static u32
-- 
1.9.1



[PATCH net 1/3] net: hns: Fix for missing of_node_put() after of_parse_phandle()

2019-01-26 Thread Peng Li
From: Yonglong Liu 

In hns enet driver, we use of_parse_handle() to get hold of the
device node related to "ae-handle" but we have missed to put
the node reference using of_node_put() after we are done using
the node. This patch fixes it.

Note:
This problem is stated in Link: https://lkml.org/lkml/2018/12/22/217

Fixes: 48189d6aaf1e ("net: hns: enet specifies a reference to dsaf")
Reported-by: Alexey Khoroshilov 
Signed-off-by: Yonglong Liu 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index 5b33238..60e7d7a 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -2418,6 +2418,8 @@ static int hns_nic_dev_probe(struct platform_device *pdev)
 out_notify_fail:
(void)cancel_work_sync(>service_task);
 out_read_prop_fail:
+   /* safe for ACPI FW */
+   of_node_put(to_of_node(priv->fwnode));
free_netdev(ndev);
return ret;
 }
@@ -2447,6 +2449,9 @@ static int hns_nic_dev_remove(struct platform_device 
*pdev)
set_bit(NIC_STATE_REMOVING, >state);
(void)cancel_work_sync(>service_task);
 
+   /* safe for ACPI FW */
+   of_node_put(to_of_node(priv->fwnode));
+
free_netdev(ndev);
return 0;
 }
-- 
1.9.1



[PATCH net 0/3] net: hns: code optimizations & bugfixes for HNS driver

2019-01-26 Thread Peng Li
This patchset includes bugfixes and code optimizations for the HNS
ethernet controller driver

Yonglong Liu (3):
  net: hns: Fix for missing of_node_put() after of_parse_phandle()
  net: hns: Restart autoneg need return failed when autoneg off
  net: hns: Fix wrong read accesses via Clause 45 MDIO protocol

 drivers/net/ethernet/hisilicon/hns/hns_enet.c|  5 +
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 16 +---
 drivers/net/ethernet/hisilicon/hns_mdio.c|  2 +-
 3 files changed, 15 insertions(+), 8 deletions(-)

-- 
1.9.1



[PATCH net-next 1/9] net: hns3: refine the handle for hns3_nic_net_open/stop()

2018-12-19 Thread Peng Li
From: Jian Shen 

When triggering nic down, there is a time window between bringing down
the protocol stack and stopping the work task. If the net is up in the
time window, it may bring up the protocol stack again.

This patch fixes it by stop the work task at the beginning of
hns3_nic_net_stop(). To keep symmetrical, start the work task at the
end of hns3_nic_net_open().

Signed-off-by: Jian Shen 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  1 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c|  8 
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 22 +++---
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  | 18 ++
 4 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index 845d43d..36eab37 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -461,6 +461,7 @@ struct hnae3_ae_ops {
unsigned long (*ae_dev_reset_cnt)(struct hnae3_handle *handle);
int (*set_gro_en)(struct hnae3_handle *handle, int enable);
u16 (*get_global_queue_id)(struct hnae3_handle *handle, u16 queue_id);
+   void (*set_timer_task)(struct hnae3_handle *handle, bool enable);
 };
 
 struct hnae3_dcb_ops {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index d060029..becbf86 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -379,6 +379,7 @@ static int hns3_nic_net_up(struct net_device *netdev)
 
 static int hns3_nic_net_open(struct net_device *netdev)
 {
+   struct hns3_nic_priv *priv = netdev_priv(netdev);
struct hnae3_handle *h = hns3_get_handle(netdev);
struct hnae3_knic_private_info *kinfo;
int i, ret;
@@ -405,6 +406,9 @@ static int hns3_nic_net_open(struct net_device *netdev)
   kinfo->prio_tc[i]);
}
 
+   if (h->ae_algo->ops->set_timer_task)
+   h->ae_algo->ops->set_timer_task(priv->ae_handle, true);
+
return 0;
 }
 
@@ -437,10 +441,14 @@ static void hns3_nic_net_down(struct net_device *netdev)
 static int hns3_nic_net_stop(struct net_device *netdev)
 {
struct hns3_nic_priv *priv = netdev_priv(netdev);
+   struct hnae3_handle *h = hns3_get_handle(netdev);
 
if (test_and_set_bit(HNS3_NIC_STATE_DOWN, >state))
return 0;
 
+   if (h->ae_algo->ops->set_timer_task)
+   h->ae_algo->ops->set_timer_task(priv->ae_handle, false);
+
netif_tx_stop_all_queues(netdev);
netif_carrier_off(netdev);
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index d0e84de..a12cb14 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -5295,6 +5295,20 @@ static void hclge_reset_tqp_stats(struct hnae3_handle 
*handle)
}
 }
 
+static void hclge_set_timer_task(struct hnae3_handle *handle, bool enable)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+   struct hclge_dev *hdev = vport->back;
+
+   if (enable) {
+   mod_timer(>service_timer, jiffies + HZ);
+   } else {
+   del_timer_sync(>service_timer);
+   cancel_work_sync(>service_task);
+   clear_bit(HCLGE_STATE_SERVICE_SCHED, >state);
+   }
+}
+
 static int hclge_ae_start(struct hnae3_handle *handle)
 {
struct hclge_vport *vport = hclge_get_vport(handle);
@@ -5303,7 +5317,6 @@ static int hclge_ae_start(struct hnae3_handle *handle)
/* mac enable */
hclge_cfg_mac_mode(hdev, true);
clear_bit(HCLGE_STATE_DOWN, >state);
-   mod_timer(>service_timer, jiffies + HZ);
hdev->hw.mac.link = 0;
 
/* reset tqp stats */
@@ -5321,10 +5334,6 @@ static void hclge_ae_stop(struct hnae3_handle *handle)
 
set_bit(HCLGE_STATE_DOWN, >state);
 
-   del_timer_sync(>service_timer);
-   cancel_work_sync(>service_task);
-   clear_bit(HCLGE_STATE_SERVICE_SCHED, >state);
-
/* If it is not PF reset, the firmware will disable the MAC,
 * so it only need to stop phy here.
 */
@@ -5341,8 +5350,6 @@ static void hclge_ae_stop(struct hnae3_handle *handle)
 
/* reset tqp stats */
hclge_reset_tqp_stats(handle);
-   del_timer_sync(>service_timer);
-   cancel_work_sync(>service_task);
hclge_update_link_status(hdev);
 }
 
@@ -7996,6 +8003,7 @@ static int hclge_gro_en(struct hnae3_handle *handle, int 
enable)
.ae_dev_reset_cnt = hclge_ae_dev_reset_cnt,
.set_gro_en = hclge_gro_en,
.get_global_queue_id = hclge_cove

[PATCH net-next 5/9] net: hns3: reset tqp while doing DOWN operation

2018-12-19 Thread Peng Li
From: Huazhong Tan 

While doing DOWN operation, the driver will reclaim the memory which has
already used for TX. If the hardware is processing this memory, it will
cause a RCB error to the hardware. According the hardware's description,
the driver should reset the tqp before reclaim the memory during DOWN.

Signed-off-by: Huazhong Tan 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c   | 4 
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 4 
 2 files changed, 8 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 0b04d04..98ae282 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -5331,6 +5331,7 @@ static void hclge_ae_stop(struct hnae3_handle *handle)
 {
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
+   int i;
 
set_bit(HCLGE_STATE_DOWN, >state);
 
@@ -5343,6 +5344,9 @@ static void hclge_ae_stop(struct hnae3_handle *handle)
return;
}
 
+   for (i = 0; i < handle->kinfo.num_tqps; i++)
+   hclge_reset_tqp(handle, i);
+
/* Mac disable */
hclge_cfg_mac_mode(hdev, false);
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index 919c3aa..156242f 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -1870,9 +1870,13 @@ static int hclgevf_ae_start(struct hnae3_handle *handle)
 static void hclgevf_ae_stop(struct hnae3_handle *handle)
 {
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
+   int i;
 
set_bit(HCLGEVF_STATE_DOWN, >state);
 
+   for (i = 0; i < handle->kinfo.num_tqps; i++)
+   hclgevf_reset_tqp(handle, i);
+
/* reset tqp stats */
hclgevf_reset_tqp_stats(handle);
hclgevf_update_link_status(hdev, 0);
-- 
1.9.1



[PATCH net-next 3/9] net: hns3: fix a bug caused by udelay

2018-12-19 Thread Peng Li
udelay() in driver may always occupancy processor. If there is only
one cpu in system, the VF driver may initialize fail when insmod
PF and VF driver in the same system. This patch use msleep() to free
cpu when VF wait PF message.

Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c
index ef9c8e6..84653f5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c
@@ -26,7 +26,7 @@ static int hclgevf_get_mbx_resp(struct hclgevf_dev *hdev, u16 
code0, u16 code1,
u8 *resp_data, u16 resp_len)
 {
 #define HCLGEVF_MAX_TRY_TIMES  500
-#define HCLGEVF_SLEEP_USCOEND  1000
+#define HCLGEVF_SLEEP_USECOND  1000
struct hclgevf_mbx_resp_status *mbx_resp;
u16 r_code0, r_code1;
int i = 0;
@@ -43,7 +43,7 @@ static int hclgevf_get_mbx_resp(struct hclgevf_dev *hdev, u16 
code0, u16 code1,
if (test_bit(HCLGEVF_STATE_CMD_DISABLE, >state))
return -EIO;
 
-   udelay(HCLGEVF_SLEEP_USCOEND);
+   usleep_range(HCLGEVF_SLEEP_USECOND, HCLGEVF_SLEEP_USECOND * 2);
i++;
}
 
-- 
1.9.1



[PATCH net-next 6/9] net: hns3: fix vf id check issue when add flow director rule

2018-12-19 Thread Peng Li
From: Jian Shen 

When add flow director fule for vf, the vf id is used as array
subscript before valid checking, which may cause memory overflow.

Fixes: dd74f815dd41 ("net: hns3: Add support for rule add/delete for flow 
director")
Signed-off-by: Jian Shen 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 98ae282..9f89858 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4677,6 +4677,13 @@ static int hclge_add_fd_entry(struct hnae3_handle 
*handle,
u8 vf = ethtool_get_flow_spec_ring_vf(fs->ring_cookie);
u16 tqps;
 
+   if (vf > hdev->num_req_vfs) {
+   dev_err(>pdev->dev,
+   "Error: vf id (%d) > max vf num (%d)\n",
+   vf, hdev->num_req_vfs);
+   return -EINVAL;
+   }
+
dst_vport_id = vf ? hdev->vport[vf].vport_id : vport->vport_id;
tqps = vf ? hdev->vport[vf].alloc_tqps : vport->alloc_tqps;
 
@@ -4687,13 +4694,6 @@ static int hclge_add_fd_entry(struct hnae3_handle 
*handle,
return -EINVAL;
}
 
-   if (vf > hdev->num_req_vfs) {
-   dev_err(>pdev->dev,
-   "Error: vf id (%d) > max vf num (%d)\n",
-   vf, hdev->num_req_vfs);
-   return -EINVAL;
-   }
-
action = HCLGE_FD_ACTION_ACCEPT_PACKET;
q_index = ring;
}
-- 
1.9.1



[PATCH net-next 4/9] net: hns3: add max vector number check for pf

2018-12-19 Thread Peng Li
From: Jian Shen 

Each pf supports max 64 vectors and 128 tqps. For 2p/4p core scenario,
there may be more than 64 cpus online. So the result of min_t(u16,
num_Online_cpus(), tqp_num) may be more than 64. This patch adds check
for the vector number.

Fixes: dd38c72604dc ("net: hns3: fix for coalesce configuration lost during 
reset")
Signed-off-by: Jian Shen 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index becbf86..624b8a7 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -3118,6 +3118,8 @@ static int hns3_nic_init_vector_data(struct hns3_nic_priv 
*priv)
 
 static int hns3_nic_alloc_vector_data(struct hns3_nic_priv *priv)
 {
+#define HNS3_VECTOR_PF_MAX_NUM 64
+
struct hnae3_handle *h = priv->ae_handle;
struct hns3_enet_tqp_vector *tqp_vector;
struct hnae3_vector_info *vector;
@@ -3130,6 +3132,8 @@ static int hns3_nic_alloc_vector_data(struct 
hns3_nic_priv *priv)
/* RSS size, cpu online and vector_num should be the same */
/* Should consider 2p/4p later */
vector_num = min_t(u16, num_online_cpus(), tqp_num);
+   vector_num = min_t(u16, vector_num, HNS3_VECTOR_PF_MAX_NUM);
+
vector = devm_kcalloc(>dev, vector_num, sizeof(*vector),
  GFP_KERNEL);
if (!vector)
-- 
1.9.1



[PATCH net-next 9/9] net: hns3: remove redundant variable initialization

2018-12-19 Thread Peng Li
This patch removes the redundant variable initialization,
as driver will devm_kzalloc to set value to hdev soon.

Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index 156242f..82103d5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -1721,7 +1721,7 @@ static int hclgevf_configure(struct hclgevf_dev *hdev)
 static int hclgevf_alloc_hdev(struct hnae3_ae_dev *ae_dev)
 {
struct pci_dev *pdev = ae_dev->pdev;
-   struct hclgevf_dev *hdev = ae_dev->priv;
+   struct hclgevf_dev *hdev;
 
hdev = devm_kzalloc(>dev, sizeof(*hdev), GFP_KERNEL);
if (!hdev)
-- 
1.9.1



[PATCH net-next 0/9] net: hns3: code optimizations & bugfixes for HNS3 driver

2018-12-19 Thread Peng Li
This patchset includes bugfixes and code optimizations for the HNS3
ethernet controller driver

Huazhong Tan (1):
  net: hns3: reset tqp while doing DOWN operation

Jian Shen (5):
  net: hns3: refine the handle for hns3_nic_net_open/stop()
  net: hns3: change default tc state to close
  net: hns3: add max vector number check for pf
  net: hns3: fix vf id check issue when add flow director rule
  net: hns3: don't restore rules when flow director is disabled

Peng Li (3):
  net: hns3: fix a bug caused by udelay
  net: hns3: fix the descriptor index when get rss type
  net: hns3: remove redundant variable initialization

 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  1 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 21 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 46 +++---
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  | 24 ---
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c   |  4 +-
 5 files changed, 73 insertions(+), 23 deletions(-)

-- 
1.9.1



[PATCH net-next 2/9] net: hns3: change default tc state to close

2018-12-19 Thread Peng Li
From: Jian Shen 

In original codes, default tc value is set to the max tc. It's more
reasonable to close tc by changing default tc value to 1. Users can
enable it with lldp tool when they want to use tc.

Signed-off-by: Jian Shen 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index a12cb14..0b04d04 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -960,7 +960,7 @@ static int hclge_configure(struct hclge_dev *hdev)
hdev->pfc_max = hdev->tc_max;
}
 
-   hdev->tm_info.num_tc = hdev->tc_max;
+   hdev->tm_info.num_tc = 1;
 
/* Currently not support uncontiuous tc */
for (i = 0; i < hdev->tm_info.num_tc; i++)
-- 
1.9.1



[PATCH net-next 8/9] net: hns3: fix the descriptor index when get rss type

2018-12-19 Thread Peng Li
Driver gets rss information from the last descriptor of the packet.
When driver handle the rss type, ring->next_to_clean indicates the
first descriptor of next packet.

This patch fix the descriptor index with "ring->next_to_clean - 1".

Fixes: 232fc64b6e62 ("net: hns3: Add HW RSS hash information to RX skb")
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 624b8a7..d3b9aaf 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2550,9 +2550,16 @@ static void hns3_set_gro_param(struct sk_buff *skb, u32 
l234info,
 static void hns3_set_rx_skb_rss_type(struct hns3_enet_ring *ring,
 struct sk_buff *skb)
 {
-   struct hns3_desc *desc = >desc[ring->next_to_clean];
struct hnae3_handle *handle = ring->tqp->handle;
enum pkt_hash_types rss_type;
+   struct hns3_desc *desc;
+   int last_bd;
+
+   /* When driver handle the rss type, ring->next_to_clean indicates the
+* first descriptor of next packet, need -1 here.
+*/
+   last_bd = (ring->next_to_clean - 1 + ring->desc_num) % ring->desc_num;
+   desc = >desc[last_bd];
 
if (le32_to_cpu(desc->rx.rss_hash))
rss_type = handle->kinfo.rss_type;
-- 
1.9.1



[PATCH net-next 7/9] net: hns3: don't restore rules when flow director is disabled

2018-12-19 Thread Peng Li
From: Jian Shen 

When user disables flow director, all the rules will be disabled. But
when reset happens, it will restore all the rules again. It's not
reasonable. This patch fixes it by add flow director status check before
restore fules.

Fixes: 6871af29b3ab ("net: hns3: Add reset handle for flow director")
Fixes: c17852a8932f ("net: hns3: Add support for enable/disable flow director")
Signed-off-by: Jian Shen 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 9f89858..f7637c0 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4808,6 +4808,10 @@ static int hclge_restore_fd_entries(struct hnae3_handle 
*handle)
if (!hnae3_dev_fd_supported(hdev))
return 0;
 
+   /* if fd is disabled, should not restore it when reset */
+   if (!hdev->fd_cfg.fd_en)
+   return 0;
+
hlist_for_each_entry_safe(rule, node, >fd_rule_list, rule_node) {
ret = hclge_config_action(hdev, HCLGE_FD_STAGE_1, rule);
if (!ret)
-- 
1.9.1



[PATCH net-next 02/12] net: hns3: uninitialize pci in the hclgevf_uninit

2018-12-18 Thread Peng Li
From: Huazhong Tan 

In the hclgevf_pci_reset(), it only uninitialize and initialize
the msi, so if the initialization fails, hclgevf_uninit_hdev()
does not need to uninitialize the msi, but needs to uninitialize
the pci, otherwise it will cause pci resource not free.

Fixes: 862d969a3a4d ("net: hns3: do VF's pci re-initialization while PF doing 
FLR")
Signed-off-by: Huazhong Tan 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index 75327dc..86596ee 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -2401,9 +2401,9 @@ static void hclgevf_uninit_hdev(struct hclgevf_dev *hdev)
if (test_bit(HCLGEVF_STATE_IRQ_INITED, >state)) {
hclgevf_misc_irq_uninit(hdev);
hclgevf_uninit_msi(hdev);
-   hclgevf_pci_uninit(hdev);
}
 
+   hclgevf_pci_uninit(hdev);
hclgevf_cmd_uninit(hdev);
 }
 
-- 
1.9.1



[PATCH net-next 08/12] net: hns3: remove 1000M/half support of phy

2018-12-18 Thread Peng Li
From: Fuyun Liang 

Our phy does not support 1000M/half, this patch removes 1000M/half from
PHY_SUPPORTED_FEATURES.

Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
index 741cb3b..d8ef436 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -12,7 +12,7 @@
 SUPPORTED_TP | \
 PHY_10BT_FEATURES | \
 PHY_100BT_FEATURES | \
-PHY_1000BT_FEATURES)
+SUPPORTED_1000baseT_Full)
 
 enum hclge_mdio_c22_op_seq {
HCLGE_MDIO_C22_WRITE = 1,
-- 
1.9.1



[PATCH net-next 05/12] net: hns3: remove unnecessary configuration recapture while resetting

2018-12-18 Thread Peng Li
From: Huazhong Tan 

When doing reset, it is unnecessary to get the hardware's default
configuration again, otherwise, the user's configuration will be
overwritten.

Fixes: 4ed340ab8f49 ("net: hns3: Add reset process in hclge_main")
Signed-off-by: Huazhong Tan 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 13 -
 1 file changed, 13 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index a8a2ccf..b66eee9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -7380,19 +7380,6 @@ static int hclge_reset_ae_dev(struct hnae3_ae_dev 
*ae_dev)
return ret;
}
 
-   ret = hclge_get_cap(hdev);
-   if (ret) {
-   dev_err(>dev, "get hw capability error, ret = %d.\n",
-   ret);
-   return ret;
-   }
-
-   ret = hclge_configure(hdev);
-   if (ret) {
-   dev_err(>dev, "Configure dev error, ret = %d.\n", ret);
-   return ret;
-   }
-
ret = hclge_map_tqp(hdev);
if (ret) {
dev_err(>dev, "Map tqp error, ret = %d.\n", ret);
-- 
1.9.1



[PATCH net-next 11/12] net: hns3: aligning buffer size in SSU to 256 bytes

2018-12-18 Thread Peng Li
From: Yunsheng Lin 

The hardware expects the buffer size set to SSU is aligned to
256 bytes, this patch aligns the buffer size to 256 byte using
roundup or rounddown function.

Signed-off-by: Yunsheng Lin 
Signed-off-by: Peng Li 
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 43 +-
 1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index c52e903..f847fde 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -26,6 +26,8 @@
 #define HCLGE_STATS_READ(p, offset) (*((u64 *)((u8 *)(p) + (offset
 #define HCLGE_MAC_STATS_FIELD_OFF(f) (offsetof(struct hclge_mac_stats, f))
 
+#define HCLGE_BUF_SIZE_UNIT256
+
 static int hclge_set_mac_mtu(struct hclge_dev *hdev, int new_mps);
 static int hclge_init_vlan_config(struct hclge_dev *hdev);
 static int hclge_reset_ae_dev(struct hnae3_ae_dev *ae_dev);
@@ -693,12 +695,16 @@ static int hclge_query_pf_resource(struct hclge_dev *hdev)
else
hdev->tx_buf_size = HCLGE_DEFAULT_TX_BUF;
 
+   hdev->tx_buf_size = roundup(hdev->tx_buf_size, HCLGE_BUF_SIZE_UNIT);
+
if (req->dv_buf_size)
hdev->dv_buf_size =
__le16_to_cpu(req->dv_buf_size) << HCLGE_BUF_UNIT_S;
else
hdev->dv_buf_size = HCLGE_DEFAULT_DV;
 
+   hdev->dv_buf_size = roundup(hdev->dv_buf_size, HCLGE_BUF_SIZE_UNIT);
+
if (hnae3_dev_roce_supported(hdev)) {
hdev->roce_base_msix_offset =
hnae3_get_field(__le16_to_cpu(req->msixcap_localid_ba_rocee),
@@ -1380,48 +1386,50 @@ static bool  hclge_is_rx_buf_ok(struct hclge_dev *hdev,
 {
u32 shared_buf_min, shared_buf_tc, shared_std;
int tc_num, pfc_enable_num;
-   u32 shared_buf;
+   u32 shared_buf, aligned_mps;
u32 rx_priv;
int i;
 
tc_num = hclge_get_tc_num(hdev);
pfc_enable_num = hclge_get_pfc_enalbe_num(hdev);
+   aligned_mps = roundup(hdev->mps, HCLGE_BUF_SIZE_UNIT);
 
if (hnae3_dev_dcb_supported(hdev))
-   shared_buf_min = 2 * hdev->mps + hdev->dv_buf_size;
+   shared_buf_min = 2 * aligned_mps + hdev->dv_buf_size;
else
-   shared_buf_min = hdev->mps + HCLGE_NON_DCB_ADDITIONAL_BUF
+   shared_buf_min = aligned_mps + HCLGE_NON_DCB_ADDITIONAL_BUF
+ hdev->dv_buf_size;
 
-   shared_buf_tc = pfc_enable_num * hdev->mps +
-   (tc_num - pfc_enable_num) * hdev->mps / 2 +
-   hdev->mps;
+   shared_buf_tc = pfc_enable_num * aligned_mps +
+   (tc_num - pfc_enable_num) * aligned_mps / 2 +
+   aligned_mps;
shared_std = max_t(u32, shared_buf_min, shared_buf_tc);
 
rx_priv = hclge_get_rx_priv_buff_alloced(buf_alloc);
if (rx_all <= rx_priv + shared_std)
return false;
 
-   shared_buf = rx_all - rx_priv;
+   shared_buf = rounddown(rx_all - rx_priv, HCLGE_BUF_SIZE_UNIT);
buf_alloc->s_buf.buf_size = shared_buf;
if (hnae3_dev_dcb_supported(hdev)) {
buf_alloc->s_buf.self.high = shared_buf - hdev->dv_buf_size;
buf_alloc->s_buf.self.low = buf_alloc->s_buf.self.high
-   - hdev->mps / 2;
+   - roundup(aligned_mps / 2, HCLGE_BUF_SIZE_UNIT);
} else {
-   buf_alloc->s_buf.self.high = hdev->mps +
+   buf_alloc->s_buf.self.high = aligned_mps +
HCLGE_NON_DCB_ADDITIONAL_BUF;
-   buf_alloc->s_buf.self.low = hdev->mps / 2;
+   buf_alloc->s_buf.self.low =
+   roundup(aligned_mps / 2, HCLGE_BUF_SIZE_UNIT);
}
 
for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
if ((hdev->hw_tc_map & BIT(i)) &&
(hdev->tm_info.hw_pfc_map & BIT(i))) {
-   buf_alloc->s_buf.tc_thrd[i].low = hdev->mps;
-   buf_alloc->s_buf.tc_thrd[i].high = 2 * hdev->mps;
+   buf_alloc->s_buf.tc_thrd[i].low = aligned_mps;
+   buf_alloc->s_buf.tc_thrd[i].high = 2 * aligned_mps;
} else {
buf_alloc->s_buf.tc_thrd[i].low = 0;
-   buf_alloc->s_buf.tc_thrd[i].high = hdev->mps;
+   buf_alloc->s_buf.tc_thrd[i].high = aligned_mps;
}
}
 
@@ -1461,7 +1469,6 @@ static int hclge_tx_buffer_calc(struct hclge_dev *hdev,
 static int hclge_rx_buffer_calc(struct hclge_dev *hdev,
  

[PATCH net-next 10/12] net: hns3: getting tx and dv buffer size through firmware

2018-12-18 Thread Peng Li
From: Yunsheng Lin 

This patch adds support of getting tx and dv buffer size through
firmware, because different version of hardware requires different
size of tx and dv buffer.

This patch also add dv_buf_size to tc' private buffer size even if
pfc is not enable for the tc.

Signed-off-by: Yunsheng Lin 
Signed-off-by: Peng Li 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  5 ++-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 41 --
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  3 ++
 3 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 4771780..f23042b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -420,7 +420,9 @@ struct hclge_pf_res_cmd {
 #define HCLGE_PF_VEC_NUM_M GENMASK(7, 0)
__le16 pf_intr_vector_number;
__le16 pf_own_fun_number;
-   __le32 rsv[3];
+   __le16 tx_buf_size;
+   __le16 dv_buf_size;
+   __le32 rsv[2];
 };
 
 #define HCLGE_CFG_OFFSET_S 0
@@ -839,6 +841,7 @@ struct hclge_serdes_lb_cmd {
 #define HCLGE_TOTAL_PKT_BUF0x108000 /* 1.03125M bytes */
 #define HCLGE_DEFAULT_DV   0xA000   /* 40k byte */
 #define HCLGE_DEFAULT_NON_DCB_DV   0x7800  /* 30K byte */
+#define HCLGE_NON_DCB_ADDITIONAL_BUF   0x200   /* 512 byte */
 
 #define HCLGE_TYPE_CRQ 0
 #define HCLGE_TYPE_CSQ 1
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index b66eee9..c52e903 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -687,6 +687,18 @@ static int hclge_query_pf_resource(struct hclge_dev *hdev)
hdev->num_tqps = __le16_to_cpu(req->tqp_num);
hdev->pkt_buf_size = __le16_to_cpu(req->buf_size) << HCLGE_BUF_UNIT_S;
 
+   if (req->tx_buf_size)
+   hdev->tx_buf_size =
+   __le16_to_cpu(req->tx_buf_size) << HCLGE_BUF_UNIT_S;
+   else
+   hdev->tx_buf_size = HCLGE_DEFAULT_TX_BUF;
+
+   if (req->dv_buf_size)
+   hdev->dv_buf_size =
+   __le16_to_cpu(req->dv_buf_size) << HCLGE_BUF_UNIT_S;
+   else
+   hdev->dv_buf_size = HCLGE_DEFAULT_DV;
+
if (hnae3_dev_roce_supported(hdev)) {
hdev->roce_base_msix_offset =
hnae3_get_field(__le16_to_cpu(req->msixcap_localid_ba_rocee),
@@ -1376,9 +1388,10 @@ static bool  hclge_is_rx_buf_ok(struct hclge_dev *hdev,
pfc_enable_num = hclge_get_pfc_enalbe_num(hdev);
 
if (hnae3_dev_dcb_supported(hdev))
-   shared_buf_min = 2 * hdev->mps + HCLGE_DEFAULT_DV;
+   shared_buf_min = 2 * hdev->mps + hdev->dv_buf_size;
else
-   shared_buf_min = 2 * hdev->mps + HCLGE_DEFAULT_NON_DCB_DV;
+   shared_buf_min = hdev->mps + HCLGE_NON_DCB_ADDITIONAL_BUF
+   + hdev->dv_buf_size;
 
shared_buf_tc = pfc_enable_num * hdev->mps +
(tc_num - pfc_enable_num) * hdev->mps / 2 +
@@ -1391,8 +1404,15 @@ static bool  hclge_is_rx_buf_ok(struct hclge_dev *hdev,
 
shared_buf = rx_all - rx_priv;
buf_alloc->s_buf.buf_size = shared_buf;
-   buf_alloc->s_buf.self.high = shared_buf;
-   buf_alloc->s_buf.self.low =  2 * hdev->mps;
+   if (hnae3_dev_dcb_supported(hdev)) {
+   buf_alloc->s_buf.self.high = shared_buf - hdev->dv_buf_size;
+   buf_alloc->s_buf.self.low = buf_alloc->s_buf.self.high
+   - hdev->mps / 2;
+   } else {
+   buf_alloc->s_buf.self.high = hdev->mps +
+   HCLGE_NON_DCB_ADDITIONAL_BUF;
+   buf_alloc->s_buf.self.low = hdev->mps / 2;
+   }
 
for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
if ((hdev->hw_tc_map & BIT(i)) &&
@@ -1419,11 +1439,11 @@ static int hclge_tx_buffer_calc(struct hclge_dev *hdev,
for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
struct hclge_priv_buf *priv = _alloc->priv_buf[i];
 
-   if (total_size < HCLGE_DEFAULT_TX_BUF)
+   if (total_size < hdev->tx_buf_size)
return -ENOMEM;
 
if (hdev->hw_tc_map & BIT(i))
-   priv->tx_buf_size = HCLGE_DEFAULT_TX_BUF;
+   priv->tx_buf_size = hdev->tx_buf_size;
else
priv->tx_buf_size = 0;
 
@@ -1469,11 +1489,12 @@ static int hclg

[PATCH net-next 00/12] net: hns3: code optimizations & bugfixes for HNS3 driver

2018-12-18 Thread Peng Li
This patchset includes bugfixes and code optimizations for the HNS3
ethernet controller driver

Fuyun Liang (1):
  net: hns3: remove 1000M/half support of phy

Huazhong Tan (6):
  net: hns3: fix error handling int the hns3_get_vector_ring_chain
  net: hns3: uninitialize pci in the hclgevf_uninit
  net: hns3: fix napi_disable not return problem
  net: hns3: update some variables while hclge_reset()/hclgevf_reset()
done
  net: hns3: remove unnecessary configuration recapture while resetting
  net: hns3: fix incomplete uninitialization of IRQ in the
hns3_nic_uninit_vector_data()

Peng Li (2):
  net: hns3: update coalesce param per second
  net: hns3: synchronize speed and duplex from phy when phy link up

Yunsheng Lin (3):
  net: hns3: getting tx and dv buffer size through firmware
  net: hns3: aligning buffer size in SSU to 256 bytes
  net: hns3: fix a SSU buffer checking bug

 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 29 ---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|  4 -
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  5 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 95 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  3 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c|  6 +-
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  |  5 +-
 7 files changed, 88 insertions(+), 59 deletions(-)

-- 
1.9.1



[PATCH net-next 04/12] net: hns3: update some variables while hclge_reset()/hclgevf_reset() done

2018-12-18 Thread Peng Li
From: Huazhong Tan 

When hclge_reset() completes successfully, it should update the
last_reset_time, set reset_fail_cnt to 0, and set reset_type of
hnae3_ae_dev to HNAE3_NONE_RESET.

Also when hclgevf_reset() completes successfully, it should update
the last_reset_time, and set reset_type of hnae3_ae_dev to
HNAE3_NONE_RESET.

Signed-off-by: Huazhong Tan 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c   | 5 -
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 3 +++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 3fe08cf..a8a2ccf 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2810,7 +2810,6 @@ static void hclge_reset(struct hclge_dev *hdev)
 */
ae_dev->reset_type = hdev->reset_type;
hdev->reset_count++;
-   hdev->last_reset_time = jiffies;
/* perform reset of the stack & ae device for a client */
ret = hclge_notify_roce_client(hdev, HNAE3_DOWN_CLIENT);
if (ret)
@@ -2873,6 +2872,10 @@ static void hclge_reset(struct hclge_dev *hdev)
if (ret)
goto err_reset;
 
+   hdev->last_reset_time = jiffies;
+   hdev->reset_fail_cnt = 0;
+   ae_dev->reset_type = HNAE3_NONE_RESET;
+
return;
 
 err_reset_lock:
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index 86596ee..54ba93a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -1342,6 +1342,9 @@ static int hclgevf_reset(struct hclgevf_dev *hdev)
 
rtnl_unlock();
 
+   hdev->last_reset_time = jiffies;
+   ae_dev->reset_type = HNAE3_NONE_RESET;
+
return ret;
 err_reset_lock:
rtnl_unlock();
-- 
1.9.1



[PATCH net-next 01/12] net: hns3: fix error handling int the hns3_get_vector_ring_chain

2018-12-18 Thread Peng Li
From: Huazhong Tan 

When hns3_get_vector_ring_chain() failed in the
hns3_nic_init_vector_data(), it should do the error handling instead
of return directly.

Also, cur_chain should be freed instead of chain and head->next should
be set to NULL in error handling of hns3_get_vector_ring_chain.

This patch fixes them.

Fixes: 73b907a083b8 ("net: hns3: bugfix for buffer not free problem during 
resetting")
Signed-off-by: Huazhong Tan 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 69142a3..2081e2e 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2993,9 +2993,10 @@ static int hns3_get_vector_ring_chain(struct 
hns3_enet_tqp_vector *tqp_vector,
cur_chain = head->next;
while (cur_chain) {
chain = cur_chain->next;
-   devm_kfree(>dev, chain);
+   devm_kfree(>dev, cur_chain);
cur_chain = chain;
}
+   head->next = NULL;
 
return -ENOMEM;
 }
@@ -3086,7 +3087,7 @@ static int hns3_nic_init_vector_data(struct hns3_nic_priv 
*priv)
ret = hns3_get_vector_ring_chain(tqp_vector,
 _ring_chain);
if (ret)
-   return ret;
+   goto map_ring_fail;
 
ret = h->ae_algo->ops->map_ring_to_vector(h,
tqp_vector->vector_irq, _ring_chain);
-- 
1.9.1



[PATCH net-next 07/12] net: hns3: update coalesce param per second

2018-12-18 Thread Peng Li
coalesce param updates every 100 napi times, it may update a little
late if ping test after a high rate flow, may over napi poll is called
100 times as ping test sends packets every second.

This patch updates coalesce param every second, instead with every
100 napi times. It can not update the param 100% in time, but the
lag time is very short.

Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 8 +++-
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h | 4 
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 354eca8..d060029 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -240,7 +240,6 @@ static void hns3_vector_gl_rl_init(struct 
hns3_enet_tqp_vector *tqp_vector,
tqp_vector->tx_group.coal.int_gl = HNS3_INT_GL_50K;
tqp_vector->rx_group.coal.int_gl = HNS3_INT_GL_50K;
 
-   tqp_vector->int_adapt_down = HNS3_INT_ADAPT_DOWN_START;
tqp_vector->rx_group.coal.flow_level = HNS3_FLOW_LOW;
tqp_vector->tx_group.coal.flow_level = HNS3_FLOW_LOW;
 }
@@ -2846,10 +2845,10 @@ static void hns3_update_new_int_gl(struct 
hns3_enet_tqp_vector *tqp_vector)
struct hns3_enet_ring_group *tx_group = _vector->tx_group;
bool rx_update, tx_update;
 
-   if (tqp_vector->int_adapt_down > 0) {
-   tqp_vector->int_adapt_down--;
+   /* update param every 1000ms */
+   if (time_before(jiffies,
+   tqp_vector->last_jiffies + msecs_to_jiffies(1000)))
return;
-   }
 
if (rx_group->coal.gl_adapt_enable) {
rx_update = hns3_get_new_int_gl(rx_group);
@@ -2866,7 +2865,6 @@ static void hns3_update_new_int_gl(struct 
hns3_enet_tqp_vector *tqp_vector)
}
 
tqp_vector->last_jiffies = jiffies;
-   tqp_vector->int_adapt_down = HNS3_INT_ADAPT_DOWN_START;
 }
 
 static int hns3_nic_common_poll(struct napi_struct *napi, int budget)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
index 4e4b48b..e55995e 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
@@ -476,8 +476,6 @@ enum hns3_link_mode_bits {
 #define HNS3_INT_RL_MAX0x00EC
 #define HNS3_INT_RL_ENABLE_MASK0x40
 
-#define HNS3_INT_ADAPT_DOWN_START  100
-
 struct hns3_enet_coalesce {
u16 int_gl;
u8 gl_adapt_enable;
@@ -512,8 +510,6 @@ struct hns3_enet_tqp_vector {
 
char name[HNAE3_INT_NAME_LEN];
 
-   /* when 0 should adjust interrupt coalesce parameter */
-   u8 int_adapt_down;
unsigned long last_jiffies;
 } cacheline_internodealigned_in_smp;
 
-- 
1.9.1



[PATCH net-next 12/12] net: hns3: fix a SSU buffer checking bug

2018-12-18 Thread Peng Li
From: Yunsheng Lin 

When caculating the SSU buffer, it first allocate tx and
rx private buffer, then the remaining buffer is for rx
shared buffer. The remaining buffer size should be at
least bigger than or equal to the shared_std, which is the
minimum shared buffer size required by the driver, but
currently if the remaining buffer size is equal to the
shared_std, it returns failure, which causes SSU buffer
allocation failure problem.

This patch fixes this problem by rounding up shared_std before
checking the the remaining buffer size bigger than or equal to
the shared_std.

Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support")
Signed-off-by: Yunsheng Lin 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index f847fde..d0e84de 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -1403,10 +1403,11 @@ static bool  hclge_is_rx_buf_ok(struct hclge_dev *hdev,
shared_buf_tc = pfc_enable_num * aligned_mps +
(tc_num - pfc_enable_num) * aligned_mps / 2 +
aligned_mps;
-   shared_std = max_t(u32, shared_buf_min, shared_buf_tc);
+   shared_std = roundup(max_t(u32, shared_buf_min, shared_buf_tc),
+HCLGE_BUF_SIZE_UNIT);
 
rx_priv = hclge_get_rx_priv_buff_alloced(buf_alloc);
-   if (rx_all <= rx_priv + shared_std)
+   if (rx_all < rx_priv + shared_std)
return false;
 
shared_buf = rounddown(rx_all - rx_priv, HCLGE_BUF_SIZE_UNIT);
-- 
1.9.1



[PATCH net-next 09/12] net: hns3: synchronize speed and duplex from phy when phy link up

2018-12-18 Thread Peng Li
Driver calls phy_connect_direct and registers hclge_mac_adjust_link
to synchronize mac speed and duplex from phy. It is better to
synchronize mac speed and duplex from phy when phy link up.

Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
index d8ef436..dabb843 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -179,6 +179,10 @@ static void hclge_mac_adjust_link(struct net_device 
*netdev)
int duplex, speed;
int ret;
 
+   /* When phy link down, do nothing */
+   if (netdev->phydev->link == 0)
+   return;
+
speed = netdev->phydev->speed;
duplex = netdev->phydev->duplex;
 
-- 
1.9.1



[PATCH net-next 06/12] net: hns3: fix incomplete uninitialization of IRQ in the hns3_nic_uninit_vector_data()

2018-12-18 Thread Peng Li
From: Huazhong Tan 

In the hns3_nic_uninit_vector_data(), the procedure of uninitializing
the tqp_vector's IRQ has not set affinity_notify to NULL and changes
its init flag. This patch fixes it. And for simplificaton, local
variable tqp_vector is used instead of priv->tqp_vector[i].

Fixes: 424eb834a9be ("net: hns3: Unified HNS3 {VF|PF} Ethernet Driver for hip08 
SoC")
Signed-off-by: Huazhong Tan 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index e7cde08..354eca8 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -3181,12 +3181,12 @@ static int hns3_nic_uninit_vector_data(struct 
hns3_nic_priv *priv)
 
hns3_free_vector_ring_chain(tqp_vector, _ring_chain);
 
-   if (priv->tqp_vector[i].irq_init_flag == HNS3_VECTOR_INITED) {
-   (void)irq_set_affinity_hint(
-   priv->tqp_vector[i].vector_irq,
-   NULL);
-   free_irq(priv->tqp_vector[i].vector_irq,
->tqp_vector[i]);
+   if (tqp_vector->irq_init_flag == HNS3_VECTOR_INITED) {
+   irq_set_affinity_notifier(tqp_vector->vector_irq,
+ NULL);
+   irq_set_affinity_hint(tqp_vector->vector_irq, NULL);
+   free_irq(tqp_vector->vector_irq, tqp_vector);
+   tqp_vector->irq_init_flag = HNS3_VECTOR_NOT_INITED;
}
 
priv->ring_data[i].ring->irq_init_flag = HNS3_VECTOR_NOT_INITED;
-- 
1.9.1



[PATCH net-next 03/12] net: hns3: fix napi_disable not return problem

2018-12-18 Thread Peng Li
From: Huazhong Tan 

While doing DOWN, the calling of napi_disable() may not return, since the
napi_complete() in the hns3_nic_common_poll() will never be called when
HNS3_NIC_STATE_DOWN is set. So we need to call napi_complete() before
checking HNS3_NIC_STETE_DOWN.

Fixes: ff0699e04b97 ("net: hns3: stop napi polling when HNS3_NIC_STATE_DOWN is 
set")
Signed-off-by: Huazhong Tan 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 2081e2e..e7cde08 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2909,8 +2909,8 @@ static int hns3_nic_common_poll(struct napi_struct *napi, 
int budget)
if (!clean_complete)
return budget;
 
-   if (likely(!test_bit(HNS3_NIC_STATE_DOWN, >state)) &&
-   napi_complete(napi)) {
+   if (napi_complete(napi) &&
+   likely(!test_bit(HNS3_NIC_STATE_DOWN, >state))) {
hns3_update_new_int_gl(tqp_vector);
hns3_mask_vector_irq(tqp_vector, 1);
}
-- 
1.9.1



[Patch net 07/10] net: hns: Avoid net reset caused by pause frames storm

2018-12-14 Thread Peng Li
From: Yonglong Liu 

There will be a large number of MAC pause frames on the net,
which caused tx timeout of net device. And then the net device
was reset to try to recover it. So that is not useful, and will
cause some other problems.

So need doubled ndev->watchdog_timeo if device watchdog occurred
until watchdog_timeo up to 40s and then try resetting to recover
it.

When collecting dfx information such as hardware registers when tx timeout.
Some registers for count were cleared when read. So need move this task
before update net state which also read the count registers.

Signed-off-by: Yonglong Liu 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index 03d959c..8a53c82 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -1509,11 +1509,19 @@ static int hns_nic_net_stop(struct net_device *ndev)
 }
 
 static void hns_tx_timeout_reset(struct hns_nic_priv *priv);
+#define HNS_TX_TIMEO_LIMIT (40 * HZ)
 static void hns_nic_net_timeout(struct net_device *ndev)
 {
struct hns_nic_priv *priv = netdev_priv(ndev);
 
-   hns_tx_timeout_reset(priv);
+   if (ndev->watchdog_timeo < HNS_TX_TIMEO_LIMIT) {
+   ndev->watchdog_timeo *= 2;
+   netdev_info(ndev, "watchdog_timo changed to %d.\n",
+   ndev->watchdog_timeo);
+   } else {
+   ndev->watchdog_timeo = HNS_NIC_TX_TIMEOUT;
+   hns_tx_timeout_reset(priv);
+   }
 }
 
 static int hns_nic_do_ioctl(struct net_device *netdev, struct ifreq *ifr,
@@ -2076,11 +2084,11 @@ static void hns_nic_service_task(struct work_struct 
*work)
= container_of(work, struct hns_nic_priv, service_task);
struct hnae_handle *h = priv->ae_handle;
 
+   hns_nic_reset_subtask(priv);
hns_nic_update_link_status(priv->netdev);
h->dev->ops->update_led_status(h);
hns_nic_update_stats(priv->netdev);
 
-   hns_nic_reset_subtask(priv);
hns_nic_service_event_complete(priv);
 }
 
-- 
1.9.1



[Patch net 06/10] net: hns: Free irq when exit from abnormal branch

2018-12-14 Thread Peng Li
From: Yonglong Liu 

1.In "hns_nic_init_irq", if request irq fail at index i,
  the function return directly without releasing irq resources
  that already requested.

2.In "hns_nic_net_up" after "hns_nic_init_irq",
  if exceptional branch occurs, irqs that already requested
  are not release.

Signed-off-by: Yonglong Liu 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index c9454c4..03d959c 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -1284,6 +1284,22 @@ static int hns_nic_init_affinity_mask(int q_num, int 
ring_idx,
return cpu;
 }
 
+static void hns_nic_free_irq(int q_num, struct hns_nic_priv *priv)
+{
+   int i;
+
+   for (i = 0; i < q_num * 2; i++) {
+   if (priv->ring_data[i].ring->irq_init_flag == RCB_IRQ_INITED) {
+   irq_set_affinity_hint(priv->ring_data[i].ring->irq,
+ NULL);
+   free_irq(priv->ring_data[i].ring->irq,
+>ring_data[i]);
+   priv->ring_data[i].ring->irq_init_flag =
+   RCB_IRQ_NOT_INITED;
+   }
+   }
+}
+
 static int hns_nic_init_irq(struct hns_nic_priv *priv)
 {
struct hnae_handle *h = priv->ae_handle;
@@ -1309,7 +1325,7 @@ static int hns_nic_init_irq(struct hns_nic_priv *priv)
if (ret) {
netdev_err(priv->netdev, "request irq(%d) fail\n",
   rd->ring->irq);
-   return ret;
+   goto out_free_irq;
}
disable_irq(rd->ring->irq);
 
@@ -1324,6 +1340,10 @@ static int hns_nic_init_irq(struct hns_nic_priv *priv)
}
 
return 0;
+
+out_free_irq:
+   hns_nic_free_irq(h->q_num, priv);
+   return ret;
 }
 
 static int hns_nic_net_up(struct net_device *ndev)
@@ -1371,6 +1391,7 @@ static int hns_nic_net_up(struct net_device *ndev)
for (j = i - 1; j >= 0; j--)
hns_nic_ring_close(ndev, j);
 
+   hns_nic_free_irq(h->q_num, priv);
set_bit(NIC_STATE_DOWN, >state);
 
return ret;
-- 
1.9.1



[Patch net 02/10] net: hns: All ports can not work when insmod hns ko after rmmod.

2018-12-14 Thread Peng Li
From: Yonglong Liu 

There are two test cases:
1. Remove the 4 modules:hns_enet_drv/hns_dsaf/hnae/hns_mdio,
   and install them again, must use "ifconfig down/ifconfig up"
   command pair to bring port to work.

   This patch calls phy_stop function when init phy to fix this bug.

2. Remove the 2 modules:hns_enet_drv/hns_dsaf, and install them again,
   all ports can not use anymore, because of the phy devices register
   failed(phy devices already exists).

   Phy devices are registered when hns_dsaf installed, this patch
   removes them when hns_dsaf removed.

The two cases are sometimes related, fixing the second case also requires
fixing the first case, so fix them together.

Signed-off-by: Yonglong Liu 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 15 +++
 drivers/net/ethernet/hisilicon/hns/hns_enet.c |  3 +++
 2 files changed, 18 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
index 3613e40..a97228c 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
@@ -778,6 +778,17 @@ static int hns_mac_register_phy(struct hns_mac_cb *mac_cb)
return rc;
 }
 
+static void hns_mac_remove_phydev(struct hns_mac_cb *mac_cb)
+{
+   if (!to_acpi_device_node(mac_cb->fw_port) || !mac_cb->phy_dev)
+   return;
+
+   phy_device_remove(mac_cb->phy_dev);
+   phy_device_free(mac_cb->phy_dev);
+
+   mac_cb->phy_dev = NULL;
+}
+
 #define MAC_MEDIA_TYPE_MAX_LEN 16
 
 static const struct {
@@ -1117,7 +1128,11 @@ 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++) {
+   if (!dsaf_dev->mac_cb[i])
+   continue;
+
dsaf_dev->misc_op->cpld_reset_led(dsaf_dev->mac_cb[i]);
+   hns_mac_remove_phydev(dsaf_dev->mac_cb[i]);
dsaf_dev->mac_cb[i] = NULL;
}
 }
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index 28e9078..c205a0e 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -1186,6 +1186,9 @@ int hns_nic_init_phy(struct net_device *ndev, struct 
hnae_handle *h)
if (h->phy_if == PHY_INTERFACE_MODE_XGMII)
phy_dev->autoneg = false;
 
+   if (h->phy_if == PHY_INTERFACE_MODE_SGMII)
+   phy_stop(phy_dev);
+
return 0;
 }
 
-- 
1.9.1



[Patch net 05/10] net: hns: Clean rx fbd when ae stopped.

2018-12-14 Thread Peng Li
From: Yonglong Liu 

If there are packets in hardware when changing the speed or duplex,
it may cause hardware hang up.

This patch adds the code to wait rx fbd clean up when ae stopped.

Signed-off-by: Yonglong Liu 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
index b52029e..ad1779f 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
@@ -379,6 +379,9 @@ static void hns_ae_stop(struct hnae_handle *handle)
 
hns_ae_ring_enable_all(handle, 0);
 
+   /* clean rx fbd. */
+   hns_rcb_wait_fbd_clean(handle->qs, handle->q_num, RCB_INT_FLAG_RX);
+
(void)hns_mac_vm_config_bc_en(mac_cb, 0, false);
 }
 
-- 
1.9.1



[Patch net 08/10] net: hns: Fix ntuple-filters status error.

2018-12-14 Thread Peng Li
From: Yonglong Liu 

The ntuple-filters features is forced on by chip.
But it shows "ntuple-filters: off [fixed]" when use ethtool.
This patch make it correct with "ntuple-filters: on [fixed]".

Signed-off-by: Yonglong Liu 
Signed-off-by: Peng Li 
---
 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 8a53c82..6242249 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -2374,7 +2374,7 @@ static int hns_nic_dev_probe(struct platform_device *pdev)
ndev->min_mtu = MAC_MIN_MTU;
switch (priv->enet_ver) {
case AE_VERSION_2:
-   ndev->features |= NETIF_F_TSO | NETIF_F_TSO6;
+   ndev->features |= NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_NTUPLE;
ndev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_GSO |
NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6;
-- 
1.9.1



[Patch net 09/10] net: hns: Add mac pcs config when enable|disable mac

2018-12-14 Thread Peng Li
From: Yonglong Liu 

In some case, when mac enable|disable and adjust link, may cause hard to
link(or abnormal) between mac and phy. This patch adds the code for rx PCS
to avoid this bug.

Disable the rx PCS when driver disable the gmac, and enable the rx PCS
when driver enable the mac.

Signed-off-by: Yonglong Liu 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c | 14 ++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h  |  1 +
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
index aaf72c0..1790cda 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
@@ -67,11 +67,14 @@ static void hns_gmac_enable(void *mac_drv, enum 
mac_commom_mode mode)
struct mac_driver *drv = (struct mac_driver *)mac_drv;
 
/*enable GE rX/tX */
-   if ((mode == MAC_COMM_MODE_TX) || (mode == MAC_COMM_MODE_RX_AND_TX))
+   if (mode == MAC_COMM_MODE_TX || mode == MAC_COMM_MODE_RX_AND_TX)
dsaf_set_dev_bit(drv, GMAC_PORT_EN_REG, GMAC_PORT_TX_EN_B, 1);
 
-   if ((mode == MAC_COMM_MODE_RX) || (mode == MAC_COMM_MODE_RX_AND_TX))
+   if (mode == MAC_COMM_MODE_RX || mode == MAC_COMM_MODE_RX_AND_TX) {
+   /* enable rx pcs */
+   dsaf_set_dev_bit(drv, GMAC_PCS_RX_EN_REG, 0, 0);
dsaf_set_dev_bit(drv, GMAC_PORT_EN_REG, GMAC_PORT_RX_EN_B, 1);
+   }
 }
 
 static void hns_gmac_disable(void *mac_drv, enum mac_commom_mode mode)
@@ -79,11 +82,14 @@ static void hns_gmac_disable(void *mac_drv, enum 
mac_commom_mode mode)
struct mac_driver *drv = (struct mac_driver *)mac_drv;
 
/*disable GE rX/tX */
-   if ((mode == MAC_COMM_MODE_TX) || (mode == MAC_COMM_MODE_RX_AND_TX))
+   if (mode == MAC_COMM_MODE_TX || mode == MAC_COMM_MODE_RX_AND_TX)
dsaf_set_dev_bit(drv, GMAC_PORT_EN_REG, GMAC_PORT_TX_EN_B, 0);
 
-   if ((mode == MAC_COMM_MODE_RX) || (mode == MAC_COMM_MODE_RX_AND_TX))
+   if (mode == MAC_COMM_MODE_RX || mode == MAC_COMM_MODE_RX_AND_TX) {
+   /* disable rx pcs */
+   dsaf_set_dev_bit(drv, GMAC_PCS_RX_EN_REG, 0, 1);
dsaf_set_dev_bit(drv, GMAC_PORT_EN_REG, GMAC_PORT_RX_EN_B, 0);
+   }
 }
 
 /* hns_gmac_get_en - get port enable
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h
index f171d11..b9733b0 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h
@@ -534,6 +534,7 @@
 #define GMAC_LD_LINK_COUNTER_REG   0x01D0UL
 #define GMAC_LOOP_REG  0x01DCUL
 #define GMAC_RECV_CONTROL_REG  0x01E0UL
+#define GMAC_PCS_RX_EN_REG 0x01E4UL
 #define GMAC_VLAN_CODE_REG 0x01E8UL
 #define GMAC_RX_OVERRUN_CNT_REG0x01ECUL
 #define GMAC_RX_LENGTHFIELD_ERR_CNT_REG0x01F4UL
-- 
1.9.1



[Patch net 00/10] net: hns: Code improvements & fixes for HNS driver

2018-12-14 Thread Peng Li
This patchset introduces some code improvements and fixes
for the identified problems in the HNS driver.

Every patch is independent.

Yonglong Liu (10):
  net: hns: Incorrect offset address used for some registers.
  net: hns: All ports can not work when insmod hns ko after rmmod.
  net: hns: some registers use wrong address according to the datasheet.
  net: hns: fixed bug that netdev was opened twice
  net: hns: clean rx fbd when ae stopped.
  net: hns: free irq when exit from abnormal branch
  net: hns: Avoid net reset caused by pause frames storm
  net: hns: Fix ntuple-filters status error.
  net: hns: Add mac pcs config when enable|disable mac
  net: hns: fix ping failed when use net bridge and send multicast

 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  |   3 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c |  14 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  |  15 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 503 ++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h  |  13 +-
 drivers/net/ethernet/hisilicon/hns/hns_enet.c  |  43 +-
 6 files changed, 413 insertions(+), 178 deletions(-)

-- 
1.9.1



[Patch net 04/10] net: hns: Fixed bug that netdev was opened twice

2018-12-14 Thread Peng Li
From: Yonglong Liu 

After resetting dsaf to try to repair chip error such as ecc error,
the net device will be open if net interface is up. But at this time
if there is the users set the net device up with the command ifconfig,
the net device will be opened twice consecutively.

Function napi_enable was called when open device. And Kernel panic will
be occurred if it was called twice consecutively. Such as follow:
static inline void napi_enable(struct napi_struct *n)
{
 BUG_ON(!test_bit(NAPI_STATE_SCHED, >state));
 smp_mb__before_clear_bit();
 clear_bit(NAPI_STATE_SCHED, >state);
}

[37255.571996] Kernel panic - not syncing: BUG!
[37255.595234] Call trace:
[37255.597694] [] dump_backtrace+0x0/0x1a0
[37255.603114] [] show_stack+0x20/0x28
[37255.608187] [] dump_stack+0x98/0xb8
[37255.613258] [] panic+0x10c/0x26c
[37255.618070] [] hns_nic_net_up+0x30c/0x4e0
[37255.623664] [] hns_nic_net_open+0x94/0x12c
[37255.629346] [] __dev_open+0xf4/0x168
[37255.634504] [] __dev_change_flags+0x98/0x15c
[37255.640359] [] dev_change_flags+0x2c/0x68
[37255.769580] [] devinet_ioctl+0x650/0x704
[37255.775086] [] inet_ioctl+0x98/0xb4
[37255.780159] [] sock_do_ioctl+0x44/0x84
[37255.785490] [] sock_ioctl+0x248/0x30c
[37255.790737] [] do_vfs_ioctl+0x480/0x618
[37255.796156] [] SyS_ioctl+0x90/0xa4
[37255.801139] SMP: stopping secondary CPUs
[37255.805079] kbox: catch panic event.
[37255.809586] collected_len = 128928, LOG_BUF_LEN_LOCAL = 131072
[37255.816103] flush cache 0x80003f00  size 0x80
[37255.822192] flush cache 0x80003f00  size 0x80
[37255.828289] flush cache 0x80003f00  size 0x80
[37255.834378] kbox: no notify die func register. no need to notify
[37255.840413] ---[ end Kernel panic - not syncing: BUG!

This patchset fix this bug according to the flag NIC_STATE_DOWN.

Signed-off-by: Yonglong Liu 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns/hns_enet.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c 
b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
index c205a0e..c9454c4 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
@@ -1333,6 +1333,9 @@ static int hns_nic_net_up(struct net_device *ndev)
int i, j;
int ret;
 
+   if (!test_bit(NIC_STATE_DOWN, >state))
+   return 0;
+
ret = hns_nic_init_irq(priv);
if (ret != 0) {
netdev_err(ndev, "hns init irq failed! ret=%d\n", ret);
-- 
1.9.1



[Patch net 01/10] net: hns: Incorrect offset address used for some registers.

2018-12-14 Thread Peng Li
From: Yonglong Liu 

According to the hip06 Datasheet:
1. The offset of INGRESS_SW_VLAN_TAG_DISC should be 0x1A00+4*all_chn_num
2. The offset of INGRESS_IN_DATA_STP_DISC should be 0x1A50+4*all_chn_num

Signed-off-by: Yonglong Liu 
Signed-off-by: Peng Li 
---
 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 e557a4e..dc9215a 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -2166,9 +2166,9 @@ void hns_dsaf_update_stats(struct dsaf_device *dsaf_dev, 
u32 node_num)
DSAF_INODE_LOCAL_ADDR_FALSE_NUM_0_REG + 0x80 * (u64)node_num);
 
hw_stats->vlan_drop += dsaf_read_dev(dsaf_dev,
-   DSAF_INODE_SW_VLAN_TAG_DISC_0_REG + 0x80 * (u64)node_num);
+   DSAF_INODE_SW_VLAN_TAG_DISC_0_REG + 4 * (u64)node_num);
hw_stats->stp_drop += dsaf_read_dev(dsaf_dev,
-   DSAF_INODE_IN_DATA_STP_DISC_0_REG + 0x80 * (u64)node_num);
+   DSAF_INODE_IN_DATA_STP_DISC_0_REG + 4 * (u64)node_num);
 
/* pfc pause frame statistics stored in dsaf inode*/
if ((node_num < DSAF_SERVICE_NW_NUM) && !is_ver1) {
-- 
1.9.1



[Patch net 10/10] net: hns: Fix ping failed when use net bridge and send multicast

2018-12-14 Thread Peng Li
From: Yonglong Liu 

Create a net bridge, add eth and vnet to the bridge. The vnet is used
by a virtual machine. When ping the virtual machine from the outside
host and the virtual machine send multicast at the same time, the ping
package will lost.

The multicast package send to the eth, eth will send it to the bridge too,
and the bridge learn the mac of eth. When outside host ping the virtual
mechine, it will match the promisc entry of the eth which is not expected,
and the bridge send it to eth not to vnet, cause ping lost.

So this patch change promisc tcam entry position to the END of 512 tcam
entries, which indicate lower priority. And separate one promisc entry to
two: mc & uc, to avoid package match the wrong tcam entry.

Signed-off-by: Yonglong Liu 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 257 +
 1 file changed, 216 insertions(+), 41 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index 97d62de..3b9e74b 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -935,6 +935,62 @@ static void hns_dsaf_tcam_mc_cfg(
 }
 
 /**
+ * hns_dsaf_tcam_uc_cfg_vague - INT
+ * @dsaf_dev: dsa fabric device struct pointer
+ * @address,
+ * @ptbl_tcam_data,
+ */
+static void hns_dsaf_tcam_uc_cfg_vague(struct dsaf_device *dsaf_dev,
+  u32 address,
+  struct dsaf_tbl_tcam_data *tcam_data,
+  struct dsaf_tbl_tcam_data *tcam_mask,
+  struct dsaf_tbl_tcam_ucast_cfg *tcam_uc)
+{
+   spin_lock_bh(_dev->tcam_lock);
+   hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
+   hns_dsaf_tbl_tcam_data_cfg(dsaf_dev, tcam_data);
+   hns_dsaf_tbl_tcam_ucast_cfg(dsaf_dev, tcam_uc);
+   hns_dsaf_tbl_tcam_match_cfg(dsaf_dev, tcam_mask);
+   hns_dsaf_tbl_tcam_data_ucast_pul(dsaf_dev);
+
+   /*Restore Match Data*/
+   tcam_mask->tbl_tcam_data_high = 0x;
+   tcam_mask->tbl_tcam_data_low = 0x;
+   hns_dsaf_tbl_tcam_match_cfg(dsaf_dev, tcam_mask);
+
+   spin_unlock_bh(_dev->tcam_lock);
+}
+
+/**
+ * hns_dsaf_tcam_mc_cfg_vague - INT
+ * @dsaf_dev: dsa fabric device struct pointer
+ * @address,
+ * @ptbl_tcam_data,
+ * @ptbl_tcam_mask
+ * @ptbl_tcam_mcast
+ */
+static void hns_dsaf_tcam_mc_cfg_vague(struct dsaf_device *dsaf_dev,
+  u32 address,
+  struct dsaf_tbl_tcam_data *tcam_data,
+  struct dsaf_tbl_tcam_data *tcam_mask,
+  struct dsaf_tbl_tcam_mcast_cfg *tcam_mc)
+{
+   spin_lock_bh(_dev->tcam_lock);
+   hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
+   hns_dsaf_tbl_tcam_data_cfg(dsaf_dev, tcam_data);
+   hns_dsaf_tbl_tcam_mcast_cfg(dsaf_dev, tcam_mc);
+   hns_dsaf_tbl_tcam_match_cfg(dsaf_dev, tcam_mask);
+   hns_dsaf_tbl_tcam_data_mcast_pul(dsaf_dev);
+
+   /*Restore Match Data*/
+   tcam_mask->tbl_tcam_data_high = 0x;
+   tcam_mask->tbl_tcam_data_low = 0x;
+   hns_dsaf_tbl_tcam_match_cfg(dsaf_dev, tcam_mask);
+
+   spin_unlock_bh(_dev->tcam_lock);
+}
+
+/**
  * hns_dsaf_tcam_mc_invld - INT
  * @dsaf_id: dsa fabric id
  * @address
@@ -1493,6 +1549,27 @@ static u16 hns_dsaf_find_empty_mac_entry(struct 
dsaf_device *dsaf_dev)
 }
 
 /**
+ * hns_dsaf_find_empty_mac_entry_reverse
+ * search dsa fabric soft empty-entry from the end
+ * @dsaf_dev: dsa fabric device struct pointer
+ */
+static u16 hns_dsaf_find_empty_mac_entry_reverse(struct dsaf_device *dsaf_dev)
+{
+   struct dsaf_drv_priv *priv = hns_dsaf_dev_priv(dsaf_dev);
+   struct dsaf_drv_soft_mac_tbl *soft_mac_entry;
+   int i;
+
+   soft_mac_entry = priv->soft_mac_tbl + (DSAF_TCAM_SUM - 1);
+   for (i = (DSAF_TCAM_SUM - 1); i > 0; i--) {
+   /* search all entry from end to start.*/
+   if (soft_mac_entry->index == DSAF_INVALID_ENTRY_IDX)
+   return i;
+   soft_mac_entry--;
+   }
+   return DSAF_INVALID_ENTRY_IDX;
+}
+
+/**
  * hns_dsaf_set_mac_key - set mac key
  * @dsaf_dev: dsa fabric device struct pointer
  * @mac_key: tcam key pointer
@@ -2673,58 +2750,156 @@ int hns_dsaf_get_regs_count(void)
return DSAF_DUMP_REGS_NUM;
 }
 
-/* Reserve the last TCAM entry for promisc support */
-#define dsaf_promisc_tcam_entry(port) \
-   (DSAF_TCAM_SUM - DSAFV2_MAC_FUZZY_TCAM_NUM + (port))
-void hns_dsaf_set_promisc_tcam(struct dsaf_device *dsaf_dev,
-  u32 port, bool enable)
+static void set_promisc_tcam_enable(struct dsaf_device *dsaf_dev, u32 port)
 {
+   struct dsaf_tbl_tcam_ucast_cfg tbl_tcam_ucast = {0, 1, 0, 0, 0x8

[Patch net 03/10] net: hns: Some registers use wrong address according to the datasheet.

2018-12-14 Thread Peng Li
From: Yonglong Liu 

According to the hip06 datasheet:
1.Six registers use wrong address:
  RCB_COM_SF_CFG_INTMASK_RING
  RCB_COM_SF_CFG_RING_STS
  RCB_COM_SF_CFG_RING
  RCB_COM_SF_CFG_INTMASK_BD
  RCB_COM_SF_CFG_BD_RINT_STS
  DSAF_INODE_VC1_IN_PKT_NUM_0_REG
2.The offset of DSAF_INODE_VC1_IN_PKT_NUM_0_REG should be
  0x103C + 0x80 * all_chn_num
3.The offset to show the value of DSAF_INODE_IN_DATA_STP_DISC_0_REG
  is wrong, so the value of DSAF_INODE_SW_VLAN_TAG_DISC_0_REG will be
  overwrite

These registers are only used in "ethtool -d", so that did not cause ndev
to misfunction.

Signed-off-by: Yonglong Liu 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 242 ++---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h  |  12 +-
 2 files changed, 127 insertions(+), 127 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index dc9215a..97d62de 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -2285,237 +2285,237 @@ void hns_dsaf_get_regs(struct dsaf_device *ddev, u32 
port, void *data)
DSAF_INODE_BD_ORDER_STATUS_0_REG + j * 4);
p[223 + i] = dsaf_read_dev(ddev,
DSAF_INODE_SW_VLAN_TAG_DISC_0_REG + j * 4);
-   p[224 + i] = dsaf_read_dev(ddev,
+   p[226 + i] = dsaf_read_dev(ddev,
DSAF_INODE_IN_DATA_STP_DISC_0_REG + j * 4);
}
 
-   p[227] = dsaf_read_dev(ddev, DSAF_INODE_GE_FC_EN_0_REG + port * 4);
+   p[229] = dsaf_read_dev(ddev, DSAF_INODE_GE_FC_EN_0_REG + port * 4);
 
for (i = 0; i < DSAF_INODE_NUM / DSAF_COMM_CHN; i++) {
j = i * DSAF_COMM_CHN + port;
-   p[228 + i] = dsaf_read_dev(ddev,
+   p[230 + i] = dsaf_read_dev(ddev,
DSAF_INODE_VC0_IN_PKT_NUM_0_REG + j * 4);
}
 
-   p[231] = dsaf_read_dev(ddev,
-   DSAF_INODE_VC1_IN_PKT_NUM_0_REG + port * 4);
+   p[233] = dsaf_read_dev(ddev,
+   DSAF_INODE_VC1_IN_PKT_NUM_0_REG + port * 0x80);
 
/* dsaf inode registers */
for (i = 0; i < HNS_DSAF_SBM_NUM(ddev) / DSAF_COMM_CHN; i++) {
j = i * DSAF_COMM_CHN + port;
-   p[232 + i] = dsaf_read_dev(ddev,
+   p[234 + i] = dsaf_read_dev(ddev,
DSAF_SBM_CFG_REG_0_REG + j * 0x80);
-   p[235 + i] = dsaf_read_dev(ddev,
+   p[237 + i] = dsaf_read_dev(ddev,
DSAF_SBM_BP_CFG_0_XGE_REG_0_REG + j * 0x80);
-   p[238 + i] = dsaf_read_dev(ddev,
+   p[240 + i] = dsaf_read_dev(ddev,
DSAF_SBM_BP_CFG_1_REG_0_REG + j * 0x80);
-   p[241 + i] = dsaf_read_dev(ddev,
+   p[243 + i] = dsaf_read_dev(ddev,
DSAF_SBM_BP_CFG_2_XGE_REG_0_REG + j * 0x80);
-   p[244 + i] = dsaf_read_dev(ddev,
+   p[246 + i] = dsaf_read_dev(ddev,
DSAF_SBM_FREE_CNT_0_0_REG + j * 0x80);
-   p[245 + i] = dsaf_read_dev(ddev,
+   p[249 + i] = dsaf_read_dev(ddev,
DSAF_SBM_FREE_CNT_1_0_REG + j * 0x80);
-   p[248 + i] = dsaf_read_dev(ddev,
+   p[252 + i] = dsaf_read_dev(ddev,
DSAF_SBM_BP_CNT_0_0_REG + j * 0x80);
-   p[251 + i] = dsaf_read_dev(ddev,
+   p[255 + i] = dsaf_read_dev(ddev,
DSAF_SBM_BP_CNT_1_0_REG + j * 0x80);
-   p[254 + i] = dsaf_read_dev(ddev,
+   p[258 + i] = dsaf_read_dev(ddev,
DSAF_SBM_BP_CNT_2_0_REG + j * 0x80);
-   p[257 + i] = dsaf_read_dev(ddev,
+   p[261 + i] = dsaf_read_dev(ddev,
DSAF_SBM_BP_CNT_3_0_REG + j * 0x80);
-   p[260 + i] = dsaf_read_dev(ddev,
+   p[264 + i] = dsaf_read_dev(ddev,
DSAF_SBM_INER_ST_0_REG + j * 0x80);
-   p[263 + i] = dsaf_read_dev(ddev,
+   p[267 + i] = dsaf_read_dev(ddev,
DSAF_SBM_MIB_REQ_FAILED_TC_0_REG + j * 0x80);
-   p[266 + i] = dsaf_read_dev(ddev,
+   p[270 + i] = dsaf_read_dev(ddev,
DSAF_SBM_LNK_INPORT_CNT_0_REG + j * 0x80);
-   p[269 + i] = dsaf_read_dev(ddev,
+   p[273 + i] = dsaf_read_dev(ddev,
DSAF_SBM_LNK_DROP_CNT_0_REG + j * 0x80);
-   p[272 + i] = dsaf_read_dev(ddev,
+   p[276 + i] = dsaf_read_dev(ddev,
DSAF_SBM_INF_OUTPORT_CNT_0_REG + j * 0x80);
-   p[275 + i] = ds

[PATCH V2 net 0/2] net: hns: fix some bugs about speed and duplex change

2018-08-26 Thread Peng Li
If there are packets in hardware when changing the spped
or duplex, it may cause hardware hang up.

This patchset adds the code for waiting chip to clean the all
pkts(TX & RX) in chip when the driver uses the function named
"adjust link".

This patchset cleans the pkts as follows:
1) close rx of chip, close tx of protocol stack.
2) wait rcb, ppe, mac to clean.
3) adjust link
4) open rx of chip, open tx of protocol stack.

---
Change log:
V1 -> V2:
1, remove a patch according to the comment reported by Andrew Lunn.
---
Peng Li (2):
  net: hns: add the code for cleaning pkt in chip
  net: hns: add netif_carrier_off before change speed and duplex

 drivers/net/ethernet/hisilicon/hns/hnae.h  |  2 +
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  | 67 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c | 36 
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 44 ++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h  |  8 +++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 29 ++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h |  3 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c  | 23 
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.h  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c  | 23 
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.h  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_enet.c  | 21 ++-
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   |  2 +
 14 files changed, 257 insertions(+), 4 deletions(-)

-- 
2.9.3



[PATCH V2 net 0/2] net: hns: fix some bugs about speed and duplex change

2018-08-26 Thread Peng Li
If there are packets in hardware when changing the spped
or duplex, it may cause hardware hang up.

This patchset adds the code for waiting chip to clean the all
pkts(TX & RX) in chip when the driver uses the function named
"adjust link".

This patchset cleans the pkts as follows:
1) close rx of chip, close tx of protocol stack.
2) wait rcb, ppe, mac to clean.
3) adjust link
4) open rx of chip, open tx of protocol stack.

---
Change log:
V1 -> V2:
1, remove a patch according to the comment reported by Andrew Lunn.
---
Peng Li (2):
  net: hns: add the code for cleaning pkt in chip
  net: hns: add netif_carrier_off before change speed and duplex

 drivers/net/ethernet/hisilicon/hns/hnae.h  |  2 +
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  | 67 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c | 36 
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 44 ++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h  |  8 +++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 29 ++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h |  3 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c  | 23 
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.h  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c  | 23 
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.h  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_enet.c  | 21 ++-
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   |  2 +
 14 files changed, 257 insertions(+), 4 deletions(-)

-- 
2.9.3



[PATCH V2 net 2/2] net: hns: add netif_carrier_off before change speed and duplex

2018-08-26 Thread Peng Li
If there are packets in hardware when changing the speed
or duplex, it may cause hardware hang up.

This patch adds netif_carrier_off before change speed and
duplex in ethtool_ops.set_link_ksettings, and adds
netif_carrier_on after complete the change.

Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
index 08f3c47..774beda 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
@@ -243,7 +243,9 @@ static int hns_nic_set_link_ksettings(struct net_device 
*net_dev,
}
 
if (h->dev->ops->adjust_link) {
+   netif_carrier_off(net_dev);
h->dev->ops->adjust_link(h, (int)speed, cmd->base.duplex);
+   netif_carrier_on(net_dev);
return 0;
}
 
-- 
2.9.3



[PATCH V2 net 1/2] net: hns: add the code for cleaning pkt in chip

2018-08-26 Thread Peng Li
If there are packets in hardware when changing the speed
or duplex, it may cause hardware hang up.

This patch adds the code for waiting chip to clean the all
pkts(TX & RX) in chip when the driver uses the function named
"adjust link".

This patch cleans the pkts as follows:
1) close rx of chip, close tx of protocol stack.
2) wait rcb, ppe, mac to clean.
3) adjust link
4) open rx of chip, open tx of protocol stack.

Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns/hnae.h  |  2 +
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  | 67 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c | 36 
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 44 ++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h  |  8 +++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 29 ++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h |  3 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c  | 23 
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.h  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c  | 23 
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.h  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_enet.c  | 21 ++-
 13 files changed, 255 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.h 
b/drivers/net/ethernet/hisilicon/hns/hnae.h
index cad52bd..08a750f 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.h
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.h
@@ -486,6 +486,8 @@ struct hnae_ae_ops {
u8 *auto_neg, u16 *speed, u8 *duplex);
void (*toggle_ring_irq)(struct hnae_ring *ring, u32 val);
void (*adjust_link)(struct hnae_handle *handle, int speed, int duplex);
+   bool (*need_adjust_link)(struct hnae_handle *handle,
+int speed, int duplex);
int (*set_loopback)(struct hnae_handle *handle,
enum hnae_loop loop_mode, int en);
void (*get_ring_bdnum_limit)(struct hnae_queue *queue,
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
index e6aad30..b52029e 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
@@ -155,6 +155,41 @@ static void hns_ae_put_handle(struct hnae_handle *handle)
hns_ae_get_ring_pair(handle->qs[i])->used_by_vf = 0;
 }
 
+static int hns_ae_wait_flow_down(struct hnae_handle *handle)
+{
+   struct dsaf_device *dsaf_dev;
+   struct hns_ppe_cb *ppe_cb;
+   struct hnae_vf_cb *vf_cb;
+   int ret;
+   int i;
+
+   for (i = 0; i < handle->q_num; i++) {
+   ret = hns_rcb_wait_tx_ring_clean(handle->qs[i]);
+   if (ret)
+   return ret;
+   }
+
+   ppe_cb = hns_get_ppe_cb(handle);
+   ret = hns_ppe_wait_tx_fifo_clean(ppe_cb);
+   if (ret)
+   return ret;
+
+   dsaf_dev = hns_ae_get_dsaf_dev(handle->dev);
+   if (!dsaf_dev)
+   return -EINVAL;
+   ret = hns_dsaf_wait_pkt_clean(dsaf_dev, handle->dport_id);
+   if (ret)
+   return ret;
+
+   vf_cb = hns_ae_get_vf_cb(handle);
+   ret = hns_mac_wait_fifo_clean(vf_cb->mac_cb);
+   if (ret)
+   return ret;
+
+   mdelay(10);
+   return 0;
+}
+
 static void hns_ae_ring_enable_all(struct hnae_handle *handle, int val)
 {
int q_num = handle->q_num;
@@ -399,12 +434,41 @@ static int hns_ae_get_mac_info(struct hnae_handle *handle,
return hns_mac_get_port_info(mac_cb, auto_neg, speed, duplex);
 }
 
+static bool hns_ae_need_adjust_link(struct hnae_handle *handle, int speed,
+   int duplex)
+{
+   struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
+
+   return hns_mac_need_adjust_link(mac_cb, speed, duplex);
+}
+
 static void hns_ae_adjust_link(struct hnae_handle *handle, int speed,
   int duplex)
 {
struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
 
-   hns_mac_adjust_link(mac_cb, speed, duplex);
+   switch (mac_cb->dsaf_dev->dsaf_ver) {
+   case AE_VERSION_1:
+   hns_mac_adjust_link(mac_cb, speed, duplex);
+   break;
+
+   case AE_VERSION_2:
+   /* chip need to clear all pkt inside */
+   hns_mac_disable(mac_cb, MAC_COMM_MODE_RX);
+   if (hns_ae_wait_flow_down(handle)) {
+   hns_mac_enable(mac_cb, MAC_COMM_MODE_RX);
+   break;
+   }
+
+   hns_mac_adjust_link(mac_cb, speed, duplex);
+   hns_mac_enable(mac_cb, MAC_COMM_MODE_RX);
+   break;
+
+   default:
+   break;
+   }
+
+   return;
 }
 
 static void hns_ae_get_ring_bdnum_l

[PATCH V2 net 2/2] net: hns: add netif_carrier_off before change speed and duplex

2018-08-26 Thread Peng Li
If there are packets in hardware when changing the speed
or duplex, it may cause hardware hang up.

This patch adds netif_carrier_off before change speed and
duplex in ethtool_ops.set_link_ksettings, and adds
netif_carrier_on after complete the change.

Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
index 08f3c47..774beda 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
@@ -243,7 +243,9 @@ static int hns_nic_set_link_ksettings(struct net_device 
*net_dev,
}
 
if (h->dev->ops->adjust_link) {
+   netif_carrier_off(net_dev);
h->dev->ops->adjust_link(h, (int)speed, cmd->base.duplex);
+   netif_carrier_on(net_dev);
return 0;
}
 
-- 
2.9.3



[PATCH V2 net 1/2] net: hns: add the code for cleaning pkt in chip

2018-08-26 Thread Peng Li
If there are packets in hardware when changing the speed
or duplex, it may cause hardware hang up.

This patch adds the code for waiting chip to clean the all
pkts(TX & RX) in chip when the driver uses the function named
"adjust link".

This patch cleans the pkts as follows:
1) close rx of chip, close tx of protocol stack.
2) wait rcb, ppe, mac to clean.
3) adjust link
4) open rx of chip, open tx of protocol stack.

Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns/hnae.h  |  2 +
 drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c  | 67 +-
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c | 36 
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c  | 44 ++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h  |  8 +++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 29 ++
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h |  3 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.c  | 23 
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_ppe.h  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c  | 23 
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.h  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h  |  1 +
 drivers/net/ethernet/hisilicon/hns/hns_enet.c  | 21 ++-
 13 files changed, 255 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns/hnae.h 
b/drivers/net/ethernet/hisilicon/hns/hnae.h
index cad52bd..08a750f 100644
--- a/drivers/net/ethernet/hisilicon/hns/hnae.h
+++ b/drivers/net/ethernet/hisilicon/hns/hnae.h
@@ -486,6 +486,8 @@ struct hnae_ae_ops {
u8 *auto_neg, u16 *speed, u8 *duplex);
void (*toggle_ring_irq)(struct hnae_ring *ring, u32 val);
void (*adjust_link)(struct hnae_handle *handle, int speed, int duplex);
+   bool (*need_adjust_link)(struct hnae_handle *handle,
+int speed, int duplex);
int (*set_loopback)(struct hnae_handle *handle,
enum hnae_loop loop_mode, int en);
void (*get_ring_bdnum_limit)(struct hnae_queue *queue,
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c 
b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
index e6aad30..b52029e 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
@@ -155,6 +155,41 @@ static void hns_ae_put_handle(struct hnae_handle *handle)
hns_ae_get_ring_pair(handle->qs[i])->used_by_vf = 0;
 }
 
+static int hns_ae_wait_flow_down(struct hnae_handle *handle)
+{
+   struct dsaf_device *dsaf_dev;
+   struct hns_ppe_cb *ppe_cb;
+   struct hnae_vf_cb *vf_cb;
+   int ret;
+   int i;
+
+   for (i = 0; i < handle->q_num; i++) {
+   ret = hns_rcb_wait_tx_ring_clean(handle->qs[i]);
+   if (ret)
+   return ret;
+   }
+
+   ppe_cb = hns_get_ppe_cb(handle);
+   ret = hns_ppe_wait_tx_fifo_clean(ppe_cb);
+   if (ret)
+   return ret;
+
+   dsaf_dev = hns_ae_get_dsaf_dev(handle->dev);
+   if (!dsaf_dev)
+   return -EINVAL;
+   ret = hns_dsaf_wait_pkt_clean(dsaf_dev, handle->dport_id);
+   if (ret)
+   return ret;
+
+   vf_cb = hns_ae_get_vf_cb(handle);
+   ret = hns_mac_wait_fifo_clean(vf_cb->mac_cb);
+   if (ret)
+   return ret;
+
+   mdelay(10);
+   return 0;
+}
+
 static void hns_ae_ring_enable_all(struct hnae_handle *handle, int val)
 {
int q_num = handle->q_num;
@@ -399,12 +434,41 @@ static int hns_ae_get_mac_info(struct hnae_handle *handle,
return hns_mac_get_port_info(mac_cb, auto_neg, speed, duplex);
 }
 
+static bool hns_ae_need_adjust_link(struct hnae_handle *handle, int speed,
+   int duplex)
+{
+   struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
+
+   return hns_mac_need_adjust_link(mac_cb, speed, duplex);
+}
+
 static void hns_ae_adjust_link(struct hnae_handle *handle, int speed,
   int duplex)
 {
struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle);
 
-   hns_mac_adjust_link(mac_cb, speed, duplex);
+   switch (mac_cb->dsaf_dev->dsaf_ver) {
+   case AE_VERSION_1:
+   hns_mac_adjust_link(mac_cb, speed, duplex);
+   break;
+
+   case AE_VERSION_2:
+   /* chip need to clear all pkt inside */
+   hns_mac_disable(mac_cb, MAC_COMM_MODE_RX);
+   if (hns_ae_wait_flow_down(handle)) {
+   hns_mac_enable(mac_cb, MAC_COMM_MODE_RX);
+   break;
+   }
+
+   hns_mac_adjust_link(mac_cb, speed, duplex);
+   hns_mac_enable(mac_cb, MAC_COMM_MODE_RX);
+   break;
+
+   default:
+   break;
+   }
+
+   return;
 }
 
 static void hns_ae_get_ring_bdnum_l

[PATCH net-next 1/5] net: hns3: fix for returning wrong value problem in hns3_get_rss_key_size

2018-03-23 Thread Peng Li
From: Fuyun Liang <liangfuy...@huawei.com>

The return type of hns3_get_rss_key_size is u32. But a negative value is
returned. This patch fixes it by replacing the negative value with zero.

Signed-off-by: Fuyun Liang <liangfuy...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index 9d07116..ac523c9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -638,7 +638,7 @@ static u32 hns3_get_rss_key_size(struct net_device *netdev)
 
if (!h->ae_algo || !h->ae_algo->ops ||
!h->ae_algo->ops->get_rss_key_size)
-   return -EOPNOTSUPP;
+   return 0;
 
return h->ae_algo->ops->get_rss_key_size(h);
 }
-- 
2.9.3



[PATCH net-next 4/5] net: hns3: fix for not initializing VF rss_hash_key problem

2018-03-23 Thread Peng Li
From: Fuyun Liang <liangfuy...@huawei.com>

Default rss_hash_key value should be given to all vports. But just the
PF rss_hash_key has the default value here. This patch adds rss_hash_key
Initialization for all vports.

Signed-off-by: Fuyun Liang <liangfuy...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index bede411..ce093c3 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3466,8 +3466,6 @@ static void hclge_rss_init_cfg(struct hclge_dev *hdev)
struct hclge_vport *vport = hdev->vport;
int i;
 
-   netdev_rss_key_fill(vport->rss_hash_key, HCLGE_RSS_KEY_SIZE);
-
for (i = 0; i < hdev->num_vmdq_vport + 1; i++) {
vport[i].rss_tuple_sets.ipv4_tcp_en =
HCLGE_RSS_INPUT_TUPLE_OTHER;
@@ -3487,6 +3485,8 @@ static void hclge_rss_init_cfg(struct hclge_dev *hdev)
HCLGE_RSS_INPUT_TUPLE_OTHER;
 
vport[i].rss_algo = HCLGE_RSS_HASH_ALGO_TOEPLITZ;
+
+   netdev_rss_key_fill(vport[i].rss_hash_key, HCLGE_RSS_KEY_SIZE);
}
 
hclge_rss_indir_init_cfg(hdev);
-- 
2.9.3



[PATCH net-next 1/5] net: hns3: fix for returning wrong value problem in hns3_get_rss_key_size

2018-03-23 Thread Peng Li
From: Fuyun Liang 

The return type of hns3_get_rss_key_size is u32. But a negative value is
returned. This patch fixes it by replacing the negative value with zero.

Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index 9d07116..ac523c9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -638,7 +638,7 @@ static u32 hns3_get_rss_key_size(struct net_device *netdev)
 
if (!h->ae_algo || !h->ae_algo->ops ||
!h->ae_algo->ops->get_rss_key_size)
-   return -EOPNOTSUPP;
+   return 0;
 
return h->ae_algo->ops->get_rss_key_size(h);
 }
-- 
2.9.3



[PATCH net-next 4/5] net: hns3: fix for not initializing VF rss_hash_key problem

2018-03-23 Thread Peng Li
From: Fuyun Liang 

Default rss_hash_key value should be given to all vports. But just the
PF rss_hash_key has the default value here. This patch adds rss_hash_key
Initialization for all vports.

Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index bede411..ce093c3 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3466,8 +3466,6 @@ static void hclge_rss_init_cfg(struct hclge_dev *hdev)
struct hclge_vport *vport = hdev->vport;
int i;
 
-   netdev_rss_key_fill(vport->rss_hash_key, HCLGE_RSS_KEY_SIZE);
-
for (i = 0; i < hdev->num_vmdq_vport + 1; i++) {
vport[i].rss_tuple_sets.ipv4_tcp_en =
HCLGE_RSS_INPUT_TUPLE_OTHER;
@@ -3487,6 +3485,8 @@ static void hclge_rss_init_cfg(struct hclge_dev *hdev)
HCLGE_RSS_INPUT_TUPLE_OTHER;
 
vport[i].rss_algo = HCLGE_RSS_HASH_ALGO_TOEPLITZ;
+
+   netdev_rss_key_fill(vport[i].rss_hash_key, HCLGE_RSS_KEY_SIZE);
}
 
hclge_rss_indir_init_cfg(hdev);
-- 
2.9.3



[PATCH net-next 5/5] net: hns3: never send command queue message to IMP when reset

2018-03-23 Thread Peng Li
IMP will not handle and command queue message any more when it is
in core/global, driver should not send command queue message to
IMP until reinitialize the NIC HW.

This patch checks the status and avoid the message sent to IMP when
reset.

Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 23 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c|  6 ++
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index ce093c3..2066dd7 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3584,6 +3584,9 @@ static int hclge_unmap_ring_frm_vector(struct 
hnae3_handle *handle,
struct hclge_dev *hdev = vport->back;
int vector_id, ret;
 
+   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
+   return 0;
+
vector_id = hclge_get_vector_index(hdev, vector);
if (vector_id < 0) {
dev_err(>pdev->dev,
@@ -3781,13 +3784,16 @@ static int hclge_ae_start(struct hnae3_handle *handle)
clear_bit(HCLGE_STATE_DOWN, >state);
mod_timer(>service_timer, jiffies + HZ);
 
+   /* reset tqp stats */
+   hclge_reset_tqp_stats(handle);
+
+   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
+   return 0;
+
ret = hclge_mac_start_phy(hdev);
if (ret)
return ret;
 
-   /* reset tqp stats */
-   hclge_reset_tqp_stats(handle);
-
return 0;
 }
 
@@ -3797,6 +3803,12 @@ static void hclge_ae_stop(struct hnae3_handle *handle)
struct hclge_dev *hdev = vport->back;
int i;
 
+   del_timer_sync(>service_timer);
+   cancel_work_sync(>service_task);
+
+   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
+   return;
+
for (i = 0; i < vport->alloc_tqps; i++)
hclge_tqp_enable(hdev, i, 0, false);
 
@@ -3807,8 +3819,6 @@ static void hclge_ae_stop(struct hnae3_handle *handle)
 
/* reset tqp stats */
hclge_reset_tqp_stats(handle);
-   del_timer_sync(>service_timer);
-   cancel_work_sync(>service_task);
hclge_update_link_status(hdev);
 }
 
@@ -4940,6 +4950,9 @@ void hclge_reset_tqp(struct hnae3_handle *handle, u16 
queue_id)
u16 queue_gid;
int ret;
 
+   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
+   return;
+
queue_gid = hclge_covert_handle_qid_global(handle, queue_id);
 
ret = hclge_tqp_enable(hdev, queue_id, 0, false);
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
index c1dea3a..682c2d6 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -60,6 +60,9 @@ static int hclge_mdio_write(struct mii_bus *bus, int phyid, 
int regnum,
struct hclge_desc desc;
int ret;
 
+   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
+   return 0;
+
hclge_cmd_setup_basic_desc(, HCLGE_OPC_MDIO_CONFIG, false);
 
mdio_cmd = (struct hclge_mdio_cfg_cmd *)desc.data;
@@ -95,6 +98,9 @@ static int hclge_mdio_read(struct mii_bus *bus, int phyid, 
int regnum)
struct hclge_desc desc;
int ret;
 
+   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
+   return 0;
+
hclge_cmd_setup_basic_desc(, HCLGE_OPC_MDIO_CONFIG, true);
 
mdio_cmd = (struct hclge_mdio_cfg_cmd *)desc.data;
-- 
2.9.3



[PATCH net-next 5/5] net: hns3: never send command queue message to IMP when reset

2018-03-23 Thread Peng Li
IMP will not handle and command queue message any more when it is
in core/global, driver should not send command queue message to
IMP until reinitialize the NIC HW.

This patch checks the status and avoid the message sent to IMP when
reset.

Signed-off-by: Peng Li 
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 23 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c|  6 ++
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index ce093c3..2066dd7 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3584,6 +3584,9 @@ static int hclge_unmap_ring_frm_vector(struct 
hnae3_handle *handle,
struct hclge_dev *hdev = vport->back;
int vector_id, ret;
 
+   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
+   return 0;
+
vector_id = hclge_get_vector_index(hdev, vector);
if (vector_id < 0) {
dev_err(>pdev->dev,
@@ -3781,13 +3784,16 @@ static int hclge_ae_start(struct hnae3_handle *handle)
clear_bit(HCLGE_STATE_DOWN, >state);
mod_timer(>service_timer, jiffies + HZ);
 
+   /* reset tqp stats */
+   hclge_reset_tqp_stats(handle);
+
+   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
+   return 0;
+
ret = hclge_mac_start_phy(hdev);
if (ret)
return ret;
 
-   /* reset tqp stats */
-   hclge_reset_tqp_stats(handle);
-
return 0;
 }
 
@@ -3797,6 +3803,12 @@ static void hclge_ae_stop(struct hnae3_handle *handle)
struct hclge_dev *hdev = vport->back;
int i;
 
+   del_timer_sync(>service_timer);
+   cancel_work_sync(>service_task);
+
+   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
+   return;
+
for (i = 0; i < vport->alloc_tqps; i++)
hclge_tqp_enable(hdev, i, 0, false);
 
@@ -3807,8 +3819,6 @@ static void hclge_ae_stop(struct hnae3_handle *handle)
 
/* reset tqp stats */
hclge_reset_tqp_stats(handle);
-   del_timer_sync(>service_timer);
-   cancel_work_sync(>service_task);
hclge_update_link_status(hdev);
 }
 
@@ -4940,6 +4950,9 @@ void hclge_reset_tqp(struct hnae3_handle *handle, u16 
queue_id)
u16 queue_gid;
int ret;
 
+   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
+   return;
+
queue_gid = hclge_covert_handle_qid_global(handle, queue_id);
 
ret = hclge_tqp_enable(hdev, queue_id, 0, false);
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
index c1dea3a..682c2d6 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -60,6 +60,9 @@ static int hclge_mdio_write(struct mii_bus *bus, int phyid, 
int regnum,
struct hclge_desc desc;
int ret;
 
+   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
+   return 0;
+
hclge_cmd_setup_basic_desc(, HCLGE_OPC_MDIO_CONFIG, false);
 
mdio_cmd = (struct hclge_mdio_cfg_cmd *)desc.data;
@@ -95,6 +98,9 @@ static int hclge_mdio_read(struct mii_bus *bus, int phyid, 
int regnum)
struct hclge_desc desc;
int ret;
 
+   if (test_bit(HCLGE_STATE_RST_HANDLING, >state))
+   return 0;
+
hclge_cmd_setup_basic_desc(, HCLGE_OPC_MDIO_CONFIG, true);
 
mdio_cmd = (struct hclge_mdio_cfg_cmd *)desc.data;
-- 
2.9.3



[PATCH net-next 3/5] net: hns3: fix for the wrong shift problem in hns3_set_txbd_baseinfo

2018-03-23 Thread Peng Li
From: Fuyun Liang <liangfuy...@huawei.com>

Third parameter of hnae_set_field is shift, But a mask is given. This
patch fixes it by replacing HNS3_TXD_BDTYPE_M with HNS3_TXD_BDTYPE_S.

Signed-off-by: Fuyun Liang <liangfuy...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 40a3eb7..a31b4ad 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -764,7 +764,7 @@ static void hns3_set_txbd_baseinfo(u16 
*bdtp_fe_sc_vld_ra_ri, int frag_end)
 {
/* Config bd buffer end */
hnae_set_field(*bdtp_fe_sc_vld_ra_ri, HNS3_TXD_BDTYPE_M,
-  HNS3_TXD_BDTYPE_M, 0);
+  HNS3_TXD_BDTYPE_S, 0);
hnae_set_bit(*bdtp_fe_sc_vld_ra_ri, HNS3_TXD_FE_B, !!frag_end);
hnae_set_bit(*bdtp_fe_sc_vld_ra_ri, HNS3_TXD_VLD_B, 1);
hnae_set_field(*bdtp_fe_sc_vld_ra_ri, HNS3_TXD_SC_M, HNS3_TXD_SC_S, 0);
-- 
2.9.3



[PATCH net-next 2/5] net: hns3: fix for returning wrong value problem in hns3_get_rss_indir_size

2018-03-23 Thread Peng Li
From: Fuyun Liang <liangfuy...@huawei.com>

The return type of hns3_get_rss_indir_size is u32. But a negative value is
returned. This patch fixes it by replacing the negative value with zero.

Signed-off-by: Fuyun Liang <liangfuy...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index ac523c9..eb3c34f 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -649,7 +649,7 @@ static u32 hns3_get_rss_indir_size(struct net_device 
*netdev)
 
if (!h->ae_algo || !h->ae_algo->ops ||
!h->ae_algo->ops->get_rss_indir_size)
-   return -EOPNOTSUPP;
+   return 0;
 
return h->ae_algo->ops->get_rss_indir_size(h);
 }
-- 
2.9.3



[PATCH net-next 3/5] net: hns3: fix for the wrong shift problem in hns3_set_txbd_baseinfo

2018-03-23 Thread Peng Li
From: Fuyun Liang 

Third parameter of hnae_set_field is shift, But a mask is given. This
patch fixes it by replacing HNS3_TXD_BDTYPE_M with HNS3_TXD_BDTYPE_S.

Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 40a3eb7..a31b4ad 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -764,7 +764,7 @@ static void hns3_set_txbd_baseinfo(u16 
*bdtp_fe_sc_vld_ra_ri, int frag_end)
 {
/* Config bd buffer end */
hnae_set_field(*bdtp_fe_sc_vld_ra_ri, HNS3_TXD_BDTYPE_M,
-  HNS3_TXD_BDTYPE_M, 0);
+  HNS3_TXD_BDTYPE_S, 0);
hnae_set_bit(*bdtp_fe_sc_vld_ra_ri, HNS3_TXD_FE_B, !!frag_end);
hnae_set_bit(*bdtp_fe_sc_vld_ra_ri, HNS3_TXD_VLD_B, 1);
hnae_set_field(*bdtp_fe_sc_vld_ra_ri, HNS3_TXD_SC_M, HNS3_TXD_SC_S, 0);
-- 
2.9.3



[PATCH net-next 2/5] net: hns3: fix for returning wrong value problem in hns3_get_rss_indir_size

2018-03-23 Thread Peng Li
From: Fuyun Liang 

The return type of hns3_get_rss_indir_size is u32. But a negative value is
returned. This patch fixes it by replacing the negative value with zero.

Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index ac523c9..eb3c34f 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -649,7 +649,7 @@ static u32 hns3_get_rss_indir_size(struct net_device 
*netdev)
 
if (!h->ae_algo || !h->ae_algo->ops ||
!h->ae_algo->ops->get_rss_indir_size)
-   return -EOPNOTSUPP;
+   return 0;
 
return h->ae_algo->ops->get_rss_indir_size(h);
 }
-- 
2.9.3



[PATCH net-next 0/5] fix some bugs for HNS3

2018-03-23 Thread Peng Li
This patchset fixes some bugs for HNS3 driver:
[Patch 1/5 - 2/5] fix 2 return vlaue issues.
[Patch 3/5 - 4/5] fix 2 comments reported by code review.
[Ptach 5/5] avoid sending message to IMP because IMP will not
handle any message when it is resetting.

Fuyun Liang (4):
  net: hns3: fix for returning wrong value problem in
hns3_get_rss_key_size
  net: hns3: fix for returning wrong value problem in
hns3_get_rss_indir_size
  net: hns3: fix for the wrong shift problem in hns3_set_txbd_baseinfo
  net: hns3: fix for not initializing VF rss_hash_key problem

Peng Li (1):
  net: hns3: never send command queue message to IMP when reset

 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c|  2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c |  4 ++--
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 27 --
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c|  6 +
 4 files changed, 29 insertions(+), 10 deletions(-)

-- 
2.9.3



[PATCH net-next 0/5] fix some bugs for HNS3

2018-03-23 Thread Peng Li
This patchset fixes some bugs for HNS3 driver:
[Patch 1/5 - 2/5] fix 2 return vlaue issues.
[Patch 3/5 - 4/5] fix 2 comments reported by code review.
[Ptach 5/5] avoid sending message to IMP because IMP will not
handle any message when it is resetting.

Fuyun Liang (4):
  net: hns3: fix for returning wrong value problem in
hns3_get_rss_key_size
  net: hns3: fix for returning wrong value problem in
hns3_get_rss_indir_size
  net: hns3: fix for the wrong shift problem in hns3_set_txbd_baseinfo
  net: hns3: fix for not initializing VF rss_hash_key problem

Peng Li (1):
  net: hns3: never send command queue message to IMP when reset

 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c|  2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c |  4 ++--
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 27 --
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c|  6 +
 4 files changed, 29 insertions(+), 10 deletions(-)

-- 
2.9.3



[PATCH net-next 02/11] net: hns3: fix the VF queue reset flow error

2018-03-21 Thread Peng Li
VF queue reset flow is different from PF queue reset flow.
VF driver should stop VF queue first, then send message to PF
and PF do the reset. PF should send a response to VF after
PF complete the queue reset, VF can initialize the queue hw
after get the response.
This patch fixes the VF queue reset flow as the correct step.

Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 37 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  1 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c | 11 ---
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  | 10 --
 4 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index e110c65..588f231 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4926,6 +4926,43 @@ void hclge_reset_tqp(struct hnae3_handle *handle, u16 
queue_id)
}
 }
 
+void hclge_reset_vf_queue(struct hclge_vport *vport, u16 queue_id)
+{
+   struct hclge_dev *hdev = vport->back;
+   int reset_try_times = 0;
+   int reset_status;
+   u16 queue_gid;
+   int ret;
+
+   queue_gid = hclge_covert_handle_qid_global(>nic, queue_id);
+
+   ret = hclge_send_reset_tqp_cmd(hdev, queue_gid, true);
+   if (ret) {
+   dev_warn(>pdev->dev,
+"Send reset tqp cmd fail, ret = %d\n", ret);
+   return;
+   }
+
+   reset_try_times = 0;
+   while (reset_try_times++ < HCLGE_TQP_RESET_TRY_TIMES) {
+   /* Wait for tqp hw reset */
+   msleep(20);
+   reset_status = hclge_get_reset_status(hdev, queue_gid);
+   if (reset_status)
+   break;
+   }
+
+   if (reset_try_times >= HCLGE_TQP_RESET_TRY_TIMES) {
+   dev_warn(>pdev->dev, "Reset TQP fail\n");
+   return;
+   }
+
+   ret = hclge_send_reset_tqp_cmd(hdev, queue_gid, false);
+   if (ret)
+   dev_warn(>pdev->dev,
+"Deassert the soft reset fail, ret = %d\n", ret);
+}
+
 static u32 hclge_get_fw_version(struct hnae3_handle *handle)
 {
struct hclge_vport *vport = hclge_get_vport(handle);
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
index 7bff6ef..edbcb73 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
@@ -646,5 +646,6 @@ void hclge_rss_indir_init_cfg(struct hclge_dev *hdev);
 
 void hclge_mbx_handler(struct hclge_dev *hdev);
 void hclge_reset_tqp(struct hnae3_handle *handle, u16 queue_id);
+void hclge_reset_vf_queue(struct hclge_vport *vport, u16 queue_id);
 int hclge_cfg_flowctrl(struct hclge_dev *hdev);
 #endif
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
index 4a49a6b..cef14e7 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
@@ -322,14 +322,17 @@ static int hclge_get_link_info(struct hclge_vport *vport,
  HCLGE_MBX_LINK_STAT_CHANGE, dest_vfid);
 }
 
-static void hclge_reset_vf_queue(struct hclge_vport *vport,
-struct hclge_mbx_vf_to_pf_cmd *mbx_req)
+static void hclge_mbx_reset_vf_queue(struct hclge_vport *vport,
+struct hclge_mbx_vf_to_pf_cmd *mbx_req)
 {
u16 queue_id;
 
memcpy(_id, _req->msg[2], sizeof(queue_id));
 
-   hclge_reset_tqp(>nic, queue_id);
+   hclge_reset_vf_queue(vport, queue_id);
+
+   /* send response msg to VF after queue reset complete*/
+   hclge_gen_resp_to_vf(vport, mbx_req, 0, NULL, 0);
 }
 
 void hclge_mbx_handler(struct hclge_dev *hdev)
@@ -407,7 +410,7 @@ void hclge_mbx_handler(struct hclge_dev *hdev)
ret);
break;
case HCLGE_MBX_QUEUE_RESET:
-   hclge_reset_vf_queue(vport, req);
+   hclge_mbx_reset_vf_queue(vport, req);
break;
default:
dev_err(>pdev->dev,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index 2337025..c96cf03 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -817,11 +817,17 @@ static void hclgevf_reset_tqp(struct hnae3_handle 
*handle, u16 queue_id)
 {
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
u8

[PATCH net-next 02/11] net: hns3: fix the VF queue reset flow error

2018-03-21 Thread Peng Li
VF queue reset flow is different from PF queue reset flow.
VF driver should stop VF queue first, then send message to PF
and PF do the reset. PF should send a response to VF after
PF complete the queue reset, VF can initialize the queue hw
after get the response.
This patch fixes the VF queue reset flow as the correct step.

Signed-off-by: Peng Li 
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 37 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  1 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c | 11 ---
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  | 10 --
 4 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index e110c65..588f231 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4926,6 +4926,43 @@ void hclge_reset_tqp(struct hnae3_handle *handle, u16 
queue_id)
}
 }
 
+void hclge_reset_vf_queue(struct hclge_vport *vport, u16 queue_id)
+{
+   struct hclge_dev *hdev = vport->back;
+   int reset_try_times = 0;
+   int reset_status;
+   u16 queue_gid;
+   int ret;
+
+   queue_gid = hclge_covert_handle_qid_global(>nic, queue_id);
+
+   ret = hclge_send_reset_tqp_cmd(hdev, queue_gid, true);
+   if (ret) {
+   dev_warn(>pdev->dev,
+"Send reset tqp cmd fail, ret = %d\n", ret);
+   return;
+   }
+
+   reset_try_times = 0;
+   while (reset_try_times++ < HCLGE_TQP_RESET_TRY_TIMES) {
+   /* Wait for tqp hw reset */
+   msleep(20);
+   reset_status = hclge_get_reset_status(hdev, queue_gid);
+   if (reset_status)
+   break;
+   }
+
+   if (reset_try_times >= HCLGE_TQP_RESET_TRY_TIMES) {
+   dev_warn(>pdev->dev, "Reset TQP fail\n");
+   return;
+   }
+
+   ret = hclge_send_reset_tqp_cmd(hdev, queue_gid, false);
+   if (ret)
+   dev_warn(>pdev->dev,
+"Deassert the soft reset fail, ret = %d\n", ret);
+}
+
 static u32 hclge_get_fw_version(struct hnae3_handle *handle)
 {
struct hclge_vport *vport = hclge_get_vport(handle);
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
index 7bff6ef..edbcb73 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
@@ -646,5 +646,6 @@ void hclge_rss_indir_init_cfg(struct hclge_dev *hdev);
 
 void hclge_mbx_handler(struct hclge_dev *hdev);
 void hclge_reset_tqp(struct hnae3_handle *handle, u16 queue_id);
+void hclge_reset_vf_queue(struct hclge_vport *vport, u16 queue_id);
 int hclge_cfg_flowctrl(struct hclge_dev *hdev);
 #endif
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
index 4a49a6b..cef14e7 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
@@ -322,14 +322,17 @@ static int hclge_get_link_info(struct hclge_vport *vport,
  HCLGE_MBX_LINK_STAT_CHANGE, dest_vfid);
 }
 
-static void hclge_reset_vf_queue(struct hclge_vport *vport,
-struct hclge_mbx_vf_to_pf_cmd *mbx_req)
+static void hclge_mbx_reset_vf_queue(struct hclge_vport *vport,
+struct hclge_mbx_vf_to_pf_cmd *mbx_req)
 {
u16 queue_id;
 
memcpy(_id, _req->msg[2], sizeof(queue_id));
 
-   hclge_reset_tqp(>nic, queue_id);
+   hclge_reset_vf_queue(vport, queue_id);
+
+   /* send response msg to VF after queue reset complete*/
+   hclge_gen_resp_to_vf(vport, mbx_req, 0, NULL, 0);
 }
 
 void hclge_mbx_handler(struct hclge_dev *hdev)
@@ -407,7 +410,7 @@ void hclge_mbx_handler(struct hclge_dev *hdev)
ret);
break;
case HCLGE_MBX_QUEUE_RESET:
-   hclge_reset_vf_queue(vport, req);
+   hclge_mbx_reset_vf_queue(vport, req);
break;
default:
dev_err(>pdev->dev,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index 2337025..c96cf03 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -817,11 +817,17 @@ static void hclgevf_reset_tqp(struct hnae3_handle 
*handle, u16 queue_id)
 {
struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
u8 msg_d

[PATCH net-next 06/11] net: hns3: change GL update rate

2018-03-21 Thread Peng Li
From: Fuyun Liang <liangfuy...@huawei.com>

The interrupt coalescing self-adaptive function updates the int_gl every
interrupt. The GL update rate is too faster to get a better new GL value.
This patch changes the GL update rate to every one hundred interrupts.
The GL update rate is defined by HNS3_INT_ADAPT_DOWN_START.

Signed-off-by: Fuyun Liang <liangfuy...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 8 
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index f700ec1..e7cf7b4 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -214,6 +214,7 @@ static void hns3_vector_gl_rl_init(struct 
hns3_enet_tqp_vector *tqp_vector,
/* Default: disable RL */
h->kinfo.int_rl_setting = 0;
 
+   tqp_vector->int_adapt_down = HNS3_INT_ADAPT_DOWN_START;
tqp_vector->rx_group.coal.flow_level = HNS3_FLOW_LOW;
tqp_vector->tx_group.coal.flow_level = HNS3_FLOW_LOW;
 }
@@ -2492,6 +2493,11 @@ static void hns3_update_new_int_gl(struct 
hns3_enet_tqp_vector *tqp_vector)
struct hns3_enet_ring_group *tx_group = _vector->tx_group;
bool rx_update, tx_update;
 
+   if (tqp_vector->int_adapt_down > 0) {
+   tqp_vector->int_adapt_down--;
+   return;
+   }
+
if (rx_group->coal.gl_adapt_enable) {
rx_update = hns3_get_new_int_gl(rx_group);
if (rx_update)
@@ -2505,6 +2511,8 @@ static void hns3_update_new_int_gl(struct 
hns3_enet_tqp_vector *tqp_vector)
hns3_set_vector_coalesce_tx_gl(tqp_vector,
   tx_group->coal.int_gl);
}
+
+   tqp_vector->int_adapt_down = HNS3_INT_ADAPT_DOWN_START;
 }
 
 static int hns3_nic_common_poll(struct napi_struct *napi, int budget)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
index c313780..2fe870b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
@@ -462,6 +462,8 @@ enum hns3_link_mode_bits {
 #define HNS3_INT_RL_MAX0x00EC
 #define HNS3_INT_RL_ENABLE_MASK0x40
 
+#define HNS3_INT_ADAPT_DOWN_START  100
+
 struct hns3_enet_coalesce {
u16 int_gl;
u8 gl_adapt_enable;
-- 
2.9.3



[PATCH net-next 10/11] net: hns3: add querying speed and duplex support to VF

2018-03-21 Thread Peng Li
From: Fuyun Liang <liangfuy...@huawei.com>

This patch adds support for querying speed and duplex by ethtool ethX
to VF.

Signed-off-by: Fuyun Liang <liangfuy...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c |  8 ++--
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  | 22 ++
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h  |  4 
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c   |  5 +
 4 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
index cef14e7..949da0c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
@@ -309,16 +309,20 @@ static int hclge_get_link_info(struct hclge_vport *vport,
 {
struct hclge_dev *hdev = vport->back;
u16 link_status;
-   u8 msg_data[2];
+   u8 msg_data[8];
u8 dest_vfid;
+   u16 duplex;
 
/* mac.link can only be 0 or 1 */
link_status = (u16)hdev->hw.mac.link;
+   duplex = hdev->hw.mac.duplex;
memcpy(_data[0], _status, sizeof(u16));
+   memcpy(_data[2], >hw.mac.speed, sizeof(u32));
+   memcpy(_data[6], , sizeof(u16));
dest_vfid = mbx_req->mbx_src_vfid;
 
/* send this requested info to VF */
-   return hclge_send_mbx_msg(vport, msg_data, sizeof(u8),
+   return hclge_send_mbx_msg(vport, msg_data, sizeof(msg_data),
  HCLGE_MBX_LINK_STAT_CHANGE, dest_vfid);
 }
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index f917a1e..906dfa3 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -1475,6 +1475,27 @@ static int hclgevf_get_status(struct hnae3_handle 
*handle)
return hdev->hw.mac.link;
 }
 
+static void hclgevf_get_ksettings_an_result(struct hnae3_handle *handle,
+   u8 *auto_neg, u32 *speed,
+   u8 *duplex)
+{
+   struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
+
+   if (speed)
+   *speed = hdev->hw.mac.speed;
+   if (duplex)
+   *duplex = hdev->hw.mac.duplex;
+   if (auto_neg)
+   *auto_neg = AUTONEG_DISABLE;
+}
+
+void hclgevf_update_speed_duplex(struct hclgevf_dev *hdev, u32 speed,
+u8 duplex)
+{
+   hdev->hw.mac.speed = speed;
+   hdev->hw.mac.duplex = duplex;
+}
+
 static const struct hnae3_ae_ops hclgevf_ops = {
.init_ae_dev = hclgevf_init_ae_dev,
.uninit_ae_dev = hclgevf_uninit_ae_dev,
@@ -1508,6 +1529,7 @@ static const struct hnae3_ae_ops hclgevf_ops = {
.get_channels = hclgevf_get_channels,
.get_tqps_and_rss_info = hclgevf_get_tqps_and_rss_info,
.get_status = hclgevf_get_status,
+   .get_ksettings_an_result = hclgevf_get_ksettings_an_result,
 };
 
 static struct hnae3_ae_algo ae_algovf = {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h
index a63bee4..0eaea06 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h
@@ -61,6 +61,8 @@ enum hclgevf_states {
 struct hclgevf_mac {
u8 mac_addr[ETH_ALEN];
int link;
+   u8 duplex;
+   u32 speed;
 };
 
 struct hclgevf_hw {
@@ -161,4 +163,6 @@ int hclgevf_send_mbx_msg(struct hclgevf_dev *hdev, u16 
code, u16 subcode,
 u8 *resp_data, u16 resp_len);
 void hclgevf_mbx_handler(struct hclgevf_dev *hdev);
 void hclgevf_update_link_status(struct hclgevf_dev *hdev, int link_state);
+void hclgevf_update_speed_duplex(struct hclgevf_dev *hdev, u32 speed,
+u8 duplex);
 #endif
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c
index 9768f71..a63ed3a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c
@@ -133,6 +133,8 @@ void hclgevf_mbx_handler(struct hclgevf_dev *hdev)
struct hclgevf_cmq_ring *crq;
struct hclgevf_desc *desc;
u16 link_status, flag;
+   u32 speed;
+   u8 duplex;
u8 *temp;
int i;
 
@@ -164,9 +166,12 @@ void hclgevf_mbx_handler(struct hclgevf_dev *hdev)
break;
case HCLGE_MBX_LINK_STAT_CHANGE:
link_status = le16_to_cpu(req->msg[1]);
+   memcpy(, >msg[2], sizeof(speed));
+   duplex = (u8)le16_to_cpu(req->

[PATCH net-next 05/11] net: hns3: increase the max time for IMP handle command

2018-03-21 Thread Peng Li
It may need more time for IMP handle some command, such as reset.
This patch enlarges the max time for cmd timeout.

Driver will check the IMP result every us, it may break through the
loop when get the right result. So not all command need the max time.

Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h   | 2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_cmd.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 3fd10a6..aae4abe 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -12,7 +12,7 @@
 #include 
 #include 
 
-#define HCLGE_CMDQ_TX_TIMEOUT  1000
+#define HCLGE_CMDQ_TX_TIMEOUT  3
 
 struct hclge_dev;
 struct hclge_desc {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_cmd.h
index 2caca93..621c6cb 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_cmd.h
@@ -7,7 +7,7 @@
 #include 
 #include "hnae3.h"
 
-#define HCLGEVF_CMDQ_TX_TIMEOUT200
+#define HCLGEVF_CMDQ_TX_TIMEOUT3
 #define HCLGEVF_CMDQ_RX_INVLD_B0
 #define HCLGEVF_CMDQ_RX_OUTVLD_B   1
 
-- 
2.9.3



[PATCH net-next 10/11] net: hns3: add querying speed and duplex support to VF

2018-03-21 Thread Peng Li
From: Fuyun Liang 

This patch adds support for querying speed and duplex by ethtool ethX
to VF.

Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c |  8 ++--
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  | 22 ++
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h  |  4 
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c   |  5 +
 4 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
index cef14e7..949da0c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
@@ -309,16 +309,20 @@ static int hclge_get_link_info(struct hclge_vport *vport,
 {
struct hclge_dev *hdev = vport->back;
u16 link_status;
-   u8 msg_data[2];
+   u8 msg_data[8];
u8 dest_vfid;
+   u16 duplex;
 
/* mac.link can only be 0 or 1 */
link_status = (u16)hdev->hw.mac.link;
+   duplex = hdev->hw.mac.duplex;
memcpy(_data[0], _status, sizeof(u16));
+   memcpy(_data[2], >hw.mac.speed, sizeof(u32));
+   memcpy(_data[6], , sizeof(u16));
dest_vfid = mbx_req->mbx_src_vfid;
 
/* send this requested info to VF */
-   return hclge_send_mbx_msg(vport, msg_data, sizeof(u8),
+   return hclge_send_mbx_msg(vport, msg_data, sizeof(msg_data),
  HCLGE_MBX_LINK_STAT_CHANGE, dest_vfid);
 }
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index f917a1e..906dfa3 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -1475,6 +1475,27 @@ static int hclgevf_get_status(struct hnae3_handle 
*handle)
return hdev->hw.mac.link;
 }
 
+static void hclgevf_get_ksettings_an_result(struct hnae3_handle *handle,
+   u8 *auto_neg, u32 *speed,
+   u8 *duplex)
+{
+   struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
+
+   if (speed)
+   *speed = hdev->hw.mac.speed;
+   if (duplex)
+   *duplex = hdev->hw.mac.duplex;
+   if (auto_neg)
+   *auto_neg = AUTONEG_DISABLE;
+}
+
+void hclgevf_update_speed_duplex(struct hclgevf_dev *hdev, u32 speed,
+u8 duplex)
+{
+   hdev->hw.mac.speed = speed;
+   hdev->hw.mac.duplex = duplex;
+}
+
 static const struct hnae3_ae_ops hclgevf_ops = {
.init_ae_dev = hclgevf_init_ae_dev,
.uninit_ae_dev = hclgevf_uninit_ae_dev,
@@ -1508,6 +1529,7 @@ static const struct hnae3_ae_ops hclgevf_ops = {
.get_channels = hclgevf_get_channels,
.get_tqps_and_rss_info = hclgevf_get_tqps_and_rss_info,
.get_status = hclgevf_get_status,
+   .get_ksettings_an_result = hclgevf_get_ksettings_an_result,
 };
 
 static struct hnae3_ae_algo ae_algovf = {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h
index a63bee4..0eaea06 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h
@@ -61,6 +61,8 @@ enum hclgevf_states {
 struct hclgevf_mac {
u8 mac_addr[ETH_ALEN];
int link;
+   u8 duplex;
+   u32 speed;
 };
 
 struct hclgevf_hw {
@@ -161,4 +163,6 @@ int hclgevf_send_mbx_msg(struct hclgevf_dev *hdev, u16 
code, u16 subcode,
 u8 *resp_data, u16 resp_len);
 void hclgevf_mbx_handler(struct hclgevf_dev *hdev);
 void hclgevf_update_link_status(struct hclgevf_dev *hdev, int link_state);
+void hclgevf_update_speed_duplex(struct hclgevf_dev *hdev, u32 speed,
+u8 duplex);
 #endif
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c
index 9768f71..a63ed3a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c
@@ -133,6 +133,8 @@ void hclgevf_mbx_handler(struct hclgevf_dev *hdev)
struct hclgevf_cmq_ring *crq;
struct hclgevf_desc *desc;
u16 link_status, flag;
+   u32 speed;
+   u8 duplex;
u8 *temp;
int i;
 
@@ -164,9 +166,12 @@ void hclgevf_mbx_handler(struct hclgevf_dev *hdev)
break;
case HCLGE_MBX_LINK_STAT_CHANGE:
link_status = le16_to_cpu(req->msg[1]);
+   memcpy(, >msg[2], sizeof(speed));
+   duplex = (u8)le16_to_cpu(req->msg[4]);
 
/* updat

[PATCH net-next 05/11] net: hns3: increase the max time for IMP handle command

2018-03-21 Thread Peng Li
It may need more time for IMP handle some command, such as reset.
This patch enlarges the max time for cmd timeout.

Driver will check the IMP result every us, it may break through the
loop when get the right result. So not all command need the max time.

Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h   | 2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_cmd.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 3fd10a6..aae4abe 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -12,7 +12,7 @@
 #include 
 #include 
 
-#define HCLGE_CMDQ_TX_TIMEOUT  1000
+#define HCLGE_CMDQ_TX_TIMEOUT  3
 
 struct hclge_dev;
 struct hclge_desc {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_cmd.h
index 2caca93..621c6cb 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_cmd.h
@@ -7,7 +7,7 @@
 #include 
 #include "hnae3.h"
 
-#define HCLGEVF_CMDQ_TX_TIMEOUT200
+#define HCLGEVF_CMDQ_TX_TIMEOUT3
 #define HCLGEVF_CMDQ_RX_INVLD_B0
 #define HCLGEVF_CMDQ_RX_OUTVLD_B   1
 
-- 
2.9.3



[PATCH net-next 06/11] net: hns3: change GL update rate

2018-03-21 Thread Peng Li
From: Fuyun Liang 

The interrupt coalescing self-adaptive function updates the int_gl every
interrupt. The GL update rate is too faster to get a better new GL value.
This patch changes the GL update rate to every one hundred interrupts.
The GL update rate is defined by HNS3_INT_ADAPT_DOWN_START.

Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 8 
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index f700ec1..e7cf7b4 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -214,6 +214,7 @@ static void hns3_vector_gl_rl_init(struct 
hns3_enet_tqp_vector *tqp_vector,
/* Default: disable RL */
h->kinfo.int_rl_setting = 0;
 
+   tqp_vector->int_adapt_down = HNS3_INT_ADAPT_DOWN_START;
tqp_vector->rx_group.coal.flow_level = HNS3_FLOW_LOW;
tqp_vector->tx_group.coal.flow_level = HNS3_FLOW_LOW;
 }
@@ -2492,6 +2493,11 @@ static void hns3_update_new_int_gl(struct 
hns3_enet_tqp_vector *tqp_vector)
struct hns3_enet_ring_group *tx_group = _vector->tx_group;
bool rx_update, tx_update;
 
+   if (tqp_vector->int_adapt_down > 0) {
+   tqp_vector->int_adapt_down--;
+   return;
+   }
+
if (rx_group->coal.gl_adapt_enable) {
rx_update = hns3_get_new_int_gl(rx_group);
if (rx_update)
@@ -2505,6 +2511,8 @@ static void hns3_update_new_int_gl(struct 
hns3_enet_tqp_vector *tqp_vector)
hns3_set_vector_coalesce_tx_gl(tqp_vector,
   tx_group->coal.int_gl);
}
+
+   tqp_vector->int_adapt_down = HNS3_INT_ADAPT_DOWN_START;
 }
 
 static int hns3_nic_common_poll(struct napi_struct *napi, int budget)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
index c313780..2fe870b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
@@ -462,6 +462,8 @@ enum hns3_link_mode_bits {
 #define HNS3_INT_RL_MAX0x00EC
 #define HNS3_INT_RL_ENABLE_MASK0x40
 
+#define HNS3_INT_ADAPT_DOWN_START  100
+
 struct hns3_enet_coalesce {
u16 int_gl;
u8 gl_adapt_enable;
-- 
2.9.3



[PATCH net-next 08/11] net: hns3: fix for getting wrong link mode problem

2018-03-21 Thread Peng Li
From: Fuyun Liang <liangfuy...@huawei.com>

Fixed link mode is returned by hns3_get_link_ksettings. It is
unreasonable.

This patch fixes it by adding some related functions to get link
mode from hardware.

Signed-off-by: Fuyun Liang <liangfuy...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  4 +
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 98 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  2 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 83 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  9 ++
 5 files changed, 107 insertions(+), 89 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index 70441d2..9daa88d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -411,6 +411,10 @@ struct hnae3_ae_ops {
 u32 *flowctrl_adv);
int (*set_led_id)(struct hnae3_handle *handle,
  enum ethtool_phys_id_state status);
+   void (*get_link_mode)(struct hnae3_handle *handle,
+ unsigned long *supported,
+ unsigned long *advertising);
+   void (*get_port_type)(struct hnae3_handle *handle, u8 *port_type);
 };
 
 struct hnae3_dcb_ops {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index 2db127c..502f347 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -74,19 +74,6 @@ struct hns3_link_mode_mapping {
u32 ethtool_link_mode;
 };
 
-static const struct hns3_link_mode_mapping hns3_lm_map[] = {
-   {HNS3_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT},
-   {HNS3_LM_AUTONEG_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT},
-   {HNS3_LM_TP_BIT, ETHTOOL_LINK_MODE_TP_BIT},
-   {HNS3_LM_PAUSE_BIT, ETHTOOL_LINK_MODE_Pause_BIT},
-   {HNS3_LM_BACKPLANE_BIT, ETHTOOL_LINK_MODE_Backplane_BIT},
-   {HNS3_LM_10BASET_HALF_BIT, ETHTOOL_LINK_MODE_10baseT_Half_BIT},
-   {HNS3_LM_10BASET_FULL_BIT, ETHTOOL_LINK_MODE_10baseT_Full_BIT},
-   {HNS3_LM_100BASET_HALF_BIT, ETHTOOL_LINK_MODE_100baseT_Half_BIT},
-   {HNS3_LM_100BASET_FULL_BIT, ETHTOOL_LINK_MODE_100baseT_Full_BIT},
-   {HNS3_LM_1000BASET_FULL_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT},
-};
-
 static int hns3_lp_setup(struct net_device *ndev, enum hnae3_loop loop)
 {
struct hnae3_handle *h = hns3_get_handle(ndev);
@@ -365,24 +352,6 @@ static void hns3_self_test(struct net_device *ndev,
dev_open(ndev);
 }
 
-static void hns3_driv_to_eth_caps(u32 caps, struct ethtool_link_ksettings *cmd,
- bool is_advertised)
-{
-   int i;
-
-   for (i = 0; i < ARRAY_SIZE(hns3_lm_map); i++) {
-   if (!(caps & hns3_lm_map[i].hns3_link_mode))
-   continue;
-
-   if (is_advertised)
-   __set_bit(hns3_lm_map[i].ethtool_link_mode,
- cmd->link_modes.advertising);
-   else
-   __set_bit(hns3_lm_map[i].ethtool_link_mode,
- cmd->link_modes.supported);
-   }
-}
-
 static int hns3_get_sset_count(struct net_device *netdev, int stringset)
 {
struct hnae3_handle *h = hns3_get_handle(netdev);
@@ -594,9 +563,6 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
 {
struct hnae3_handle *h = hns3_get_handle(netdev);
u32 flowctrl_adv = 0;
-   u32 supported_caps;
-   u32 advertised_caps;
-   u8 media_type = HNAE3_MEDIA_TYPE_UNKNOWN;
u8 link_stat;
 
if (!h->ae_algo || !h->ae_algo->ops)
@@ -619,62 +585,16 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
cmd->base.duplex = DUPLEX_UNKNOWN;
}
 
-   /* 2.media_type get from bios parameter block */
-   if (h->ae_algo->ops->get_media_type) {
-   h->ae_algo->ops->get_media_type(h, _type);
+   /* 2.get link mode and port type*/
+   if (h->ae_algo->ops->get_link_mode)
+   h->ae_algo->ops->get_link_mode(h,
+  cmd->link_modes.supported,
+  cmd->link_modes.advertising);
 
-   switch (media_type) {
-   case HNAE3_MEDIA_TYPE_FIBER:
-   cmd->base.port = PORT_FIBRE;
-   supported_caps = HNS3_LM_FIBRE_BIT |
-HNS3_LM_AUTONEG_BIT |
-HNS3_LM_PAUSE_BIT |
-HNS3_LM_1000BASET_FULL_BIT;
-
-

[PATCH net-next 07/11] net: hns3: change the time interval of int_gl calculating

2018-03-21 Thread Peng Li
From: Fuyun Liang <liangfuy...@huawei.com>

Since we change the update rate of int_gl from every interrupt to every
one hundred interrupts, the old way to get time interval by int_gl value
is not accurate. This patch calculates the time interval using the jiffies
value.

Signed-off-by: Fuyun Liang <liangfuy...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 46 -
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h |  1 +
 2 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index e7cf7b4..0b4a676 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2406,15 +2406,15 @@ int hns3_clean_rx_ring(
 
 static bool hns3_get_new_int_gl(struct hns3_enet_ring_group *ring_group)
 {
-#define HNS3_RX_ULTRA_PACKET_RATE 4
+   struct hns3_enet_tqp_vector *tqp_vector =
+   ring_group->ring->tqp_vector;
enum hns3_flow_level_range new_flow_level;
-   struct hns3_enet_tqp_vector *tqp_vector;
-   int packets_per_secs;
-   int bytes_per_usecs;
+   int packets_per_msecs;
+   int bytes_per_msecs;
+   u32 time_passed_ms;
u16 new_int_gl;
-   int usecs;
 
-   if (!ring_group->coal.int_gl)
+   if (!ring_group->coal.int_gl || !tqp_vector->last_jiffies)
return false;
 
if (ring_group->total_packets == 0) {
@@ -2431,33 +2431,44 @@ static bool hns3_get_new_int_gl(struct 
hns3_enet_ring_group *ring_group)
 */
new_flow_level = ring_group->coal.flow_level;
new_int_gl = ring_group->coal.int_gl;
-   tqp_vector = ring_group->ring->tqp_vector;
-   usecs = (ring_group->coal.int_gl << 1);
-   bytes_per_usecs = ring_group->total_bytes / usecs;
-   /* 100 microseconds */
-   packets_per_secs = ring_group->total_packets * 100 / usecs;
+   time_passed_ms =
+   jiffies_to_msecs(jiffies - tqp_vector->last_jiffies);
+
+   if (!time_passed_ms)
+   return false;
+
+   do_div(ring_group->total_packets, time_passed_ms);
+   packets_per_msecs = ring_group->total_packets;
+
+   do_div(ring_group->total_bytes, time_passed_ms);
+   bytes_per_msecs = ring_group->total_bytes;
+
+#define HNS3_RX_LOW_BYTE_RATE 1
+#define HNS3_RX_MID_BYTE_RATE 2
 
switch (new_flow_level) {
case HNS3_FLOW_LOW:
-   if (bytes_per_usecs > 10)
+   if (bytes_per_msecs > HNS3_RX_LOW_BYTE_RATE)
new_flow_level = HNS3_FLOW_MID;
break;
case HNS3_FLOW_MID:
-   if (bytes_per_usecs > 20)
+   if (bytes_per_msecs > HNS3_RX_MID_BYTE_RATE)
new_flow_level = HNS3_FLOW_HIGH;
-   else if (bytes_per_usecs <= 10)
+   else if (bytes_per_msecs <= HNS3_RX_LOW_BYTE_RATE)
new_flow_level = HNS3_FLOW_LOW;
break;
case HNS3_FLOW_HIGH:
case HNS3_FLOW_ULTRA:
default:
-   if (bytes_per_usecs <= 20)
+   if (bytes_per_msecs <= HNS3_RX_MID_BYTE_RATE)
new_flow_level = HNS3_FLOW_MID;
break;
}
 
-   if ((packets_per_secs > HNS3_RX_ULTRA_PACKET_RATE) &&
-   (_vector->rx_group == ring_group))
+#define HNS3_RX_ULTRA_PACKET_RATE 40
+
+   if (packets_per_msecs > HNS3_RX_ULTRA_PACKET_RATE &&
+   _vector->rx_group == ring_group)
new_flow_level = HNS3_FLOW_ULTRA;
 
switch (new_flow_level) {
@@ -2512,6 +2523,7 @@ static void hns3_update_new_int_gl(struct 
hns3_enet_tqp_vector *tqp_vector)
   tx_group->coal.int_gl);
}
 
+   tqp_vector->last_jiffies = jiffies;
tqp_vector->int_adapt_down = HNS3_INT_ADAPT_DOWN_START;
 }
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
index 2fe870b..39daa01 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
@@ -499,6 +499,7 @@ struct hns3_enet_tqp_vector {
 
/* when 0 should adjust interrupt coalesce parameter */
u8 int_adapt_down;
+   unsigned long last_jiffies;
 } cacheline_internodealigned_in_smp;
 
 enum hns3_udp_tnl_type {
-- 
2.9.3



[PATCH net-next 08/11] net: hns3: fix for getting wrong link mode problem

2018-03-21 Thread Peng Li
From: Fuyun Liang 

Fixed link mode is returned by hns3_get_link_ksettings. It is
unreasonable.

This patch fixes it by adding some related functions to get link
mode from hardware.

Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  4 +
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 98 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  2 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 83 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  9 ++
 5 files changed, 107 insertions(+), 89 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index 70441d2..9daa88d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -411,6 +411,10 @@ struct hnae3_ae_ops {
 u32 *flowctrl_adv);
int (*set_led_id)(struct hnae3_handle *handle,
  enum ethtool_phys_id_state status);
+   void (*get_link_mode)(struct hnae3_handle *handle,
+ unsigned long *supported,
+ unsigned long *advertising);
+   void (*get_port_type)(struct hnae3_handle *handle, u8 *port_type);
 };
 
 struct hnae3_dcb_ops {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index 2db127c..502f347 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -74,19 +74,6 @@ struct hns3_link_mode_mapping {
u32 ethtool_link_mode;
 };
 
-static const struct hns3_link_mode_mapping hns3_lm_map[] = {
-   {HNS3_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT},
-   {HNS3_LM_AUTONEG_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT},
-   {HNS3_LM_TP_BIT, ETHTOOL_LINK_MODE_TP_BIT},
-   {HNS3_LM_PAUSE_BIT, ETHTOOL_LINK_MODE_Pause_BIT},
-   {HNS3_LM_BACKPLANE_BIT, ETHTOOL_LINK_MODE_Backplane_BIT},
-   {HNS3_LM_10BASET_HALF_BIT, ETHTOOL_LINK_MODE_10baseT_Half_BIT},
-   {HNS3_LM_10BASET_FULL_BIT, ETHTOOL_LINK_MODE_10baseT_Full_BIT},
-   {HNS3_LM_100BASET_HALF_BIT, ETHTOOL_LINK_MODE_100baseT_Half_BIT},
-   {HNS3_LM_100BASET_FULL_BIT, ETHTOOL_LINK_MODE_100baseT_Full_BIT},
-   {HNS3_LM_1000BASET_FULL_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT},
-};
-
 static int hns3_lp_setup(struct net_device *ndev, enum hnae3_loop loop)
 {
struct hnae3_handle *h = hns3_get_handle(ndev);
@@ -365,24 +352,6 @@ static void hns3_self_test(struct net_device *ndev,
dev_open(ndev);
 }
 
-static void hns3_driv_to_eth_caps(u32 caps, struct ethtool_link_ksettings *cmd,
- bool is_advertised)
-{
-   int i;
-
-   for (i = 0; i < ARRAY_SIZE(hns3_lm_map); i++) {
-   if (!(caps & hns3_lm_map[i].hns3_link_mode))
-   continue;
-
-   if (is_advertised)
-   __set_bit(hns3_lm_map[i].ethtool_link_mode,
- cmd->link_modes.advertising);
-   else
-   __set_bit(hns3_lm_map[i].ethtool_link_mode,
- cmd->link_modes.supported);
-   }
-}
-
 static int hns3_get_sset_count(struct net_device *netdev, int stringset)
 {
struct hnae3_handle *h = hns3_get_handle(netdev);
@@ -594,9 +563,6 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
 {
struct hnae3_handle *h = hns3_get_handle(netdev);
u32 flowctrl_adv = 0;
-   u32 supported_caps;
-   u32 advertised_caps;
-   u8 media_type = HNAE3_MEDIA_TYPE_UNKNOWN;
u8 link_stat;
 
if (!h->ae_algo || !h->ae_algo->ops)
@@ -619,62 +585,16 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
cmd->base.duplex = DUPLEX_UNKNOWN;
}
 
-   /* 2.media_type get from bios parameter block */
-   if (h->ae_algo->ops->get_media_type) {
-   h->ae_algo->ops->get_media_type(h, _type);
+   /* 2.get link mode and port type*/
+   if (h->ae_algo->ops->get_link_mode)
+   h->ae_algo->ops->get_link_mode(h,
+  cmd->link_modes.supported,
+  cmd->link_modes.advertising);
 
-   switch (media_type) {
-   case HNAE3_MEDIA_TYPE_FIBER:
-   cmd->base.port = PORT_FIBRE;
-   supported_caps = HNS3_LM_FIBRE_BIT |
-HNS3_LM_AUTONEG_BIT |
-HNS3_LM_PAUSE_BIT |
-HNS3_LM_1000BASET_FULL_BIT;
-
-   advertised_caps = supported_caps;
-   break;
-   case HNA

[PATCH net-next 07/11] net: hns3: change the time interval of int_gl calculating

2018-03-21 Thread Peng Li
From: Fuyun Liang 

Since we change the update rate of int_gl from every interrupt to every
one hundred interrupts, the old way to get time interval by int_gl value
is not accurate. This patch calculates the time interval using the jiffies
value.

Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 46 -
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h |  1 +
 2 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index e7cf7b4..0b4a676 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2406,15 +2406,15 @@ int hns3_clean_rx_ring(
 
 static bool hns3_get_new_int_gl(struct hns3_enet_ring_group *ring_group)
 {
-#define HNS3_RX_ULTRA_PACKET_RATE 4
+   struct hns3_enet_tqp_vector *tqp_vector =
+   ring_group->ring->tqp_vector;
enum hns3_flow_level_range new_flow_level;
-   struct hns3_enet_tqp_vector *tqp_vector;
-   int packets_per_secs;
-   int bytes_per_usecs;
+   int packets_per_msecs;
+   int bytes_per_msecs;
+   u32 time_passed_ms;
u16 new_int_gl;
-   int usecs;
 
-   if (!ring_group->coal.int_gl)
+   if (!ring_group->coal.int_gl || !tqp_vector->last_jiffies)
return false;
 
if (ring_group->total_packets == 0) {
@@ -2431,33 +2431,44 @@ static bool hns3_get_new_int_gl(struct 
hns3_enet_ring_group *ring_group)
 */
new_flow_level = ring_group->coal.flow_level;
new_int_gl = ring_group->coal.int_gl;
-   tqp_vector = ring_group->ring->tqp_vector;
-   usecs = (ring_group->coal.int_gl << 1);
-   bytes_per_usecs = ring_group->total_bytes / usecs;
-   /* 100 microseconds */
-   packets_per_secs = ring_group->total_packets * 100 / usecs;
+   time_passed_ms =
+   jiffies_to_msecs(jiffies - tqp_vector->last_jiffies);
+
+   if (!time_passed_ms)
+   return false;
+
+   do_div(ring_group->total_packets, time_passed_ms);
+   packets_per_msecs = ring_group->total_packets;
+
+   do_div(ring_group->total_bytes, time_passed_ms);
+   bytes_per_msecs = ring_group->total_bytes;
+
+#define HNS3_RX_LOW_BYTE_RATE 1
+#define HNS3_RX_MID_BYTE_RATE 2
 
switch (new_flow_level) {
case HNS3_FLOW_LOW:
-   if (bytes_per_usecs > 10)
+   if (bytes_per_msecs > HNS3_RX_LOW_BYTE_RATE)
new_flow_level = HNS3_FLOW_MID;
break;
case HNS3_FLOW_MID:
-   if (bytes_per_usecs > 20)
+   if (bytes_per_msecs > HNS3_RX_MID_BYTE_RATE)
new_flow_level = HNS3_FLOW_HIGH;
-   else if (bytes_per_usecs <= 10)
+   else if (bytes_per_msecs <= HNS3_RX_LOW_BYTE_RATE)
new_flow_level = HNS3_FLOW_LOW;
break;
case HNS3_FLOW_HIGH:
case HNS3_FLOW_ULTRA:
default:
-   if (bytes_per_usecs <= 20)
+   if (bytes_per_msecs <= HNS3_RX_MID_BYTE_RATE)
new_flow_level = HNS3_FLOW_MID;
break;
}
 
-   if ((packets_per_secs > HNS3_RX_ULTRA_PACKET_RATE) &&
-   (_vector->rx_group == ring_group))
+#define HNS3_RX_ULTRA_PACKET_RATE 40
+
+   if (packets_per_msecs > HNS3_RX_ULTRA_PACKET_RATE &&
+   _vector->rx_group == ring_group)
new_flow_level = HNS3_FLOW_ULTRA;
 
switch (new_flow_level) {
@@ -2512,6 +2523,7 @@ static void hns3_update_new_int_gl(struct 
hns3_enet_tqp_vector *tqp_vector)
   tx_group->coal.int_gl);
}
 
+   tqp_vector->last_jiffies = jiffies;
tqp_vector->int_adapt_down = HNS3_INT_ADAPT_DOWN_START;
 }
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
index 2fe870b..39daa01 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
@@ -499,6 +499,7 @@ struct hns3_enet_tqp_vector {
 
/* when 0 should adjust interrupt coalesce parameter */
u8 int_adapt_down;
+   unsigned long last_jiffies;
 } cacheline_internodealigned_in_smp;
 
 enum hns3_udp_tnl_type {
-- 
2.9.3



[PATCH net-next 01/11] net: hns3: reallocate tx/rx buffer after changing mtu

2018-03-21 Thread Peng Li
From: Fuyun Liang <liangfuy...@huawei.com>

When changing the mtu, the max frame size also will be changed. The tx
buffer size and the rx buffer size to be allocated are determined by max
frame size. So when max frame size is changed, the tx buffer and rx buffer
need to be reallocated.

When the tc_num is changed, the tx buffer and rx buffer need to be
reallocated too. So calling set_mtu and buffer_alloc separately is better.

Signed-off-by: Fuyun Liang <liangfuy...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 36 +-
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index d70619b..e110c65 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4772,11 +4772,9 @@ static int hclge_en_hw_strip_rxvtag(struct hnae3_handle 
*handle, bool enable)
return hclge_set_vlan_rx_offload_cfg(vport);
 }
 
-static int hclge_set_mtu(struct hnae3_handle *handle, int new_mtu)
+static int hclge_set_mac_mtu(struct hclge_dev *hdev, int new_mtu)
 {
-   struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_config_max_frm_size_cmd *req;
-   struct hclge_dev *hdev = vport->back;
struct hclge_desc desc;
int max_frm_size;
int ret;
@@ -4805,6 +4803,27 @@ static int hclge_set_mtu(struct hnae3_handle *handle, 
int new_mtu)
return 0;
 }
 
+static int hclge_set_mtu(struct hnae3_handle *handle, int new_mtu)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+   struct hclge_dev *hdev = vport->back;
+   int ret;
+
+   ret = hclge_set_mac_mtu(hdev, new_mtu);
+   if (ret) {
+   dev_err(>pdev->dev,
+   "Change mtu fail, ret =%d\n", ret);
+   return ret;
+   }
+
+   ret = hclge_buffer_alloc(hdev);
+   if (ret)
+   dev_err(>pdev->dev,
+   "Allocate buffer fail, ret =%d\n", ret);
+
+   return ret;
+}
+
 static int hclge_send_reset_tqp_cmd(struct hclge_dev *hdev, u16 queue_id,
bool enable)
 {
@@ -5392,11 +5411,6 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
dev_err(>dev, "Mac init error, ret = %d\n", ret);
return ret;
}
-   ret = hclge_buffer_alloc(hdev);
-   if (ret) {
-   dev_err(>dev, "Buffer allocate fail, ret =%d\n", ret);
-   return  ret;
-   }
 
ret = hclge_config_tso(hdev, HCLGE_TSO_MSS_MIN, HCLGE_TSO_MSS_MAX);
if (ret) {
@@ -5503,12 +5517,6 @@ static int hclge_reset_ae_dev(struct hnae3_ae_dev 
*ae_dev)
return ret;
}
 
-   ret = hclge_buffer_alloc(hdev);
-   if (ret) {
-   dev_err(>dev, "Buffer allocate fail, ret =%d\n", ret);
-   return ret;
-   }
-
ret = hclge_config_tso(hdev, HCLGE_TSO_MSS_MIN, HCLGE_TSO_MSS_MAX);
if (ret) {
dev_err(>dev, "Enable tso fail, ret =%d\n", ret);
-- 
2.9.3



[PATCH net-next 01/11] net: hns3: reallocate tx/rx buffer after changing mtu

2018-03-21 Thread Peng Li
From: Fuyun Liang 

When changing the mtu, the max frame size also will be changed. The tx
buffer size and the rx buffer size to be allocated are determined by max
frame size. So when max frame size is changed, the tx buffer and rx buffer
need to be reallocated.

When the tc_num is changed, the tx buffer and rx buffer need to be
reallocated too. So calling set_mtu and buffer_alloc separately is better.

Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 36 +-
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index d70619b..e110c65 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4772,11 +4772,9 @@ static int hclge_en_hw_strip_rxvtag(struct hnae3_handle 
*handle, bool enable)
return hclge_set_vlan_rx_offload_cfg(vport);
 }
 
-static int hclge_set_mtu(struct hnae3_handle *handle, int new_mtu)
+static int hclge_set_mac_mtu(struct hclge_dev *hdev, int new_mtu)
 {
-   struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_config_max_frm_size_cmd *req;
-   struct hclge_dev *hdev = vport->back;
struct hclge_desc desc;
int max_frm_size;
int ret;
@@ -4805,6 +4803,27 @@ static int hclge_set_mtu(struct hnae3_handle *handle, 
int new_mtu)
return 0;
 }
 
+static int hclge_set_mtu(struct hnae3_handle *handle, int new_mtu)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+   struct hclge_dev *hdev = vport->back;
+   int ret;
+
+   ret = hclge_set_mac_mtu(hdev, new_mtu);
+   if (ret) {
+   dev_err(>pdev->dev,
+   "Change mtu fail, ret =%d\n", ret);
+   return ret;
+   }
+
+   ret = hclge_buffer_alloc(hdev);
+   if (ret)
+   dev_err(>pdev->dev,
+   "Allocate buffer fail, ret =%d\n", ret);
+
+   return ret;
+}
+
 static int hclge_send_reset_tqp_cmd(struct hclge_dev *hdev, u16 queue_id,
bool enable)
 {
@@ -5392,11 +5411,6 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
dev_err(>dev, "Mac init error, ret = %d\n", ret);
return ret;
}
-   ret = hclge_buffer_alloc(hdev);
-   if (ret) {
-   dev_err(>dev, "Buffer allocate fail, ret =%d\n", ret);
-   return  ret;
-   }
 
ret = hclge_config_tso(hdev, HCLGE_TSO_MSS_MIN, HCLGE_TSO_MSS_MAX);
if (ret) {
@@ -5503,12 +5517,6 @@ static int hclge_reset_ae_dev(struct hnae3_ae_dev 
*ae_dev)
return ret;
}
 
-   ret = hclge_buffer_alloc(hdev);
-   if (ret) {
-   dev_err(>dev, "Buffer allocate fail, ret =%d\n", ret);
-   return ret;
-   }
-
ret = hclge_config_tso(hdev, HCLGE_TSO_MSS_MIN, HCLGE_TSO_MSS_MAX);
if (ret) {
dev_err(>dev, "Enable tso fail, ret =%d\n", ret);
-- 
2.9.3



[PATCH net-next 03/11] net: hns3: fix for vlan table lost problem when resetting

2018-03-21 Thread Peng Li
From: Yunsheng Lin <linyunsh...@huawei.com>

The vlan table in hardware is clear after PF/Core/IMP/Global
reset, which will cause vlan tagged packets not being received
problem.

This patch fixes it by restoring the vlan table after reset.

Signed-off-by: Yunsheng Lin <linyunsh...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 26 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h |  3 +++
 2 files changed, 29 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 94f0b92..f700ec1 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1404,11 +1404,15 @@ static int hns3_vlan_rx_add_vid(struct net_device 
*netdev,
__be16 proto, u16 vid)
 {
struct hnae3_handle *h = hns3_get_handle(netdev);
+   struct hns3_nic_priv *priv = netdev_priv(netdev);
int ret = -EIO;
 
if (h->ae_algo->ops->set_vlan_filter)
ret = h->ae_algo->ops->set_vlan_filter(h, proto, vid, false);
 
+   if (!ret)
+   set_bit(vid, priv->active_vlans);
+
return ret;
 }
 
@@ -1416,14 +1420,32 @@ static int hns3_vlan_rx_kill_vid(struct net_device 
*netdev,
 __be16 proto, u16 vid)
 {
struct hnae3_handle *h = hns3_get_handle(netdev);
+   struct hns3_nic_priv *priv = netdev_priv(netdev);
int ret = -EIO;
 
if (h->ae_algo->ops->set_vlan_filter)
ret = h->ae_algo->ops->set_vlan_filter(h, proto, vid, true);
 
+   if (!ret)
+   clear_bit(vid, priv->active_vlans);
+
return ret;
 }
 
+static void hns3_restore_vlan(struct net_device *netdev)
+{
+   struct hns3_nic_priv *priv = netdev_priv(netdev);
+   u16 vid;
+   int ret;
+
+   for_each_set_bit(vid, priv->active_vlans, VLAN_N_VID) {
+   ret = hns3_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
+   if (ret)
+   netdev_warn(netdev, "Restore vlan: %d filter, ret:%d\n",
+   vid, ret);
+   }
+}
+
 static int hns3_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan,
u8 qos, __be16 vlan_proto)
 {
@@ -3341,6 +3363,10 @@ static int hns3_reset_notify_init_enet(struct 
hnae3_handle *handle)
hns3_nic_set_rx_mode(netdev);
hns3_recover_hw_addr(netdev);
 
+   /* Hardware table is only clear when pf resets */
+   if (!(handle->flags & HNAE3_SUPPORT_VF))
+   hns3_restore_vlan(netdev);
+
/* Carrier off reporting is important to ethtool even BEFORE open */
netif_carrier_off(netdev);
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
index a5f4550..c313780 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
@@ -10,6 +10,8 @@
 #ifndef __HNS3_ENET_H
 #define __HNS3_ENET_H
 
+#include 
+
 #include "hnae3.h"
 
 extern const char hns3_driver_version[];
@@ -539,6 +541,7 @@ struct hns3_nic_priv {
struct notifier_block notifier_block;
/* Vxlan/Geneve information */
struct hns3_udp_tunnel udp_tnl[HNS3_UDP_TNL_MAX];
+   unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
 };
 
 union l3_hdr_info {
-- 
2.9.3



[PATCH net-next 03/11] net: hns3: fix for vlan table lost problem when resetting

2018-03-21 Thread Peng Li
From: Yunsheng Lin 

The vlan table in hardware is clear after PF/Core/IMP/Global
reset, which will cause vlan tagged packets not being received
problem.

This patch fixes it by restoring the vlan table after reset.

Signed-off-by: Yunsheng Lin 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 26 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h |  3 +++
 2 files changed, 29 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 94f0b92..f700ec1 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1404,11 +1404,15 @@ static int hns3_vlan_rx_add_vid(struct net_device 
*netdev,
__be16 proto, u16 vid)
 {
struct hnae3_handle *h = hns3_get_handle(netdev);
+   struct hns3_nic_priv *priv = netdev_priv(netdev);
int ret = -EIO;
 
if (h->ae_algo->ops->set_vlan_filter)
ret = h->ae_algo->ops->set_vlan_filter(h, proto, vid, false);
 
+   if (!ret)
+   set_bit(vid, priv->active_vlans);
+
return ret;
 }
 
@@ -1416,14 +1420,32 @@ static int hns3_vlan_rx_kill_vid(struct net_device 
*netdev,
 __be16 proto, u16 vid)
 {
struct hnae3_handle *h = hns3_get_handle(netdev);
+   struct hns3_nic_priv *priv = netdev_priv(netdev);
int ret = -EIO;
 
if (h->ae_algo->ops->set_vlan_filter)
ret = h->ae_algo->ops->set_vlan_filter(h, proto, vid, true);
 
+   if (!ret)
+   clear_bit(vid, priv->active_vlans);
+
return ret;
 }
 
+static void hns3_restore_vlan(struct net_device *netdev)
+{
+   struct hns3_nic_priv *priv = netdev_priv(netdev);
+   u16 vid;
+   int ret;
+
+   for_each_set_bit(vid, priv->active_vlans, VLAN_N_VID) {
+   ret = hns3_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
+   if (ret)
+   netdev_warn(netdev, "Restore vlan: %d filter, ret:%d\n",
+   vid, ret);
+   }
+}
+
 static int hns3_ndo_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan,
u8 qos, __be16 vlan_proto)
 {
@@ -3341,6 +3363,10 @@ static int hns3_reset_notify_init_enet(struct 
hnae3_handle *handle)
hns3_nic_set_rx_mode(netdev);
hns3_recover_hw_addr(netdev);
 
+   /* Hardware table is only clear when pf resets */
+   if (!(handle->flags & HNAE3_SUPPORT_VF))
+   hns3_restore_vlan(netdev);
+
/* Carrier off reporting is important to ethtool even BEFORE open */
netif_carrier_off(netdev);
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
index a5f4550..c313780 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
@@ -10,6 +10,8 @@
 #ifndef __HNS3_ENET_H
 #define __HNS3_ENET_H
 
+#include 
+
 #include "hnae3.h"
 
 extern const char hns3_driver_version[];
@@ -539,6 +541,7 @@ struct hns3_nic_priv {
struct notifier_block notifier_block;
/* Vxlan/Geneve information */
struct hns3_udp_tunnel udp_tnl[HNS3_UDP_TNL_MAX];
+   unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
 };
 
 union l3_hdr_info {
-- 
2.9.3



[PATCH net-next 04/11] net: hns3: export pci table of hclge and hclgevf to userspace

2018-03-21 Thread Peng Li
From: Yunsheng Lin <linyunsh...@huawei.com>

There is no module that is dependent on hclge or hclgevf's symbol,
but hns_enet need them to provide ops for it to run. When there is
a need to auto load the hns3 driver, the auto load will fail because
hclge or hclgevf is not loaded.

Hns_enet has already exported the pci table, so this patch exports
the pci table for hclge and hclgevf module too.

Signed-off-by: Yunsheng Lin <linyunsh...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c   | 2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 588f231..869e98a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -55,6 +55,8 @@ static const struct pci_device_id ae_algo_pci_tbl[] = {
{0, }
 };
 
+MODULE_DEVICE_TABLE(pci, ae_algo_pci_tbl);
+
 static const char hns3_nic_test_strs[][ETH_GSTRING_LEN] = {
"MacLoopback test",
"Serdes Loopback test",
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index c96cf03..14b0e26 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -18,6 +18,8 @@ static const struct pci_device_id ae_algovf_pci_tbl[] = {
{0, }
 };
 
+MODULE_DEVICE_TABLE(pci, ae_algovf_pci_tbl);
+
 static inline struct hclgevf_dev *hclgevf_ae_get_hdev(
struct hnae3_handle *handle)
 {
-- 
2.9.3



[PATCH net-next 04/11] net: hns3: export pci table of hclge and hclgevf to userspace

2018-03-21 Thread Peng Li
From: Yunsheng Lin 

There is no module that is dependent on hclge or hclgevf's symbol,
but hns_enet need them to provide ops for it to run. When there is
a need to auto load the hns3 driver, the auto load will fail because
hclge or hclgevf is not loaded.

Hns_enet has already exported the pci table, so this patch exports
the pci table for hclge and hclgevf module too.

Signed-off-by: Yunsheng Lin 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c   | 2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 588f231..869e98a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -55,6 +55,8 @@ static const struct pci_device_id ae_algo_pci_tbl[] = {
{0, }
 };
 
+MODULE_DEVICE_TABLE(pci, ae_algo_pci_tbl);
+
 static const char hns3_nic_test_strs[][ETH_GSTRING_LEN] = {
"MacLoopback test",
"Serdes Loopback test",
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index c96cf03..14b0e26 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -18,6 +18,8 @@ static const struct pci_device_id ae_algovf_pci_tbl[] = {
{0, }
 };
 
+MODULE_DEVICE_TABLE(pci, ae_algovf_pci_tbl);
+
 static inline struct hclgevf_dev *hclgevf_ae_get_hdev(
struct hnae3_handle *handle)
 {
-- 
2.9.3



[PATCH net-next 09/11] net: hns3: add get_link support to VF

2018-03-21 Thread Peng Li
From: Fuyun Liang <liangfuy...@huawei.com>

This patch adds ethtool_ops.get_link support to VF.

Signed-off-by: Fuyun Liang <liangfuy...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c| 1 +
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 8 
 2 files changed, 9 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index 502f347..513d8d6 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -1053,6 +1053,7 @@ static const struct ethtool_ops hns3vf_ethtool_ops = {
.get_channels = hns3_get_channels,
.get_coalesce = hns3_get_coalesce,
.set_coalesce = hns3_set_coalesce,
+   .get_link = hns3_get_link,
 };
 
 static const struct ethtool_ops hns3_ethtool_ops = {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index 14b0e26..f917a1e 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -1468,6 +1468,13 @@ static void hclgevf_get_tqps_and_rss_info(struct 
hnae3_handle *handle,
*max_rss_size = hdev->rss_size_max;
 }
 
+static int hclgevf_get_status(struct hnae3_handle *handle)
+{
+   struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
+
+   return hdev->hw.mac.link;
+}
+
 static const struct hnae3_ae_ops hclgevf_ops = {
.init_ae_dev = hclgevf_init_ae_dev,
.uninit_ae_dev = hclgevf_uninit_ae_dev,
@@ -1500,6 +1507,7 @@ static const struct hnae3_ae_ops hclgevf_ops = {
.set_vlan_filter = hclgevf_set_vlan_filter,
.get_channels = hclgevf_get_channels,
.get_tqps_and_rss_info = hclgevf_get_tqps_and_rss_info,
+   .get_status = hclgevf_get_status,
 };
 
 static struct hnae3_ae_algo ae_algovf = {
-- 
2.9.3



[PATCH net-next 11/11] net: hns3: fix for not returning problem in get_link_ksettings when phy exists

2018-03-21 Thread Peng Li
From: Fuyun Liang <liangfuy...@huawei.com>

When phy exists, phy_ethtool_ksettings_get function is enough to get the
link ksettings. If the phy exists, get_link_ksettings function can return
directly after phy_ethtool_ksettings_get is called.

Signed-off-by: Fuyun Liang <liangfuy...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index 513d8d6..9d07116 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -569,9 +569,13 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
return -EOPNOTSUPP;
 
/* 1.auto_neg & speed & duplex from cmd */
-   if (netdev->phydev)
+   if (netdev->phydev) {
phy_ethtool_ksettings_get(netdev->phydev, cmd);
-   else if (h->ae_algo->ops->get_ksettings_an_result)
+
+   return 0;
+   }
+
+   if (h->ae_algo->ops->get_ksettings_an_result)
h->ae_algo->ops->get_ksettings_an_result(h,
 >base.autoneg,
 >base.speed,
-- 
2.9.3



[PATCH net-next 09/11] net: hns3: add get_link support to VF

2018-03-21 Thread Peng Li
From: Fuyun Liang 

This patch adds ethtool_ops.get_link support to VF.

Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c| 1 +
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 8 
 2 files changed, 9 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index 502f347..513d8d6 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -1053,6 +1053,7 @@ static const struct ethtool_ops hns3vf_ethtool_ops = {
.get_channels = hns3_get_channels,
.get_coalesce = hns3_get_coalesce,
.set_coalesce = hns3_set_coalesce,
+   .get_link = hns3_get_link,
 };
 
 static const struct ethtool_ops hns3_ethtool_ops = {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index 14b0e26..f917a1e 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -1468,6 +1468,13 @@ static void hclgevf_get_tqps_and_rss_info(struct 
hnae3_handle *handle,
*max_rss_size = hdev->rss_size_max;
 }
 
+static int hclgevf_get_status(struct hnae3_handle *handle)
+{
+   struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
+
+   return hdev->hw.mac.link;
+}
+
 static const struct hnae3_ae_ops hclgevf_ops = {
.init_ae_dev = hclgevf_init_ae_dev,
.uninit_ae_dev = hclgevf_uninit_ae_dev,
@@ -1500,6 +1507,7 @@ static const struct hnae3_ae_ops hclgevf_ops = {
.set_vlan_filter = hclgevf_set_vlan_filter,
.get_channels = hclgevf_get_channels,
.get_tqps_and_rss_info = hclgevf_get_tqps_and_rss_info,
+   .get_status = hclgevf_get_status,
 };
 
 static struct hnae3_ae_algo ae_algovf = {
-- 
2.9.3



[PATCH net-next 11/11] net: hns3: fix for not returning problem in get_link_ksettings when phy exists

2018-03-21 Thread Peng Li
From: Fuyun Liang 

When phy exists, phy_ethtool_ksettings_get function is enough to get the
link ksettings. If the phy exists, get_link_ksettings function can return
directly after phy_ethtool_ksettings_get is called.

Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index 513d8d6..9d07116 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -569,9 +569,13 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
return -EOPNOTSUPP;
 
/* 1.auto_neg & speed & duplex from cmd */
-   if (netdev->phydev)
+   if (netdev->phydev) {
phy_ethtool_ksettings_get(netdev->phydev, cmd);
-   else if (h->ae_algo->ops->get_ksettings_an_result)
+
+   return 0;
+   }
+
+   if (h->ae_algo->ops->get_ksettings_an_result)
h->ae_algo->ops->get_ksettings_an_result(h,
 >base.autoneg,
 >base.speed,
-- 
2.9.3



[PATCH net-next 00/11] fix some bugs for HNS3 driver

2018-03-21 Thread Peng Li
This patchset fixes some bugs for HNS3 driver:
[Patch 1/11 - 5/11] fix various bugs reported by hisilicon test team.
[Patch 6/11 - 7/11] fix bugs about interrupt coalescing self-adaptive
function.
[Patch 8/11 - 11/11] fix bugs about ethtool_ops.get_link_ksettings.

Fuyun Liang (7):
  net: hns3: reallocate tx/rx buffer after changing mtu
  net: hns3: change GL update rate
  net: hns3: change the time interval of int_gl calculating
  net: hns3: fix for getting wrong link mode problem
  net: hns3: add get_link support to VF
  net: hns3: add querying speed and duplex support to VF
  net: hns3: fix for not returning problem in get_link_ksettings when
phy exists

Peng Li (2):
  net: hns3: fix the VF queue reset flow error
  net: hns3: increase the max time for IMP handle command

Yunsheng Lin (2):
  net: hns3: fix for vlan table lost problem when resetting
  net: hns3: export pci table of hclge and hclgevf to userspace

 drivers/net/ethernet/hisilicon/hns3/hnae3.h|   4 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c|  80 ---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|   6 +
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 107 +++---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |   4 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 158 +++--
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  10 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c |  19 ++-
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_cmd.h   |   2 +-
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  |  42 +-
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h  |   4 +
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c   |   5 +
 12 files changed, 309 insertions(+), 132 deletions(-)

-- 
2.9.3



[PATCH net-next 00/11] fix some bugs for HNS3 driver

2018-03-21 Thread Peng Li
This patchset fixes some bugs for HNS3 driver:
[Patch 1/11 - 5/11] fix various bugs reported by hisilicon test team.
[Patch 6/11 - 7/11] fix bugs about interrupt coalescing self-adaptive
function.
[Patch 8/11 - 11/11] fix bugs about ethtool_ops.get_link_ksettings.

Fuyun Liang (7):
  net: hns3: reallocate tx/rx buffer after changing mtu
  net: hns3: change GL update rate
  net: hns3: change the time interval of int_gl calculating
  net: hns3: fix for getting wrong link mode problem
  net: hns3: add get_link support to VF
  net: hns3: add querying speed and duplex support to VF
  net: hns3: fix for not returning problem in get_link_ksettings when
phy exists

Peng Li (2):
  net: hns3: fix the VF queue reset flow error
  net: hns3: increase the max time for IMP handle command

Yunsheng Lin (2):
  net: hns3: fix for vlan table lost problem when resetting
  net: hns3: export pci table of hclge and hclgevf to userspace

 drivers/net/ethernet/hisilicon/hns3/hnae3.h|   4 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c|  80 ---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|   6 +
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 107 +++---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |   4 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 158 +++--
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  10 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c |  19 ++-
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_cmd.h   |   2 +-
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  |  42 +-
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h  |   4 +
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c   |   5 +
 12 files changed, 309 insertions(+), 132 deletions(-)

-- 
2.9.3



[PATCH net-next 01/12] net: hns3: add existence check when remove old uc mac address

2018-03-09 Thread Peng Li
From: Fuyun Liang <liangfuy...@huawei.com>

When driver is in initial state, the mac_vlan table table is empty.
So the delete operation for mac address must fail. Existence check
is needed here. Otherwise, the error message will make user confused.

Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support")
Signed-off-by: Fuyun Liang <liangfuy...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h |  3 ++-
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c |  4 ++--
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 17 +++--
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c  |  2 ++
 .../net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c   | 10 +++---
 5 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index a072048..70441d2 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -338,7 +338,8 @@ struct hnae3_ae_ops {
   u32 *tx_usecs_high, u32 *rx_usecs_high);
 
void (*get_mac_addr)(struct hnae3_handle *handle, u8 *p);
-   int (*set_mac_addr)(struct hnae3_handle *handle, void *p);
+   int (*set_mac_addr)(struct hnae3_handle *handle, void *p,
+   bool is_first);
int (*add_uc_addr)(struct hnae3_handle *handle,
   const unsigned char *addr);
int (*rm_uc_addr)(struct hnae3_handle *handle,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 0a8c427..8113d22 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1120,7 +1120,7 @@ static int hns3_nic_net_set_mac_address(struct net_device 
*netdev, void *p)
if (!mac_addr || !is_valid_ether_addr((const u8 *)mac_addr->sa_data))
return -EADDRNOTAVAIL;
 
-   ret = h->ae_algo->ops->set_mac_addr(h, mac_addr->sa_data);
+   ret = h->ae_algo->ops->set_mac_addr(h, mac_addr->sa_data, false);
if (ret) {
netdev_err(netdev, "set_mac_address fail, ret=%d!\n", ret);
return ret;
@@ -3048,7 +3048,7 @@ static void hns3_init_mac_addr(struct net_device *netdev)
}
 
if (h->ae_algo->ops->set_mac_addr)
-   h->ae_algo->ops->set_mac_addr(h, netdev->dev_addr);
+   h->ae_algo->ops->set_mac_addr(h, netdev->dev_addr, true);
 
 }
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index a318773..632672c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4378,7 +4378,8 @@ static void hclge_get_mac_addr(struct hnae3_handle 
*handle, u8 *p)
ether_addr_copy(p, hdev->hw.mac.mac_addr);
 }
 
-static int hclge_set_mac_addr(struct hnae3_handle *handle, void *p)
+static int hclge_set_mac_addr(struct hnae3_handle *handle, void *p,
+ bool is_first)
 {
const unsigned char *new_addr = (const unsigned char *)p;
struct hclge_vport *vport = hclge_get_vport(handle);
@@ -4395,11 +4396,9 @@ static int hclge_set_mac_addr(struct hnae3_handle 
*handle, void *p)
return -EINVAL;
}
 
-   ret = hclge_rm_uc_addr(handle, hdev->hw.mac.mac_addr);
-   if (ret)
+   if (!is_first && hclge_rm_uc_addr(handle, hdev->hw.mac.mac_addr))
dev_warn(>pdev->dev,
-"remove old uc mac address fail, ret =%d.\n",
-ret);
+"remove old uc mac address fail.\n");
 
ret = hclge_add_uc_addr(handle, new_addr);
if (ret) {
@@ -4407,12 +4406,10 @@ static int hclge_set_mac_addr(struct hnae3_handle 
*handle, void *p)
"add uc mac address fail, ret =%d.\n",
ret);
 
-   ret = hclge_add_uc_addr(handle, hdev->hw.mac.mac_addr);
-   if (ret) {
+   if (!is_first &&
+   hclge_add_uc_addr(handle, hdev->hw.mac.mac_addr))
dev_err(>pdev->dev,
-   "restore uc mac address fail, ret =%d.\n",
-   ret);
-   }
+   "restore uc mac address fail.\n");
 
return -EIO;
}
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
index f332de6..ed34ca3 100644
--- a/dri

[PATCH net-next 01/12] net: hns3: add existence check when remove old uc mac address

2018-03-09 Thread Peng Li
From: Fuyun Liang 

When driver is in initial state, the mac_vlan table table is empty.
So the delete operation for mac address must fail. Existence check
is needed here. Otherwise, the error message will make user confused.

Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support")
Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h |  3 ++-
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c |  4 ++--
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 17 +++--
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c  |  2 ++
 .../net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c   | 10 +++---
 5 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index a072048..70441d2 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -338,7 +338,8 @@ struct hnae3_ae_ops {
   u32 *tx_usecs_high, u32 *rx_usecs_high);
 
void (*get_mac_addr)(struct hnae3_handle *handle, u8 *p);
-   int (*set_mac_addr)(struct hnae3_handle *handle, void *p);
+   int (*set_mac_addr)(struct hnae3_handle *handle, void *p,
+   bool is_first);
int (*add_uc_addr)(struct hnae3_handle *handle,
   const unsigned char *addr);
int (*rm_uc_addr)(struct hnae3_handle *handle,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 0a8c427..8113d22 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1120,7 +1120,7 @@ static int hns3_nic_net_set_mac_address(struct net_device 
*netdev, void *p)
if (!mac_addr || !is_valid_ether_addr((const u8 *)mac_addr->sa_data))
return -EADDRNOTAVAIL;
 
-   ret = h->ae_algo->ops->set_mac_addr(h, mac_addr->sa_data);
+   ret = h->ae_algo->ops->set_mac_addr(h, mac_addr->sa_data, false);
if (ret) {
netdev_err(netdev, "set_mac_address fail, ret=%d!\n", ret);
return ret;
@@ -3048,7 +3048,7 @@ static void hns3_init_mac_addr(struct net_device *netdev)
}
 
if (h->ae_algo->ops->set_mac_addr)
-   h->ae_algo->ops->set_mac_addr(h, netdev->dev_addr);
+   h->ae_algo->ops->set_mac_addr(h, netdev->dev_addr, true);
 
 }
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index a318773..632672c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4378,7 +4378,8 @@ static void hclge_get_mac_addr(struct hnae3_handle 
*handle, u8 *p)
ether_addr_copy(p, hdev->hw.mac.mac_addr);
 }
 
-static int hclge_set_mac_addr(struct hnae3_handle *handle, void *p)
+static int hclge_set_mac_addr(struct hnae3_handle *handle, void *p,
+ bool is_first)
 {
const unsigned char *new_addr = (const unsigned char *)p;
struct hclge_vport *vport = hclge_get_vport(handle);
@@ -4395,11 +4396,9 @@ static int hclge_set_mac_addr(struct hnae3_handle 
*handle, void *p)
return -EINVAL;
}
 
-   ret = hclge_rm_uc_addr(handle, hdev->hw.mac.mac_addr);
-   if (ret)
+   if (!is_first && hclge_rm_uc_addr(handle, hdev->hw.mac.mac_addr))
dev_warn(>pdev->dev,
-"remove old uc mac address fail, ret =%d.\n",
-ret);
+"remove old uc mac address fail.\n");
 
ret = hclge_add_uc_addr(handle, new_addr);
if (ret) {
@@ -4407,12 +4406,10 @@ static int hclge_set_mac_addr(struct hnae3_handle 
*handle, void *p)
"add uc mac address fail, ret =%d.\n",
ret);
 
-   ret = hclge_add_uc_addr(handle, hdev->hw.mac.mac_addr);
-   if (ret) {
+   if (!is_first &&
+   hclge_add_uc_addr(handle, hdev->hw.mac.mac_addr))
dev_err(>pdev->dev,
-   "restore uc mac address fail, ret =%d.\n",
-   ret);
-   }
+   "restore uc mac address fail.\n");
 
return -EIO;
}
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
index f332de6..ed34ca3 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/h

[PATCH net-next 02/12] net: hns3: fix for netdev not running problem after calling net_stop and net_open

2018-03-09 Thread Peng Li
From: Fuyun Liang <liangfuy...@huawei.com>

The link status update function is called by timer every second. But
net_stop and net_open may be called with very short intervals. The link
status update function can not detect the link state has changed. It
causes the netdev not running problem.

This patch fixes it by updating the link state in ae_stop function.

Signed-off-by: Fuyun Liang <liangfuy...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c   | 3 +++
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 632672c..cc60407 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3756,6 +3756,9 @@ static void hclge_ae_stop(struct hnae3_handle *handle)
 
/* reset tqp stats */
hclge_reset_tqp_stats(handle);
+   del_timer_sync(>service_timer);
+   cancel_work_sync(>service_task);
+   hclge_update_link_status(hdev);
 }
 
 static int hclge_get_mac_vlan_cmd_status(struct hclge_vport *vport,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index ba3fed1..c80a604 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -1066,6 +1066,9 @@ static void hclgevf_ae_stop(struct hnae3_handle *handle)
 
/* reset tqp stats */
hclgevf_reset_tqp_stats(handle);
+   del_timer_sync(>service_timer);
+   cancel_work_sync(>service_task);
+   hclgevf_update_link_status(hdev, 0);
 }
 
 static void hclgevf_state_init(struct hclgevf_dev *hdev)
-- 
2.9.3



[PATCH net-next 02/12] net: hns3: fix for netdev not running problem after calling net_stop and net_open

2018-03-09 Thread Peng Li
From: Fuyun Liang 

The link status update function is called by timer every second. But
net_stop and net_open may be called with very short intervals. The link
status update function can not detect the link state has changed. It
causes the netdev not running problem.

This patch fixes it by updating the link state in ae_stop function.

Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c   | 3 +++
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 632672c..cc60407 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3756,6 +3756,9 @@ static void hclge_ae_stop(struct hnae3_handle *handle)
 
/* reset tqp stats */
hclge_reset_tqp_stats(handle);
+   del_timer_sync(>service_timer);
+   cancel_work_sync(>service_task);
+   hclge_update_link_status(hdev);
 }
 
 static int hclge_get_mac_vlan_cmd_status(struct hclge_vport *vport,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index ba3fed1..c80a604 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -1066,6 +1066,9 @@ static void hclgevf_ae_stop(struct hnae3_handle *handle)
 
/* reset tqp stats */
hclgevf_reset_tqp_stats(handle);
+   del_timer_sync(>service_timer);
+   cancel_work_sync(>service_task);
+   hclgevf_update_link_status(hdev, 0);
 }
 
 static void hclgevf_state_init(struct hclgevf_dev *hdev)
-- 
2.9.3



[PATCH net-next 04/12] net: hns3: unify the pause params setup function

2018-03-09 Thread Peng Li
From: Fuyun Liang <liangfuy...@huawei.com>

Since the firmware cmd to setup mac pause params is the same as the
firmware cmd to pfc pause params, this patch unifies the pause params
setup function.

Signed-off-by: Fuyun Liang <liangfuy...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c|  2 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  | 23 +++---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |  2 +-
 3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index cc60407..ea33cc5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4417,7 +4417,7 @@ static int hclge_set_mac_addr(struct hnae3_handle 
*handle, void *p,
return -EIO;
}
 
-   ret = hclge_mac_pause_addr_cfg(hdev, new_addr);
+   ret = hclge_pause_addr_cfg(hdev, new_addr);
if (ret) {
dev_err(>pdev->dev,
"configure mac pause address fail, ret =%d.\n",
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
index 36bd79a..4134a82 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
@@ -138,8 +138,8 @@ static int hclge_pfc_pause_en_cfg(struct hclge_dev *hdev, 
u8 tx_rx_bitmap,
return hclge_cmd_send(>hw, , 1);
 }
 
-static int hclge_mac_pause_param_cfg(struct hclge_dev *hdev, const u8 *addr,
-u8 pause_trans_gap, u16 pause_trans_time)
+static int hclge_pause_param_cfg(struct hclge_dev *hdev, const u8 *addr,
+u8 pause_trans_gap, u16 pause_trans_time)
 {
struct hclge_cfg_pause_param_cmd *pause_param;
struct hclge_desc desc;
@@ -155,7 +155,7 @@ static int hclge_mac_pause_param_cfg(struct hclge_dev 
*hdev, const u8 *addr,
return hclge_cmd_send(>hw, , 1);
 }
 
-int hclge_mac_pause_addr_cfg(struct hclge_dev *hdev, const u8 *mac_addr)
+int hclge_pause_addr_cfg(struct hclge_dev *hdev, const u8 *mac_addr)
 {
struct hclge_cfg_pause_param_cmd *pause_param;
struct hclge_desc desc;
@@ -174,7 +174,7 @@ int hclge_mac_pause_addr_cfg(struct hclge_dev *hdev, const 
u8 *mac_addr)
trans_gap = pause_param->pause_trans_gap;
trans_time = le16_to_cpu(pause_param->pause_trans_time);
 
-   return hclge_mac_pause_param_cfg(hdev, mac_addr, trans_gap,
+   return hclge_pause_param_cfg(hdev, mac_addr, trans_gap,
 trans_time);
 }
 
@@ -1096,11 +1096,11 @@ static int hclge_tm_schd_setup_hw(struct hclge_dev 
*hdev)
return hclge_tm_schd_mode_hw(hdev);
 }
 
-static int hclge_mac_pause_param_setup_hw(struct hclge_dev *hdev)
+static int hclge_pause_param_setup_hw(struct hclge_dev *hdev)
 {
struct hclge_mac *mac = >hw.mac;
 
-   return hclge_mac_pause_param_cfg(hdev, mac->mac_addr,
+   return hclge_pause_param_cfg(hdev, mac->mac_addr,
 HCLGE_DEFAULT_PAUSE_TRANS_GAP,
 HCLGE_DEFAULT_PAUSE_TRANS_TIME);
 }
@@ -1151,13 +1151,12 @@ int hclge_pause_setup_hw(struct hclge_dev *hdev)
int ret;
u8 i;
 
-   if (hdev->tm_info.fc_mode != HCLGE_FC_PFC) {
-   ret = hclge_mac_pause_setup_hw(hdev);
-   if (ret)
-   return ret;
+   ret = hclge_pause_param_setup_hw(hdev);
+   if (ret)
+   return ret;
 
-   return hclge_mac_pause_param_setup_hw(hdev);
-   }
+   if (hdev->tm_info.fc_mode != HCLGE_FC_PFC)
+   return hclge_mac_pause_setup_hw(hdev);
 
/* Only DCB-supported dev supports qset back pressure and pfc cmd */
if (!hnae3_dev_dcb_supported(hdev))
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h
index 5401e75..c30c85b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h
@@ -129,5 +129,5 @@ int hclge_tm_dwrr_cfg(struct hclge_dev *hdev);
 int hclge_tm_map_cfg(struct hclge_dev *hdev);
 int hclge_tm_init_hw(struct hclge_dev *hdev);
 int hclge_mac_pause_en_cfg(struct hclge_dev *hdev, bool tx, bool rx);
-int hclge_mac_pause_addr_cfg(struct hclge_dev *hdev, const u8 *mac_addr);
+int hclge_pause_addr_cfg(struct hclge_dev *hdev, const u8 *mac_addr);
 #endif
-- 
2.9.3



[PATCH net-next 04/12] net: hns3: unify the pause params setup function

2018-03-09 Thread Peng Li
From: Fuyun Liang 

Since the firmware cmd to setup mac pause params is the same as the
firmware cmd to pfc pause params, this patch unifies the pause params
setup function.

Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c|  2 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  | 23 +++---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |  2 +-
 3 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index cc60407..ea33cc5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4417,7 +4417,7 @@ static int hclge_set_mac_addr(struct hnae3_handle 
*handle, void *p,
return -EIO;
}
 
-   ret = hclge_mac_pause_addr_cfg(hdev, new_addr);
+   ret = hclge_pause_addr_cfg(hdev, new_addr);
if (ret) {
dev_err(>pdev->dev,
"configure mac pause address fail, ret =%d.\n",
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
index 36bd79a..4134a82 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
@@ -138,8 +138,8 @@ static int hclge_pfc_pause_en_cfg(struct hclge_dev *hdev, 
u8 tx_rx_bitmap,
return hclge_cmd_send(>hw, , 1);
 }
 
-static int hclge_mac_pause_param_cfg(struct hclge_dev *hdev, const u8 *addr,
-u8 pause_trans_gap, u16 pause_trans_time)
+static int hclge_pause_param_cfg(struct hclge_dev *hdev, const u8 *addr,
+u8 pause_trans_gap, u16 pause_trans_time)
 {
struct hclge_cfg_pause_param_cmd *pause_param;
struct hclge_desc desc;
@@ -155,7 +155,7 @@ static int hclge_mac_pause_param_cfg(struct hclge_dev 
*hdev, const u8 *addr,
return hclge_cmd_send(>hw, , 1);
 }
 
-int hclge_mac_pause_addr_cfg(struct hclge_dev *hdev, const u8 *mac_addr)
+int hclge_pause_addr_cfg(struct hclge_dev *hdev, const u8 *mac_addr)
 {
struct hclge_cfg_pause_param_cmd *pause_param;
struct hclge_desc desc;
@@ -174,7 +174,7 @@ int hclge_mac_pause_addr_cfg(struct hclge_dev *hdev, const 
u8 *mac_addr)
trans_gap = pause_param->pause_trans_gap;
trans_time = le16_to_cpu(pause_param->pause_trans_time);
 
-   return hclge_mac_pause_param_cfg(hdev, mac_addr, trans_gap,
+   return hclge_pause_param_cfg(hdev, mac_addr, trans_gap,
 trans_time);
 }
 
@@ -1096,11 +1096,11 @@ static int hclge_tm_schd_setup_hw(struct hclge_dev 
*hdev)
return hclge_tm_schd_mode_hw(hdev);
 }
 
-static int hclge_mac_pause_param_setup_hw(struct hclge_dev *hdev)
+static int hclge_pause_param_setup_hw(struct hclge_dev *hdev)
 {
struct hclge_mac *mac = >hw.mac;
 
-   return hclge_mac_pause_param_cfg(hdev, mac->mac_addr,
+   return hclge_pause_param_cfg(hdev, mac->mac_addr,
 HCLGE_DEFAULT_PAUSE_TRANS_GAP,
 HCLGE_DEFAULT_PAUSE_TRANS_TIME);
 }
@@ -1151,13 +1151,12 @@ int hclge_pause_setup_hw(struct hclge_dev *hdev)
int ret;
u8 i;
 
-   if (hdev->tm_info.fc_mode != HCLGE_FC_PFC) {
-   ret = hclge_mac_pause_setup_hw(hdev);
-   if (ret)
-   return ret;
+   ret = hclge_pause_param_setup_hw(hdev);
+   if (ret)
+   return ret;
 
-   return hclge_mac_pause_param_setup_hw(hdev);
-   }
+   if (hdev->tm_info.fc_mode != HCLGE_FC_PFC)
+   return hclge_mac_pause_setup_hw(hdev);
 
/* Only DCB-supported dev supports qset back pressure and pfc cmd */
if (!hnae3_dev_dcb_supported(hdev))
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h
index 5401e75..c30c85b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h
@@ -129,5 +129,5 @@ int hclge_tm_dwrr_cfg(struct hclge_dev *hdev);
 int hclge_tm_map_cfg(struct hclge_dev *hdev);
 int hclge_tm_init_hw(struct hclge_dev *hdev);
 int hclge_mac_pause_en_cfg(struct hclge_dev *hdev, bool tx, bool rx);
-int hclge_mac_pause_addr_cfg(struct hclge_dev *hdev, const u8 *mac_addr);
+int hclge_pause_addr_cfg(struct hclge_dev *hdev, const u8 *mac_addr);
 #endif
-- 
2.9.3



[PATCH net-next 00/12] fix some bugs for HNS3 driver

2018-03-09 Thread Peng Li
This patchset fixes some bugs for HNS3 driver:
[Patch 1/12 - Patch 8/12] fix various bugs for PF driver.
[Patch 9/12 - Patch 12/12] fix issues when change the us mac address of
PF/VF device to an existent one in the mac_vlan table.

Fuyun Liang (4):
  net: hns3: add existence check when remove old uc mac address
  net: hns3: fix for netdev not running problem after calling net_stop
and net_open
  net: hns3: fix for ipv6 address loss problem after setting channels
  net: hns3: unify the pause params setup function

Jian Shen (4):
  net: hns3: fix error type definition of return value
  net: hns3: fix return value error of hclge_get_mac_vlan_cmd_status()
  net: hns3: add existence checking before adding unicast mac address
  net: hns3: add result checking for VF when modify unicast mac address

Peng Li (2):
  net: hns3: fix rx path skb->truesize reporting bug
  net: hns3: add support for querying pfc puase packets statistic

Yunsheng Lin (2):
  net: hns3: fix for loopback failure when vlan filter is enable
  net: hns3: fix for buffer overflow smatch warning

 drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h|  2 +
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  3 +-
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 18 +++--
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 16 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c | 14 
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 59 ++---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c | 23 ---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  | 76 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |  8 ++-
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  | 75 +++--
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c   |  4 ++
 11 files changed, 205 insertions(+), 93 deletions(-)

-- 
2.9.3



[PATCH net-next 00/12] fix some bugs for HNS3 driver

2018-03-09 Thread Peng Li
This patchset fixes some bugs for HNS3 driver:
[Patch 1/12 - Patch 8/12] fix various bugs for PF driver.
[Patch 9/12 - Patch 12/12] fix issues when change the us mac address of
PF/VF device to an existent one in the mac_vlan table.

Fuyun Liang (4):
  net: hns3: add existence check when remove old uc mac address
  net: hns3: fix for netdev not running problem after calling net_stop
and net_open
  net: hns3: fix for ipv6 address loss problem after setting channels
  net: hns3: unify the pause params setup function

Jian Shen (4):
  net: hns3: fix error type definition of return value
  net: hns3: fix return value error of hclge_get_mac_vlan_cmd_status()
  net: hns3: add existence checking before adding unicast mac address
  net: hns3: add result checking for VF when modify unicast mac address

Peng Li (2):
  net: hns3: fix rx path skb->truesize reporting bug
  net: hns3: add support for querying pfc puase packets statistic

Yunsheng Lin (2):
  net: hns3: fix for loopback failure when vlan filter is enable
  net: hns3: fix for buffer overflow smatch warning

 drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h|  2 +
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  3 +-
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 18 +++--
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 16 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c | 14 
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 59 ++---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c | 23 ---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  | 76 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |  8 ++-
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  | 75 +++--
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c   |  4 ++
 11 files changed, 205 insertions(+), 93 deletions(-)

-- 
2.9.3



[PATCH net-next 06/12] net: hns3: add support for querying pfc puase packets statistic

2018-03-09 Thread Peng Li
This patch add support for querying pfc puase packets statistic
in hclge_ieee_getpfc, which is used to tell user how many pfc
puase packets have been sent and received by this mac port.

Signed-off-by: Yunsheng Lin <linyunsh...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c | 14 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  | 53 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |  6 +++
 3 files changed, 73 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c
index 407cfab..955f0e3 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c
@@ -205,9 +205,11 @@ static int hclge_ieee_setets(struct hnae3_handle *h, 
struct ieee_ets *ets)
 
 static int hclge_ieee_getpfc(struct hnae3_handle *h, struct ieee_pfc *pfc)
 {
+   u64 requests[HNAE3_MAX_TC], indications[HNAE3_MAX_TC];
struct hclge_vport *vport = hclge_get_vport(h);
struct hclge_dev *hdev = vport->back;
u8 i, j, pfc_map, *prio_tc;
+   int ret;
 
memset(pfc, 0, sizeof(*pfc));
pfc->pfc_cap = hdev->pfc_max;
@@ -222,6 +224,18 @@ static int hclge_ieee_getpfc(struct hnae3_handle *h, 
struct ieee_pfc *pfc)
}
}
 
+   ret = hclge_pfc_tx_stats_get(hdev, requests);
+   if (ret)
+   return ret;
+
+   ret = hclge_pfc_rx_stats_get(hdev, indications);
+   if (ret)
+   return ret;
+
+   for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
+   pfc->requests[i] = requests[i];
+   pfc->indications[i] = indications[i];
+   }
return 0;
 }
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
index 4134a82..885f25c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
@@ -23,6 +23,9 @@ enum hclge_shaper_level {
HCLGE_SHAPER_LVL_PF = 1,
 };
 
+#define HCLGE_TM_PFC_PKT_GET_CMD_NUM   3
+#define HCLGE_TM_PFC_NUM_GET_PER_CMD   3
+
 #define HCLGE_SHAPER_BS_U_DEF  5
 #define HCLGE_SHAPER_BS_S_DEF  20
 
@@ -112,6 +115,56 @@ static int hclge_shaper_para_calc(u32 ir, u8 shaper_level,
return 0;
 }
 
+static int hclge_pfc_stats_get(struct hclge_dev *hdev,
+  enum hclge_opcode_type opcode, u64 *stats)
+{
+   struct hclge_desc desc[HCLGE_TM_PFC_PKT_GET_CMD_NUM];
+   int ret, i, j;
+
+   if (!(opcode == HCLGE_OPC_QUERY_PFC_RX_PKT_CNT ||
+ opcode == HCLGE_OPC_QUERY_PFC_TX_PKT_CNT))
+   return -EINVAL;
+
+   for (i = 0; i < HCLGE_TM_PFC_PKT_GET_CMD_NUM; i++) {
+   hclge_cmd_setup_basic_desc([i], opcode, true);
+   if (i != (HCLGE_TM_PFC_PKT_GET_CMD_NUM - 1))
+   desc[i].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+   else
+   desc[i].flag &= ~cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+   }
+
+   ret = hclge_cmd_send(>hw, desc, HCLGE_TM_PFC_PKT_GET_CMD_NUM);
+   if (ret) {
+   dev_err(>pdev->dev,
+   "Get pfc pause stats fail, ret = %d.\n", ret);
+   return ret;
+   }
+
+   for (i = 0; i < HCLGE_TM_PFC_PKT_GET_CMD_NUM; i++) {
+   struct hclge_pfc_stats_cmd *pfc_stats =
+   (struct hclge_pfc_stats_cmd *)desc[i].data;
+
+   for (j = 0; j < HCLGE_TM_PFC_NUM_GET_PER_CMD; j++) {
+   u32 index = i * HCLGE_TM_PFC_PKT_GET_CMD_NUM + j;
+
+   if (index < HCLGE_MAX_TC_NUM)
+   stats[index] =
+   le64_to_cpu(pfc_stats->pkt_num[j]);
+   }
+   }
+   return 0;
+}
+
+int hclge_pfc_rx_stats_get(struct hclge_dev *hdev, u64 *stats)
+{
+   return hclge_pfc_stats_get(hdev, HCLGE_OPC_QUERY_PFC_RX_PKT_CNT, stats);
+}
+
+int hclge_pfc_tx_stats_get(struct hclge_dev *hdev, u64 *stats)
+{
+   return hclge_pfc_stats_get(hdev, HCLGE_OPC_QUERY_PFC_TX_PKT_CNT, stats);
+}
+
 int hclge_mac_pause_en_cfg(struct hclge_dev *hdev, bool tx, bool rx)
 {
struct hclge_desc desc;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h
index c30c85b..2dbe177 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h
@@ -109,6 +109,10 @@ struct hclge_cfg_pause_param_cmd {
__le16 pause_trans_time;
 };
 
+struct hclge_pfc_stats_cmd {
+   __le64 pkt_num[3];
+};
+
 struct hclge_port_shapping_cmd {
__le32 port_shapping_para;
 };
@@ -130,4 +134,6 @@ int hclge_tm_map_cfg(struct h

[PATCH net-next 06/12] net: hns3: add support for querying pfc puase packets statistic

2018-03-09 Thread Peng Li
This patch add support for querying pfc puase packets statistic
in hclge_ieee_getpfc, which is used to tell user how many pfc
puase packets have been sent and received by this mac port.

Signed-off-by: Yunsheng Lin 
Signed-off-by: Peng Li 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c | 14 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  | 53 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |  6 +++
 3 files changed, 73 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c
index 407cfab..955f0e3 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_dcb.c
@@ -205,9 +205,11 @@ static int hclge_ieee_setets(struct hnae3_handle *h, 
struct ieee_ets *ets)
 
 static int hclge_ieee_getpfc(struct hnae3_handle *h, struct ieee_pfc *pfc)
 {
+   u64 requests[HNAE3_MAX_TC], indications[HNAE3_MAX_TC];
struct hclge_vport *vport = hclge_get_vport(h);
struct hclge_dev *hdev = vport->back;
u8 i, j, pfc_map, *prio_tc;
+   int ret;
 
memset(pfc, 0, sizeof(*pfc));
pfc->pfc_cap = hdev->pfc_max;
@@ -222,6 +224,18 @@ static int hclge_ieee_getpfc(struct hnae3_handle *h, 
struct ieee_pfc *pfc)
}
}
 
+   ret = hclge_pfc_tx_stats_get(hdev, requests);
+   if (ret)
+   return ret;
+
+   ret = hclge_pfc_rx_stats_get(hdev, indications);
+   if (ret)
+   return ret;
+
+   for (i = 0; i < HCLGE_MAX_TC_NUM; i++) {
+   pfc->requests[i] = requests[i];
+   pfc->indications[i] = indications[i];
+   }
return 0;
 }
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
index 4134a82..885f25c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
@@ -23,6 +23,9 @@ enum hclge_shaper_level {
HCLGE_SHAPER_LVL_PF = 1,
 };
 
+#define HCLGE_TM_PFC_PKT_GET_CMD_NUM   3
+#define HCLGE_TM_PFC_NUM_GET_PER_CMD   3
+
 #define HCLGE_SHAPER_BS_U_DEF  5
 #define HCLGE_SHAPER_BS_S_DEF  20
 
@@ -112,6 +115,56 @@ static int hclge_shaper_para_calc(u32 ir, u8 shaper_level,
return 0;
 }
 
+static int hclge_pfc_stats_get(struct hclge_dev *hdev,
+  enum hclge_opcode_type opcode, u64 *stats)
+{
+   struct hclge_desc desc[HCLGE_TM_PFC_PKT_GET_CMD_NUM];
+   int ret, i, j;
+
+   if (!(opcode == HCLGE_OPC_QUERY_PFC_RX_PKT_CNT ||
+ opcode == HCLGE_OPC_QUERY_PFC_TX_PKT_CNT))
+   return -EINVAL;
+
+   for (i = 0; i < HCLGE_TM_PFC_PKT_GET_CMD_NUM; i++) {
+   hclge_cmd_setup_basic_desc([i], opcode, true);
+   if (i != (HCLGE_TM_PFC_PKT_GET_CMD_NUM - 1))
+   desc[i].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+   else
+   desc[i].flag &= ~cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+   }
+
+   ret = hclge_cmd_send(>hw, desc, HCLGE_TM_PFC_PKT_GET_CMD_NUM);
+   if (ret) {
+   dev_err(>pdev->dev,
+   "Get pfc pause stats fail, ret = %d.\n", ret);
+   return ret;
+   }
+
+   for (i = 0; i < HCLGE_TM_PFC_PKT_GET_CMD_NUM; i++) {
+   struct hclge_pfc_stats_cmd *pfc_stats =
+   (struct hclge_pfc_stats_cmd *)desc[i].data;
+
+   for (j = 0; j < HCLGE_TM_PFC_NUM_GET_PER_CMD; j++) {
+   u32 index = i * HCLGE_TM_PFC_PKT_GET_CMD_NUM + j;
+
+   if (index < HCLGE_MAX_TC_NUM)
+   stats[index] =
+   le64_to_cpu(pfc_stats->pkt_num[j]);
+   }
+   }
+   return 0;
+}
+
+int hclge_pfc_rx_stats_get(struct hclge_dev *hdev, u64 *stats)
+{
+   return hclge_pfc_stats_get(hdev, HCLGE_OPC_QUERY_PFC_RX_PKT_CNT, stats);
+}
+
+int hclge_pfc_tx_stats_get(struct hclge_dev *hdev, u64 *stats)
+{
+   return hclge_pfc_stats_get(hdev, HCLGE_OPC_QUERY_PFC_TX_PKT_CNT, stats);
+}
+
 int hclge_mac_pause_en_cfg(struct hclge_dev *hdev, bool tx, bool rx)
 {
struct hclge_desc desc;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h
index c30c85b..2dbe177 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h
@@ -109,6 +109,10 @@ struct hclge_cfg_pause_param_cmd {
__le16 pause_trans_time;
 };
 
+struct hclge_pfc_stats_cmd {
+   __le64 pkt_num[3];
+};
+
 struct hclge_port_shapping_cmd {
__le32 port_shapping_para;
 };
@@ -130,4 +134,6 @@ int hclge_tm_map_cfg(struct hclge_dev *hdev);
 int hclge_tm_init_hw(struct hclge_dev *h

[PATCH net-next 03/12] net: hns3: fix for ipv6 address loss problem after setting channels

2018-03-09 Thread Peng Li
From: Fuyun Liang <liangfuy...@huawei.com>

The function of dev_close and dev_open is just likes ifconfig  down
and ifconfig  up. The ipv6 address will be lost after dev_close and
dev_open are called. This patch uses hns3_nic_net_stop to replace dev_close
and uses hns3_nic_net_open to replace dev_open.

Signed-off-by: Fuyun Liang <liangfuy...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 8113d22..4dba974 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -3503,7 +3503,7 @@ int hns3_set_channels(struct net_device *netdev,
return 0;
 
if (if_running)
-   dev_close(netdev);
+   hns3_nic_net_stop(netdev);
 
hns3_clear_all_ring(h);
 
@@ -3546,7 +3546,7 @@ int hns3_set_channels(struct net_device *netdev,
 
 open_netdev:
if (if_running)
-   dev_open(netdev);
+   hns3_nic_net_open(netdev);
 
return ret;
 }
-- 
2.9.3



[PATCH net-next 05/12] net: hns3: fix rx path skb->truesize reporting bug

2018-03-09 Thread Peng Li
Original skb->truesize reports the received packet size,
not the actual buffer size NIC driver allocated(1 Page).
The linux net protocol will misjudge the true size of rx queue.

Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 4dba974..94f0b92 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2080,15 +2080,13 @@ static void hns3_nic_reuse_page(struct sk_buff *skb, 
int i,
desc = >desc[ring->next_to_clean];
size = le16_to_cpu(desc->rx.size);
 
-   if (twobufs) {
-   truesize = hnae_buf_size(ring);
-   } else {
-   truesize = ALIGN(size, L1_CACHE_BYTES);
+   truesize = hnae_buf_size(ring);
+
+   if (!twobufs)
last_offset = hnae_page_size(ring) - hnae_buf_size(ring);
-   }
 
skb_add_rx_frag(skb, i, desc_cb->priv, desc_cb->page_offset + pull_len,
-   size - pull_len, truesize - pull_len);
+   size - pull_len, truesize);
 
 /* Avoid re-using remote pages,flag default unreuse */
if (unlikely(page_to_nid(desc_cb->priv) != numa_node_id()))
-- 
2.9.3



[PATCH net-next 03/12] net: hns3: fix for ipv6 address loss problem after setting channels

2018-03-09 Thread Peng Li
From: Fuyun Liang 

The function of dev_close and dev_open is just likes ifconfig  down
and ifconfig  up. The ipv6 address will be lost after dev_close and
dev_open are called. This patch uses hns3_nic_net_stop to replace dev_close
and uses hns3_nic_net_open to replace dev_open.

Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 8113d22..4dba974 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -3503,7 +3503,7 @@ int hns3_set_channels(struct net_device *netdev,
return 0;
 
if (if_running)
-   dev_close(netdev);
+   hns3_nic_net_stop(netdev);
 
hns3_clear_all_ring(h);
 
@@ -3546,7 +3546,7 @@ int hns3_set_channels(struct net_device *netdev,
 
 open_netdev:
if (if_running)
-   dev_open(netdev);
+   hns3_nic_net_open(netdev);
 
return ret;
 }
-- 
2.9.3



[PATCH net-next 05/12] net: hns3: fix rx path skb->truesize reporting bug

2018-03-09 Thread Peng Li
Original skb->truesize reports the received packet size,
not the actual buffer size NIC driver allocated(1 Page).
The linux net protocol will misjudge the true size of rx queue.

Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 4dba974..94f0b92 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2080,15 +2080,13 @@ static void hns3_nic_reuse_page(struct sk_buff *skb, 
int i,
desc = >desc[ring->next_to_clean];
size = le16_to_cpu(desc->rx.size);
 
-   if (twobufs) {
-   truesize = hnae_buf_size(ring);
-   } else {
-   truesize = ALIGN(size, L1_CACHE_BYTES);
+   truesize = hnae_buf_size(ring);
+
+   if (!twobufs)
last_offset = hnae_page_size(ring) - hnae_buf_size(ring);
-   }
 
skb_add_rx_frag(skb, i, desc_cb->priv, desc_cb->page_offset + pull_len,
-   size - pull_len, truesize - pull_len);
+   size - pull_len, truesize);
 
 /* Avoid re-using remote pages,flag default unreuse */
if (unlikely(page_to_nid(desc_cb->priv) != numa_node_id()))
-- 
2.9.3



[PATCH net-next 10/12] net: hns3: fix return value error of hclge_get_mac_vlan_cmd_status()

2018-03-09 Thread Peng Li
From: Jian Shen <shenjia...@huawei.com>

Error code -EIO was used to indicate mutilple errors in function
hclge_get_mac_vlan_cmd_status().This patch fixes it by using
error code depending on the error type.

For no space error, return -ENOSPC.
For entry not found, return -ENOENT.
For command send fail, return -EIO.
For invalid op code, return -EINVAL.

Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support")
Signed-off-by: Jian Shen <shenjia...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index ba84281..47dcc98 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3779,11 +3779,11 @@ static int hclge_get_mac_vlan_cmd_status(struct 
hclge_vport *vport,
if ((!resp_code) || (resp_code == 1)) {
return_status = 0;
} else if (resp_code == 2) {
-   return_status = -EIO;
+   return_status = -ENOSPC;
dev_err(>pdev->dev,
"add mac addr failed for uc_overflow.\n");
} else if (resp_code == 3) {
-   return_status = -EIO;
+   return_status = -ENOSPC;
dev_err(>pdev->dev,
"add mac addr failed for mc_overflow.\n");
} else {
@@ -3795,7 +3795,7 @@ static int hclge_get_mac_vlan_cmd_status(struct 
hclge_vport *vport,
if (!resp_code) {
return_status = 0;
} else if (resp_code == 1) {
-   return_status = -EIO;
+   return_status = -ENOENT;
dev_dbg(>pdev->dev,
"remove mac addr failed for miss.\n");
} else {
@@ -3807,7 +3807,7 @@ static int hclge_get_mac_vlan_cmd_status(struct 
hclge_vport *vport,
if (!resp_code) {
return_status = 0;
} else if (resp_code == 1) {
-   return_status = -EIO;
+   return_status = -ENOENT;
dev_dbg(>pdev->dev,
"lookup mac addr failed for miss.\n");
} else {
@@ -3816,7 +3816,7 @@ static int hclge_get_mac_vlan_cmd_status(struct 
hclge_vport *vport,
resp_code);
}
} else {
-   return_status = -EIO;
+   return_status = -EINVAL;
dev_err(>pdev->dev,
"unknown opcode for 
get_mac_vlan_cmd_status,opcode=%d.\n",
op);
-- 
2.9.3



[PATCH net-next 10/12] net: hns3: fix return value error of hclge_get_mac_vlan_cmd_status()

2018-03-09 Thread Peng Li
From: Jian Shen 

Error code -EIO was used to indicate mutilple errors in function
hclge_get_mac_vlan_cmd_status().This patch fixes it by using
error code depending on the error type.

For no space error, return -ENOSPC.
For entry not found, return -ENOENT.
For command send fail, return -EIO.
For invalid op code, return -EINVAL.

Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support")
Signed-off-by: Jian Shen 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index ba84281..47dcc98 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3779,11 +3779,11 @@ static int hclge_get_mac_vlan_cmd_status(struct 
hclge_vport *vport,
if ((!resp_code) || (resp_code == 1)) {
return_status = 0;
} else if (resp_code == 2) {
-   return_status = -EIO;
+   return_status = -ENOSPC;
dev_err(>pdev->dev,
"add mac addr failed for uc_overflow.\n");
} else if (resp_code == 3) {
-   return_status = -EIO;
+   return_status = -ENOSPC;
dev_err(>pdev->dev,
"add mac addr failed for mc_overflow.\n");
} else {
@@ -3795,7 +3795,7 @@ static int hclge_get_mac_vlan_cmd_status(struct 
hclge_vport *vport,
if (!resp_code) {
return_status = 0;
} else if (resp_code == 1) {
-   return_status = -EIO;
+   return_status = -ENOENT;
dev_dbg(>pdev->dev,
"remove mac addr failed for miss.\n");
} else {
@@ -3807,7 +3807,7 @@ static int hclge_get_mac_vlan_cmd_status(struct 
hclge_vport *vport,
if (!resp_code) {
return_status = 0;
} else if (resp_code == 1) {
-   return_status = -EIO;
+   return_status = -ENOENT;
dev_dbg(>pdev->dev,
"lookup mac addr failed for miss.\n");
} else {
@@ -3816,7 +3816,7 @@ static int hclge_get_mac_vlan_cmd_status(struct 
hclge_vport *vport,
resp_code);
}
} else {
-   return_status = -EIO;
+   return_status = -EINVAL;
dev_err(>pdev->dev,
"unknown opcode for 
get_mac_vlan_cmd_status,opcode=%d.\n",
op);
-- 
2.9.3



[PATCH net-next 12/12] net: hns3: add result checking for VF when modify unicast mac address

2018-03-09 Thread Peng Li
From: Jian Shen <shenjia...@huawei.com>

VF changes unicast mac address by sending mailbox msg to PF, then PF
completes the mac address modification. It may fail when the target
uc mac address is already in the mac_vlan table. VF should be aware
of it by reading the message result.

Signed-off-by: Jian Shen <shenjia...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c| 2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c  | 4 
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
index e3e4ded..4a49a6b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
@@ -365,7 +365,7 @@ void hclge_mbx_handler(struct hclge_dev *hdev)
ret);
break;
case HCLGE_MBX_SET_UNICAST:
-   ret = hclge_set_vf_uc_mac_addr(vport, req, false);
+   ret = hclge_set_vf_uc_mac_addr(vport, req, true);
if (ret)
dev_err(>pdev->dev,
"PF fail(%d) to set VF UC MAC Addr\n",
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index 6c240d6..2337025 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -744,7 +744,7 @@ static int hclgevf_set_mac_addr(struct hnae3_handle 
*handle, void *p,
 
status = hclgevf_send_mbx_msg(hdev, HCLGE_MBX_SET_UNICAST,
  subcode, msg_data, ETH_ALEN * 2,
- false, NULL, 0);
+ true, NULL, 0);
if (!status)
ether_addr_copy(hdev->hw.mac.mac_addr, new_mac_addr);
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c
index 18283ef..9768f71 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c
@@ -54,6 +54,10 @@ static int hclgevf_get_mbx_resp(struct hclgevf_dev *hdev, 
u16 code0, u16 code1,
mbx_resp = >mbx_resp;
r_code0 = (u16)(mbx_resp->origin_mbx_msg >> 16);
r_code1 = (u16)(mbx_resp->origin_mbx_msg & 0xff);
+
+   if (mbx_resp->resp_status)
+   return mbx_resp->resp_status;
+
if (resp_data)
memcpy(resp_data, _resp->additional_info[0], resp_len);
 
-- 
2.9.3



[PATCH net-next 09/12] net: hns3: fix error type definition of return value

2018-03-09 Thread Peng Li
From: Jian Shen <shenjia...@huawei.com>

An enum type variable was used to store an "int" type return value.
This patch fixes it.

Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support")
Signed-off-by: Jian Shen <shenjia...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index ea33cc5..ba84281 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4107,8 +4107,8 @@ int hclge_add_uc_addr_common(struct hclge_vport *vport,
 {
struct hclge_dev *hdev = vport->back;
struct hclge_mac_vlan_tbl_entry_cmd req;
-   enum hclge_cmd_status status;
u16 egress_port = 0;
+   int ret;
 
/* mac addr check */
if (is_zero_ether_addr(addr) ||
@@ -4140,9 +4140,9 @@ int hclge_add_uc_addr_common(struct hclge_vport *vport,
 
hclge_prepare_mac_addr(, addr);
 
-   status = hclge_add_mac_vlan_tbl(vport, , NULL);
+   ret = hclge_add_mac_vlan_tbl(vport, , NULL);
 
-   return status;
+   return ret;
 }
 
 static int hclge_rm_uc_addr(struct hnae3_handle *handle,
@@ -4158,7 +4158,7 @@ int hclge_rm_uc_addr_common(struct hclge_vport *vport,
 {
struct hclge_dev *hdev = vport->back;
struct hclge_mac_vlan_tbl_entry_cmd req;
-   enum hclge_cmd_status status;
+   int ret;
 
/* mac addr check */
if (is_zero_ether_addr(addr) ||
@@ -4174,9 +4174,9 @@ int hclge_rm_uc_addr_common(struct hclge_vport *vport,
hnae_set_bit(req.flags, HCLGE_MAC_VLAN_BIT0_EN_B, 1);
hnae_set_bit(req.entry_type, HCLGE_MAC_VLAN_BIT0_EN_B, 0);
hclge_prepare_mac_addr(, addr);
-   status = hclge_remove_mac_vlan_tbl(vport, );
+   ret = hclge_remove_mac_vlan_tbl(vport, );
 
-   return status;
+   return ret;
 }
 
 static int hclge_add_mc_addr(struct hnae3_handle *handle,
-- 
2.9.3



[PATCH net-next 11/12] net: hns3: add existence checking before adding unicast mac address

2018-03-09 Thread Peng Li
From: Jian Shen <shenjia...@huawei.com>

It's not allowed to add two same unicast mac address entries to the
mac_vlan table. When modify the uc mac address of a VF device to the
same value with the PF device's, the PF device will lose its entry of
the mac_vlan table.

Lookup the mac address in the mac_vlan table, and add it if the entry
is inexistent.

Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support")
Signed-off-by: Jian Shen <shenjia...@huawei.com>
Signed-off-by: Peng Li <lipeng...@huawei.com>
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 47dcc98..d70619b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4107,6 +4107,7 @@ int hclge_add_uc_addr_common(struct hclge_vport *vport,
 {
struct hclge_dev *hdev = vport->back;
struct hclge_mac_vlan_tbl_entry_cmd req;
+   struct hclge_desc desc;
u16 egress_port = 0;
int ret;
 
@@ -4140,7 +4141,21 @@ int hclge_add_uc_addr_common(struct hclge_vport *vport,
 
hclge_prepare_mac_addr(, addr);
 
-   ret = hclge_add_mac_vlan_tbl(vport, , NULL);
+   /* Lookup the mac address in the mac_vlan table, and add
+* it if the entry is inexistent. Repeated unicast entry
+* is not allowed in the mac vlan table.
+*/
+   ret = hclge_lookup_mac_vlan_tbl(vport, , , false);
+   if (ret == -ENOENT)
+   return hclge_add_mac_vlan_tbl(vport, , NULL);
+
+   /* check if we just hit the duplicate */
+   if (!ret)
+   ret = -EINVAL;
+
+   dev_err(>pdev->dev,
+   "PF failed to add unicast entry(%pM) in the MAC table\n",
+   addr);
 
return ret;
 }
-- 
2.9.3



[PATCH net-next 09/12] net: hns3: fix error type definition of return value

2018-03-09 Thread Peng Li
From: Jian Shen 

An enum type variable was used to store an "int" type return value.
This patch fixes it.

Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support")
Signed-off-by: Jian Shen 
Signed-off-by: Peng Li 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index ea33cc5..ba84281 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4107,8 +4107,8 @@ int hclge_add_uc_addr_common(struct hclge_vport *vport,
 {
struct hclge_dev *hdev = vport->back;
struct hclge_mac_vlan_tbl_entry_cmd req;
-   enum hclge_cmd_status status;
u16 egress_port = 0;
+   int ret;
 
/* mac addr check */
if (is_zero_ether_addr(addr) ||
@@ -4140,9 +4140,9 @@ int hclge_add_uc_addr_common(struct hclge_vport *vport,
 
hclge_prepare_mac_addr(, addr);
 
-   status = hclge_add_mac_vlan_tbl(vport, , NULL);
+   ret = hclge_add_mac_vlan_tbl(vport, , NULL);
 
-   return status;
+   return ret;
 }
 
 static int hclge_rm_uc_addr(struct hnae3_handle *handle,
@@ -4158,7 +4158,7 @@ int hclge_rm_uc_addr_common(struct hclge_vport *vport,
 {
struct hclge_dev *hdev = vport->back;
struct hclge_mac_vlan_tbl_entry_cmd req;
-   enum hclge_cmd_status status;
+   int ret;
 
/* mac addr check */
if (is_zero_ether_addr(addr) ||
@@ -4174,9 +4174,9 @@ int hclge_rm_uc_addr_common(struct hclge_vport *vport,
hnae_set_bit(req.flags, HCLGE_MAC_VLAN_BIT0_EN_B, 1);
hnae_set_bit(req.entry_type, HCLGE_MAC_VLAN_BIT0_EN_B, 0);
hclge_prepare_mac_addr(, addr);
-   status = hclge_remove_mac_vlan_tbl(vport, );
+   ret = hclge_remove_mac_vlan_tbl(vport, );
 
-   return status;
+   return ret;
 }
 
 static int hclge_add_mc_addr(struct hnae3_handle *handle,
-- 
2.9.3



  1   2   3   4   >