[PATCH net-next 17/17] net: hns3: change TM sched mode to TC-based mode when SRIOV enabled

2017-12-18 Thread Lipeng
TC-based sched mode supports SRIOV enabled and SRIOV disabled. This
patch change the TM sched mode to TC-based mode in initialization
process.

Fixes: cc9bb43 (net: hns3: Add tc-based TM support for sriov enabled port)
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 1ec03bc..28b1364 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -1100,10 +1100,7 @@ static int hclge_configure(struct hclge_dev *hdev)
for (i = 0; i < hdev->tm_info.num_tc; i++)
hnae_set_bit(hdev->hw_tc_map, i, 1);
 
-   if (!hdev->num_vmdq_vport && !hdev->num_req_vfs)
-   hdev->tx_sch_mode = HCLGE_FLAG_TC_BASE_SCH_MODE;
-   else
-   hdev->tx_sch_mode = HCLGE_FLAG_VNET_BASE_SCH_MODE;
+   hdev->tx_sch_mode = HCLGE_FLAG_TC_BASE_SCH_MODE;
 
return ret;
 }
-- 
1.9.1



[PATCH net-next 12/17] net: hns3: add support for set_pauseparam

2017-12-18 Thread Lipeng
This patch adds set_pauseparam support for ethtool cmd.

Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 13 
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 83 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  |  2 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |  1 +
 4 files changed, 98 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index 59fae11..e56a586 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -559,6 +559,18 @@ static void hns3_get_pauseparam(struct net_device *netdev,
¶m->rx_pause, ¶m->tx_pause);
 }
 
+static int hns3_set_pauseparam(struct net_device *netdev,
+  struct ethtool_pauseparam *param)
+{
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+
+   if (h->ae_algo->ops->set_pauseparam)
+   return h->ae_algo->ops->set_pauseparam(h, param->autoneg,
+  param->rx_pause,
+  param->tx_pause);
+   return -EOPNOTSUPP;
+}
+
 static int hns3_get_link_ksettings(struct net_device *netdev,
   struct ethtool_link_ksettings *cmd)
 {
@@ -880,6 +892,7 @@ void hns3_get_channels(struct net_device *netdev,
.get_ringparam = hns3_get_ringparam,
.set_ringparam = hns3_set_ringparam,
.get_pauseparam = hns3_get_pauseparam,
+   .set_pauseparam = hns3_set_pauseparam,
.get_strings = hns3_get_strings,
.get_ethtool_stats = hns3_get_stats,
.get_sset_count = hns3_get_sset_count,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index cc326de..8bfa287 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4660,6 +4660,53 @@ static u32 hclge_get_fw_version(struct hnae3_handle 
*handle)
return hdev->fw_version;
 }
 
+static void hclge_set_flowctrl_adv(struct hclge_dev *hdev, u32 rx_en, u32 
tx_en)
+{
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+
+   if (!phydev)
+   return;
+
+   phydev->advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause);
+
+   if (rx_en)
+   phydev->advertising |= ADVERTISED_Pause | ADVERTISED_Asym_Pause;
+
+   if (tx_en)
+   phydev->advertising ^= ADVERTISED_Asym_Pause;
+}
+
+static int hclge_cfg_pauseparam(struct hclge_dev *hdev, u32 rx_en, u32 tx_en)
+{
+   enum hclge_fc_mode fc_mode;
+   int ret;
+
+   if (rx_en && tx_en)
+   fc_mode = HCLGE_FC_FULL;
+   else if (rx_en && !tx_en)
+   fc_mode = HCLGE_FC_RX_PAUSE;
+   else if (!rx_en && tx_en)
+   fc_mode = HCLGE_FC_TX_PAUSE;
+   else
+   fc_mode = HCLGE_FC_NONE;
+
+   if (hdev->tm_info.fc_mode == HCLGE_FC_PFC) {
+   hdev->fc_mode_last_time = fc_mode;
+   return 0;
+   }
+
+   ret = hclge_mac_pause_en_cfg(hdev, tx_en, rx_en);
+   if (ret) {
+   dev_err(&hdev->pdev->dev, "configure pauseparam error, ret = 
%d.\n",
+   ret);
+   return ret;
+   }
+
+   hdev->tm_info.fc_mode = fc_mode;
+
+   return 0;
+}
+
 static void hclge_get_pauseparam(struct hnae3_handle *handle, u32 *auto_neg,
 u32 *rx_en, u32 *tx_en)
 {
@@ -4689,6 +4736,41 @@ static void hclge_get_pauseparam(struct hnae3_handle 
*handle, u32 *auto_neg,
}
 }
 
+static int hclge_set_pauseparam(struct hnae3_handle *handle, u32 auto_neg,
+   u32 rx_en, u32 tx_en)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+   struct hclge_dev *hdev = vport->back;
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+   u32 fc_autoneg;
+
+   /* Only support flow control negotiation for netdev with
+* phy attached for now.
+*/
+   if (!phydev)
+   return -EOPNOTSUPP;
+
+   fc_autoneg = hclge_get_autoneg(handle);
+   if (auto_neg != fc_autoneg) {
+   dev_info(&hdev->pdev->dev,
+"To change autoneg please use: ethtool -s  
autoneg \n");
+   return -EOPNOTSUPP;
+   }
+
+   if (hdev->tm_info.fc_mode == HCLGE_FC_PFC) {
+   dev_info(&hdev->pdev->dev,
+"Priority flow control enabled. Cannot set link flow 
control.\n");
+   return -EOPNOTSUPP;
+   }
+
+   hclge_set_flowctrl_adv(hdev, rx_en,

[PATCH net-next 15/17] net: hns3: add support for querying advertised pause frame by ethtool ethx

2017-12-18 Thread Lipeng
This patch adds support for querying advertised pause frame by using
ethtool command(ethtool ethx).

Fixes: 496d03e960ae (net: hns3: Add Ethtool support to HNS3 driver)
Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h |  2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c  | 15 +++
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 15 +++
 3 files changed, 32 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index a67d02a9..82e9a80 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -394,6 +394,8 @@ struct hnae3_ae_ops {
void (*get_tqps_and_rss_info)(struct hnae3_handle *h,
  u16 *free_tqps, u16 *max_rss_size);
int (*set_channels)(struct hnae3_handle *handle, u32 new_tqps_num);
+   void (*get_flowctrl_adv)(struct hnae3_handle *handle,
+u32 *flowctrl_adv);
 };
 
 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 e56a586..f217a24 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -575,6 +575,7 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
   struct ethtool_link_ksettings *cmd)
 {
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;
@@ -650,6 +651,8 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
if (!cmd->base.autoneg)
advertised_caps &= ~HNS3_LM_AUTONEG_BIT;
 
+   advertised_caps &= ~HNS3_LM_PAUSE_BIT;
+
/* now, map driver link modes to ethtool link modes */
hns3_driv_to_eth_caps(supported_caps, cmd, false);
hns3_driv_to_eth_caps(advertised_caps, cmd, true);
@@ -662,6 +665,18 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
/* 4.mdio_support */
cmd->base.mdio_support = ETH_MDIO_SUPPORTS_C22;
 
+   /* 5.get flow control setttings */
+   if (h->ae_algo->ops->get_flowctrl_adv)
+   h->ae_algo->ops->get_flowctrl_adv(h, &flowctrl_adv);
+
+   if (flowctrl_adv & ADVERTISED_Pause)
+   ethtool_link_ksettings_add_link_mode(cmd, advertising,
+Pause);
+
+   if (flowctrl_adv & ADVERTISED_Asym_Pause)
+   ethtool_link_ksettings_add_link_mode(cmd, advertising,
+Asym_Pause);
+
return 0;
 }
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 26b07c3..1ec03bc 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4660,6 +4660,20 @@ static u32 hclge_get_fw_version(struct hnae3_handle 
*handle)
return hdev->fw_version;
 }
 
+static void hclge_get_flowctrl_adv(struct hnae3_handle *handle,
+  u32 *flowctrl_adv)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+   struct hclge_dev *hdev = vport->back;
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+
+   if (!phydev)
+   return;
+
+   *flowctrl_adv |= (phydev->advertising & ADVERTISED_Pause) |
+(phydev->advertising & ADVERTISED_Asym_Pause);
+}
+
 static void hclge_set_flowctrl_adv(struct hclge_dev *hdev, u32 rx_en, u32 
tx_en)
 {
struct phy_device *phydev = hdev->hw.mac.phydev;
@@ -5477,6 +5491,7 @@ static int hclge_set_channels(struct hnae3_handle 
*handle, u32 new_tqps_num)
.get_tqps_and_rss_info = hclge_get_tqps_and_rss_info,
.set_channels = hclge_set_channels,
.get_channels = hclge_get_channels,
+   .get_flowctrl_adv = hclge_get_flowctrl_adv,
 };
 
 static struct hnae3_ae_algo ae_algo = {
-- 
1.9.1



[PATCH net-next 11/17] net: hns3: fix for getting auto-negotiation state in hclge_get_autoneg

2017-12-18 Thread Lipeng
From: Fuyun Liang 

When phy exists, we use the value of phydev.autoneg to represent the
auto-negotiation state of hardware. Otherwise, we use the value of
mac.autoneg to represent it.

This patch fixes for getting a error value of auto-negotiation state in
hclge_get_autoneg().

Fixes: 46a3df9f9718 (net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support)
Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 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 6879bad..cc326de 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2172,6 +2172,10 @@ static int hclge_get_autoneg(struct hnae3_handle *handle)
 {
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+
+   if (phydev)
+   return phydev->autoneg;
 
return hdev->hw.mac.autoneg;
 }
-- 
1.9.1



[PATCH net-next 13/17] net: hns3: add support to update flow control settings after autoneg

2017-12-18 Thread Lipeng
When auto-negotiation is enabled, the MAC flow control settings is
based on the flow control negotiation result. And it should be configured
after a valid link has been established. This patch adds support to update
flow control settings after auto-negotiation has completed.

Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 36 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c|  4 +++
 3 files changed, 41 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 8bfa287..26b07c3 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4707,6 +4707,42 @@ static int hclge_cfg_pauseparam(struct hclge_dev *hdev, 
u32 rx_en, u32 tx_en)
return 0;
 }
 
+int hclge_cfg_flowctrl(struct hclge_dev *hdev)
+{
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+   u16 local_advertising = 0;
+   u16 remote_advertising = 0;
+   u32 rx_pause, tx_pause;
+   u8 flowctl;
+
+   if (!phydev->link || !phydev->autoneg)
+   return 0;
+
+   if (phydev->advertising & ADVERTISED_Pause)
+   local_advertising = ADVERTISE_PAUSE_CAP;
+
+   if (phydev->advertising & ADVERTISED_Asym_Pause)
+   local_advertising |= ADVERTISE_PAUSE_ASYM;
+
+   if (phydev->pause)
+   remote_advertising = LPA_PAUSE_CAP;
+
+   if (phydev->asym_pause)
+   remote_advertising |= LPA_PAUSE_ASYM;
+
+   flowctl = mii_resolve_flowctrl_fdx(local_advertising,
+  remote_advertising);
+   tx_pause = flowctl & FLOW_CTRL_TX;
+   rx_pause = flowctl & FLOW_CTRL_RX;
+
+   if (phydev->duplex == HCLGE_MAC_HALF) {
+   tx_pause = 0;
+   rx_pause = 0;
+   }
+
+   return hclge_cfg_pauseparam(hdev, rx_pause, tx_pause);
+}
+
 static void hclge_get_pauseparam(struct hnae3_handle *handle, u32 *auto_neg,
 u32 *rx_en, u32 *tx_en)
 {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
index cda520c..28cc063 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
@@ -602,4 +602,5 @@ int hclge_set_vf_vlan_common(struct hclge_dev *vport, int 
vfid,
 
 void hclge_mbx_handler(struct hclge_dev *hdev);
 void hclge_reset_tqp(struct hnae3_handle *handle, u16 queue_id);
+int hclge_cfg_flowctrl(struct hclge_dev *hdev);
 #endif
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
index 7069e94..3745153 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -183,6 +183,10 @@ static void hclge_mac_adjust_link(struct net_device 
*netdev)
ret = hclge_cfg_mac_speed_dup(hdev, speed, duplex);
if (ret)
netdev_err(netdev, "failed to adjust link.\n");
+
+   ret = hclge_cfg_flowctrl(hdev);
+   if (ret)
+   netdev_err(netdev, "failed to configure flow control.\n");
 }
 
 int hclge_mac_start_phy(struct hclge_dev *hdev)
-- 
1.9.1



[PATCH net-next 14/17] net: hns3: add Asym Pause support to phy default features

2017-12-18 Thread Lipeng
From: Fuyun Liang 

commit c4fb2cdf575d (net: hns3: fix a bug for phy supported feature
initialization) adds default supported features for phy, but our hardware
also supports Asym Pause. This patch adds Asym Pause support to phy
default features to prevent Asym Pause can not be advertised when the phy
negotiates flow control.

Fixes: c4fb2cdf575d (net: hns3: fix a bug for phy supported feature 
initialization)
Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
index 3745153..c1dea3a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -17,6 +17,7 @@
 #define HCLGE_PHY_SUPPORTED_FEATURES   (SUPPORTED_Autoneg | \
 SUPPORTED_TP | \
 SUPPORTED_Pause | \
+SUPPORTED_Asym_Pause | \
 PHY_10BT_FEATURES | \
 PHY_100BT_FEATURES | \
 PHY_1000BT_FEATURES)
-- 
1.9.1



[PATCH net-next 16/17] net: hns3: Increase the default depth of bucket for TM shaper

2017-12-18 Thread Lipeng
Burstiness of a flow is determined by the depth of a bucket, When the
upper rate of shaper is large, the current depth of a bucket is not
enough.

The default upper rate of shaper is 100G, so increase the depth of
a bucket according to UM.

Signed-off-by: Yunsheng Lin 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
index 7cfe1eb..ea9355d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
@@ -23,8 +23,8 @@ enum hclge_shaper_level {
HCLGE_SHAPER_LVL_PF = 1,
 };
 
-#define HCLGE_SHAPER_BS_U_DEF  1
-#define HCLGE_SHAPER_BS_S_DEF  4
+#define HCLGE_SHAPER_BS_U_DEF  5
+#define HCLGE_SHAPER_BS_S_DEF  20
 
 #define HCLGE_ETHER_MAX_RATE   10
 
-- 
1.9.1



[PATCH net-next 06/17] net: hns3: Add a mask initialization for mac_vlan table

2017-12-18 Thread Lipeng
This patch sets vlan masked, in order to avoid the received
packets being filtered.

Signed-off-by: Shenjian 
Signed-off-by: Lipeng 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h | 10 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 39 +-
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 1eb9ff0..10adf86 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -191,6 +191,7 @@ enum hclge_opcode_type {
HCLGE_OPC_MAC_VLAN_INSERT   = 0x1003,
HCLGE_OPC_MAC_ETHTYPE_ADD   = 0x1010,
HCLGE_OPC_MAC_ETHTYPE_REMOVE= 0x1011,
+   HCLGE_OPC_MAC_VLAN_MASK_SET = 0x1012,
 
/* Multicast linear table cmd */
HCLGE_OPC_MTA_MAC_MODE_CFG  = 0x1020,
@@ -589,6 +590,15 @@ struct hclge_mac_vlan_tbl_entry_cmd {
u8  rsv2[6];
 };
 
+#define HCLGE_VLAN_MASK_EN_B   0x0
+struct hclge_mac_vlan_mask_entry_cmd {
+   u8 rsv0[2];
+   u8 vlan_mask;
+   u8 rsv1;
+   u8 mac_mask[6];
+   u8 rsv2[14];
+};
+
 #define HCLGE_CFG_MTA_MAC_SEL_S0x0
 #define HCLGE_CFG_MTA_MAC_SEL_MGENMASK(1, 0)
 #define HCLGE_CFG_MTA_MAC_EN_B 0x7
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index b8658b8..80d002f 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2200,9 +2200,34 @@ static int hclge_get_autoneg(struct hnae3_handle *handle)
return hdev->hw.mac.autoneg;
 }
 
+static int hclge_set_default_mac_vlan_mask(struct hclge_dev *hdev,
+  bool mask_vlan,
+  u8 *mac_mask)
+{
+   struct hclge_mac_vlan_mask_entry_cmd *req;
+   struct hclge_desc desc;
+   int status;
+
+   req = (struct hclge_mac_vlan_mask_entry_cmd *)desc.data;
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_MAC_VLAN_MASK_SET, false);
+
+   hnae_set_bit(req->vlan_mask, HCLGE_VLAN_MASK_EN_B,
+mask_vlan ? 1 : 0);
+   ether_addr_copy(req->mac_mask, mac_mask);
+
+   status = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (status)
+   dev_err(&hdev->pdev->dev,
+   "Config mac_vlan_mask failed for cmd_send, ret =%d\n",
+   status);
+
+   return status;
+}
+
 static int hclge_mac_init(struct hclge_dev *hdev)
 {
struct hclge_mac *mac = &hdev->hw.mac;
+   u8 mac_mask[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
int ret;
 
ret = hclge_cfg_mac_speed_dup(hdev, hdev->hw.mac.speed, HCLGE_MAC_FULL);
@@ -2228,7 +2253,19 @@ static int hclge_mac_init(struct hclge_dev *hdev)
return ret;
}
 
-   return hclge_cfg_func_mta_filter(hdev, 0, hdev->accept_mta_mc);
+   ret = hclge_cfg_func_mta_filter(hdev, 0, hdev->accept_mta_mc);
+   if (ret) {
+   dev_err(&hdev->pdev->dev,
+   "set mta filter mode fail ret=%d\n", ret);
+   return ret;
+   }
+
+   ret = hclge_set_default_mac_vlan_mask(hdev, true, mac_mask);
+   if (ret)
+   dev_err(&hdev->pdev->dev,
+   "set default mac_vlan_mask fail ret=%d\n", ret);
+
+   return ret;
 }
 
 static void hclge_mbx_task_schedule(struct hclge_dev *hdev)
-- 
1.9.1



[PATCH net-next 10/17] net: hns3: cleanup mac auto-negotiation state query

2017-12-18 Thread Lipeng
From: Fuyun Liang 

When checking whether auto-negotiation is on, driver only needs to
check the value of mac.autoneg(SW) directly, and does not need to
query it from hardware. Because this value is always synchronized
with the auto-negotiation state of hardware.

This patch removes the mac auto-negotiation state query.

Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 24 --
 1 file changed, 24 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 8099a7c..6879bad 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2137,28 +2137,6 @@ static int hclge_query_mac_an_speed_dup(struct hclge_dev 
*hdev, int *speed,
return 0;
 }
 
-static int hclge_query_autoneg_result(struct hclge_dev *hdev)
-{
-   struct hclge_mac *mac = &hdev->hw.mac;
-   struct hclge_query_an_speed_dup_cmd *req;
-   struct hclge_desc desc;
-   int ret;
-
-   req = (struct hclge_query_an_speed_dup_cmd *)desc.data;
-
-   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_AN_RESULT, true);
-   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
-   if (ret) {
-   dev_err(&hdev->pdev->dev,
-   "autoneg result query cmd failed %d.\n", ret);
-   return ret;
-   }
-
-   mac->autoneg = hnae_get_bit(req->an_syn_dup_speed, HCLGE_QUERY_AN_B);
-
-   return 0;
-}
-
 static int hclge_set_autoneg_en(struct hclge_dev *hdev, bool enable)
 {
struct hclge_config_auto_neg_cmd *req;
@@ -2195,8 +2173,6 @@ static int hclge_get_autoneg(struct hnae3_handle *handle)
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
 
-   hclge_query_autoneg_result(hdev);
-
return hdev->hw.mac.autoneg;
 }
 
-- 
1.9.1



[PATCH net-next 08/17] net: hns3: Add ethtool related offload command

2017-12-18 Thread Lipeng
This patch adds offload command related to "ethtool -K".

Signed-off-by: Shenjian 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h |  3 +++
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 16 
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 13 +
 3 files changed, 32 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index a5d3d22..a67d02a9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -278,6 +278,8 @@ struct hnae3_ae_dev {
  *   Set vlan filter config of Ports
  * set_vf_vlan_filter()
  *   Set vlan filter config of vf
+ * enable_hw_strip_rxvtag()
+ *   Enable/disable hardware strip vlan tag of packets received
  */
 struct hnae3_ae_ops {
int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev);
@@ -384,6 +386,7 @@ struct hnae3_ae_ops {
   u16 vlan_id, bool is_kill);
int (*set_vf_vlan_filter)(struct hnae3_handle *handle, int vfid,
  u16 vlan, u8 qos, __be16 proto);
+   int (*enable_hw_strip_rxvtag)(struct hnae3_handle *handle, bool enable);
void (*reset_event)(struct hnae3_handle *handle,
enum hnae3_reset_type reset);
void (*get_channels)(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 2aeddf9..956c85f 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1032,6 +1032,9 @@ static int hns3_nic_set_features(struct net_device 
*netdev,
 netdev_features_t features)
 {
struct hns3_nic_priv *priv = netdev_priv(netdev);
+   struct hnae3_handle *h = priv->ae_handle;
+   netdev_features_t changed;
+   int ret;
 
if (features & (NETIF_F_TSO | NETIF_F_TSO6)) {
priv->ops.fill_desc = hns3_fill_desc_tso;
@@ -1041,6 +1044,17 @@ static int hns3_nic_set_features(struct net_device 
*netdev,
priv->ops.maybe_stop_tx = hns3_nic_maybe_stop_tx;
}
 
+   changed = netdev->features ^ features;
+   if (changed & NETIF_F_HW_VLAN_CTAG_RX) {
+   if (features & NETIF_F_HW_VLAN_CTAG_RX)
+   ret = h->ae_algo->ops->enable_hw_strip_rxvtag(h, true);
+   else
+   ret = h->ae_algo->ops->enable_hw_strip_rxvtag(h, false);
+
+   if (ret)
+   return ret;
+   }
+
netdev->features = features;
return 0;
 }
@@ -1492,6 +1506,7 @@ static void hns3_set_default_feature(struct net_device 
*netdev)
 
netdev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
NETIF_F_HW_VLAN_CTAG_FILTER |
+   NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_GSO |
NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_GRE |
NETIF_F_GSO_GRE_CSUM | NETIF_F_GSO_UDP_TUNNEL |
@@ -1506,6 +1521,7 @@ static void hns3_set_default_feature(struct net_device 
*netdev)
 
netdev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
NETIF_F_HW_VLAN_CTAG_FILTER |
+   NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_GSO |
NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_GRE |
NETIF_F_GSO_GRE_CSUM | NETIF_F_GSO_UDP_TUNNEL |
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index d0118ed..8099a7c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4547,6 +4547,18 @@ static int hclge_init_vlan_config(struct hclge_dev *hdev)
return hclge_set_port_vlan_filter(handle, htons(ETH_P_8021Q), 0, false);
 }
 
+static int hclge_en_hw_strip_rxvtag(struct hnae3_handle *handle, bool enable)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+
+   vport->rxvlan_cfg.strip_tag1_en = false;
+   vport->rxvlan_cfg.strip_tag2_en = enable;
+   vport->rxvlan_cfg.vlan1_vlan_prionly = false;
+   vport->rxvlan_cfg.vlan2_vlan_prionly = false;
+
+   return hclge_set_vlan_rx_offload_cfg(vport);
+}
+
 static int hclge_set_mtu(struct hnae3_handle *handle, int new_mtu)
 {
struct hclge_vport *vport = hclge_get_vport(handle);
@@ -5361,6 +5373,7 @@ static int hclge_set_channels(struct hnae3_handle 
*handle, u32 new_tqps_num)
.get_mdix_mode = hclge_get_mdix_mode,
.set_vlan_filter = hclge_set_port_vlan_filter,
.set_vf_vlan_filter = hclge_set_vf_vlan_filter,
+  

[PATCH net-next 00/17] add some features and fix some bugs for HNS3 driver

2017-12-18 Thread Lipeng
This patchset adds some new feature support and fixes some bugs:
[Patch 1/17 - 5/17] add the support to modify/query the tqp number
through ethtool -L/l command, and also fix some related bugs for
change tqp number.
[Patch 6/17 - 9-17] add support vlan tag offload on tx&&rx direction
for pf, and fix some related bugs.
[patch 10/17 - 11/17] fix bugs for auto negotiation.
[patch 12/17] adds support for ethtool command set_pauseparam.
[patch 13/17 - 14/17] add support to update flow control settings after
autoneg.
[patch 15/17 - 17/17] fix some other bugs in net-next.

Fuyun Liang (3):
  net: hns3: cleanup mac auto-negotiation state query
  net: hns3: fix for getting auto-negotiation state in hclge_get_autoneg
  net: hns3: add Asym Pause support to phy default features

Lipeng (13):
  net: hns3: add support to query tqps number
  net: hns3: add support to modify tqps number
  net: hns3: change the returned tqp number by ethtool -x
  net: hns3: Free the ring_data structrue when change tqps
  net: hns3: Add a mask initialization for mac_vlan table
  net: hns3: Add vlan offload config command
  net: hns3: Add ethtool related offload command
  net: hns3: Add handling vlan tag offload in bd
  net: hns3: add support for set_pauseparam
  net: hns3: add support to update flow control settings after autoneg
  net: hns3: add support for querying advertised pause frame by ethtool
ethx
  net: hns3: Increase the default depth of bucket for TM shaper
  net: hns3: change TM sched mode to TC-based mode when SRIOV enabled

qumingguang (1):
  net: hns3: Get rss_size_max from configuration but not hardcode

 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  10 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 225 -
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|   2 +
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c |  41 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  57 +++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 513 +++--
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  38 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c|   5 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  |   6 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |   1 +
 10 files changed, 854 insertions(+), 44 deletions(-)

-- 
1.9.1



[PATCH net-next 05/17] net: hns3: Get rss_size_max from configuration but not hardcode

2017-12-18 Thread Lipeng
From: qumingguang 

Add configuration for rss_size_max in hdev but not hardcode it.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h  | 2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 6 +-
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index ce5ed88..1eb9ff0 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -399,6 +399,8 @@ struct hclge_pf_res_cmd {
 #define HCLGE_CFG_MAC_ADDR_H_M GENMASK(15, 0)
 #define HCLGE_CFG_DEFAULT_SPEED_S  16
 #define HCLGE_CFG_DEFAULT_SPEED_M  GENMASK(23, 16)
+#define HCLGE_CFG_RSS_SIZE_S   24
+#define HCLGE_CFG_RSS_SIZE_M   GENMASK(31, 24)
 
 struct hclge_cfg_param_cmd {
__le32 offset;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index f354681..b8658b8 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -982,6 +982,10 @@ static void hclge_parse_cfg(struct hclge_cfg *cfg, struct 
hclge_desc *desc)
cfg->default_speed = hnae_get_field(__le32_to_cpu(req->param[3]),
HCLGE_CFG_DEFAULT_SPEED_M,
HCLGE_CFG_DEFAULT_SPEED_S);
+   cfg->rss_size_max = hnae_get_field(__le32_to_cpu(req->param[3]),
+  HCLGE_CFG_RSS_SIZE_M,
+  HCLGE_CFG_RSS_SIZE_S);
+
for (i = 0; i < ETH_ALEN; i++)
cfg->mac_addr[i] = (mac_addr_tmp >> (8 * i)) & 0xff;
 
@@ -1059,7 +1063,7 @@ static int hclge_configure(struct hclge_dev *hdev)
 
hdev->num_vmdq_vport = cfg.vmdq_vport_num;
hdev->base_tqp_pid = 0;
-   hdev->rss_size_max = 1;
+   hdev->rss_size_max = cfg.rss_size_max;
hdev->rx_buf_len = cfg.rx_buf_len;
ether_addr_copy(hdev->hw.mac.mac_addr, cfg.mac_addr);
hdev->hw.mac.media_type = cfg.media_type;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
index fb043b5..4858909 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
@@ -220,6 +220,7 @@ struct hclge_cfg {
u8 tc_num;
u16 tqp_desc_num;
u16 rx_buf_len;
+   u16 rss_size_max;
u8 phy_addr;
u8 media_type;
u8 mac_addr[ETH_ALEN];
-- 
1.9.1



[PATCH net-next 03/17] net: hns3: change the returned tqp number by ethtool -x

2017-12-18 Thread Lipeng
This patch modify the return data of get_rxnfc, it will return
the current handle's rss_size but not the total tqp number.
because the tc_size has been change to the log2 of roundup
power of two of rss_size.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 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 a040445..59fae11 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -730,7 +730,7 @@ static int hns3_get_rxnfc(struct net_device *netdev,
 
switch (cmd->cmd) {
case ETHTOOL_GRXRINGS:
-   cmd->data = h->kinfo.num_tc * h->kinfo.rss_size;
+   cmd->data = h->kinfo.rss_size;
break;
case ETHTOOL_GRXFH:
return h->ae_algo->ops->get_rss_tuple(h, cmd);
-- 
1.9.1



[PATCH net-next 09/17] net: hns3: Add handling vlan tag offload in bd

2017-12-18 Thread Lipeng
This patch deals with the vlan tag information between
sk_buff and rx/tx bd.

Signed-off-by: Shenjian 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 83 +++--
 1 file changed, 78 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 956c85f..ece6bff 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -723,6 +723,58 @@ static void hns3_set_txbd_baseinfo(u16 
*bdtp_fe_sc_vld_ra_ri, int frag_end)
hnae_set_field(*bdtp_fe_sc_vld_ra_ri, HNS3_TXD_SC_M, HNS3_TXD_SC_S, 0);
 }
 
+static int hns3_fill_desc_vtags(struct sk_buff *skb,
+   struct hns3_enet_ring *tx_ring,
+   u32 *inner_vlan_flag,
+   u32 *out_vlan_flag,
+   u16 *inner_vtag,
+   u16 *out_vtag)
+{
+#define HNS3_TX_VLAN_PRIO_SHIFT 13
+
+   if (skb->protocol == htons(ETH_P_8021Q) &&
+   !(tx_ring->tqp->handle->kinfo.netdev->features &
+   NETIF_F_HW_VLAN_CTAG_TX)) {
+/* When HW VLAN acceleration is turned off, and the stack
+ * sets the protocol to 802.1q, the driver just need to
+ * set the protocol to the encapsulated ethertype.
+ */
+   skb->protocol = vlan_get_protocol(skb);
+   return 0;
+   }
+
+   if (skb_vlan_tag_present(skb)) {
+   u16 vlan_tag;
+
+   vlan_tag = skb_vlan_tag_get(skb);
+   vlan_tag |= (skb->priority & 0x7) << HNS3_TX_VLAN_PRIO_SHIFT;
+
+   /* Based on hw strategy, use out_vtag in two layer tag case,
+* and use inner_vtag in one tag case.
+*/
+   if (skb->protocol == htons(ETH_P_8021Q)) {
+   hnae_set_bit(*out_vlan_flag, HNS3_TXD_OVLAN_B, 1);
+   *out_vtag = vlan_tag;
+   } else {
+   hnae_set_bit(*inner_vlan_flag, HNS3_TXD_VLAN_B, 1);
+   *inner_vtag = vlan_tag;
+   }
+   } else if (skb->protocol == htons(ETH_P_8021Q)) {
+   struct vlan_ethhdr *vhdr;
+   int rc;
+
+   rc = skb_cow_head(skb, 0);
+   if (rc < 0)
+   return rc;
+   vhdr = (struct vlan_ethhdr *)skb->data;
+   vhdr->h_vlan_TCI |= cpu_to_be16((skb->priority & 0x7)
+   << HNS3_TX_VLAN_PRIO_SHIFT);
+   }
+
+   skb->protocol = vlan_get_protocol(skb);
+   return 0;
+}
+
 static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
  int size, dma_addr_t dma, int frag_end,
  enum hns_desc_type type)
@@ -733,6 +785,8 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void 
*priv,
u16 bdtp_fe_sc_vld_ra_ri = 0;
u32 type_cs_vlan_tso = 0;
struct sk_buff *skb;
+   u16 inner_vtag = 0;
+   u16 out_vtag = 0;
u32 paylen = 0;
u16 mss = 0;
__be16 protocol;
@@ -756,15 +810,16 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, 
void *priv,
skb = (struct sk_buff *)priv;
paylen = skb->len;
 
+   ret = hns3_fill_desc_vtags(skb, ring, &type_cs_vlan_tso,
+  &ol_type_vlan_len_msec,
+  &inner_vtag, &out_vtag);
+   if (unlikely(ret))
+   return ret;
+
if (skb->ip_summed == CHECKSUM_PARTIAL) {
skb_reset_mac_len(skb);
protocol = skb->protocol;
 
-   /* vlan packet*/
-   if (protocol == htons(ETH_P_8021Q)) {
-   protocol = vlan_get_protocol(skb);
-   skb->protocol = protocol;
-   }
ret = hns3_get_l4_protocol(skb, &ol4_proto, &il4_proto);
if (ret)
return ret;
@@ -790,6 +845,8 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void 
*priv,
cpu_to_le32(type_cs_vlan_tso);
desc->tx.paylen = cpu_to_le32(paylen);
desc->tx.mss = cpu_to_le16(mss);
+   desc->tx.vlan_tag = cpu_to_le16(inner_vtag);
+   desc->tx.outer_vlan_tag = cpu_to_le16(out_vtag);
}
 
/* move ring pointer to next.*/
@@ -2101,6 +2158,22 @@ static int hns3_handle_rx_bd(struct hns3_enet_ring *ring,
 
prefetchw(skb->data);
 
+   /* Based on hw strategy, the tag offl

[PATCH net-next 01/17] net: hns3: add support to query tqps number

2017-12-18 Thread Lipeng
This patch add the support to query tqps number for PF driver
by using ehtool -l command.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h |  2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c  | 10 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 21 +
 3 files changed, 33 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index a9e2b32..d887721 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -386,6 +386,8 @@ struct hnae3_ae_ops {
  u16 vlan, u8 qos, __be16 proto);
void (*reset_event)(struct hnae3_handle *handle,
enum hnae3_reset_type reset);
+   void (*get_channels)(struct hnae3_handle *handle,
+struct ethtool_channels *ch);
 };
 
 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 65a69b4..e7689ea 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -849,6 +849,15 @@ static int hns3_nway_reset(struct net_device *netdev)
return genphy_restart_aneg(phy);
 }
 
+void hns3_get_channels(struct net_device *netdev,
+  struct ethtool_channels *ch)
+{
+struct hnae3_handle *h = hns3_get_handle(netdev);
+
+if (h->ae_algo->ops->get_channels)
+h->ae_algo->ops->get_channels(h, ch);
+}
+
 static const struct ethtool_ops hns3vf_ethtool_ops = {
.get_drvinfo = hns3_get_drvinfo,
.get_ringparam = hns3_get_ringparam,
@@ -883,6 +892,7 @@ static int hns3_nway_reset(struct net_device *netdev)
.get_link_ksettings = hns3_get_link_ksettings,
.set_link_ksettings = hns3_set_link_ksettings,
.nway_reset = hns3_nway_reset,
+   .get_channels = hns3_get_channels,
 };
 
 void hns3_ethtool_set_ops(struct net_device *netdev)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index e97fd66..533e15e5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -5002,6 +5002,26 @@ static void hclge_uninit_ae_dev(struct hnae3_ae_dev 
*ae_dev)
ae_dev->priv = NULL;
 }
 
+static u32 hclge_get_max_channels(struct hnae3_handle *handle)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+   struct hnae3_knic_private_info *kinfo = &handle->kinfo;
+   struct hclge_dev *hdev = vport->back;
+
+   return min_t(u32, hdev->rss_size_max * kinfo->num_tc, hdev->num_tqps);
+}
+
+static void hclge_get_channels(struct hnae3_handle *handle,
+  struct ethtool_channels *ch)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+
+   ch->max_combined = hclge_get_max_channels(handle);
+   ch->other_count = 1;
+   ch->max_other = 1;
+   ch->combined_count = vport->alloc_tqps;
+}
+
 static const struct hnae3_ae_ops hclge_ops = {
.init_ae_dev = hclge_init_ae_dev,
.uninit_ae_dev = hclge_uninit_ae_dev,
@@ -5046,6 +5066,7 @@ static void hclge_uninit_ae_dev(struct hnae3_ae_dev 
*ae_dev)
.set_vlan_filter = hclge_set_port_vlan_filter,
.set_vf_vlan_filter = hclge_set_vf_vlan_filter,
.reset_event = hclge_reset_event,
+   .get_channels = hclge_get_channels,
 };
 
 static struct hnae3_ae_algo ae_algo = {
-- 
1.9.1



[PATCH net-next 04/17] net: hns3: Free the ring_data structrue when change tqps

2017-12-18 Thread Lipeng
This patch fix a memory leak problems in change tqps process,
the function hns3_uninit_all_ring and hns3_init_all_ring
may be called many times.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 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 e52de45..2aeddf9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2800,8 +2800,12 @@ int hns3_uninit_all_ring(struct hns3_nic_priv *priv)
h->ae_algo->ops->reset_queue(h, i);
 
hns3_fini_ring(priv->ring_data[i].ring);
+   devm_kfree(priv->dev, priv->ring_data[i].ring);
hns3_fini_ring(priv->ring_data[i + h->kinfo.num_tqps].ring);
+   devm_kfree(priv->dev,
+  priv->ring_data[i + h->kinfo.num_tqps].ring);
}
+   devm_kfree(priv->dev, priv->ring_data);
 
return 0;
 }
-- 
1.9.1



[PATCH net-next 07/17] net: hns3: Add vlan offload config command

2017-12-18 Thread Lipeng
This patch adds vlan offload config commands, initializes
the rules of tx/rx vlan tag handle for hw.

Signed-off-by: Shenjian 
Signed-off-by: Lipeng 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  45 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 158 -
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  36 +
 3 files changed, 233 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 10adf86..f5baba21 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -180,6 +180,10 @@ enum hclge_opcode_type {
/* Promisuous mode command */
HCLGE_OPC_CFG_PROMISC_MODE  = 0x0E01,
 
+   /* Vlan offload command */
+   HCLGE_OPC_VLAN_PORT_TX_CFG  = 0x0F01,
+   HCLGE_OPC_VLAN_PORT_RX_CFG  = 0x0F02,
+
/* Interrupts cmd */
HCLGE_OPC_ADD_RING_TO_VECTOR= 0x1503,
HCLGE_OPC_DEL_RING_TO_VECTOR= 0x1504,
@@ -670,6 +674,47 @@ struct hclge_vlan_filter_vf_cfg_cmd {
u8  vf_bitmap[16];
 };
 
+#define HCLGE_ACCEPT_TAG_B 0
+#define HCLGE_ACCEPT_UNTAG_B   1
+#define HCLGE_PORT_INS_TAG1_EN_B   2
+#define HCLGE_PORT_INS_TAG2_EN_B   3
+#define HCLGE_CFG_NIC_ROCE_SEL_B   4
+struct hclge_vport_vtag_tx_cfg_cmd {
+   u8 vport_vlan_cfg;
+   u8 vf_offset;
+   u8 rsv1[2];
+   __le16 def_vlan_tag1;
+   __le16 def_vlan_tag2;
+   u8 vf_bitmap[8];
+   u8 rsv2[8];
+};
+
+#define HCLGE_REM_TAG1_EN_B0
+#define HCLGE_REM_TAG2_EN_B1
+#define HCLGE_SHOW_TAG1_EN_B   2
+#define HCLGE_SHOW_TAG2_EN_B   3
+struct hclge_vport_vtag_rx_cfg_cmd {
+   u8 vport_vlan_cfg;
+   u8 vf_offset;
+   u8 rsv1[6];
+   u8 vf_bitmap[8];
+   u8 rsv2[8];
+};
+
+struct hclge_tx_vlan_type_cfg_cmd {
+   __le16 ot_vlan_type;
+   __le16 in_vlan_type;
+   u8 rsv[20];
+};
+
+struct hclge_rx_vlan_type_cfg_cmd {
+   __le16 ot_fst_vlan_type;
+   __le16 ot_sec_vlan_type;
+   __le16 in_fst_vlan_type;
+   __le16 in_sec_vlan_type;
+   u8 rsv[16];
+};
+
 struct hclge_cfg_com_tqp_queue_cmd {
__le16 tqp_id;
__le16 stream_id;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 80d002f..d0118ed 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4380,23 +4380,169 @@ static int hclge_set_vf_vlan_filter(struct 
hnae3_handle *handle, int vfid,
return hclge_set_vf_vlan_common(hdev, vfid, false, vlan, qos, proto);
 }
 
+static int hclge_set_vlan_tx_offload_cfg(struct hclge_vport *vport)
+{
+   struct hclge_tx_vtag_cfg *vcfg = &vport->txvlan_cfg;
+   struct hclge_vport_vtag_tx_cfg_cmd *req;
+   struct hclge_dev *hdev = vport->back;
+   struct hclge_desc desc;
+   int status;
+
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_VLAN_PORT_TX_CFG, false);
+
+   req = (struct hclge_vport_vtag_tx_cfg_cmd *)desc.data;
+   req->def_vlan_tag1 = cpu_to_le16(vcfg->default_tag1);
+   req->def_vlan_tag2 = cpu_to_le16(vcfg->default_tag2);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_ACCEPT_TAG_B,
+vcfg->accept_tag ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_ACCEPT_UNTAG_B,
+vcfg->accept_untag ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_PORT_INS_TAG1_EN_B,
+vcfg->insert_tag1_en ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_PORT_INS_TAG2_EN_B,
+vcfg->insert_tag2_en ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_CFG_NIC_ROCE_SEL_B, 0);
+
+   req->vf_offset = vport->vport_id / HCLGE_VF_NUM_PER_CMD;
+   req->vf_bitmap[req->vf_offset] =
+   1 << (vport->vport_id % HCLGE_VF_NUM_PER_BYTE);
+
+   status = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (status)
+   dev_err(&hdev->pdev->dev,
+   "Send port txvlan cfg command fail, ret =%d\n",
+   status);
+
+   return status;
+}
+
+static int hclge_set_vlan_rx_offload_cfg(struct hclge_vport *vport)
+{
+   struct hclge_rx_vtag_cfg *vcfg = &vport->rxvlan_cfg;
+   struct hclge_vport_vtag_rx_cfg_cmd *req;
+   struct hclge_dev *hdev = vport->back;
+   struct hclge_desc desc;
+   int status;
+
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_VLAN_PORT_RX_CFG, false);
+
+   req = (struct hclge_vport_vtag_rx_cfg_cmd *)desc.data;
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_REM_TAG1_EN_B,
+vcfg->strip_tag1_en ? 1 : 0);
+   h

[PATCH net-next 02/17] net: hns3: add support to modify tqps number

2017-12-18 Thread Lipeng
This patch add the support to change tqps number for PF driver
by using ehtool -L command.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|   3 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 122 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|   2 +
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c |   1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 111 +++
 5 files changed, 239 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index d887721..a5d3d22 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -388,6 +388,9 @@ struct hnae3_ae_ops {
enum hnae3_reset_type reset);
void (*get_channels)(struct hnae3_handle *handle,
 struct ethtool_channels *ch);
+   void (*get_tqps_and_rss_info)(struct hnae3_handle *h,
+ u16 *free_tqps, u16 *max_rss_size);
+   int (*set_channels)(struct hnae3_handle *handle, u32 new_tqps_num);
 };
 
 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 c2c1323..e52de45 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2651,6 +2651,19 @@ static int hns3_get_ring_config(struct hns3_nic_priv 
*priv)
return ret;
 }
 
+static void hns3_put_ring_config(struct hns3_nic_priv *priv)
+{
+   struct hnae3_handle *h = priv->ae_handle;
+   u16 i;
+
+   for (i = 0; i < h->kinfo.num_tqps; i++) {
+   devm_kfree(priv->dev, priv->ring_data[i].ring);
+   devm_kfree(priv->dev,
+  priv->ring_data[i + h->kinfo.num_tqps].ring);
+   }
+   devm_kfree(priv->dev, priv->ring_data);
+}
+
 static int hns3_alloc_ring_memory(struct hns3_enet_ring *ring)
 {
int ret;
@@ -3162,6 +3175,115 @@ static int hns3_reset_notify(struct hnae3_handle 
*handle,
return ret;
 }
 
+static u16 hns3_get_max_available_channels(struct net_device *netdev)
+{
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+   u16 free_tqps, max_rss_size, max_tqps;
+
+   h->ae_algo->ops->get_tqps_and_rss_info(h, &free_tqps, &max_rss_size);
+   max_tqps = h->kinfo.num_tc * max_rss_size;
+
+   return min_t(u16, max_tqps, (free_tqps + h->kinfo.num_tqps));
+}
+
+static int hns3_modify_tqp_num(struct net_device *netdev, u16 new_tqp_num)
+{
+   struct hns3_nic_priv *priv = netdev_priv(netdev);
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+   int ret;
+
+   ret = h->ae_algo->ops->set_channels(h, new_tqp_num);
+   if (ret)
+   return ret;
+
+   ret = hns3_get_ring_config(priv);
+   if (ret)
+   return ret;
+
+   ret = hns3_nic_init_vector_data(priv);
+   if (ret)
+   goto err_uninit_vector;
+
+   ret = hns3_init_all_ring(priv);
+   if (ret)
+   goto err_put_ring;
+
+   return 0;
+
+err_put_ring:
+   hns3_put_ring_config(priv);
+err_uninit_vector:
+   hns3_nic_uninit_vector_data(priv);
+   return ret;
+}
+
+static int hns3_adjust_tqps_num(u8 num_tc, u32 new_tqp_num)
+{
+   return (new_tqp_num / num_tc) * num_tc;
+}
+
+int hns3_set_channels(struct net_device *netdev,
+ struct ethtool_channels *ch)
+{
+   struct hns3_nic_priv *priv = netdev_priv(netdev);
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+   struct hnae3_knic_private_info *kinfo = &h->kinfo;
+   bool if_running = netif_running(netdev);
+   u32 new_tqp_num = ch->combined_count;
+   u16 org_tqp_num;
+   int ret;
+
+   if (ch->rx_count || ch->tx_count)
+   return -EINVAL;
+
+   if (new_tqp_num > hns3_get_max_available_channels(netdev) ||
+   new_tqp_num < kinfo->num_tc) {
+   dev_err(&netdev->dev,
+   "Change tqps fail, the tqp range is from %d to %d",
+   kinfo->num_tc,
+   hns3_get_max_available_channels(netdev));
+   return -EINVAL;
+   }
+
+   new_tqp_num = hns3_adjust_tqps_num(kinfo->num_tc, new_tqp_num);
+   if (kinfo->num_tqps == new_tqp_num)
+   return 0;
+
+   if (if_running)
+   dev_close(netdev);
+
+   hns3_clear_all_ring(h);
+
+   ret = hns3_nic_uninit_vector_data(priv);
+   if (ret) {
+   dev_err(&netdev->dev,
+   "Unbind vector with tqp fail, nothing is changed");
+   goto open_netdev;
+   }
+
+   hns3_uninit_all_ring(priv);
+
+   org_tqp_num = h->kinfo.

[PATCH V2 net-next 03/17] net: hns3: change the returned tqp number by ethtool -x

2017-12-18 Thread Lipeng
This patch modifies the return data of get_rxnfc, it will return
the current handle's rss_size but not the total tqp number.
because the tc_size has been change to the log2 of roundup
power of two of rss_size.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 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 1b2d79b..2fd2656 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -730,7 +730,7 @@ static int hns3_get_rxnfc(struct net_device *netdev,
 
switch (cmd->cmd) {
case ETHTOOL_GRXRINGS:
-   cmd->data = h->kinfo.num_tc * h->kinfo.rss_size;
+   cmd->data = h->kinfo.rss_size;
break;
case ETHTOOL_GRXFH:
return h->ae_algo->ops->get_rss_tuple(h, cmd);
-- 
1.9.1



[PATCH V2 net-next 00/17] add some features and fix some bugs for HNS3 driver

2017-12-18 Thread Lipeng
This patchset adds some new feature support and fixes some bugs:
[Patch 1/17 - 5/17] add the support to modify/query the tqp number
through ethtool -L/l command, and also fix some related bugs for
change tqp number.
[Patch 6/17 - 9-17] add support vlan tag offload on tx&&rx direction
for pf, and fix some related bugs.
[patch 10/17 - 11/17] fix bugs for auto negotiation.
[patch 12/17] adds support for ethtool command set_pauseparam.
[patch 13/17 - 14/17] add support to update flow control settings after
autoneg.
[patch 15/17 - 17/17] fix some other bugs in net-next.

---
Change Log:
V1 -> V2:
1, fix the comments from Sergei Shtylyov.
---

Fuyun Liang (3):
  net: hns3: cleanup mac auto-negotiation state query
  net: hns3: fix for getting auto-negotiation state in hclge_get_autoneg
  net: hns3: add Asym Pause support to phy default features

Lipeng (13):
  net: hns3: add support to query tqps number
  net: hns3: add support to modify tqps number
  net: hns3: change the returned tqp number by ethtool -x
  net: hns3: Free the ring_data structrue when change tqps
  net: hns3: Add a mask initialization for mac_vlan table
  net: hns3: Add vlan offload config command
  net: hns3: Add ethtool related offload command
  net: hns3: Add handling vlan tag offload in bd
  net: hns3: add support for set_pauseparam
  net: hns3: add support to update flow control settings after autoneg
  net: hns3: add support for querying advertised pause frame by ethtool
ethx
  net: hns3: Increase the default depth of bucket for TM shaper
  net: hns3: change TM sched mode to TC-based mode when SRIOV enabled

qumingguang (1):
  net: hns3: Get rss_size_max from configuration but not hardcode

 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  10 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 225 -
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|   2 +
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c |  41 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  57 +++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 513 +++--
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  38 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c|   5 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  |   6 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |   1 +
 10 files changed, 854 insertions(+), 44 deletions(-)

-- 
1.9.1



[PATCH V2 net-next 02/17] net: hns3: add support to modify tqps number

2017-12-18 Thread Lipeng
This patch add the support to change tqps number for PF driver
by using ehtool -L command.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|   3 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 122 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|   2 +
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c |   1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 111 +++
 5 files changed, 239 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index d887721..a5d3d22 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -388,6 +388,9 @@ struct hnae3_ae_ops {
enum hnae3_reset_type reset);
void (*get_channels)(struct hnae3_handle *handle,
 struct ethtool_channels *ch);
+   void (*get_tqps_and_rss_info)(struct hnae3_handle *h,
+ u16 *free_tqps, u16 *max_rss_size);
+   int (*set_channels)(struct hnae3_handle *handle, u32 new_tqps_num);
 };
 
 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 c2c1323..be43d09 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2651,6 +2651,19 @@ static int hns3_get_ring_config(struct hns3_nic_priv 
*priv)
return ret;
 }
 
+static void hns3_put_ring_config(struct hns3_nic_priv *priv)
+{
+   struct hnae3_handle *h = priv->ae_handle;
+   u16 i;
+
+   for (i = 0; i < h->kinfo.num_tqps; i++) {
+   devm_kfree(priv->dev, priv->ring_data[i].ring);
+   devm_kfree(priv->dev,
+  priv->ring_data[i + h->kinfo.num_tqps].ring);
+   }
+   devm_kfree(priv->dev, priv->ring_data);
+}
+
 static int hns3_alloc_ring_memory(struct hns3_enet_ring *ring)
 {
int ret;
@@ -3162,6 +3175,115 @@ static int hns3_reset_notify(struct hnae3_handle 
*handle,
return ret;
 }
 
+static u16 hns3_get_max_available_channels(struct net_device *netdev)
+{
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+   u16 free_tqps, max_rss_size, max_tqps;
+
+   h->ae_algo->ops->get_tqps_and_rss_info(h, &free_tqps, &max_rss_size);
+   max_tqps = h->kinfo.num_tc * max_rss_size;
+
+   return min_t(u16, max_tqps, (free_tqps + h->kinfo.num_tqps));
+}
+
+static int hns3_modify_tqp_num(struct net_device *netdev, u16 new_tqp_num)
+{
+   struct hns3_nic_priv *priv = netdev_priv(netdev);
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+   int ret;
+
+   ret = h->ae_algo->ops->set_channels(h, new_tqp_num);
+   if (ret)
+   return ret;
+
+   ret = hns3_get_ring_config(priv);
+   if (ret)
+   return ret;
+
+   ret = hns3_nic_init_vector_data(priv);
+   if (ret)
+   goto err_uninit_vector;
+
+   ret = hns3_init_all_ring(priv);
+   if (ret)
+   goto err_put_ring;
+
+   return 0;
+
+err_put_ring:
+   hns3_put_ring_config(priv);
+err_uninit_vector:
+   hns3_nic_uninit_vector_data(priv);
+   return ret;
+}
+
+static int hns3_adjust_tqps_num(u8 num_tc, u32 new_tqp_num)
+{
+   return (new_tqp_num / num_tc) * num_tc;
+}
+
+int hns3_set_channels(struct net_device *netdev,
+ struct ethtool_channels *ch)
+{
+   struct hns3_nic_priv *priv = netdev_priv(netdev);
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+   struct hnae3_knic_private_info *kinfo = &h->kinfo;
+   bool if_running = netif_running(netdev);
+   u32 new_tqp_num = ch->combined_count;
+   u16 org_tqp_num;
+   int ret;
+
+   if (ch->rx_count || ch->tx_count)
+   return -EINVAL;
+
+   if (new_tqp_num > hns3_get_max_available_channels(netdev) ||
+   new_tqp_num < kinfo->num_tc) {
+   dev_err(&netdev->dev,
+   "Change tqps fail, the tqp range is from %d to %d",
+   kinfo->num_tc,
+   hns3_get_max_available_channels(netdev));
+   return -EINVAL;
+   }
+
+   new_tqp_num = hns3_adjust_tqps_num(kinfo->num_tc, new_tqp_num);
+   if (kinfo->num_tqps == new_tqp_num)
+   return 0;
+
+   if (if_running)
+   dev_close(netdev);
+
+   hns3_clear_all_ring(h);
+
+   ret = hns3_nic_uninit_vector_data(priv);
+   if (ret) {
+   dev_err(&netdev->dev,
+   "Unbind vector with tqp fail, nothing is changed");
+   goto open_netdev;
+   }
+
+   hns3_uninit_all_ring(priv);
+
+   org_tqp_num = h->kinfo.

[PATCH V2 net-next 13/17] net: hns3: add support to update flow control settings after autoneg

2017-12-18 Thread Lipeng
When auto-negotiation is enabled, the MAC flow control settings is
based on the flow control negotiation result. And it should be configured
after a valid link has been established. This patch adds support to update
flow control settings after auto-negotiation has completed.

Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 36 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c|  4 +++
 3 files changed, 41 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index fbe5dee..f5465a8 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4707,6 +4707,42 @@ static int hclge_cfg_pauseparam(struct hclge_dev *hdev, 
u32 rx_en, u32 tx_en)
return 0;
 }
 
+int hclge_cfg_flowctrl(struct hclge_dev *hdev)
+{
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+   u16 local_advertising = 0;
+   u16 remote_advertising = 0;
+   u32 rx_pause, tx_pause;
+   u8 flowctl;
+
+   if (!phydev->link || !phydev->autoneg)
+   return 0;
+
+   if (phydev->advertising & ADVERTISED_Pause)
+   local_advertising = ADVERTISE_PAUSE_CAP;
+
+   if (phydev->advertising & ADVERTISED_Asym_Pause)
+   local_advertising |= ADVERTISE_PAUSE_ASYM;
+
+   if (phydev->pause)
+   remote_advertising = LPA_PAUSE_CAP;
+
+   if (phydev->asym_pause)
+   remote_advertising |= LPA_PAUSE_ASYM;
+
+   flowctl = mii_resolve_flowctrl_fdx(local_advertising,
+  remote_advertising);
+   tx_pause = flowctl & FLOW_CTRL_TX;
+   rx_pause = flowctl & FLOW_CTRL_RX;
+
+   if (phydev->duplex == HCLGE_MAC_HALF) {
+   tx_pause = 0;
+   rx_pause = 0;
+   }
+
+   return hclge_cfg_pauseparam(hdev, rx_pause, tx_pause);
+}
+
 static void hclge_get_pauseparam(struct hnae3_handle *handle, u32 *auto_neg,
 u32 *rx_en, u32 *tx_en)
 {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
index cda520c..28cc063 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
@@ -602,4 +602,5 @@ int hclge_set_vf_vlan_common(struct hclge_dev *vport, int 
vfid,
 
 void hclge_mbx_handler(struct hclge_dev *hdev);
 void hclge_reset_tqp(struct hnae3_handle *handle, u16 queue_id);
+int hclge_cfg_flowctrl(struct hclge_dev *hdev);
 #endif
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
index 7069e94..3745153 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -183,6 +183,10 @@ static void hclge_mac_adjust_link(struct net_device 
*netdev)
ret = hclge_cfg_mac_speed_dup(hdev, speed, duplex);
if (ret)
netdev_err(netdev, "failed to adjust link.\n");
+
+   ret = hclge_cfg_flowctrl(hdev);
+   if (ret)
+   netdev_err(netdev, "failed to configure flow control.\n");
 }
 
 int hclge_mac_start_phy(struct hclge_dev *hdev)
-- 
1.9.1



[PATCH V2 net-next 04/17] net: hns3: Free the ring_data structrue when change tqps

2017-12-18 Thread Lipeng
This patch fixes a memory leak problems in change tqps process,
the function hns3_uninit_all_ring and hns3_init_all_ring
may be called many times.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 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 be43d09..b7fe980 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2800,8 +2800,12 @@ int hns3_uninit_all_ring(struct hns3_nic_priv *priv)
h->ae_algo->ops->reset_queue(h, i);
 
hns3_fini_ring(priv->ring_data[i].ring);
+   devm_kfree(priv->dev, priv->ring_data[i].ring);
hns3_fini_ring(priv->ring_data[i + h->kinfo.num_tqps].ring);
+   devm_kfree(priv->dev,
+  priv->ring_data[i + h->kinfo.num_tqps].ring);
}
+   devm_kfree(priv->dev, priv->ring_data);
 
return 0;
 }
-- 
1.9.1



[PATCH V2 net-next 05/17] net: hns3: Get rss_size_max from configuration but not hardcode

2017-12-18 Thread Lipeng
From: qumingguang 

Add configuration for rss_size_max in hdev but not hardcode it.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h  | 2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 6 +-
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index ce5ed88..1eb9ff0 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -399,6 +399,8 @@ struct hclge_pf_res_cmd {
 #define HCLGE_CFG_MAC_ADDR_H_M GENMASK(15, 0)
 #define HCLGE_CFG_DEFAULT_SPEED_S  16
 #define HCLGE_CFG_DEFAULT_SPEED_M  GENMASK(23, 16)
+#define HCLGE_CFG_RSS_SIZE_S   24
+#define HCLGE_CFG_RSS_SIZE_M   GENMASK(31, 24)
 
 struct hclge_cfg_param_cmd {
__le32 offset;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index f354681..b8658b8 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -982,6 +982,10 @@ static void hclge_parse_cfg(struct hclge_cfg *cfg, struct 
hclge_desc *desc)
cfg->default_speed = hnae_get_field(__le32_to_cpu(req->param[3]),
HCLGE_CFG_DEFAULT_SPEED_M,
HCLGE_CFG_DEFAULT_SPEED_S);
+   cfg->rss_size_max = hnae_get_field(__le32_to_cpu(req->param[3]),
+  HCLGE_CFG_RSS_SIZE_M,
+  HCLGE_CFG_RSS_SIZE_S);
+
for (i = 0; i < ETH_ALEN; i++)
cfg->mac_addr[i] = (mac_addr_tmp >> (8 * i)) & 0xff;
 
@@ -1059,7 +1063,7 @@ static int hclge_configure(struct hclge_dev *hdev)
 
hdev->num_vmdq_vport = cfg.vmdq_vport_num;
hdev->base_tqp_pid = 0;
-   hdev->rss_size_max = 1;
+   hdev->rss_size_max = cfg.rss_size_max;
hdev->rx_buf_len = cfg.rx_buf_len;
ether_addr_copy(hdev->hw.mac.mac_addr, cfg.mac_addr);
hdev->hw.mac.media_type = cfg.media_type;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
index fb043b5..4858909 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
@@ -220,6 +220,7 @@ struct hclge_cfg {
u8 tc_num;
u16 tqp_desc_num;
u16 rx_buf_len;
+   u16 rss_size_max;
u8 phy_addr;
u8 media_type;
u8 mac_addr[ETH_ALEN];
-- 
1.9.1



[PATCH V2 net-next 01/17] net: hns3: add support to query tqps number

2017-12-18 Thread Lipeng
This patch adds the support to query tqps number for PF driver
by using ehtool -l command.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h |  2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c  | 10 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 21 +
 3 files changed, 33 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index a9e2b32..d887721 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -386,6 +386,8 @@ struct hnae3_ae_ops {
  u16 vlan, u8 qos, __be16 proto);
void (*reset_event)(struct hnae3_handle *handle,
enum hnae3_reset_type reset);
+   void (*get_channels)(struct hnae3_handle *handle,
+struct ethtool_channels *ch);
 };
 
 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 65a69b4..23af36c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -849,6 +849,15 @@ static int hns3_nway_reset(struct net_device *netdev)
return genphy_restart_aneg(phy);
 }
 
+void hns3_get_channels(struct net_device *netdev,
+  struct ethtool_channels *ch)
+{
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+
+   if (h->ae_algo->ops->get_channels)
+   h->ae_algo->ops->get_channels(h, ch);
+}
+
 static const struct ethtool_ops hns3vf_ethtool_ops = {
.get_drvinfo = hns3_get_drvinfo,
.get_ringparam = hns3_get_ringparam,
@@ -883,6 +892,7 @@ static int hns3_nway_reset(struct net_device *netdev)
.get_link_ksettings = hns3_get_link_ksettings,
.set_link_ksettings = hns3_set_link_ksettings,
.nway_reset = hns3_nway_reset,
+   .get_channels = hns3_get_channels,
 };
 
 void hns3_ethtool_set_ops(struct net_device *netdev)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index e97fd66..533e15e5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -5002,6 +5002,26 @@ static void hclge_uninit_ae_dev(struct hnae3_ae_dev 
*ae_dev)
ae_dev->priv = NULL;
 }
 
+static u32 hclge_get_max_channels(struct hnae3_handle *handle)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+   struct hnae3_knic_private_info *kinfo = &handle->kinfo;
+   struct hclge_dev *hdev = vport->back;
+
+   return min_t(u32, hdev->rss_size_max * kinfo->num_tc, hdev->num_tqps);
+}
+
+static void hclge_get_channels(struct hnae3_handle *handle,
+  struct ethtool_channels *ch)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+
+   ch->max_combined = hclge_get_max_channels(handle);
+   ch->other_count = 1;
+   ch->max_other = 1;
+   ch->combined_count = vport->alloc_tqps;
+}
+
 static const struct hnae3_ae_ops hclge_ops = {
.init_ae_dev = hclge_init_ae_dev,
.uninit_ae_dev = hclge_uninit_ae_dev,
@@ -5046,6 +5066,7 @@ static void hclge_uninit_ae_dev(struct hnae3_ae_dev 
*ae_dev)
.set_vlan_filter = hclge_set_port_vlan_filter,
.set_vf_vlan_filter = hclge_set_vf_vlan_filter,
.reset_event = hclge_reset_event,
+   .get_channels = hclge_get_channels,
 };
 
 static struct hnae3_ae_algo ae_algo = {
-- 
1.9.1



[PATCH V2 net-next 12/17] net: hns3: add support for set_pauseparam

2017-12-18 Thread Lipeng
This patch adds set_pauseparam support for ethtool cmd.

Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 13 
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 83 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  |  2 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |  1 +
 4 files changed, 98 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index 2fd2656..b829ec7 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -559,6 +559,18 @@ static void hns3_get_pauseparam(struct net_device *netdev,
¶m->rx_pause, ¶m->tx_pause);
 }
 
+static int hns3_set_pauseparam(struct net_device *netdev,
+  struct ethtool_pauseparam *param)
+{
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+
+   if (h->ae_algo->ops->set_pauseparam)
+   return h->ae_algo->ops->set_pauseparam(h, param->autoneg,
+  param->rx_pause,
+  param->tx_pause);
+   return -EOPNOTSUPP;
+}
+
 static int hns3_get_link_ksettings(struct net_device *netdev,
   struct ethtool_link_ksettings *cmd)
 {
@@ -880,6 +892,7 @@ void hns3_get_channels(struct net_device *netdev,
.get_ringparam = hns3_get_ringparam,
.set_ringparam = hns3_set_ringparam,
.get_pauseparam = hns3_get_pauseparam,
+   .set_pauseparam = hns3_set_pauseparam,
.get_strings = hns3_get_strings,
.get_ethtool_stats = hns3_get_stats,
.get_sset_count = hns3_get_sset_count,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index b65c74f..fbe5dee 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4660,6 +4660,53 @@ static u32 hclge_get_fw_version(struct hnae3_handle 
*handle)
return hdev->fw_version;
 }
 
+static void hclge_set_flowctrl_adv(struct hclge_dev *hdev, u32 rx_en, u32 
tx_en)
+{
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+
+   if (!phydev)
+   return;
+
+   phydev->advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause);
+
+   if (rx_en)
+   phydev->advertising |= ADVERTISED_Pause | ADVERTISED_Asym_Pause;
+
+   if (tx_en)
+   phydev->advertising ^= ADVERTISED_Asym_Pause;
+}
+
+static int hclge_cfg_pauseparam(struct hclge_dev *hdev, u32 rx_en, u32 tx_en)
+{
+   enum hclge_fc_mode fc_mode;
+   int ret;
+
+   if (rx_en && tx_en)
+   fc_mode = HCLGE_FC_FULL;
+   else if (rx_en && !tx_en)
+   fc_mode = HCLGE_FC_RX_PAUSE;
+   else if (!rx_en && tx_en)
+   fc_mode = HCLGE_FC_TX_PAUSE;
+   else
+   fc_mode = HCLGE_FC_NONE;
+
+   if (hdev->tm_info.fc_mode == HCLGE_FC_PFC) {
+   hdev->fc_mode_last_time = fc_mode;
+   return 0;
+   }
+
+   ret = hclge_mac_pause_en_cfg(hdev, tx_en, rx_en);
+   if (ret) {
+   dev_err(&hdev->pdev->dev, "configure pauseparam error, ret = 
%d.\n",
+   ret);
+   return ret;
+   }
+
+   hdev->tm_info.fc_mode = fc_mode;
+
+   return 0;
+}
+
 static void hclge_get_pauseparam(struct hnae3_handle *handle, u32 *auto_neg,
 u32 *rx_en, u32 *tx_en)
 {
@@ -4689,6 +4736,41 @@ static void hclge_get_pauseparam(struct hnae3_handle 
*handle, u32 *auto_neg,
}
 }
 
+static int hclge_set_pauseparam(struct hnae3_handle *handle, u32 auto_neg,
+   u32 rx_en, u32 tx_en)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+   struct hclge_dev *hdev = vport->back;
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+   u32 fc_autoneg;
+
+   /* Only support flow control negotiation for netdev with
+* phy attached for now.
+*/
+   if (!phydev)
+   return -EOPNOTSUPP;
+
+   fc_autoneg = hclge_get_autoneg(handle);
+   if (auto_neg != fc_autoneg) {
+   dev_info(&hdev->pdev->dev,
+"To change autoneg please use: ethtool -s  
autoneg \n");
+   return -EOPNOTSUPP;
+   }
+
+   if (hdev->tm_info.fc_mode == HCLGE_FC_PFC) {
+   dev_info(&hdev->pdev->dev,
+"Priority flow control enabled. Cannot set link flow 
control.\n");
+   return -EOPNOTSUPP;
+   }
+
+   hclge_set_flowctrl_adv(hdev, rx_en,

[PATCH V2 net-next 07/17] net: hns3: Add vlan offload config command

2017-12-18 Thread Lipeng
This patch adds vlan offload config commands, initializes
the rules of tx/rx vlan tag handle for hw.

Signed-off-by: Shenjian 
Signed-off-by: Lipeng 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  45 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 158 -
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  36 +
 3 files changed, 233 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 10adf86..f5baba21 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -180,6 +180,10 @@ enum hclge_opcode_type {
/* Promisuous mode command */
HCLGE_OPC_CFG_PROMISC_MODE  = 0x0E01,
 
+   /* Vlan offload command */
+   HCLGE_OPC_VLAN_PORT_TX_CFG  = 0x0F01,
+   HCLGE_OPC_VLAN_PORT_RX_CFG  = 0x0F02,
+
/* Interrupts cmd */
HCLGE_OPC_ADD_RING_TO_VECTOR= 0x1503,
HCLGE_OPC_DEL_RING_TO_VECTOR= 0x1504,
@@ -670,6 +674,47 @@ struct hclge_vlan_filter_vf_cfg_cmd {
u8  vf_bitmap[16];
 };
 
+#define HCLGE_ACCEPT_TAG_B 0
+#define HCLGE_ACCEPT_UNTAG_B   1
+#define HCLGE_PORT_INS_TAG1_EN_B   2
+#define HCLGE_PORT_INS_TAG2_EN_B   3
+#define HCLGE_CFG_NIC_ROCE_SEL_B   4
+struct hclge_vport_vtag_tx_cfg_cmd {
+   u8 vport_vlan_cfg;
+   u8 vf_offset;
+   u8 rsv1[2];
+   __le16 def_vlan_tag1;
+   __le16 def_vlan_tag2;
+   u8 vf_bitmap[8];
+   u8 rsv2[8];
+};
+
+#define HCLGE_REM_TAG1_EN_B0
+#define HCLGE_REM_TAG2_EN_B1
+#define HCLGE_SHOW_TAG1_EN_B   2
+#define HCLGE_SHOW_TAG2_EN_B   3
+struct hclge_vport_vtag_rx_cfg_cmd {
+   u8 vport_vlan_cfg;
+   u8 vf_offset;
+   u8 rsv1[6];
+   u8 vf_bitmap[8];
+   u8 rsv2[8];
+};
+
+struct hclge_tx_vlan_type_cfg_cmd {
+   __le16 ot_vlan_type;
+   __le16 in_vlan_type;
+   u8 rsv[20];
+};
+
+struct hclge_rx_vlan_type_cfg_cmd {
+   __le16 ot_fst_vlan_type;
+   __le16 ot_sec_vlan_type;
+   __le16 in_fst_vlan_type;
+   __le16 in_sec_vlan_type;
+   u8 rsv[16];
+};
+
 struct hclge_cfg_com_tqp_queue_cmd {
__le16 tqp_id;
__le16 stream_id;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index d7f6063..d4cdc8d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4380,23 +4380,169 @@ static int hclge_set_vf_vlan_filter(struct 
hnae3_handle *handle, int vfid,
return hclge_set_vf_vlan_common(hdev, vfid, false, vlan, qos, proto);
 }
 
+static int hclge_set_vlan_tx_offload_cfg(struct hclge_vport *vport)
+{
+   struct hclge_tx_vtag_cfg *vcfg = &vport->txvlan_cfg;
+   struct hclge_vport_vtag_tx_cfg_cmd *req;
+   struct hclge_dev *hdev = vport->back;
+   struct hclge_desc desc;
+   int status;
+
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_VLAN_PORT_TX_CFG, false);
+
+   req = (struct hclge_vport_vtag_tx_cfg_cmd *)desc.data;
+   req->def_vlan_tag1 = cpu_to_le16(vcfg->default_tag1);
+   req->def_vlan_tag2 = cpu_to_le16(vcfg->default_tag2);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_ACCEPT_TAG_B,
+vcfg->accept_tag ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_ACCEPT_UNTAG_B,
+vcfg->accept_untag ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_PORT_INS_TAG1_EN_B,
+vcfg->insert_tag1_en ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_PORT_INS_TAG2_EN_B,
+vcfg->insert_tag2_en ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_CFG_NIC_ROCE_SEL_B, 0);
+
+   req->vf_offset = vport->vport_id / HCLGE_VF_NUM_PER_CMD;
+   req->vf_bitmap[req->vf_offset] =
+   1 << (vport->vport_id % HCLGE_VF_NUM_PER_BYTE);
+
+   status = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (status)
+   dev_err(&hdev->pdev->dev,
+   "Send port txvlan cfg command fail, ret =%d\n",
+   status);
+
+   return status;
+}
+
+static int hclge_set_vlan_rx_offload_cfg(struct hclge_vport *vport)
+{
+   struct hclge_rx_vtag_cfg *vcfg = &vport->rxvlan_cfg;
+   struct hclge_vport_vtag_rx_cfg_cmd *req;
+   struct hclge_dev *hdev = vport->back;
+   struct hclge_desc desc;
+   int status;
+
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_VLAN_PORT_RX_CFG, false);
+
+   req = (struct hclge_vport_vtag_rx_cfg_cmd *)desc.data;
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_REM_TAG1_EN_B,
+vcfg->strip_tag1_en ? 1 : 0);
+   h

[PATCH V2 net-next 16/17] net: hns3: Increase the default depth of bucket for TM shaper

2017-12-18 Thread Lipeng
Burstiness of a flow is determined by the depth of a bucket, When the
upper rate of shaper is large, the current depth of a bucket is not
enough.

The default upper rate of shaper is 100G, so increase the depth of
a bucket according to UM.

Signed-off-by: Yunsheng Lin 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
index 7cfe1eb..ea9355d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
@@ -23,8 +23,8 @@ enum hclge_shaper_level {
HCLGE_SHAPER_LVL_PF = 1,
 };
 
-#define HCLGE_SHAPER_BS_U_DEF  1
-#define HCLGE_SHAPER_BS_S_DEF  4
+#define HCLGE_SHAPER_BS_U_DEF  5
+#define HCLGE_SHAPER_BS_S_DEF  20
 
 #define HCLGE_ETHER_MAX_RATE   10
 
-- 
1.9.1



[PATCH V2 net-next 08/17] net: hns3: Add ethtool related offload command

2017-12-18 Thread Lipeng
This patch adds offload command related to "ethtool -K".

Signed-off-by: Shenjian 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h |  3 +++
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 16 
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 13 +
 3 files changed, 32 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index a5d3d22..a67d02a9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -278,6 +278,8 @@ struct hnae3_ae_dev {
  *   Set vlan filter config of Ports
  * set_vf_vlan_filter()
  *   Set vlan filter config of vf
+ * enable_hw_strip_rxvtag()
+ *   Enable/disable hardware strip vlan tag of packets received
  */
 struct hnae3_ae_ops {
int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev);
@@ -384,6 +386,7 @@ struct hnae3_ae_ops {
   u16 vlan_id, bool is_kill);
int (*set_vf_vlan_filter)(struct hnae3_handle *handle, int vfid,
  u16 vlan, u8 qos, __be16 proto);
+   int (*enable_hw_strip_rxvtag)(struct hnae3_handle *handle, bool enable);
void (*reset_event)(struct hnae3_handle *handle,
enum hnae3_reset_type reset);
void (*get_channels)(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 b7fe980..377964a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1032,6 +1032,9 @@ static int hns3_nic_set_features(struct net_device 
*netdev,
 netdev_features_t features)
 {
struct hns3_nic_priv *priv = netdev_priv(netdev);
+   struct hnae3_handle *h = priv->ae_handle;
+   netdev_features_t changed;
+   int ret;
 
if (features & (NETIF_F_TSO | NETIF_F_TSO6)) {
priv->ops.fill_desc = hns3_fill_desc_tso;
@@ -1041,6 +1044,17 @@ static int hns3_nic_set_features(struct net_device 
*netdev,
priv->ops.maybe_stop_tx = hns3_nic_maybe_stop_tx;
}
 
+   changed = netdev->features ^ features;
+   if (changed & NETIF_F_HW_VLAN_CTAG_RX) {
+   if (features & NETIF_F_HW_VLAN_CTAG_RX)
+   ret = h->ae_algo->ops->enable_hw_strip_rxvtag(h, true);
+   else
+   ret = h->ae_algo->ops->enable_hw_strip_rxvtag(h, false);
+
+   if (ret)
+   return ret;
+   }
+
netdev->features = features;
return 0;
 }
@@ -1492,6 +1506,7 @@ static void hns3_set_default_feature(struct net_device 
*netdev)
 
netdev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
NETIF_F_HW_VLAN_CTAG_FILTER |
+   NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_GSO |
NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_GRE |
NETIF_F_GSO_GRE_CSUM | NETIF_F_GSO_UDP_TUNNEL |
@@ -1506,6 +1521,7 @@ static void hns3_set_default_feature(struct net_device 
*netdev)
 
netdev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
NETIF_F_HW_VLAN_CTAG_FILTER |
+   NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_GSO |
NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_GRE |
NETIF_F_GSO_GRE_CSUM | NETIF_F_GSO_UDP_TUNNEL |
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index d4cdc8d..e253f73 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4547,6 +4547,18 @@ static int hclge_init_vlan_config(struct hclge_dev *hdev)
return hclge_set_port_vlan_filter(handle, htons(ETH_P_8021Q), 0, false);
 }
 
+static int hclge_en_hw_strip_rxvtag(struct hnae3_handle *handle, bool enable)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+
+   vport->rxvlan_cfg.strip_tag1_en = false;
+   vport->rxvlan_cfg.strip_tag2_en = enable;
+   vport->rxvlan_cfg.vlan1_vlan_prionly = false;
+   vport->rxvlan_cfg.vlan2_vlan_prionly = false;
+
+   return hclge_set_vlan_rx_offload_cfg(vport);
+}
+
 static int hclge_set_mtu(struct hnae3_handle *handle, int new_mtu)
 {
struct hclge_vport *vport = hclge_get_vport(handle);
@@ -5361,6 +5373,7 @@ static int hclge_set_channels(struct hnae3_handle 
*handle, u32 new_tqps_num)
.get_mdix_mode = hclge_get_mdix_mode,
.set_vlan_filter = hclge_set_port_vlan_filter,
.set_vf_vlan_filter = hclge_set_vf_vlan_filter,
+  

[PATCH V2 net-next 09/17] net: hns3: Add handling vlan tag offload in bd

2017-12-18 Thread Lipeng
This patch deals with the vlan tag information between
sk_buff and rx/tx bd.

Signed-off-by: Shenjian 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 83 +++--
 1 file changed, 78 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 377964a..212d0dc 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -723,6 +723,58 @@ static void hns3_set_txbd_baseinfo(u16 
*bdtp_fe_sc_vld_ra_ri, int frag_end)
hnae_set_field(*bdtp_fe_sc_vld_ra_ri, HNS3_TXD_SC_M, HNS3_TXD_SC_S, 0);
 }
 
+static int hns3_fill_desc_vtags(struct sk_buff *skb,
+   struct hns3_enet_ring *tx_ring,
+   u32 *inner_vlan_flag,
+   u32 *out_vlan_flag,
+   u16 *inner_vtag,
+   u16 *out_vtag)
+{
+#define HNS3_TX_VLAN_PRIO_SHIFT 13
+
+   if (skb->protocol == htons(ETH_P_8021Q) &&
+   !(tx_ring->tqp->handle->kinfo.netdev->features &
+   NETIF_F_HW_VLAN_CTAG_TX)) {
+   /* When HW VLAN acceleration is turned off, and the stack
+* sets the protocol to 802.1q, the driver just need to
+* set the protocol to the encapsulated ethertype.
+*/
+   skb->protocol = vlan_get_protocol(skb);
+   return 0;
+   }
+
+   if (skb_vlan_tag_present(skb)) {
+   u16 vlan_tag;
+
+   vlan_tag = skb_vlan_tag_get(skb);
+   vlan_tag |= (skb->priority & 0x7) << HNS3_TX_VLAN_PRIO_SHIFT;
+
+   /* Based on hw strategy, use out_vtag in two layer tag case,
+* and use inner_vtag in one tag case.
+*/
+   if (skb->protocol == htons(ETH_P_8021Q)) {
+   hnae_set_bit(*out_vlan_flag, HNS3_TXD_OVLAN_B, 1);
+   *out_vtag = vlan_tag;
+   } else {
+   hnae_set_bit(*inner_vlan_flag, HNS3_TXD_VLAN_B, 1);
+   *inner_vtag = vlan_tag;
+   }
+   } else if (skb->protocol == htons(ETH_P_8021Q)) {
+   struct vlan_ethhdr *vhdr;
+   int rc;
+
+   rc = skb_cow_head(skb, 0);
+   if (rc < 0)
+   return rc;
+   vhdr = (struct vlan_ethhdr *)skb->data;
+   vhdr->h_vlan_TCI |= cpu_to_be16((skb->priority & 0x7)
+   << HNS3_TX_VLAN_PRIO_SHIFT);
+   }
+
+   skb->protocol = vlan_get_protocol(skb);
+   return 0;
+}
+
 static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
  int size, dma_addr_t dma, int frag_end,
  enum hns_desc_type type)
@@ -733,6 +785,8 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void 
*priv,
u16 bdtp_fe_sc_vld_ra_ri = 0;
u32 type_cs_vlan_tso = 0;
struct sk_buff *skb;
+   u16 inner_vtag = 0;
+   u16 out_vtag = 0;
u32 paylen = 0;
u16 mss = 0;
__be16 protocol;
@@ -756,15 +810,16 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, 
void *priv,
skb = (struct sk_buff *)priv;
paylen = skb->len;
 
+   ret = hns3_fill_desc_vtags(skb, ring, &type_cs_vlan_tso,
+  &ol_type_vlan_len_msec,
+  &inner_vtag, &out_vtag);
+   if (unlikely(ret))
+   return ret;
+
if (skb->ip_summed == CHECKSUM_PARTIAL) {
skb_reset_mac_len(skb);
protocol = skb->protocol;
 
-   /* vlan packet*/
-   if (protocol == htons(ETH_P_8021Q)) {
-   protocol = vlan_get_protocol(skb);
-   skb->protocol = protocol;
-   }
ret = hns3_get_l4_protocol(skb, &ol4_proto, &il4_proto);
if (ret)
return ret;
@@ -790,6 +845,8 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void 
*priv,
cpu_to_le32(type_cs_vlan_tso);
desc->tx.paylen = cpu_to_le32(paylen);
desc->tx.mss = cpu_to_le16(mss);
+   desc->tx.vlan_tag = cpu_to_le16(inner_vtag);
+   desc->tx.outer_vlan_tag = cpu_to_le16(out_vtag);
}
 
/* move ring pointer to next.*/
@@ -2101,6 +2158,22 @@ static int hns3_handle_rx_bd(struct hns3_enet_ring *ring,
 
prefetchw(skb->data);
 
+   /* Based on hw strategy, the tag offl

[PATCH V2 net-next 15/17] net: hns3: add support for querying advertised pause frame by ethtool ethx

2017-12-18 Thread Lipeng
This patch adds support for querying advertised pause frame by using
ethtool command(ethtool ethx).

Fixes: 496d03e960ae ("net: hns3: Add Ethtool support to HNS3 driver")
Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h |  2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c  | 15 +++
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 15 +++
 3 files changed, 32 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index a67d02a9..82e9a80 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -394,6 +394,8 @@ struct hnae3_ae_ops {
void (*get_tqps_and_rss_info)(struct hnae3_handle *h,
  u16 *free_tqps, u16 *max_rss_size);
int (*set_channels)(struct hnae3_handle *handle, u32 new_tqps_num);
+   void (*get_flowctrl_adv)(struct hnae3_handle *handle,
+u32 *flowctrl_adv);
 };
 
 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 b829ec7..2ae4d39 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -575,6 +575,7 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
   struct ethtool_link_ksettings *cmd)
 {
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;
@@ -650,6 +651,8 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
if (!cmd->base.autoneg)
advertised_caps &= ~HNS3_LM_AUTONEG_BIT;
 
+   advertised_caps &= ~HNS3_LM_PAUSE_BIT;
+
/* now, map driver link modes to ethtool link modes */
hns3_driv_to_eth_caps(supported_caps, cmd, false);
hns3_driv_to_eth_caps(advertised_caps, cmd, true);
@@ -662,6 +665,18 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
/* 4.mdio_support */
cmd->base.mdio_support = ETH_MDIO_SUPPORTS_C22;
 
+   /* 5.get flow control setttings */
+   if (h->ae_algo->ops->get_flowctrl_adv)
+   h->ae_algo->ops->get_flowctrl_adv(h, &flowctrl_adv);
+
+   if (flowctrl_adv & ADVERTISED_Pause)
+   ethtool_link_ksettings_add_link_mode(cmd, advertising,
+Pause);
+
+   if (flowctrl_adv & ADVERTISED_Asym_Pause)
+   ethtool_link_ksettings_add_link_mode(cmd, advertising,
+Asym_Pause);
+
return 0;
 }
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index f5465a8..ff63bca 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4660,6 +4660,20 @@ static u32 hclge_get_fw_version(struct hnae3_handle 
*handle)
return hdev->fw_version;
 }
 
+static void hclge_get_flowctrl_adv(struct hnae3_handle *handle,
+  u32 *flowctrl_adv)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+   struct hclge_dev *hdev = vport->back;
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+
+   if (!phydev)
+   return;
+
+   *flowctrl_adv |= (phydev->advertising & ADVERTISED_Pause) |
+(phydev->advertising & ADVERTISED_Asym_Pause);
+}
+
 static void hclge_set_flowctrl_adv(struct hclge_dev *hdev, u32 rx_en, u32 
tx_en)
 {
struct phy_device *phydev = hdev->hw.mac.phydev;
@@ -5477,6 +5491,7 @@ static int hclge_set_channels(struct hnae3_handle 
*handle, u32 new_tqps_num)
.get_tqps_and_rss_info = hclge_get_tqps_and_rss_info,
.set_channels = hclge_set_channels,
.get_channels = hclge_get_channels,
+   .get_flowctrl_adv = hclge_get_flowctrl_adv,
 };
 
 static struct hnae3_ae_algo ae_algo = {
-- 
1.9.1



[PATCH V2 net-next 17/17] net: hns3: change TM sched mode to TC-based mode when SRIOV enabled

2017-12-18 Thread Lipeng
TC-based sched mode supports SRIOV enabled and SRIOV disabled. This
patch change the TM sched mode to TC-based mode in initialization
process.

Fixes: cc9bb43ab394 ("net: hns3: Add tc-based TM support for sriov enabled 
port")
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index ff63bca..01bc744 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -1100,10 +1100,7 @@ static int hclge_configure(struct hclge_dev *hdev)
for (i = 0; i < hdev->tm_info.num_tc; i++)
hnae_set_bit(hdev->hw_tc_map, i, 1);
 
-   if (!hdev->num_vmdq_vport && !hdev->num_req_vfs)
-   hdev->tx_sch_mode = HCLGE_FLAG_TC_BASE_SCH_MODE;
-   else
-   hdev->tx_sch_mode = HCLGE_FLAG_VNET_BASE_SCH_MODE;
+   hdev->tx_sch_mode = HCLGE_FLAG_TC_BASE_SCH_MODE;
 
return ret;
 }
-- 
1.9.1



[PATCH V2 net-next 11/17] net: hns3: fix for getting auto-negotiation state in hclge_get_autoneg

2017-12-18 Thread Lipeng
From: Fuyun Liang 

When phy exists, we use the value of phydev.autoneg to represent the
auto-negotiation state of hardware. Otherwise, we use the value of
mac.autoneg to represent it.

This patch fixes for getting a error value of auto-negotiation state in
hclge_get_autoneg().

Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support")
Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 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 9ccfe86..b65c74f 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2172,6 +2172,10 @@ static int hclge_get_autoneg(struct hnae3_handle *handle)
 {
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+
+   if (phydev)
+   return phydev->autoneg;
 
return hdev->hw.mac.autoneg;
 }
-- 
1.9.1



[PATCH V2 net-next 06/17] net: hns3: Add a mask initialization for mac_vlan table

2017-12-18 Thread Lipeng
This patch sets vlan masked, in order to avoid the received
packets being filtered.

Signed-off-by: Shenjian 
Signed-off-by: Lipeng 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h | 10 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 39 +-
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 1eb9ff0..10adf86 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -191,6 +191,7 @@ enum hclge_opcode_type {
HCLGE_OPC_MAC_VLAN_INSERT   = 0x1003,
HCLGE_OPC_MAC_ETHTYPE_ADD   = 0x1010,
HCLGE_OPC_MAC_ETHTYPE_REMOVE= 0x1011,
+   HCLGE_OPC_MAC_VLAN_MASK_SET = 0x1012,
 
/* Multicast linear table cmd */
HCLGE_OPC_MTA_MAC_MODE_CFG  = 0x1020,
@@ -589,6 +590,15 @@ struct hclge_mac_vlan_tbl_entry_cmd {
u8  rsv2[6];
 };
 
+#define HCLGE_VLAN_MASK_EN_B   0x0
+struct hclge_mac_vlan_mask_entry_cmd {
+   u8 rsv0[2];
+   u8 vlan_mask;
+   u8 rsv1;
+   u8 mac_mask[6];
+   u8 rsv2[14];
+};
+
 #define HCLGE_CFG_MTA_MAC_SEL_S0x0
 #define HCLGE_CFG_MTA_MAC_SEL_MGENMASK(1, 0)
 #define HCLGE_CFG_MTA_MAC_EN_B 0x7
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index b8658b8..d7f6063 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2200,9 +2200,34 @@ static int hclge_get_autoneg(struct hnae3_handle *handle)
return hdev->hw.mac.autoneg;
 }
 
+static int hclge_set_default_mac_vlan_mask(struct hclge_dev *hdev,
+  bool mask_vlan,
+  u8 *mac_mask)
+{
+   struct hclge_mac_vlan_mask_entry_cmd *req;
+   struct hclge_desc desc;
+   int status;
+
+   req = (struct hclge_mac_vlan_mask_entry_cmd *)desc.data;
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_MAC_VLAN_MASK_SET, false);
+
+   hnae_set_bit(req->vlan_mask, HCLGE_VLAN_MASK_EN_B,
+mask_vlan ? 1 : 0);
+   ether_addr_copy(req->mac_mask, mac_mask);
+
+   status = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (status)
+   dev_err(&hdev->pdev->dev,
+   "Config mac_vlan_mask failed for cmd_send, ret =%d\n",
+   status);
+
+   return status;
+}
+
 static int hclge_mac_init(struct hclge_dev *hdev)
 {
struct hclge_mac *mac = &hdev->hw.mac;
+   u8 mac_mask[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
int ret;
 
ret = hclge_cfg_mac_speed_dup(hdev, hdev->hw.mac.speed, HCLGE_MAC_FULL);
@@ -2228,7 +2253,19 @@ static int hclge_mac_init(struct hclge_dev *hdev)
return ret;
}
 
-   return hclge_cfg_func_mta_filter(hdev, 0, hdev->accept_mta_mc);
+   ret = hclge_cfg_func_mta_filter(hdev, 0, hdev->accept_mta_mc);
+   if (ret) {
+   dev_err(&hdev->pdev->dev,
+   "set mta filter mode fail ret=%d\n", ret);
+   return ret;
+   }
+
+   ret = hclge_set_default_mac_vlan_mask(hdev, true, mac_mask);
+   if (ret)
+   dev_err(&hdev->pdev->dev,
+   "set default mac_vlan_mask fail ret=%d\n", ret);
+
+   return ret;
 }
 
 static void hclge_mbx_task_schedule(struct hclge_dev *hdev)
-- 
1.9.1



[PATCH V2 net-next 10/17] net: hns3: cleanup mac auto-negotiation state query

2017-12-18 Thread Lipeng
From: Fuyun Liang 

When checking whether auto-negotiation is on, driver only needs to
check the value of mac.autoneg(SW) directly, and does not need to
query it from hardware. Because this value is always synchronized
with the auto-negotiation state of hardware.

This patch removes the mac auto-negotiation state query.

Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 24 --
 1 file changed, 24 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index e253f73..9ccfe86 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2137,28 +2137,6 @@ static int hclge_query_mac_an_speed_dup(struct hclge_dev 
*hdev, int *speed,
return 0;
 }
 
-static int hclge_query_autoneg_result(struct hclge_dev *hdev)
-{
-   struct hclge_mac *mac = &hdev->hw.mac;
-   struct hclge_query_an_speed_dup_cmd *req;
-   struct hclge_desc desc;
-   int ret;
-
-   req = (struct hclge_query_an_speed_dup_cmd *)desc.data;
-
-   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_AN_RESULT, true);
-   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
-   if (ret) {
-   dev_err(&hdev->pdev->dev,
-   "autoneg result query cmd failed %d.\n", ret);
-   return ret;
-   }
-
-   mac->autoneg = hnae_get_bit(req->an_syn_dup_speed, HCLGE_QUERY_AN_B);
-
-   return 0;
-}
-
 static int hclge_set_autoneg_en(struct hclge_dev *hdev, bool enable)
 {
struct hclge_config_auto_neg_cmd *req;
@@ -2195,8 +2173,6 @@ static int hclge_get_autoneg(struct hnae3_handle *handle)
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
 
-   hclge_query_autoneg_result(hdev);
-
return hdev->hw.mac.autoneg;
 }
 
-- 
1.9.1



[PATCH V2 net-next 14/17] net: hns3: add Asym Pause support to phy default features

2017-12-18 Thread Lipeng
From: Fuyun Liang 

commit c4fb2cdf575d ("net: hns3: fix a bug for phy supported feature
initialization") adds default supported features for phy, but our hardware
also supports Asym Pause. This patch adds Asym Pause support to phy
default features to prevent Asym Pause can not be advertised when the phy
negotiates flow control.

Fixes: c4fb2cdf575d ("net: hns3: fix a bug for phy supported feature 
initialization")
Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
index 3745153..c1dea3a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -17,6 +17,7 @@
 #define HCLGE_PHY_SUPPORTED_FEATURES   (SUPPORTED_Autoneg | \
 SUPPORTED_TP | \
 SUPPORTED_Pause | \
+SUPPORTED_Asym_Pause | \
 PHY_10BT_FEATURES | \
 PHY_100BT_FEATURES | \
 PHY_1000BT_FEATURES)
-- 
1.9.1



[PATCH V3 net-next 03/17] net: hns3: change the returned tqp number by ethtool -x

2017-12-20 Thread Lipeng
This patch modifies the return data of get_rxnfc, it will return
the current handle's rss_size but not the total tqp number.
because the tc_size has been change to the log2 of roundup
power of two of rss_size.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 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 1b2d79b..2fd2656 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -730,7 +730,7 @@ static int hns3_get_rxnfc(struct net_device *netdev,
 
switch (cmd->cmd) {
case ETHTOOL_GRXRINGS:
-   cmd->data = h->kinfo.num_tc * h->kinfo.rss_size;
+   cmd->data = h->kinfo.rss_size;
break;
case ETHTOOL_GRXFH:
return h->ae_algo->ops->get_rss_tuple(h, cmd);
-- 
1.9.1



[PATCH V3 net-next 01/17] net: hns3: add support to query tqps number

2017-12-20 Thread Lipeng
This patch adds the support to query tqps number for PF driver
by using ehtool -l command.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h |  2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c  | 10 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 21 +
 3 files changed, 33 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index a9e2b32..d887721 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -386,6 +386,8 @@ struct hnae3_ae_ops {
  u16 vlan, u8 qos, __be16 proto);
void (*reset_event)(struct hnae3_handle *handle,
enum hnae3_reset_type reset);
+   void (*get_channels)(struct hnae3_handle *handle,
+struct ethtool_channels *ch);
 };
 
 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 65a69b4..23af36c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -849,6 +849,15 @@ static int hns3_nway_reset(struct net_device *netdev)
return genphy_restart_aneg(phy);
 }
 
+void hns3_get_channels(struct net_device *netdev,
+  struct ethtool_channels *ch)
+{
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+
+   if (h->ae_algo->ops->get_channels)
+   h->ae_algo->ops->get_channels(h, ch);
+}
+
 static const struct ethtool_ops hns3vf_ethtool_ops = {
.get_drvinfo = hns3_get_drvinfo,
.get_ringparam = hns3_get_ringparam,
@@ -883,6 +892,7 @@ static int hns3_nway_reset(struct net_device *netdev)
.get_link_ksettings = hns3_get_link_ksettings,
.set_link_ksettings = hns3_set_link_ksettings,
.nway_reset = hns3_nway_reset,
+   .get_channels = hns3_get_channels,
 };
 
 void hns3_ethtool_set_ops(struct net_device *netdev)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index e97fd66..a3101bc 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -5002,6 +5002,26 @@ static void hclge_uninit_ae_dev(struct hnae3_ae_dev 
*ae_dev)
ae_dev->priv = NULL;
 }
 
+static u32 hclge_get_max_channels(struct hnae3_handle *handle)
+{
+   struct hnae3_knic_private_info *kinfo = &handle->kinfo;
+   struct hclge_vport *vport = hclge_get_vport(handle);
+   struct hclge_dev *hdev = vport->back;
+
+   return min_t(u32, hdev->rss_size_max * kinfo->num_tc, hdev->num_tqps);
+}
+
+static void hclge_get_channels(struct hnae3_handle *handle,
+  struct ethtool_channels *ch)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+
+   ch->max_combined = hclge_get_max_channels(handle);
+   ch->other_count = 1;
+   ch->max_other = 1;
+   ch->combined_count = vport->alloc_tqps;
+}
+
 static const struct hnae3_ae_ops hclge_ops = {
.init_ae_dev = hclge_init_ae_dev,
.uninit_ae_dev = hclge_uninit_ae_dev,
@@ -5046,6 +5066,7 @@ static void hclge_uninit_ae_dev(struct hnae3_ae_dev 
*ae_dev)
.set_vlan_filter = hclge_set_port_vlan_filter,
.set_vf_vlan_filter = hclge_set_vf_vlan_filter,
.reset_event = hclge_reset_event,
+   .get_channels = hclge_get_channels,
 };
 
 static struct hnae3_ae_algo ae_algo = {
-- 
1.9.1



[PATCH V3 net-next 00/17] add some features and fix some bugs for HNS3 driver

2017-12-20 Thread Lipeng
This patchset adds some new feature support and fixes some bugs:
[Patch 1/17 - 5/17] add the support to modify/query the tqp number
through ethtool -L/l command, and also fix some related bugs for
change tqp number.
[Patch 6/17 - 9-17] add support vlan tag offload on tx&&rx direction
for pf, and fix some related bugs.
[patch 10/17 - 11/17] fix bugs for auto negotiation.
[patch 12/17] adds support for ethtool command set_pauseparam.
[patch 13/17 - 14/17] add support to update flow control settings after
autoneg.
[patch 15/17 - 17/17] fix some other bugs in net-next.

---
Change Log:
V2 -> V3:
1, order local variables requested by David Miller.
2, use "int" for index iteration loops requested by David Miller.

V1 -> V2:
1, fix the comments from Sergei Shtylyov.
---

Fuyun Liang (3):
  net: hns3: cleanup mac auto-negotiation state query
  net: hns3: fix for getting auto-negotiation state in hclge_get_autoneg
  net: hns3: add Asym Pause support to phy default features

Lipeng (13):
  net: hns3: add support to query tqps number
  net: hns3: add support to modify tqps number
  net: hns3: change the returned tqp number by ethtool -x
  net: hns3: Free the ring_data structrue when change tqps
  net: hns3: Add a mask initialization for mac_vlan table
  net: hns3: Add vlan offload config command
  net: hns3: Add ethtool related offload command
  net: hns3: Add handling vlan tag offload in bd
  net: hns3: add support for set_pauseparam
  net: hns3: add support to update flow control settings after autoneg
  net: hns3: add support for querying advertised pause frame by ethtool
ethx
  net: hns3: Increase the default depth of bucket for TM shaper
  net: hns3: change TM sched mode to TC-based mode when SRIOV enabled

qumingguang (1):
  net: hns3: Get rss_size_max from configuration but not hardcode

 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  10 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 225 -
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|   2 +
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c |  41 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  57 +++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 514 +++--
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  38 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c|   5 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  |   6 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |   1 +
 10 files changed, 855 insertions(+), 44 deletions(-)

-- 
1.9.1



[PATCH V3 net-next 07/17] net: hns3: Add vlan offload config command

2017-12-20 Thread Lipeng
This patch adds vlan offload config commands, initializes
the rules of tx/rx vlan tag handle for hw.

Signed-off-by: Shenjian 
Signed-off-by: Lipeng 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  45 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 158 -
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  36 +
 3 files changed, 233 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 10adf86..f5baba21 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -180,6 +180,10 @@ enum hclge_opcode_type {
/* Promisuous mode command */
HCLGE_OPC_CFG_PROMISC_MODE  = 0x0E01,
 
+   /* Vlan offload command */
+   HCLGE_OPC_VLAN_PORT_TX_CFG  = 0x0F01,
+   HCLGE_OPC_VLAN_PORT_RX_CFG  = 0x0F02,
+
/* Interrupts cmd */
HCLGE_OPC_ADD_RING_TO_VECTOR= 0x1503,
HCLGE_OPC_DEL_RING_TO_VECTOR= 0x1504,
@@ -670,6 +674,47 @@ struct hclge_vlan_filter_vf_cfg_cmd {
u8  vf_bitmap[16];
 };
 
+#define HCLGE_ACCEPT_TAG_B 0
+#define HCLGE_ACCEPT_UNTAG_B   1
+#define HCLGE_PORT_INS_TAG1_EN_B   2
+#define HCLGE_PORT_INS_TAG2_EN_B   3
+#define HCLGE_CFG_NIC_ROCE_SEL_B   4
+struct hclge_vport_vtag_tx_cfg_cmd {
+   u8 vport_vlan_cfg;
+   u8 vf_offset;
+   u8 rsv1[2];
+   __le16 def_vlan_tag1;
+   __le16 def_vlan_tag2;
+   u8 vf_bitmap[8];
+   u8 rsv2[8];
+};
+
+#define HCLGE_REM_TAG1_EN_B0
+#define HCLGE_REM_TAG2_EN_B1
+#define HCLGE_SHOW_TAG1_EN_B   2
+#define HCLGE_SHOW_TAG2_EN_B   3
+struct hclge_vport_vtag_rx_cfg_cmd {
+   u8 vport_vlan_cfg;
+   u8 vf_offset;
+   u8 rsv1[6];
+   u8 vf_bitmap[8];
+   u8 rsv2[8];
+};
+
+struct hclge_tx_vlan_type_cfg_cmd {
+   __le16 ot_vlan_type;
+   __le16 in_vlan_type;
+   u8 rsv[20];
+};
+
+struct hclge_rx_vlan_type_cfg_cmd {
+   __le16 ot_fst_vlan_type;
+   __le16 ot_sec_vlan_type;
+   __le16 in_fst_vlan_type;
+   __le16 in_sec_vlan_type;
+   u8 rsv[16];
+};
+
 struct hclge_cfg_com_tqp_queue_cmd {
__le16 tqp_id;
__le16 stream_id;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index a1d9398..113b859 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4380,23 +4380,169 @@ static int hclge_set_vf_vlan_filter(struct 
hnae3_handle *handle, int vfid,
return hclge_set_vf_vlan_common(hdev, vfid, false, vlan, qos, proto);
 }
 
+static int hclge_set_vlan_tx_offload_cfg(struct hclge_vport *vport)
+{
+   struct hclge_tx_vtag_cfg *vcfg = &vport->txvlan_cfg;
+   struct hclge_vport_vtag_tx_cfg_cmd *req;
+   struct hclge_dev *hdev = vport->back;
+   struct hclge_desc desc;
+   int status;
+
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_VLAN_PORT_TX_CFG, false);
+
+   req = (struct hclge_vport_vtag_tx_cfg_cmd *)desc.data;
+   req->def_vlan_tag1 = cpu_to_le16(vcfg->default_tag1);
+   req->def_vlan_tag2 = cpu_to_le16(vcfg->default_tag2);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_ACCEPT_TAG_B,
+vcfg->accept_tag ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_ACCEPT_UNTAG_B,
+vcfg->accept_untag ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_PORT_INS_TAG1_EN_B,
+vcfg->insert_tag1_en ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_PORT_INS_TAG2_EN_B,
+vcfg->insert_tag2_en ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_CFG_NIC_ROCE_SEL_B, 0);
+
+   req->vf_offset = vport->vport_id / HCLGE_VF_NUM_PER_CMD;
+   req->vf_bitmap[req->vf_offset] =
+   1 << (vport->vport_id % HCLGE_VF_NUM_PER_BYTE);
+
+   status = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (status)
+   dev_err(&hdev->pdev->dev,
+   "Send port txvlan cfg command fail, ret =%d\n",
+   status);
+
+   return status;
+}
+
+static int hclge_set_vlan_rx_offload_cfg(struct hclge_vport *vport)
+{
+   struct hclge_rx_vtag_cfg *vcfg = &vport->rxvlan_cfg;
+   struct hclge_vport_vtag_rx_cfg_cmd *req;
+   struct hclge_dev *hdev = vport->back;
+   struct hclge_desc desc;
+   int status;
+
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_VLAN_PORT_RX_CFG, false);
+
+   req = (struct hclge_vport_vtag_rx_cfg_cmd *)desc.data;
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_REM_TAG1_EN_B,
+vcfg->strip_tag1_en ? 1 : 0);
+   h

[PATCH V3 net-next 12/17] net: hns3: add support for set_pauseparam

2017-12-20 Thread Lipeng
This patch adds set_pauseparam support for ethtool cmd.

Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 13 
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 83 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  |  2 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |  1 +
 4 files changed, 98 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index 2fd2656..b829ec7 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -559,6 +559,18 @@ static void hns3_get_pauseparam(struct net_device *netdev,
¶m->rx_pause, ¶m->tx_pause);
 }
 
+static int hns3_set_pauseparam(struct net_device *netdev,
+  struct ethtool_pauseparam *param)
+{
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+
+   if (h->ae_algo->ops->set_pauseparam)
+   return h->ae_algo->ops->set_pauseparam(h, param->autoneg,
+  param->rx_pause,
+  param->tx_pause);
+   return -EOPNOTSUPP;
+}
+
 static int hns3_get_link_ksettings(struct net_device *netdev,
   struct ethtool_link_ksettings *cmd)
 {
@@ -880,6 +892,7 @@ void hns3_get_channels(struct net_device *netdev,
.get_ringparam = hns3_get_ringparam,
.set_ringparam = hns3_set_ringparam,
.get_pauseparam = hns3_get_pauseparam,
+   .set_pauseparam = hns3_set_pauseparam,
.get_strings = hns3_get_strings,
.get_ethtool_stats = hns3_get_stats,
.get_sset_count = hns3_get_sset_count,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 14e1054..0f55ee6 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4660,6 +4660,53 @@ static u32 hclge_get_fw_version(struct hnae3_handle 
*handle)
return hdev->fw_version;
 }
 
+static void hclge_set_flowctrl_adv(struct hclge_dev *hdev, u32 rx_en, u32 
tx_en)
+{
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+
+   if (!phydev)
+   return;
+
+   phydev->advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause);
+
+   if (rx_en)
+   phydev->advertising |= ADVERTISED_Pause | ADVERTISED_Asym_Pause;
+
+   if (tx_en)
+   phydev->advertising ^= ADVERTISED_Asym_Pause;
+}
+
+static int hclge_cfg_pauseparam(struct hclge_dev *hdev, u32 rx_en, u32 tx_en)
+{
+   enum hclge_fc_mode fc_mode;
+   int ret;
+
+   if (rx_en && tx_en)
+   fc_mode = HCLGE_FC_FULL;
+   else if (rx_en && !tx_en)
+   fc_mode = HCLGE_FC_RX_PAUSE;
+   else if (!rx_en && tx_en)
+   fc_mode = HCLGE_FC_TX_PAUSE;
+   else
+   fc_mode = HCLGE_FC_NONE;
+
+   if (hdev->tm_info.fc_mode == HCLGE_FC_PFC) {
+   hdev->fc_mode_last_time = fc_mode;
+   return 0;
+   }
+
+   ret = hclge_mac_pause_en_cfg(hdev, tx_en, rx_en);
+   if (ret) {
+   dev_err(&hdev->pdev->dev, "configure pauseparam error, ret = 
%d.\n",
+   ret);
+   return ret;
+   }
+
+   hdev->tm_info.fc_mode = fc_mode;
+
+   return 0;
+}
+
 static void hclge_get_pauseparam(struct hnae3_handle *handle, u32 *auto_neg,
 u32 *rx_en, u32 *tx_en)
 {
@@ -4689,6 +4736,41 @@ static void hclge_get_pauseparam(struct hnae3_handle 
*handle, u32 *auto_neg,
}
 }
 
+static int hclge_set_pauseparam(struct hnae3_handle *handle, u32 auto_neg,
+   u32 rx_en, u32 tx_en)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+   struct hclge_dev *hdev = vport->back;
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+   u32 fc_autoneg;
+
+   /* Only support flow control negotiation for netdev with
+* phy attached for now.
+*/
+   if (!phydev)
+   return -EOPNOTSUPP;
+
+   fc_autoneg = hclge_get_autoneg(handle);
+   if (auto_neg != fc_autoneg) {
+   dev_info(&hdev->pdev->dev,
+"To change autoneg please use: ethtool -s  
autoneg \n");
+   return -EOPNOTSUPP;
+   }
+
+   if (hdev->tm_info.fc_mode == HCLGE_FC_PFC) {
+   dev_info(&hdev->pdev->dev,
+"Priority flow control enabled. Cannot set link flow 
control.\n");
+   return -EOPNOTSUPP;
+   }
+
+   hclge_set_flowctrl_adv(hdev, rx_en,

[PATCH V3 net-next 16/17] net: hns3: Increase the default depth of bucket for TM shaper

2017-12-20 Thread Lipeng
Burstiness of a flow is determined by the depth of a bucket, When the
upper rate of shaper is large, the current depth of a bucket is not
enough.

The default upper rate of shaper is 100G, so increase the depth of
a bucket according to UM.

Signed-off-by: Yunsheng Lin 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
index 7cfe1eb..ea9355d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
@@ -23,8 +23,8 @@ enum hclge_shaper_level {
HCLGE_SHAPER_LVL_PF = 1,
 };
 
-#define HCLGE_SHAPER_BS_U_DEF  1
-#define HCLGE_SHAPER_BS_S_DEF  4
+#define HCLGE_SHAPER_BS_U_DEF  5
+#define HCLGE_SHAPER_BS_S_DEF  20
 
 #define HCLGE_ETHER_MAX_RATE   10
 
-- 
1.9.1



[PATCH V3 net-next 02/17] net: hns3: add support to modify tqps number

2017-12-20 Thread Lipeng
This patch adds the support to change tqps number for PF driver
by using ehtool -L command.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|   3 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 122 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|   2 +
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c |   1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 112 +++
 5 files changed, 240 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index d887721..a5d3d22 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -388,6 +388,9 @@ struct hnae3_ae_ops {
enum hnae3_reset_type reset);
void (*get_channels)(struct hnae3_handle *handle,
 struct ethtool_channels *ch);
+   void (*get_tqps_and_rss_info)(struct hnae3_handle *h,
+ u16 *free_tqps, u16 *max_rss_size);
+   int (*set_channels)(struct hnae3_handle *handle, u32 new_tqps_num);
 };
 
 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 c2c1323..7e92068 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2651,6 +2651,19 @@ static int hns3_get_ring_config(struct hns3_nic_priv 
*priv)
return ret;
 }
 
+static void hns3_put_ring_config(struct hns3_nic_priv *priv)
+{
+   struct hnae3_handle *h = priv->ae_handle;
+   int i;
+
+   for (i = 0; i < h->kinfo.num_tqps; i++) {
+   devm_kfree(priv->dev, priv->ring_data[i].ring);
+   devm_kfree(priv->dev,
+  priv->ring_data[i + h->kinfo.num_tqps].ring);
+   }
+   devm_kfree(priv->dev, priv->ring_data);
+}
+
 static int hns3_alloc_ring_memory(struct hns3_enet_ring *ring)
 {
int ret;
@@ -3162,6 +3175,115 @@ static int hns3_reset_notify(struct hnae3_handle 
*handle,
return ret;
 }
 
+static u16 hns3_get_max_available_channels(struct net_device *netdev)
+{
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+   u16 free_tqps, max_rss_size, max_tqps;
+
+   h->ae_algo->ops->get_tqps_and_rss_info(h, &free_tqps, &max_rss_size);
+   max_tqps = h->kinfo.num_tc * max_rss_size;
+
+   return min_t(u16, max_tqps, (free_tqps + h->kinfo.num_tqps));
+}
+
+static int hns3_modify_tqp_num(struct net_device *netdev, u16 new_tqp_num)
+{
+   struct hns3_nic_priv *priv = netdev_priv(netdev);
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+   int ret;
+
+   ret = h->ae_algo->ops->set_channels(h, new_tqp_num);
+   if (ret)
+   return ret;
+
+   ret = hns3_get_ring_config(priv);
+   if (ret)
+   return ret;
+
+   ret = hns3_nic_init_vector_data(priv);
+   if (ret)
+   goto err_uninit_vector;
+
+   ret = hns3_init_all_ring(priv);
+   if (ret)
+   goto err_put_ring;
+
+   return 0;
+
+err_put_ring:
+   hns3_put_ring_config(priv);
+err_uninit_vector:
+   hns3_nic_uninit_vector_data(priv);
+   return ret;
+}
+
+static int hns3_adjust_tqps_num(u8 num_tc, u32 new_tqp_num)
+{
+   return (new_tqp_num / num_tc) * num_tc;
+}
+
+int hns3_set_channels(struct net_device *netdev,
+ struct ethtool_channels *ch)
+{
+   struct hns3_nic_priv *priv = netdev_priv(netdev);
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+   struct hnae3_knic_private_info *kinfo = &h->kinfo;
+   bool if_running = netif_running(netdev);
+   u32 new_tqp_num = ch->combined_count;
+   u16 org_tqp_num;
+   int ret;
+
+   if (ch->rx_count || ch->tx_count)
+   return -EINVAL;
+
+   if (new_tqp_num > hns3_get_max_available_channels(netdev) ||
+   new_tqp_num < kinfo->num_tc) {
+   dev_err(&netdev->dev,
+   "Change tqps fail, the tqp range is from %d to %d",
+   kinfo->num_tc,
+   hns3_get_max_available_channels(netdev));
+   return -EINVAL;
+   }
+
+   new_tqp_num = hns3_adjust_tqps_num(kinfo->num_tc, new_tqp_num);
+   if (kinfo->num_tqps == new_tqp_num)
+   return 0;
+
+   if (if_running)
+   dev_close(netdev);
+
+   hns3_clear_all_ring(h);
+
+   ret = hns3_nic_uninit_vector_data(priv);
+   if (ret) {
+   dev_err(&netdev->dev,
+   "Unbind vector with tqp fail, nothing is changed");
+   goto open_netdev;
+   }
+
+   hns3_uninit_all_ring(priv);
+
+   org_tqp_num = h->

[PATCH V3 net-next 06/17] net: hns3: Add a mask initialization for mac_vlan table

2017-12-20 Thread Lipeng
This patch sets vlan masked, in order to avoid the received
packets being filtered.

Signed-off-by: Shenjian 
Signed-off-by: Lipeng 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h | 10 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 39 +-
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 1eb9ff0..10adf86 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -191,6 +191,7 @@ enum hclge_opcode_type {
HCLGE_OPC_MAC_VLAN_INSERT   = 0x1003,
HCLGE_OPC_MAC_ETHTYPE_ADD   = 0x1010,
HCLGE_OPC_MAC_ETHTYPE_REMOVE= 0x1011,
+   HCLGE_OPC_MAC_VLAN_MASK_SET = 0x1012,
 
/* Multicast linear table cmd */
HCLGE_OPC_MTA_MAC_MODE_CFG  = 0x1020,
@@ -589,6 +590,15 @@ struct hclge_mac_vlan_tbl_entry_cmd {
u8  rsv2[6];
 };
 
+#define HCLGE_VLAN_MASK_EN_B   0x0
+struct hclge_mac_vlan_mask_entry_cmd {
+   u8 rsv0[2];
+   u8 vlan_mask;
+   u8 rsv1;
+   u8 mac_mask[6];
+   u8 rsv2[14];
+};
+
 #define HCLGE_CFG_MTA_MAC_SEL_S0x0
 #define HCLGE_CFG_MTA_MAC_SEL_MGENMASK(1, 0)
 #define HCLGE_CFG_MTA_MAC_EN_B 0x7
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 691f85e..a1d9398 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2200,9 +2200,34 @@ static int hclge_get_autoneg(struct hnae3_handle *handle)
return hdev->hw.mac.autoneg;
 }
 
+static int hclge_set_default_mac_vlan_mask(struct hclge_dev *hdev,
+  bool mask_vlan,
+  u8 *mac_mask)
+{
+   struct hclge_mac_vlan_mask_entry_cmd *req;
+   struct hclge_desc desc;
+   int status;
+
+   req = (struct hclge_mac_vlan_mask_entry_cmd *)desc.data;
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_MAC_VLAN_MASK_SET, false);
+
+   hnae_set_bit(req->vlan_mask, HCLGE_VLAN_MASK_EN_B,
+mask_vlan ? 1 : 0);
+   ether_addr_copy(req->mac_mask, mac_mask);
+
+   status = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (status)
+   dev_err(&hdev->pdev->dev,
+   "Config mac_vlan_mask failed for cmd_send, ret =%d\n",
+   status);
+
+   return status;
+}
+
 static int hclge_mac_init(struct hclge_dev *hdev)
 {
struct hclge_mac *mac = &hdev->hw.mac;
+   u8 mac_mask[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
int ret;
 
ret = hclge_cfg_mac_speed_dup(hdev, hdev->hw.mac.speed, HCLGE_MAC_FULL);
@@ -2228,7 +2253,19 @@ static int hclge_mac_init(struct hclge_dev *hdev)
return ret;
}
 
-   return hclge_cfg_func_mta_filter(hdev, 0, hdev->accept_mta_mc);
+   ret = hclge_cfg_func_mta_filter(hdev, 0, hdev->accept_mta_mc);
+   if (ret) {
+   dev_err(&hdev->pdev->dev,
+   "set mta filter mode fail ret=%d\n", ret);
+   return ret;
+   }
+
+   ret = hclge_set_default_mac_vlan_mask(hdev, true, mac_mask);
+   if (ret)
+   dev_err(&hdev->pdev->dev,
+   "set default mac_vlan_mask fail ret=%d\n", ret);
+
+   return ret;
 }
 
 static void hclge_mbx_task_schedule(struct hclge_dev *hdev)
-- 
1.9.1



[PATCH V3 net-next 17/17] net: hns3: change TM sched mode to TC-based mode when SRIOV enabled

2017-12-20 Thread Lipeng
TC-based sched mode supports SRIOV enabled and SRIOV disabled. This
patch change the TM sched mode to TC-based mode in initialization
process.

Fixes: cc9bb43ab394 ("net: hns3: Add tc-based TM support for sriov enabled 
port")
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 4d69688..0874acf 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -1100,10 +1100,7 @@ static int hclge_configure(struct hclge_dev *hdev)
for (i = 0; i < hdev->tm_info.num_tc; i++)
hnae_set_bit(hdev->hw_tc_map, i, 1);
 
-   if (!hdev->num_vmdq_vport && !hdev->num_req_vfs)
-   hdev->tx_sch_mode = HCLGE_FLAG_TC_BASE_SCH_MODE;
-   else
-   hdev->tx_sch_mode = HCLGE_FLAG_VNET_BASE_SCH_MODE;
+   hdev->tx_sch_mode = HCLGE_FLAG_TC_BASE_SCH_MODE;
 
return ret;
 }
-- 
1.9.1



[PATCH V3 net-next 11/17] net: hns3: fix for getting auto-negotiation state in hclge_get_autoneg

2017-12-20 Thread Lipeng
From: Fuyun Liang 

When phy exists, we use the value of phydev.autoneg to represent the
auto-negotiation state of hardware. Otherwise, we use the value of
mac.autoneg to represent it.

This patch fixes for getting a error value of auto-negotiation state in
hclge_get_autoneg().

Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support")
Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 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 046f4bb..14e1054 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2172,6 +2172,10 @@ static int hclge_get_autoneg(struct hnae3_handle *handle)
 {
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+
+   if (phydev)
+   return phydev->autoneg;
 
return hdev->hw.mac.autoneg;
 }
-- 
1.9.1



[PATCH V3 net-next 08/17] net: hns3: Add ethtool related offload command

2017-12-20 Thread Lipeng
This patch adds offload command related to "ethtool -K".

Signed-off-by: Shenjian 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h |  3 +++
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 16 
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 13 +
 3 files changed, 32 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index a5d3d22..a67d02a9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -278,6 +278,8 @@ struct hnae3_ae_dev {
  *   Set vlan filter config of Ports
  * set_vf_vlan_filter()
  *   Set vlan filter config of vf
+ * enable_hw_strip_rxvtag()
+ *   Enable/disable hardware strip vlan tag of packets received
  */
 struct hnae3_ae_ops {
int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev);
@@ -384,6 +386,7 @@ struct hnae3_ae_ops {
   u16 vlan_id, bool is_kill);
int (*set_vf_vlan_filter)(struct hnae3_handle *handle, int vfid,
  u16 vlan, u8 qos, __be16 proto);
+   int (*enable_hw_strip_rxvtag)(struct hnae3_handle *handle, bool enable);
void (*reset_event)(struct hnae3_handle *handle,
enum hnae3_reset_type reset);
void (*get_channels)(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 1c93038..301b329 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1032,6 +1032,9 @@ static int hns3_nic_set_features(struct net_device 
*netdev,
 netdev_features_t features)
 {
struct hns3_nic_priv *priv = netdev_priv(netdev);
+   struct hnae3_handle *h = priv->ae_handle;
+   netdev_features_t changed;
+   int ret;
 
if (features & (NETIF_F_TSO | NETIF_F_TSO6)) {
priv->ops.fill_desc = hns3_fill_desc_tso;
@@ -1041,6 +1044,17 @@ static int hns3_nic_set_features(struct net_device 
*netdev,
priv->ops.maybe_stop_tx = hns3_nic_maybe_stop_tx;
}
 
+   changed = netdev->features ^ features;
+   if (changed & NETIF_F_HW_VLAN_CTAG_RX) {
+   if (features & NETIF_F_HW_VLAN_CTAG_RX)
+   ret = h->ae_algo->ops->enable_hw_strip_rxvtag(h, true);
+   else
+   ret = h->ae_algo->ops->enable_hw_strip_rxvtag(h, false);
+
+   if (ret)
+   return ret;
+   }
+
netdev->features = features;
return 0;
 }
@@ -1492,6 +1506,7 @@ static void hns3_set_default_feature(struct net_device 
*netdev)
 
netdev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
NETIF_F_HW_VLAN_CTAG_FILTER |
+   NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_GSO |
NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_GRE |
NETIF_F_GSO_GRE_CSUM | NETIF_F_GSO_UDP_TUNNEL |
@@ -1506,6 +1521,7 @@ static void hns3_set_default_feature(struct net_device 
*netdev)
 
netdev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
NETIF_F_HW_VLAN_CTAG_FILTER |
+   NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_GSO |
NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_GRE |
NETIF_F_GSO_GRE_CSUM | NETIF_F_GSO_UDP_TUNNEL |
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 113b859..d77a6de 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4547,6 +4547,18 @@ static int hclge_init_vlan_config(struct hclge_dev *hdev)
return hclge_set_port_vlan_filter(handle, htons(ETH_P_8021Q), 0, false);
 }
 
+static int hclge_en_hw_strip_rxvtag(struct hnae3_handle *handle, bool enable)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+
+   vport->rxvlan_cfg.strip_tag1_en = false;
+   vport->rxvlan_cfg.strip_tag2_en = enable;
+   vport->rxvlan_cfg.vlan1_vlan_prionly = false;
+   vport->rxvlan_cfg.vlan2_vlan_prionly = false;
+
+   return hclge_set_vlan_rx_offload_cfg(vport);
+}
+
 static int hclge_set_mtu(struct hnae3_handle *handle, int new_mtu)
 {
struct hclge_vport *vport = hclge_get_vport(handle);
@@ -5362,6 +5374,7 @@ static int hclge_set_channels(struct hnae3_handle 
*handle, u32 new_tqps_num)
.get_mdix_mode = hclge_get_mdix_mode,
.set_vlan_filter = hclge_set_port_vlan_filter,
.set_vf_vlan_filter = hclge_set_vf_vlan_filter,
+  

[PATCH V3 net-next 09/17] net: hns3: Add handling vlan tag offload in bd

2017-12-20 Thread Lipeng
This patch deals with the vlan tag information between
sk_buff and rx/tx bd.

Signed-off-by: Shenjian 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 83 +++--
 1 file changed, 78 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 301b329..320ae88 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -723,6 +723,58 @@ static void hns3_set_txbd_baseinfo(u16 
*bdtp_fe_sc_vld_ra_ri, int frag_end)
hnae_set_field(*bdtp_fe_sc_vld_ra_ri, HNS3_TXD_SC_M, HNS3_TXD_SC_S, 0);
 }
 
+static int hns3_fill_desc_vtags(struct sk_buff *skb,
+   struct hns3_enet_ring *tx_ring,
+   u32 *inner_vlan_flag,
+   u32 *out_vlan_flag,
+   u16 *inner_vtag,
+   u16 *out_vtag)
+{
+#define HNS3_TX_VLAN_PRIO_SHIFT 13
+
+   if (skb->protocol == htons(ETH_P_8021Q) &&
+   !(tx_ring->tqp->handle->kinfo.netdev->features &
+   NETIF_F_HW_VLAN_CTAG_TX)) {
+   /* When HW VLAN acceleration is turned off, and the stack
+* sets the protocol to 802.1q, the driver just need to
+* set the protocol to the encapsulated ethertype.
+*/
+   skb->protocol = vlan_get_protocol(skb);
+   return 0;
+   }
+
+   if (skb_vlan_tag_present(skb)) {
+   u16 vlan_tag;
+
+   vlan_tag = skb_vlan_tag_get(skb);
+   vlan_tag |= (skb->priority & 0x7) << HNS3_TX_VLAN_PRIO_SHIFT;
+
+   /* Based on hw strategy, use out_vtag in two layer tag case,
+* and use inner_vtag in one tag case.
+*/
+   if (skb->protocol == htons(ETH_P_8021Q)) {
+   hnae_set_bit(*out_vlan_flag, HNS3_TXD_OVLAN_B, 1);
+   *out_vtag = vlan_tag;
+   } else {
+   hnae_set_bit(*inner_vlan_flag, HNS3_TXD_VLAN_B, 1);
+   *inner_vtag = vlan_tag;
+   }
+   } else if (skb->protocol == htons(ETH_P_8021Q)) {
+   struct vlan_ethhdr *vhdr;
+   int rc;
+
+   rc = skb_cow_head(skb, 0);
+   if (rc < 0)
+   return rc;
+   vhdr = (struct vlan_ethhdr *)skb->data;
+   vhdr->h_vlan_TCI |= cpu_to_be16((skb->priority & 0x7)
+   << HNS3_TX_VLAN_PRIO_SHIFT);
+   }
+
+   skb->protocol = vlan_get_protocol(skb);
+   return 0;
+}
+
 static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
  int size, dma_addr_t dma, int frag_end,
  enum hns_desc_type type)
@@ -733,6 +785,8 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void 
*priv,
u16 bdtp_fe_sc_vld_ra_ri = 0;
u32 type_cs_vlan_tso = 0;
struct sk_buff *skb;
+   u16 inner_vtag = 0;
+   u16 out_vtag = 0;
u32 paylen = 0;
u16 mss = 0;
__be16 protocol;
@@ -756,15 +810,16 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, 
void *priv,
skb = (struct sk_buff *)priv;
paylen = skb->len;
 
+   ret = hns3_fill_desc_vtags(skb, ring, &type_cs_vlan_tso,
+  &ol_type_vlan_len_msec,
+  &inner_vtag, &out_vtag);
+   if (unlikely(ret))
+   return ret;
+
if (skb->ip_summed == CHECKSUM_PARTIAL) {
skb_reset_mac_len(skb);
protocol = skb->protocol;
 
-   /* vlan packet*/
-   if (protocol == htons(ETH_P_8021Q)) {
-   protocol = vlan_get_protocol(skb);
-   skb->protocol = protocol;
-   }
ret = hns3_get_l4_protocol(skb, &ol4_proto, &il4_proto);
if (ret)
return ret;
@@ -790,6 +845,8 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void 
*priv,
cpu_to_le32(type_cs_vlan_tso);
desc->tx.paylen = cpu_to_le32(paylen);
desc->tx.mss = cpu_to_le16(mss);
+   desc->tx.vlan_tag = cpu_to_le16(inner_vtag);
+   desc->tx.outer_vlan_tag = cpu_to_le16(out_vtag);
}
 
/* move ring pointer to next.*/
@@ -2101,6 +2158,22 @@ static int hns3_handle_rx_bd(struct hns3_enet_ring *ring,
 
prefetchw(skb->data);
 
+   /* Based on hw strategy, the tag offl

[PATCH V3 net-next 13/17] net: hns3: add support to update flow control settings after autoneg

2017-12-20 Thread Lipeng
When auto-negotiation is enabled, the MAC flow control settings is
based on the flow control negotiation result. And it should be configured
after a valid link has been established. This patch adds support to update
flow control settings after auto-negotiation has completed.

Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 36 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c|  4 +++
 3 files changed, 41 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 0f55ee6..bb31212 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4707,6 +4707,42 @@ static int hclge_cfg_pauseparam(struct hclge_dev *hdev, 
u32 rx_en, u32 tx_en)
return 0;
 }
 
+int hclge_cfg_flowctrl(struct hclge_dev *hdev)
+{
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+   u16 remote_advertising = 0;
+   u16 local_advertising = 0;
+   u32 rx_pause, tx_pause;
+   u8 flowctl;
+
+   if (!phydev->link || !phydev->autoneg)
+   return 0;
+
+   if (phydev->advertising & ADVERTISED_Pause)
+   local_advertising = ADVERTISE_PAUSE_CAP;
+
+   if (phydev->advertising & ADVERTISED_Asym_Pause)
+   local_advertising |= ADVERTISE_PAUSE_ASYM;
+
+   if (phydev->pause)
+   remote_advertising = LPA_PAUSE_CAP;
+
+   if (phydev->asym_pause)
+   remote_advertising |= LPA_PAUSE_ASYM;
+
+   flowctl = mii_resolve_flowctrl_fdx(local_advertising,
+  remote_advertising);
+   tx_pause = flowctl & FLOW_CTRL_TX;
+   rx_pause = flowctl & FLOW_CTRL_RX;
+
+   if (phydev->duplex == HCLGE_MAC_HALF) {
+   tx_pause = 0;
+   rx_pause = 0;
+   }
+
+   return hclge_cfg_pauseparam(hdev, rx_pause, tx_pause);
+}
+
 static void hclge_get_pauseparam(struct hnae3_handle *handle, u32 *auto_neg,
 u32 *rx_en, u32 *tx_en)
 {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
index cda520c..28cc063 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
@@ -602,4 +602,5 @@ int hclge_set_vf_vlan_common(struct hclge_dev *vport, int 
vfid,
 
 void hclge_mbx_handler(struct hclge_dev *hdev);
 void hclge_reset_tqp(struct hnae3_handle *handle, u16 queue_id);
+int hclge_cfg_flowctrl(struct hclge_dev *hdev);
 #endif
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
index 7069e94..3745153 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -183,6 +183,10 @@ static void hclge_mac_adjust_link(struct net_device 
*netdev)
ret = hclge_cfg_mac_speed_dup(hdev, speed, duplex);
if (ret)
netdev_err(netdev, "failed to adjust link.\n");
+
+   ret = hclge_cfg_flowctrl(hdev);
+   if (ret)
+   netdev_err(netdev, "failed to configure flow control.\n");
 }
 
 int hclge_mac_start_phy(struct hclge_dev *hdev)
-- 
1.9.1



[PATCH V3 net-next 10/17] net: hns3: cleanup mac auto-negotiation state query

2017-12-20 Thread Lipeng
From: Fuyun Liang 

When checking whether auto-negotiation is on, driver only needs to
check the value of mac.autoneg(SW) directly, and does not need to
query it from hardware. Because this value is always synchronized
with the auto-negotiation state of hardware.

This patch removes the mac auto-negotiation state query.

Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 24 --
 1 file changed, 24 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index d77a6de..046f4bb 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2137,28 +2137,6 @@ static int hclge_query_mac_an_speed_dup(struct hclge_dev 
*hdev, int *speed,
return 0;
 }
 
-static int hclge_query_autoneg_result(struct hclge_dev *hdev)
-{
-   struct hclge_mac *mac = &hdev->hw.mac;
-   struct hclge_query_an_speed_dup_cmd *req;
-   struct hclge_desc desc;
-   int ret;
-
-   req = (struct hclge_query_an_speed_dup_cmd *)desc.data;
-
-   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_AN_RESULT, true);
-   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
-   if (ret) {
-   dev_err(&hdev->pdev->dev,
-   "autoneg result query cmd failed %d.\n", ret);
-   return ret;
-   }
-
-   mac->autoneg = hnae_get_bit(req->an_syn_dup_speed, HCLGE_QUERY_AN_B);
-
-   return 0;
-}
-
 static int hclge_set_autoneg_en(struct hclge_dev *hdev, bool enable)
 {
struct hclge_config_auto_neg_cmd *req;
@@ -2195,8 +2173,6 @@ static int hclge_get_autoneg(struct hnae3_handle *handle)
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
 
-   hclge_query_autoneg_result(hdev);
-
return hdev->hw.mac.autoneg;
 }
 
-- 
1.9.1



[PATCH V3 net-next 14/17] net: hns3: add Asym Pause support to phy default features

2017-12-20 Thread Lipeng
From: Fuyun Liang 

commit c4fb2cdf575d ("net: hns3: fix a bug for phy supported feature
initialization") adds default supported features for phy, but our hardware
also supports Asym Pause. This patch adds Asym Pause support to phy
default features to prevent Asym Pause can not be advertised when the phy
negotiates flow control.

Fixes: c4fb2cdf575d ("net: hns3: fix a bug for phy supported feature 
initialization")
Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
index 3745153..c1dea3a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -17,6 +17,7 @@
 #define HCLGE_PHY_SUPPORTED_FEATURES   (SUPPORTED_Autoneg | \
 SUPPORTED_TP | \
 SUPPORTED_Pause | \
+SUPPORTED_Asym_Pause | \
 PHY_10BT_FEATURES | \
 PHY_100BT_FEATURES | \
 PHY_1000BT_FEATURES)
-- 
1.9.1



[PATCH V3 net-next 05/17] net: hns3: Get rss_size_max from configuration but not hardcode

2017-12-20 Thread Lipeng
From: qumingguang 

Add configuration for rss_size_max in hdev but not hardcode it.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h  | 2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 6 +-
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index ce5ed88..1eb9ff0 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -399,6 +399,8 @@ struct hclge_pf_res_cmd {
 #define HCLGE_CFG_MAC_ADDR_H_M GENMASK(15, 0)
 #define HCLGE_CFG_DEFAULT_SPEED_S  16
 #define HCLGE_CFG_DEFAULT_SPEED_M  GENMASK(23, 16)
+#define HCLGE_CFG_RSS_SIZE_S   24
+#define HCLGE_CFG_RSS_SIZE_M   GENMASK(31, 24)
 
 struct hclge_cfg_param_cmd {
__le32 offset;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 7fab102..691f85e 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -982,6 +982,10 @@ static void hclge_parse_cfg(struct hclge_cfg *cfg, struct 
hclge_desc *desc)
cfg->default_speed = hnae_get_field(__le32_to_cpu(req->param[3]),
HCLGE_CFG_DEFAULT_SPEED_M,
HCLGE_CFG_DEFAULT_SPEED_S);
+   cfg->rss_size_max = hnae_get_field(__le32_to_cpu(req->param[3]),
+  HCLGE_CFG_RSS_SIZE_M,
+  HCLGE_CFG_RSS_SIZE_S);
+
for (i = 0; i < ETH_ALEN; i++)
cfg->mac_addr[i] = (mac_addr_tmp >> (8 * i)) & 0xff;
 
@@ -1059,7 +1063,7 @@ static int hclge_configure(struct hclge_dev *hdev)
 
hdev->num_vmdq_vport = cfg.vmdq_vport_num;
hdev->base_tqp_pid = 0;
-   hdev->rss_size_max = 1;
+   hdev->rss_size_max = cfg.rss_size_max;
hdev->rx_buf_len = cfg.rx_buf_len;
ether_addr_copy(hdev->hw.mac.mac_addr, cfg.mac_addr);
hdev->hw.mac.media_type = cfg.media_type;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
index fb043b5..4858909 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
@@ -220,6 +220,7 @@ struct hclge_cfg {
u8 tc_num;
u16 tqp_desc_num;
u16 rx_buf_len;
+   u16 rss_size_max;
u8 phy_addr;
u8 media_type;
u8 mac_addr[ETH_ALEN];
-- 
1.9.1



[PATCH V3 net-next 04/17] net: hns3: Free the ring_data structrue when change tqps

2017-12-20 Thread Lipeng
This patch fixes a memory leak problems in change tqps process,
the function hns3_uninit_all_ring and hns3_init_all_ring
may be called many times.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 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 7e92068..1c93038 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2800,8 +2800,12 @@ int hns3_uninit_all_ring(struct hns3_nic_priv *priv)
h->ae_algo->ops->reset_queue(h, i);
 
hns3_fini_ring(priv->ring_data[i].ring);
+   devm_kfree(priv->dev, priv->ring_data[i].ring);
hns3_fini_ring(priv->ring_data[i + h->kinfo.num_tqps].ring);
+   devm_kfree(priv->dev,
+  priv->ring_data[i + h->kinfo.num_tqps].ring);
}
+   devm_kfree(priv->dev, priv->ring_data);
 
return 0;
 }
-- 
1.9.1



[PATCH V3 net-next 15/17] net: hns3: add support for querying advertised pause frame by ethtool ethx

2017-12-20 Thread Lipeng
This patch adds support for querying advertised pause frame by using
ethtool command(ethtool ethx).

Fixes: 496d03e960ae ("net: hns3: Add Ethtool support to HNS3 driver")
Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h |  2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c  | 15 +++
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 15 +++
 3 files changed, 32 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index a67d02a9..82e9a80 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -394,6 +394,8 @@ struct hnae3_ae_ops {
void (*get_tqps_and_rss_info)(struct hnae3_handle *h,
  u16 *free_tqps, u16 *max_rss_size);
int (*set_channels)(struct hnae3_handle *handle, u32 new_tqps_num);
+   void (*get_flowctrl_adv)(struct hnae3_handle *handle,
+u32 *flowctrl_adv);
 };
 
 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 b829ec7..2ae4d39 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -575,6 +575,7 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
   struct ethtool_link_ksettings *cmd)
 {
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;
@@ -650,6 +651,8 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
if (!cmd->base.autoneg)
advertised_caps &= ~HNS3_LM_AUTONEG_BIT;
 
+   advertised_caps &= ~HNS3_LM_PAUSE_BIT;
+
/* now, map driver link modes to ethtool link modes */
hns3_driv_to_eth_caps(supported_caps, cmd, false);
hns3_driv_to_eth_caps(advertised_caps, cmd, true);
@@ -662,6 +665,18 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
/* 4.mdio_support */
cmd->base.mdio_support = ETH_MDIO_SUPPORTS_C22;
 
+   /* 5.get flow control setttings */
+   if (h->ae_algo->ops->get_flowctrl_adv)
+   h->ae_algo->ops->get_flowctrl_adv(h, &flowctrl_adv);
+
+   if (flowctrl_adv & ADVERTISED_Pause)
+   ethtool_link_ksettings_add_link_mode(cmd, advertising,
+Pause);
+
+   if (flowctrl_adv & ADVERTISED_Asym_Pause)
+   ethtool_link_ksettings_add_link_mode(cmd, advertising,
+Asym_Pause);
+
return 0;
 }
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index bb31212..4d69688 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4660,6 +4660,20 @@ static u32 hclge_get_fw_version(struct hnae3_handle 
*handle)
return hdev->fw_version;
 }
 
+static void hclge_get_flowctrl_adv(struct hnae3_handle *handle,
+  u32 *flowctrl_adv)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+   struct hclge_dev *hdev = vport->back;
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+
+   if (!phydev)
+   return;
+
+   *flowctrl_adv |= (phydev->advertising & ADVERTISED_Pause) |
+(phydev->advertising & ADVERTISED_Asym_Pause);
+}
+
 static void hclge_set_flowctrl_adv(struct hclge_dev *hdev, u32 rx_en, u32 
tx_en)
 {
struct phy_device *phydev = hdev->hw.mac.phydev;
@@ -5478,6 +5492,7 @@ static int hclge_set_channels(struct hnae3_handle 
*handle, u32 new_tqps_num)
.get_tqps_and_rss_info = hclge_get_tqps_and_rss_info,
.set_channels = hclge_set_channels,
.get_channels = hclge_get_channels,
+   .get_flowctrl_adv = hclge_get_flowctrl_adv,
 };
 
 static struct hnae3_ae_algo ae_algo = {
-- 
1.9.1



[PATCH V4 net-next 10/17] net: hns3: cleanup mac auto-negotiation state query

2017-12-20 Thread Lipeng
From: Fuyun Liang 

When checking whether auto-negotiation is on, driver only needs to
check the value of mac.autoneg(SW) directly, and does not need to
query it from hardware. Because this value is always synchronized
with the auto-negotiation state of hardware.

This patch removes the mac auto-negotiation state query.

Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 24 --
 1 file changed, 24 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index d77a6de..046f4bb 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2137,28 +2137,6 @@ static int hclge_query_mac_an_speed_dup(struct hclge_dev 
*hdev, int *speed,
return 0;
 }
 
-static int hclge_query_autoneg_result(struct hclge_dev *hdev)
-{
-   struct hclge_mac *mac = &hdev->hw.mac;
-   struct hclge_query_an_speed_dup_cmd *req;
-   struct hclge_desc desc;
-   int ret;
-
-   req = (struct hclge_query_an_speed_dup_cmd *)desc.data;
-
-   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_QUERY_AN_RESULT, true);
-   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
-   if (ret) {
-   dev_err(&hdev->pdev->dev,
-   "autoneg result query cmd failed %d.\n", ret);
-   return ret;
-   }
-
-   mac->autoneg = hnae_get_bit(req->an_syn_dup_speed, HCLGE_QUERY_AN_B);
-
-   return 0;
-}
-
 static int hclge_set_autoneg_en(struct hclge_dev *hdev, bool enable)
 {
struct hclge_config_auto_neg_cmd *req;
@@ -2195,8 +2173,6 @@ static int hclge_get_autoneg(struct hnae3_handle *handle)
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
 
-   hclge_query_autoneg_result(hdev);
-
return hdev->hw.mac.autoneg;
 }
 
-- 
1.9.1



[PATCH V4 net-next 04/17] net: hns3: free the ring_data structrue when change tqps

2017-12-20 Thread Lipeng
This patch fixes a memory leak problems in change tqps process,
the function hns3_uninit_all_ring and hns3_init_all_ring
may be called many times.

Signed-off-by: Lipeng 
Signed-off-by: Mingguang Qu 
---
 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 7e92068..1c93038 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2800,8 +2800,12 @@ int hns3_uninit_all_ring(struct hns3_nic_priv *priv)
h->ae_algo->ops->reset_queue(h, i);
 
hns3_fini_ring(priv->ring_data[i].ring);
+   devm_kfree(priv->dev, priv->ring_data[i].ring);
hns3_fini_ring(priv->ring_data[i + h->kinfo.num_tqps].ring);
+   devm_kfree(priv->dev,
+  priv->ring_data[i + h->kinfo.num_tqps].ring);
}
+   devm_kfree(priv->dev, priv->ring_data);
 
return 0;
 }
-- 
1.9.1



[PATCH V4 net-next 16/17] net: hns3: Increase the default depth of bucket for TM shaper

2017-12-20 Thread Lipeng
Burstiness of a flow is determined by the depth of a bucket, When the
upper rate of shaper is large, the current depth of a bucket is not
enough.

The default upper rate of shaper is 100G, so increase the depth of
a bucket according to UM.

Signed-off-by: Lipeng 
Signed-off-by: Yunsheng Lin 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
index 7cfe1eb..ea9355d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
@@ -23,8 +23,8 @@ enum hclge_shaper_level {
HCLGE_SHAPER_LVL_PF = 1,
 };
 
-#define HCLGE_SHAPER_BS_U_DEF  1
-#define HCLGE_SHAPER_BS_S_DEF  4
+#define HCLGE_SHAPER_BS_U_DEF  5
+#define HCLGE_SHAPER_BS_S_DEF  20
 
 #define HCLGE_ETHER_MAX_RATE   10
 
-- 
1.9.1



[PATCH V4 net-next 12/17] net: hns3: add support for set_pauseparam

2017-12-20 Thread Lipeng
This patch adds set_pauseparam support for ethtool cmd.

Signed-off-by: Lipeng 
Signed-off-by: Fuyun Liang 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 13 
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 83 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  |  2 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |  1 +
 4 files changed, 98 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
index 2fd2656..b829ec7 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -559,6 +559,18 @@ static void hns3_get_pauseparam(struct net_device *netdev,
¶m->rx_pause, ¶m->tx_pause);
 }
 
+static int hns3_set_pauseparam(struct net_device *netdev,
+  struct ethtool_pauseparam *param)
+{
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+
+   if (h->ae_algo->ops->set_pauseparam)
+   return h->ae_algo->ops->set_pauseparam(h, param->autoneg,
+  param->rx_pause,
+  param->tx_pause);
+   return -EOPNOTSUPP;
+}
+
 static int hns3_get_link_ksettings(struct net_device *netdev,
   struct ethtool_link_ksettings *cmd)
 {
@@ -880,6 +892,7 @@ void hns3_get_channels(struct net_device *netdev,
.get_ringparam = hns3_get_ringparam,
.set_ringparam = hns3_set_ringparam,
.get_pauseparam = hns3_get_pauseparam,
+   .set_pauseparam = hns3_set_pauseparam,
.get_strings = hns3_get_strings,
.get_ethtool_stats = hns3_get_stats,
.get_sset_count = hns3_get_sset_count,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 14e1054..0f55ee6 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4660,6 +4660,53 @@ static u32 hclge_get_fw_version(struct hnae3_handle 
*handle)
return hdev->fw_version;
 }
 
+static void hclge_set_flowctrl_adv(struct hclge_dev *hdev, u32 rx_en, u32 
tx_en)
+{
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+
+   if (!phydev)
+   return;
+
+   phydev->advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause);
+
+   if (rx_en)
+   phydev->advertising |= ADVERTISED_Pause | ADVERTISED_Asym_Pause;
+
+   if (tx_en)
+   phydev->advertising ^= ADVERTISED_Asym_Pause;
+}
+
+static int hclge_cfg_pauseparam(struct hclge_dev *hdev, u32 rx_en, u32 tx_en)
+{
+   enum hclge_fc_mode fc_mode;
+   int ret;
+
+   if (rx_en && tx_en)
+   fc_mode = HCLGE_FC_FULL;
+   else if (rx_en && !tx_en)
+   fc_mode = HCLGE_FC_RX_PAUSE;
+   else if (!rx_en && tx_en)
+   fc_mode = HCLGE_FC_TX_PAUSE;
+   else
+   fc_mode = HCLGE_FC_NONE;
+
+   if (hdev->tm_info.fc_mode == HCLGE_FC_PFC) {
+   hdev->fc_mode_last_time = fc_mode;
+   return 0;
+   }
+
+   ret = hclge_mac_pause_en_cfg(hdev, tx_en, rx_en);
+   if (ret) {
+   dev_err(&hdev->pdev->dev, "configure pauseparam error, ret = 
%d.\n",
+   ret);
+   return ret;
+   }
+
+   hdev->tm_info.fc_mode = fc_mode;
+
+   return 0;
+}
+
 static void hclge_get_pauseparam(struct hnae3_handle *handle, u32 *auto_neg,
 u32 *rx_en, u32 *tx_en)
 {
@@ -4689,6 +4736,41 @@ static void hclge_get_pauseparam(struct hnae3_handle 
*handle, u32 *auto_neg,
}
 }
 
+static int hclge_set_pauseparam(struct hnae3_handle *handle, u32 auto_neg,
+   u32 rx_en, u32 tx_en)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+   struct hclge_dev *hdev = vport->back;
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+   u32 fc_autoneg;
+
+   /* Only support flow control negotiation for netdev with
+* phy attached for now.
+*/
+   if (!phydev)
+   return -EOPNOTSUPP;
+
+   fc_autoneg = hclge_get_autoneg(handle);
+   if (auto_neg != fc_autoneg) {
+   dev_info(&hdev->pdev->dev,
+"To change autoneg please use: ethtool -s  
autoneg \n");
+   return -EOPNOTSUPP;
+   }
+
+   if (hdev->tm_info.fc_mode == HCLGE_FC_PFC) {
+   dev_info(&hdev->pdev->dev,
+"Priority flow control enabled. Cannot set link flow 
control.\n");
+   return -EOPNOTSUPP;
+   }
+
+   hclge_set_flowctrl_adv(hdev, rx_en,

[PATCH V4 net-next 15/17] net: hns3: add support for querying advertised pause frame by ethtool ethx

2017-12-20 Thread Lipeng
This patch adds support for querying advertised pause frame by using
ethtool command(ethtool ethx).

Fixes: 496d03e960ae ("net: hns3: Add Ethtool support to HNS3 driver")
Signed-off-by: Lipeng 
Signed-off-by: Fuyun Liang 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h |  2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c  | 15 +++
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 15 +++
 3 files changed, 32 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index a67d02a9..82e9a80 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -394,6 +394,8 @@ struct hnae3_ae_ops {
void (*get_tqps_and_rss_info)(struct hnae3_handle *h,
  u16 *free_tqps, u16 *max_rss_size);
int (*set_channels)(struct hnae3_handle *handle, u32 new_tqps_num);
+   void (*get_flowctrl_adv)(struct hnae3_handle *handle,
+u32 *flowctrl_adv);
 };
 
 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 b829ec7..2ae4d39 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -575,6 +575,7 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
   struct ethtool_link_ksettings *cmd)
 {
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;
@@ -650,6 +651,8 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
if (!cmd->base.autoneg)
advertised_caps &= ~HNS3_LM_AUTONEG_BIT;
 
+   advertised_caps &= ~HNS3_LM_PAUSE_BIT;
+
/* now, map driver link modes to ethtool link modes */
hns3_driv_to_eth_caps(supported_caps, cmd, false);
hns3_driv_to_eth_caps(advertised_caps, cmd, true);
@@ -662,6 +665,18 @@ static int hns3_get_link_ksettings(struct net_device 
*netdev,
/* 4.mdio_support */
cmd->base.mdio_support = ETH_MDIO_SUPPORTS_C22;
 
+   /* 5.get flow control setttings */
+   if (h->ae_algo->ops->get_flowctrl_adv)
+   h->ae_algo->ops->get_flowctrl_adv(h, &flowctrl_adv);
+
+   if (flowctrl_adv & ADVERTISED_Pause)
+   ethtool_link_ksettings_add_link_mode(cmd, advertising,
+Pause);
+
+   if (flowctrl_adv & ADVERTISED_Asym_Pause)
+   ethtool_link_ksettings_add_link_mode(cmd, advertising,
+Asym_Pause);
+
return 0;
 }
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index bb31212..4d69688 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4660,6 +4660,20 @@ static u32 hclge_get_fw_version(struct hnae3_handle 
*handle)
return hdev->fw_version;
 }
 
+static void hclge_get_flowctrl_adv(struct hnae3_handle *handle,
+  u32 *flowctrl_adv)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+   struct hclge_dev *hdev = vport->back;
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+
+   if (!phydev)
+   return;
+
+   *flowctrl_adv |= (phydev->advertising & ADVERTISED_Pause) |
+(phydev->advertising & ADVERTISED_Asym_Pause);
+}
+
 static void hclge_set_flowctrl_adv(struct hclge_dev *hdev, u32 rx_en, u32 
tx_en)
 {
struct phy_device *phydev = hdev->hw.mac.phydev;
@@ -5478,6 +5492,7 @@ static int hclge_set_channels(struct hnae3_handle 
*handle, u32 new_tqps_num)
.get_tqps_and_rss_info = hclge_get_tqps_and_rss_info,
.set_channels = hclge_set_channels,
.get_channels = hclge_get_channels,
+   .get_flowctrl_adv = hclge_get_flowctrl_adv,
 };
 
 static struct hnae3_ae_algo ae_algo = {
-- 
1.9.1



[PATCH V4 net-next 06/17] net: hns3: add a mask initialization for mac_vlan table

2017-12-20 Thread Lipeng
This patch sets vlan masked, in order to avoid the received
packets being filtered.

Signed-off-by: Lipeng 
Signed-off-by: Jian Shen 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h | 10 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 39 +-
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 1eb9ff0..10adf86 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -191,6 +191,7 @@ enum hclge_opcode_type {
HCLGE_OPC_MAC_VLAN_INSERT   = 0x1003,
HCLGE_OPC_MAC_ETHTYPE_ADD   = 0x1010,
HCLGE_OPC_MAC_ETHTYPE_REMOVE= 0x1011,
+   HCLGE_OPC_MAC_VLAN_MASK_SET = 0x1012,
 
/* Multicast linear table cmd */
HCLGE_OPC_MTA_MAC_MODE_CFG  = 0x1020,
@@ -589,6 +590,15 @@ struct hclge_mac_vlan_tbl_entry_cmd {
u8  rsv2[6];
 };
 
+#define HCLGE_VLAN_MASK_EN_B   0x0
+struct hclge_mac_vlan_mask_entry_cmd {
+   u8 rsv0[2];
+   u8 vlan_mask;
+   u8 rsv1;
+   u8 mac_mask[6];
+   u8 rsv2[14];
+};
+
 #define HCLGE_CFG_MTA_MAC_SEL_S0x0
 #define HCLGE_CFG_MTA_MAC_SEL_MGENMASK(1, 0)
 #define HCLGE_CFG_MTA_MAC_EN_B 0x7
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 691f85e..a1d9398 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2200,9 +2200,34 @@ static int hclge_get_autoneg(struct hnae3_handle *handle)
return hdev->hw.mac.autoneg;
 }
 
+static int hclge_set_default_mac_vlan_mask(struct hclge_dev *hdev,
+  bool mask_vlan,
+  u8 *mac_mask)
+{
+   struct hclge_mac_vlan_mask_entry_cmd *req;
+   struct hclge_desc desc;
+   int status;
+
+   req = (struct hclge_mac_vlan_mask_entry_cmd *)desc.data;
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_MAC_VLAN_MASK_SET, false);
+
+   hnae_set_bit(req->vlan_mask, HCLGE_VLAN_MASK_EN_B,
+mask_vlan ? 1 : 0);
+   ether_addr_copy(req->mac_mask, mac_mask);
+
+   status = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (status)
+   dev_err(&hdev->pdev->dev,
+   "Config mac_vlan_mask failed for cmd_send, ret =%d\n",
+   status);
+
+   return status;
+}
+
 static int hclge_mac_init(struct hclge_dev *hdev)
 {
struct hclge_mac *mac = &hdev->hw.mac;
+   u8 mac_mask[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
int ret;
 
ret = hclge_cfg_mac_speed_dup(hdev, hdev->hw.mac.speed, HCLGE_MAC_FULL);
@@ -2228,7 +2253,19 @@ static int hclge_mac_init(struct hclge_dev *hdev)
return ret;
}
 
-   return hclge_cfg_func_mta_filter(hdev, 0, hdev->accept_mta_mc);
+   ret = hclge_cfg_func_mta_filter(hdev, 0, hdev->accept_mta_mc);
+   if (ret) {
+   dev_err(&hdev->pdev->dev,
+   "set mta filter mode fail ret=%d\n", ret);
+   return ret;
+   }
+
+   ret = hclge_set_default_mac_vlan_mask(hdev, true, mac_mask);
+   if (ret)
+   dev_err(&hdev->pdev->dev,
+   "set default mac_vlan_mask fail ret=%d\n", ret);
+
+   return ret;
 }
 
 static void hclge_mbx_task_schedule(struct hclge_dev *hdev)
-- 
1.9.1



[PATCH V4 net-next 14/17] net: hns3: add Asym Pause support to phy default features

2017-12-20 Thread Lipeng
From: Fuyun Liang 

commit c4fb2cdf575d ("net: hns3: fix a bug for phy supported feature
initialization") adds default supported features for phy, but our hardware
also supports Asym Pause. This patch adds Asym Pause support to phy
default features to prevent Asym Pause can not be advertised when the phy
negotiates flow control.

Fixes: c4fb2cdf575d ("net: hns3: fix a bug for phy supported feature 
initialization")
Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
index 3745153..c1dea3a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -17,6 +17,7 @@
 #define HCLGE_PHY_SUPPORTED_FEATURES   (SUPPORTED_Autoneg | \
 SUPPORTED_TP | \
 SUPPORTED_Pause | \
+SUPPORTED_Asym_Pause | \
 PHY_10BT_FEATURES | \
 PHY_100BT_FEATURES | \
 PHY_1000BT_FEATURES)
-- 
1.9.1



[PATCH V4 net-next 07/17] net: hns3: add vlan offload config command

2017-12-20 Thread Lipeng
This patch adds vlan offload config commands, initializes
the rules of tx/rx vlan tag handle for hw.

Signed-off-by: Lipeng 
Signed-off-by: Jian Shen 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  45 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 158 -
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  36 +
 3 files changed, 233 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 10adf86..f5baba21 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -180,6 +180,10 @@ enum hclge_opcode_type {
/* Promisuous mode command */
HCLGE_OPC_CFG_PROMISC_MODE  = 0x0E01,
 
+   /* Vlan offload command */
+   HCLGE_OPC_VLAN_PORT_TX_CFG  = 0x0F01,
+   HCLGE_OPC_VLAN_PORT_RX_CFG  = 0x0F02,
+
/* Interrupts cmd */
HCLGE_OPC_ADD_RING_TO_VECTOR= 0x1503,
HCLGE_OPC_DEL_RING_TO_VECTOR= 0x1504,
@@ -670,6 +674,47 @@ struct hclge_vlan_filter_vf_cfg_cmd {
u8  vf_bitmap[16];
 };
 
+#define HCLGE_ACCEPT_TAG_B 0
+#define HCLGE_ACCEPT_UNTAG_B   1
+#define HCLGE_PORT_INS_TAG1_EN_B   2
+#define HCLGE_PORT_INS_TAG2_EN_B   3
+#define HCLGE_CFG_NIC_ROCE_SEL_B   4
+struct hclge_vport_vtag_tx_cfg_cmd {
+   u8 vport_vlan_cfg;
+   u8 vf_offset;
+   u8 rsv1[2];
+   __le16 def_vlan_tag1;
+   __le16 def_vlan_tag2;
+   u8 vf_bitmap[8];
+   u8 rsv2[8];
+};
+
+#define HCLGE_REM_TAG1_EN_B0
+#define HCLGE_REM_TAG2_EN_B1
+#define HCLGE_SHOW_TAG1_EN_B   2
+#define HCLGE_SHOW_TAG2_EN_B   3
+struct hclge_vport_vtag_rx_cfg_cmd {
+   u8 vport_vlan_cfg;
+   u8 vf_offset;
+   u8 rsv1[6];
+   u8 vf_bitmap[8];
+   u8 rsv2[8];
+};
+
+struct hclge_tx_vlan_type_cfg_cmd {
+   __le16 ot_vlan_type;
+   __le16 in_vlan_type;
+   u8 rsv[20];
+};
+
+struct hclge_rx_vlan_type_cfg_cmd {
+   __le16 ot_fst_vlan_type;
+   __le16 ot_sec_vlan_type;
+   __le16 in_fst_vlan_type;
+   __le16 in_sec_vlan_type;
+   u8 rsv[16];
+};
+
 struct hclge_cfg_com_tqp_queue_cmd {
__le16 tqp_id;
__le16 stream_id;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index a1d9398..113b859 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4380,23 +4380,169 @@ static int hclge_set_vf_vlan_filter(struct 
hnae3_handle *handle, int vfid,
return hclge_set_vf_vlan_common(hdev, vfid, false, vlan, qos, proto);
 }
 
+static int hclge_set_vlan_tx_offload_cfg(struct hclge_vport *vport)
+{
+   struct hclge_tx_vtag_cfg *vcfg = &vport->txvlan_cfg;
+   struct hclge_vport_vtag_tx_cfg_cmd *req;
+   struct hclge_dev *hdev = vport->back;
+   struct hclge_desc desc;
+   int status;
+
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_VLAN_PORT_TX_CFG, false);
+
+   req = (struct hclge_vport_vtag_tx_cfg_cmd *)desc.data;
+   req->def_vlan_tag1 = cpu_to_le16(vcfg->default_tag1);
+   req->def_vlan_tag2 = cpu_to_le16(vcfg->default_tag2);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_ACCEPT_TAG_B,
+vcfg->accept_tag ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_ACCEPT_UNTAG_B,
+vcfg->accept_untag ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_PORT_INS_TAG1_EN_B,
+vcfg->insert_tag1_en ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_PORT_INS_TAG2_EN_B,
+vcfg->insert_tag2_en ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_CFG_NIC_ROCE_SEL_B, 0);
+
+   req->vf_offset = vport->vport_id / HCLGE_VF_NUM_PER_CMD;
+   req->vf_bitmap[req->vf_offset] =
+   1 << (vport->vport_id % HCLGE_VF_NUM_PER_BYTE);
+
+   status = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (status)
+   dev_err(&hdev->pdev->dev,
+   "Send port txvlan cfg command fail, ret =%d\n",
+   status);
+
+   return status;
+}
+
+static int hclge_set_vlan_rx_offload_cfg(struct hclge_vport *vport)
+{
+   struct hclge_rx_vtag_cfg *vcfg = &vport->rxvlan_cfg;
+   struct hclge_vport_vtag_rx_cfg_cmd *req;
+   struct hclge_dev *hdev = vport->back;
+   struct hclge_desc desc;
+   int status;
+
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_VLAN_PORT_RX_CFG, false);
+
+   req = (struct hclge_vport_vtag_rx_cfg_cmd *)desc.data;
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_REM_TAG1_EN_B,
+vcfg->strip_tag1_en ? 1 : 0);
+   h

[PATCH V4 net-next 09/17] net: hns3: add handling vlan tag offload in bd

2017-12-20 Thread Lipeng
This patch deals with the vlan tag information between
sk_buff and rx/tx bd.

Signed-off-by: Lipeng 
Signed-off-by: Jian Shen 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 83 +++--
 1 file changed, 78 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 301b329..320ae88 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -723,6 +723,58 @@ static void hns3_set_txbd_baseinfo(u16 
*bdtp_fe_sc_vld_ra_ri, int frag_end)
hnae_set_field(*bdtp_fe_sc_vld_ra_ri, HNS3_TXD_SC_M, HNS3_TXD_SC_S, 0);
 }
 
+static int hns3_fill_desc_vtags(struct sk_buff *skb,
+   struct hns3_enet_ring *tx_ring,
+   u32 *inner_vlan_flag,
+   u32 *out_vlan_flag,
+   u16 *inner_vtag,
+   u16 *out_vtag)
+{
+#define HNS3_TX_VLAN_PRIO_SHIFT 13
+
+   if (skb->protocol == htons(ETH_P_8021Q) &&
+   !(tx_ring->tqp->handle->kinfo.netdev->features &
+   NETIF_F_HW_VLAN_CTAG_TX)) {
+   /* When HW VLAN acceleration is turned off, and the stack
+* sets the protocol to 802.1q, the driver just need to
+* set the protocol to the encapsulated ethertype.
+*/
+   skb->protocol = vlan_get_protocol(skb);
+   return 0;
+   }
+
+   if (skb_vlan_tag_present(skb)) {
+   u16 vlan_tag;
+
+   vlan_tag = skb_vlan_tag_get(skb);
+   vlan_tag |= (skb->priority & 0x7) << HNS3_TX_VLAN_PRIO_SHIFT;
+
+   /* Based on hw strategy, use out_vtag in two layer tag case,
+* and use inner_vtag in one tag case.
+*/
+   if (skb->protocol == htons(ETH_P_8021Q)) {
+   hnae_set_bit(*out_vlan_flag, HNS3_TXD_OVLAN_B, 1);
+   *out_vtag = vlan_tag;
+   } else {
+   hnae_set_bit(*inner_vlan_flag, HNS3_TXD_VLAN_B, 1);
+   *inner_vtag = vlan_tag;
+   }
+   } else if (skb->protocol == htons(ETH_P_8021Q)) {
+   struct vlan_ethhdr *vhdr;
+   int rc;
+
+   rc = skb_cow_head(skb, 0);
+   if (rc < 0)
+   return rc;
+   vhdr = (struct vlan_ethhdr *)skb->data;
+   vhdr->h_vlan_TCI |= cpu_to_be16((skb->priority & 0x7)
+   << HNS3_TX_VLAN_PRIO_SHIFT);
+   }
+
+   skb->protocol = vlan_get_protocol(skb);
+   return 0;
+}
+
 static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
  int size, dma_addr_t dma, int frag_end,
  enum hns_desc_type type)
@@ -733,6 +785,8 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void 
*priv,
u16 bdtp_fe_sc_vld_ra_ri = 0;
u32 type_cs_vlan_tso = 0;
struct sk_buff *skb;
+   u16 inner_vtag = 0;
+   u16 out_vtag = 0;
u32 paylen = 0;
u16 mss = 0;
__be16 protocol;
@@ -756,15 +810,16 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, 
void *priv,
skb = (struct sk_buff *)priv;
paylen = skb->len;
 
+   ret = hns3_fill_desc_vtags(skb, ring, &type_cs_vlan_tso,
+  &ol_type_vlan_len_msec,
+  &inner_vtag, &out_vtag);
+   if (unlikely(ret))
+   return ret;
+
if (skb->ip_summed == CHECKSUM_PARTIAL) {
skb_reset_mac_len(skb);
protocol = skb->protocol;
 
-   /* vlan packet*/
-   if (protocol == htons(ETH_P_8021Q)) {
-   protocol = vlan_get_protocol(skb);
-   skb->protocol = protocol;
-   }
ret = hns3_get_l4_protocol(skb, &ol4_proto, &il4_proto);
if (ret)
return ret;
@@ -790,6 +845,8 @@ static int hns3_fill_desc(struct hns3_enet_ring *ring, void 
*priv,
cpu_to_le32(type_cs_vlan_tso);
desc->tx.paylen = cpu_to_le32(paylen);
desc->tx.mss = cpu_to_le16(mss);
+   desc->tx.vlan_tag = cpu_to_le16(inner_vtag);
+   desc->tx.outer_vlan_tag = cpu_to_le16(out_vtag);
}
 
/* move ring pointer to next.*/
@@ -2101,6 +2158,22 @@ static int hns3_handle_rx_bd(struct hns3_enet_ring *ring,
 
prefetchw(skb->data);
 
+   /* Based on hw strategy, the tag offl

[PATCH V4 net-next 05/17] net: hns3: get rss_size_max from configuration but not hardcode

2017-12-20 Thread Lipeng
Add configuration for rss_size_max in hdev but not hardcode it.

Signed-off-by: Lipeng 
Signed-off-by: Mingguang Qu 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h  | 2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 6 +-
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index ce5ed88..1eb9ff0 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -399,6 +399,8 @@ struct hclge_pf_res_cmd {
 #define HCLGE_CFG_MAC_ADDR_H_M GENMASK(15, 0)
 #define HCLGE_CFG_DEFAULT_SPEED_S  16
 #define HCLGE_CFG_DEFAULT_SPEED_M  GENMASK(23, 16)
+#define HCLGE_CFG_RSS_SIZE_S   24
+#define HCLGE_CFG_RSS_SIZE_M   GENMASK(31, 24)
 
 struct hclge_cfg_param_cmd {
__le32 offset;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 7fab102..691f85e 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -982,6 +982,10 @@ static void hclge_parse_cfg(struct hclge_cfg *cfg, struct 
hclge_desc *desc)
cfg->default_speed = hnae_get_field(__le32_to_cpu(req->param[3]),
HCLGE_CFG_DEFAULT_SPEED_M,
HCLGE_CFG_DEFAULT_SPEED_S);
+   cfg->rss_size_max = hnae_get_field(__le32_to_cpu(req->param[3]),
+  HCLGE_CFG_RSS_SIZE_M,
+  HCLGE_CFG_RSS_SIZE_S);
+
for (i = 0; i < ETH_ALEN; i++)
cfg->mac_addr[i] = (mac_addr_tmp >> (8 * i)) & 0xff;
 
@@ -1059,7 +1063,7 @@ static int hclge_configure(struct hclge_dev *hdev)
 
hdev->num_vmdq_vport = cfg.vmdq_vport_num;
hdev->base_tqp_pid = 0;
-   hdev->rss_size_max = 1;
+   hdev->rss_size_max = cfg.rss_size_max;
hdev->rx_buf_len = cfg.rx_buf_len;
ether_addr_copy(hdev->hw.mac.mac_addr, cfg.mac_addr);
hdev->hw.mac.media_type = cfg.media_type;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
index fb043b5..4858909 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
@@ -220,6 +220,7 @@ struct hclge_cfg {
u8 tc_num;
u16 tqp_desc_num;
u16 rx_buf_len;
+   u16 rss_size_max;
u8 phy_addr;
u8 media_type;
u8 mac_addr[ETH_ALEN];
-- 
1.9.1



[PATCH V4 net-next 17/17] net: hns3: change TM sched mode to TC-based mode when SRIOV enabled

2017-12-20 Thread Lipeng
TC-based sched mode supports SRIOV enabled and SRIOV disabled. This
patch change the TM sched mode to TC-based mode in initialization
process.

Fixes: cc9bb43ab394 ("net: hns3: Add tc-based TM support for sriov enabled 
port")
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 4d69688..0874acf 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -1100,10 +1100,7 @@ static int hclge_configure(struct hclge_dev *hdev)
for (i = 0; i < hdev->tm_info.num_tc; i++)
hnae_set_bit(hdev->hw_tc_map, i, 1);
 
-   if (!hdev->num_vmdq_vport && !hdev->num_req_vfs)
-   hdev->tx_sch_mode = HCLGE_FLAG_TC_BASE_SCH_MODE;
-   else
-   hdev->tx_sch_mode = HCLGE_FLAG_VNET_BASE_SCH_MODE;
+   hdev->tx_sch_mode = HCLGE_FLAG_TC_BASE_SCH_MODE;
 
return ret;
 }
-- 
1.9.1



[PATCH V4 net-next 03/17] net: hns3: change the returned tqp number by ethtool -x

2017-12-20 Thread Lipeng
This patch modifies the return data of get_rxnfc, it will return
the current handle's rss_size but not the total tqp number.
because the tc_size has been change to the log2 of roundup
power of two of rss_size.

Signed-off-by: Lipeng 
Signed-off-by: Mingguang Qu 
---
 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 1b2d79b..2fd2656 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -730,7 +730,7 @@ static int hns3_get_rxnfc(struct net_device *netdev,
 
switch (cmd->cmd) {
case ETHTOOL_GRXRINGS:
-   cmd->data = h->kinfo.num_tc * h->kinfo.rss_size;
+   cmd->data = h->kinfo.rss_size;
break;
case ETHTOOL_GRXFH:
return h->ae_algo->ops->get_rss_tuple(h, cmd);
-- 
1.9.1



[PATCH V4 net-next 02/17] net: hns3: add support to modify tqps number

2017-12-20 Thread Lipeng
This patch adds the support to change tqps number for PF driver
by using ehtool -L command.

Signed-off-by: Lipeng 
Signed-off-by: Mingguang Qu 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|   3 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 122 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|   2 +
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c |   1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 112 +++
 5 files changed, 240 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index d887721..a5d3d22 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -388,6 +388,9 @@ struct hnae3_ae_ops {
enum hnae3_reset_type reset);
void (*get_channels)(struct hnae3_handle *handle,
 struct ethtool_channels *ch);
+   void (*get_tqps_and_rss_info)(struct hnae3_handle *h,
+ u16 *free_tqps, u16 *max_rss_size);
+   int (*set_channels)(struct hnae3_handle *handle, u32 new_tqps_num);
 };
 
 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 c2c1323..7e92068 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2651,6 +2651,19 @@ static int hns3_get_ring_config(struct hns3_nic_priv 
*priv)
return ret;
 }
 
+static void hns3_put_ring_config(struct hns3_nic_priv *priv)
+{
+   struct hnae3_handle *h = priv->ae_handle;
+   int i;
+
+   for (i = 0; i < h->kinfo.num_tqps; i++) {
+   devm_kfree(priv->dev, priv->ring_data[i].ring);
+   devm_kfree(priv->dev,
+  priv->ring_data[i + h->kinfo.num_tqps].ring);
+   }
+   devm_kfree(priv->dev, priv->ring_data);
+}
+
 static int hns3_alloc_ring_memory(struct hns3_enet_ring *ring)
 {
int ret;
@@ -3162,6 +3175,115 @@ static int hns3_reset_notify(struct hnae3_handle 
*handle,
return ret;
 }
 
+static u16 hns3_get_max_available_channels(struct net_device *netdev)
+{
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+   u16 free_tqps, max_rss_size, max_tqps;
+
+   h->ae_algo->ops->get_tqps_and_rss_info(h, &free_tqps, &max_rss_size);
+   max_tqps = h->kinfo.num_tc * max_rss_size;
+
+   return min_t(u16, max_tqps, (free_tqps + h->kinfo.num_tqps));
+}
+
+static int hns3_modify_tqp_num(struct net_device *netdev, u16 new_tqp_num)
+{
+   struct hns3_nic_priv *priv = netdev_priv(netdev);
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+   int ret;
+
+   ret = h->ae_algo->ops->set_channels(h, new_tqp_num);
+   if (ret)
+   return ret;
+
+   ret = hns3_get_ring_config(priv);
+   if (ret)
+   return ret;
+
+   ret = hns3_nic_init_vector_data(priv);
+   if (ret)
+   goto err_uninit_vector;
+
+   ret = hns3_init_all_ring(priv);
+   if (ret)
+   goto err_put_ring;
+
+   return 0;
+
+err_put_ring:
+   hns3_put_ring_config(priv);
+err_uninit_vector:
+   hns3_nic_uninit_vector_data(priv);
+   return ret;
+}
+
+static int hns3_adjust_tqps_num(u8 num_tc, u32 new_tqp_num)
+{
+   return (new_tqp_num / num_tc) * num_tc;
+}
+
+int hns3_set_channels(struct net_device *netdev,
+ struct ethtool_channels *ch)
+{
+   struct hns3_nic_priv *priv = netdev_priv(netdev);
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+   struct hnae3_knic_private_info *kinfo = &h->kinfo;
+   bool if_running = netif_running(netdev);
+   u32 new_tqp_num = ch->combined_count;
+   u16 org_tqp_num;
+   int ret;
+
+   if (ch->rx_count || ch->tx_count)
+   return -EINVAL;
+
+   if (new_tqp_num > hns3_get_max_available_channels(netdev) ||
+   new_tqp_num < kinfo->num_tc) {
+   dev_err(&netdev->dev,
+   "Change tqps fail, the tqp range is from %d to %d",
+   kinfo->num_tc,
+   hns3_get_max_available_channels(netdev));
+   return -EINVAL;
+   }
+
+   new_tqp_num = hns3_adjust_tqps_num(kinfo->num_tc, new_tqp_num);
+   if (kinfo->num_tqps == new_tqp_num)
+   return 0;
+
+   if (if_running)
+   dev_close(netdev);
+
+   hns3_clear_all_ring(h);
+
+   ret = hns3_nic_uninit_vector_data(priv);
+   if (ret) {
+   dev_err(&netdev->dev,
+   "Unbind vector with tqp fail, nothing is changed");
+   goto open_netdev;
+   }
+
+   hns3_uninit_all_ring(priv);
+
+   org_tqp_num = h->

[PATCH V4 net-next 11/17] net: hns3: fix for getting auto-negotiation state in hclge_get_autoneg

2017-12-20 Thread Lipeng
From: Fuyun Liang 

When phy exists, we use the value of phydev.autoneg to represent the
auto-negotiation state of hardware. Otherwise, we use the value of
mac.autoneg to represent it.

This patch fixes for getting a error value of auto-negotiation state in
hclge_get_autoneg().

Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support")
Signed-off-by: Fuyun Liang 
Signed-off-by: Lipeng 
---
 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 046f4bb..14e1054 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2172,6 +2172,10 @@ static int hclge_get_autoneg(struct hnae3_handle *handle)
 {
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+
+   if (phydev)
+   return phydev->autoneg;
 
return hdev->hw.mac.autoneg;
 }
-- 
1.9.1



[PATCH V4 net-next 13/17] net: hns3: add support to update flow control settings after autoneg

2017-12-20 Thread Lipeng
When auto-negotiation is enabled, the MAC flow control settings is
based on the flow control negotiation result. And it should be configured
after a valid link has been established. This patch adds support to update
flow control settings after auto-negotiation has completed.

Signed-off-by: Lipeng 
Signed-off-by: Fuyun Liang 
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 36 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c|  4 +++
 3 files changed, 41 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 0f55ee6..bb31212 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4707,6 +4707,42 @@ static int hclge_cfg_pauseparam(struct hclge_dev *hdev, 
u32 rx_en, u32 tx_en)
return 0;
 }
 
+int hclge_cfg_flowctrl(struct hclge_dev *hdev)
+{
+   struct phy_device *phydev = hdev->hw.mac.phydev;
+   u16 remote_advertising = 0;
+   u16 local_advertising = 0;
+   u32 rx_pause, tx_pause;
+   u8 flowctl;
+
+   if (!phydev->link || !phydev->autoneg)
+   return 0;
+
+   if (phydev->advertising & ADVERTISED_Pause)
+   local_advertising = ADVERTISE_PAUSE_CAP;
+
+   if (phydev->advertising & ADVERTISED_Asym_Pause)
+   local_advertising |= ADVERTISE_PAUSE_ASYM;
+
+   if (phydev->pause)
+   remote_advertising = LPA_PAUSE_CAP;
+
+   if (phydev->asym_pause)
+   remote_advertising |= LPA_PAUSE_ASYM;
+
+   flowctl = mii_resolve_flowctrl_fdx(local_advertising,
+  remote_advertising);
+   tx_pause = flowctl & FLOW_CTRL_TX;
+   rx_pause = flowctl & FLOW_CTRL_RX;
+
+   if (phydev->duplex == HCLGE_MAC_HALF) {
+   tx_pause = 0;
+   rx_pause = 0;
+   }
+
+   return hclge_cfg_pauseparam(hdev, rx_pause, tx_pause);
+}
+
 static void hclge_get_pauseparam(struct hnae3_handle *handle, u32 *auto_neg,
 u32 *rx_en, u32 *tx_en)
 {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
index cda520c..28cc063 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
@@ -602,4 +602,5 @@ int hclge_set_vf_vlan_common(struct hclge_dev *vport, int 
vfid,
 
 void hclge_mbx_handler(struct hclge_dev *hdev);
 void hclge_reset_tqp(struct hnae3_handle *handle, u16 queue_id);
+int hclge_cfg_flowctrl(struct hclge_dev *hdev);
 #endif
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
index 7069e94..3745153 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c
@@ -183,6 +183,10 @@ static void hclge_mac_adjust_link(struct net_device 
*netdev)
ret = hclge_cfg_mac_speed_dup(hdev, speed, duplex);
if (ret)
netdev_err(netdev, "failed to adjust link.\n");
+
+   ret = hclge_cfg_flowctrl(hdev);
+   if (ret)
+   netdev_err(netdev, "failed to configure flow control.\n");
 }
 
 int hclge_mac_start_phy(struct hclge_dev *hdev)
-- 
1.9.1



[PATCH V4 net-next 08/17] net: hns3: add ethtool related offload command

2017-12-20 Thread Lipeng
This patch adds offload command related to "ethtool -K".

Signed-off-by: Lipeng 
Signed-off-by: Jian Shen 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h |  3 +++
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 16 
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 13 +
 3 files changed, 32 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index a5d3d22..a67d02a9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -278,6 +278,8 @@ struct hnae3_ae_dev {
  *   Set vlan filter config of Ports
  * set_vf_vlan_filter()
  *   Set vlan filter config of vf
+ * enable_hw_strip_rxvtag()
+ *   Enable/disable hardware strip vlan tag of packets received
  */
 struct hnae3_ae_ops {
int (*init_ae_dev)(struct hnae3_ae_dev *ae_dev);
@@ -384,6 +386,7 @@ struct hnae3_ae_ops {
   u16 vlan_id, bool is_kill);
int (*set_vf_vlan_filter)(struct hnae3_handle *handle, int vfid,
  u16 vlan, u8 qos, __be16 proto);
+   int (*enable_hw_strip_rxvtag)(struct hnae3_handle *handle, bool enable);
void (*reset_event)(struct hnae3_handle *handle,
enum hnae3_reset_type reset);
void (*get_channels)(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 1c93038..301b329 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1032,6 +1032,9 @@ static int hns3_nic_set_features(struct net_device 
*netdev,
 netdev_features_t features)
 {
struct hns3_nic_priv *priv = netdev_priv(netdev);
+   struct hnae3_handle *h = priv->ae_handle;
+   netdev_features_t changed;
+   int ret;
 
if (features & (NETIF_F_TSO | NETIF_F_TSO6)) {
priv->ops.fill_desc = hns3_fill_desc_tso;
@@ -1041,6 +1044,17 @@ static int hns3_nic_set_features(struct net_device 
*netdev,
priv->ops.maybe_stop_tx = hns3_nic_maybe_stop_tx;
}
 
+   changed = netdev->features ^ features;
+   if (changed & NETIF_F_HW_VLAN_CTAG_RX) {
+   if (features & NETIF_F_HW_VLAN_CTAG_RX)
+   ret = h->ae_algo->ops->enable_hw_strip_rxvtag(h, true);
+   else
+   ret = h->ae_algo->ops->enable_hw_strip_rxvtag(h, false);
+
+   if (ret)
+   return ret;
+   }
+
netdev->features = features;
return 0;
 }
@@ -1492,6 +1506,7 @@ static void hns3_set_default_feature(struct net_device 
*netdev)
 
netdev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
NETIF_F_HW_VLAN_CTAG_FILTER |
+   NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_GSO |
NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_GRE |
NETIF_F_GSO_GRE_CSUM | NETIF_F_GSO_UDP_TUNNEL |
@@ -1506,6 +1521,7 @@ static void hns3_set_default_feature(struct net_device 
*netdev)
 
netdev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
NETIF_F_HW_VLAN_CTAG_FILTER |
+   NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
NETIF_F_RXCSUM | NETIF_F_SG | NETIF_F_GSO |
NETIF_F_GRO | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_GSO_GRE |
NETIF_F_GSO_GRE_CSUM | NETIF_F_GSO_UDP_TUNNEL |
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 113b859..d77a6de 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4547,6 +4547,18 @@ static int hclge_init_vlan_config(struct hclge_dev *hdev)
return hclge_set_port_vlan_filter(handle, htons(ETH_P_8021Q), 0, false);
 }
 
+static int hclge_en_hw_strip_rxvtag(struct hnae3_handle *handle, bool enable)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+
+   vport->rxvlan_cfg.strip_tag1_en = false;
+   vport->rxvlan_cfg.strip_tag2_en = enable;
+   vport->rxvlan_cfg.vlan1_vlan_prionly = false;
+   vport->rxvlan_cfg.vlan2_vlan_prionly = false;
+
+   return hclge_set_vlan_rx_offload_cfg(vport);
+}
+
 static int hclge_set_mtu(struct hnae3_handle *handle, int new_mtu)
 {
struct hclge_vport *vport = hclge_get_vport(handle);
@@ -5362,6 +5374,7 @@ static int hclge_set_channels(struct hnae3_handle 
*handle, u32 new_tqps_num)
.get_mdix_mode = hclge_get_mdix_mode,
.set_vlan_filter = hclge_set_port_vlan_filter,
.set_vf_vlan_filter = hclge_set_vf_vlan_filter,
+  

[PATCH V4 net-next 01/17] net: hns3: add support to query tqps number

2017-12-20 Thread Lipeng
This patch adds the support to query tqps number for PF driver
by using ehtool -l command.

Signed-off-by: Lipeng 
Signed-off-by: Mingguang Qu 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h |  2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c  | 10 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 21 +
 3 files changed, 33 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index a9e2b32..d887721 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -386,6 +386,8 @@ struct hnae3_ae_ops {
  u16 vlan, u8 qos, __be16 proto);
void (*reset_event)(struct hnae3_handle *handle,
enum hnae3_reset_type reset);
+   void (*get_channels)(struct hnae3_handle *handle,
+struct ethtool_channels *ch);
 };
 
 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 65a69b4..23af36c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
@@ -849,6 +849,15 @@ static int hns3_nway_reset(struct net_device *netdev)
return genphy_restart_aneg(phy);
 }
 
+void hns3_get_channels(struct net_device *netdev,
+  struct ethtool_channels *ch)
+{
+   struct hnae3_handle *h = hns3_get_handle(netdev);
+
+   if (h->ae_algo->ops->get_channels)
+   h->ae_algo->ops->get_channels(h, ch);
+}
+
 static const struct ethtool_ops hns3vf_ethtool_ops = {
.get_drvinfo = hns3_get_drvinfo,
.get_ringparam = hns3_get_ringparam,
@@ -883,6 +892,7 @@ static int hns3_nway_reset(struct net_device *netdev)
.get_link_ksettings = hns3_get_link_ksettings,
.set_link_ksettings = hns3_set_link_ksettings,
.nway_reset = hns3_nway_reset,
+   .get_channels = hns3_get_channels,
 };
 
 void hns3_ethtool_set_ops(struct net_device *netdev)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index e97fd66..a3101bc 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -5002,6 +5002,26 @@ static void hclge_uninit_ae_dev(struct hnae3_ae_dev 
*ae_dev)
ae_dev->priv = NULL;
 }
 
+static u32 hclge_get_max_channels(struct hnae3_handle *handle)
+{
+   struct hnae3_knic_private_info *kinfo = &handle->kinfo;
+   struct hclge_vport *vport = hclge_get_vport(handle);
+   struct hclge_dev *hdev = vport->back;
+
+   return min_t(u32, hdev->rss_size_max * kinfo->num_tc, hdev->num_tqps);
+}
+
+static void hclge_get_channels(struct hnae3_handle *handle,
+  struct ethtool_channels *ch)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+
+   ch->max_combined = hclge_get_max_channels(handle);
+   ch->other_count = 1;
+   ch->max_other = 1;
+   ch->combined_count = vport->alloc_tqps;
+}
+
 static const struct hnae3_ae_ops hclge_ops = {
.init_ae_dev = hclge_init_ae_dev,
.uninit_ae_dev = hclge_uninit_ae_dev,
@@ -5046,6 +5066,7 @@ static void hclge_uninit_ae_dev(struct hnae3_ae_dev 
*ae_dev)
.set_vlan_filter = hclge_set_port_vlan_filter,
.set_vf_vlan_filter = hclge_set_vf_vlan_filter,
.reset_event = hclge_reset_event,
+   .get_channels = hclge_get_channels,
 };
 
 static struct hnae3_ae_algo ae_algo = {
-- 
1.9.1



[PATCH V4 net-next 00/17] add some features and fix some bugs for HNS3 driver

2017-12-20 Thread Lipeng
This patchset adds some new feature support and fixes some bugs:
[Patch 1/17 - 5/17] add the support to modify/query the tqp number
through ethtool -L/l command, and also fix some related bugs for
change tqp number.
[Patch 6/17 - 9-17] add support vlan tag offload on tx&&rx direction
for pf, and fix some related bugs.
[patch 10/17 - 11/17] fix bugs for auto negotiation.
[patch 12/17] adds support for ethtool command set_pauseparam.
[patch 13/17 - 14/17] add support to update flow control settings after
autoneg.
[patch 15/17 - 17/17] fix some other bugs in net-next.

---
Change Log:
V3 -> V4:
1, Change the name spelling of Mingguang Qu and Jian Shen.

V2 -> V3:
1, order local variables requested by David Miller.
2, use "int" for index iteration loops requested by David Miller.

V1 -> V2:
1, fix the comments from Sergei Shtylyov.
---

Fuyun Liang (3):
  net: hns3: cleanup mac auto-negotiation state query
  net: hns3: fix for getting auto-negotiation state in hclge_get_autoneg
  net: hns3: add Asym Pause support to phy default features

Lipeng (14):
  net: hns3: add support to query tqps number
  net: hns3: add support to modify tqps number
  net: hns3: change the returned tqp number by ethtool -x
  net: hns3: free the ring_data structrue when change tqps
  net: hns3: get rss_size_max from configuration but not hardcode
  net: hns3: add a mask initialization for mac_vlan table
  net: hns3: add vlan offload config command
  net: hns3: add ethtool related offload command
  net: hns3: add handling vlan tag offload in bd
  net: hns3: add support for set_pauseparam
  net: hns3: add support to update flow control settings after autoneg
  net: hns3: add support for querying advertised pause frame by ethtool
ethx
  net: hns3: Increase the default depth of bucket for TM shaper
  net: hns3: change TM sched mode to TC-based mode when SRIOV enabled

 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  10 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 225 -
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|   2 +
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c |  41 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  57 +++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 514 +++--
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  38 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c|   5 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  |   6 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |   1 +
 10 files changed, 855 insertions(+), 44 deletions(-)

-- 
1.9.1



[PATCH net-next 1/5] net: hns3: fixes the ring index in hns3_fini_ring

2017-10-10 Thread Lipeng
This patch fixes the ring index in hns3_fini_ring.

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

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
index 26bbc91..acb82cf 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
@@ -2661,7 +2661,7 @@ static int hns3_init_all_ring(struct hns3_nic_priv *priv)
 
 out_when_alloc_ring_memory:
for (j = i - 1; j >= 0; j--)
-   hns3_fini_ring(priv->ring_data[i].ring);
+   hns3_fini_ring(priv->ring_data[j].ring);
 
return -ENOMEM;
 }
-- 
1.9.1



[PATCH net-next 0/5] Support set_ringparam and {set|get}_rxnfc ethtool commands

2017-10-10 Thread Lipeng
1, Patch [1/5,2/5] add support for ethtool ops set_ringparam
   (ethtool -G) and fix related bug.
2, Patch [3/5,4/5, 5/5] add support for ethtool ops
   set_rxnfc/get_rxnfc (-n/-N) and fix related bug. 

Lipeng (5):
  net: hns3: fixes the ring index in hns3_fini_ring
  net: hns3: add support for set_ringparam
  net: hns3: add support for set_rxnfc
  net: hns3: add support for ETHTOOL_GRXFH
  net: hns3: fix the ring count for ETHTOOL_GRXRINGS

 drivers/net/ethernet/hisilicon/hns3/hnae3.h|   4 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c |   9 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |   1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 159 -
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|   8 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c |   6 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h |   4 +
 .../ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c  |  95 +++-
 8 files changed, 280 insertions(+), 6 deletions(-)

-- 
1.9.1



[PATCH net-next 3/5] net: hns3: add support for set_rxnfc

2017-10-10 Thread Lipeng
This patch supports the ethtool's set_rxnfc().

Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  2 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c |  9 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 95 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  8 ++
 .../ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c  | 16 
 6 files changed, 129 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index c677530..d952d62 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -339,6 +339,8 @@ struct hnae3_ae_ops {
   u8 *hfunc);
int (*set_rss)(struct hnae3_handle *handle, const u32 *indir,
   const u8 *key, const u8 hfunc);
+   int (*set_rss_tuple)(struct hnae3_handle *handle,
+struct ethtool_rxnfc *cmd);
 
int (*get_tc_size)(struct hnae3_handle *handle);
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
index 8ecd807..60960e5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
@@ -85,6 +85,15 @@ static int hclge_init_cmd_queue(struct hclge_dev *hdev, int 
ring_type)
return 0;
 }
 
+void hclge_cmd_reuse_desc(struct hclge_desc *desc, bool is_read)
+{
+   desc->flag = cpu_to_le16(HCLGE_CMD_FLAG_NO_INTR | HCLGE_CMD_FLAG_IN);
+   if (is_read)
+   desc->flag |= cpu_to_le16(HCLGE_CMD_FLAG_WR);
+   else
+   desc->flag &= cpu_to_le16(~HCLGE_CMD_FLAG_WR);
+}
+
 void hclge_cmd_setup_basic_desc(struct hclge_desc *desc,
enum hclge_opcode_type opcode, bool is_read)
 {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 8f3ba02a..b437334 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -739,6 +739,7 @@ static inline u32 hclge_read_reg(u8 __iomem *base, u32 reg)
 int hclge_cmd_send(struct hclge_hw *hw, struct hclge_desc *desc, int num);
 void hclge_cmd_setup_basic_desc(struct hclge_desc *desc,
enum hclge_opcode_type opcode, bool is_read);
+void hclge_cmd_reuse_desc(struct hclge_desc *desc, bool is_read);
 
 int hclge_cmd_set_promisc_mode(struct hclge_dev *hdev,
   struct hclge_promisc_param *param);
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index c91c779..5b5e52c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2595,8 +2595,6 @@ static int hclge_set_rss_tc_mode(struct hclge_dev *hdev, 
u16 *tc_valid,
 
 static int hclge_set_rss_input_tuple(struct hclge_dev *hdev)
 {
-#define HCLGE_RSS_INPUT_TUPLE_OTHER0xf
-#define HCLGE_RSS_INPUT_TUPLE_SCTP 0x1f
struct hclge_rss_input_tuple_cmd *req;
struct hclge_desc desc;
int ret;
@@ -2677,6 +2675,98 @@ static int hclge_set_rss(struct hnae3_handle *handle, 
const u32 *indir,
return ret;
 }
 
+static u8 hclge_get_rss_hash_bits(struct ethtool_rxnfc *nfc)
+{
+   u8 hash_sets = nfc->data & RXH_L4_B_0_1 ? HCLGE_S_PORT_BIT : 0;
+
+   if (nfc->data & RXH_L4_B_2_3)
+   hash_sets |= HCLGE_D_PORT_BIT;
+   else
+   hash_sets &= ~HCLGE_D_PORT_BIT;
+
+   if (nfc->data & RXH_IP_SRC)
+   hash_sets |= HCLGE_S_IP_BIT;
+   else
+   hash_sets &= ~HCLGE_S_IP_BIT;
+
+   if (nfc->data & RXH_IP_DST)
+   hash_sets |= HCLGE_D_IP_BIT;
+   else
+   hash_sets &= ~HCLGE_D_IP_BIT;
+
+   if (nfc->flow_type == SCTP_V4_FLOW || nfc->flow_type == SCTP_V6_FLOW)
+   hash_sets |= HCLGE_V_TAG_BIT;
+
+   return hash_sets;
+}
+
+static int hclge_set_rss_tuple(struct hnae3_handle *handle,
+  struct ethtool_rxnfc *nfc)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+   struct hclge_dev *hdev = vport->back;
+   struct hclge_rss_input_tuple_cmd *req;
+   struct hclge_desc desc;
+   u8 tuple_sets;
+   int ret;
+
+   if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
+ RXH_L4_B_0_1 | RXH_L4_B_2_3))
+   return -EINVAL;
+
+   req = (struct hclge_rss_input_tuple_cmd *)desc.data;
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_RSS_INPUT_TUPLE, true);
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if 

[PATCH net-next 5/5] net: hns3: fix the ring count for ETHTOOL_GRXRINGS

2017-10-10 Thread Lipeng
This patch fix the ring count for ETHTOOL_GRXRINGS. Ring count
not TC size should be return for command "ethtool -n ethx".

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

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
index b64fbd3..9b36ce0 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
@@ -450,7 +450,7 @@ static int hns3_get_rxnfc(struct net_device *netdev,
 
switch (cmd->cmd) {
case ETHTOOL_GRXRINGS:
-   cmd->data = h->ae_algo->ops->get_tc_size(h);
+   cmd->data = h->kinfo.num_tc * h->kinfo.rss_size;
break;
case ETHTOOL_GRXFH:
return h->ae_algo->ops->get_rss_tuple(h, cmd);
-- 
1.9.1



[PATCH net-next 2/5] net: hns3: add support for set_ringparam

2017-10-10 Thread Lipeng
This patch supports the ethtool's set_ringparam().

Signed-off-by: Lipeng 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c |  4 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h |  4 ++
 .../ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c  | 75 ++
 3 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
index acb82cf..ba550c1 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
@@ -2637,7 +2637,7 @@ static void hns3_init_ring_hw(struct hns3_enet_ring *ring)
}
 }
 
-static int hns3_init_all_ring(struct hns3_nic_priv *priv)
+int hns3_init_all_ring(struct hns3_nic_priv *priv)
 {
struct hnae3_handle *h = priv->ae_handle;
int ring_num = h->kinfo.num_tqps * 2;
@@ -2666,7 +2666,7 @@ static int hns3_init_all_ring(struct hns3_nic_priv *priv)
return -ENOMEM;
 }
 
-static int hns3_uninit_all_ring(struct hns3_nic_priv *priv)
+int hns3_uninit_all_ring(struct hns3_nic_priv *priv)
 {
struct hnae3_handle *h = priv->ae_handle;
int i;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h
index dd8d40c..6659989 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h
@@ -76,6 +76,8 @@ enum hns3_nic_state {
 #define HNS3_RING_NAME_LEN 16
 #define HNS3_BUFFER_SIZE_2048  2048
 #define HNS3_RING_MAX_PENDING  32768
+#define HNS3_RING_MIN_PENDING  8
+#define HNS3_RING_BD_MULTIPLE  8
 #define HNS3_MAX_MTU   9728
 
 #define HNS3_BD_SIZE_512_TYPE  0
@@ -593,6 +595,8 @@ static inline void hns3_write_reg(void __iomem *base, u32 
reg, u32 value)
 void hns3_ethtool_set_ops(struct net_device *netdev);
 
 int hns3_clean_tx_ring(struct hns3_enet_ring *ring, int budget);
+int hns3_init_all_ring(struct hns3_nic_priv *priv);
+int hns3_uninit_all_ring(struct hns3_nic_priv *priv);
 
 #ifdef CONFIG_HNS3_DCB
 void hns3_dcbnl_setup(struct hnae3_handle *handle);
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
index 060bace..1c5d003 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
@@ -459,10 +459,85 @@ static int hns3_get_rxnfc(struct net_device *netdev,
return 0;
 }
 
+int hns3_change_all_ring_bd_num(struct hns3_nic_priv *priv, u32 new_desc_num)
+{
+   struct hnae3_handle *h = priv->ae_handle;
+   int i;
+
+   h->kinfo.num_desc = new_desc_num;
+
+   for (i = 0; i < h->kinfo.num_tqps * 2; i++)
+   priv->ring_data[i].ring->desc_num = new_desc_num;
+
+   return hns3_init_all_ring(priv);
+}
+
+int hns3_set_ringparam(struct net_device *ndev, struct ethtool_ringparam 
*param)
+{
+   struct hns3_nic_priv *priv = netdev_priv(ndev);
+   struct hnae3_handle *h = priv->ae_handle;
+   bool if_running = netif_running(ndev);
+   u32 old_desc_num, new_desc_num;
+   int ret;
+
+   if (param->rx_mini_pending || param->rx_jumbo_pending)
+   return -EINVAL;
+
+   if (param->tx_pending != param->rx_pending) {
+   netdev_err(ndev,
+  "Descriptors of tx and rx must be equal");
+   return -EINVAL;
+   }
+
+   if (param->tx_pending > HNS3_RING_MAX_PENDING ||
+   param->tx_pending < HNS3_RING_MIN_PENDING) {
+   netdev_err(ndev,
+  "Descriptors requested (Tx/Rx: %d) out of range 
[%d-%d]\n",
+  param->tx_pending, HNS3_RING_MIN_PENDING,
+  HNS3_RING_MAX_PENDING);
+   return -EINVAL;
+   }
+
+   new_desc_num = param->tx_pending;
+
+   /* Hardware requires that its descriptors must be multiple of eight */
+   new_desc_num = ALIGN(new_desc_num, HNS3_RING_BD_MULTIPLE);
+   old_desc_num = h->kinfo.num_desc;
+   if (old_desc_num == new_desc_num)
+   return 0;
+
+   netdev_info(ndev,
+   "Changing descriptor count from %d to %d.\n",
+   old_desc_num, new_desc_num);
+
+   if (if_running)
+   dev_close(ndev);
+
+   ret = hns3_uninit_all_ring(priv);
+   if (ret)
+   return ret;
+
+   ret = hns3_change_all_ring_bd_num(priv, new_desc_num);
+   if (ret) {
+   ret = hns3_change_all_ring_bd_num(priv, old_desc_num);
+   if (ret) {
+   netdev_err(ndev,
+

[PATCH net-next 4/5] net: hns3: add support for ETHTOOL_GRXFH

2017-10-10 Thread Lipeng
This patch add support for ethtool's ETHTOOL_GRXFH in hns3_get_rxnfc().

Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  2 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 64 ++
 .../ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c  |  2 +
 3 files changed, 68 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index d952d62..575f50d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -341,6 +341,8 @@ struct hnae3_ae_ops {
   const u8 *key, const u8 hfunc);
int (*set_rss_tuple)(struct hnae3_handle *handle,
 struct ethtool_rxnfc *cmd);
+   int (*get_rss_tuple)(struct hnae3_handle *handle,
+struct ethtool_rxnfc *cmd);
 
int (*get_tc_size)(struct hnae3_handle *handle);
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 5b5e52c..c322b45 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2767,6 +2767,69 @@ static int hclge_set_rss_tuple(struct hnae3_handle 
*handle,
return ret;
 }
 
+static int hclge_get_rss_tuple(struct hnae3_handle *handle,
+  struct ethtool_rxnfc *nfc)
+{
+   struct hclge_vport *vport = hclge_get_vport(handle);
+   struct hclge_dev *hdev = vport->back;
+   struct hclge_rss_input_tuple_cmd *req;
+   struct hclge_desc desc;
+   u8 tuple_sets;
+   int ret;
+
+   nfc->data = 0;
+
+   req = (struct hclge_rss_input_tuple_cmd *)desc.data;
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_RSS_INPUT_TUPLE, true);
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret) {
+   dev_err(&hdev->pdev->dev,
+   "Read rss tuple fail, status = %d\n", ret);
+   return ret;
+   }
+
+   switch (nfc->flow_type) {
+   case TCP_V4_FLOW:
+   tuple_sets = req->ipv4_tcp_en;
+   break;
+   case UDP_V4_FLOW:
+   tuple_sets = req->ipv4_udp_en;
+   break;
+   case TCP_V6_FLOW:
+   tuple_sets = req->ipv6_tcp_en;
+   break;
+   case UDP_V6_FLOW:
+   tuple_sets = req->ipv6_udp_en;
+   break;
+   case SCTP_V4_FLOW:
+   tuple_sets = req->ipv4_sctp_en;
+   break;
+   case SCTP_V6_FLOW:
+   tuple_sets = req->ipv6_sctp_en;
+   break;
+   case IPV4_FLOW:
+   case IPV6_FLOW:
+   tuple_sets = HCLGE_S_IP_BIT | HCLGE_D_IP_BIT;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   if (!tuple_sets)
+   return 0;
+
+   if (tuple_sets & HCLGE_D_PORT_BIT)
+   nfc->data |= RXH_L4_B_2_3;
+   if (tuple_sets & HCLGE_S_PORT_BIT)
+   nfc->data |= RXH_L4_B_0_1;
+   if (tuple_sets & HCLGE_D_IP_BIT)
+   nfc->data |= RXH_IP_DST;
+   if (tuple_sets & HCLGE_S_IP_BIT)
+   nfc->data |= RXH_IP_SRC;
+
+   return 0;
+}
+
 static int hclge_get_tc_size(struct hnae3_handle *handle)
 {
struct hclge_vport *vport = hclge_get_vport(handle);
@@ -4435,6 +4498,7 @@ static void hclge_uninit_ae_dev(struct hnae3_ae_dev 
*ae_dev)
.get_rss = hclge_get_rss,
.set_rss = hclge_set_rss,
.set_rss_tuple = hclge_set_rss_tuple,
+   .get_rss_tuple = hclge_get_rss_tuple,
.get_tc_size = hclge_get_tc_size,
.get_mac_addr = hclge_get_mac_addr,
.set_mac_addr = hclge_set_mac_addr,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
index f0e88e0..b64fbd3 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
@@ -452,6 +452,8 @@ static int hns3_get_rxnfc(struct net_device *netdev,
case ETHTOOL_GRXRINGS:
cmd->data = h->ae_algo->ops->get_tc_size(h);
break;
+   case ETHTOOL_GRXFH:
+   return h->ae_algo->ops->get_rss_tuple(h, cmd);
default:
return -EOPNOTSUPP;
}
-- 
1.9.1



[PATCH net-next 2/7] net: hns3: fix the bug when map buffer fail

2017-10-23 Thread Lipeng
If one buffer had been recieved to stack, driver will alloc a new buffer,
map the buffer to device and replace the old buffer. When map fail, should
only free the new alloced buffer, but not free all buffers in the ring.

Fixes: 76ad4f0 (net: hns3: Add support of HNS3 Ethernet Driver for hip08 SoC)

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

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
index 3ddcd47..58aa2dd 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
@@ -1555,7 +1555,7 @@ static int hns3_reserve_buffer_map(struct hns3_enet_ring 
*ring,
return 0;
 
 out_with_buf:
-   hns3_free_buffers(ring);
+   hns3_free_buffer(ring, cb);
 out:
return ret;
 }
-- 
1.9.1



[PATCH net-next 7/7] net: hns3: fix a bug about hns3_clean_tx_ring

2017-10-23 Thread Lipeng
The return value of hns3_clean_tx_ring means tx ring clean result.
Return true means clean complete and there is no more pakcet need
clean. Retrun false means there is packets need clean and napi need
poll again. The last return of hns3_clean_tx_ring is
"return !!budget" as budget will decrease when clean a buffer.

If there is no valid BD in TX ring, return 0 for hns3_clean_tx_ring
will cause napi poll again and never complete the napi poll. This
patch fixes the bug.

Fixes: 76ad4f0 (net: hns3: Add support of HNS3 Ethernet Driver for hip08 SoC)

Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c | 6 +++---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
index 06af3c8..537f6c3 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
@@ -1629,7 +1629,7 @@ static int is_valid_clean_head(struct hns3_enet_ring 
*ring, int h)
return u > c ? (h > c && h <= u) : (h > c || h <= u);
 }
 
-int hns3_clean_tx_ring(struct hns3_enet_ring *ring, int budget)
+bool hns3_clean_tx_ring(struct hns3_enet_ring *ring, int budget)
 {
struct net_device *netdev = ring->tqp->handle->kinfo.netdev;
struct netdev_queue *dev_queue;
@@ -1640,7 +1640,7 @@ int hns3_clean_tx_ring(struct hns3_enet_ring *ring, int 
budget)
rmb(); /* Make sure head is ready before touch any data */
 
if (is_ring_empty(ring) || head == ring->next_to_clean)
-   return 0; /* no data to poll */
+   return true; /* no data to poll */
 
if (!is_valid_clean_head(ring, head)) {
netdev_err(netdev, "wrong head (%d, %d-%d)\n", head,
@@ -1649,7 +1649,7 @@ int hns3_clean_tx_ring(struct hns3_enet_ring *ring, int 
budget)
u64_stats_update_begin(&ring->syncp);
ring->stats.io_err_cnt++;
u64_stats_update_end(&ring->syncp);
-   return -EIO;
+   return true;
}
 
bytes = 0;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h
index 6228b26..58dc30b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h
@@ -594,7 +594,7 @@ static inline void hns3_write_reg(void __iomem *base, u32 
reg, u32 value)
 
 void hns3_ethtool_set_ops(struct net_device *netdev);
 
-int hns3_clean_tx_ring(struct hns3_enet_ring *ring, int budget);
+bool hns3_clean_tx_ring(struct hns3_enet_ring *ring, int budget);
 int hns3_init_all_ring(struct hns3_nic_priv *priv);
 int hns3_uninit_all_ring(struct hns3_nic_priv *priv);
 netdev_tx_t hns3_nic_net_xmit(struct sk_buff *skb, struct net_device *netdev);
-- 
1.9.1



[PATCH net-next 1/7] net: hns3: fix a bug when alloc new buffer

2017-10-23 Thread Lipeng
When alloce new buffer to HW, should unmap the old buffer first.
This old code map the old buffer but not unmap the old buffer,
this patch fixes it.

Fixes: 76ad4f0 (net: hns3: Add support of HNS3 Ethernet Driver for hip08 SoC)

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

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
index 8383d67..3ddcd47 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
@@ -1595,7 +1595,7 @@ static int hns3_alloc_ring_buffers(struct hns3_enet_ring 
*ring)
 static void hns3_replace_buffer(struct hns3_enet_ring *ring, int i,
struct hns3_desc_cb *res_cb)
 {
-   hns3_map_buffer(ring, &ring->desc_cb[i]);
+   hns3_unmap_buffer(ring, &ring->desc_cb[i]);
ring->desc_cb[i] = *res_cb;
ring->desc[i].addr = cpu_to_le64(ring->desc_cb[i].dma);
 }
-- 
1.9.1



[PATCH net-next 6/7] net: hns3: remove redundant memset when alloc buffer

2017-10-23 Thread Lipeng
HW will use packet length to write packets to buffer or read
packets from buffer. There is a redundant memset when alloc buffer,
the memset have no sense and will increase time-consuming.
This patch removes it.

Fixes: 76ad4f0 (net: hns3: Add support of HNS3 Ethernet Driver for hip08 SoC)

Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
index 14de0f7..06af3c8 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
@@ -1444,8 +1444,6 @@ static int hns3_alloc_buffer(struct hns3_enet_ring *ring,
cb->length = hnae_page_size(ring);
cb->type = DESC_TYPE_PAGE;
 
-   memset(cb->buf, 0, cb->length);
-
return 0;
 }
 
-- 
1.9.1



[PATCH net-next 5/7] net: hns3: fix the TX/RX ring.queue_index in hns3_ring_get_cfg

2017-10-23 Thread Lipeng
The interface hns3_ring_get_cfg only update TX ring queue_index,
but do not update RX ring queue_index. This patch fixes it.

Fixes: 76ad4f0 (net: hns3: Add support of HNS3 Ethernet Driver for hip08 SoC)

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

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
index 58aa2dd..14de0f7 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
@@ -2506,16 +2506,16 @@ static int hns3_ring_get_cfg(struct hnae3_queue *q, 
struct hns3_nic_priv *priv,
 
if (ring_type == HNAE3_RING_TYPE_TX) {
ring_data[q->tqp_index].ring = ring;
+   ring_data[q->tqp_index].queue_index = q->tqp_index;
ring->io_base = (u8 __iomem *)q->io_base + HNS3_TX_REG_OFFSET;
} else {
ring_data[q->tqp_index + queue_num].ring = ring;
+   ring_data[q->tqp_index + queue_num].queue_index = q->tqp_index;
ring->io_base = q->io_base;
}
 
hnae_set_bit(ring->flag, HNAE3_RING_TYPE_B, ring_type);
 
-   ring_data[q->tqp_index].queue_index = q->tqp_index;
-
ring->tqp = q;
ring->desc = NULL;
ring->desc_cb = NULL;
-- 
1.9.1



[PATCH net-next 3/7] net: hns3: fix the ops check in hns3_get_rxnfc

2017-10-23 Thread Lipeng
1# patch: 07d2995 net: hns3: add support for ETHTOOL_GRXFH.
2# patch: 5668abd net: hns3: add support for set_ringparam.

1# patch adds ae_algo->ops->get_rss_tuple to hns3_get_rxnfc
and 2# patch delete ae_algo->ops->get_tc_size
from hns3_get_rxnfc.This patch fix the ops check in hns3_get_rxnfc.

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

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
index 6c469e4..5cd163b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c
@@ -717,7 +717,7 @@ static int hns3_get_rxnfc(struct net_device *netdev,
 {
struct hnae3_handle *h = hns3_get_handle(netdev);
 
-   if (!h->ae_algo || !h->ae_algo->ops || !h->ae_algo->ops->get_tc_size)
+   if (!h->ae_algo || !h->ae_algo->ops || !h->ae_algo->ops->get_rss_tuple)
return -EOPNOTSUPP;
 
switch (cmd->cmd) {
-- 
1.9.1



[PATCH net-next 4/7] net: hns3: get vf count by pci_sriov_get_totalvfs

2017-10-23 Thread Lipeng
This patch gets vf count by standard function pci_sriov_get_totalvfs,
instead of info from NIC HW.

Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 3 ++-
 1 file changed, 2 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 8508521..4431241 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -837,7 +837,6 @@ static int hclge_parse_func_status(struct hclge_dev *hdev,
else
hdev->flag &= ~HCLGE_FLAG_MAIN;
 
-   hdev->num_req_vfs = status->vf_num / status->pf_num;
return 0;
 }
 
@@ -4361,6 +4360,8 @@ static int hclge_pci_init(struct hclge_dev *hdev)
goto err_clr_master;
}
 
+   hdev->num_req_vfs = pci_sriov_get_totalvfs(pdev);
+
return 0;
 err_clr_master:
pci_clear_master(pdev);
-- 
1.9.1



[PATCH net-next 0/7] net: hns3: bug fixes & code improvements

2017-10-23 Thread Lipeng
This patchset introduces various HNS3 bug fixes, optimizations and code
improvements.

Lipeng (7):
  net: hns3: fix a bug when alloc new buffer
  net: hns3: fix the bug when map buffer fail
  net: hns3: fix the ops check in hns3_get_rxnfc
  net: hns3: get vf count by pci_sriov_get_totalvfs
  net: hns3: fix the TX/RX ring.queue_index in hns3_ring_get_cfg
  net: hns3: remove redundant memset when alloc buffer
  net: hns3: fix a bug about hns3_clean_tx_ring

 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c  |  3 ++-
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c   | 16 +++-
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h   |  2 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hns3_ethtool.c|  2 +-
 4 files changed, 11 insertions(+), 12 deletions(-)

-- 
1.9.1



[PATCH net-next 4/4] net: hns3: fix the bug when reuse command description in hclge_add_mac_vlan_tbl

2017-10-24 Thread Lipeng
When reusing a command description read from HW, driver should set
IN_VLD bit, WR bit and NO_INTR bit. If IN_VLD bit and NO_INTR bit
are not set, the command fails and driver prints error message:

[  135.261284] hns3 :7d:00.0: cmdq execute failed for 
get_mac_vlan_cmd_status,status=2.
[  135.270983] hns3 :7d:00.0: add mac addr failed for cmd_send, ret =-5.

This patch fixes the bug.
Fixes: 46a3df9 (net: hns3: Add HNS3 Acceleration Engine & Compatibility Layer 
Support)

Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index d11a9a5..0b95fbe 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3600,11 +3600,11 @@ static int hclge_add_mac_vlan_tbl(struct hclge_vport 
*vport,
   resp_code,
   HCLGE_MAC_VLAN_ADD);
} else {
-   mc_desc[0].flag &= cpu_to_le16(~HCLGE_CMD_FLAG_WR);
+   hclge_cmd_reuse_desc(&mc_desc[0], false);
mc_desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
-   mc_desc[1].flag &= cpu_to_le16(~HCLGE_CMD_FLAG_WR);
+   hclge_cmd_reuse_desc(&mc_desc[1], false);
mc_desc[1].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
-   mc_desc[2].flag &= cpu_to_le16(~HCLGE_CMD_FLAG_WR);
+   hclge_cmd_reuse_desc(&mc_desc[2], false);
mc_desc[2].flag &= cpu_to_le16(~HCLGE_CMD_FLAG_NEXT);
memcpy(mc_desc[0].data, req,
   sizeof(struct hclge_mac_vlan_tbl_entry_cmd));
-- 
1.9.1



[PATCH net-next 3/4] net: hns3: fix a bug in hclge_uninit_client_instance

2017-10-24 Thread Lipeng
HNS3 driver initialize hdev->roce_client and vport->roce.client in
hclge_init_client_instance, and need set hdev->roce_client and
vport->roce.client NULL.

If do not set them NULL when uninit, it will fail in the scene:
insmod hns3.ko, hns-roce.ko, hns-roce-hw-v3.ko successfully, but
rmmod hns3.ko after rmmod hns-roce-hw-v2.ko and hns-roce.ko.
This patch fixes the issue.

Fixes: 46a3df9 (net: hns3: Add HNS3 Acceleration Engine & Compatibility Layer 
Support)

Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 10 --
 1 file changed, 8 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 2c22d3c..d11a9a5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4311,13 +4311,19 @@ static void hclge_uninit_client_instance(struct 
hnae3_client *client,
 
for (i = 0; i < hdev->num_vmdq_vport + 1; i++) {
vport = &hdev->vport[i];
-   if (hdev->roce_client)
+   if (hdev->roce_client) {
hdev->roce_client->ops->uninit_instance(&vport->roce,
0);
+   hdev->roce_client = NULL;
+   vport->roce.client = NULL;
+   }
if (client->type == HNAE3_CLIENT_ROCE)
return;
-   if (client->ops->uninit_instance)
+   if (client->ops->uninit_instance) {
client->ops->uninit_instance(&vport->nic, 0);
+   hdev->nic_client = NULL;
+   vport->nic.client = NULL;
+   }
}
 }
 
-- 
1.9.1



[PATCH net-next 2/4] net: hns3: add nic_client check when initialize roce base information

2017-10-24 Thread Lipeng
Roce driver works base on HNS3 driver.If insmod Roce driver before
NIC driver there is a error because do not check nic_client. This patch
adds nic_client check when initialize roce base information.

Fixes: 46a3df9 (net: hns3: Add HNS3 Acceleration Engine & Compatibility Layer 
Support)

Signed-off-by: Lipeng 
---
 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 4431241..2c22d3c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4285,7 +4285,7 @@ static int hclge_init_client_instance(struct hnae3_client 
*client,
vport->roce.client = client;
}
 
-   if (hdev->roce_client) {
+   if (hdev->roce_client && hdev->nic_client) {
ret = hclge_init_roce_base_info(vport);
if (ret)
goto err;
-- 
1.9.1



[PATCH net-next 0/4] net: hns3: fix some bugs for HNS3 driver

2017-10-24 Thread Lipeng
This patchset fixes some bugs reported by Hisilicon test team.

Lipeng (4):
  net: hns3: fix the bug of hns3_set_txbd_baseinfo
  net: hns3: add nic_client check when initialize roce base information
  net: hns3: fix a bug in hclge_uninit_client_instance
  net: hns3: fix the bug when reuse command description in
hclge_add_mac_vlan_tbl

 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 18 --
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c |  2 +-
 2 files changed, 13 insertions(+), 7 deletions(-)

-- 
1.9.1



[PATCH net-next 1/4] net: hns3: fix the bug of hns3_set_txbd_baseinfo

2017-10-24 Thread Lipeng
The SC bits of TX BD mean switch control. For this area, value 0
indicates no switch control, the packet is routed according to the
forwarding table. Value 1 indicates that the packet is transmitted
to the network bypassing the forwarding table.

As HNS3 driver need support VF later, VF conmunicate with its own
PF need forwarding table. This patch sets SC bits of TX BD 0 and use
forwarding table.

Fixes: 76ad4f0 (net: hns3: Add support of HNS3 Ethernet Driver for hip08 SoC)

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

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
index 537f6c3..c6c5b2a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
@@ -716,7 +716,7 @@ static void hns3_set_txbd_baseinfo(u16 
*bdtp_fe_sc_vld_ra_ri, int frag_end)
   HNS3_TXD_BDTYPE_M, 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, 1);
+   hnae_set_field(*bdtp_fe_sc_vld_ra_ri, HNS3_TXD_SC_M, HNS3_TXD_SC_S, 0);
 }
 
 static int hns3_fill_desc(struct hns3_enet_ring *ring, void *priv,
-- 
1.9.1



[PATCH net-next 1/9] net: hns3: Refactor the mapping of tqp to vport

2017-11-01 Thread Lipeng
From: qumingguang 

This patch refactor the mapping of tqp to vport, making the maping function
can be used both in the reset process and initialization process.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 61 ++
 1 file changed, 50 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 0b95fbe..a56d878 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -1184,11 +1184,7 @@ static int  hclge_assign_tqp(struct hclge_vport *vport,
 struct hnae3_queue **tqp, u16 num_tqps)
 {
struct hclge_dev *hdev = vport->back;
-   int i, alloced, func_id, ret;
-   bool is_pf;
-
-   func_id = vport->vport_id;
-   is_pf = (vport->vport_id == 0) ? true : false;
+   int i, alloced;
 
for (i = 0, alloced = 0; i < hdev->num_tqps &&
 alloced < num_tqps; i++) {
@@ -1197,12 +1193,6 @@ static int  hclge_assign_tqp(struct hclge_vport *vport,
hdev->htqp[i].q.tqp_index = alloced;
tqp[alloced] = &hdev->htqp[i].q;
hdev->htqp[i].alloced = true;
-   ret = hclge_map_tqps_to_func(hdev, func_id,
-hdev->htqp[i].index,
-alloced, is_pf);
-   if (ret)
-   return ret;
-
alloced++;
}
}
@@ -1254,6 +1244,49 @@ static int hclge_knic_setup(struct hclge_vport *vport, 
u16 num_tqps)
return 0;
 }
 
+static int hclge_map_tqp_to_vport(struct hclge_dev *hdev,
+ struct hclge_vport *vport)
+{
+   struct hnae3_handle *nic = &vport->nic;
+   struct hnae3_knic_private_info *kinfo;
+   u16 i;
+
+   kinfo = &nic->kinfo;
+   for (i = 0; i < kinfo->num_tqps; i++) {
+   struct hclge_tqp *q =
+   container_of(kinfo->tqp[i], struct hclge_tqp, q);
+   bool is_pf;
+   int ret;
+
+   is_pf = (vport->vport_id == 0) ? true : false;
+   ret = hclge_map_tqps_to_func(hdev, vport->vport_id, q->index,
+i, is_pf);
+   if (ret)
+   return ret;
+   }
+
+   return 0;
+}
+
+static int hclge_map_tqp(struct hclge_dev *hdev)
+{
+   struct hclge_vport *vport = hdev->vport;
+   u16 i, num_vport;
+
+   num_vport = hdev->num_vmdq_vport + hdev->num_req_vfs + 1;
+   for (i = 0; i < num_vport; i++) {
+   int ret;
+
+   ret = hclge_map_tqp_to_vport(hdev, vport);
+   if (ret)
+   return ret;
+
+   vport++;
+   }
+
+   return 0;
+}
+
 static void hclge_unic_setup(struct hclge_vport *vport, u16 num_tqps)
 {
/* this would be initialized later */
@@ -4459,6 +4492,12 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
return ret;
}
 
+   ret = hclge_map_tqp(hdev);
+   if (ret) {
+   dev_err(&pdev->dev, "Map tqp error, ret = %d.\n", ret);
+   return ret;
+   }
+
ret = hclge_mac_init(hdev);
if (ret) {
dev_err(&pdev->dev, "Mac init error, ret = %d\n", ret);
-- 
1.9.1



[PATCH net-next 0/9] net: hns3: add support for reset

2017-11-01 Thread Lipeng
There are 4 reset types for HNS3 PF driver, include global reset,
core reset, IMP reset, PF reset.The core reset will reset all datapath
of all functions except IMP, MAC and PCI interface. Global reset is equal
with the core reset plus all MAC reset. IMP reset is caused by watchdog
timer expiration, the same range with core reset. PF reset will reset
whole physical function. 

This patchset adds reset support for hns3 driver and fix some related bugs.

Lipeng (2):
  net: hns3: Add timeout process in hns3_enet
  net: hns3: Add reset interface implementation in client

qumingguang (7):
  net: hns3: Refactor the mapping of tqp to vport
  net: hns3: Refactor mac_init function
  net: hns3: Refactor the initialization of command queue
  net: hns3: Add support for misc interrupt
  net: hns3: Add reset process in hclge_main
  net: hns3: Fix a misuse to devm_free_irq
  net: hns3: hns3:fix a bug about statistic counter in reset process

 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  19 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c |  39 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  13 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 454 -
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  18 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c | 244 ++-
 .../net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.h |   2 +
 7 files changed, 750 insertions(+), 39 deletions(-)

-- 
1.9.1



[PATCH net-next 2/9] net: hns3: Refactor mac_init function

2017-11-01 Thread Lipeng
From: qumingguang 

It needs initialize mdio in initialization process, but reset process
does not reset mdio, so do not initialize mdio in reset process.
This patch move out the mdio configuration function from the mac_init.
So mac_init can be used both in reset process and initialization process.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 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 a56d878..4ef4592 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -2228,13 +2228,6 @@ static int hclge_mac_init(struct hclge_dev *hdev)
 
mac->link = 0;
 
-   ret = hclge_mac_mdio_config(hdev);
-   if (ret) {
-   dev_warn(&hdev->pdev->dev,
-"mdio config fail ret=%d\n", ret);
-   return ret;
-   }
-
/* Initialize the MTA table work mode */
hdev->accept_mta_mc = true;
hdev->enable_mta= true;
@@ -4498,6 +4491,13 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
return ret;
}
 
+   ret = hclge_mac_mdio_config(hdev);
+   if (ret) {
+   dev_warn(&hdev->pdev->dev,
+"mdio config fail ret=%d\n", ret);
+   return ret;
+   }
+
ret = hclge_mac_init(hdev);
if (ret) {
dev_err(&pdev->dev, "Mac init error, ret = %d\n", ret);
-- 
1.9.1



[PATCH net-next 3/9] net: hns3: Refactor the initialization of command queue

2017-11-01 Thread Lipeng
From: qumingguang 

There is no necessary to reallocate the descriptor and remap the descriptor
memory in reset process, But there is still some other action exit in both
reset process and initialization process.

To reuse the common interface of reset process and initialization process,
This patch moved out the descriptor allocate and memory maping from
interface cmdq_init.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c | 39 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c|  9 -
 3 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
index 60960e5..ff13d18 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
@@ -62,7 +62,7 @@ static void hclge_free_cmd_desc(struct hclge_cmq_ring *ring)
ring->desc = NULL;
 }
 
-static int hclge_init_cmd_queue(struct hclge_dev *hdev, int ring_type)
+static int hclge_alloc_cmd_queue(struct hclge_dev *hdev, int ring_type)
 {
struct hclge_hw *hw = &hdev->hw;
struct hclge_cmq_ring *ring =
@@ -79,9 +79,6 @@ static int hclge_init_cmd_queue(struct hclge_dev *hdev, int 
ring_type)
return ret;
}
 
-   ring->next_to_clean = 0;
-   ring->next_to_use = 0;
-
return 0;
 }
 
@@ -302,37 +299,52 @@ static enum hclge_cmd_status 
hclge_cmd_query_firmware_version(
return ret;
 }
 
-int hclge_cmd_init(struct hclge_dev *hdev)
+int hclge_cmd_queue_init(struct hclge_dev *hdev)
 {
-   u32 version;
int ret;
 
/* Setup the queue entries for use cmd queue */
hdev->hw.cmq.csq.desc_num = HCLGE_NIC_CMQ_DESC_NUM;
hdev->hw.cmq.crq.desc_num = HCLGE_NIC_CMQ_DESC_NUM;
 
-   /* Setup the lock for command queue */
-   spin_lock_init(&hdev->hw.cmq.csq.lock);
-   spin_lock_init(&hdev->hw.cmq.crq.lock);
-
/* Setup Tx write back timeout */
hdev->hw.cmq.tx_timeout = HCLGE_CMDQ_TX_TIMEOUT;
 
/* Setup queue rings */
-   ret = hclge_init_cmd_queue(hdev, HCLGE_TYPE_CSQ);
+   ret = hclge_alloc_cmd_queue(hdev, HCLGE_TYPE_CSQ);
if (ret) {
dev_err(&hdev->pdev->dev,
"CSQ ring setup error %d\n", ret);
return ret;
}
 
-   ret = hclge_init_cmd_queue(hdev, HCLGE_TYPE_CRQ);
+   ret = hclge_alloc_cmd_queue(hdev, HCLGE_TYPE_CRQ);
if (ret) {
dev_err(&hdev->pdev->dev,
"CRQ ring setup error %d\n", ret);
goto err_csq;
}
 
+   return 0;
+err_csq:
+   hclge_free_cmd_desc(&hdev->hw.cmq.csq);
+   return ret;
+}
+
+int hclge_cmd_init(struct hclge_dev *hdev)
+{
+   u32 version;
+   int ret;
+
+   hdev->hw.cmq.csq.next_to_clean = 0;
+   hdev->hw.cmq.csq.next_to_use = 0;
+   hdev->hw.cmq.crq.next_to_clean = 0;
+   hdev->hw.cmq.crq.next_to_use = 0;
+
+   /* Setup the lock for command queue */
+   spin_lock_init(&hdev->hw.cmq.csq.lock);
+   spin_lock_init(&hdev->hw.cmq.crq.lock);
+
hclge_cmd_init_regs(&hdev->hw);
 
ret = hclge_cmd_query_firmware_version(&hdev->hw, &version);
@@ -346,9 +358,6 @@ int hclge_cmd_init(struct hclge_dev *hdev)
dev_info(&hdev->pdev->dev, "The firmware version is %08x\n", version);
 
return 0;
-err_csq:
-   hclge_free_cmd_desc(&hdev->hw.cmq.csq);
-   return ret;
 }
 
 static void hclge_destroy_queue(struct hclge_cmq_ring *ring)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index b437334..6bdc216 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -750,4 +750,5 @@ enum hclge_cmd_status hclge_cmd_mdio_read(struct hclge_hw 
*hw,
  struct hclge_desc *desc);
 
 void hclge_destroy_cmd_queue(struct hclge_hw *hw);
+int hclge_cmd_queue_init(struct hclge_dev *hdev);
 #endif
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 4ef4592..a7686fe 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4446,7 +4446,14 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
goto err_pci_init;
}
 
-   /* Command queue initialize */
+   /* Firmware command queue initialize */
+   ret = hclge_cmd_queue_init(hdev);
+   if (ret) {
+   dev_er

[PATCH net-next 5/9] net: hns3: Add reset process in hclge_main

2017-11-01 Thread Lipeng
From: qumingguang 

This patch add reset support for PF,It include : global reset, core reset,
IMP reset, PF reset.The core reset will Reset all datapath of all functions
except IMP, MAC and PCI interface. Global reset is equal with the core
reset plus all MAC reset. IMP reset is caused by watchdog timer expiration,
the same range with core reset. PF reset will reset whole physical
function.

Signed-off-by: qumingguang 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  19 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |   7 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 295 -
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  16 +-
 4 files changed, 332 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index 3acd8db..5fc8c97 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -110,6 +110,21 @@ enum hnae3_media_type {
HNAE3_MEDIA_TYPE_BACKPLANE,
 };
 
+enum hnae3_reset_notify_type {
+   HNAE3_DOWN_CLIENT,
+   HNAE3_INIT_CLIENT,
+   HNAE3_UNINIT_CLIENT,
+   HNAE3_UP_CLIENT,
+};
+
+enum hnae3_reset_type {
+   HNAE3_FUNC_RESET,
+   HNAE3_CORE_RESET,
+   HNAE3_GLOBAL_RESET,
+   HNAE3_IMP_RESET,
+   HNAE3_NONE_RESET,
+};
+
 struct hnae3_vector_info {
u8 __iomem *io_addr;
int vector;
@@ -133,6 +148,8 @@ struct hnae3_client_ops {
void (*uninit_instance)(struct hnae3_handle *handle, bool reset);
void (*link_status_change)(struct hnae3_handle *handle, bool state);
int (*setup_tc)(struct hnae3_handle *handle, u8 tc);
+   int (*reset_notify)(struct hnae3_handle *handle,
+   enum hnae3_reset_notify_type type);
 };
 
 #define HNAE3_CLIENT_NAME_LENGTH 16
@@ -367,6 +384,8 @@ struct hnae3_ae_ops {
   u16 vlan_id, bool is_kill);
int (*set_vf_vlan_filter)(struct hnae3_handle *handle, int vfid,
  u16 vlan, u8 qos, __be16 proto);
+   void (*reset_event)(struct hnae3_handle *handle,
+   enum hnae3_reset_type reset_level, u16 vfid);
 };
 
 struct hnae3_dcb_ops {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index db4d887..844c83e 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -697,6 +697,13 @@ struct hclge_reset_tqp_queue_cmd {
u8 rsv[20];
 };
 
+#define HCLGE_CFG_RESET_MAC_B  3
+#define HCLGE_CFG_RESET_FUNC_B 7
+struct hclge_reset_cmd {
+   u8 mac_func_reset;
+   u8 fun_reset_vfid;
+   u8 rsv[22];
+};
 #define HCLGE_DEFAULT_TX_BUF   0x4000   /* 16k  bytes */
 #define HCLGE_TOTAL_PKT_BUF0x108000 /* 1.03125M bytes */
 #define HCLGE_DEFAULT_DV   0xA000   /* 40k byte */
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 7558cfb..141c758 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -35,6 +35,7 @@ static int hclge_set_mta_filter_mode(struct hclge_dev *hdev,
 enum hclge_mta_dmac_sel_type mta_mac_sel,
 bool enable);
 static int hclge_init_vlan_config(struct hclge_dev *hdev);
+static int hclge_reset_ae_dev(struct hnae3_ae_dev *ae_dev);
 
 static struct hnae3_ae_algo ae_algo;
 
@@ -2392,6 +2393,11 @@ static void hclge_service_complete(struct hclge_dev 
*hdev)
clear_bit(HCLGE_STATE_SERVICE_SCHED, &hdev->state);
 }
 
+void hclge_enable_vector(struct hclge_misc_vector *vector, bool enable)
+{
+   writel(enable, vector->addr);
+}
+
 static irqreturn_t hclge_misc_irq_handle(int irq, void *data)
 {
struct hclge_dev *hdev = data;
@@ -2441,13 +2447,214 @@ static int hclge_misc_irq_init(struct hclge_dev *hdev)
return ret;
 }
 
-void hclge_enable_vector(struct hclge_misc_vector *vector, bool enable)
+static int hclge_notify_client(struct hclge_dev *hdev,
+  enum hnae3_reset_notify_type type)
 {
-   writel(enable, vector->addr);
+   struct hnae3_client *client = hdev->nic_client;
+   u16 i;
+
+   if (!client->ops->reset_notify)
+   return -EOPNOTSUPP;
+
+   for (i = 0; i < hdev->num_vmdq_vport + 1; i++) {
+   struct hnae3_handle *handle = &hdev->vport[i].nic;
+   int ret;
+
+   ret = client->ops->reset_notify(handle, type);
+   if (ret)
+   return ret;
+   }
+
+   return 0;
+}
+
+static int hclge_reset_wait(struct hclge_dev *hdev)
+{
+#define HCLGE_RESET_WATI_MS

[PATCH net-next 1/8] net: hns3: add check when initialize

2017-08-31 Thread Lipeng
private waterline and and common packet buffer

Command HCLGE_OPC_RX_PRIV_WL_ALLOC configure waterline for TC's PFC,
which has private buffer.Command HCLGE_OPC_RX_COM_THRD_ALLOC Control
each TC's occupation in common packet buffer, also generate PFC for
TC, which has not private buffer.When device do not support DCB,
command HCLGE_OPC_RX_PRIV_WL_ALLOC and HCLGE_OPC_RX_COM_THRD_ALLOC
should not be used.

The current code does not support DCB feature, DCB feature will be added
later. The current code works well if device support DCB though it do
not enable DCB feature, but it works fail if device do not support DCB.

Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 41 --
 2 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index b2f28ae..e23e028 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -50,6 +50,7 @@
 
 #define HNAE3_DEV_INITED_B 0x0
 #define HNAE_DEV_SUPPORT_ROCE_B0x1
+#define HNAE_DEV_SUPPORT_DCB_B 0x2
 
 #define ring_ptr_move_fw(ring, p) \
((ring)->p = ((ring)->p + 1) % (ring)->desc_num)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index bb45365..acc4016 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -60,6 +60,16 @@ static int hclge_set_mta_filter_mode(struct hclge_dev *hdev,
{0, }
 };
 
+static const struct pci_device_id dcb_pci_tbl[] = {
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_25GE_RDMA_MACSEC), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_50GE_RDMA_MACSEC), 0},
+   {PCI_VDEVICE(HUAWEI, HNAE3_DEV_ID_100G_RDMA_MACSEC), 0},
+   /* Required last entry */
+   {0, }
+};
+
 static const char hns3_nic_test_strs[][ETH_GSTRING_LEN] = {
"MacLoopback test",
"Serdes Loopback test",
@@ -1782,18 +1792,23 @@ int hclge_buffer_alloc(struct hclge_dev *hdev)
return ret;
}
 
-   ret = hclge_rx_priv_wl_config(hdev);
-   if (ret) {
-   dev_err(&hdev->pdev->dev,
-   "could not configure rx private waterline %d\n", ret);
-   return ret;
-   }
+   if (hnae_get_bit(hdev->ae_dev->flag,
+HNAE_DEV_SUPPORT_DCB_B)) {
+   ret = hclge_rx_priv_wl_config(hdev);
+   if (ret) {
+   dev_err(&hdev->pdev->dev,
+   "could not configure rx private waterline %d\n",
+   ret);
+   return ret;
+   }
 
-   ret = hclge_common_thrd_config(hdev);
-   if (ret) {
-   dev_err(&hdev->pdev->dev,
-   "could not configure common threshold %d\n", ret);
-   return ret;
+   ret = hclge_common_thrd_config(hdev);
+   if (ret) {
+   dev_err(&hdev->pdev->dev,
+   "could not configure common threshold %d\n",
+   ret);
+   return ret;
+   }
}
 
ret = hclge_common_wl_config(hdev);
@@ -4076,6 +4091,10 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
if (id)
hnae_set_bit(ae_dev->flag, HNAE_DEV_SUPPORT_ROCE_B, 1);
 
+   id = pci_match_id(dcb_pci_tbl, ae_dev->pdev);
+   if (id)
+   hnae_set_bit(ae_dev->flag, HNAE_DEV_SUPPORT_DCB_B, 1);
+
ret = hclge_pci_init(hdev);
if (ret) {
dev_err(&pdev->dev, "PCI init failed\n");
-- 
1.9.1



[PATCH net-next 8/8] net: hns3: reimplemmentation of pkt buffer allocation

2017-08-31 Thread Lipeng
Current implemmentation of buffer allocation in SSU do not meet
the requirement to do the buffer reallocation. This patch fixs
that in order to support buffer reallocation between Mac and
PFC pause.

Signed-off-by: Yunsheng Lin 
Signed-off-by: Lipeng 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  32 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 368 +++--
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|   5 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  |  84 -
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |   9 +
 5 files changed, 308 insertions(+), 190 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 5887418..26e8ca6 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -141,7 +141,7 @@ enum hclge_opcode_type {
 
/* Packet buffer allocate command */
HCLGE_OPC_TX_BUFF_ALLOC = 0x0901,
-   HCLGE_OPC_RX_PRIV_BUFF_ALLOC= 0x0902,
+   HCLGE_OPC_RX_BUFF_ALLOC = 0x0902,
HCLGE_OPC_RX_PRIV_WL_ALLOC  = 0x0903,
HCLGE_OPC_RX_COM_THRD_ALLOC = 0x0904,
HCLGE_OPC_RX_COM_WL_ALLOC   = 0x0905,
@@ -264,14 +264,15 @@ struct hclge_ctrl_vector_chain {
 #define HCLGE_TC_NUM   8
 #define HCLGE_TC0_PRI_BUF_EN_B 15 /* Bit 15 indicate enable or not */
 #define HCLGE_BUF_UNIT_S   7  /* Buf size is united by 128 bytes */
-struct hclge_tx_buff_alloc {
-   __le16 tx_pkt_buff[HCLGE_TC_NUM];
-   u8 tx_buff_rsv[8];
+struct hclge_tx_buf_alloc {
+   __le16 buf[HCLGE_TC_NUM];
+   u8 rsv[8];
 };
 
-struct hclge_rx_priv_buff {
-   __le16 buf_num[HCLGE_TC_NUM];
-   u8 rsv[8];
+struct hclge_rx_buf_alloc {
+   __le16 priv_buf[HCLGE_TC_NUM];
+   __le16 shared_buf;
+   u8 rsv[6];
 };
 
 struct hclge_query_version {
@@ -308,19 +309,24 @@ struct hclge_tc_thrd {
u32 high;
 };
 
-struct hclge_priv_buf {
+struct hclge_rx_priv_buf {
struct hclge_waterline wl;  /* Waterline for low and high*/
u32 buf_size;   /* TC private buffer size */
-   u32 enable; /* Enable TC private buffer or not */
 };
 
 #define HCLGE_MAX_TC_NUM   8
-struct hclge_shared_buf {
+struct hclge_rx_shared_buf {
struct hclge_waterline self;
struct hclge_tc_thrd tc_thrd[HCLGE_MAX_TC_NUM];
u32 buf_size;
 };
 
+struct hclge_pkt_buf_alloc {
+   u32 tx_buf_size[HCLGE_MAX_TC_NUM];
+   struct hclge_rx_priv_buf rx_buf[HCLGE_MAX_TC_NUM];
+   struct hclge_rx_shared_buf s_buf;
+};
+
 #define HCLGE_RX_COM_WL_EN_B   15
 struct hclge_rx_com_wl_buf {
__le16 high_wl;
@@ -707,9 +713,9 @@ struct hclge_reset_tqp_queue {
u8 rsv[20];
 };
 
-#define HCLGE_DEFAULT_TX_BUF   0x4000   /* 16k  bytes */
-#define HCLGE_TOTAL_PKT_BUF0x108000 /* 1.03125M bytes */
-#define HCLGE_DEFAULT_DV   0xA000   /* 40k byte */
+#define HCLGE_DEFAULT_TX_BUF   0x4000  /* 16k  bytes */
+#define HCLGE_DEFAULT_DV   0xA000  /* 40k byte */
+#define HCLGE_DEFAULT_NON_DCB_DV   0x7800  /* 30K 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 d0a30f5..61073c2 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -1094,8 +1094,18 @@ static int hclge_configure(struct hclge_dev *hdev)
hdev->tm_info.num_tc = 1;
}
 
+   /* non-DCB supported dev */
+   if (!hnae_get_bit(hdev->ae_dev->flag,
+ HNAE_DEV_SUPPORT_DCB_B)) {
+   hdev->tc_cap = 1;
+   hdev->pfc_cap = 0;
+   } else {
+   hdev->tc_cap = hdev->tm_info.num_tc;
+   hdev->pfc_cap = hdev->tm_info.num_tc;
+   }
+
/* Currently not support uncontiuous tc */
-   for (i = 0; i < cfg.tc_num; i++)
+   for (i = 0; i < hdev->tc_cap; i++)
hnae_set_bit(hdev->hw_tc_map, i, 1);
 
if (!hdev->num_vmdq_vport && !hdev->num_req_vfs)
@@ -1344,45 +1354,32 @@ static int hclge_alloc_vport(struct hclge_dev *hdev)
return 0;
 }
 
-static int  hclge_cmd_alloc_tx_buff(struct hclge_dev *hdev, u16 buf_size)
+static int hclge_tx_buffer_alloc(struct hclge_dev *hdev,
+struct hclge_pkt_buf_alloc *buf_alloc)
 {
-/* TX buffer size is unit by 128 byte */
-#define HCLGE_BUF_SIZE_UNIT_SHIFT  7
-#define HCLGE_BUF_SIZE_UPDATE_EN_MSK   BIT(15)
-   struct hclge_tx_buff_alloc *req;
struct hclge_desc desc;
-   int ret;
+   struct hclge_tx_buf_alloc *req =
+   (struct hclge_tx_buf_alloc *)desc.dat

[PATCH net-next 6/8] net: hns3: fix bug of reuse command description

2017-08-31 Thread Lipeng
When reuse command description, the in/out bit and W/R bit of the
command flag should be both updated. The old code did not update
in/out bit, this patch fix it.

Signed-off-by: Mingguang Qu 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c  | 9 +
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h  | 2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 6 +++---
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
index 8b511e6..fe2b116 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
@@ -85,6 +85,15 @@ static int hclge_init_cmd_queue(struct hclge_dev *hdev, int 
ring_type)
return 0;
 }
 
+void hclge_cmd_reuse_desc(struct hclge_desc *desc, bool is_read)
+{
+   desc->flag = cpu_to_le16(HCLGE_CMD_FLAG_NO_INTR | HCLGE_CMD_FLAG_IN);
+   if (is_read)
+   desc->flag |= cpu_to_le16(HCLGE_CMD_FLAG_WR);
+   else
+   desc->flag &= cpu_to_le16(~HCLGE_CMD_FLAG_WR);
+}
+
 void hclge_cmd_setup_basic_desc(struct hclge_desc *desc,
enum hclge_opcode_type opcode, bool is_read)
 {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index b841df1..5887418 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -753,7 +753,7 @@ static inline u32 hclge_read_reg(u8 __iomem *base, u32 reg)
 int hclge_cmd_send(struct hclge_hw *hw, struct hclge_desc *desc, int num);
 void hclge_cmd_setup_basic_desc(struct hclge_desc *desc,
enum hclge_opcode_type opcode, bool is_read);
-
+void hclge_cmd_reuse_desc(struct hclge_desc *desc, bool is_read);
 int hclge_cmd_set_promisc_mode(struct hclge_dev *hdev,
   struct hclge_promisc_param *param);
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index f2ea88f..12be24f 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3302,11 +3302,11 @@ static int hclge_add_mac_vlan_tbl(struct hclge_vport 
*vport,
   resp_code,
   HCLGE_MAC_VLAN_ADD);
} else {
-   mc_desc[0].flag &= cpu_to_le16(~HCLGE_CMD_FLAG_WR);
+   hclge_cmd_reuse_desc(&mc_desc[0], false);
mc_desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
-   mc_desc[1].flag &= cpu_to_le16(~HCLGE_CMD_FLAG_WR);
+   hclge_cmd_reuse_desc(&mc_desc[1], false);
mc_desc[1].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
-   mc_desc[2].flag &= cpu_to_le16(~HCLGE_CMD_FLAG_WR);
+   hclge_cmd_reuse_desc(&mc_desc[2], false);
mc_desc[2].flag &= cpu_to_le16(~HCLGE_CMD_FLAG_NEXT);
memcpy(mc_desc[0].data, req,
   sizeof(struct hclge_mac_vlan_tbl_entry));
-- 
1.9.1



[PATCH net-next 4/8] net: hns3: set default vlan id to PF

2017-08-31 Thread Lipeng
When there is no vlan id in the packets, hardware will treat the vlan id
as 0 and look for the mac_vlan table. This patch set the default vlan id
of PF as 0.

Signed-off-by: Mingguang Qu 
Signed-off-by: Lipeng 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 5d49856..7374053 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3698,6 +3698,7 @@ static int hclge_init_vlan_config(struct hclge_dev *hdev)
 {
 #define HCLGE_VLAN_TYPE_VF_TABLE   0
 #define HCLGE_VLAN_TYPE_PORT_TABLE 1
+   struct hnae3_handle *handle;
int ret;
 
ret = hclge_set_vlan_filter_ctrl(hdev, HCLGE_VLAN_TYPE_VF_TABLE,
@@ -3707,6 +3708,8 @@ static int hclge_init_vlan_config(struct hclge_dev *hdev)
 
ret = hclge_set_vlan_filter_ctrl(hdev, HCLGE_VLAN_TYPE_PORT_TABLE,
 true);
+   handle = &hdev->vport[0].nic;
+   ret = hclge_set_port_vlan_filter(handle, htons(ETH_P_8021Q), 0, false);
 
return ret;
 }
-- 
1.9.1



  1   2   >