RE: [Intel-wired-lan] [PATCH V2 net] ice: Re-organizes reqstd/avail {R, T}XQ check/code for efficiency+readability

2021-04-20 Thread Salil Mehta
> From: Brelinski, TonyX [mailto:tonyx.brelin...@intel.com]
> Sent: Tuesday, April 20, 2021 9:26 PM
> 
> > From: Intel-wired-lan  On Behalf Of
> > Salil Mehta
> > Sent: Tuesday, April 13, 2021 3:45 PM
> > To: da...@davemloft.net; k...@kernel.org
> > Cc: salil.me...@huawei.com; linux...@openeuler.org;
> > netdev@vger.kernel.org; linux...@huawei.com; linux-
> > ker...@vger.kernel.org; Jeff Kirsher ; intel-
> > wired-...@lists.osuosl.org
> > Subject: [Intel-wired-lan] [PATCH V2 net] ice: Re-organizes reqstd/avail {R,
> > T}XQ check/code for efficiency+readability
> >
> > If user has explicitly requested the number of {R,T}XQs, then it is
> > unnecessary to get the count of already available {R,T}XQs from the PF
> > avail_{r,t}xqs bitmap. This value will get overridden by user specified 
> > value
> in
> > any case.
> >
> > This patch does minor re-organization of the code for improving the flow and
> > readabiltiy. This scope of improvement was found during the review of the
> > ICE driver code.
> >
> > FYI, I could not test this change due to unavailability of the hardware.
> > It would be helpful if somebody can test this patch and provide Tested-by
> > Tag. Many thanks!
> >
> > Fixes: 87324e747fde ("ice: Implement ethtool ops for channels")
> > Cc: intel-wired-...@lists.osuosl.org
> > Cc: Jeff Kirsher 
> > Signed-off-by: Salil Mehta 
> > --
> > Change V1->V2
> >  (*) Fixed the comments from Anthony Nguyen(Intel)
> >  Link: https://lkml.org/lkml/2021/4/12/1997
> > ---
> >  drivers/net/ethernet/intel/ice/ice_lib.c | 14 --
> >  1 file changed, 8 insertions(+), 6 deletions(-)
> 
> Tested-by: Tony Brelinski  (A Contingent Worker at
> Intel)

Many thanks! 

Salil.



[PATCH V2 net] ice: Re-organizes reqstd/avail {R,T}XQ check/code for efficiency+readability

2021-04-13 Thread Salil Mehta
If user has explicitly requested the number of {R,T}XQs, then it is
unnecessary to get the count of already available {R,T}XQs from the
PF avail_{r,t}xqs bitmap. This value will get overridden by user specified
value in any case.

This patch does minor re-organization of the code for improving the flow
and readabiltiy. This scope of improvement was found during the review of
the ICE driver code.

FYI, I could not test this change due to unavailability of the hardware.
It would be helpful if somebody can test this patch and provide Tested-by
Tag. Many thanks!

Fixes: 87324e747fde ("ice: Implement ethtool ops for channels")
Cc: intel-wired-...@lists.osuosl.org
Cc: Jeff Kirsher 
Signed-off-by: Salil Mehta 
--
Change V1->V2
 (*) Fixed the comments from Anthony Nguyen(Intel)
 Link: https://lkml.org/lkml/2021/4/12/1997
---
 drivers/net/ethernet/intel/ice/ice_lib.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c 
b/drivers/net/ethernet/intel/ice/ice_lib.c
index d13c7fc8fb0a..d77133d6baa7 100644
--- a/drivers/net/ethernet/intel/ice/ice_lib.c
+++ b/drivers/net/ethernet/intel/ice/ice_lib.c
@@ -161,12 +161,13 @@ static void ice_vsi_set_num_qs(struct ice_vsi *vsi, u16 
vf_id)
 
switch (vsi->type) {
case ICE_VSI_PF:
-   vsi->alloc_txq = min3(pf->num_lan_msix,
- ice_get_avail_txq_count(pf),
- (u16)num_online_cpus());
if (vsi->req_txq) {
vsi->alloc_txq = vsi->req_txq;
vsi->num_txq = vsi->req_txq;
+   } else {
+   vsi->alloc_txq = min3(pf->num_lan_msix,
+ ice_get_avail_txq_count(pf),
+ (u16)num_online_cpus());
}
 
pf->num_lan_tx = vsi->alloc_txq;
@@ -175,12 +176,13 @@ static void ice_vsi_set_num_qs(struct ice_vsi *vsi, u16 
vf_id)
if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
vsi->alloc_rxq = 1;
} else {
-   vsi->alloc_rxq = min3(pf->num_lan_msix,
- ice_get_avail_rxq_count(pf),
- (u16)num_online_cpus());
if (vsi->req_rxq) {
vsi->alloc_rxq = vsi->req_rxq;
vsi->num_rxq = vsi->req_rxq;
+   } else {
+   vsi->alloc_rxq = min3(pf->num_lan_msix,
+ 
ice_get_avail_rxq_count(pf),
+ (u16)num_online_cpus());
}
}
 
-- 
2.17.1



RE: [PATCH net] ice: Re-organizes reqstd/avail {R,T}XQ check/code for efficiency+readability

2021-04-13 Thread Salil Mehta
Hi Anthony,
Thanks for reviewing!

> From: Nguyen, Anthony L [mailto:anthony.l.ngu...@intel.com]
> Sent: Monday, April 12, 2021 11:41 PM
> To: da...@davemloft.net; k...@kernel.org; Salil Mehta 
> Cc: netdev@vger.kernel.org; linux-ker...@vger.kernel.org; Brandeburg, Jesse
> ; linux...@openeuler.org; Tieman, Henry W
> ; Linuxarm 
> Subject: Re: [PATCH net] ice: Re-organizes reqstd/avail {R,T}XQ check/code for
> efficiency+readability
> 
> On Sun, 2021-04-11 at 02:45 +0100, Salil Mehta wrote:
> > If user has explicitly requested the number of {R,T}XQs, then it is
> > unnecessary
> > to get the count of already available {R,T}XQs from the PF
> > avail_{r,t}xqs
> > bitmap. This value will get overriden by user specified value in any
> 
> s/overriden/overridden

Ok.

> 
> > case.
> >
> > This patch does minor re-organization of the code for improving the
> > flow and
> > readabiltiy. This scope of improvement was found during the review of
> > the ICE
> > driver code.
> 
> The changes themselves look ok, but there are some checkpatch issues.
> Also, could you include intel-wired-...@lists.osuosl.org

Sure. will fix them.

> 
> > FYI, I could not test this change due to unavailability of the
> > hardware. It
> > would helpful if somebody can test this and provide Tested-by Tag.
> > Many thanks!
> >
> > Fixes: 11b7551e096d ("ice: Implement ethtool ops for channels")
> 
> This commit id doesn't exist.

Will fix. Sorry about this.

> 
> > Signed-off-by: Salil Mehta 
> > ---
> >  drivers/net/ethernet/intel/ice/ice_lib.c | 14 --
> >  1 file changed, 8 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c
> > b/drivers/net/ethernet/intel/ice/ice_lib.c
> > index d13c7fc8fb0a..161e8dfe548c 100644
> > --- a/drivers/net/ethernet/intel/ice/ice_lib.c
> > +++ b/drivers/net/ethernet/intel/ice/ice_lib.c
> > @@ -161,12 +161,13 @@ static void ice_vsi_set_num_qs(struct ice_vsi
> > *vsi, u16 vf_id)
> >
> > switch (vsi->type) {
> > case ICE_VSI_PF:
> > -   vsi->alloc_txq = min3(pf->num_lan_msix,
> > - ice_get_avail_txq_count(pf),
> > - (u16)num_online_cpus());
> > if (vsi->req_txq) {
> > vsi->alloc_txq = vsi->req_txq;
> > vsi->num_txq = vsi->req_txq;
> > +   } else {
> > +   vsi->alloc_txq = min3(pf->num_lan_msix,
> > +ice_get_avail_txq_count(pf),
> > +(u16)num_online_cpus());
> 
> Alignment is incorrect.

Ok. Will check, perhaps the cause of the checkpatch.pl errors.

> 
> > }
> >
> > pf->num_lan_tx = vsi->alloc_txq;
> > @@ -175,12 +176,13 @@ static void ice_vsi_set_num_qs(struct ice_vsi
> > *vsi, u16 vf_id)
> > if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
> > vsi->alloc_rxq = 1;
> > } else {
> > -   vsi->alloc_rxq = min3(pf->num_lan_msix,
> > - ice_get_avail_rxq_count(p
> > f),
> > - (u16)num_online_cpus());
> > if (vsi->req_rxq) {
> > vsi->alloc_rxq = vsi->req_rxq;
> > vsi->num_rxq = vsi->req_rxq;
> > +   } else {
> > +   vsi->alloc_rxq = min3(pf->num_lan_msix,
> > +ice_get_avail_rxq_coun
> > t(pf),
> > +(u16)num_online_cpus()
> 
> Same, alignment is incorrect.

Ok. Will fix.

Thanks
Salil.


[PATCH net] ice: Re-organizes reqstd/avail {R,T}XQ check/code for efficiency+readability

2021-04-10 Thread Salil Mehta
If user has explicitly requested the number of {R,T}XQs, then it is unnecessary
to get the count of already available {R,T}XQs from the PF avail_{r,t}xqs
bitmap. This value will get overriden by user specified value in any case.

This patch does minor re-organization of the code for improving the flow and
readabiltiy. This scope of improvement was found during the review of the ICE
driver code.

FYI, I could not test this change due to unavailability of the hardware. It
would helpful if somebody can test this and provide Tested-by Tag. Many thanks!

Fixes: 11b7551e096d ("ice: Implement ethtool ops for channels")
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/intel/ice/ice_lib.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c 
b/drivers/net/ethernet/intel/ice/ice_lib.c
index d13c7fc8fb0a..161e8dfe548c 100644
--- a/drivers/net/ethernet/intel/ice/ice_lib.c
+++ b/drivers/net/ethernet/intel/ice/ice_lib.c
@@ -161,12 +161,13 @@ static void ice_vsi_set_num_qs(struct ice_vsi *vsi, u16 
vf_id)
 
switch (vsi->type) {
case ICE_VSI_PF:
-   vsi->alloc_txq = min3(pf->num_lan_msix,
- ice_get_avail_txq_count(pf),
- (u16)num_online_cpus());
if (vsi->req_txq) {
vsi->alloc_txq = vsi->req_txq;
vsi->num_txq = vsi->req_txq;
+   } else {
+   vsi->alloc_txq = min3(pf->num_lan_msix,
+ice_get_avail_txq_count(pf),
+(u16)num_online_cpus());
}
 
pf->num_lan_tx = vsi->alloc_txq;
@@ -175,12 +176,13 @@ static void ice_vsi_set_num_qs(struct ice_vsi *vsi, u16 
vf_id)
if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
vsi->alloc_rxq = 1;
} else {
-   vsi->alloc_rxq = min3(pf->num_lan_msix,
- ice_get_avail_rxq_count(pf),
- (u16)num_online_cpus());
if (vsi->req_rxq) {
vsi->alloc_rxq = vsi->req_rxq;
vsi->num_rxq = vsi->req_rxq;
+   } else {
+   vsi->alloc_rxq = min3(pf->num_lan_msix,
+ice_get_avail_rxq_count(pf),
+(u16)num_online_cpus());
}
}
 
-- 
2.17.1



[PATCH net] net: hns3: Trivial spell fix in hns3 driver

2021-04-09 Thread Salil Mehta
Some trivial spelling mistakes which caught my eye during the
review of the code.

Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c   | 2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 4 ++--
 2 files 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 2dd2af269b46..b0dbe6dcaa7b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -11210,7 +11210,7 @@ static int hclge_set_channels(struct hnae3_handle 
*handle, u32 new_tqps_num,
if (ret)
return ret;
 
-   /* RSS indirection table has been configuared by user */
+   /* RSS indirection table has been configured by user */
if (rxfh_configured)
goto out;
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index 700e068764c8..4c5ec5e38cea 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -2193,7 +2193,7 @@ static void hclgevf_reset_service_task(struct hclgevf_dev 
*hdev)
 
if (test_and_clear_bit(HCLGEVF_RESET_PENDING,
   &hdev->reset_state)) {
-   /* PF has initmated that it is about to reset the hardware.
+   /* PF has intimated that it is about to reset the hardware.
 * We now have to poll & check if hardware has actually
 * completed the reset sequence. On hardware reset completion,
 * VF needs to reset the client and ae device.
@@ -3497,7 +3497,7 @@ static int hclgevf_set_channels(struct hnae3_handle 
*handle, u32 new_tqps_num,
if (ret)
return ret;
 
-   /* RSS indirection table has been configuared by user */
+   /* RSS indirection table has been configured by user */
if (rxfh_configured)
goto out;
 
-- 
2.17.1



RE: [Linuxarm] Re: [PATCH net] net: hns3: Limiting the scope of vector_ring_chain variable

2021-04-06 Thread Salil Mehta
Hi Dave,
Hope I am not missing something and not sure how this patchwork bot works,
the patch was sent for -net repo (i.e. bug fixes branch) but it got applied
to the -net-next repo.

> Subject: [Linuxarm] Re: [PATCH net] net: hns3: Limiting the scope of
> vector_ring_chain variable

[...]

> Hello:
> 
> This patch was applied to netdev/net-next.git (refs/heads/master):
>

I was wondering if I missed anything in my submission or because of some
other reason this patch was chosen to be applied to the -net-next repo
instead. Perhaps this is not classified as bug?

Many thanks
Salil

> From: patchwork-bot+netdev...@kernel.org
> [mailto:patchwork-bot+netdev...@kernel.org]
> Sent: Monday, April 5, 2021 11:10 PM
> To: Salil Mehta 
> Cc: da...@davemloft.net; k...@kernel.org; netdev@vger.kernel.org;
> linux-ker...@vger.kernel.org; Linuxarm ;
> linux...@openeuler.org
> Subject: [Linuxarm] Re: [PATCH net] net: hns3: Limiting the scope of
> vector_ring_chain variable
> 
> Hello:
> 
> This patch was applied to netdev/net-next.git (refs/heads/master):
> 
> On Mon, 5 Apr 2021 18:28:25 +0100 you wrote:
> > Limiting the scope of the variable vector_ring_chain to the block where it
> > is used.
> >
> > Fixes: 424eb834a9be ("net: hns3: Unified HNS3 {VF|PF} Ethernet Driver for 
> > hip08
> SoC")
> > Signed-off-by: Salil Mehta 
> > ---
> >  drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> Here is the summary with links:
>   - [net] net: hns3: Limiting the scope of vector_ring_chain variable
> https://git.kernel.org/netdev/net-next/c/d392ecd1bc29
> 
> You are awesome, thank you!
> --
> Deet-doot-dot, I am a bot.
> https://korg.docs.kernel.org/patchwork/pwbot.html
> 
> ___
> Linuxarm mailing list -- linux...@openeuler.org
> To unsubscribe send an email to linuxarm-le...@openeuler.org


[PATCH net] net: hns3: Limiting the scope of vector_ring_chain variable

2021-04-05 Thread Salil Mehta
Limiting the scope of the variable vector_ring_chain to the block where it
is used.

Fixes: 424eb834a9be ("net: hns3: Unified HNS3 {VF|PF} Ethernet Driver for hip08 
SoC")
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index bf4302a5cf95..65752f363f43 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -3704,7 +3704,6 @@ static void hns3_nic_set_cpumask(struct hns3_nic_priv 
*priv)
 
 static int hns3_nic_init_vector_data(struct hns3_nic_priv *priv)
 {
-   struct hnae3_ring_chain_node vector_ring_chain;
struct hnae3_handle *h = priv->ae_handle;
struct hns3_enet_tqp_vector *tqp_vector;
int ret;
@@ -3736,6 +3735,8 @@ static int hns3_nic_init_vector_data(struct hns3_nic_priv 
*priv)
}
 
for (i = 0; i < priv->vector_num; i++) {
+   struct hnae3_ring_chain_node vector_ring_chain;
+
tqp_vector = &priv->tqp_vector[i];
 
tqp_vector->rx_group.total_bytes = 0;
-- 
2.17.1



[PATCH V2 net 2/2] net: hns3: Remove un-necessary 'else-if' in the hclge_reset_event()

2021-04-05 Thread Salil Mehta
Code to defer the reset(which caps the frequency of the reset) schedules the
timer and returns. Hence, following 'else-if' looks un-necessary.

Fixes: 9de0b86f6444 ("net: hns3: Prevent to request reset frequently")
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 4 +++-
 1 file changed, 3 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 58d210bbb311..2dd2af269b46 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3980,7 +3980,9 @@ static void hclge_reset_event(struct pci_dev *pdev, 
struct hnae3_handle *handle)
  HCLGE_RESET_INTERVAL))) {
mod_timer(&hdev->reset_timer, jiffies + HCLGE_RESET_INTERVAL);
return;
-   } else if (hdev->default_reset_request) {
+   }
+
+   if (hdev->default_reset_request) {
hdev->reset_level =
hclge_get_reset_level(ae_dev,
  &hdev->default_reset_request);
-- 
2.17.1



[PATCH V2 net 0/2] Misc. fixes for hns3 driver

2021-04-05 Thread Salil Mehta
Fixes for the miscellaneous problems found during the review of the code.

Change Summary:
 Patch 1/2, Change V1->V2:
   [1] Fixed comments from Leon Romanovsky
   Link: https://lkml.org/lkml/2021/4/4/14
 Patch 2/2, Change V1->V2:
   None

Salil Mehta (2):
  net: hns3: Remove the left over redundant check & assignment
  net: hns3: Remove un-necessary 'else-if' in the hclge_reset_event()

 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

-- 
2.17.1



[PATCH V2 net 1/2] net: hns3: Remove the left over redundant check & assignment

2021-04-05 Thread Salil Mehta
This removes the left over check and assignment which is no longer used
anywhere in the function and should have been removed as part of the
below mentioned patch.

Fixes: 012fcb52f67c ("net: hns3: activate reset timer when calling reset_event")
Signed-off-by: Salil Mehta 
--
V1->V2:
[1] Fixed comments from Leon Romanovsky
Link: https://lkml.org/lkml/2021/4/4/14
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 3 ---
 1 file changed, 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 e3f81c7e0ce7..58d210bbb311 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3966,7 +3966,6 @@ static void hclge_reset_event(struct pci_dev *pdev, 
struct hnae3_handle *handle)
 *normalcy is to reset.
 * 2. A new reset request from the stack due to timeout
 *
-* For the first case,error event might not have ae handle available.
 * check if this is a new reset request and we are not here just because
 * last reset attempt did not succeed and watchdog hit us again. We will
 * know this if last reset request did not occur very recently (watchdog
@@ -3976,8 +3975,6 @@ static void hclge_reset_event(struct pci_dev *pdev, 
struct hnae3_handle *handle)
 * want to make sure we throttle the reset request. Therefore, we will
 * not allow it again before 3*HZ times.
 */
-   if (!handle)
-   handle = &hdev->vport[0].nic;
 
if (time_before(jiffies, (hdev->last_reset_time +
  HCLGE_RESET_INTERVAL))) {
-- 
2.17.1



RE: [PATCH net 1/2] net: hns3: Remove the left over redundant check & assignment

2021-04-05 Thread Salil Mehta
> From: Leon Romanovsky [mailto:l...@kernel.org]
> Sent: Monday, April 5, 2021 1:43 PM
> To: Salil Mehta 
> Cc: da...@davemloft.net; k...@kernel.org; netdev@vger.kernel.org;
> linux-ker...@vger.kernel.org; Linuxarm ;
> linux...@openeuler.org
> Subject: Re: [PATCH net 1/2] net: hns3: Remove the left over redundant check
> & assignment
> 
> On Mon, Apr 05, 2021 at 12:26:37PM +, Salil Mehta wrote:
> > Hi Leon,
> > Thanks for the review.
> >
> > > From: Leon Romanovsky [mailto:l...@kernel.org]
> > > Sent: Sunday, April 4, 2021 7:26 AM
> > > To: Salil Mehta 
> > > Cc: da...@davemloft.net; k...@kernel.org; netdev@vger.kernel.org;
> > > linux-ker...@vger.kernel.org; Linuxarm ;
> > > linux...@openeuler.org
> > > Subject: Re: [PATCH net 1/2] net: hns3: Remove the left over redundant 
> > > check
> > > & assignment
> > >
> > > On Sat, Apr 03, 2021 at 02:35:19AM +0100, Salil Mehta wrote:
> > > > This removes the left over check and assignment which is no longer used
> > > > anywhere in the function and should have been removed as part of the
> > > > below mentioned patch.
> > > >
> > > > Fixes: 012fcb52f67c ("net: hns3: activate reset timer when calling
> > > reset_event")
> > > > Signed-off-by: Salil Mehta 
> > > > ---
> > > >  drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 2 --
> > > >  1 file changed, 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 e3f81c7e0ce7..7ad0722383f5 100644
> > > > --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
> > > > +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
> > > > @@ -3976,8 +3976,6 @@ static void hclge_reset_event(struct pci_dev 
> > > > *pdev,
> > > struct hnae3_handle *handle)
> > > >  * want to make sure we throttle the reset request. Therefore, 
> > > > we will
> > > >  * not allow it again before 3*HZ times.
> > > >  */
> > > > -   if (!handle)
> > > > -   handle = &hdev->vport[0].nic;
> > >
> > > The comment above should be updated too, and probably the signature of
> > > hclge_reset_event() worth to be changed.
> >
> >
> > Yes, true. Both the comment and the prototype will be updated in near 
> > future.
> > I can assure you this did not go un-noticed during the change. There are
> > some internal subtleties which I am trying to sort out. Those might come
> > as part of different patch-set which deals with other related changes as 
> > well.
> 
> I can buy such explanation for the change in function signature, but have hard
> time to believe that extra commit is needed to change comment above.

Sure, I understand your point. Earlier I thought to retain the comment for 
reference
and make it part of the refactor change. But will send another version changing
the comment now. No issues :)

Many thanks

> 
> Thanks
> 
> >
> > The current change(and some other) will pave the way for necessary 
> > refactoring
> > Of the code being done.
> >
> >
> > >
> > > Thanks
> > >
> > > >
> > > > if (time_before(jiffies, (hdev->last_reset_time +
> > > >   HCLGE_RESET_INTERVAL))) {
> > > > --
> > > > 2.17.1
> > > >


RE: [PATCH net 1/2] net: hns3: Remove the left over redundant check & assignment

2021-04-05 Thread Salil Mehta
Hi Leon,
Thanks for the review.

> From: Leon Romanovsky [mailto:l...@kernel.org]
> Sent: Sunday, April 4, 2021 7:26 AM
> To: Salil Mehta 
> Cc: da...@davemloft.net; k...@kernel.org; netdev@vger.kernel.org;
> linux-ker...@vger.kernel.org; Linuxarm ;
> linux...@openeuler.org
> Subject: Re: [PATCH net 1/2] net: hns3: Remove the left over redundant check
> & assignment
> 
> On Sat, Apr 03, 2021 at 02:35:19AM +0100, Salil Mehta wrote:
> > This removes the left over check and assignment which is no longer used
> > anywhere in the function and should have been removed as part of the
> > below mentioned patch.
> >
> > Fixes: 012fcb52f67c ("net: hns3: activate reset timer when calling
> reset_event")
> > Signed-off-by: Salil Mehta 
> > ---
> >  drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 2 --
> >  1 file changed, 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 e3f81c7e0ce7..7ad0722383f5 100644
> > --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
> > +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
> > @@ -3976,8 +3976,6 @@ static void hclge_reset_event(struct pci_dev *pdev,
> struct hnae3_handle *handle)
> >  * want to make sure we throttle the reset request. Therefore, we will
> >  * not allow it again before 3*HZ times.
> >  */
> > -   if (!handle)
> > -   handle = &hdev->vport[0].nic;
> 
> The comment above should be updated too, and probably the signature of
> hclge_reset_event() worth to be changed.


Yes, true. Both the comment and the prototype will be updated in near future.
I can assure you this did not go un-noticed during the change. There are
some internal subtleties which I am trying to sort out. Those might come
as part of different patch-set which deals with other related changes as well.

The current change(and some other) will pave the way for necessary refactoring
Of the code being done.


> 
> Thanks
> 
> >
> > if (time_before(jiffies, (hdev->last_reset_time +
> >   HCLGE_RESET_INTERVAL))) {
> > --
> > 2.17.1
> >


[PATCH net 2/2] net: hns3: Remove un-necessary 'else-if' in the hclge_reset_event()

2021-04-02 Thread Salil Mehta
Code to defer the reset(which caps the frequency of the reset) schedules the
timer and returns. Hence, following 'else-if' looks un-necessary.

Fixes: 9de0b86f6444 ("net: hns3: Prevent to request reset frequently")
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 4 +++-
 1 file changed, 3 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 7ad0722383f5..2ed464e13d1b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3981,7 +3981,9 @@ static void hclge_reset_event(struct pci_dev *pdev, 
struct hnae3_handle *handle)
  HCLGE_RESET_INTERVAL))) {
mod_timer(&hdev->reset_timer, jiffies + HCLGE_RESET_INTERVAL);
return;
-   } else if (hdev->default_reset_request) {
+   }
+
+   if (hdev->default_reset_request) {
hdev->reset_level =
hclge_get_reset_level(ae_dev,
  &hdev->default_reset_request);
-- 
2.17.1



[PATCH net 1/2] net: hns3: Remove the left over redundant check & assignment

2021-04-02 Thread Salil Mehta
This removes the left over check and assignment which is no longer used
anywhere in the function and should have been removed as part of the
below mentioned patch.

Fixes: 012fcb52f67c ("net: hns3: activate reset timer when calling reset_event")
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 2 --
 1 file changed, 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 e3f81c7e0ce7..7ad0722383f5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3976,8 +3976,6 @@ static void hclge_reset_event(struct pci_dev *pdev, 
struct hnae3_handle *handle)
 * want to make sure we throttle the reset request. Therefore, we will
 * not allow it again before 3*HZ times.
 */
-   if (!handle)
-   handle = &hdev->vport[0].nic;
 
if (time_before(jiffies, (hdev->last_reset_time +
  HCLGE_RESET_INTERVAL))) {
-- 
2.17.1



[PATCH net 0/2] Misc. fixes for hns3 driver

2021-04-02 Thread Salil Mehta
Fixes for the miscellaneous problems found during the review of the code.

Salil Mehta (2):
  net: hns3: Remove the left over redundant check & assignment
  net: hns3: Remove un-necessary 'else-if' in the hclge_reset_event()

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

-- 
2.17.1



RE: [PATCH V2 net-next 0/2] net: hns3: adds two VLAN feature

2020-05-28 Thread Salil Mehta
Hi Jakub/David,

> From: Jakub Kicinski [mailto:k...@kernel.org]
> Sent: Wednesday, May 27, 2020 8:31 PM
> To: tanhuazhong 
> Cc: David Miller ; netdev@vger.kernel.org;
> linux-ker...@vger.kernel.org; Salil Mehta ;
> Zhuangyuzeng (Yisen) ; Linuxarm 
> Subject: Re: [PATCH V2 net-next 0/2] net: hns3: adds two VLAN feature
> 
> On Wed, 27 May 2020 10:31:59 +0800 tanhuazhong wrote:
> > Hi, Jakub & David.
> >
> > For patch#1, is it acceptable adding "ethtool --get-priv-flags"
> > to query the VLAN. If yes, I will send a RFC for it.
> 
> The recommended way of implementing vfs with advanced vlan
> configurations is via "switchdev mode" & representors.

AFAIK, switchdev ops only facilitates the standard abstract
interface to any underlying standard or proprietary hardware
which could be ASIC, eswitch etc. Therefore, standard tools
like ip, bridge or even stacks like FRR etc. could be used
while leveraging the below hardware forwarding.

Not sure how will switchdev ops will be of help here?


Just curious how does Mellanox supports Hybrid port mode?

In general, 
We can have port being configured as Access/Trunk ports.

Access port = Only untagged packets are sent or are expected.
RX'ed Tagged packets are dropped.
Trunk Port  = Only Tagged packet are received or sent and any
Untagged packets received are dropped.

Mellanox also support Hybrid mode in Onyx platform:

Hybrid - packets are sent tagged or untagged, the port
expects both tagged and untagged packets. This mode is
a combination of Access and Trunk modes. There is an
option to configure multiple VLANs on the hybrid port.
PVID is configured on the port for untagged ingress
packets.

First two configuration are easy to realize using the
standard Linux configuration tools like ip/bridge but
not sure about the hybrid? also, why do we even need
to create a bridge to realize any of above port modes?

Note: HNS hardware does not have eswitch support.


Salil.



RE: Question about setting speed and duplex failed after auto-negotiation disabled on marvell phy

2019-03-01 Thread Salil Mehta
(+) LinuxArm

> From: Michal Vokáč [mailto:michal.vo...@ysoft.com]
> Sent: Friday, March 1, 2019 12:58 PM
> To: liweihang 
> Cc: netdev@vger.kernel.org; da...@davemloft.net; linyunsheng
> ; Zhuangyuzeng (Yisen)
> ; Salil Mehta ; lipeng
> (Y) ; shenjian (K) 
> Subject: Re: Question about setting speed and duplex failed after auto-
> negotiation disabled on marvell phy
> 
> On 01. 03. 19 12:26, liweihang wrote:
> > Hi all,
> >
> > We encountered a problem that if there are two devices in kernel v5.0 with
> > marvell phy 88E1510 connect with each other directly, one with autoneg on 
> > and
> > the other off. The one who has disabled auto-negotiation will failed on 
> > setting
> > speed and duplex mode. Their speed and duplex mode will go to 10M/half. And
> > no matter what speed and duplex we set by ethtool -s ethx speed XX duplex 
> > full,
> > they will go to 10M/half. If we disable auto-negotiation on both sides and 
> > set
> > same speed and duplex, there speed and duplex mode will go to Unknown.
> >
> > I found that m88e1121_config_aneg() has been modified by commit
> > d6ab93364734 net: phy: marvell: Avoid unnecessary soft reset
> > And in that patch, genphy_soft_reset() was moved below genphy_config_aneg(),
> > which caused value of speed and duplex in MII_BMCR was cleared. And then 
> > they
> > will go to 10M/half.
> >
> > static int m88e1121_config_aneg(struct phy_device *phydev)
> > {
> > +   int changed = 0;
> > int err = 0;
> >
> >  if (phy_interface_is_rgmii(phydev)) {
> > @@ -487,15 +455,26 @@  static int m88e1121_config_aneg(struct phy_device 
> > *phydev)
> >return err;
> > }
> >
> > -err = genphy_soft_reset(phydev);
> > +   err = marvell_set_polarity(phydev, phydev->mdix_ctrl);
> > if (err < 0)
> >  return err;
> >
> > -err = marvell_set_polarity(phydev, phydev->mdix_ctrl);
> > +   changed = err;
> > +
> > +   err = genphy_config_aneg(phydev);
> > if (err < 0)
> >  return err;
> >
> > -return genphy_config_aneg(phydev);
> > +   if (phydev->autoneg != autoneg || changed) {
> > +/* A software reset is used to ensure a "commit" of the
> > +* changes is done.
> > +*/
> > +err = genphy_soft_reset(phydev);
> > +if (err < 0)
> > +  return err;
> > +   }
> > +
> > +   return 0;
> > }
> >
> > I moved genphy_soft_reset back and it tested ok. And in my opinion, if we 
> > have to do
> > soft reset after genphy_config_aneg(phydev), it should be like this:
> >
> >   if (phydev->autoneg != AUTONEG_ENABLE) {
> > int bmcr;
> >
> > bmcr = phy_read(phydev, MII_BMCR);
> > if (bmcr < 0)
> >  return bmcr;
> >
> > err = phy_write(phydev, MII_BMCR, bmcr | BMCR_RESET);
> > if (err < 0)
> >return err;
> > }
> >
> > The above code has been mentioned in commit 3438634456c4
> > net: phy: marvell: Use core genphy_soft_reset(), phy_write() was replaced by
> > genphy_soft_reset() in that patch.
> >
> > I think this issue will affect devices with Marvell PHY ID 
> > 88E1112//1121/
> > 1318/1240/1510/1540/1545/6390.
> >
> > If there are any better info or suggestion regarding this problem, it would 
> > be very
> > helpful, thanks in advance.
> 
> I am not sure what exact -rc version you are using (kernel v5.0 is not yet
> released). I would recommend you to test the latest linux-next or even
> net-next as there is quite a lot of new patches and fixes targeting Marvell
> chips.
> 
> Best regards,
> Michal
> >
> > reference:
> > [1] https://lore.kernel.org/patchwork/patch/991682/
> > [2] https://patchwork.ozlabs.org/patch/795435/
> >



RE: [PATCH] net: hns: Fix object reference leaks in hns_dsaf_roce_reset()

2019-02-18 Thread Salil Mehta
> From: John Garry
> Sent: Friday, February 15, 2019 12:00 PM
> 
> On 15/02/2019 11:25, Salil Mehta wrote:
> >> From: John Garry
> >> Sent: Friday, February 15, 2019 10:52 AM
> >>
> >> On 14/02/2019 06:41, Huang Zijiang wrote:
> >>> The of_find_device_by_node() takes a reference to the underlying device
> >>> structure, we should release that reference.
> >>
> >> of_find_device_by_node() is not called for every path, so is this change 
> >> proper:
> >
> >
> > It looks okay to me and with the suggested device reference is being
> > released from every possible error leg in the function. Could you be
> > more specific which error path is not being addressed?
> >
> >>/* find the platform device corresponding to fwnode */
> >>if (is_of_node(dsaf_fwnode)) {
> >>pdev = of_find_device_by_node(to_of_node(dsaf_fwnode));
> >
> >
> > This will get the reference to the device, which needs to be
> > released later.
> >
> >
> >>} else if (is_acpi_device_node(dsaf_fwnode)) {
> >>pdev = hns_dsaf_find_platform_device(dsaf_fwnode);
> >
> >
> > This will also get the reference to the device when bus_find_device()
> > gets called and returns the 'device'. Therefore, this needs to be
> > released as well using put_device()
> 
> OK, I see. That's non-obvious.
> 
> And so the commit message was simply incomplete.
> 
> So who finally drops this reference? This patch only seems to release on
> error path. I checked the callers and they don't seem to.


Yes, in the positive leg the put_device() was missing. Thanks for identifying!
I have floated the patch to fix it https://www.lkml.org/lkml/2019/2/18/1161


Salil.



[PATCH net] net: hns: Fixes the missing put_device in positive leg for roce reset

2019-02-18 Thread Salil Mehta
This patch fixes the missing device reference release-after-use in
the positive leg of the roce reset API of the HNS DSAF.

Fixes: c969c6e7ab8c ("net: hns: Fix object reference leaks in 
hns_dsaf_roce_reset()")
Reported-by: John Garry 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c 
b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
index b8155f5..ac55db0 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
@@ -3128,6 +3128,9 @@ int hns_dsaf_roce_reset(struct fwnode_handle 
*dsaf_fwnode, bool dereset)
dsaf_set_bit(credit, DSAF_SBM_ROCEE_CFG_CRD_EN_B, 1);
dsaf_write_dev(dsaf_dev, DSAF_SBM_ROCEE_CFG_REG_REG, credit);
}
+
+   put_device(&pdev->dev);
+
return 0;
 }
 EXPORT_SYMBOL(hns_dsaf_roce_reset);
-- 
2.7.4




RE: [PATCH] net: hns: Fix object reference leaks in hns_dsaf_roce_reset()

2019-02-15 Thread Salil Mehta
> From: John Garry
> Sent: Friday, February 15, 2019 10:52 AM
> 
> On 14/02/2019 06:41, Huang Zijiang wrote:
> > The of_find_device_by_node() takes a reference to the underlying device
> > structure, we should release that reference.
> 
> of_find_device_by_node() is not called for every path, so is this change 
> proper:


It looks okay to me and with the suggested device reference is being
released from every possible error leg in the function. Could you be
more specific which error path is not being addressed?



>   /* find the platform device corresponding to fwnode */
>   if (is_of_node(dsaf_fwnode)) {
>   pdev = of_find_device_by_node(to_of_node(dsaf_fwnode));


This will get the reference to the device, which needs to be
released later.


>   } else if (is_acpi_device_node(dsaf_fwnode)) {
>   pdev = hns_dsaf_find_platform_device(dsaf_fwnode);


This will also get the reference to the device when bus_find_device()
gets called and returns the 'device'. Therefore, this needs to be
released as well using put_device()



>   } else {
>   pr_err("fwnode is neither OF or ACPI type\n");
>   return -EINVAL;
>   }
> 
>   /* check if we were a success in fetching pdev */
>   if (!pdev) {
>   pr_err("couldn't find platform device for node\n");
>   return -ENODEV;
>   }
> 
>   /* retrieve the dsaf_device from the driver data */
>   dsaf_dev = dev_get_drvdata(&pdev->dev);
>   if (!dsaf_dev) {
>   dev_err(&pdev->dev, "dsaf_dev is NULL\n");
>   return -ENODEV;
>   }
> 
> John


[...]

> > --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
> > +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
> > @@ -3081,6 +3081,7 @@ int hns_dsaf_roce_reset(struct fwnode_handle 
> > *dsaf_fwnode, bool dereset)
> > dsaf_dev = dev_get_drvdata(&pdev->dev);
> > if (!dsaf_dev) {
> > dev_err(&pdev->dev, "dsaf_dev is NULL\n");
> > +   put_device(&pdev->dev);


This looks okay.


> > return -ENODEV;
> > }
> >
> > @@ -3088,6 +3089,7 @@ int hns_dsaf_roce_reset(struct fwnode_handle 
> > *dsaf_fwnode, bool dereset)
> > if (AE_IS_VER1(dsaf_dev->dsaf_ver)) {
> > dev_err(dsaf_dev->dev, "%s v1 chip doesn't support RoCE!\n",
> > dsaf_dev->ae_dev.name);
> > +   put_device(&pdev->dev);


This looks okay.


Salil.


RE: [PATCH net-next] net: hns3: Fix potential NULL dereference on allocation error

2019-01-28 Thread Salil Mehta
> From: yuehaibing
> Sent: Friday, January 25, 2019 3:14 AM
> To: da...@davemloft.net; Zhuangyuzeng (Yisen) ;
> Salil Mehta ; lipeng (Y) 
> Cc: linux-ker...@vger.kernel.org; netdev@vger.kernel.org; yuehaibing 
> 
> Subject: [PATCH net-next] net: hns3: Fix potential NULL dereference on
> allocation error
> 
> hclge_mac_update_stats_complete doesn't check for NULL
> returns of kcalloc, it may result in an Oops.
> 
> Fixes: d174ea75c96a ("net: hns3: add statistics for PFC frames and MAC
> control frames")
> Signed-off-by: YueHaibing 
> ---
>  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 64b1589..7971606 100644
> --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
> @@ -343,6 +343,9 @@ static int hclge_mac_update_stats_complete(struct
> hclge_dev *hdev, u32 desc_num)
>   int ret;
> 
>   desc = kcalloc(desc_num, sizeof(struct hclge_desc), GFP_KERNEL);
> + if (!desc)
> + return -ENOMEM;
> +


looks good to me.

Reviewed-by: Salil Mehta 




RE: hns: question regarding ae_node device node refcounting

2019-01-11 Thread Salil Mehta
Hi Alexey,

> From: Alexey Khoroshilov [mailto:khoroshi...@ispras.ru]
> Sent: Saturday, December 22, 2018 9:55 PM
> To: Zhuangyuzeng (Yisen) ; Salil Mehta
> ; lipeng (Y) 
> Cc: Alexey Khoroshilov ; David S. Miller
> ; netdev@vger.kernel.org; linux-
> ker...@vger.kernel.org; ldv-proj...@linuxtesting.org
> Subject: net: hns: question regarding ae_node device node refcounting
> 
> Hello,
> 
> hns_nic_dev_probe() increments refcount of ae_node device node:
>   ae_node = of_parse_phandle(dev->of_node, "ae-handle", 0);
> 
> But there is no of_node_put() for ae_node.
> What is the right place to decrement the ae_node refount?
> 
> Should it be placed in hns_nic_dev_probe() or in hns_nic_dev_remove()?
> Or may be it is managed by fwnode somehow?

Thanks for bringing this to notice. Yes, you are right of_node_put()
is missing. We will float a fix for this soon.

Cheers
Salil


[PATCH V2 net-next 3/6] net: hns3: Add "status register" information query function

2018-12-15 Thread Salil Mehta
From: liuzhongzhu 

This patch prints status register information by module.

debugfs command:
echo dump reg [mode name] > cmd

Sample Command:
root@(none)# echo dump reg bios common > cmd
 BP_CPU_STATE: 0x0
 DFX_MSIX_INFO_NIC_0: 0xc000
 DFX_MSIX_INFO_NIC_1: 0xf
 DFX_MSIX_INFO_NIC_2: 0x2
 DFX_MSIX_INFO_NIC_3: 0x2
 DFX_MSIX_INFO_ROC_0: 0xc000
 DFX_MSIX_INFO_ROC_1: 0x0
 DFX_MSIX_INFO_ROC_2: 0x0
 DFX_MSIX_INFO_ROC_3: 0x0
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c |  15 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  14 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 194 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h | 662 +
 4 files changed, 885 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 4c5a421456b7..e6268e03d221 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -201,6 +201,10 @@ static int hns3_dbg_bd_info(struct hnae3_handle *h, char 
*cmd_buf)
 
 static void hns3_dbg_help(struct hnae3_handle *h)
 {
+#define HNS3_DBG_BUF_LEN 256
+
+   char printf_buf[HNS3_DBG_BUF_LEN];
+
dev_info(&h->pdev->dev, "available commands\n");
dev_info(&h->pdev->dev, "queue info [number]\n");
dev_info(&h->pdev->dev, "bd info [q_num] \n");
@@ -211,6 +215,17 @@ static void hns3_dbg_help(struct hnae3_handle *h)
dev_info(&h->pdev->dev, "dump qos pri map\n");
dev_info(&h->pdev->dev, "dump qos buf cfg\n");
dev_info(&h->pdev->dev, "dump mng tbl\n");
+
+   memset(printf_buf, 0, HNS3_DBG_BUF_LEN);
+   strncat(printf_buf, "dump reg [[bios common] [ssu ]",
+   HNS3_DBG_BUF_LEN - 1);
+   strncat(printf_buf + strlen(printf_buf),
+   " [igu egu ] [rpu ]",
+   HNS3_DBG_BUF_LEN - strlen(printf_buf) - 1);
+   strncat(printf_buf + strlen(printf_buf),
+   " [rtc] [ppp] [rcb] [tqp ]]\n",
+   HNS3_DBG_BUF_LEN - strlen(printf_buf) - 1);
+   dev_info(&h->pdev->dev, "%s", printf_buf);
 }
 
 static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index dcacfa089b74..2b281d909f51 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -86,6 +86,20 @@ enum hclge_opcode_type {
HCLGE_OPC_QUERY_REG_NUM = 0x0040,
HCLGE_OPC_QUERY_32_BIT_REG  = 0x0041,
HCLGE_OPC_QUERY_64_BIT_REG  = 0x0042,
+   HCLGE_OPC_DFX_BD_NUM= 0x0043,
+   HCLGE_OPC_DFX_BIOS_COMMON_REG   = 0x0044,
+   HCLGE_OPC_DFX_SSU_REG_0 = 0x0045,
+   HCLGE_OPC_DFX_SSU_REG_1 = 0x0046,
+   HCLGE_OPC_DFX_IGU_EGU_REG   = 0x0047,
+   HCLGE_OPC_DFX_RPU_REG_0 = 0x0048,
+   HCLGE_OPC_DFX_RPU_REG_1 = 0x0049,
+   HCLGE_OPC_DFX_NCSI_REG  = 0x004A,
+   HCLGE_OPC_DFX_RTC_REG   = 0x004B,
+   HCLGE_OPC_DFX_PPP_REG   = 0x004C,
+   HCLGE_OPC_DFX_RCB_REG   = 0x004D,
+   HCLGE_OPC_DFX_TQP_REG   = 0x004E,
+   HCLGE_OPC_DFX_SSU_REG_2 = 0x004F,
+   HCLGE_OPC_DFX_QUERY_CHIP_CAP= 0x0050,
 
/* MAC command */
HCLGE_OPC_CONFIG_MAC_MODE   = 0x0301,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
index 77a11618040d..7d18ed8e17f0 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
@@ -9,6 +9,198 @@
 #include "hclge_tm.h"
 #include "hnae3.h"
 
+static int hclge_dbg_get_dfx_bd_num(struct hclge_dev *hdev, int offset)
+{
+   struct hclge_desc desc[4];
+   int ret;
+
+   hclge_cmd_setup_basic_desc(&desc[0], HCLGE_OPC_DFX_BD_NUM, true);
+   desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+   hclge_cmd_setup_basic_desc(&desc[1], HCLGE_OPC_DFX_BD_NUM, true);
+   desc[1].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+   hclge_cmd_setup_basic_desc(&desc[2], HCLGE_OPC_DFX_BD_NUM, true);
+   desc[2].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+   hclge_cmd_setup_basic_desc(&desc[3], HCLGE_OPC_DFX_BD_NUM, true);
+
+   ret = hclge_cmd_send(&hdev->hw, desc, 4);
+   if (ret != HCLGE_CMD_EXEC_SUCCESS) {
+   dev_err(&hdev->pdev->dev,
+   "get dfx bdnum fail, status is %d.\n", ret);
+   return ret

[PATCH V2 net-next 2/6] net: hns3: Add "manager table" information query function

2018-12-15 Thread Salil Mehta
From: liuzhongzhu 

This patch prints manager table information.

debugfs command:
echo dump mng tbl > cmd

Sample Command:
root@(none)# echo dump mng tbl > cmd
 entry|mac_addr |mask|ether|mask|vlan|mask|i_map|i_dir|e_type
 00   |01:00:5e:00:00:01|0   |0|0   ||0   |00   |00   |0
 01   |c2:f1:c5:82:68:17|0   |0|0   ||0   |00   |00   |0
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c |  5 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h | 19 +++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 66 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h | 12 
 4 files changed, 100 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 9a026556df0e..4c5a421456b7 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -48,7 +48,7 @@ static int hns3_dbg_queue_info(struct hnae3_handle *h, char 
*cmd_buf)
 * to prevent reference to invalid memory. And need to ensure
 * that the following code is executed within 100ms.
 */
-   if (test_bit(HNS3_NIC_STATE_INITED, &priv->state) ||
+   if (!test_bit(HNS3_NIC_STATE_INITED, &priv->state) ||
test_bit(HNS3_NIC_STATE_RESETTING, &priv->state))
return -EPERM;
 
@@ -210,6 +210,7 @@ static void hns3_dbg_help(struct hnae3_handle *h)
dev_info(&h->pdev->dev, "dump qos pause cfg\n");
dev_info(&h->pdev->dev, "dump qos pri map\n");
dev_info(&h->pdev->dev, "dump qos buf cfg\n");
+   dev_info(&h->pdev->dev, "dump mng tbl\n");
 }
 
 static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
@@ -254,7 +255,7 @@ static ssize_t hns3_dbg_cmd_write(struct file *filp, const 
char __user *buffer,
return 0;
 
/* Judge if the instance is being reset. */
-   if (test_bit(HNS3_NIC_STATE_INITED, &priv->state) ||
+   if (!test_bit(HNS3_NIC_STATE_INITED, &priv->state) ||
test_bit(HNS3_NIC_STATE_RESETTING, &priv->state))
return 0;
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index b1ee6feb0caf..dcacfa089b74 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -237,6 +237,7 @@ enum hclge_opcode_type {
HCLGE_TM_QCN_MEM_INT_CFG= 0x1A14,
HCLGE_PPP_CMD0_INT_CMD  = 0x2100,
HCLGE_PPP_CMD1_INT_CMD  = 0x2101,
+   HCLGE_MAC_ETHERTYPE_IDX_RD  = 0x2105,
HCLGE_NCSI_INT_EN   = 0x2401,
 };
 
@@ -744,6 +745,24 @@ struct hclge_cfg_tx_queue_pointer_cmd {
u8 rsv[14];
 };
 
+#pragma pack(1)
+struct hclge_mac_ethertype_idx_rd_cmd {
+   u8  flags;
+   u8  resp_code;
+   __le16  vlan_tag;
+   u8  mac_add[6];
+   __le16  index;
+   __le16  ethter_type;
+   __le16  egress_port;
+   __le16  egress_queue;
+   __le16  rev0;
+   u8  i_port_bitmap;
+   u8  i_port_direction;
+   u8  rev1[2];
+};
+
+#pragma pack()
+
 #define HCLGE_TSO_MSS_MIN_S0
 #define HCLGE_TSO_MSS_MIN_MGENMASK(13, 0)
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
index 14577bbf3e11..77a11618040d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
@@ -407,6 +407,70 @@ static void hclge_dbg_dump_qos_buf_cfg(struct hclge_dev 
*hdev)
"dump qos buf cfg fail(0x%x), status is %d\n", cmd, ret);
 }
 
+static void hclge_dbg_dump_mng_table(struct hclge_dev *hdev)
+{
+   struct hclge_mac_ethertype_idx_rd_cmd *req0;
+   char printf_buf[HCLGE_DBG_BUF_LEN];
+   struct hclge_desc desc;
+   int ret, i;
+
+   dev_info(&hdev->pdev->dev, "mng tab:\n");
+   memset(printf_buf, 0, HCLGE_DBG_BUF_LEN);
+   strncat(printf_buf,
+   "entry|mac_addr |mask|ether|mask|vlan|mask",
+   HCLGE_DBG_BUF_LEN - 1);
+   strncat(printf_buf + strlen(printf_buf),
+   "|i_map|i_dir|e_type|pf_id|vf_id|q_id|drop\n",
+   HCLGE_DBG_BUF_LEN - strlen(printf_buf) - 1);
+
+   dev_info(&hdev->pdev->dev, "%s", printf_buf);
+
+   for (i = 0; i < HCLGE_DBG_MNG_TBL_MAX; i++) {
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_MAC_ETHERTYPE_IDX_RD,
+  tru

[PATCH V2 net-next 0/6] net: hns3: Add more commands to Debugfs in HNS3 driver

2018-12-15 Thread Salil Mehta
This patch-set adds few more debugfs commands to HNS3 Ethernet
Driver. Support has been added to query info related to below
items:
1. Packet buffer descriptor ("echo bd info [queue no] [bd index] > cmd")
2. Manager table("echo dump mng tbl > cmd")
3. Dfx status register("echo dump reg ssu [prt id] > cmd")
4. Dcb status register("echo dump reg dcb [port id] > cmd")
5. Queue map ("echo queue map [queue no] > cmd")
6. Tm map ("echo tm map [queue no] > cmd")

NOTE: Above commands are *read-only* and are only intended to
query the information from the SoC(and dump inside the kernel,
for now) and in no way tries to perform write operations for
the purpose of configuration etc.

Change Log:
V1-->V2:
1. Addressed the GCC-8.2 compiler issue reported by David S. Miller.
   Link: https://lkml.org/lkml/2018/12/14/1298

liuzhongzhu (6):
  net: hns3: Add "bd info" query function
  net: hns3: Add "manager table" information query function
  net: hns3: Add "status register" information query function
  net: hns3: Add "dcb register" status information query function
  net: hns3: Add "queue map" information query function
  net: hns3: Add "tm map" status information query function

 drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h|   1 +
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|   1 +
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c | 140 -
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  43 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 446 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h | 690 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c|   4 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|   1 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c |  20 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |   7 +
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  |  18 +
 11 files changed, 1366 insertions(+), 5 deletions(-)

-- 
2.11.0




[PATCH V2 net-next 5/6] net: hns3: Add "queue map" information query function

2018-12-15 Thread Salil Mehta
From: liuzhongzhu 

This patch prints queue map information.

debugfs command:
echo dump queue map > cmd

Sample Command:
root@(none)# echo queue map > cmd
 local queue id | global queue id | vector id
  0  32 769
  1  33 770
  2  34 771
  3  35 772
  4  36 773
  5  37 774
  6  38 775
  7  39 776
  8  40 777
  9  41 778
 10  42 779
 11  43 780
 12  44 781
 13  45 782
 14  46 783
 15  47 784
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h|  1 +
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  1 +
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c | 33 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c|  4 +--
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  1 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c | 20 +
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  | 18 
 7 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h 
b/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h
index 4d9cf39da48c..691d12174902 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h
@@ -39,6 +39,7 @@ enum HCLGE_MBX_OPCODE {
HCLGE_MBX_KEEP_ALIVE,   /* (VF -> PF) send keep alive cmd */
HCLGE_MBX_SET_ALIVE,/* (VF -> PF) set alive state */
HCLGE_MBX_SET_MTU,  /* (VF -> PF) set mtu */
+   HCLGE_MBX_GET_QID_IN_PF,/* (VF -> PF) get queue id in pf */
 };
 
 /* below are per-VF mac-vlan subcodes */
diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index 294e725c7c44..845d43d3a920 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -460,6 +460,7 @@ struct hnae3_ae_ops {
bool (*ae_dev_resetting)(struct hnae3_handle *handle);
unsigned long (*ae_dev_reset_cnt)(struct hnae3_handle *handle);
int (*set_gro_en)(struct hnae3_handle *handle, int enable);
+   u16 (*get_global_queue_id)(struct hnae3_handle *handle, u16 queue_id);
 };
 
 struct hnae3_dcb_ops {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 005b7e77c3f3..76c74b4b9777 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -125,6 +125,36 @@ static int hns3_dbg_queue_info(struct hnae3_handle *h, 
char *cmd_buf)
return 0;
 }
 
+static int hns3_dbg_queue_map(struct hnae3_handle *h)
+{
+   struct hns3_nic_priv *priv = h->priv;
+   struct hns3_nic_ring_data *ring_data;
+   int i;
+
+   if (!h->ae_algo->ops->get_global_queue_id)
+   return -EOPNOTSUPP;
+
+   dev_info(&h->pdev->dev, "map info for queue id and vector id\n");
+   dev_info(&h->pdev->dev,
+"local queue id | global queue id | vector id\n");
+   for (i = 0; i < h->kinfo.num_tqps; i++) {
+   u16 global_qid;
+
+   global_qid = h->ae_algo->ops->get_global_queue_id(h, i);
+   ring_data = &priv->ring_data[i];
+   if (!ring_data || !ring_data->ring ||
+   !ring_data->ring->tqp_vector)
+   continue;
+
+   dev_info(&h->pdev->dev,
+"  %4d%4d%4d\n",
+i, global_qid,
+ring_data->ring->tqp_vector->vector_irq);
+   }
+
+   return 0;
+}
+
 static int hns3_dbg_bd_info(struct hnae3_handle *h, char *cmd_buf)
 {
struct hns3_nic_priv *priv = h->priv;
@@ -207,6 +237,7 @@ static void hns3_dbg_help(struct hnae3_handle *h)
 
dev_info(&h->pdev->dev, "available commands\n");
dev_info(&h->pdev->dev, "queue info [number]\n");
+   dev_info(&h->pdev->dev, "queue map\n");
dev_info(&h->pdev->dev, "bd info [q_num] \n");
dev_info(&h->pdev->dev, "dump fd tcam\n");
dev_info(&h->pdev->dev, "dump tc\n");
@@ -303,6 +334,8 @@ static ssize_t hns3_dbg_cmd_write(struct file *filp, const 

[PATCH V2 net-next 6/6] net: hns3: Add "tm map" status information query function

2018-12-15 Thread Salil Mehta
From: liuzhongzhu 

This patch prints dcb register status  information by module.

debugfs command:
root@(none)# echo dump tm map 100 > cmd
queue_id | qset_id | pri_id | tc_id
0100 | 0065| 08 | 00
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c |  1 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 84 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |  7 ++
 4 files changed, 93 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 76c74b4b9777..0de543faa5b1 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -241,6 +241,7 @@ static void hns3_dbg_help(struct hnae3_handle *h)
dev_info(&h->pdev->dev, "bd info [q_num] \n");
dev_info(&h->pdev->dev, "dump fd tcam\n");
dev_info(&h->pdev->dev, "dump tc\n");
+   dev_info(&h->pdev->dev, "dump tm map [q_num]\n");
dev_info(&h->pdev->dev, "dump tm\n");
dev_info(&h->pdev->dev, "dump qos pause cfg\n");
dev_info(&h->pdev->dev, "dump qos pri map\n");
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index c3758f7cb9a0..47717800e0b5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -165,6 +165,7 @@ enum hclge_opcode_type {
HCLGE_OPC_CFG_TX_QUEUE  = 0x0B01,
HCLGE_OPC_QUERY_TX_POINTER  = 0x0B02,
HCLGE_OPC_QUERY_TX_STATUS   = 0x0B03,
+   HCLGE_OPC_TQP_TX_QUEUE_TC   = 0x0B04,
HCLGE_OPC_CFG_RX_QUEUE  = 0x0B11,
HCLGE_OPC_QUERY_RX_POINTER  = 0x0B12,
HCLGE_OPC_QUERY_RX_STATUS   = 0x0B13,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
index 2d43d347ddfd..26d80504c730 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
@@ -537,6 +537,88 @@ static void hclge_dbg_dump_tm(struct hclge_dev *hdev)
cmd, ret);
 }
 
+static void hclge_dbg_dump_tm_map(struct hclge_dev *hdev, char *cmd_buf)
+{
+   struct hclge_bp_to_qs_map_cmd *bp_to_qs_map_cmd;
+   struct hclge_nq_to_qs_link_cmd *nq_to_qs_map;
+   struct hclge_qs_to_pri_link_cmd *map;
+   struct hclge_tqp_tx_queue_tc_cmd *tc;
+   enum hclge_opcode_type cmd;
+   struct hclge_desc desc;
+   int queue_id, group_id;
+   u32 qset_maping[32];
+   int tc_id, qset_id;
+   int pri_id, ret;
+   u32 i;
+
+   ret = kstrtouint(&cmd_buf[12], 10, &queue_id);
+   queue_id = (ret != 0) ? 0 : queue_id;
+
+   cmd = HCLGE_OPC_TM_NQ_TO_QS_LINK;
+   nq_to_qs_map = (struct hclge_nq_to_qs_link_cmd *)desc.data;
+   hclge_cmd_setup_basic_desc(&desc, cmd, true);
+   nq_to_qs_map->nq_id = cpu_to_le16(queue_id);
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret)
+   goto err_tm_map_cmd_send;
+   qset_id = nq_to_qs_map->qset_id & 0x3FF;
+
+   cmd = HCLGE_OPC_TM_QS_TO_PRI_LINK;
+   map = (struct hclge_qs_to_pri_link_cmd *)desc.data;
+   hclge_cmd_setup_basic_desc(&desc, cmd, true);
+   map->qs_id = cpu_to_le16(qset_id);
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret)
+   goto err_tm_map_cmd_send;
+   pri_id = map->priority;
+
+   cmd = HCLGE_OPC_TQP_TX_QUEUE_TC;
+   tc = (struct hclge_tqp_tx_queue_tc_cmd *)desc.data;
+   hclge_cmd_setup_basic_desc(&desc, cmd, true);
+   tc->queue_id = cpu_to_le16(queue_id);
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret)
+   goto err_tm_map_cmd_send;
+   tc_id = tc->tc_id & 0x7;
+
+   dev_info(&hdev->pdev->dev, "queue_id | qset_id | pri_id | tc_id\n");
+   dev_info(&hdev->pdev->dev, "%04d | %04d| %02d | %02d\n",
+queue_id, qset_id, pri_id, tc_id);
+
+   cmd = HCLGE_OPC_TM_BP_TO_QSET_MAPPING;
+   bp_to_qs_map_cmd = (struct hclge_bp_to_qs_map_cmd *)desc.data;
+   for (group_id = 0; group_id < 32; group_id++) {
+   hclge_cmd_setup_basic_desc(&desc, cmd, true);
+   bp_to_qs_map_cmd->tc_id = tc_id;
+   bp_to_qs_map_cmd->qs_group_id = group_id;
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret)
+   goto 

[PATCH V2 net-next 4/6] net: hns3: Add "dcb register" status information query function

2018-12-15 Thread Salil Mehta
From: liuzhongzhu 

This patch prints dcb register status  information by module.

debugfs command:
root@(none)# echo dump reg dcb > cmd
 roce_qset_mask: 0x0
 nic_qs_mask: 0x0
 qs_shaping_pass: 0x0
 qs_bp_sts: 0x0
 pri_mask: 0x0
 pri_cshaping_pass: 0x0
 pri_pshaping_pass: 0x0
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c |   7 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |   9 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 102 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h |  16 
 4 files changed, 134 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index e6268e03d221..005b7e77c3f3 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -226,6 +226,13 @@ static void hns3_dbg_help(struct hnae3_handle *h)
" [rtc] [ppp] [rcb] [tqp ]]\n",
HNS3_DBG_BUF_LEN - strlen(printf_buf) - 1);
dev_info(&h->pdev->dev, "%s", printf_buf);
+
+   memset(printf_buf, 0, HNS3_DBG_BUF_LEN);
+   strncat(printf_buf, "dump reg dcb [port_id] [pri_id] [pg_id]",
+   HNS3_DBG_BUF_LEN - 1);
+   strncat(printf_buf + strlen(printf_buf), " [rq_id] [nq_id] [qset_id]\n",
+   HNS3_DBG_BUF_LEN - strlen(printf_buf) - 1);
+   dev_info(&h->pdev->dev, "%s", printf_buf);
 }
 
 static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 2b281d909f51..c3758f7cb9a0 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -140,6 +140,15 @@ enum hclge_opcode_type {
HCLGE_OPC_TM_QS_SCH_MODE_CFG= 0x0814,
HCLGE_OPC_TM_BP_TO_QSET_MAPPING = 0x0815,
HCLGE_OPC_ETS_TC_WEIGHT = 0x0843,
+   HCLGE_OPC_QSET_DFX_STS  = 0x0844,
+   HCLGE_OPC_PRI_DFX_STS   = 0x0845,
+   HCLGE_OPC_PG_DFX_STS= 0x0846,
+   HCLGE_OPC_PORT_DFX_STS  = 0x0847,
+   HCLGE_OPC_SCH_NQ_CNT= 0x0848,
+   HCLGE_OPC_SCH_RQ_CNT= 0x0849,
+   HCLGE_OPC_TM_INTERNAL_STS   = 0x0850,
+   HCLGE_OPC_TM_INTERNAL_CNT   = 0x0851,
+   HCLGE_OPC_TM_INTERNAL_STS_1 = 0x0852,
 
/* Packet buffer allocate commands */
HCLGE_OPC_TX_BUFF_ALLOC = 0x0901,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
index 7d18ed8e17f0..2d43d347ddfd 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
@@ -107,6 +107,106 @@ static void hclge_dbg_dump_reg_common(struct hclge_dev 
*hdev,
kfree(desc_src);
 }
 
+static void hclge_dbg_dump_dcb(struct hclge_dev *hdev, char *cmd_buf)
+{
+   struct device *dev = &hdev->pdev->dev;
+   struct hclge_dbg_bitmap_cmd *bitmap;
+   int rq_id, pri_id, qset_id;
+   int port_id, nq_id, pg_id;
+   struct hclge_desc desc[2];
+
+   int cnt, ret;
+
+   cnt = sscanf(cmd_buf, "%i %i %i %i %i %i",
+&port_id, &pri_id, &pg_id, &rq_id, &nq_id, &qset_id);
+   if (cnt != 6) {
+   dev_err(&hdev->pdev->dev,
+   "dump dcb: bad command parameter, cnt=%d\n", cnt);
+   return;
+   }
+
+   ret = hclge_dbg_cmd_send(hdev, desc, qset_id, 1,
+HCLGE_OPC_QSET_DFX_STS);
+   if (ret)
+   return;
+
+   bitmap = (struct hclge_dbg_bitmap_cmd *)&desc[0].data[1];
+   dev_info(dev, "roce_qset_mask: 0x%x\n", bitmap->bit0);
+   dev_info(dev, "nic_qs_mask: 0x%x\n", bitmap->bit1);
+   dev_info(dev, "qs_shaping_pass: 0x%x\n", bitmap->bit2);
+   dev_info(dev, "qs_bp_sts: 0x%x\n", bitmap->bit3);
+
+   ret = hclge_dbg_cmd_send(hdev, desc, pri_id, 1, HCLGE_OPC_PRI_DFX_STS);
+   if (ret)
+   return;
+
+   bitmap = (struct hclge_dbg_bitmap_cmd *)&desc[0].data[1];
+   dev_info(dev, "pri_mask: 0x%x\n", bitmap->bit0);
+   dev_info(dev, "pri_cshaping_pass: 0x%x\n", bitmap->bit1);
+   dev_info(dev, "pri_pshaping_pass: 0x%x\n", bitmap->bit2);
+
+   ret = hclge_dbg_cmd_send(hdev, desc, pg_id, 1, HCLGE_OPC_PG_DFX_STS);
+   if (ret)
+   return;
+
+   bitmap = (struct hclge_dbg_bitmap_cmd *)&desc[0].data[1];
+   dev_info(dev, "pg_mask: 0x%x\n", bitmap->bit0);
+   d

[PATCH V2 net-next 1/6] net: hns3: Add "bd info" query function

2018-12-15 Thread Salil Mehta
From: liuzhongzhu 

This patch prints Sending and receiving
package descriptor information.

debugfs command:
echo dump bd info 1 > cmd

Sample Command:
root@(none)# echo bd info 1 > cmd
hns3 :7d:00.0: TX Queue Num: 0, BD Index: 0
hns3 :7d:00.0: (TX) addr: 0x0
hns3 :7d:00.0: (TX)vlan_tag: 0
hns3 :7d:00.0: (TX)send_size: 0
hns3 :7d:00.0: (TX)vlan_tso: 0
hns3 :7d:00.0: (TX)l2_len: 0
hns3 :7d:00.0: (TX)l3_len: 0
hns3 :7d:00.0: (TX)l4_len: 0
hns3 :7d:00.0: (TX)vlan_tag: 0
hns3 :7d:00.0: (TX)tv: 0
hns3 :7d:00.0: (TX)vlan_msec: 0
hns3 :7d:00.0: (TX)ol2_len: 0
hns3 :7d:00.0: (TX)ol3_len: 0
hns3 :7d:00.0: (TX)ol4_len: 0
hns3 :7d:00.0: (TX)paylen: 0
hns3 :7d:00.0: (TX)vld_ra_ri: 0
hns3 :7d:00.0: (TX)mss: 0
hns3 :7d:00.0: RX Queue Num: 0, BD Index: 120
hns3 :7d:00.0: (RX)addr: 0xffee7000
hns3 :7d:00.0: (RX)pkt_len: 0
hns3 :7d:00.0: (RX)size: 0
hns3 :7d:00.0: (RX)rss_hash: 0
hns3 :7d:00.0: (RX)fd_id: 0
hns3 :7d:00.0: (RX)vlan_tag: 0
hns3 :7d:00.0: (RX)o_dm_vlan_id_fb: 0
hns3 :7d:00.0: (RX)ot_vlan_tag: 0
hns3 :7d:00.0: (RX)bd_base_info: 0

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c | 79 +-
 1 file changed, 78 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 86d667a3730a..9a026556df0e 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -52,7 +52,7 @@ static int hns3_dbg_queue_info(struct hnae3_handle *h, char 
*cmd_buf)
test_bit(HNS3_NIC_STATE_RESETTING, &priv->state))
return -EPERM;
 
-   ring = ring_data[i + h->kinfo.num_tqps].ring;
+   ring = ring_data[(u32)(i + h->kinfo.num_tqps)].ring;
base_add_h = readl_relaxed(ring->tqp->io_base +
   HNS3_RING_RX_RING_BASEADDR_H_REG);
base_add_l = readl_relaxed(ring->tqp->io_base +
@@ -125,10 +125,85 @@ static int hns3_dbg_queue_info(struct hnae3_handle *h, 
char *cmd_buf)
return 0;
 }
 
+static int hns3_dbg_bd_info(struct hnae3_handle *h, char *cmd_buf)
+{
+   struct hns3_nic_priv *priv = h->priv;
+   struct hns3_nic_ring_data *ring_data;
+   struct hns3_desc *rx_desc, *tx_desc;
+   struct device *dev = &h->pdev->dev;
+   struct hns3_enet_ring *ring;
+   u32 tx_index, rx_index;
+   u32 q_num, value;
+   int cnt;
+
+   cnt = sscanf(&cmd_buf[8], "%u %u", &q_num, &tx_index);
+   if (cnt == 2) {
+   rx_index = tx_index;
+   } else if (cnt != 1) {
+   dev_err(dev, "bd info: bad command string, cnt=%d\n", cnt);
+   return -EINVAL;
+   }
+
+   if (q_num >= h->kinfo.num_tqps) {
+   dev_err(dev, "Queue number(%u) is out of range(%u)\n", q_num,
+   h->kinfo.num_tqps - 1);
+   return -EINVAL;
+   }
+
+   ring_data = priv->ring_data;
+   ring  = ring_data[q_num].ring;
+   value = readl_relaxed(ring->tqp->io_base + HNS3_RING_TX_RING_TAIL_REG);
+   tx_index = (cnt == 1) ? value : tx_index;
+
+   if (tx_index >= ring->desc_num) {
+   dev_err(dev, "bd index (%u) is out of range(%u)\n", tx_index,
+   ring->desc_num - 1);
+   return -EINVAL;
+   }
+
+   tx_desc = &ring->desc[tx_index];
+   dev_info(dev, "TX Queue Num: %u, BD Index: %u\n", q_num, tx_index);
+   dev_info(dev, "(TX) addr: 0x%llx\n", tx_desc->addr);
+   dev_info(dev, "(TX)vlan_tag: %u\n", tx_desc->tx.vlan_tag);
+   dev_info(dev, "(TX)send_size: %u\n", tx_desc->tx.send_size);
+   dev_info(dev, "(TX)vlan_tso: %u\n", tx_desc->tx.type_cs_vlan_tso);
+   dev_info(dev, "(TX)l2_len: %u\n", tx_desc->tx.l2_len);
+   dev_info(dev, "(TX)l3_len: %u\n", tx_desc->tx.l3_len);
+   dev_info(dev, "(TX)l4_len: %u\n", tx_desc->tx.l4_len);
+   dev_info(dev, "(TX)vlan_tag: %u\n", tx_desc->tx.outer_vlan_tag);
+   dev_info(dev, "(TX)tv: %u\n", tx_desc->tx.tv);
+   dev_info(dev, "(TX)vlan_msec: %u\n", tx_desc->tx.ol_type_vlan_msec);
+   dev_info(dev, "(TX)ol2_len: %u\n", tx_desc->tx.ol2_len);
+   dev_info(dev, "(TX)ol3_len: %u\n", tx_desc->tx.ol3_len);
+   dev_info(dev, "(TX)ol4_len: %u\n", tx_desc->tx.ol4_len);
+   dev_info(dev, "(TX)paylen: %u\n", tx_desc->tx.paylen);
+   dev_info(dev, "(TX)vld_ra_ri: %u\n", tx_desc->tx.bdtp_fe_sc_vld_ra_ri);

RE: [PATCH net-next 0/6] net: hns3: Add more commands to Debugfs in HNS3 driver

2018-12-15 Thread Salil Mehta
> From: David Miller [mailto:da...@davemloft.net]
> Sent: Friday, December 14, 2018 10:37 PM
> To: Salil Mehta 
> Cc: Zhuangyuzeng (Yisen) ; lipeng (Y)
> ; mehta.sa...@opnsrc.net; netdev@vger.kernel.org;
> linux-ker...@vger.kernel.org; Linuxarm 
> Subject: Re: [PATCH net-next 0/6] net: hns3: Add more commands to
> Debugfs in HNS3 driver
> 
> From: David Miller 
> Date: Fri, 14 Dec 2018 14:30:46 -0800 (PST)
> 
> > From: Salil Mehta 
> > Date: Tue, 11 Dec 2018 17:13:24 +
> >
> >> This patch-set adds few more debugfs commands to HNS3 Ethernet
> >> Driver. Support has been added to query info related to below
> >> items:
> >> 1. Packet buffer descriptor ("echo bd info [queue no] [bd index] > cmd")
> >> 2. Manager table("echo dump mng tbl > cmd")
> >> 3. Dfx status register("echo dump reg ssu [prt id] > cmd")
> >> 4. Dcb status register("echo dump reg dcb [port id] > cmd")
> >> 5. Queue map ("echo queue map [queue no] > cmd")
> >> 6. Tm map ("echo tm map [queue no] > cmd")
> >>
> >> NOTE: Above commands are *read-only* and are only intended to
> >> query the information from the SoC(and dump inside the kernel,
> >> for now) and in no way tries to perform write operations for
> >> the purpose of configuration etc.
> >
> > Series applied.
> 
> Actually, reverted.
> 
> Please fix these warnings and resubmit (with gcc version
> "gcc (GCC) 8.2.1 20181105 (Red Hat 8.2.1-5)"):
> 
> In file included from ./include/linux/bitmap.h:9,
>  from ./include/linux/cpumask.h:12,
>  from ./arch/x86/include/asm/cpumask.h:5,
>  from ./arch/x86/include/asm/msr.h:11,
>  from ./arch/x86/include/asm/processor.h:21,
>  from ./arch/x86/include/asm/cpufeature.h:8,
>  from ./arch/x86/include/asm/thread_info.h:53,
>  from ./include/linux/thread_info.h:38,
>  from ./arch/x86/include/asm/preempt.h:7,
>  from ./include/linux/preempt.h:81,
>  from ./include/linux/spinlock.h:51,
>  from ./include/linux/wait.h:9,
>  from ./include/linux/wait_bit.h:8,
>  from ./include/linux/fs.h:6,
>  from ./include/linux/debugfs.h:15,
>  from
> drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c:4:
> In function ‘strncat’,
> inlined from ‘hns3_dbg_help’ at
> drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c:263:2:
> ./include/linux/string.h:320:10: warning: ‘__builtin_strncat’ specified
> bound 256 equals destination size [-Wstringop-overflow=]
>return __builtin_strncat(p, q, count);
>   ^~
> In function ‘strncat’,
> inlined from ‘hns3_dbg_help’ at
> drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c:252:2:
> ./include/linux/string.h:320:10: warning: ‘__builtin_strncat’ specified
> bound 256 equals destination size [-Wstringop-overflow=]
>return __builtin_strncat(p, q, count);
>   ^~
> In file included from ./include/linux/bitmap.h:9,
>  from ./include/linux/cpumask.h:12,
>  from ./arch/x86/include/asm/cpumask.h:5,
>  from ./arch/x86/include/asm/msr.h:11,
>  from ./arch/x86/include/asm/processor.h:21,
>  from ./include/linux/mutex.h:19,
>  from ./include/linux/kernfs.h:13,
>  from ./include/linux/sysfs.h:16,
>  from ./include/linux/kobject.h:20,
>  from ./include/linux/device.h:16,
>  from
> drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c:4:
> In function ‘strncat’,
> inlined from ‘hclge_dbg_dump_mng_table’ at
> drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c:795:2:
> ./include/linux/string.h:320:10: warning: ‘__builtin_strncat’ specified
> bound 256 equals destination size [-Wstringop-overflow=]
>return __builtin_strncat(p, q, count);
>   ^~

Ahh, goodness. Perhaps, I have been using outdated compiler.
I will float the V2 version today after fixing above.

Thanks
Dave


[PATCH net-next 0/6] net: hns3: Add more commands to Debugfs in HNS3 driver

2018-12-11 Thread Salil Mehta
This patch-set adds few more debugfs commands to HNS3 Ethernet
Driver. Support has been added to query info related to below
items:
1. Packet buffer descriptor ("echo bd info [queue no] [bd index] > cmd")
2. Manager table("echo dump mng tbl > cmd")
3. Dfx status register("echo dump reg ssu [prt id] > cmd")
4. Dcb status register("echo dump reg dcb [port id] > cmd")
5. Queue map ("echo queue map [queue no] > cmd")
6. Tm map ("echo tm map [queue no] > cmd")

NOTE: Above commands are *read-only* and are only intended to
query the information from the SoC(and dump inside the kernel,
for now) and in no way tries to perform write operations for
the purpose of configuration etc.

liuzhongzhu (6):
  net: hns3: Add "bd info" query function
  net: hns3: Add "manager table" information query function
  net: hns3: Add "status register" information query function
  net: hns3: Add "dcb register" status information query function
  net: hns3: Add "queue map" information query function
  net: hns3: Add "tm map" status information query function

 drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h|   1 +
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|   1 +
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c | 136 +++-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  43 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 446 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h | 690 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c|   4 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|   1 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c |  20 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |   7 +
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  |  18 +
 11 files changed, 1364 insertions(+), 3 deletions(-)

-- 
2.7.4




[PATCH net-next 1/6] net: hns3: Add "bd info" query function

2018-12-11 Thread Salil Mehta
From: liuzhongzhu 

This patch prints Sending and receiving
packet descriptor information.

debugfs command:
echo dump bd info 1 > cmd

Sample Command:
root@(none)# echo bd info 1 > cmd
hns3 :7d:00.0: TX Queue Num: 0, BD Index: 0
hns3 :7d:00.0: (TX) addr: 0x0
hns3 :7d:00.0: (TX)vlan_tag: 0
hns3 :7d:00.0: (TX)send_size: 0
hns3 :7d:00.0: (TX)vlan_tso: 0
hns3 :7d:00.0: (TX)l2_len: 0
hns3 :7d:00.0: (TX)l3_len: 0
hns3 :7d:00.0: (TX)l4_len: 0
hns3 :7d:00.0: (TX)vlan_tag: 0
hns3 :7d:00.0: (TX)tv: 0
hns3 :7d:00.0: (TX)vlan_msec: 0
hns3 :7d:00.0: (TX)ol2_len: 0
hns3 :7d:00.0: (TX)ol3_len: 0
hns3 :7d:00.0: (TX)ol4_len: 0
hns3 :7d:00.0: (TX)paylen: 0
hns3 :7d:00.0: (TX)vld_ra_ri: 0
hns3 :7d:00.0: (TX)mss: 0
hns3 :7d:00.0: RX Queue Num: 0, BD Index: 120
hns3 :7d:00.0: (RX)addr: 0xffee7000
hns3 :7d:00.0: (RX)pkt_len: 0
hns3 :7d:00.0: (RX)size: 0
hns3 :7d:00.0: (RX)rss_hash: 0
hns3 :7d:00.0: (RX)fd_id: 0
hns3 :7d:00.0: (RX)vlan_tag: 0
hns3 :7d:00.0: (RX)o_dm_vlan_id_fb: 0
hns3 :7d:00.0: (RX)ot_vlan_tag: 0
hns3 :7d:00.0: (RX)bd_base_info: 0

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c | 79 +-
 1 file changed, 78 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 86d667a..9a02655 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -52,7 +52,7 @@ static int hns3_dbg_queue_info(struct hnae3_handle *h, char 
*cmd_buf)
test_bit(HNS3_NIC_STATE_RESETTING, &priv->state))
return -EPERM;
 
-   ring = ring_data[i + h->kinfo.num_tqps].ring;
+   ring = ring_data[(u32)(i + h->kinfo.num_tqps)].ring;
base_add_h = readl_relaxed(ring->tqp->io_base +
   HNS3_RING_RX_RING_BASEADDR_H_REG);
base_add_l = readl_relaxed(ring->tqp->io_base +
@@ -125,10 +125,85 @@ static int hns3_dbg_queue_info(struct hnae3_handle *h, 
char *cmd_buf)
return 0;
 }
 
+static int hns3_dbg_bd_info(struct hnae3_handle *h, char *cmd_buf)
+{
+   struct hns3_nic_priv *priv = h->priv;
+   struct hns3_nic_ring_data *ring_data;
+   struct hns3_desc *rx_desc, *tx_desc;
+   struct device *dev = &h->pdev->dev;
+   struct hns3_enet_ring *ring;
+   u32 tx_index, rx_index;
+   u32 q_num, value;
+   int cnt;
+
+   cnt = sscanf(&cmd_buf[8], "%u %u", &q_num, &tx_index);
+   if (cnt == 2) {
+   rx_index = tx_index;
+   } else if (cnt != 1) {
+   dev_err(dev, "bd info: bad command string, cnt=%d\n", cnt);
+   return -EINVAL;
+   }
+
+   if (q_num >= h->kinfo.num_tqps) {
+   dev_err(dev, "Queue number(%u) is out of range(%u)\n", q_num,
+   h->kinfo.num_tqps - 1);
+   return -EINVAL;
+   }
+
+   ring_data = priv->ring_data;
+   ring  = ring_data[q_num].ring;
+   value = readl_relaxed(ring->tqp->io_base + HNS3_RING_TX_RING_TAIL_REG);
+   tx_index = (cnt == 1) ? value : tx_index;
+
+   if (tx_index >= ring->desc_num) {
+   dev_err(dev, "bd index (%u) is out of range(%u)\n", tx_index,
+   ring->desc_num - 1);
+   return -EINVAL;
+   }
+
+   tx_desc = &ring->desc[tx_index];
+   dev_info(dev, "TX Queue Num: %u, BD Index: %u\n", q_num, tx_index);
+   dev_info(dev, "(TX) addr: 0x%llx\n", tx_desc->addr);
+   dev_info(dev, "(TX)vlan_tag: %u\n", tx_desc->tx.vlan_tag);
+   dev_info(dev, "(TX)send_size: %u\n", tx_desc->tx.send_size);
+   dev_info(dev, "(TX)vlan_tso: %u\n", tx_desc->tx.type_cs_vlan_tso);
+   dev_info(dev, "(TX)l2_len: %u\n", tx_desc->tx.l2_len);
+   dev_info(dev, "(TX)l3_len: %u\n", tx_desc->tx.l3_len);
+   dev_info(dev, "(TX)l4_len: %u\n", tx_desc->tx.l4_len);
+   dev_info(dev, "(TX)vlan_tag: %u\n", tx_desc->tx.outer_vlan_tag);
+   dev_info(dev, "(TX)tv: %u\n", tx_desc->tx.tv);
+   dev_info(dev, "(TX)vlan_msec: %u\n", tx_desc->tx.ol_type_vlan_msec);
+   dev_info(dev, "(TX)ol2_len: %u\n", tx_desc->tx.ol2_len);
+   dev_info(dev, "(TX)ol3_len: %u\n", tx_desc->tx.ol3_len);
+   dev_info(dev, "(TX)ol4_len: %u\n", tx_desc->tx.ol4_len);
+   dev_info(dev, "(TX)paylen: %u\n", tx_desc->tx.paylen);
+   dev_info(dev, "(TX)vld_ra_ri: %u\n", tx_desc->tx.bdtp_fe_sc_vld_ra_ri);
+   dev_

[PATCH net-next 3/6] net: hns3: Add "status register" information query function

2018-12-11 Thread Salil Mehta
From: liuzhongzhu 

This patch prints status register information by module.

debugfs command:
echo dump reg [mode name] > cmd

Sample Command:
root@(none)# echo dump reg bios common > cmd
 BP_CPU_STATE: 0x0
 DFX_MSIX_INFO_NIC_0: 0xc000
 DFX_MSIX_INFO_NIC_1: 0xf
 DFX_MSIX_INFO_NIC_2: 0x2
 DFX_MSIX_INFO_NIC_3: 0x2
 DFX_MSIX_INFO_ROC_0: 0xc000
 DFX_MSIX_INFO_ROC_1: 0x0
 DFX_MSIX_INFO_ROC_2: 0x0
 DFX_MSIX_INFO_ROC_3: 0x0
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c |  15 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  14 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 194 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h | 662 +
 4 files changed, 885 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 5067ee3..c34d412 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -201,6 +201,10 @@ static int hns3_dbg_bd_info(struct hnae3_handle *h, char 
*cmd_buf)
 
 static void hns3_dbg_help(struct hnae3_handle *h)
 {
+#define HNS3_DBG_BUF_LEN 256
+
+   char printf_buf[HNS3_DBG_BUF_LEN];
+
dev_info(&h->pdev->dev, "available commands\n");
dev_info(&h->pdev->dev, "queue info [number]\n");
dev_info(&h->pdev->dev, "bd info [q_num] \n");
@@ -211,6 +215,17 @@ static void hns3_dbg_help(struct hnae3_handle *h)
dev_info(&h->pdev->dev, "dump qos pri map\n");
dev_info(&h->pdev->dev, "dump qos buf cfg\n");
dev_info(&h->pdev->dev, "dump mng tbl\n");
+
+   memset(printf_buf, 0, HNS3_DBG_BUF_LEN);
+   strncat(printf_buf, "dump reg [[bios common] [ssu ]",
+   HNS3_DBG_BUF_LEN);
+   strncat(printf_buf + strlen(printf_buf),
+   " [igu egu ] [rpu ]",
+   HNS3_DBG_BUF_LEN - strlen(printf_buf));
+   strncat(printf_buf + strlen(printf_buf),
+   " [rtc] [ppp] [rcb] [tqp ]]\n",
+   HNS3_DBG_BUF_LEN - strlen(printf_buf));
+   dev_info(&h->pdev->dev, "%s", printf_buf);
 }
 
 static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 61b617c..5d69e0d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -86,6 +86,20 @@ enum hclge_opcode_type {
HCLGE_OPC_QUERY_REG_NUM = 0x0040,
HCLGE_OPC_QUERY_32_BIT_REG  = 0x0041,
HCLGE_OPC_QUERY_64_BIT_REG  = 0x0042,
+   HCLGE_OPC_DFX_BD_NUM= 0x0043,
+   HCLGE_OPC_DFX_BIOS_COMMON_REG   = 0x0044,
+   HCLGE_OPC_DFX_SSU_REG_0 = 0x0045,
+   HCLGE_OPC_DFX_SSU_REG_1 = 0x0046,
+   HCLGE_OPC_DFX_IGU_EGU_REG   = 0x0047,
+   HCLGE_OPC_DFX_RPU_REG_0 = 0x0048,
+   HCLGE_OPC_DFX_RPU_REG_1 = 0x0049,
+   HCLGE_OPC_DFX_NCSI_REG  = 0x004A,
+   HCLGE_OPC_DFX_RTC_REG   = 0x004B,
+   HCLGE_OPC_DFX_PPP_REG   = 0x004C,
+   HCLGE_OPC_DFX_RCB_REG   = 0x004D,
+   HCLGE_OPC_DFX_TQP_REG   = 0x004E,
+   HCLGE_OPC_DFX_SSU_REG_2 = 0x004F,
+   HCLGE_OPC_DFX_QUERY_CHIP_CAP= 0x0050,
 
/* MAC command */
HCLGE_OPC_CONFIG_MAC_MODE   = 0x0301,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
index 832c7f4..3aa3483 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
@@ -9,6 +9,198 @@
 #include "hclge_tm.h"
 #include "hnae3.h"
 
+static int hclge_dbg_get_dfx_bd_num(struct hclge_dev *hdev, int offset)
+{
+   struct hclge_desc desc[4];
+   int ret;
+
+   hclge_cmd_setup_basic_desc(&desc[0], HCLGE_OPC_DFX_BD_NUM, true);
+   desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+   hclge_cmd_setup_basic_desc(&desc[1], HCLGE_OPC_DFX_BD_NUM, true);
+   desc[1].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+   hclge_cmd_setup_basic_desc(&desc[2], HCLGE_OPC_DFX_BD_NUM, true);
+   desc[2].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+   hclge_cmd_setup_basic_desc(&desc[3], HCLGE_OPC_DFX_BD_NUM, true);
+
+   ret = hclge_cmd_send(&hdev->hw, desc, 4);
+   if (ret != HCLGE_CMD_EXEC_SUCCESS) {
+   dev_err(&hdev->pdev->dev,
+   "get dfx bdnum fail, status is %d.\n", ret);
+   return ret;
+   }
+
+   return (int)desc[offset / 6].data[of

[PATCH net-next 5/6] net: hns3: Add "queue map" information query function

2018-12-11 Thread Salil Mehta
From: liuzhongzhu 

This patch prints queue map information.

debugfs command:
echo dump queue map > cmd

Sample Command:
root@(none)# echo queue map > cmd
 local queue id | global queue id | vector id
  0  32 769
  1  33 770
  2  34 771
  3  35 772
  4  36 773
  5  37 774
  6  38 775
  7  39 776
  8  40 777
  9  41 778
 10  42 779
 11  43 780
 12  44 781
 13  45 782
 14  46 783
 15  47 784
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h|  1 +
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  1 +
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c | 33 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c|  4 +--
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  1 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c | 20 +
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  | 18 
 7 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h 
b/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h
index 4d9cf39..691d121 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h
@@ -39,6 +39,7 @@ enum HCLGE_MBX_OPCODE {
HCLGE_MBX_KEEP_ALIVE,   /* (VF -> PF) send keep alive cmd */
HCLGE_MBX_SET_ALIVE,/* (VF -> PF) set alive state */
HCLGE_MBX_SET_MTU,  /* (VF -> PF) set mtu */
+   HCLGE_MBX_GET_QID_IN_PF,/* (VF -> PF) get queue id in pf */
 };
 
 /* below are per-VF mac-vlan subcodes */
diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index 294e725..845d43d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -460,6 +460,7 @@ struct hnae3_ae_ops {
bool (*ae_dev_resetting)(struct hnae3_handle *handle);
unsigned long (*ae_dev_reset_cnt)(struct hnae3_handle *handle);
int (*set_gro_en)(struct hnae3_handle *handle, int enable);
+   u16 (*get_global_queue_id)(struct hnae3_handle *handle, u16 queue_id);
 };
 
 struct hnae3_dcb_ops {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index be11e3d..fe5ec68 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -125,6 +125,36 @@ static int hns3_dbg_queue_info(struct hnae3_handle *h, 
char *cmd_buf)
return 0;
 }
 
+static int hns3_dbg_queue_map(struct hnae3_handle *h)
+{
+   struct hns3_nic_priv *priv = h->priv;
+   struct hns3_nic_ring_data *ring_data;
+   int i;
+
+   if (!h->ae_algo->ops->get_global_queue_id)
+   return -EOPNOTSUPP;
+
+   dev_info(&h->pdev->dev, "map info for queue id and vector id\n");
+   dev_info(&h->pdev->dev,
+"local queue id | global queue id | vector id\n");
+   for (i = 0; i < h->kinfo.num_tqps; i++) {
+   u16 global_qid;
+
+   global_qid = h->ae_algo->ops->get_global_queue_id(h, i);
+   ring_data = &priv->ring_data[i];
+   if (!ring_data || !ring_data->ring ||
+   !ring_data->ring->tqp_vector)
+   continue;
+
+   dev_info(&h->pdev->dev,
+"  %4d%4d%4d\n",
+i, global_qid,
+ring_data->ring->tqp_vector->vector_irq);
+   }
+
+   return 0;
+}
+
 static int hns3_dbg_bd_info(struct hnae3_handle *h, char *cmd_buf)
 {
struct hns3_nic_priv *priv = h->priv;
@@ -207,6 +237,7 @@ static void hns3_dbg_help(struct hnae3_handle *h)
 
dev_info(&h->pdev->dev, "available commands\n");
dev_info(&h->pdev->dev, "queue info [number]\n");
+   dev_info(&h->pdev->dev, "queue map\n");
dev_info(&h->pdev->dev, "bd info [q_num] \n");
dev_info(&h->pdev->dev, "dump fd tcam\n");
dev_info(&h->pdev->dev, "dump tc\n");
@@ -303,6 +334,8 @@ static ssize_t hns3_dbg_cmd_write(struct file *filp, const 
char __user *buffer,
hns3_dbg_

[PATCH net-next 2/6] net: hns3: Add "manager table" information query function

2018-12-11 Thread Salil Mehta
From: liuzhongzhu 

This patch prints manager table information.

debugfs command:
echo dump mng tbl > cmd

Sample Command:
root@(none)# echo dump mng tbl > cmd
 entry|mac_addr |mask|ether|mask|vlan|mask|i_map|i_dir|e_type
 00   |01:00:5e:00:00:01|0   |0|0   ||0   |00   |00   |0
 01   |c2:f1:c5:82:68:17|0   |0|0   ||0   |00   |00   |0
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c |  1 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h | 19 +++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 66 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h | 12 
 4 files changed, 98 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 9a02655..5067ee3 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -210,6 +210,7 @@ static void hns3_dbg_help(struct hnae3_handle *h)
dev_info(&h->pdev->dev, "dump qos pause cfg\n");
dev_info(&h->pdev->dev, "dump qos pri map\n");
dev_info(&h->pdev->dev, "dump qos buf cfg\n");
+   dev_info(&h->pdev->dev, "dump mng tbl\n");
 }
 
 static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index b1ee6fe..61b617c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -237,6 +237,7 @@ enum hclge_opcode_type {
HCLGE_TM_QCN_MEM_INT_CFG= 0x1A14,
HCLGE_PPP_CMD0_INT_CMD  = 0x2100,
HCLGE_PPP_CMD1_INT_CMD  = 0x2101,
+   HCLGE_MAC_ETHERTYPE_IDX_RD  = 0x2105,
HCLGE_NCSI_INT_EN   = 0x2401,
 };
 
@@ -744,6 +745,24 @@ struct hclge_cfg_tx_queue_pointer_cmd {
u8 rsv[14];
 };
 
+#pragma pack(1)
+struct hclge_mac_ethertype_idx_rd_cmd {
+   u8  flags;
+   u8  resp_code;
+   __le16  vlan_tag;
+   u8  mac_add[6];
+   __le16  index;
+   __le16  ethter_type;
+   __le16  egress_port;
+   __le16  egress_queue;
+   __le16  rev0;
+   u8  i_port_bitmap;
+   u8  i_port_direction;
+   u8  rev1[2];
+};
+
+#pragma pack()
+
 #define HCLGE_TSO_MSS_MIN_S0
 #define HCLGE_TSO_MSS_MIN_MGENMASK(13, 0)
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
index 14577bb..832c7f4 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
@@ -407,6 +407,70 @@ static void hclge_dbg_dump_qos_buf_cfg(struct hclge_dev 
*hdev)
"dump qos buf cfg fail(0x%x), status is %d\n", cmd, ret);
 }
 
+static void hclge_dbg_dump_mng_table(struct hclge_dev *hdev)
+{
+   struct hclge_mac_ethertype_idx_rd_cmd *req0;
+   char printf_buf[HCLGE_DBG_BUF_LEN];
+   struct hclge_desc desc;
+   int ret, i;
+
+   dev_info(&hdev->pdev->dev, "mng tab:\n");
+   memset(printf_buf, 0, HCLGE_DBG_BUF_LEN);
+   strncat(printf_buf,
+   "entry|mac_addr |mask|ether|mask|vlan|mask",
+   HCLGE_DBG_BUF_LEN);
+   strncat(printf_buf + strlen(printf_buf),
+   "|i_map|i_dir|e_type|pf_id|vf_id|q_id|drop\n",
+   HCLGE_DBG_BUF_LEN - strlen(printf_buf));
+
+   dev_info(&hdev->pdev->dev, "%s", printf_buf);
+
+   for (i = 0; i < HCLGE_DBG_MNG_TBL_MAX; i++) {
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_MAC_ETHERTYPE_IDX_RD,
+  true);
+   req0 = (struct hclge_mac_ethertype_idx_rd_cmd *)&desc.data;
+   req0->index = cpu_to_le16(i);
+
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret) {
+   dev_err(&hdev->pdev->dev,
+   "call hclge_cmd_send fail, ret = %d\n", ret);
+   return;
+   }
+
+   if (!req0->resp_code)
+   continue;
+
+   memset(printf_buf, 0, HCLGE_DBG_BUF_LEN);
+   snprintf(printf_buf, HCLGE_DBG_BUF_LEN,
+"%02u   |%02x:%02x:%02x:%02x:%02x:%02x|",
+req0->index, req0->mac_add[0], req0->mac_add[1],
+req0->mac_add[2], req0->mac_add[3], req0->mac_add[4],
+req0->mac_add[5]);
+
+   snprintf(printf_buf + strlen(printf_buf),
+  

[PATCH net-next 6/6] net: hns3: Add "tm map" status information query function

2018-12-11 Thread Salil Mehta
From: liuzhongzhu 

This patch prints dcb register status  information by module.

debugfs command:
root@(none)# echo dump tm map 100 > cmd
queue_id | qset_id | pri_id | tc_id
0100 | 0065| 08 | 00
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c |  1 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 84 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |  7 ++
 4 files changed, 93 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index fe5ec68..0872ca5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -241,6 +241,7 @@ static void hns3_dbg_help(struct hnae3_handle *h)
dev_info(&h->pdev->dev, "bd info [q_num] \n");
dev_info(&h->pdev->dev, "dump fd tcam\n");
dev_info(&h->pdev->dev, "dump tc\n");
+   dev_info(&h->pdev->dev, "dump tm map [q_num]\n");
dev_info(&h->pdev->dev, "dump tm\n");
dev_info(&h->pdev->dev, "dump qos pause cfg\n");
dev_info(&h->pdev->dev, "dump qos pri map\n");
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index dc8b7c2..71c1678 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -165,6 +165,7 @@ enum hclge_opcode_type {
HCLGE_OPC_CFG_TX_QUEUE  = 0x0B01,
HCLGE_OPC_QUERY_TX_POINTER  = 0x0B02,
HCLGE_OPC_QUERY_TX_STATUS   = 0x0B03,
+   HCLGE_OPC_TQP_TX_QUEUE_TC   = 0x0B04,
HCLGE_OPC_CFG_RX_QUEUE  = 0x0B11,
HCLGE_OPC_QUERY_RX_POINTER  = 0x0B12,
HCLGE_OPC_QUERY_RX_STATUS   = 0x0B13,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
index d1d693b..dda5f00 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
@@ -537,6 +537,88 @@ static void hclge_dbg_dump_tm(struct hclge_dev *hdev)
cmd, ret);
 }
 
+static void hclge_dbg_dump_tm_map(struct hclge_dev *hdev, char *cmd_buf)
+{
+   struct hclge_bp_to_qs_map_cmd *bp_to_qs_map_cmd;
+   struct hclge_nq_to_qs_link_cmd *nq_to_qs_map;
+   struct hclge_qs_to_pri_link_cmd *map;
+   struct hclge_tqp_tx_queue_tc_cmd *tc;
+   enum hclge_opcode_type cmd;
+   struct hclge_desc desc;
+   int queue_id, group_id;
+   u32 qset_maping[32];
+   int tc_id, qset_id;
+   int pri_id, ret;
+   u32 i;
+
+   ret = kstrtouint(&cmd_buf[12], 10, &queue_id);
+   queue_id = (ret != 0) ? 0 : queue_id;
+
+   cmd = HCLGE_OPC_TM_NQ_TO_QS_LINK;
+   nq_to_qs_map = (struct hclge_nq_to_qs_link_cmd *)desc.data;
+   hclge_cmd_setup_basic_desc(&desc, cmd, true);
+   nq_to_qs_map->nq_id = cpu_to_le16(queue_id);
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret)
+   goto err_tm_map_cmd_send;
+   qset_id = nq_to_qs_map->qset_id & 0x3FF;
+
+   cmd = HCLGE_OPC_TM_QS_TO_PRI_LINK;
+   map = (struct hclge_qs_to_pri_link_cmd *)desc.data;
+   hclge_cmd_setup_basic_desc(&desc, cmd, true);
+   map->qs_id = cpu_to_le16(qset_id);
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret)
+   goto err_tm_map_cmd_send;
+   pri_id = map->priority;
+
+   cmd = HCLGE_OPC_TQP_TX_QUEUE_TC;
+   tc = (struct hclge_tqp_tx_queue_tc_cmd *)desc.data;
+   hclge_cmd_setup_basic_desc(&desc, cmd, true);
+   tc->queue_id = cpu_to_le16(queue_id);
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret)
+   goto err_tm_map_cmd_send;
+   tc_id = tc->tc_id & 0x7;
+
+   dev_info(&hdev->pdev->dev, "queue_id | qset_id | pri_id | tc_id\n");
+   dev_info(&hdev->pdev->dev, "%04d | %04d| %02d | %02d\n",
+queue_id, qset_id, pri_id, tc_id);
+
+   cmd = HCLGE_OPC_TM_BP_TO_QSET_MAPPING;
+   bp_to_qs_map_cmd = (struct hclge_bp_to_qs_map_cmd *)desc.data;
+   for (group_id = 0; group_id < 32; group_id++) {
+   hclge_cmd_setup_basic_desc(&desc, cmd, true);
+   bp_to_qs_map_cmd->tc_id = tc_id;
+   bp_to_qs_map_cmd->qs_group_id = group_id;
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret)
+   goto err_tm_map_cmd_send;
+
+   qset_m

[PATCH net-next 4/6] net: hns3: Add "dcb register" status information query function

2018-12-11 Thread Salil Mehta
From: liuzhongzhu 

This patch prints dcb register status  information by module.

debugfs command:
root@(none)# echo dump reg dcb > cmd
 roce_qset_mask: 0x0
 nic_qs_mask: 0x0
 qs_shaping_pass: 0x0
 qs_bp_sts: 0x0
 pri_mask: 0x0
 pri_cshaping_pass: 0x0
 pri_pshaping_pass: 0x0
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c |   7 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |   9 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 102 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h |  16 
 4 files changed, 134 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index c34d412..be11e3d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -226,6 +226,13 @@ static void hns3_dbg_help(struct hnae3_handle *h)
" [rtc] [ppp] [rcb] [tqp ]]\n",
HNS3_DBG_BUF_LEN - strlen(printf_buf));
dev_info(&h->pdev->dev, "%s", printf_buf);
+
+   memset(printf_buf, 0, HNS3_DBG_BUF_LEN);
+   strncat(printf_buf, "dump reg dcb [port_id] [pri_id] [pg_id]",
+   HNS3_DBG_BUF_LEN);
+   strncat(printf_buf + strlen(printf_buf), " [rq_id] [nq_id] [qset_id]\n",
+   HNS3_DBG_BUF_LEN - strlen(printf_buf));
+   dev_info(&h->pdev->dev, "%s", printf_buf);
 }
 
 static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 5d69e0d..dc8b7c2 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -140,6 +140,15 @@ enum hclge_opcode_type {
HCLGE_OPC_TM_QS_SCH_MODE_CFG= 0x0814,
HCLGE_OPC_TM_BP_TO_QSET_MAPPING = 0x0815,
HCLGE_OPC_ETS_TC_WEIGHT = 0x0843,
+   HCLGE_OPC_QSET_DFX_STS  = 0x0844,
+   HCLGE_OPC_PRI_DFX_STS   = 0x0845,
+   HCLGE_OPC_PG_DFX_STS= 0x0846,
+   HCLGE_OPC_PORT_DFX_STS  = 0x0847,
+   HCLGE_OPC_SCH_NQ_CNT= 0x0848,
+   HCLGE_OPC_SCH_RQ_CNT= 0x0849,
+   HCLGE_OPC_TM_INTERNAL_STS   = 0x0850,
+   HCLGE_OPC_TM_INTERNAL_CNT   = 0x0851,
+   HCLGE_OPC_TM_INTERNAL_STS_1 = 0x0852,
 
/* Packet buffer allocate commands */
HCLGE_OPC_TX_BUFF_ALLOC = 0x0901,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
index 3aa3483..d1d693b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
@@ -107,6 +107,106 @@ static void hclge_dbg_dump_reg_common(struct hclge_dev 
*hdev,
kfree(desc_src);
 }
 
+static void hclge_dbg_dump_dcb(struct hclge_dev *hdev, char *cmd_buf)
+{
+   struct device *dev = &hdev->pdev->dev;
+   struct hclge_dbg_bitmap_cmd *bitmap;
+   int rq_id, pri_id, qset_id;
+   int port_id, nq_id, pg_id;
+   struct hclge_desc desc[2];
+
+   int cnt, ret;
+
+   cnt = sscanf(cmd_buf, "%i %i %i %i %i %i",
+&port_id, &pri_id, &pg_id, &rq_id, &nq_id, &qset_id);
+   if (cnt != 6) {
+   dev_err(&hdev->pdev->dev,
+   "dump dcb: bad command parameter, cnt=%d\n", cnt);
+   return;
+   }
+
+   ret = hclge_dbg_cmd_send(hdev, desc, qset_id, 1,
+HCLGE_OPC_QSET_DFX_STS);
+   if (ret)
+   return;
+
+   bitmap = (struct hclge_dbg_bitmap_cmd *)&desc[0].data[1];
+   dev_info(dev, "roce_qset_mask: 0x%x\n", bitmap->bit0);
+   dev_info(dev, "nic_qs_mask: 0x%x\n", bitmap->bit1);
+   dev_info(dev, "qs_shaping_pass: 0x%x\n", bitmap->bit2);
+   dev_info(dev, "qs_bp_sts: 0x%x\n", bitmap->bit3);
+
+   ret = hclge_dbg_cmd_send(hdev, desc, pri_id, 1, HCLGE_OPC_PRI_DFX_STS);
+   if (ret)
+   return;
+
+   bitmap = (struct hclge_dbg_bitmap_cmd *)&desc[0].data[1];
+   dev_info(dev, "pri_mask: 0x%x\n", bitmap->bit0);
+   dev_info(dev, "pri_cshaping_pass: 0x%x\n", bitmap->bit1);
+   dev_info(dev, "pri_pshaping_pass: 0x%x\n", bitmap->bit2);
+
+   ret = hclge_dbg_cmd_send(hdev, desc, pg_id, 1, HCLGE_OPC_PG_DFX_STS);
+   if (ret)
+   return;
+
+   bitmap = (struct hclge_dbg_bitmap_cmd *)&desc[0].data[1];
+   dev_info(dev, "pg_mask: 0x%x\n", bitmap->bit0);
+   dev_info(dev, "pg_cshaping_pass: 0x%x\

[PATCH net-next 01/14] net: hns3: remove existing process error functions and reorder hw_blk table

2018-12-07 Thread Salil Mehta
From: Shiju Jose 

1.The command interface for queryng and clearing hw errors is
  changed, which requires the new process error functions to be added.
  This patch removes all the current process error functions and
  associated definitions. The new functions to handle ras errors
  would be added in this patch set.

2. Fixed order issue of the hw_blk table.

Signed-off-by: Shiju Jose 
Signed-off-by: Salil Mehta 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  12 -
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c | 462 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h |  19 -
 3 files changed, 18 insertions(+), 475 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index e1805b9..d2fb210 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -216,25 +216,13 @@ enum hclge_opcode_type {
 
/* Error INT commands */
HCLGE_TM_SCH_ECC_INT_EN = 0x0829,
-   HCLGE_TM_SCH_ECC_ERR_RINT_CMD   = 0x082d,
-   HCLGE_TM_SCH_ECC_ERR_RINT_CE= 0x082f,
-   HCLGE_TM_SCH_ECC_ERR_RINT_NFE   = 0x0830,
-   HCLGE_TM_SCH_ECC_ERR_RINT_FE= 0x0831,
-   HCLGE_TM_SCH_MBIT_ECC_INFO_CMD  = 0x0833,
HCLGE_COMMON_ECC_INT_CFG= 0x1505,
-   HCLGE_IGU_EGU_TNL_INT_QUERY = 0x1802,
HCLGE_IGU_EGU_TNL_INT_EN= 0x1803,
-   HCLGE_IGU_EGU_TNL_INT_CLR   = 0x1804,
-   HCLGE_IGU_COMMON_INT_QUERY  = 0x1805,
HCLGE_IGU_COMMON_INT_EN = 0x1806,
-   HCLGE_IGU_COMMON_INT_CLR= 0x1807,
HCLGE_TM_QCN_MEM_INT_CFG= 0x1A14,
-   HCLGE_TM_QCN_MEM_INT_INFO_CMD   = 0x1A17,
HCLGE_PPP_CMD0_INT_CMD  = 0x2100,
HCLGE_PPP_CMD1_INT_CMD  = 0x2101,
-   HCLGE_NCSI_INT_QUERY= 0x2400,
HCLGE_NCSI_INT_EN   = 0x2401,
-   HCLGE_NCSI_INT_CLR  = 0x2402,
 };
 
 #define HCLGE_TQP_REG_OFFSET   0x8
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
index 6da9e22..ac9ab3c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
@@ -336,25 +336,6 @@ static const struct hclge_hw_error hclge_qcn_ecc_err_int[] 
= {
{ /* sentinel */ }
 };
 
-static void hclge_log_error(struct device *dev,
-   const struct hclge_hw_error *err_list,
-   u32 err_sts)
-{
-   const struct hclge_hw_error *err;
-   int i = 0;
-
-   while (err_list[i].msg) {
-   err = &err_list[i];
-   if (!(err->int_msk & err_sts)) {
-   i++;
-   continue;
-   }
-   dev_warn(dev, "%s [error status=0x%x] found\n",
-err->msg, err_sts);
-   i++;
-   }
-}
-
 /* hclge_cmd_query_error: read the error information
  * @hdev: pointer to struct hclge_dev
  * @desc: descriptor for describing the command
@@ -391,53 +372,6 @@ static int hclge_cmd_query_error(struct hclge_dev *hdev,
return ret;
 }
 
-/* hclge_cmd_clear_error: clear the error status
- * @hdev: pointer to struct hclge_dev
- * @desc: descriptor for describing the command
- * @desc_src: prefilled descriptor from the previous command for reusing
- * @cmd:  command opcode
- * @flag: flag for extended command structure
- *
- * This function clear the error status in the hw register/s using command
- */
-static int hclge_cmd_clear_error(struct hclge_dev *hdev,
-struct hclge_desc *desc,
-struct hclge_desc *desc_src,
-u32 cmd, u16 flag)
-{
-   struct device *dev = &hdev->pdev->dev;
-   int num = 1;
-   int ret, i;
-
-   if (cmd) {
-   hclge_cmd_setup_basic_desc(&desc[0], cmd, false);
-   if (flag) {
-   desc[0].flag |= cpu_to_le16(flag);
-   hclge_cmd_setup_basic_desc(&desc[1], cmd, false);
-   num = 2;
-   }
-   if (desc_src) {
-   for (i = 0; i < 6; i++) {
-   desc[0].data[i] = desc_src[0].data[i];
-   if (flag)
-   desc[1].data[i] = desc_src[1].data[i];
-   }
-   }
-   } else {
-   hclge_cmd_reuse_desc(&desc[0], false);
-   if (flag) {
-   desc[0].flag |= cpu_to_le16(flag);
-   hclge_cmd_reuse_desc(&desc[1], false);
-   num = 2;
-   }
-   }
-   ret = hclge_cmd_send(&hdev->hw, &des

[PATCH net-next 00/14] net: hns3: Additions/optimizations related to HNS3 H/W err handling

2018-12-07 Thread Salil Mehta
This patch set primarily does following addtions and optimizations
related to error handling in HNS3 Ethernet driver:

 1. Name changes for enable and process functions and minor loop
optimizations. [PATCH 1-6]
 2. Modify query and clearing of RAS errors using new set of commands
because modules specific commands for clearing RCB PPP PF, SSU are
obselete. [PATCH 7]
 3. Deletes logging 1-bit errors for RAS in HNS3 driver as these never
get reported to the driver. [PATCH 8]
 4. Add handling of NIC hw errors reported through MSIx rather than
PCIe AER channel. [PATCH 9]
 5. Add handling for the HW RAS and MSIx errors in the modules MAC, PPP
PF, MSIx SRAM, RCB and SSU. [PATCH 10-13]
 6. Add handling of RoCEE RAS errors. [PATCH 14]

Salil Mehta (1):
  net: hns3: add handling of hw errors reported through MSIX

Shiju Jose (13):
  net: hns3: remove existing process error functions and reorder hw_blk
table
  net: hns3: rename enable error interrupt functions
  net: hns3: re-enable error interrupts on hw reset
  net: hns3: deletes unnecessary settings of the descriptor data
  net: hns3: rename process_hw_error function
  net: hns3: add optimization in the hclge_hw_error_set_state
  net: hns3: add handling of hw ras errors using new set of commands
  net: hns3: deleted logging 1 bit errors
  net: hns3: add handling of hw errors of MAC
  net: hns3: handle hw errors of PPP PF
  net: hns3: handle hw errors of PPU(RCB)
  net: hns3: handle hw errors of SSU
  net: hns3: add handling of RDMA RAS errors

 drivers/net/ethernet/hisilicon/hns3/hnae3.h|3 +-
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c|4 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |   27 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c | 1554 
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h |   79 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c|   55 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|1 +
 7 files changed, 1067 insertions(+), 656 deletions(-)

-- 
2.7.4




[PATCH net-next 12/14] net: hns3: handle hw errors of PPU(RCB)

2018-12-07 Thread Salil Mehta
From: Shiju Jose 

This patch enables and handles hw RAS and MSIx errors of PPU(RCB).

Signed-off-by: Shiju Jose 
Signed-off-by: Salil Mehta 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |   3 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c | 162 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h |  15 ++
 3 files changed, 180 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 46af567..0223e83 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -217,6 +217,9 @@ enum hclge_opcode_type {
/* Error INT commands */
HCLGE_MAC_COMMON_INT_EN = 0x030E,
HCLGE_TM_SCH_ECC_INT_EN = 0x0829,
+   HCLGE_PPU_MPF_ECC_INT_CMD   = 0x0B40,
+   HCLGE_PPU_MPF_OTHER_INT_CMD = 0x0B41,
+   HCLGE_PPU_PF_OTHER_INT_CMD  = 0x0B42,
HCLGE_COMMON_ECC_INT_CFG= 0x1505,
HCLGE_QUERY_RAS_INT_STS_BD_NUM  = 0x1510,
HCLGE_QUERY_CLEAR_MPF_RAS_INT   = 0x1511,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
index e82ef4f..00086ce 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
@@ -222,6 +222,47 @@ static const struct hclge_hw_error 
hclge_mac_afifo_tnl_int[] = {
{ /* sentinel */ }
 };
 
+static const struct hclge_hw_error hclge_ppu_mpf_abnormal_int_st2[] = {
+   { .int_msk = BIT(13), .msg = "rpu_rx_pkt_bit32_ecc_mbit_err" },
+   { .int_msk = BIT(14), .msg = "rpu_rx_pkt_bit33_ecc_mbit_err" },
+   { .int_msk = BIT(15), .msg = "rpu_rx_pkt_bit34_ecc_mbit_err" },
+   { .int_msk = BIT(16), .msg = "rpu_rx_pkt_bit35_ecc_mbit_err" },
+   { .int_msk = BIT(17), .msg = "rcb_tx_ring_ecc_mbit_err" },
+   { .int_msk = BIT(18), .msg = "rcb_rx_ring_ecc_mbit_err" },
+   { .int_msk = BIT(19), .msg = "rcb_tx_fbd_ecc_mbit_err" },
+   { .int_msk = BIT(20), .msg = "rcb_rx_ebd_ecc_mbit_err" },
+   { .int_msk = BIT(21), .msg = "rcb_tso_info_ecc_mbit_err" },
+   { .int_msk = BIT(22), .msg = "rcb_tx_int_info_ecc_mbit_err" },
+   { .int_msk = BIT(23), .msg = "rcb_rx_int_info_ecc_mbit_err" },
+   { .int_msk = BIT(24), .msg = "tpu_tx_pkt_0_ecc_mbit_err" },
+   { .int_msk = BIT(25), .msg = "tpu_tx_pkt_1_ecc_mbit_err" },
+   { .int_msk = BIT(26), .msg = "rd_bus_err" },
+   { .int_msk = BIT(27), .msg = "wr_bus_err" },
+   { .int_msk = BIT(28), .msg = "reg_search_miss" },
+   { .int_msk = BIT(29), .msg = "rx_q_search_miss" },
+   { .int_msk = BIT(30), .msg = "ooo_ecc_err_detect" },
+   { .int_msk = BIT(31), .msg = "ooo_ecc_err_multpl" },
+   { /* sentinel */ }
+};
+
+static const struct hclge_hw_error hclge_ppu_mpf_abnormal_int_st3[] = {
+   { .int_msk = BIT(4), .msg = "gro_bd_ecc_mbit_err" },
+   { .int_msk = BIT(5), .msg = "gro_context_ecc_mbit_err" },
+   { .int_msk = BIT(6), .msg = "rx_stash_cfg_ecc_mbit_err" },
+   { .int_msk = BIT(7), .msg = "axi_rd_fbd_ecc_mbit_err" },
+   { /* sentinel */ }
+};
+
+static const struct hclge_hw_error hclge_ppu_pf_abnormal_int[] = {
+   { .int_msk = BIT(0), .msg = "over_8bd_no_fe" },
+   { .int_msk = BIT(1), .msg = "tso_mss_cmp_min_err" },
+   { .int_msk = BIT(2), .msg = "tso_mss_cmp_max_err" },
+   { .int_msk = BIT(3), .msg = "tx_rd_fbd_poison" },
+   { .int_msk = BIT(4), .msg = "rx_rd_ebd_poison" },
+   { .int_msk = BIT(5), .msg = "buf_wait_timeout" },
+   { /* sentinel */ }
+};
+
 static void hclge_log_error(struct device *dev, char *reg,
const struct hclge_hw_error *err,
u32 err_sts)
@@ -489,6 +530,82 @@ static int hclge_config_mac_err_int(struct hclge_dev 
*hdev, bool en)
return ret;
 }
 
+static int hclge_config_ppu_error_interrupts(struct hclge_dev *hdev, u32 cmd,
+bool en)
+{
+   struct device *dev = &hdev->pdev->dev;
+   struct hclge_desc desc[2];
+   int num = 1;
+   int ret;
+
+   /* configure PPU error interrupts */
+   if (cmd == HCLGE_PPU_MPF_ECC_INT_CMD) {
+   hclge_cmd_setup_basic_desc(&desc[0], cmd, false);
+   desc[0].flag |= HCLGE_CMD_FLAG_NEXT;
+   hclge_cmd_setup_basic_desc(&desc[1], cmd, false);
+   if (en) {
+   desc[0].data[0] = HCLGE_PPU_MPF_ABNORMAL_INT0_EN;
+   desc[0].dat

[PATCH net-next 07/14] net: hns3: add handling of hw ras errors using new set of commands

2018-12-07 Thread Salil Mehta
From: Shiju Jose 

1. This patch adds handling of hw ras errors using new set of
   common commands.
2. Updated the error message tables to match the register's name and
   error status returned by the commands.

Signed-off-by: Shiju Jose 
Signed-off-by: Salil Mehta 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |   3 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c | 489 ++---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h |   9 +
 3 files changed, 331 insertions(+), 170 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index d2fb210..0a0eb6c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -217,6 +217,9 @@ enum hclge_opcode_type {
/* Error INT commands */
HCLGE_TM_SCH_ECC_INT_EN = 0x0829,
HCLGE_COMMON_ECC_INT_CFG= 0x1505,
+   HCLGE_QUERY_RAS_INT_STS_BD_NUM  = 0x1510,
+   HCLGE_QUERY_CLEAR_MPF_RAS_INT   = 0x1511,
+   HCLGE_QUERY_CLEAR_PF_RAS_INT= 0x1512,
HCLGE_IGU_EGU_TNL_INT_EN= 0x1803,
HCLGE_IGU_COMMON_INT_EN = 0x1806,
HCLGE_TM_QCN_MEM_INT_CFG= 0x1A14,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
index d1c9f7a..22e7c5b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
@@ -20,12 +20,7 @@ static const struct hclge_hw_error hclge_imp_tcm_ecc_int[] = 
{
{ .int_msk = BIT(13), .msg = "imp_dtcm1_mem0_ecc_mbit_err" },
{ .int_msk = BIT(14), .msg = "imp_dtcm1_mem1_ecc_1bit_err" },
{ .int_msk = BIT(15), .msg = "imp_dtcm1_mem1_ecc_mbit_err" },
-   { /* sentinel */ }
-};
-
-static const struct hclge_hw_error hclge_imp_itcm4_ecc_int[] = {
-   { .int_msk = BIT(0), .msg = "imp_itcm4_ecc_1bit_err" },
-   { .int_msk = BIT(1), .msg = "imp_itcm4_ecc_mbit_err" },
+   { .int_msk = BIT(17), .msg = "imp_itcm4_ecc_mbit_err" },
{ /* sentinel */ }
 };
 
@@ -46,26 +41,14 @@ static const struct hclge_hw_error 
hclge_cmdq_nic_mem_ecc_int[] = {
{ .int_msk = BIT(13), .msg = "cmdq_nic_rx_addr_ecc_mbit_err" },
{ .int_msk = BIT(14), .msg = "cmdq_nic_tx_addr_ecc_1bit_err" },
{ .int_msk = BIT(15), .msg = "cmdq_nic_tx_addr_ecc_mbit_err" },
-   { /* sentinel */ }
-};
-
-static const struct hclge_hw_error hclge_cmdq_rocee_mem_ecc_int[] = {
-   { .int_msk = BIT(0), .msg = "cmdq_rocee_rx_depth_ecc_1bit_err" },
-   { .int_msk = BIT(1), .msg = "cmdq_rocee_rx_depth_ecc_mbit_err" },
-   { .int_msk = BIT(2), .msg = "cmdq_rocee_tx_depth_ecc_1bit_err" },
-   { .int_msk = BIT(3), .msg = "cmdq_rocee_tx_depth_ecc_mbit_err" },
-   { .int_msk = BIT(4), .msg = "cmdq_rocee_rx_tail_ecc_1bit_err" },
-   { .int_msk = BIT(5), .msg = "cmdq_rocee_rx_tail_ecc_mbit_err" },
-   { .int_msk = BIT(6), .msg = "cmdq_rocee_tx_tail_ecc_1bit_err" },
-   { .int_msk = BIT(7), .msg = "cmdq_rocee_tx_tail_ecc_mbit_err" },
-   { .int_msk = BIT(8), .msg = "cmdq_rocee_rx_head_ecc_1bit_err" },
-   { .int_msk = BIT(9), .msg = "cmdq_rocee_rx_head_ecc_mbit_err" },
-   { .int_msk = BIT(10), .msg = "cmdq_rocee_tx_head_ecc_1bit_err" },
-   { .int_msk = BIT(11), .msg = "cmdq_rocee_tx_head_ecc_mbit_err" },
-   { .int_msk = BIT(12), .msg = "cmdq_rocee_rx_addr_ecc_1bit_err" },
-   { .int_msk = BIT(13), .msg = "cmdq_rocee_rx_addr_ecc_mbit_err" },
-   { .int_msk = BIT(14), .msg = "cmdq_rocee_tx_addr_ecc_1bit_err" },
-   { .int_msk = BIT(15), .msg = "cmdq_rocee_tx_addr_ecc_mbit_err" },
+   { .int_msk = BIT(17), .msg = "cmdq_rocee_rx_depth_ecc_mbit_err" },
+   { .int_msk = BIT(19), .msg = "cmdq_rocee_tx_depth_ecc_mbit_err" },
+   { .int_msk = BIT(21), .msg = "cmdq_rocee_rx_tail_ecc_mbit_err" },
+   { .int_msk = BIT(23), .msg = "cmdq_rocee_tx_tail_ecc_mbit_err" },
+   { .int_msk = BIT(25), .msg = "cmdq_rocee_rx_head_ecc_mbit_err" },
+   { .int_msk = BIT(27), .msg = "cmdq_rocee_tx_head_ecc_mbit_err" },
+   { .int_msk = BIT(29), .msg = "cmdq_rocee_rx_addr_ecc_mbit_err" },
+   { .int_msk = BIT(31), .msg = "cmdq_rocee_tx_addr_ecc_mbit_err" },
{ /* sentinel */ }
 };
 
@@ -85,7 +68,13 @@ static const struct hclge_hw_error hclge_tqp_int_ecc_int[] = 
{
{ /* sentinel */ }
 };
 
-static const struct hclge_hw_error hclge_igu_com_err_int[] = {
+static const struct hclge_hw_error hclge_msix_sram_ecc_int[] = {
+   {

[PATCH net-next 10/14] net: hns3: add handling of hw errors of MAC

2018-12-07 Thread Salil Mehta
From: Shiju Jose 

This patch adds enable and handling of hw errors of
the MAC block.

Signed-off-by: Shiju Jose 
Signed-off-by: Salil Mehta 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  1 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c | 48 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h |  2 +
 3 files changed, 51 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 08d02b9..46af567 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -215,6 +215,7 @@ enum hclge_opcode_type {
HCLGE_OPC_SFP_GET_SPEED = 0x7104,
 
/* Error INT commands */
+   HCLGE_MAC_COMMON_INT_EN = 0x030E,
HCLGE_TM_SCH_ECC_INT_EN = 0x0829,
HCLGE_COMMON_ECC_INT_CFG= 0x1505,
HCLGE_QUERY_RAS_INT_STS_BD_NUM  = 0x1510,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
index 0676670..20f8bb5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
@@ -210,6 +210,18 @@ static const struct hclge_hw_error hclge_qcn_ecc_rint[] = {
{ /* sentinel */ }
 };
 
+static const struct hclge_hw_error hclge_mac_afifo_tnl_int[] = {
+   { .int_msk = BIT(0), .msg = "egu_cge_afifo_ecc_1bit_err" },
+   { .int_msk = BIT(1), .msg = "egu_cge_afifo_ecc_mbit_err" },
+   { .int_msk = BIT(2), .msg = "egu_lge_afifo_ecc_1bit_err" },
+   { .int_msk = BIT(3), .msg = "egu_lge_afifo_ecc_mbit_err" },
+   { .int_msk = BIT(4), .msg = "cge_igu_afifo_ecc_1bit_err" },
+   { .int_msk = BIT(5), .msg = "cge_igu_afifo_ecc_mbit_err" },
+   { .int_msk = BIT(6), .msg = "lge_igu_afifo_ecc_1bit_err" },
+   { .int_msk = BIT(7), .msg = "lge_igu_afifo_ecc_mbit_err" },
+   { /* sentinel */ }
+};
+
 static void hclge_log_error(struct device *dev, char *reg,
const struct hclge_hw_error *err,
u32 err_sts)
@@ -452,6 +464,27 @@ static int hclge_config_tm_hw_err_int(struct hclge_dev 
*hdev, bool en)
return ret;
 }
 
+static int hclge_config_mac_err_int(struct hclge_dev *hdev, bool en)
+{
+   struct device *dev = &hdev->pdev->dev;
+   struct hclge_desc desc;
+   int ret;
+
+   /* configure MAC common error interrupts */
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_MAC_COMMON_INT_EN, false);
+   if (en)
+   desc.data[0] = cpu_to_le32(HCLGE_MAC_COMMON_ERR_INT_EN);
+
+   desc.data[1] = cpu_to_le32(HCLGE_MAC_COMMON_ERR_INT_EN_MASK);
+
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret)
+   dev_err(dev,
+   "fail(%d) to configure MAC COMMON error intr\n", ret);
+
+   return ret;
+}
+
 #define HCLGE_SET_DEFAULT_RESET_REQUEST(reset_type) \
do { \
if (ae_dev->ops->set_default_reset_request) \
@@ -688,6 +721,10 @@ static const struct hclge_hw_blk hw_blk[] = {
  .msk = BIT(5), .name = "COMMON",
  .config_err_int = hclge_config_common_hw_err_int,
},
+   {
+ .msk = BIT(8), .name = "MAC",
+ .config_err_int = hclge_config_mac_err_int,
+   },
{ /* sentinel */ }
 };
 
@@ -735,7 +772,9 @@ int hclge_handle_hw_msix_error(struct hclge_dev *hdev,
u32 mpf_bd_num, pf_bd_num, bd_num;
struct hclge_desc desc_bd;
struct hclge_desc *desc;
+   __le32 *desc_data;
int ret = 0;
+   u32 status;
 
/* set default handling */
set_bit(HNAE3_FUNC_RESET, reset_requests);
@@ -774,6 +813,15 @@ int hclge_handle_hw_msix_error(struct hclge_dev *hdev,
goto msi_error;
}
 
+   /* log MAC errors */
+   desc_data = (__le32 *)&desc[1];
+   status = le32_to_cpu(*desc_data);
+   if (status) {
+   hclge_log_error(dev, "MAC_AFIFO_TNL_INT_R",
+   &hclge_mac_afifo_tnl_int[0], status);
+   set_bit(HNAE3_GLOBAL_RESET, reset_requests);
+   }
+
/* clear all main PF MSIx errors */
hclge_cmd_reuse_desc(&desc[0], false);
desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h
index 05adccb..8e7d151 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h
@@ -44,6 +44,8 @@
 #define HCLGE_TM_QCN_MEM_ERR_INT_EN0xFF
 #define HCLGE_NCSI_ERR_INT_EN  0x3
 #define HCLGE_NCSI_ERR_INT_TYPE0x9
+#define HCLGE_MAC_COMMON

[PATCH net-next 09/14] net: hns3: add handling of hw errors reported through MSIX

2018-12-07 Thread Salil Mehta
This patch adds handling for HNS3 hardware errors(non-standard)
which are reported through MSIX interrupts and not through
PCIe AER channel.

These MSIX reported hardware errors are handled using common
misc. interrupt handler. Hardware error related registers
cannot be cleared in context to the interrupt received as
they require *heavy* access to hardware using IMP(Integrated
Mangement Processor) commands. Hence, we defer the clearing
of such error events till later time.

Since, we have defered exact identification of errors we
will have to defer the level of receovery/reset which
might be required. Hence, a new reset type UNKNOWN reset
has been introduced which effectively defers the assertion
of the reset till we get hold of kind of errors at later
time.

Signed-off-by: Salil Mehta 
Signed-off-by: Shiju Jose 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  1 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  3 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c | 93 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h |  5 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 39 -
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  1 +
 6 files changed, 140 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index 9d9f4f9..294e725 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -136,6 +136,7 @@ enum hnae3_reset_type {
HNAE3_CORE_RESET,
HNAE3_GLOBAL_RESET,
HNAE3_IMP_RESET,
+   HNAE3_UNKNOWN_RESET,
HNAE3_NONE_RESET,
 };
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 0a0eb6c..08d02b9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -220,6 +220,9 @@ enum hclge_opcode_type {
HCLGE_QUERY_RAS_INT_STS_BD_NUM  = 0x1510,
HCLGE_QUERY_CLEAR_MPF_RAS_INT   = 0x1511,
HCLGE_QUERY_CLEAR_PF_RAS_INT= 0x1512,
+   HCLGE_QUERY_MSIX_INT_STS_BD_NUM = 0x1513,
+   HCLGE_QUERY_CLEAR_ALL_MPF_MSIX_INT  = 0x1514,
+   HCLGE_QUERY_CLEAR_ALL_PF_MSIX_INT   = 0x1515,
HCLGE_IGU_EGU_TNL_INT_EN= 0x1803,
HCLGE_IGU_COMMON_INT_EN = 0x1806,
HCLGE_TM_QCN_MEM_INT_CFG= 0x1A14,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
index 7371ae4..0676670 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
@@ -727,3 +727,96 @@ pci_ers_result_t hclge_handle_hw_ras_error(struct 
hnae3_ae_dev *ae_dev)
 
return PCI_ERS_RESULT_RECOVERED;
 }
+
+int hclge_handle_hw_msix_error(struct hclge_dev *hdev,
+  unsigned long *reset_requests)
+{
+   struct device *dev = &hdev->pdev->dev;
+   u32 mpf_bd_num, pf_bd_num, bd_num;
+   struct hclge_desc desc_bd;
+   struct hclge_desc *desc;
+   int ret = 0;
+
+   /* set default handling */
+   set_bit(HNAE3_FUNC_RESET, reset_requests);
+
+   /* query the number of bds for the MSIx int status */
+   hclge_cmd_setup_basic_desc(&desc_bd, HCLGE_QUERY_MSIX_INT_STS_BD_NUM,
+  true);
+   ret = hclge_cmd_send(&hdev->hw, &desc_bd, 1);
+   if (ret) {
+   dev_err(dev, "fail(%d) to query msix int status bd num\n",
+   ret);
+   /* reset everything for now */
+   set_bit(HNAE3_GLOBAL_RESET, reset_requests);
+   return ret;
+   }
+
+   mpf_bd_num = le32_to_cpu(desc_bd.data[0]);
+   pf_bd_num = le32_to_cpu(desc_bd.data[1]);
+   bd_num = max_t(u32, mpf_bd_num, pf_bd_num);
+
+   desc = kcalloc(bd_num, sizeof(struct hclge_desc), GFP_KERNEL);
+   if (!desc)
+   goto out;
+
+   /* query all main PF MSIx errors */
+   hclge_cmd_setup_basic_desc(&desc[0], HCLGE_QUERY_CLEAR_ALL_MPF_MSIX_INT,
+  true);
+   desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+
+   ret = hclge_cmd_send(&hdev->hw, &desc[0], mpf_bd_num);
+   if (ret) {
+   dev_err(dev, "query all mpf msix int cmd failed (%d)\n",
+   ret);
+   /* reset everything for now */
+   set_bit(HNAE3_GLOBAL_RESET, reset_requests);
+   goto msi_error;
+   }
+
+   /* clear all main PF MSIx errors */
+   hclge_cmd_reuse_desc(&desc[0], false);
+   desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+
+   ret = hclge_cmd_send(&hdev->hw, &desc[0], mpf_bd_num);
+   if (ret) {
+   dev_err(dev, "clear all mpf msi

[PATCH net-next 03/14] net: hns3: re-enable error interrupts on hw reset

2018-12-07 Thread Salil Mehta
From: Shiju Jose 

This patch adds calling hclge_hw_error_set_state function
to re-enable the error interrupts those will be disabled on
the hw reset.

Signed-off-by: Shiju Jose 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c  |  2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h  |  1 -
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 14 +-
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
index 21437fe..7e23d36 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
@@ -540,7 +540,7 @@ static int hclge_config_ppp_hw_err_int(struct hclge_dev 
*hdev, bool en)
return ret;
 }
 
-int hclge_config_tm_hw_err_int(struct hclge_dev *hdev, bool en)
+static int hclge_config_tm_hw_err_int(struct hclge_dev *hdev, bool en)
 {
struct device *dev = &hdev->pdev->dev;
struct hclge_desc desc;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h
index 856374c..405739b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h
@@ -59,6 +59,5 @@ struct hclge_hw_error {
 };
 
 int hclge_hw_error_set_state(struct hclge_dev *hdev, bool state);
-int hclge_config_tm_hw_err_int(struct hclge_dev *hdev, bool en);
 pci_ers_result_t hclge_process_ras_hw_error(struct hnae3_ae_dev *ae_dev);
 #endif
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 5cea95c..431d92a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -7269,7 +7269,7 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
ret = hclge_hw_error_set_state(hdev, true);
if (ret) {
dev_err(&pdev->dev,
-   "hw error interrupts enable failed, ret =%d\n", ret);
+   "fail(%d) to enable hw error interrupts\n", ret);
goto err_mdiobus_unreg;
}
 
@@ -7405,11 +7405,15 @@ static int hclge_reset_ae_dev(struct hnae3_ae_dev 
*ae_dev)
return ret;
}
 
-   /* Re-enable the TM hw error interrupts because
-* they get disabled on core/global reset.
+   /* Re-enable the hw error interrupts because
+* the interrupts get disabled on core/global reset.
 */
-   if (hclge_config_tm_hw_err_int(hdev, true))
-   dev_err(&pdev->dev, "failed to enable TM hw error 
interrupts\n");
+   ret = hclge_hw_error_set_state(hdev, true);
+   if (ret) {
+   dev_err(&pdev->dev,
+   "fail(%d) to re-enable HNS hw error interrupts\n", ret);
+   return ret;
+   }
 
hclge_reset_vport_state(hdev);
 
-- 
2.7.4




[PATCH net-next 04/14] net: hns3: deletes unnecessary settings of the descriptor data

2018-12-07 Thread Salil Mehta
From: Shiju Jose 

This patch deletes unnecessary setting of the descriptor data
to 0 for disabling error interrupts because
it is already done by the hclge_cmd_setup_basic_desc function.

Signed-off-by: Shiju Jose 
Signed-off-by: Salil Mehta 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c | 27 --
 1 file changed, 5 insertions(+), 22 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
index 7e23d36..62fab23 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
@@ -390,13 +390,8 @@ static int hclge_config_common_hw_err_int(struct hclge_dev 
*hdev, bool en)
desc[0].data[3] = cpu_to_le32(HCLGE_IMP_RD_POISON_ERR_INT_EN);
desc[0].data[4] = cpu_to_le32(HCLGE_TQP_ECC_ERR_INT_EN);
desc[0].data[5] = cpu_to_le32(HCLGE_IMP_ITCM4_ECC_ERR_INT_EN);
-   } else {
-   desc[0].data[0] = 0;
-   desc[0].data[2] = 0;
-   desc[0].data[3] = 0;
-   desc[0].data[4] = 0;
-   desc[0].data[5] = 0;
}
+
desc[1].data[0] = cpu_to_le32(HCLGE_IMP_TCM_ECC_ERR_INT_EN_MASK);
desc[1].data[2] = cpu_to_le32(HCLGE_CMDQ_NIC_ECC_ERR_INT_EN_MASK |
HCLGE_CMDQ_ROCEE_ECC_ERR_INT_EN_MASK);
@@ -425,8 +420,6 @@ static int hclge_config_ncsi_hw_err_int(struct hclge_dev 
*hdev, bool en)
hclge_cmd_setup_basic_desc(&desc, HCLGE_NCSI_INT_EN, false);
if (en)
desc.data[0] = cpu_to_le32(HCLGE_NCSI_ERR_INT_EN);
-   else
-   desc.data[0] = 0;
 
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret)
@@ -446,8 +439,7 @@ static int hclge_config_igu_egu_hw_err_int(struct hclge_dev 
*hdev, bool en)
hclge_cmd_setup_basic_desc(&desc, HCLGE_IGU_COMMON_INT_EN, false);
if (en)
desc.data[0] = cpu_to_le32(HCLGE_IGU_ERR_INT_EN);
-   else
-   desc.data[0] = 0;
+
desc.data[1] = cpu_to_le32(HCLGE_IGU_ERR_INT_EN_MASK);
 
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
@@ -460,8 +452,7 @@ static int hclge_config_igu_egu_hw_err_int(struct hclge_dev 
*hdev, bool en)
hclge_cmd_setup_basic_desc(&desc, HCLGE_IGU_EGU_TNL_INT_EN, false);
if (en)
desc.data[0] = cpu_to_le32(HCLGE_IGU_TNL_ERR_INT_EN);
-   else
-   desc.data[0] = 0;
+
desc.data[1] = cpu_to_le32(HCLGE_IGU_TNL_ERR_INT_EN_MASK);
 
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
@@ -494,10 +485,8 @@ static int hclge_config_ppp_error_interrupt(struct 
hclge_dev *hdev, u32 cmd,
cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT0_EN);
desc[0].data[1] =
cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT1_EN);
-   } else {
-   desc[0].data[0] = 0;
-   desc[0].data[1] = 0;
}
+
desc[1].data[0] =
cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT0_EN_MASK);
desc[1].data[1] =
@@ -508,10 +497,8 @@ static int hclge_config_ppp_error_interrupt(struct 
hclge_dev *hdev, u32 cmd,
cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT2_EN);
desc[0].data[1] =
cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT3_EN);
-   } else {
-   desc[0].data[0] = 0;
-   desc[0].data[1] = 0;
}
+
desc[1].data[0] =
cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT2_EN_MASK);
desc[1].data[1] =
@@ -550,8 +537,6 @@ static int hclge_config_tm_hw_err_int(struct hclge_dev 
*hdev, bool en)
hclge_cmd_setup_basic_desc(&desc, HCLGE_TM_SCH_ECC_INT_EN, false);
if (en)
desc.data[0] = cpu_to_le32(HCLGE_TM_SCH_ECC_ERR_INT_EN);
-   else
-   desc.data[0] = 0;
 
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
@@ -570,8 +555,6 @@ static int hclge_config_tm_hw_err_int(struct hclge_dev 
*hdev, bool en)
hclge_cmd_reuse_desc(&desc, false);
if (en)
desc.data[1] = cpu_to_le32(HCLGE_TM_QCN_MEM_ERR_INT_EN);
-   else
-   desc.data[1] = 0;
 
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret)
-- 
2.7.4




[PATCH net-next 02/14] net: hns3: rename enable error interrupt functions

2018-12-07 Thread Salil Mehta
From: Shiju Jose 

This patch
- renames the enable error interrupt functions.
  The reason is that these functions
  are used for both enable and disable error interrupts.

- removes redundant logs from the enable error interrupt functions.

Signed-off-by: Shiju Jose 
Signed-off-by: Salil Mehta 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c | 83 --
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h |  4 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c|  2 +-
 3 files changed, 34 insertions(+), 55 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
index ac9ab3c..21437fe 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
@@ -372,18 +372,18 @@ static int hclge_cmd_query_error(struct hclge_dev *hdev,
return ret;
 }
 
-static int hclge_enable_common_error(struct hclge_dev *hdev, bool en)
+static int hclge_config_common_hw_err_int(struct hclge_dev *hdev, bool en)
 {
struct device *dev = &hdev->pdev->dev;
struct hclge_desc desc[2];
int ret;
 
+   /* configure common error interrupts */
hclge_cmd_setup_basic_desc(&desc[0], HCLGE_COMMON_ECC_INT_CFG, false);
desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
hclge_cmd_setup_basic_desc(&desc[1], HCLGE_COMMON_ECC_INT_CFG, false);
 
if (en) {
-   /* enable COMMON error interrupts */
desc[0].data[0] = cpu_to_le32(HCLGE_IMP_TCM_ECC_ERR_INT_EN);
desc[0].data[2] = cpu_to_le32(HCLGE_CMDQ_NIC_ECC_ERR_INT_EN |
HCLGE_CMDQ_ROCEE_ECC_ERR_INT_EN);
@@ -391,7 +391,6 @@ static int hclge_enable_common_error(struct hclge_dev 
*hdev, bool en)
desc[0].data[4] = cpu_to_le32(HCLGE_TQP_ECC_ERR_INT_EN);
desc[0].data[5] = cpu_to_le32(HCLGE_IMP_ITCM4_ECC_ERR_INT_EN);
} else {
-   /* disable COMMON error interrupts */
desc[0].data[0] = 0;
desc[0].data[2] = 0;
desc[0].data[3] = 0;
@@ -408,13 +407,12 @@ static int hclge_enable_common_error(struct hclge_dev 
*hdev, bool en)
ret = hclge_cmd_send(&hdev->hw, &desc[0], 2);
if (ret)
dev_err(dev,
-   "failed(%d) to enable/disable COMMON err interrupts\n",
-   ret);
+   "fail(%d) to configure common err interrupts\n", ret);
 
return ret;
 }
 
-static int hclge_enable_ncsi_error(struct hclge_dev *hdev, bool en)
+static int hclge_config_ncsi_hw_err_int(struct hclge_dev *hdev, bool en)
 {
struct device *dev = &hdev->pdev->dev;
struct hclge_desc desc;
@@ -423,7 +421,7 @@ static int hclge_enable_ncsi_error(struct hclge_dev *hdev, 
bool en)
if (hdev->pdev->revision < 0x21)
return 0;
 
-   /* enable/disable NCSI  error interrupts */
+   /* configure NCSI error interrupts */
hclge_cmd_setup_basic_desc(&desc, HCLGE_NCSI_INT_EN, false);
if (en)
desc.data[0] = cpu_to_le32(HCLGE_NCSI_ERR_INT_EN);
@@ -433,19 +431,18 @@ static int hclge_enable_ncsi_error(struct hclge_dev 
*hdev, bool en)
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret)
dev_err(dev,
-   "failed(%d) to enable/disable NCSI error interrupts\n",
-   ret);
+   "fail(%d) to configure  NCSI error interrupts\n", ret);
 
return ret;
 }
 
-static int hclge_enable_igu_egu_error(struct hclge_dev *hdev, bool en)
+static int hclge_config_igu_egu_hw_err_int(struct hclge_dev *hdev, bool en)
 {
struct device *dev = &hdev->pdev->dev;
struct hclge_desc desc;
int ret;
 
-   /* enable/disable error interrupts */
+   /* configure IGU,EGU error interrupts */
hclge_cmd_setup_basic_desc(&desc, HCLGE_IGU_COMMON_INT_EN, false);
if (en)
desc.data[0] = cpu_to_le32(HCLGE_IGU_ERR_INT_EN);
@@ -456,8 +453,7 @@ static int hclge_enable_igu_egu_error(struct hclge_dev 
*hdev, bool en)
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
dev_err(dev,
-   "failed(%d) to enable/disable IGU common interrupts\n",
-   ret);
+   "fail(%d) to configure IGU common interrupts\n", ret);
return ret;
}
 
@@ -471,26 +467,23 @@ static int hclge_enable_igu_egu_error(struct hclge_dev 
*hdev, bool en)
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
dev_err(dev,
-   "failed(%d) to enable/disable IGU-EGU TNL interrupts\n

[PATCH net-next 06/14] net: hns3: add optimization in the hclge_hw_error_set_state

2018-12-07 Thread Salil Mehta
From: Shiju Jose 

1. This patch adds minor loop optimization in the
   hclge_hw_error_set_state function.
2. Adds logging module's name if it fails to configure the
   error interrupts.

Signed-off-by: Shiju Jose 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
index 2d07be8..d1c9f7a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
@@ -586,18 +586,16 @@ static const struct hclge_hw_blk hw_blk[] = {
 
 int hclge_hw_error_set_state(struct hclge_dev *hdev, bool state)
 {
+   const struct hclge_hw_blk *module = hw_blk;
int ret = 0;
-   int i = 0;
 
-   while (hw_blk[i].name) {
-   if (!hw_blk[i].config_err_int) {
-   i++;
-   continue;
+   while (module->name) {
+   if (module->config_err_int) {
+   ret = module->config_err_int(hdev, state);
+   if (ret)
+   return ret;
}
-   ret = hw_blk[i].config_err_int(hdev, state);
-   if (ret)
-   return ret;
-   i++;
+   module++;
}
 
return ret;
-- 
2.7.4




[PATCH net-next 05/14] net: hns3: rename process_hw_error function

2018-12-07 Thread Salil Mehta
From: Shiju Jose 

This patch renames process_hw_error function to
handle_hw_ras_error function to match the purpose
of the function. This is because hw errors reported through
ras and msix interrupts will be handled separately.

Signed-off-by: Shiju Jose 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h | 2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 4 ++--
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c  | 2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h  | 2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index a1707b7..9d9f4f9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -454,7 +454,7 @@ struct hnae3_ae_ops {
int (*restore_fd_rules)(struct hnae3_handle *handle);
void (*enable_fd)(struct hnae3_handle *handle, bool enable);
int (*dbg_run_cmd)(struct hnae3_handle *handle, char *cmd_buf);
-   pci_ers_result_t (*process_hw_error)(struct hnae3_ae_dev *ae_dev);
+   pci_ers_result_t (*handle_hw_ras_error)(struct hnae3_ae_dev *ae_dev);
bool (*get_hw_reset_stat)(struct hnae3_handle *handle);
bool (*ae_dev_resetting)(struct hnae3_handle *handle);
unsigned long (*ae_dev_reset_cnt)(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 d1b2de2..69142a3 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1828,8 +1828,8 @@ static pci_ers_result_t hns3_error_detected(struct 
pci_dev *pdev,
return PCI_ERS_RESULT_NONE;
}
 
-   if (ae_dev->ops->process_hw_error)
-   ret = ae_dev->ops->process_hw_error(ae_dev);
+   if (ae_dev->ops->handle_hw_ras_error)
+   ret = ae_dev->ops->handle_hw_ras_error(ae_dev);
else
return PCI_ERS_RESULT_NONE;
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
index 62fab23..2d07be8 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
@@ -603,7 +603,7 @@ int hclge_hw_error_set_state(struct hclge_dev *hdev, bool 
state)
return ret;
 }
 
-pci_ers_result_t hclge_process_ras_hw_error(struct hnae3_ae_dev *ae_dev)
+pci_ers_result_t hclge_handle_hw_ras_error(struct hnae3_ae_dev *ae_dev)
 {
struct hclge_dev *hdev = ae_dev->priv;
struct device *dev = &hdev->pdev->dev;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h
index 405739b..9fe1c96 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h
@@ -59,5 +59,5 @@ struct hclge_hw_error {
 };
 
 int hclge_hw_error_set_state(struct hclge_dev *hdev, bool state);
-pci_ers_result_t hclge_process_ras_hw_error(struct hnae3_ae_dev *ae_dev);
+pci_ers_result_t hclge_handle_hw_ras_error(struct hnae3_ae_dev *ae_dev);
 #endif
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 431d92a..354ac5f 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -7935,7 +7935,7 @@ static const struct hnae3_ae_ops hclge_ops = {
.restore_fd_rules = hclge_restore_fd_entries,
.enable_fd = hclge_enable_fd,
.dbg_run_cmd = hclge_dbg_run_cmd,
-   .process_hw_error = hclge_process_ras_hw_error,
+   .handle_hw_ras_error = hclge_handle_hw_ras_error,
.get_hw_reset_stat = hclge_get_hw_reset_stat,
.ae_dev_resetting = hclge_ae_dev_resetting,
.ae_dev_reset_cnt = hclge_ae_dev_reset_cnt,
-- 
2.7.4




[PATCH net-next 08/14] net: hns3: deleted logging 1 bit errors

2018-12-07 Thread Salil Mehta
From: Shiju Jose 

This patch deletes logging 1 bit errors for the following reasons.
1. AER does not notify 1 bit errors to the device drivers.
   However AER reports 1 bit errors to the userspace through the
   trace_aer_event for logging in the rasdaemon.
2. Firmware clears the status of 1 bit errors in the hw registers.

Signed-off-by: Shiju Jose 
Signed-off-by: Salil Mehta 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c | 37 --
 1 file changed, 37 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
index 22e7c5b..7371ae4 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
@@ -4,42 +4,26 @@
 #include "hclge_err.h"
 
 static const struct hclge_hw_error hclge_imp_tcm_ecc_int[] = {
-   { .int_msk = BIT(0), .msg = "imp_itcm0_ecc_1bit_err" },
{ .int_msk = BIT(1), .msg = "imp_itcm0_ecc_mbit_err" },
-   { .int_msk = BIT(2), .msg = "imp_itcm1_ecc_1bit_err" },
{ .int_msk = BIT(3), .msg = "imp_itcm1_ecc_mbit_err" },
-   { .int_msk = BIT(4), .msg = "imp_itcm2_ecc_1bit_err" },
{ .int_msk = BIT(5), .msg = "imp_itcm2_ecc_mbit_err" },
-   { .int_msk = BIT(6), .msg = "imp_itcm3_ecc_1bit_err" },
{ .int_msk = BIT(7), .msg = "imp_itcm3_ecc_mbit_err" },
-   { .int_msk = BIT(8), .msg = "imp_dtcm0_mem0_ecc_1bit_err" },
{ .int_msk = BIT(9), .msg = "imp_dtcm0_mem0_ecc_mbit_err" },
-   { .int_msk = BIT(10), .msg = "imp_dtcm0_mem1_ecc_1bit_err" },
{ .int_msk = BIT(11), .msg = "imp_dtcm0_mem1_ecc_mbit_err" },
-   { .int_msk = BIT(12), .msg = "imp_dtcm1_mem0_ecc_1bit_err" },
{ .int_msk = BIT(13), .msg = "imp_dtcm1_mem0_ecc_mbit_err" },
-   { .int_msk = BIT(14), .msg = "imp_dtcm1_mem1_ecc_1bit_err" },
{ .int_msk = BIT(15), .msg = "imp_dtcm1_mem1_ecc_mbit_err" },
{ .int_msk = BIT(17), .msg = "imp_itcm4_ecc_mbit_err" },
{ /* sentinel */ }
 };
 
 static const struct hclge_hw_error hclge_cmdq_nic_mem_ecc_int[] = {
-   { .int_msk = BIT(0), .msg = "cmdq_nic_rx_depth_ecc_1bit_err" },
{ .int_msk = BIT(1), .msg = "cmdq_nic_rx_depth_ecc_mbit_err" },
-   { .int_msk = BIT(2), .msg = "cmdq_nic_tx_depth_ecc_1bit_err" },
{ .int_msk = BIT(3), .msg = "cmdq_nic_tx_depth_ecc_mbit_err" },
-   { .int_msk = BIT(4), .msg = "cmdq_nic_rx_tail_ecc_1bit_err" },
{ .int_msk = BIT(5), .msg = "cmdq_nic_rx_tail_ecc_mbit_err" },
-   { .int_msk = BIT(6), .msg = "cmdq_nic_tx_tail_ecc_1bit_err" },
{ .int_msk = BIT(7), .msg = "cmdq_nic_tx_tail_ecc_mbit_err" },
-   { .int_msk = BIT(8), .msg = "cmdq_nic_rx_head_ecc_1bit_err" },
{ .int_msk = BIT(9), .msg = "cmdq_nic_rx_head_ecc_mbit_err" },
-   { .int_msk = BIT(10), .msg = "cmdq_nic_tx_head_ecc_1bit_err" },
{ .int_msk = BIT(11), .msg = "cmdq_nic_tx_head_ecc_mbit_err" },
-   { .int_msk = BIT(12), .msg = "cmdq_nic_rx_addr_ecc_1bit_err" },
{ .int_msk = BIT(13), .msg = "cmdq_nic_rx_addr_ecc_mbit_err" },
-   { .int_msk = BIT(14), .msg = "cmdq_nic_tx_addr_ecc_1bit_err" },
{ .int_msk = BIT(15), .msg = "cmdq_nic_tx_addr_ecc_mbit_err" },
{ .int_msk = BIT(17), .msg = "cmdq_rocee_rx_depth_ecc_mbit_err" },
{ .int_msk = BIT(19), .msg = "cmdq_rocee_tx_depth_ecc_mbit_err" },
@@ -53,12 +37,6 @@ static const struct hclge_hw_error 
hclge_cmdq_nic_mem_ecc_int[] = {
 };
 
 static const struct hclge_hw_error hclge_tqp_int_ecc_int[] = {
-   { .int_msk = BIT(0), .msg = "tqp_int_cfg_even_ecc_1bit_err" },
-   { .int_msk = BIT(1), .msg = "tqp_int_cfg_odd_ecc_1bit_err" },
-   { .int_msk = BIT(2), .msg = "tqp_int_ctrl_even_ecc_1bit_err" },
-   { .int_msk = BIT(3), .msg = "tqp_int_ctrl_odd_ecc_1bit_err" },
-   { .int_msk = BIT(4), .msg = "tx_que_scan_int_ecc_1bit_err" },
-   { .int_msk = BIT(5), .msg = "rx_que_scan_int_ecc_1bit_err" },
{ .int_msk = BIT(6), .msg = "tqp_int_cfg_even_ecc_mbit_err" },
{ .int_msk = BIT(7), .msg = "tqp_int_cfg_odd_ecc_mbit_err" },
{ .int_msk = BIT(8), .msg = "tqp_int_ctrl_even_ecc_mbit_err" },
@@ -76,9 +54,7 @@ static const struct hclge_hw_error hclge_msix_sram_ecc_int[] 
= {
 
 static const struct hclge_hw_error hclge_igu_int[] = {
{ .int_msk = BIT(0), .msg = "igu_rx_buf0_ecc_mbit_err" },
-   { .int_msk = BIT(1), .msg = "igu_rx_buf0_ecc_1bit_err" },
{ .int_msk = BIT(2), .msg = &

[PATCH net-next 11/14] net: hns3: handle hw errors of PPP PF

2018-12-07 Thread Salil Mehta
From: Shiju Jose 

This patch handles PF hw errors of PPP(Programmable Packet Processor).

Signed-off-by: Shiju Jose 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
index 20f8bb5..e82ef4f 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
@@ -112,8 +112,8 @@ static const struct hclge_hw_error 
hclge_ppp_mpf_abnormal_int_st1[] = {
{ /* sentinel */ }
 };
 
-static const struct hclge_hw_error hclge_ppp_pf_int[] = {
-   { .int_msk = BIT(0), .msg = "Tx_vlan_tag_err" },
+static const struct hclge_hw_error hclge_ppp_pf_abnormal_int[] = {
+   { .int_msk = BIT(0), .msg = "tx_vlan_tag_err" },
{ .int_msk = BIT(1), .msg = "rss_list_tc_unassigned_queue_err" },
{ /* sentinel */ }
 };
@@ -385,12 +385,16 @@ static int hclge_config_ppp_error_interrupt(struct 
hclge_dev *hdev, u32 cmd,
cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT0_EN);
desc[0].data[1] =
cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT1_EN);
+   desc[0].data[4] = cpu_to_le32(HCLGE_PPP_PF_ERR_INT_EN);
}
 
desc[1].data[0] =
cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT0_EN_MASK);
desc[1].data[1] =
cpu_to_le32(HCLGE_PPP_MPF_ECC_ERR_INT1_EN_MASK);
+   if (hdev->pdev->revision >= 0x21)
+   desc[1].data[2] =
+   cpu_to_le32(HCLGE_PPP_PF_ERR_INT_EN_MASK);
} else if (cmd == HCLGE_PPP_CMD1_INT_CMD) {
if (en) {
desc[0].data[0] =
@@ -850,6 +854,13 @@ int hclge_handle_hw_msix_error(struct hclge_dev *hdev,
goto msi_error;
}
 
+   /* read and log PPP PF errors */
+   desc_data = (__le32 *)&desc[2];
+   status = le32_to_cpu(*desc_data);
+   if (status)
+   hclge_log_error(dev, "PPP_PF_ABNORMAL_INT_ST0",
+   &hclge_ppp_pf_abnormal_int[0], status);
+
/* clear all PF MSIx errors */
hclge_cmd_reuse_desc(&desc[0], false);
desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
-- 
2.7.4




[PATCH net-next 13/14] net: hns3: handle hw errors of SSU

2018-12-07 Thread Salil Mehta
From: Shiju Jose 

This patch enables and handles hw errors of the Storage Switch Unit(SSU).

Signed-off-by: Shiju Jose 
Signed-off-by: Salil Mehta 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |   2 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c | 187 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h |  14 ++
 3 files changed, 203 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 0223e83..eb91519 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -217,6 +217,8 @@ enum hclge_opcode_type {
/* Error INT commands */
HCLGE_MAC_COMMON_INT_EN = 0x030E,
HCLGE_TM_SCH_ECC_INT_EN = 0x0829,
+   HCLGE_SSU_ECC_INT_CMD   = 0x0989,
+   HCLGE_SSU_COMMON_INT_CMD= 0x098C,
HCLGE_PPU_MPF_ECC_INT_CMD   = 0x0B40,
HCLGE_PPU_MPF_OTHER_INT_CMD = 0x0B41,
HCLGE_PPU_PF_OTHER_INT_CMD  = 0x0B42,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
index 00086ce..660320d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
@@ -263,6 +263,80 @@ static const struct hclge_hw_error 
hclge_ppu_pf_abnormal_int[] = {
{ /* sentinel */ }
 };
 
+static const struct hclge_hw_error hclge_ssu_com_err_int[] = {
+   { .int_msk = BIT(0), .msg = "buf_sum_err" },
+   { .int_msk = BIT(1), .msg = "ppp_mb_num_err" },
+   { .int_msk = BIT(2), .msg = "ppp_mbid_err" },
+   { .int_msk = BIT(3), .msg = "ppp_rlt_mac_err" },
+   { .int_msk = BIT(4), .msg = "ppp_rlt_host_err" },
+   { .int_msk = BIT(5), .msg = "cks_edit_position_err" },
+   { .int_msk = BIT(6), .msg = "cks_edit_condition_err" },
+   { .int_msk = BIT(7), .msg = "vlan_edit_condition_err" },
+   { .int_msk = BIT(8), .msg = "vlan_num_ot_err" },
+   { .int_msk = BIT(9), .msg = "vlan_num_in_err" },
+   { /* sentinel */ }
+};
+
+static const struct hclge_hw_error hclge_ssu_port_based_err_int[] = {
+   { .int_msk = BIT(0), .msg = "roc_pkt_without_key_port" },
+   { .int_msk = BIT(1), .msg = "tpu_pkt_without_key_port" },
+   { .int_msk = BIT(2), .msg = "igu_pkt_without_key_port" },
+   { .int_msk = BIT(3), .msg = "roc_eof_mis_match_port" },
+   { .int_msk = BIT(4), .msg = "tpu_eof_mis_match_port" },
+   { .int_msk = BIT(5), .msg = "igu_eof_mis_match_port" },
+   { .int_msk = BIT(6), .msg = "roc_sof_mis_match_port" },
+   { .int_msk = BIT(7), .msg = "tpu_sof_mis_match_port" },
+   { .int_msk = BIT(8), .msg = "igu_sof_mis_match_port" },
+   { .int_msk = BIT(11), .msg = "ets_rd_int_rx_port" },
+   { .int_msk = BIT(12), .msg = "ets_wr_int_rx_port" },
+   { .int_msk = BIT(13), .msg = "ets_rd_int_tx_port" },
+   { .int_msk = BIT(14), .msg = "ets_wr_int_tx_port" },
+   { /* sentinel */ }
+};
+
+static const struct hclge_hw_error hclge_ssu_fifo_overflow_int[] = {
+   { .int_msk = BIT(0), .msg = "ig_mac_inf_int" },
+   { .int_msk = BIT(1), .msg = "ig_host_inf_int" },
+   { .int_msk = BIT(2), .msg = "ig_roc_buf_int" },
+   { .int_msk = BIT(3), .msg = "ig_host_data_fifo_int" },
+   { .int_msk = BIT(4), .msg = "ig_host_key_fifo_int" },
+   { .int_msk = BIT(5), .msg = "tx_qcn_fifo_int" },
+   { .int_msk = BIT(6), .msg = "rx_qcn_fifo_int" },
+   { .int_msk = BIT(7), .msg = "tx_pf_rd_fifo_int" },
+   { .int_msk = BIT(8), .msg = "rx_pf_rd_fifo_int" },
+   { .int_msk = BIT(9), .msg = "qm_eof_fifo_int" },
+   { .int_msk = BIT(10), .msg = "mb_rlt_fifo_int" },
+   { .int_msk = BIT(11), .msg = "dup_uncopy_fifo_int" },
+   { .int_msk = BIT(12), .msg = "dup_cnt_rd_fifo_int" },
+   { .int_msk = BIT(13), .msg = "dup_cnt_drop_fifo_int" },
+   { .int_msk = BIT(14), .msg = "dup_cnt_wrb_fifo_int" },
+   { .int_msk = BIT(15), .msg = "host_cmd_fifo_int" },
+   { .int_msk = BIT(16), .msg = "mac_cmd_fifo_int" },
+   { .int_msk = BIT(17), .msg = "host_cmd_bitmap_empty_int" },
+   { .int_msk = BIT(18), .msg = "mac_cmd_bitmap_empty_int" },
+   { .int_msk = BIT(19), .msg = "dup_bitmap_empty_int" },
+   { .int_msk = BIT(20), .msg = "out_queue_bitmap_empty_int" },
+   { .int_msk = BIT(21), .msg = "bank2_bitmap_empty_int" },
+   

[PATCH net-next 14/14] net: hns3: add handling of RDMA RAS errors

2018-12-07 Thread Salil Mehta
From: Shiju Jose 

This patch handles the RDMA RAS errors.
1. Enable RAS interrupt, print error detail info and clear error status.
2. Do CORE reset to recovery when these non-fatal errors happened.

Signed-off-by: Xiaofei Tan 
Signed-off-by: Shiju Jose 
Signed-off-by: Salil Mehta 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |   3 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c | 185 -
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_err.h |  12 ++
 3 files changed, 199 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 eb91519..b1ee6fe 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -229,6 +229,9 @@ enum hclge_opcode_type {
HCLGE_QUERY_MSIX_INT_STS_BD_NUM = 0x1513,
HCLGE_QUERY_CLEAR_ALL_MPF_MSIX_INT  = 0x1514,
HCLGE_QUERY_CLEAR_ALL_PF_MSIX_INT   = 0x1515,
+   HCLGE_CONFIG_ROCEE_RAS_INT_EN   = 0x1580,
+   HCLGE_QUERY_CLEAR_ROCEE_RAS_INT = 0x1581,
+   HCLGE_ROCEE_PF_RAS_INT_CMD  = 0x1584,
HCLGE_IGU_EGU_TNL_INT_EN= 0x1803,
HCLGE_IGU_COMMON_INT_EN = 0x1806,
HCLGE_TM_QCN_MEM_INT_CFG= 0x1A14,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
index 660320d..2b52a51 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_err.c
@@ -337,6 +337,30 @@ static const struct hclge_hw_error 
hclge_ssu_port_based_pf_int[] = {
{ /* sentinel */ }
 };
 
+static const struct hclge_hw_error hclge_rocee_qmm_ovf_err_int[] = {
+   { .int_msk = 0, .msg = "rocee qmm ovf: sgid invalid err" },
+   { .int_msk = 0x4, .msg = "rocee qmm ovf: sgid ovf err" },
+   { .int_msk = 0x8, .msg = "rocee qmm ovf: smac invalid err" },
+   { .int_msk = 0xC, .msg = "rocee qmm ovf: smac ovf err" },
+   { .int_msk = 0x10, .msg = "rocee qmm ovf: cqc invalid err" },
+   { .int_msk = 0x11, .msg = "rocee qmm ovf: cqc ovf err" },
+   { .int_msk = 0x12, .msg = "rocee qmm ovf: cqc hopnum err" },
+   { .int_msk = 0x13, .msg = "rocee qmm ovf: cqc ba0 err" },
+   { .int_msk = 0x14, .msg = "rocee qmm ovf: srqc invalid err" },
+   { .int_msk = 0x15, .msg = "rocee qmm ovf: srqc ovf err" },
+   { .int_msk = 0x16, .msg = "rocee qmm ovf: srqc hopnum err" },
+   { .int_msk = 0x17, .msg = "rocee qmm ovf: srqc ba0 err" },
+   { .int_msk = 0x18, .msg = "rocee qmm ovf: mpt invalid err" },
+   { .int_msk = 0x19, .msg = "rocee qmm ovf: mpt ovf err" },
+   { .int_msk = 0x1A, .msg = "rocee qmm ovf: mpt hopnum err" },
+   { .int_msk = 0x1B, .msg = "rocee qmm ovf: mpt ba0 err" },
+   { .int_msk = 0x1C, .msg = "rocee qmm ovf: qpc invalid err" },
+   { .int_msk = 0x1D, .msg = "rocee qmm ovf: qpc ovf err" },
+   { .int_msk = 0x1E, .msg = "rocee qmm ovf: qpc hopnum err" },
+   { .int_msk = 0x1F, .msg = "rocee qmm ovf: qpc ba0 err" },
+   { /* sentinel */ }
+};
+
 static void hclge_log_error(struct device *dev, char *reg,
const struct hclge_hw_error *err,
u32 err_sts)
@@ -1023,6 +1047,148 @@ static int hclge_handle_all_ras_errors(struct hclge_dev 
*hdev)
return ret;
 }
 
+static int hclge_log_rocee_ovf_error(struct hclge_dev *hdev)
+{
+   struct device *dev = &hdev->pdev->dev;
+   struct hclge_desc desc[2];
+   int ret;
+
+   /* read overflow error status */
+   ret = hclge_cmd_query_error(hdev, &desc[0],
+   HCLGE_ROCEE_PF_RAS_INT_CMD,
+   0, 0, 0);
+   if (ret) {
+   dev_err(dev, "failed(%d) to query ROCEE OVF error sts\n", ret);
+   return ret;
+   }
+
+   /* log overflow error */
+   if (le32_to_cpu(desc[0].data[0]) & HCLGE_ROCEE_OVF_ERR_INT_MASK) {
+   const struct hclge_hw_error *err;
+   u32 err_sts;
+
+   err = &hclge_rocee_qmm_ovf_err_int[0];
+   err_sts = HCLGE_ROCEE_OVF_ERR_TYPE_MASK &
+ le32_to_cpu(desc[0].data[0]);
+   while (err->msg) {
+   if (err->int_msk == err_sts) {
+   dev_warn(dev, "%s [error status=0x%x] found\n",
+err->msg,
+le32_to_cpu(desc[0].data[0]));
+   break;
+   }
+   err++;
+   

RE: [RFC net-next 3/9] net: hns3: Add "port vlan table" information query function

2018-12-04 Thread Salil Mehta
> From: Andrew Lunn [mailto:and...@lunn.ch]
> Sent: Tuesday, December 4, 2018 10:56 AM
> To: Salil Mehta 
> Cc: David Miller ; jakub.kicin...@netronome.com;
> Zhuangyuzeng (Yisen) ; lipeng (Y)
> ; mehta.sa...@opnsrc.net; netdev@vger.kernel.org;
> linux-ker...@vger.kernel.org; Linuxarm ;
> Liuzhongzhu ; j...@resnulli.us;
> f.faine...@gmail.com
> Subject: Re: [RFC net-next 3/9] net: hns3: Add "port vlan table"
> information query function
> 
> > > > Adding debugfs files for basic switch concepts like MAC and VLAN tables
> > > > seems like a bit of a stretch to me.  I wonder what others think.
> > >
> > > Agreed.
> >
> >
> > I was wondering how other vendors are solving this? One way I could
> > understand is to use "Switchdev" framework which in turn will expose
> > entries to the kernel using the switch driver. In our NIC we don't
> > have a proper switch and it cannot learn/age entries.
> 
> Your hardware is there to accelerate what linux can do in software.
> How do we manage the software version of this feature?

Yes, so it can kind of represent switch in the hardware, has vports and has
tables for mac-vlan, port-vlan, vlan (which I guess kernel also supports in
vlan aware mode of bridging?). Perhaps, only way I can understand now to be
able to use standard bridge, ip link tools to fetch this info is by having
represented them by "Switchdev"?

> 
> > Also, on-SoC NIC contains other tables which might not have any standard
> > user-space interface at all. What are your suggestions regarding that?
> 
> How are these tables map to software features the Linux stack
> implements?

If you refer output shown in patch you will get an idea, 
[RFC net-next 5/9] net: hns3: Add "manager table" information query function

Manager Table stores entries for any exception packet matching or for matching
any special types like control packets which we might not want to forward
using general forwarding route using mac-vlan table.

Not sure if this makes sense inside Linux kernel? Therefore, we thought of
exposing them through the debugfs.


Thanks
Salil


RE: [RFC net-next 3/9] net: hns3: Add "port vlan table" information query function

2018-12-04 Thread Salil Mehta
> From: David Miller [mailto:da...@davemloft.net]
> Sent: Monday, December 3, 2018 11:13 PM
> To: jakub.kicin...@netronome.com
> Cc: Salil Mehta ; Zhuangyuzeng (Yisen)
> ; lipeng (Y) ;
> mehta.sa...@opnsrc.net; netdev@vger.kernel.org; linux-
> ker...@vger.kernel.org; Linuxarm ; Liuzhongzhu
> ; j...@resnulli.us; f.faine...@gmail.com
> Subject: Re: [RFC net-next 3/9] net: hns3: Add "port vlan table"
> information query function
> 
> From: Jakub Kicinski 
> Date: Mon, 3 Dec 2018 15:12:22 -0800
> 
> > On Sun, 2 Dec 2018 23:09:27 +, Salil Mehta wrote:
> >> From: liuzhongzhu 
> >>
> >> This patch prints port vlan table information.
> >>
> >> debugfs command:
> >> echo dump port vlan tbl > cmd
> >>
> >> Sample Command:
> >> root@(none)# echo dump port vlan tbl > cmd
> >>  vlan | port filter bitMap:
> >>   | :::::0001
> >> root@(none)#
> >>
> >> Signed-off-by: liuzhongzhu 
> >> Signed-off-by: Salil Mehta 
> >
> > Adding debugfs files for basic switch concepts like MAC and VLAN tables
> > seems like a bit of a stretch to me.  I wonder what others think.
> 
> Agreed.


I was wondering how other vendors are solving this? One way I could 
understand is to use "Switchdev" framework which in turn will expose
entries to the kernel using the switch driver. In our NIC we don't
have a proper switch and it cannot learn/age entries.

Also, on-SoC NIC contains other tables which might not have any standard
user-space interface at all. What are your suggestions regarding that?


Thanks
Salil


[RFC net-next 1/9] net: hns3: Add "bd info" query function

2018-12-02 Thread Salil Mehta
From: liuzhongzhu 

This patch prints Sending and receiving
packet descriptor information.

debugfs command:
echo dump bd info 1 > cmd

Sample Command:
root@(none)# echo bd info 1 > cmd
hns3 :7d:00.0: TX Queue Num: 0, BD Index: 0
hns3 :7d:00.0: (TX) addr: 0x0
hns3 :7d:00.0: (TX)vlan_tag: 0
hns3 :7d:00.0: (TX)send_size: 0
hns3 :7d:00.0: (TX)vlan_tso: 0
hns3 :7d:00.0: (TX)l2_len: 0
hns3 :7d:00.0: (TX)l3_len: 0
hns3 :7d:00.0: (TX)l4_len: 0
hns3 :7d:00.0: (TX)vlan_tag: 0
hns3 :7d:00.0: (TX)tv: 0
hns3 :7d:00.0: (TX)vlan_msec: 0
hns3 :7d:00.0: (TX)ol2_len: 0
hns3 :7d:00.0: (TX)ol3_len: 0
hns3 :7d:00.0: (TX)ol4_len: 0
hns3 :7d:00.0: (TX)paylen: 0
hns3 :7d:00.0: (TX)vld_ra_ri: 0
hns3 :7d:00.0: (TX)mss: 0
hns3 :7d:00.0: RX Queue Num: 0, BD Index: 120
hns3 :7d:00.0: (RX)addr: 0xffee7000
hns3 :7d:00.0: (RX)pkt_len: 0
hns3 :7d:00.0: (RX)size: 0
hns3 :7d:00.0: (RX)rss_hash: 0
hns3 :7d:00.0: (RX)fd_id: 0
hns3 :7d:00.0: (RX)vlan_tag: 0
hns3 :7d:00.0: (RX)o_dm_vlan_id_fb: 0
hns3 :7d:00.0: (RX)ot_vlan_tag: 0
hns3 :7d:00.0: (RX)bd_base_info: 0

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c | 79 +-
 1 file changed, 78 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 86d667a3730a..9a026556df0e 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -52,7 +52,7 @@ static int hns3_dbg_queue_info(struct hnae3_handle *h, char 
*cmd_buf)
test_bit(HNS3_NIC_STATE_RESETTING, &priv->state))
return -EPERM;
 
-   ring = ring_data[i + h->kinfo.num_tqps].ring;
+   ring = ring_data[(u32)(i + h->kinfo.num_tqps)].ring;
base_add_h = readl_relaxed(ring->tqp->io_base +
   HNS3_RING_RX_RING_BASEADDR_H_REG);
base_add_l = readl_relaxed(ring->tqp->io_base +
@@ -125,10 +125,85 @@ static int hns3_dbg_queue_info(struct hnae3_handle *h, 
char *cmd_buf)
return 0;
 }
 
+static int hns3_dbg_bd_info(struct hnae3_handle *h, char *cmd_buf)
+{
+   struct hns3_nic_priv *priv = h->priv;
+   struct hns3_nic_ring_data *ring_data;
+   struct hns3_desc *rx_desc, *tx_desc;
+   struct device *dev = &h->pdev->dev;
+   struct hns3_enet_ring *ring;
+   u32 tx_index, rx_index;
+   u32 q_num, value;
+   int cnt;
+
+   cnt = sscanf(&cmd_buf[8], "%u %u", &q_num, &tx_index);
+   if (cnt == 2) {
+   rx_index = tx_index;
+   } else if (cnt != 1) {
+   dev_err(dev, "bd info: bad command string, cnt=%d\n", cnt);
+   return -EINVAL;
+   }
+
+   if (q_num >= h->kinfo.num_tqps) {
+   dev_err(dev, "Queue number(%u) is out of range(%u)\n", q_num,
+   h->kinfo.num_tqps - 1);
+   return -EINVAL;
+   }
+
+   ring_data = priv->ring_data;
+   ring  = ring_data[q_num].ring;
+   value = readl_relaxed(ring->tqp->io_base + HNS3_RING_TX_RING_TAIL_REG);
+   tx_index = (cnt == 1) ? value : tx_index;
+
+   if (tx_index >= ring->desc_num) {
+   dev_err(dev, "bd index (%u) is out of range(%u)\n", tx_index,
+   ring->desc_num - 1);
+   return -EINVAL;
+   }
+
+   tx_desc = &ring->desc[tx_index];
+   dev_info(dev, "TX Queue Num: %u, BD Index: %u\n", q_num, tx_index);
+   dev_info(dev, "(TX) addr: 0x%llx\n", tx_desc->addr);
+   dev_info(dev, "(TX)vlan_tag: %u\n", tx_desc->tx.vlan_tag);
+   dev_info(dev, "(TX)send_size: %u\n", tx_desc->tx.send_size);
+   dev_info(dev, "(TX)vlan_tso: %u\n", tx_desc->tx.type_cs_vlan_tso);
+   dev_info(dev, "(TX)l2_len: %u\n", tx_desc->tx.l2_len);
+   dev_info(dev, "(TX)l3_len: %u\n", tx_desc->tx.l3_len);
+   dev_info(dev, "(TX)l4_len: %u\n", tx_desc->tx.l4_len);
+   dev_info(dev, "(TX)vlan_tag: %u\n", tx_desc->tx.outer_vlan_tag);
+   dev_info(dev, "(TX)tv: %u\n", tx_desc->tx.tv);
+   dev_info(dev, "(TX)vlan_msec: %u\n", tx_desc->tx.ol_type_vlan_msec);
+   dev_info(dev, "(TX)ol2_len: %u\n", tx_desc->tx.ol2_len);
+   dev_info(dev, "(TX)ol3_len: %u\n", tx_desc->tx.ol3_len);
+   dev_info(dev, "(TX)ol4_len: %u\n", tx_desc->tx.ol4_len);
+   dev_info(dev, "(TX)paylen: %u\n", tx_desc->tx.paylen);
+   dev_info(dev, "(TX)vld_ra_ri: %u\n", tx_desc->tx.bdtp_fe_sc_vld_ra_ri);
+ 

[RFC net-next 2/9] net: hns3: Add "mac table" information query function

2018-12-02 Thread Salil Mehta
From: liuzhongzhu 

This patch prints mac table information.

debugfs command:
echo dump mac tbl > cmd

Sample Command:
root@(none)# echo dump mac tbl > cmd
 Unicast tab:
 |index |mac_addr  |vlan_id |VMDq1 |U_M |mac_en |in_port
 |0088  |22:22:22:22:22:00 ||0 |0   |0  |2
 |0556  |33:33:00:00:00:01 ||1 |1   |1  |0
 |2812  |33:33:ff:82:68:17 ||1 |1   |1  |0
 |2844  |01:00:5e:00:00:01 ||1 |1   |1  |0
 |3368  |c2:f1:c5:82:68:17 ||0 |0   |0  |0
 Multicast tab: entry number = 3
 |index |mac_addr  |UM_MC_RDATA
 |0556  |33:33:00:00:00:01 |:0001:::
 |2812  |33:33:ff:82:68:17 |:0001:::
 |2844  |01:00:5e:00:00:01 |:0001:::
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c |   1 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  18 +++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 125 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h |  16 +++
 4 files changed, 160 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 9a026556df0e..e59591b1258b 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -210,6 +210,7 @@ static void hns3_dbg_help(struct hnae3_handle *h)
dev_info(&h->pdev->dev, "dump qos pause cfg\n");
dev_info(&h->pdev->dev, "dump qos pri map\n");
dev_info(&h->pdev->dev, "dump qos buf cfg\n");
+   dev_info(&h->pdev->dev, "dump mac tbl\n");
 }
 
 static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index e1805b972628..d5d10a8cbb5d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -232,6 +232,7 @@ enum hclge_opcode_type {
HCLGE_TM_QCN_MEM_INT_INFO_CMD   = 0x1A17,
HCLGE_PPP_CMD0_INT_CMD  = 0x2100,
HCLGE_PPP_CMD1_INT_CMD  = 0x2101,
+   HCLGE_PPP_MAC_VLAN_IDX_RD   = 0x2104,
HCLGE_NCSI_INT_QUERY= 0x2400,
HCLGE_NCSI_INT_EN   = 0x2401,
HCLGE_NCSI_INT_CLR  = 0x2402,
@@ -725,6 +726,23 @@ struct hclge_rx_vlan_type_cfg_cmd {
u8 rsv[16];
 };
 
+#pragma pack(1)
+struct hclge_mac_vlan_idx_rd_cmd {
+   u8  rsv0;
+   u8  resp_code;
+   __le16  vlan_tag;
+   u8  mac_add[6];
+   __le16  port;
+   u8  entry_type;
+   u8  mc_mac_en;
+   __le16  egress_port;
+   __le16  egress_queue;
+   __le16  vsi;
+   __le32  index;
+};
+
+#pragma pack()
+
 struct hclge_cfg_com_tqp_queue_cmd {
__le16 tqp_id;
__le16 stream_id;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
index 14577bbf3e11..19b76f5e93d7 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
@@ -407,6 +407,129 @@ static void hclge_dbg_dump_qos_buf_cfg(struct hclge_dev 
*hdev)
"dump qos buf cfg fail(0x%x), status is %d\n", cmd, ret);
 }
 
+static void hclge_dbg_dump_mac_table(struct hclge_dev *hdev)
+{
+   struct hclge_mac_vlan_idx_rd_cmd *mac_rd_cmd;
+   struct hclge_mac_vlan_idx_rd_mc *mc_mac_tbl;
+   char printf_buf[HCLGE_DBG_BUF_LEN];
+   struct hclge_desc desc[3];
+   u32 mc_tbl_idx, i;
+   int ret, len;
+   int j;
+
+   len = sizeof(struct hclge_mac_vlan_idx_rd_mc) * HCLGE_DBG_MAC_TBL_MAX;
+   mc_mac_tbl = kzalloc(len, GFP_KERNEL);
+   if (!mc_mac_tbl) {
+   dev_err(&hdev->pdev->dev, "mc_mac_tbl alloc memory failed\n");
+   return;
+   }
+
+   memset(printf_buf, 0, HCLGE_DBG_BUF_LEN);
+   dev_info(&hdev->pdev->dev, "Unicast tab:\n");
+   strncat(printf_buf, "|index |mac_addr  |vlan_id |VMDq1 |",
+   HCLGE_DBG_BUF_LEN);
+   strncat(printf_buf, "U_M |mac_en |in_port |E_type |E_Port\n",
+   HCLGE_DBG_BUF_LEN - strlen(printf_buf));
+
+   dev_info(&hdev->pdev->dev, "%s", printf_buf);
+
+   mc_tbl_idx = 0;
+   for (i = 0; i < HCLGE_DBG_MAC_TBL_MAX; i++) {
+   /* Prevent long-term occupation of the command channel. */
+   if ((i % 100) == 0)
+   msleep(100);
+
+   hclge_cmd_setup_basic_desc(&desc[0], HCLGE_PPP_

[RFC net-next 4/9] net: hns3: Add "vf vlan table" information query function

2018-12-02 Thread Salil Mehta
From: liuzhongzhu 

This patch prints vf vlan table information.

debugfs command:
echo dump port vlan tbl 0 > cmd

Sample Command:
root@(none)# echo dump vf vlan tbl 0 > cmd
vlan | vf filter bitMap:
 | :::::::0001
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c |  1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 93 ++
 2 files changed, 94 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 51af55f34e55..80a081e87b96 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -212,6 +212,7 @@ static void hns3_dbg_help(struct hnae3_handle *h)
dev_info(&h->pdev->dev, "dump qos buf cfg\n");
dev_info(&h->pdev->dev, "dump mac tbl\n");
dev_info(&h->pdev->dev, "dump port vlan tbl\n");
+   dev_info(&h->pdev->dev, "dump vf vlan tbl [vf id]\n");
 }
 
 static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
index 4a034a59fcb2..20e64abe7c5a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
@@ -608,6 +608,97 @@ static void hclge_dbg_dump_port_vlan_table(struct 
hclge_dev *hdev)
kfree(vlan_bitmap);
 }
 
+static void hclge_dbg_dump_vf_vlan_table(struct hclge_dev *hdev, char *cmd_buf)
+{
+   struct hclge_vlan_filter_vf_cfg_cmd *req0;
+   struct hclge_vlan_filter_vf_cfg_cmd *req1;
+   char printf_buf[HCLGE_DBG_BUF_LEN];
+   struct hclge_desc desc[2];
+   u32 *vlan_bitmap;
+   u8 vf_byte_val;
+   u8 vf_bitmap;
+   int vlan_len;
+   u32 vlan_id;
+   int ret, i;
+   bool flag;
+   u16 vf_id;
+
+   ret = kstrtou16(&cmd_buf[17], 10, &vf_id);
+   if (ret) {
+   dev_err(&hdev->pdev->dev,
+   "vf id failed. vf id max: %d\n", hdev->num_alloc_vfs);
+   return;
+   }
+
+   vlan_len = HCLGE_DBG_VLAN_ID_MAX / 8;
+   vlan_bitmap = kzalloc(vlan_len, GFP_KERNEL);
+   if (!vlan_bitmap) {
+   dev_err(&hdev->pdev->dev,
+   "port vlan table alloc memory failed\n");
+   return;
+   }
+
+   for (vlan_id = 0; vlan_id < HCLGE_DBG_VLAN_ID_MAX; vlan_id++) {
+   /* Prevent long-term occupation of the command channel. */
+   if ((vlan_id % 100) == 0)
+   msleep(100);
+
+   hclge_cmd_setup_basic_desc(&desc[0],
+  HCLGE_OPC_VLAN_FILTER_VF_CFG, true);
+   desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+   hclge_cmd_setup_basic_desc(&desc[1],
+  HCLGE_OPC_VLAN_FILTER_VF_CFG, true);
+
+   req0 = (struct hclge_vlan_filter_vf_cfg_cmd *)desc[0].data;
+   req1 = (struct hclge_vlan_filter_vf_cfg_cmd *)desc[1].data;
+   req0->vlan_id = cpu_to_le16(vlan_id);
+
+   ret = hclge_cmd_send(&hdev->hw, desc, 2);
+   if (ret) {
+   dev_err(&hdev->pdev->dev,
+   "call hclge_cmd_send fail, ret = %d\n", ret);
+   kfree(vlan_bitmap);
+   return;
+   }
+
+   if (vf_id < 128)
+   vf_bitmap = req0->vf_bitmap[vf_id / 8];
+   else
+   vf_bitmap = req1->vf_bitmap[(vf_id - 128) / 8];
+
+   vf_byte_val = 1 << (vf_id % 8);
+
+   if (vf_bitmap & vf_byte_val)
+   vlan_bitmap[(u32)(vlan_id / 32)] |= 1 << (vlan_id % 32);
+   }
+
+   dev_info(&hdev->pdev->dev, "vlan | vf filter bitMap:\n");
+
+   for (vlan_id = 0; vlan_id < HCLGE_DBG_VLAN_ID_MAX / 32; vlan_id += 8) {
+   memset(printf_buf, 0, HCLGE_DBG_BUF_LEN);
+   snprintf(printf_buf, HCLGE_DBG_BUF_LEN,
+"%04d | ", vlan_id * 32);
+
+   flag = false;
+
+   for (i = 7; i >= 0; i--) {
+   snprintf(printf_buf + strlen(printf_buf),
+HCLGE_DBG_BUF_LEN - strlen(printf_buf),
+"%08x:", vlan_bitmap[(u32)(vlan_id + i)]);
+
+   if (vlan_bitmap[(u32)(vlan_id + i)] > 0)
+   flag = true;
+   }
+
+   

[RFC net-next 6/9] net: hns3: Add "status register" information query function

2018-12-02 Thread Salil Mehta
From: liuzhongzhu 

This patch prints status register information by module.

debugfs command:
echo dump reg [mode name] > cmd

Sample Command:
root@(none)# echo dump reg bios common > cmd
 BP_CPU_STATE: 0x0
 DFX_MSIX_INFO_NIC_0: 0xc000
 DFX_MSIX_INFO_NIC_1: 0xf
 DFX_MSIX_INFO_NIC_2: 0x2
 DFX_MSIX_INFO_NIC_3: 0x2
 DFX_MSIX_INFO_ROC_0: 0xc000
 DFX_MSIX_INFO_ROC_1: 0x0
 DFX_MSIX_INFO_ROC_2: 0x0
 DFX_MSIX_INFO_ROC_3: 0x0
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c |  15 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  14 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 194 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h | 662 +
 4 files changed, 885 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index eb52d623a3bb..4e9d306fc3ff 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -201,6 +201,10 @@ static int hns3_dbg_bd_info(struct hnae3_handle *h, char 
*cmd_buf)
 
 static void hns3_dbg_help(struct hnae3_handle *h)
 {
+#define HNS3_DBG_BUF_LEN 256
+
+   char printf_buf[HNS3_DBG_BUF_LEN];
+
dev_info(&h->pdev->dev, "available commands\n");
dev_info(&h->pdev->dev, "queue info [number]\n");
dev_info(&h->pdev->dev, "bd info [q_num] \n");
@@ -214,6 +218,17 @@ static void hns3_dbg_help(struct hnae3_handle *h)
dev_info(&h->pdev->dev, "dump port vlan tbl\n");
dev_info(&h->pdev->dev, "dump vf vlan tbl [vf id]\n");
dev_info(&h->pdev->dev, "dump mng tbl\n");
+
+   memset(printf_buf, 0, HNS3_DBG_BUF_LEN);
+   strncat(printf_buf, "dump reg [[bios common] [ssu ]",
+   HNS3_DBG_BUF_LEN);
+   strncat(printf_buf + strlen(printf_buf),
+   " [igu egu ] [rpu ]",
+   HNS3_DBG_BUF_LEN - strlen(printf_buf));
+   strncat(printf_buf + strlen(printf_buf),
+   " [rtc] [ppp] [rcb] [tqp ]]\n",
+   HNS3_DBG_BUF_LEN - strlen(printf_buf));
+   dev_info(&h->pdev->dev, "%s", printf_buf);
 }
 
 static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 354bea9e718d..df18b1708f39 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -86,6 +86,20 @@ enum hclge_opcode_type {
HCLGE_OPC_QUERY_REG_NUM = 0x0040,
HCLGE_OPC_QUERY_32_BIT_REG  = 0x0041,
HCLGE_OPC_QUERY_64_BIT_REG  = 0x0042,
+   HCLGE_OPC_DFX_BD_NUM= 0x0043,
+   HCLGE_OPC_DFX_BIOS_COMMON_REG   = 0x0044,
+   HCLGE_OPC_DFX_SSU_REG_0 = 0x0045,
+   HCLGE_OPC_DFX_SSU_REG_1 = 0x0046,
+   HCLGE_OPC_DFX_IGU_EGU_REG   = 0x0047,
+   HCLGE_OPC_DFX_RPU_REG_0 = 0x0048,
+   HCLGE_OPC_DFX_RPU_REG_1 = 0x0049,
+   HCLGE_OPC_DFX_NCSI_REG  = 0x004A,
+   HCLGE_OPC_DFX_RTC_REG   = 0x004B,
+   HCLGE_OPC_DFX_PPP_REG   = 0x004C,
+   HCLGE_OPC_DFX_RCB_REG   = 0x004D,
+   HCLGE_OPC_DFX_TQP_REG   = 0x004E,
+   HCLGE_OPC_DFX_SSU_REG_2 = 0x004F,
+   HCLGE_OPC_DFX_QUERY_CHIP_CAP= 0x0050,
 
/* MAC command */
HCLGE_OPC_CONFIG_MAC_MODE   = 0x0301,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
index a70f7a374722..716af6491f1d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
@@ -9,6 +9,198 @@
 #include "hclge_tm.h"
 #include "hnae3.h"
 
+static int hclge_dbg_get_dfx_bd_num(struct hclge_dev *hdev, int offset)
+{
+   struct hclge_desc desc[4];
+   int ret;
+
+   hclge_cmd_setup_basic_desc(&desc[0], HCLGE_OPC_DFX_BD_NUM, true);
+   desc[0].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+   hclge_cmd_setup_basic_desc(&desc[1], HCLGE_OPC_DFX_BD_NUM, true);
+   desc[1].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+   hclge_cmd_setup_basic_desc(&desc[2], HCLGE_OPC_DFX_BD_NUM, true);
+   desc[2].flag |= cpu_to_le16(HCLGE_CMD_FLAG_NEXT);
+   hclge_cmd_setup_basic_desc(&desc[3], HCLGE_OPC_DFX_BD_NUM, true);
+
+   ret = hclge_cmd_send(&hdev->hw, desc, 4);
+   if (ret != HCLGE_CMD_EXEC_SUCCESS) {
+   dev_err(&hdev->pdev->dev,
+   "get dfx bdnum fail, status is %d.\n", ret);
+   return ret

[RFC net-next 7/9] net: hns3: Add "dcb register" status information query function

2018-12-02 Thread Salil Mehta
From: liuzhongzhu 

This patch prints dcb register status  information by module.

debugfs command:
root@(none)# echo dump reg dcb > cmd
 roce_qset_mask: 0x0
 nic_qs_mask: 0x0
 qs_shaping_pass: 0x0
 qs_bp_sts: 0x0
 pri_mask: 0x0
 pri_cshaping_pass: 0x0
 pri_pshaping_pass: 0x0
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c |   7 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |   9 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 102 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h |  16 
 4 files changed, 134 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 4e9d306fc3ff..4fb2bff66614 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -229,6 +229,13 @@ static void hns3_dbg_help(struct hnae3_handle *h)
" [rtc] [ppp] [rcb] [tqp ]]\n",
HNS3_DBG_BUF_LEN - strlen(printf_buf));
dev_info(&h->pdev->dev, "%s", printf_buf);
+
+   memset(printf_buf, 0, HNS3_DBG_BUF_LEN);
+   strncat(printf_buf, "dump reg dcb [port_id] [pri_id] [pg_id]",
+   HNS3_DBG_BUF_LEN);
+   strncat(printf_buf + strlen(printf_buf), " [rq_id] [nq_id] [qset_id]\n",
+   HNS3_DBG_BUF_LEN - strlen(printf_buf));
+   dev_info(&h->pdev->dev, "%s", printf_buf);
 }
 
 static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index df18b1708f39..a425b6d68f55 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -140,6 +140,15 @@ enum hclge_opcode_type {
HCLGE_OPC_TM_QS_SCH_MODE_CFG= 0x0814,
HCLGE_OPC_TM_BP_TO_QSET_MAPPING = 0x0815,
HCLGE_OPC_ETS_TC_WEIGHT = 0x0843,
+   HCLGE_OPC_QSET_DFX_STS  = 0x0844,
+   HCLGE_OPC_PRI_DFX_STS   = 0x0845,
+   HCLGE_OPC_PG_DFX_STS= 0x0846,
+   HCLGE_OPC_PORT_DFX_STS  = 0x0847,
+   HCLGE_OPC_SCH_NQ_CNT= 0x0848,
+   HCLGE_OPC_SCH_RQ_CNT= 0x0849,
+   HCLGE_OPC_TM_INTERNAL_STS   = 0x0850,
+   HCLGE_OPC_TM_INTERNAL_CNT   = 0x0851,
+   HCLGE_OPC_TM_INTERNAL_STS_1 = 0x0852,
 
/* Packet buffer allocate commands */
HCLGE_OPC_TX_BUFF_ALLOC = 0x0901,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
index 716af6491f1d..76a7ab6ea24d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
@@ -107,6 +107,106 @@ static void hclge_dbg_dump_reg_common(struct hclge_dev 
*hdev,
kfree(desc_src);
 }
 
+static void hclge_dbg_dump_dcb(struct hclge_dev *hdev, char *cmd_buf)
+{
+   struct device *dev = &hdev->pdev->dev;
+   struct hclge_dbg_bitmap_cmd *bitmap;
+   int rq_id, pri_id, qset_id;
+   int port_id, nq_id, pg_id;
+   struct hclge_desc desc[2];
+
+   int cnt, ret;
+
+   cnt = sscanf(cmd_buf, "%i %i %i %i %i %i",
+&port_id, &pri_id, &pg_id, &rq_id, &nq_id, &qset_id);
+   if (cnt != 6) {
+   dev_err(&hdev->pdev->dev,
+   "dump dcb: bad command parameter, cnt=%d\n", cnt);
+   return;
+   }
+
+   ret = hclge_dbg_cmd_send(hdev, desc, qset_id, 1,
+HCLGE_OPC_QSET_DFX_STS);
+   if (ret)
+   return;
+
+   bitmap = (struct hclge_dbg_bitmap_cmd *)&desc[0].data[1];
+   dev_info(dev, "roce_qset_mask: 0x%x\n", bitmap->bit0);
+   dev_info(dev, "nic_qs_mask: 0x%x\n", bitmap->bit1);
+   dev_info(dev, "qs_shaping_pass: 0x%x\n", bitmap->bit2);
+   dev_info(dev, "qs_bp_sts: 0x%x\n", bitmap->bit3);
+
+   ret = hclge_dbg_cmd_send(hdev, desc, pri_id, 1, HCLGE_OPC_PRI_DFX_STS);
+   if (ret)
+   return;
+
+   bitmap = (struct hclge_dbg_bitmap_cmd *)&desc[0].data[1];
+   dev_info(dev, "pri_mask: 0x%x\n", bitmap->bit0);
+   dev_info(dev, "pri_cshaping_pass: 0x%x\n", bitmap->bit1);
+   dev_info(dev, "pri_pshaping_pass: 0x%x\n", bitmap->bit2);
+
+   ret = hclge_dbg_cmd_send(hdev, desc, pg_id, 1, HCLGE_OPC_PG_DFX_STS);
+   if (ret)
+   return;
+
+   bitmap = (struct hclge_dbg_bitmap_cmd *)&desc[0].data[1];
+   dev_info(dev, "pg_mask: 0x%x\n", bitmap->bit0);
+   d

[RFC net-next 5/9] net: hns3: Add "manager table" information query function

2018-12-02 Thread Salil Mehta
From: liuzhongzhu 

This patch prints manager table information.

debugfs command:
echo dump mng tbl > cmd

Sample Command:
root@(none)# echo dump mng tbl > cmd
 entry|mac_addr |mask|ether|mask|vlan|mask|i_map|i_dir|e_type
 00   |01:00:5e:00:00:01|0   |0|0   ||0   |00   |00   |0
 01   |c2:f1:c5:82:68:17|0   |0|0   ||0   |00   |00   |0
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c |  1 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h | 16 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 66 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h |  9 +++
 4 files changed, 92 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 80a081e87b96..eb52d623a3bb 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -213,6 +213,7 @@ static void hns3_dbg_help(struct hnae3_handle *h)
dev_info(&h->pdev->dev, "dump mac tbl\n");
dev_info(&h->pdev->dev, "dump port vlan tbl\n");
dev_info(&h->pdev->dev, "dump vf vlan tbl [vf id]\n");
+   dev_info(&h->pdev->dev, "dump mng tbl\n");
 }
 
 static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index d5d10a8cbb5d..354bea9e718d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -233,6 +233,7 @@ enum hclge_opcode_type {
HCLGE_PPP_CMD0_INT_CMD  = 0x2100,
HCLGE_PPP_CMD1_INT_CMD  = 0x2101,
HCLGE_PPP_MAC_VLAN_IDX_RD   = 0x2104,
+   HCLGE_MAC_ETHERTYPE_IDX_RD  = 0x2105,
HCLGE_NCSI_INT_QUERY= 0x2400,
HCLGE_NCSI_INT_EN   = 0x2401,
HCLGE_NCSI_INT_CLR  = 0x2402,
@@ -741,6 +742,21 @@ struct hclge_mac_vlan_idx_rd_cmd {
__le32  index;
 };
 
+struct hclge_mac_ethertype_idx_rd_cmd {
+   u8  flags;
+   u8  resp_code;
+   __le16  vlan_tag;
+   u8  mac_add[6];
+   __le16  index;
+   __le16  ethter_type;
+   __le16  egress_port;
+   __le16  egress_queue;
+   __le16  rev0;
+   u8  i_port_bitmap;
+   u8  i_port_direction;
+   u8  rev1[2];
+};
+
 #pragma pack()
 
 struct hclge_cfg_com_tqp_queue_cmd {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
index 20e64abe7c5a..a70f7a374722 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
@@ -699,6 +699,70 @@ static void hclge_dbg_dump_vf_vlan_table(struct hclge_dev 
*hdev, char *cmd_buf)
kfree(vlan_bitmap);
 }
 
+static void hclge_dbg_dump_mng_table(struct hclge_dev *hdev)
+{
+   struct hclge_mac_ethertype_idx_rd_cmd *req0;
+   char printf_buf[HCLGE_DBG_BUF_LEN];
+   struct hclge_desc desc;
+   int ret, i;
+
+   dev_info(&hdev->pdev->dev, "mng tab:\n");
+   memset(printf_buf, 0, HCLGE_DBG_BUF_LEN);
+   strncat(printf_buf,
+   "entry|mac_addr |mask|ether|mask|vlan|mask",
+   HCLGE_DBG_BUF_LEN);
+   strncat(printf_buf + strlen(printf_buf),
+   "|i_map|i_dir|e_type|pf_id|vf_id|q_id|drop\n",
+   HCLGE_DBG_BUF_LEN - strlen(printf_buf));
+
+   dev_info(&hdev->pdev->dev, "%s", printf_buf);
+
+   for (i = 0; i < HCLGE_DBG_MNG_TBL_MAX; i++) {
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_MAC_ETHERTYPE_IDX_RD,
+  true);
+   req0 = (struct hclge_mac_ethertype_idx_rd_cmd *)&desc.data;
+   req0->index = cpu_to_le16(i);
+
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret) {
+   dev_err(&hdev->pdev->dev,
+   "call hclge_cmd_send fail, ret = %d\n", ret);
+   return;
+   }
+
+   if (!req0->resp_code)
+   continue;
+
+   memset(printf_buf, 0, HCLGE_DBG_BUF_LEN);
+   snprintf(printf_buf, HCLGE_DBG_BUF_LEN,
+"%02u   |%02x:%02x:%02x:%02x:%02x:%02x|",
+req0->index, req0->mac_add[0], req0->mac_add[1],
+req0->mac_add[2], req0->mac_add[3], req0->mac_add[4],
+req0->mac_add[5]);
+
+   snprintf(printf_buf + 

[RFC net-next 8/9] net: hns3: Add "queue map" information query function

2018-12-02 Thread Salil Mehta
From: liuzhongzhu 

This patch prints queue map information.

debugfs command:
echo dump queue map > cmd

Sample Command:
root@(none)# echo queue map > cmd
 local queue id | global queue id | vector id
  0  32 769
  1  33 770
  2  34 771
  3  35 772
  4  36 773
  5  37 774
  6  38 775
  7  39 776
  8  40 777
  9  41 778
 10  42 779
 11  43 780
 12  44 781
 13  45 782
 14  46 783
 15  47 784
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h|  1 +
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  1 +
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c | 33 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c|  4 +--
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  1 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c | 20 +
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  | 18 
 7 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h 
b/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h
index 4d9cf39da48c..691d12174902 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h
@@ -39,6 +39,7 @@ enum HCLGE_MBX_OPCODE {
HCLGE_MBX_KEEP_ALIVE,   /* (VF -> PF) send keep alive cmd */
HCLGE_MBX_SET_ALIVE,/* (VF -> PF) set alive state */
HCLGE_MBX_SET_MTU,  /* (VF -> PF) set mtu */
+   HCLGE_MBX_GET_QID_IN_PF,/* (VF -> PF) get queue id in pf */
 };
 
 /* below are per-VF mac-vlan subcodes */
diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index a1707b77c47f..da965ee82393 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -459,6 +459,7 @@ struct hnae3_ae_ops {
bool (*ae_dev_resetting)(struct hnae3_handle *handle);
unsigned long (*ae_dev_reset_cnt)(struct hnae3_handle *handle);
int (*set_gro_en)(struct hnae3_handle *handle, int enable);
+   u16 (*get_global_queue_id)(struct hnae3_handle *handle, u16 queue_id);
 };
 
 struct hnae3_dcb_ops {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 4fb2bff66614..826f8c13218f 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -125,6 +125,36 @@ static int hns3_dbg_queue_info(struct hnae3_handle *h, 
char *cmd_buf)
return 0;
 }
 
+static int hns3_dbg_queue_map(struct hnae3_handle *h)
+{
+   struct hns3_nic_priv *priv = h->priv;
+   struct hns3_nic_ring_data *ring_data;
+   int i;
+
+   if (!h->ae_algo->ops->get_global_queue_id)
+   return -EOPNOTSUPP;
+
+   dev_info(&h->pdev->dev, "map info for queue id and vector id\n");
+   dev_info(&h->pdev->dev,
+"local queue id | global queue id | vector id\n");
+   for (i = 0; i < h->kinfo.num_tqps; i++) {
+   u16 global_qid;
+
+   global_qid = h->ae_algo->ops->get_global_queue_id(h, i);
+   ring_data = &priv->ring_data[i];
+   if (!ring_data || !ring_data->ring ||
+   !ring_data->ring->tqp_vector)
+   continue;
+
+   dev_info(&h->pdev->dev,
+"  %4d%4d%4d\n",
+i, global_qid,
+ring_data->ring->tqp_vector->vector_irq);
+   }
+
+   return 0;
+}
+
 static int hns3_dbg_bd_info(struct hnae3_handle *h, char *cmd_buf)
 {
struct hns3_nic_priv *priv = h->priv;
@@ -207,6 +237,7 @@ static void hns3_dbg_help(struct hnae3_handle *h)
 
dev_info(&h->pdev->dev, "available commands\n");
dev_info(&h->pdev->dev, "queue info [number]\n");
+   dev_info(&h->pdev->dev, "queue map\n");
dev_info(&h->pdev->dev, "bd info [q_num] \n");
dev_info(&h->pdev->dev, "dump fd tcam\n");
dev_info(&h->pdev->dev, "dump tc\n");
@@ -306,6 +337,8 @@ static ssize_t hns3_dbg_cmd_write(struct file *filp, const 

[RFC net-next 9/9] net: hns3: Add "tm map" status information query function

2018-12-02 Thread Salil Mehta
From: liuzhongzhu 

This patch prints dcb register status  information by module.

debugfs command:
root@(none)# echo dump tm map 100 > cmd
queue_id | qset_id | pri_id | tc_id
0100 | 0065| 08 | 00
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c |  1 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 84 ++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |  7 ++
 4 files changed, 93 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index 826f8c13218f..8311369d5f24 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -241,6 +241,7 @@ static void hns3_dbg_help(struct hnae3_handle *h)
dev_info(&h->pdev->dev, "bd info [q_num] \n");
dev_info(&h->pdev->dev, "dump fd tcam\n");
dev_info(&h->pdev->dev, "dump tc\n");
+   dev_info(&h->pdev->dev, "dump tm map [q_num]\n");
dev_info(&h->pdev->dev, "dump tm\n");
dev_info(&h->pdev->dev, "dump qos pause cfg\n");
dev_info(&h->pdev->dev, "dump qos pri map\n");
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index a425b6d68f55..275c5ec655ab 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -165,6 +165,7 @@ enum hclge_opcode_type {
HCLGE_OPC_CFG_TX_QUEUE  = 0x0B01,
HCLGE_OPC_QUERY_TX_POINTER  = 0x0B02,
HCLGE_OPC_QUERY_TX_STATUS   = 0x0B03,
+   HCLGE_OPC_TQP_TX_QUEUE_TC   = 0x0B04,
HCLGE_OPC_CFG_RX_QUEUE  = 0x0B11,
HCLGE_OPC_QUERY_RX_POINTER  = 0x0B12,
HCLGE_OPC_QUERY_RX_STATUS   = 0x0B13,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
index 76a7ab6ea24d..02a36b71d58f 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
@@ -537,6 +537,88 @@ static void hclge_dbg_dump_tm(struct hclge_dev *hdev)
cmd, ret);
 }
 
+static void hclge_dbg_dump_tm_map(struct hclge_dev *hdev, char *cmd_buf)
+{
+   struct hclge_bp_to_qs_map_cmd *bp_to_qs_map_cmd;
+   struct hclge_nq_to_qs_link_cmd *nq_to_qs_map;
+   struct hclge_qs_to_pri_link_cmd *map;
+   struct hclge_tqp_tx_queue_tc_cmd *tc;
+   enum hclge_opcode_type cmd;
+   struct hclge_desc desc;
+   int queue_id, group_id;
+   u32 qset_maping[32];
+   int tc_id, qset_id;
+   int pri_id, ret;
+   u32 i;
+
+   ret = kstrtouint(&cmd_buf[12], 10, &queue_id);
+   queue_id = (ret != 0) ? 0 : queue_id;
+
+   cmd = HCLGE_OPC_TM_NQ_TO_QS_LINK;
+   nq_to_qs_map = (struct hclge_nq_to_qs_link_cmd *)desc.data;
+   hclge_cmd_setup_basic_desc(&desc, cmd, true);
+   nq_to_qs_map->nq_id = cpu_to_le16(queue_id);
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret)
+   goto err_tm_map_cmd_send;
+   qset_id = nq_to_qs_map->qset_id & 0x3FF;
+
+   cmd = HCLGE_OPC_TM_QS_TO_PRI_LINK;
+   map = (struct hclge_qs_to_pri_link_cmd *)desc.data;
+   hclge_cmd_setup_basic_desc(&desc, cmd, true);
+   map->qs_id = cpu_to_le16(qset_id);
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret)
+   goto err_tm_map_cmd_send;
+   pri_id = map->priority;
+
+   cmd = HCLGE_OPC_TQP_TX_QUEUE_TC;
+   tc = (struct hclge_tqp_tx_queue_tc_cmd *)desc.data;
+   hclge_cmd_setup_basic_desc(&desc, cmd, true);
+   tc->queue_id = cpu_to_le16(queue_id);
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret)
+   goto err_tm_map_cmd_send;
+   tc_id = tc->tc_id & 0x7;
+
+   dev_info(&hdev->pdev->dev, "queue_id | qset_id | pri_id | tc_id\n");
+   dev_info(&hdev->pdev->dev, "%04d | %04d| %02d | %02d\n",
+queue_id, qset_id, pri_id, tc_id);
+
+   cmd = HCLGE_OPC_TM_BP_TO_QSET_MAPPING;
+   bp_to_qs_map_cmd = (struct hclge_bp_to_qs_map_cmd *)desc.data;
+   for (group_id = 0; group_id < 32; group_id++) {
+   hclge_cmd_setup_basic_desc(&desc, cmd, true);
+   bp_to_qs_map_cmd->tc_id = tc_id;
+   bp_to_qs_map_cmd->qs_group_id = group_id;
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret)
+   goto 

[RFC net-next 3/9] net: hns3: Add "port vlan table" information query function

2018-12-02 Thread Salil Mehta
From: liuzhongzhu 

This patch prints port vlan table information.

debugfs command:
echo dump port vlan tbl > cmd

Sample Command:
root@(none)# echo dump port vlan tbl > cmd
 vlan | port filter bitMap:
  | :::::0001
root@(none)#

Signed-off-by: liuzhongzhu 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c |  1 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 80 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h |  3 +
 3 files changed, 84 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
index e59591b1258b..51af55f34e55 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c
@@ -211,6 +211,7 @@ static void hns3_dbg_help(struct hnae3_handle *h)
dev_info(&h->pdev->dev, "dump qos pri map\n");
dev_info(&h->pdev->dev, "dump qos buf cfg\n");
dev_info(&h->pdev->dev, "dump mac tbl\n");
+   dev_info(&h->pdev->dev, "dump port vlan tbl\n");
 }
 
 static ssize_t hns3_dbg_cmd_read(struct file *filp, char __user *buffer,
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
index 19b76f5e93d7..4a034a59fcb2 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c
@@ -530,6 +530,84 @@ static void hclge_dbg_dump_mac_table(struct hclge_dev 
*hdev)
kfree(mc_mac_tbl);
 }
 
+static void hclge_dbg_dump_port_vlan_table(struct hclge_dev *hdev)
+{
+   struct hclge_vlan_filter_pf_cfg_cmd *req;
+   char printf_buf[HCLGE_DBG_BUF_LEN];
+   struct hclge_desc desc;
+   u32 *vlan_bitmap;
+   u8 vlan_byte_val;
+   u8 vlan_offset;
+   u8 vlan_byte;
+   int vlan_len;
+   u32 vlan_id;
+   int ret, i;
+   bool flag;
+
+   vlan_len = HCLGE_DBG_VLAN_ID_MAX / 8;
+   vlan_bitmap = kzalloc(vlan_len, GFP_KERNEL);
+   if (!vlan_bitmap) {
+   dev_err(&hdev->pdev->dev,
+   "port vlan table alloc memory failed\n");
+   return;
+   }
+
+   for (vlan_id = 0; vlan_id < HCLGE_DBG_VLAN_ID_MAX; vlan_id++) {
+   /* Prevent long-term occupation of the command channel. */
+   if ((vlan_id % 100) == 0)
+   msleep(100);
+
+   hclge_cmd_setup_basic_desc(&desc,
+  HCLGE_OPC_VLAN_FILTER_PF_CFG, true);
+
+   vlan_offset = vlan_id / 160;
+   vlan_byte = (vlan_id % 160) / 8;
+   vlan_byte_val = 1 << (vlan_id % 8);
+
+   req = (struct hclge_vlan_filter_pf_cfg_cmd *)desc.data;
+   req->vlan_offset = vlan_offset;
+   req->vlan_offset_bitmap[vlan_byte] = vlan_byte_val;
+
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret) {
+   dev_err(&hdev->pdev->dev,
+   "call hclge_cmd_send fail, ret = %d\n", ret);
+   kfree(vlan_bitmap);
+   return;
+   }
+
+   if (req->vlan_cfg != 0)
+   continue;
+
+   vlan_bitmap[(u32)(vlan_id / 32)] |= 1 << (vlan_id % 32);
+   }
+
+   dev_info(&hdev->pdev->dev, "vlan | port filter bitMap:\n");
+
+   for (vlan_id = 0; vlan_id < HCLGE_DBG_VLAN_ID_MAX / 32;
+vlan_id += 8) {
+   memset(printf_buf, 0, HCLGE_DBG_BUF_LEN);
+   snprintf(printf_buf, HCLGE_DBG_BUF_LEN,
+"%04d | ", vlan_id * 32);
+   flag = false;
+
+   for (i = 7; i >= 0; i--) {
+   snprintf(printf_buf + strlen(printf_buf),
+HCLGE_DBG_BUF_LEN - strlen(printf_buf),
+"%08x:", vlan_bitmap[(u32)(vlan_id + i)]);
+
+   if (vlan_bitmap[(u32)(vlan_id + i)] > 0)
+   flag = true;
+   }
+
+   printf_buf[strlen(printf_buf) - 1] = '\n';
+   if (flag)
+   dev_info(&hdev->pdev->dev, "%s", printf_buf);
+   }
+
+   kfree(vlan_bitmap);
+}
+
 static void hclge_dbg_fd_tcam_read(struct hclge_dev *hdev, u8 stage,
   bool sel_x, u32 loc)
 {
@@ -603,6 +681,8 @@ int hclge_dbg_run_cmd(struct hnae3_handle *handle, char 
*cmd_buf)
hclge_dbg_dump_qos_buf_cfg(hdev);
} else if (strncmp(cmd_buf, "dump mac tbl", 12) == 0

[RFC net-next 0/9] net: hns3: Add more commands to Debugfs in HNS3 driver

2018-12-02 Thread Salil Mehta
This patch-set adds few more debugfs commands to HNS3 Ethernet
Driver. Support has been added to query info related to below
items:
1. Packet buffer descriptor ("echo bd info [queue no] [bd index] > cmd")
2. Mac Forward table("echo dump mac tbl > cmd")
3. Port vlan Forward table("echo dump port vlan tbl > cmd")
4. Vf vlan Forward table("echo dump vf vlan tbl [vf id]> cmd")
5. Manager table("echo dump mng tbl > cmd")
6. Dfx status register("echo dump reg ssu [prt id] > cmd")
7. Dcb status register("echo dump reg dcb [port id] > cmd")
8. Queue map ("echo queue map [queue no] > cmd")
9. Tm map ("echo tm map [queue no] > cmd")

NOTE: Above commands are *read-only* and are only intended to
query the information from the SoC(and dump inside the kernel,
for now) and in no way tries to perform write operations for
the purpose of configuration etc.

As per the earlier community review, it was understood that any
attempt to add commands for which standard tools are present is
discouraged. Any review comments and suggestions related to above
set of commands would be of great help in preapring the final
patch-set. Thank you!


liuzhongzhu (9):
  net: hns3: Add "bd info" query function
  net: hns3: Add "mac table" information query function
  net: hns3: Add "port vlan table" information query function
  net: hns3: Add "vf vlan table" information query function
  net: hns3: Add "manager table" information query function
  net: hns3: Add "status register" information query function
  net: hns3: Add "dcb register" status information query function
  net: hns3: Add "queue map" information query function
  net: hns3: Add "tm map" status information query function

 drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h|   1 +
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|   1 +
 drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c | 139 +++-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  58 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c | 744 +
 .../ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.h | 706 +++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c|   4 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|   1 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c |  20 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |   7 +
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  |  18 +
 11 files changed, 1696 insertions(+), 3 deletions(-)

-- 
2.11.0




[PATCH net-next 1/2] net: hns3: Support "ethtool -d" for HNS3 VF driver

2018-11-29 Thread Salil Mehta
From: Jian Shen 

This patch adds "ethtool -d" support for HNS3 VF Driver.

Signed-off-by: Jian Shen 
Signed-off-by: Salil Mehta 
---
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  | 120 +
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h  |  54 ++
 2 files changed, 174 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index efec1b7..417e078 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -23,6 +23,58 @@ static const struct pci_device_id ae_algovf_pci_tbl[] = {
 
 MODULE_DEVICE_TABLE(pci, ae_algovf_pci_tbl);
 
+static const u32 cmdq_reg_addr_list[] = {HCLGEVF_CMDQ_TX_ADDR_L_REG,
+HCLGEVF_CMDQ_TX_ADDR_H_REG,
+HCLGEVF_CMDQ_TX_DEPTH_REG,
+HCLGEVF_CMDQ_TX_TAIL_REG,
+HCLGEVF_CMDQ_TX_HEAD_REG,
+HCLGEVF_CMDQ_RX_ADDR_L_REG,
+HCLGEVF_CMDQ_RX_ADDR_H_REG,
+HCLGEVF_CMDQ_RX_DEPTH_REG,
+HCLGEVF_CMDQ_RX_TAIL_REG,
+HCLGEVF_CMDQ_RX_HEAD_REG,
+HCLGEVF_VECTOR0_CMDQ_SRC_REG,
+HCLGEVF_CMDQ_INTR_STS_REG,
+HCLGEVF_CMDQ_INTR_EN_REG,
+HCLGEVF_CMDQ_INTR_GEN_REG};
+
+static const u32 common_reg_addr_list[] = {HCLGEVF_MISC_VECTOR_REG_BASE,
+  HCLGEVF_RST_ING,
+  HCLGEVF_GRO_EN_REG};
+
+static const u32 ring_reg_addr_list[] = {HCLGEVF_RING_RX_ADDR_L_REG,
+HCLGEVF_RING_RX_ADDR_H_REG,
+HCLGEVF_RING_RX_BD_NUM_REG,
+HCLGEVF_RING_RX_BD_LENGTH_REG,
+HCLGEVF_RING_RX_MERGE_EN_REG,
+HCLGEVF_RING_RX_TAIL_REG,
+HCLGEVF_RING_RX_HEAD_REG,
+HCLGEVF_RING_RX_FBD_NUM_REG,
+HCLGEVF_RING_RX_OFFSET_REG,
+HCLGEVF_RING_RX_FBD_OFFSET_REG,
+HCLGEVF_RING_RX_STASH_REG,
+HCLGEVF_RING_RX_BD_ERR_REG,
+HCLGEVF_RING_TX_ADDR_L_REG,
+HCLGEVF_RING_TX_ADDR_H_REG,
+HCLGEVF_RING_TX_BD_NUM_REG,
+HCLGEVF_RING_TX_PRIORITY_REG,
+HCLGEVF_RING_TX_TC_REG,
+HCLGEVF_RING_TX_MERGE_EN_REG,
+HCLGEVF_RING_TX_TAIL_REG,
+HCLGEVF_RING_TX_HEAD_REG,
+HCLGEVF_RING_TX_FBD_NUM_REG,
+HCLGEVF_RING_TX_OFFSET_REG,
+HCLGEVF_RING_TX_EBD_NUM_REG,
+HCLGEVF_RING_TX_EBD_OFFSET_REG,
+HCLGEVF_RING_TX_BD_ERR_REG,
+HCLGEVF_RING_EN_REG};
+
+static const u32 tqp_intr_reg_addr_list[] = {HCLGEVF_TQP_INTR_CTRL_REG,
+HCLGEVF_TQP_INTR_GL0_REG,
+HCLGEVF_TQP_INTR_GL1_REG,
+HCLGEVF_TQP_INTR_GL2_REG,
+HCLGEVF_TQP_INTR_RL_REG};
+
 static inline struct hclgevf_dev *hclgevf_ae_get_hdev(
struct hnae3_handle *handle)
 {
@@ -2473,6 +2525,72 @@ static unsigned long hclgevf_ae_dev_reset_cnt(struct 
hnae3_handle *handle)
return hdev->reset_count;
 }
 
+#define MAX_SEPARATE_NUM   4
+#define SEPARATOR_VALUE0x
+#define REG_NUM_PER_LINE   4
+#define REG_LEN_PER_LINE   (REG_NUM_PER_LINE * sizeof(u32))
+
+static int hclgevf_get_regs_len(struct hnae3_handle *handle)
+{
+   int cmdq_lines, common_lines, ring_lines, tqp_intr_lines;
+   struct hclgevf_dev *hdev = hclgevf_ae_get_hdev(handle);
+
+   cmdq_lines = sizeof(cmdq_reg_addr_list) / REG_LEN_PER_LINE + 1;
+   common_lines = sizeof(common_reg_addr_list) / REG_LEN_PER_LINE + 1;
+   ring_lines = sizeof(ring_reg_addr_list) / REG_LEN_PER_LINE + 1;
+   tqp_intr_lines = sizeof(tqp_intr_reg_addr_list) / REG_LEN_PER_LINE + 1;
+
+   retur

[PATCH net-next 0/2] Adds VF/PF PCIe reg dump(ethtool -d) support to HNS3 driver

2018-11-29 Thread Salil Mehta
This patchset adds VF/PF PCIe register dump support to HNS3 VF and PF driver
using "ethtool -d" command.

Jian Shen (2):
  net: hns3: Support "ethtool -d" for HNS3 VF driver
  net: hns3: Adds support to dump(using ethool-d) PCIe regs in HNS3 PF
driver

 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 120 -
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  56 ++
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  | 120 +
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h  |  54 ++
 4 files changed, 345 insertions(+), 5 deletions(-)

-- 
2.7.4




[PATCH net-next 2/2] net: hns3: Adds support to dump(using ethool-d) PCIe regs in HNS3 PF driver

2018-11-29 Thread Salil Mehta
From: Jian Shen 

This patch adds support to dump PF PCIe registers using ethtool -d
for HNS3 PF Driver.

Signed-off-by: Jian Shen 
Signed-off-by: Salil Mehta 
---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 120 -
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  56 ++
 2 files changed, 171 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 1c8cf84..8432c84 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -48,6 +48,62 @@ static const struct pci_device_id ae_algo_pci_tbl[] = {
 
 MODULE_DEVICE_TABLE(pci, ae_algo_pci_tbl);
 
+static const u32 cmdq_reg_addr_list[] = {HCLGE_CMDQ_TX_ADDR_L_REG,
+HCLGE_CMDQ_TX_ADDR_H_REG,
+HCLGE_CMDQ_TX_DEPTH_REG,
+HCLGE_CMDQ_TX_TAIL_REG,
+HCLGE_CMDQ_TX_HEAD_REG,
+HCLGE_CMDQ_RX_ADDR_L_REG,
+HCLGE_CMDQ_RX_ADDR_H_REG,
+HCLGE_CMDQ_RX_DEPTH_REG,
+HCLGE_CMDQ_RX_TAIL_REG,
+HCLGE_CMDQ_RX_HEAD_REG,
+HCLGE_VECTOR0_CMDQ_SRC_REG,
+HCLGE_CMDQ_INTR_STS_REG,
+HCLGE_CMDQ_INTR_EN_REG,
+HCLGE_CMDQ_INTR_GEN_REG};
+
+static const u32 common_reg_addr_list[] = {HCLGE_MISC_VECTOR_REG_BASE,
+  HCLGE_VECTOR0_OTER_EN_REG,
+  HCLGE_MISC_RESET_STS_REG,
+  HCLGE_MISC_VECTOR_INT_STS,
+  HCLGE_GLOBAL_RESET_REG,
+  HCLGE_FUN_RST_ING,
+  HCLGE_GRO_EN_REG};
+
+static const u32 ring_reg_addr_list[] = {HCLGE_RING_RX_ADDR_L_REG,
+HCLGE_RING_RX_ADDR_H_REG,
+HCLGE_RING_RX_BD_NUM_REG,
+HCLGE_RING_RX_BD_LENGTH_REG,
+HCLGE_RING_RX_MERGE_EN_REG,
+HCLGE_RING_RX_TAIL_REG,
+HCLGE_RING_RX_HEAD_REG,
+HCLGE_RING_RX_FBD_NUM_REG,
+HCLGE_RING_RX_OFFSET_REG,
+HCLGE_RING_RX_FBD_OFFSET_REG,
+HCLGE_RING_RX_STASH_REG,
+HCLGE_RING_RX_BD_ERR_REG,
+HCLGE_RING_TX_ADDR_L_REG,
+HCLGE_RING_TX_ADDR_H_REG,
+HCLGE_RING_TX_BD_NUM_REG,
+HCLGE_RING_TX_PRIORITY_REG,
+HCLGE_RING_TX_TC_REG,
+HCLGE_RING_TX_MERGE_EN_REG,
+HCLGE_RING_TX_TAIL_REG,
+HCLGE_RING_TX_HEAD_REG,
+HCLGE_RING_TX_FBD_NUM_REG,
+HCLGE_RING_TX_OFFSET_REG,
+HCLGE_RING_TX_EBD_NUM_REG,
+HCLGE_RING_TX_EBD_OFFSET_REG,
+HCLGE_RING_TX_BD_ERR_REG,
+HCLGE_RING_EN_REG};
+
+static const u32 tqp_intr_reg_addr_list[] = {HCLGE_TQP_INTR_CTRL_REG,
+HCLGE_TQP_INTR_GL0_REG,
+HCLGE_TQP_INTR_GL1_REG,
+HCLGE_TQP_INTR_GL2_REG,
+HCLGE_TQP_INTR_RL_REG};
+
 static const char hns3_nic_test_strs[][ETH_GSTRING_LEN] = {
"AppLoopback test",
"Serdes serial Loopback test",
@@ -7637,8 +7693,15 @@ static int hclge_get_64_bit_regs(struct hclge_dev *hdev, 
u32 regs_num,
return 0;
 }
 
+#define MAX_SEPARATE_NUM   4
+#define SEPARATOR_VALUE0x
+#define REG_NUM_PER_LINE   4
+#define REG_LEN_PER_LINE   (REG_NUM_PER_LINE * sizeof(u32))
+
 static int hclge_get_regs_len(struct hnae3_handle *handle)
 {
+   int cmdq_lines, common_lines, ring_lines, tqp_intr_lines;
+   struct hnae3_knic_private_info *kinfo = &handle->kinfo;
struct hclge_vport *vport = hclge_get_vport(handle);
str

[PATCH net-next] net: hns3: Config NIC port speed same as that of optical module

2018-11-26 Thread Salil Mehta
From: Peng Li 

Port 0/1 of HiP08 supports 10G and 25G. This patch adds a
change to configure NIC port speed same as that of  optical
module(SFP/QFSP). Driver gets the optical module speed and
sets NIC port speed accordingly.

Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h | 23 +++---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 84 ++
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  2 +
 3 files changed, 49 insertions(+), 60 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index 2b90410..e1805b9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -90,7 +90,6 @@ enum hclge_opcode_type {
/* MAC command */
HCLGE_OPC_CONFIG_MAC_MODE   = 0x0301,
HCLGE_OPC_CONFIG_AN_MODE= 0x0304,
-   HCLGE_OPC_QUERY_AN_RESULT   = 0x0306,
HCLGE_OPC_QUERY_LINK_STATUS = 0x0307,
HCLGE_OPC_CONFIG_MAX_FRM_SIZE   = 0x0308,
HCLGE_OPC_CONFIG_SPEED_DUP  = 0x0309,
@@ -212,6 +211,9 @@ enum hclge_opcode_type {
/* Led command */
HCLGE_OPC_LED_STATUS_CFG= 0xB000,
 
+   /* SFP command */
+   HCLGE_OPC_SFP_GET_SPEED = 0x7104,
+
/* Error INT commands */
HCLGE_TM_SCH_ECC_INT_EN = 0x0829,
HCLGE_TM_SCH_ECC_ERR_RINT_CMD   = 0x082d,
@@ -544,20 +546,6 @@ struct hclge_config_mac_speed_dup_cmd {
u8 rsv[22];
 };
 
-#define HCLGE_QUERY_SPEED_S3
-#define HCLGE_QUERY_AN_B   0
-#define HCLGE_QUERY_DUPLEX_B   2
-
-#define HCLGE_QUERY_SPEED_MGENMASK(4, 0)
-#define HCLGE_QUERY_AN_M   BIT(HCLGE_QUERY_AN_B)
-#define HCLGE_QUERY_DUPLEX_M   BIT(HCLGE_QUERY_DUPLEX_B)
-
-struct hclge_query_an_speed_dup_cmd {
-   u8 an_syn_dup_speed;
-   u8 pause;
-   u8 rsv[23];
-};
-
 #define HCLGE_RING_ID_MASK GENMASK(9, 0)
 #define HCLGE_TQP_ENABLE_B 0
 
@@ -574,6 +562,11 @@ struct hclge_config_auto_neg_cmd {
u8  rsv[20];
 };
 
+struct hclge_sfp_speed_cmd {
+   __le32  sfp_speed;
+   u32 rsv[5];
+};
+
 #define HCLGE_MAC_UPLINK_PORT  0x100
 
 struct hclge_config_max_frm_size_cmd {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 696cb53..1c8cf84 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -1896,37 +1896,6 @@ static int hclge_cfg_mac_speed_dup_h(struct hnae3_handle 
*handle, int speed,
return hclge_cfg_mac_speed_dup(hdev, speed, duplex);
 }
 
-static int hclge_query_mac_an_speed_dup(struct hclge_dev *hdev, int *speed,
-   u8 *duplex)
-{
-   struct hclge_query_an_speed_dup_cmd *req;
-   struct hclge_desc desc;
-   int speed_tmp;
-   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,
-   "mac speed/autoneg/duplex query cmd failed %d\n",
-   ret);
-   return ret;
-   }
-
-   *duplex = hnae3_get_bit(req->an_syn_dup_speed, HCLGE_QUERY_DUPLEX_B);
-   speed_tmp = hnae3_get_field(req->an_syn_dup_speed, HCLGE_QUERY_SPEED_M,
-   HCLGE_QUERY_SPEED_S);
-
-   ret = hclge_parse_speed(speed_tmp, speed);
-   if (ret)
-   dev_err(&hdev->pdev->dev,
-   "could not parse speed(=%d), %d\n", speed_tmp, ret);
-
-   return ret;
-}
-
 static int hclge_set_autoneg_en(struct hclge_dev *hdev, bool enable)
 {
struct hclge_config_auto_neg_cmd *req;
@@ -1973,6 +1942,7 @@ static int hclge_mac_init(struct hclge_dev *hdev)
struct hclge_mac *mac = &hdev->hw.mac;
int ret;
 
+   hdev->support_sfp_query = true;
hdev->hw.mac.duplex = HCLGE_MAC_FULL;
ret = hclge_cfg_mac_speed_dup_hw(hdev, hdev->hw.mac.speed,
 hdev->hw.mac.duplex);
@@ -2082,34 +2052,58 @@ static void hclge_update_link_status(struct hclge_dev 
*hdev)
}
 }
 
+static int hclge_get_sfp_speed(struct hclge_dev *hdev, u32 *speed)
+{
+   struct hclge_sfp_speed_cmd *resp = NULL;
+   struct hclge_desc desc;
+   int ret;
+
+   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_SFP_GET_SPEED, true);
+   resp = (struct hclge_sfp_speed_cmd *)desc.data;
+   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
+   if (ret == -EOPNOTSUPP) {
+  

[PATCH V2 net-next 0/5] net: hns3: Add support of hardware GRO to HNS3 Driver

2018-11-15 Thread Salil Mehta
This patch-set adds support of hardware assisted GRO feature to
HNS3 driver on Rev B(=0x21) platform. Current hardware only
supports TCP/IPv{4|6} flows.

Change Log:
V1->V2:
1. Remove redundant print reported by Leon Romanovsky.
   Link: https://lkml.org/lkml/2018/11/13/715

Peng Li (5):
  net: hns3: Enable HW GRO for Rev B(=0x21) HNS3 hardware
  net: hns3: Add handling of GRO Pkts not fully RX'ed in NAPI poll
  net: hns3: Add support for ethtool -K to enable/disable HW GRO
  net: hns3: Add skb chain when num of RX buf exceeds MAX_SKB_FRAGS
  net: hns3: Adds GRO params to SKB for the stack

 drivers/net/ethernet/hisilicon/hns3/hnae3.h   |   7 +
 .../net/ethernet/hisilicon/hns3/hns3_enet.c   | 289 ++
 .../net/ethernet/hisilicon/hns3/hns3_enet.h   |  17 +-
 .../hisilicon/hns3/hns3pf/hclge_cmd.h |   7 +
 .../hisilicon/hns3/hns3pf/hclge_main.c|  39 +++
 .../hisilicon/hns3/hns3vf/hclgevf_cmd.h   |   8 +
 .../hisilicon/hns3/hns3vf/hclgevf_main.c  |  39 +++
 7 files changed, 339 insertions(+), 67 deletions(-)

-- 
2.17.1




[PATCH net-next 11/12] net: hns3: Fix client initialize state issue when roce client initialize failed

2018-09-19 Thread Salil Mehta
From: Jian Shen 

When roce is loaded before nic, the roce client will not be initialized
until nic client is initialized, but roce init flag is set before it.
Furthermore, in this case of nic initialized success and roce failed,
the nic init flag is not set, and roce init flag is not cleared.

This patch fixes it by set init flag only after the client is initialized
successfully.

Fixes: e2cb1dec9779 ("net: hns3: Add HNS3 VF HCL(Hardware Compatibility Layer) 
Support")
Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support")
Signed-off-by: Jian Shen 
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.c   | 12 +---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h   |  3 +++
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c   |  9 +
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c |  9 +
 4 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.c 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
index fff5be8..781e5de 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
@@ -29,8 +29,8 @@ static bool hnae3_client_match(enum hnae3_client_type 
client_type,
return false;
 }
 
-static void hnae3_set_client_init_flag(struct hnae3_client *client,
-  struct hnae3_ae_dev *ae_dev, int inited)
+void hnae3_set_client_init_flag(struct hnae3_client *client,
+   struct hnae3_ae_dev *ae_dev, int inited)
 {
switch (client->type) {
case HNAE3_CLIENT_KNIC:
@@ -46,6 +46,7 @@ static void hnae3_set_client_init_flag(struct hnae3_client 
*client,
break;
}
 }
+EXPORT_SYMBOL(hnae3_set_client_init_flag);
 
 static int hnae3_get_client_init_flag(struct hnae3_client *client,
   struct hnae3_ae_dev *ae_dev)
@@ -86,14 +87,11 @@ static int hnae3_match_n_instantiate(struct hnae3_client 
*client,
/* now, (un-)instantiate client by calling lower layer */
if (is_reg) {
ret = ae_dev->ops->init_client_instance(client, ae_dev);
-   if (ret) {
+   if (ret)
dev_err(&ae_dev->pdev->dev,
"fail to instantiate client, ret = %d\n", ret);
-   return ret;
-   }
 
-   hnae3_set_client_init_flag(client, ae_dev, 1);
-   return 0;
+   return ret;
}
 
if (hnae3_get_client_init_flag(client, ae_dev)) {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index c48c187..17db631 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -523,4 +523,7 @@ void hnae3_register_ae_algo(struct hnae3_ae_algo *ae_algo);
 
 void hnae3_unregister_client(struct hnae3_client *client);
 int hnae3_register_client(struct hnae3_client *client);
+
+void hnae3_set_client_init_flag(struct hnae3_client *client,
+   struct hnae3_ae_dev *ae_dev, int inited);
 #endif
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 141da18..cf365d4 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -5171,6 +5171,8 @@ static int hclge_init_client_instance(struct hnae3_client 
*client,
goto clear_nic;
}
 
+   hnae3_set_client_init_flag(client, ae_dev, 1);
+
if (hdev->roce_client &&
hnae3_dev_roce_supported(hdev)) {
struct hnae3_client *rc = hdev->roce_client;
@@ -5182,6 +5184,9 @@ static int hclge_init_client_instance(struct hnae3_client 
*client,
ret = rc->ops->init_instance(&vport->roce);
if (ret)
goto clear_roce;
+
+   hnae3_set_client_init_flag(hdev->roce_client,
+  ae_dev, 1);
}
 
break;
@@ -5193,6 +5198,8 @@ static int hclge_init_client_instance(struct hnae3_client 
*client,
if (ret)
goto clear_nic;
 
+   hnae3_set_client_init_flag(client, ae_dev, 1);
+
break;
case HNAE3_CLIENT_ROCE:
if (hnae3_dev_roce_supported(hdev)) {
@@ -5208,6 +5215,8 @@ static int hclge_init_client_instance(struct hnae3_client 
*cl

[PATCH net-next 03/10] net: hns3: Fix for waterline not setting correctly

2018-07-06 Thread Salil Mehta
From: Yunsheng Lin 

The HCLGE_RX_PRIV_EN_B is used to tell the firmware whether
to update the specific waterline value, if the is not set,
the firmware will ignore the value.

This patch fixes by setting the HCLGE_RX_PRIV_EN_B even if
the updated value is zero.

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

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 6fffc69..dae1aa5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -1834,8 +1834,6 @@ static int hclge_rx_priv_buf_alloc(struct hclge_dev *hdev,
return 0;
 }
 
-#define HCLGE_PRIV_ENABLE(a) ((a) > 0 ? 1 : 0)
-
 static int hclge_rx_priv_wl_config(struct hclge_dev *hdev,
   struct hclge_pkt_buf_alloc *buf_alloc)
 {
@@ -1863,13 +1861,11 @@ static int hclge_rx_priv_wl_config(struct hclge_dev 
*hdev,
req->tc_wl[j].high =
cpu_to_le16(priv->wl.high >> HCLGE_BUF_UNIT_S);
req->tc_wl[j].high |=
-   cpu_to_le16(HCLGE_PRIV_ENABLE(priv->wl.high) <<
-   HCLGE_RX_PRIV_EN_B);
+   cpu_to_le16(BIT(HCLGE_RX_PRIV_EN_B));
req->tc_wl[j].low =
cpu_to_le16(priv->wl.low >> HCLGE_BUF_UNIT_S);
req->tc_wl[j].low |=
-   cpu_to_le16(HCLGE_PRIV_ENABLE(priv->wl.low) <<
-   HCLGE_RX_PRIV_EN_B);
+cpu_to_le16(BIT(HCLGE_RX_PRIV_EN_B));
}
}
 
@@ -1911,13 +1907,11 @@ static int hclge_common_thrd_config(struct hclge_dev 
*hdev,
req->com_thrd[j].high =
cpu_to_le16(tc->high >> HCLGE_BUF_UNIT_S);
req->com_thrd[j].high |=
-   cpu_to_le16(HCLGE_PRIV_ENABLE(tc->high) <<
-   HCLGE_RX_PRIV_EN_B);
+cpu_to_le16(BIT(HCLGE_RX_PRIV_EN_B));
req->com_thrd[j].low =
cpu_to_le16(tc->low >> HCLGE_BUF_UNIT_S);
req->com_thrd[j].low |=
-   cpu_to_le16(HCLGE_PRIV_ENABLE(tc->low) <<
-   HCLGE_RX_PRIV_EN_B);
+cpu_to_le16(BIT(HCLGE_RX_PRIV_EN_B));
}
}
 
@@ -1943,14 +1937,10 @@ static int hclge_common_wl_config(struct hclge_dev 
*hdev,
 
req = (struct hclge_rx_com_wl *)desc.data;
req->com_wl.high = cpu_to_le16(buf->self.high >> HCLGE_BUF_UNIT_S);
-   req->com_wl.high |=
-   cpu_to_le16(HCLGE_PRIV_ENABLE(buf->self.high) <<
-   HCLGE_RX_PRIV_EN_B);
+   req->com_wl.high |=  cpu_to_le16(BIT(HCLGE_RX_PRIV_EN_B));
 
req->com_wl.low = cpu_to_le16(buf->self.low >> HCLGE_BUF_UNIT_S);
-   req->com_wl.low |=
-   cpu_to_le16(HCLGE_PRIV_ENABLE(buf->self.low) <<
-   HCLGE_RX_PRIV_EN_B);
+   req->com_wl.low |=  cpu_to_le16(BIT(HCLGE_RX_PRIV_EN_B));
 
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
-- 
2.7.4




[PATCH net-next 02/12] net: hns3: Add support for tx_accept_tag2 and tx_accept_untag2 config

2018-05-25 Thread Salil Mehta
From: Peng Li 

HNS3 Hardware can support up to two VLAN tags in transmit leg, the PPP
module can handle the packets based on the tag1 and tag2 config. This
patch adds support for tag2 config for vlan handling

Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  7 --
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 26 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|  6 +++--
 3 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index ee3cbac..3fa08f7 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -704,11 +704,14 @@ 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_ACCEPT_TAG1_B0
+#define HCLGE_ACCEPT_UNTAG1_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
+#define HCLGE_ACCEPT_TAG2_B5
+#define HCLGE_ACCEPT_UNTAG2_B  6
+
 struct hclge_vport_vtag_tx_cfg_cmd {
u8 vport_vlan_cfg;
u8 vf_offset;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 2f0bbb6..c0b8d5a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -4687,10 +4687,14 @@ static int hclge_set_vlan_tx_offload_cfg(struct 
hclge_vport *vport)
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_ACCEPT_TAG1_B,
+   vcfg->accept_tag1 ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_ACCEPT_UNTAG1_B,
+   vcfg->accept_untag1 ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_ACCEPT_TAG2_B,
+   vcfg->accept_tag2 ? 1 : 0);
+   hnae_set_bit(req->vport_vlan_cfg, HCLGE_ACCEPT_UNTAG2_B,
+   vcfg->accept_untag2 ? 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,
@@ -4814,8 +4818,18 @@ static int hclge_init_vlan_config(struct hclge_dev *hdev)
 
for (i = 0; i < hdev->num_alloc_vport; i++) {
vport = &hdev->vport[i];
-   vport->txvlan_cfg.accept_tag = true;
-   vport->txvlan_cfg.accept_untag = true;
+   vport->txvlan_cfg.accept_tag1 = true;
+   vport->txvlan_cfg.accept_untag1 = true;
+
+   /* accept_tag2 and accept_untag2 are not supported on
+* pdev revision(0x20), new revision support them. The
+* value of this two fields will not return error when driver
+* send command to fireware in revision(0x20).
+* This two fields can not configured by user.
+*/
+   vport->txvlan_cfg.accept_tag2 = true;
+   vport->txvlan_cfg.accept_untag2 = true;
+
vport->txvlan_cfg.insert_tag1_en = false;
vport->txvlan_cfg.insert_tag2_en = false;
vport->txvlan_cfg.default_tag1 = 0;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
index 93177d9..677f1e4 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
@@ -570,8 +570,10 @@ struct hclge_dev {
 
 /* VPort level vlan tag configuration for TX direction */
 struct hclge_tx_vtag_cfg {
-   bool accept_tag;/* Whether accept tagged packet from host */
-   bool accept_untag;  /* Whether accept untagged packet from host */
+   bool accept_tag1;   /* Whether accept tag1 packet from host */
+   bool accept_untag1; /* Whether accept untag1 packet from host */
+   bool accept_tag2;
+   bool accept_untag2;
bool insert_tag1_en;/* Whether insert inner vlan tag */
bool insert_tag2_en;/* Whether insert outer vlan tag */
u16  default_tag1;  /* The default inner vlan tag to insert */
-- 
2.7.4




[PATCH net-next 03/12] net: hns3: Add STRP_TAGP field support for hardware revision 0x21

2018-05-25 Thread Salil Mehta
From: Peng Li 

Hardware Revision(0x21) Buffer Descriptor adds a field STRP_TAGP
for vlan stripped processed indication. STRP_TAGP field has 2 bits,
bit 0 is stripped indication of the vlan tag in outer vlan tag
field, bit 1 is stripped indication of the vlan tag in inner vlan
tag field. For each bit, 0 indicates the tag is not stripped and
1 indicates the tag is stripped.

This patch adds STRP_TAGP support for revision(0x21), and does not
change the revision(0x20) action.

Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 42 ++---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h |  3 ++
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index ae8d749..1bcb676 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2066,6 +2066,39 @@ static void hns3_rx_skb(struct hns3_enet_ring *ring, 
struct sk_buff *skb)
napi_gro_receive(&ring->tqp_vector->napi, skb);
 }
 
+static u16 hns3_parse_vlan_tag(struct hns3_enet_ring *ring,
+  struct hns3_desc *desc, u32 l234info)
+{
+   struct pci_dev *pdev = ring->tqp->handle->pdev;
+   u16 vlan_tag;
+
+   if (pdev->revision == 0x20) {
+   vlan_tag = le16_to_cpu(desc->rx.ot_vlan_tag);
+   if (!(vlan_tag & VLAN_VID_MASK))
+   vlan_tag = le16_to_cpu(desc->rx.vlan_tag);
+
+   return vlan_tag;
+   }
+
+#define HNS3_STRP_OUTER_VLAN   0x1
+#define HNS3_STRP_INNER_VLAN   0x2
+
+   switch (hnae_get_field(l234info, HNS3_RXD_STRP_TAGP_M,
+  HNS3_RXD_STRP_TAGP_S)) {
+   case HNS3_STRP_OUTER_VLAN:
+   vlan_tag = le16_to_cpu(desc->rx.ot_vlan_tag);
+   break;
+   case HNS3_STRP_INNER_VLAN:
+   vlan_tag = le16_to_cpu(desc->rx.vlan_tag);
+   break;
+   default:
+   vlan_tag = 0;
+   break;
+   }
+
+   return vlan_tag;
+}
+
 static int hns3_handle_rx_bd(struct hns3_enet_ring *ring,
 struct sk_buff **out_skb, int *out_bnum)
 {
@@ -2155,6 +2188,9 @@ static int hns3_handle_rx_bd(struct hns3_enet_ring *ring,
}
 
*out_bnum = bnum;
+
+   l234info = le32_to_cpu(desc->rx.l234_info);
+
/* Based on hw strategy, the tag offloaded will be stored at
 * ot_vlan_tag in two layer tag case, and stored at vlan_tag
 * in one layer tag case.
@@ -2162,17 +2198,13 @@ static int hns3_handle_rx_bd(struct hns3_enet_ring 
*ring,
if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) {
u16 vlan_tag;
 
-   vlan_tag = le16_to_cpu(desc->rx.ot_vlan_tag);
-   if (!(vlan_tag & VLAN_VID_MASK))
-   vlan_tag = le16_to_cpu(desc->rx.vlan_tag);
+   vlan_tag = hns3_parse_vlan_tag(ring, desc, l234info);
if (vlan_tag & VLAN_VID_MASK)
__vlan_hwaccel_put_tag(skb,
   htons(ETH_P_8021Q),
   vlan_tag);
}
 
-   l234info = le32_to_cpu(desc->rx.l234_info);
-
if (unlikely(!hnae_get_bit(bd_base_info, HNS3_RXD_VLD_B))) {
netdev_err(netdev, "no valid bd,%016llx,%016llx\n",
   ((u64 *)desc)[0], ((u64 *)desc)[1]);
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
index 5b40f5a..38e91ca 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
@@ -104,6 +104,9 @@ enum hns3_nic_state {
 #define HNS3_RXD_L4ID_S8
 #define HNS3_RXD_L4ID_M(0xf << HNS3_RXD_L4ID_S)
 #define HNS3_RXD_FRAG_B12
+#define HNS3_RXD_STRP_TAGP_S   13
+#define HNS3_RXD_STRP_TAGP_M   (0x3 << HNS3_RXD_STRP_TAGP_S)
+
 #define HNS3_RXD_L2E_B 16
 #define HNS3_RXD_L3E_B 17
 #define HNS3_RXD_L4E_B 18
-- 
2.7.4




[PATCH net-next 07/12] net: hns3: Fixes the init of the VALID BD info in the descriptor

2018-05-25 Thread Salil Mehta
From: Fuyun Liang 

RX Buffer Descriptor contains a VALID bit which indicates if the BD
is valid and has some data. This field is set by HNS3 hardware to
intimate the driver of some valid data present in the BD. nd should
be reset by the driver when BD is being used again. In the existing
code this bit was not being (re-)initialized properly and hence was
causing problems.

Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 
SoC")
Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 1bcb676..d1ef104 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1819,6 +1819,7 @@ static void hns3_replace_buffer(struct hns3_enet_ring 
*ring, int 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);
+   ring->desc[i].rx.bd_base_info = 0;
 }
 
 static void hns3_reuse_buffer(struct hns3_enet_ring *ring, int i)
@@ -1826,6 +1827,7 @@ static void hns3_reuse_buffer(struct hns3_enet_ring 
*ring, int i)
ring->desc_cb[i].reuse_flag = 0;
ring->desc[i].addr = cpu_to_le64(ring->desc_cb[i].dma
+ ring->desc_cb[i].page_offset);
+   ring->desc[i].rx.bd_base_info = 0;
 }
 
 static void hns3_nic_reclaim_one_desc(struct hns3_enet_ring *ring, int *bytes,
-- 
2.7.4




[PATCH net-next 05/12] net: hns3: Fix for PF mailbox receving unknown message

2018-05-25 Thread Salil Mehta
From: Xi Wang 

Before the firmware updates the crq's tail pointer, if the PF driver
reads the data in the crq, the data may be incomplete at this time,
which will lead to the driver read an unknown message.

This patch fixes it by checking if crq is not empty before reading the
message.

Fixes: c1a81619d73a ("net: hns3: Add mailbox interrupt handling to PF driver")
Signed-off-by: Xi Wang 
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c | 23 +++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
index b6ae26b..31f3d9a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c
@@ -382,6 +382,13 @@ static void hclge_reset_vf(struct hclge_vport *vport,
hclge_func_reset_cmd(hdev, mbx_req->mbx_src_vfid);
 }
 
+static bool hclge_cmd_crq_empty(struct hclge_hw *hw)
+{
+   u32 tail = hclge_read_dev(hw, HCLGE_NIC_CRQ_TAIL_REG);
+
+   return tail == hw->cmq.crq.next_to_use;
+}
+
 void hclge_mbx_handler(struct hclge_dev *hdev)
 {
struct hclge_cmq_ring *crq = &hdev->hw.cmq.crq;
@@ -390,12 +397,23 @@ void hclge_mbx_handler(struct hclge_dev *hdev)
struct hclge_desc *desc;
int ret, flag;
 
-   flag = le16_to_cpu(crq->desc[crq->next_to_use].flag);
/* handle all the mailbox requests in the queue */
-   while (hnae_get_bit(flag, HCLGE_CMDQ_RX_OUTVLD_B)) {
+   while (!hclge_cmd_crq_empty(&hdev->hw)) {
desc = &crq->desc[crq->next_to_use];
req = (struct hclge_mbx_vf_to_pf_cmd *)desc->data;
 
+   flag = le16_to_cpu(crq->desc[crq->next_to_use].flag);
+   if (unlikely(!hnae_get_bit(flag, HCLGE_CMDQ_RX_OUTVLD_B))) {
+   dev_warn(&hdev->pdev->dev,
+"dropped invalid mailbox message, code = %d\n",
+req->msg[0]);
+
+   /* dropping/not processing this invalid message */
+   crq->desc[crq->next_to_use].flag = 0;
+   hclge_mbx_ring_ptr_move_crq(crq);
+   continue;
+   }
+
vport = &hdev->vport[req->mbx_src_vfid];
 
switch (req->msg[0]) {
@@ -470,7 +488,6 @@ void hclge_mbx_handler(struct hclge_dev *hdev)
}
crq->desc[crq->next_to_use].flag = 0;
hclge_mbx_ring_ptr_move_crq(crq);
-   flag = le16_to_cpu(crq->desc[crq->next_to_use].flag);
}
 
/* Write back CMDQ_RQ header pointer, M7 need this pointer */
-- 
2.7.4




[PATCH net-next 00/12] Misc. bug fixes & some minor additions to HNS3 driver

2018-05-25 Thread Salil Mehta
This patch-set provides some bug fixes figured out during testing
and review. It also provides some additions due to running of the
existing code on the new revision of the HNS3 hardware.

Fuyun Liang (3):
  net: hns3: Fixes the init of the VALID BD info in the descriptor
  net: hns3: Removes unnecessary check when clearing TX/RX rings
  net: hns3: Clear TX/RX rings when stopping port & un-initializing
client

Jian Shen (2):
  net: hns3: Remove unused led control code
  net: hns3: Adds support for led locate command for copper port

Lijun Ou (1):
  net: hns3: Fixes initalization of RoCE handle and makes it conditional

Peng Li (5):
  net: hns3: Updates RX packet info fetch in case of multi BD
  net: hns3: Add support for tx_accept_tag2 and tx_accept_untag2 config
  net: hns3: Add STRP_TAGP field support for hardware revision 0x21
  net: hns3: Add support to enable TX/RX promisc mode for H/W rev(0x21)
  net: hns3: Fixes the state to indicate client-type initialization

Xi Wang (1):
  net: hns3: Fix for PF mailbox receving unknown message

 drivers/net/ethernet/hisilicon/hns3/hnae3.c|  49 +-
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|   4 +-
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 189 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|   4 +
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c |   4 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |  22 +--
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 179 ---
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|   8 +-
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c |  23 ++-
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  |   8 +-
 10 files changed, 283 insertions(+), 207 deletions(-)

-- 
2.7.4




[PATCH net-next 01/12] net: hns3: Updates RX packet info fetch in case of multi BD

2018-05-25 Thread Salil Mehta
From: Peng Li 

In the latest revision of the hardware, if a packet is spanning
across multiple BDs then only VLD bit and current data size info
is valid in each BD, and rest of the information is only valid
in the last BD of the packet. In such case we should make sure
we are fetching RX packet size from the first descriptor and
information like VLAN should be fetched from last BD.

Signed-off-by: Peng Li 
Reviewed-by: Yisen Zhuang 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 36 -
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index cac5195..ae8d749 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -2085,9 +2085,8 @@ static int hns3_handle_rx_bd(struct hns3_enet_ring *ring,
 
prefetch(desc);
 
-   length = le16_to_cpu(desc->rx.pkt_len);
+   length = le16_to_cpu(desc->rx.size);
bd_base_info = le32_to_cpu(desc->rx.bd_base_info);
-   l234info = le32_to_cpu(desc->rx.l234_info);
 
/* Check valid BD */
if (!hnae_get_bit(bd_base_info, HNS3_RXD_VLD_B))
@@ -2121,22 +2120,6 @@ static int hns3_handle_rx_bd(struct hns3_enet_ring *ring,
 
prefetchw(skb->data);
 
-   /* Based on hw strategy, the tag offloaded will be stored at
-* ot_vlan_tag in two layer tag case, and stored at vlan_tag
-* in one layer tag case.
-*/
-   if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) {
-   u16 vlan_tag;
-
-   vlan_tag = le16_to_cpu(desc->rx.ot_vlan_tag);
-   if (!(vlan_tag & VLAN_VID_MASK))
-   vlan_tag = le16_to_cpu(desc->rx.vlan_tag);
-   if (vlan_tag & VLAN_VID_MASK)
-   __vlan_hwaccel_put_tag(skb,
-  htons(ETH_P_8021Q),
-  vlan_tag);
-   }
-
bnum = 1;
if (length <= HNS3_RX_HEAD_SIZE) {
memcpy(__skb_put(skb, length), va, ALIGN(length, sizeof(long)));
@@ -2172,6 +2155,23 @@ static int hns3_handle_rx_bd(struct hns3_enet_ring *ring,
}
 
*out_bnum = bnum;
+   /* Based on hw strategy, the tag offloaded will be stored at
+* ot_vlan_tag in two layer tag case, and stored at vlan_tag
+* in one layer tag case.
+*/
+   if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) {
+   u16 vlan_tag;
+
+   vlan_tag = le16_to_cpu(desc->rx.ot_vlan_tag);
+   if (!(vlan_tag & VLAN_VID_MASK))
+   vlan_tag = le16_to_cpu(desc->rx.vlan_tag);
+   if (vlan_tag & VLAN_VID_MASK)
+   __vlan_hwaccel_put_tag(skb,
+  htons(ETH_P_8021Q),
+  vlan_tag);
+   }
+
+   l234info = le32_to_cpu(desc->rx.l234_info);
 
if (unlikely(!hnae_get_bit(bd_base_info, HNS3_RXD_VLD_B))) {
netdev_err(netdev, "no valid bd,%016llx,%016llx\n",
-- 
2.7.4




[PATCH net-next 09/12] net: hns3: Clear TX/RX rings when stopping port & un-initializing client

2018-05-25 Thread Salil Mehta
From: Fuyun Liang 

When we down the port, some packets are left in TX/RX buffer. When we
up the port again, these old packets are forwarded to protocol stack
or are sent to internet. It will make some problem. TX/RX buffer should
be cleared when stopping port. This patch adds some function to ensure
the buffer is clean when port is started. We should clear the rings
when clients are being un-initialized as well.

Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 
SoC")
Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 115 +++--
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|   1 +
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c |   4 +
 3 files changed, 110 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 4c13c52..0529012 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -25,6 +25,9 @@
 #include "hnae3.h"
 #include "hns3_enet.h"
 
+static void hns3_clear_all_ring(struct hnae3_handle *h);
+static void hns3_force_clear_all_rx_ring(struct hnae3_handle *h);
+
 static const char hns3_driver_name[] = "hns3";
 const char hns3_driver_version[] = VERMAGIC_STRING;
 static const char hns3_driver_string[] =
@@ -273,6 +276,10 @@ static int hns3_nic_net_up(struct net_device *netdev)
int i, j;
int ret;
 
+   ret = hns3_nic_reset_all_ring(h);
+   if (ret)
+   return ret;
+
/* get irq resource for all vectors */
ret = hns3_nic_init_irq(priv);
if (ret) {
@@ -333,17 +340,19 @@ static void hns3_nic_net_down(struct net_device *netdev)
if (test_and_set_bit(HNS3_NIC_STATE_DOWN, &priv->state))
return;
 
+   /* disable vectors */
+   for (i = 0; i < priv->vector_num; i++)
+   hns3_vector_disable(&priv->tqp_vector[i]);
+
/* stop ae_dev */
ops = priv->ae_handle->ae_algo->ops;
if (ops->stop)
ops->stop(priv->ae_handle);
 
-   /* disable vectors */
-   for (i = 0; i < priv->vector_num; i++)
-   hns3_vector_disable(&priv->tqp_vector[i]);
-
/* free irq resources */
hns3_nic_uninit_irq(priv);
+
+   hns3_clear_all_ring(priv->ae_handle);
 }
 
 static int hns3_nic_net_stop(struct net_device *netdev)
@@ -2939,8 +2948,6 @@ int hns3_init_all_ring(struct hns3_nic_priv *priv)
goto out_when_alloc_ring_memory;
}
 
-   hns3_init_ring_hw(priv->ring_data[i].ring);
-
u64_stats_init(&priv->ring_data[i].ring->syncp);
}
 
@@ -3102,6 +3109,8 @@ static void hns3_client_uninit(struct hnae3_handle 
*handle, bool reset)
if (netdev->reg_state != NETREG_UNINITIALIZED)
unregister_netdev(netdev);
 
+   hns3_force_clear_all_rx_ring(handle);
+
ret = hns3_nic_uninit_vector_data(priv);
if (ret)
netdev_err(netdev, "uninit vector error\n");
@@ -3218,12 +3227,46 @@ static void hns3_recover_hw_addr(struct net_device 
*ndev)
 static void hns3_clear_tx_ring(struct hns3_enet_ring *ring)
 {
while (ring->next_to_clean != ring->next_to_use) {
+   ring->desc[ring->next_to_clean].tx.bdtp_fe_sc_vld_ra_ri = 0;
hns3_free_buffer_detach(ring, ring->next_to_clean);
ring_ptr_move_fw(ring, next_to_clean);
}
 }
 
-static void hns3_clear_rx_ring(struct hns3_enet_ring *ring)
+static int hns3_clear_rx_ring(struct hns3_enet_ring *ring)
+{
+   struct hns3_desc_cb res_cbs;
+   int ret;
+
+   while (ring->next_to_use != ring->next_to_clean) {
+   /* When a buffer is not reused, it's memory has been
+* freed in hns3_handle_rx_bd or will be freed by
+* stack, so we need to replace the buffer here.
+*/
+   if (!ring->desc_cb[ring->next_to_use].reuse_flag) {
+   ret = hns3_reserve_buffer_map(ring, &res_cbs);
+   if (ret) {
+   u64_stats_update_begin(&ring->syncp);
+   ring->stats.sw_err_cnt++;
+   u64_stats_update_end(&ring->syncp);
+   /* if alloc new buffer fail, exit directly
+* and reclear in up flow.
+*/
+   netdev_warn(ring->tqp->handle->kinfo.netdev,
+   "reserve buffer map failed, ret = 
%d\n",
+   ret);

[PATCH net-next 10/12] net: hns3: Remove unused led control code

2018-05-25 Thread Salil Mehta
From: Jian Shen 

In the previous implementation of led control for fibre port , parses the
port speed configuration, checks the link status and traffic status per
second, and updates the blink status of link led, traffic led and speed
led.

Now, the firmware takes responsibility to handle the led, the dirver just
needs to deal with locate command.

So the codes for link led, traffic led and speed led are useless now. This
patch removes these redundant codes.

Signed-off-by: Jian Shen 
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h |   1 -
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 109 -
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|   2 -
 3 files changed, 112 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index e9be6aa..de2f6f1 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -115,7 +115,6 @@ enum hclge_opcode_type {
HCLGE_OPC_QUERY_LINK_STATUS = 0x0307,
HCLGE_OPC_CONFIG_MAX_FRM_SIZE   = 0x0308,
HCLGE_OPC_CONFIG_SPEED_DUP  = 0x0309,
-   HCLGE_OPC_STATS_MAC_TRAFFIC = 0x0314,
/* MACSEC command */
 
/* PFC/Pause CMD*/
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 8ad8f62..20988aa 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -39,7 +39,6 @@ static int hclge_set_mta_filter_mode(struct hclge_dev *hdev,
 static int hclge_set_mtu(struct hnae3_handle *handle, int new_mtu);
 static int hclge_init_vlan_config(struct hclge_dev *hdev);
 static int hclge_reset_ae_dev(struct hnae3_ae_dev *ae_dev);
-static int hclge_update_led_status(struct hclge_dev *hdev);
 
 static struct hnae3_ae_algo ae_algo;
 
@@ -504,38 +503,6 @@ static int hclge_32_bit_update_stats(struct hclge_dev 
*hdev)
return 0;
 }
 
-static int hclge_mac_get_traffic_stats(struct hclge_dev *hdev)
-{
-   struct hclge_mac_stats *mac_stats = &hdev->hw_stats.mac_stats;
-   struct hclge_desc desc;
-   __le64 *desc_data;
-   int ret;
-
-   /* for fiber port, need to query the total rx/tx packets statstics,
-* used for data transferring checking.
-*/
-   if (hdev->hw.mac.media_type != HNAE3_MEDIA_TYPE_FIBER)
-   return 0;
-
-   if (test_bit(HCLGE_STATE_STATISTICS_UPDATING, &hdev->state))
-   return 0;
-
-   hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_STATS_MAC_TRAFFIC, true);
-   ret = hclge_cmd_send(&hdev->hw, &desc, 1);
-   if (ret) {
-   dev_err(&hdev->pdev->dev,
-   "Get MAC total pkt stats fail, ret = %d\n", ret);
-
-   return ret;
-   }
-
-   desc_data = (__le64 *)(&desc.data[0]);
-   mac_stats->mac_tx_total_pkt_num += le64_to_cpu(*desc_data++);
-   mac_stats->mac_rx_total_pkt_num += le64_to_cpu(*desc_data);
-
-   return 0;
-}
-
 static int hclge_mac_update_stats(struct hclge_dev *hdev)
 {
 #define HCLGE_MAC_CMD_NUM 21
@@ -2916,20 +2883,13 @@ static void hclge_service_task(struct work_struct *work)
struct hclge_dev *hdev =
container_of(work, struct hclge_dev, service_task);
 
-   /* The total rx/tx packets statstics are wanted to be updated
-* per second. Both hclge_update_stats_for_all() and
-* hclge_mac_get_traffic_stats() can do it.
-*/
if (hdev->hw_stats.stats_timer >= HCLGE_STATS_TIMER_INTERVAL) {
hclge_update_stats_for_all(hdev);
hdev->hw_stats.stats_timer = 0;
-   } else {
-   hclge_mac_get_traffic_stats(hdev);
}
 
hclge_update_speed_duplex(hdev);
hclge_update_link_status(hdev);
-   hclge_update_led_status(hdev);
hclge_service_complete(hdev);
 }
 
@@ -6100,75 +6060,6 @@ static int hclge_set_led_id(struct hnae3_handle *handle,
return ret;
 }
 
-enum hclge_led_port_speed {
-   HCLGE_SPEED_LED_FOR_1G,
-   HCLGE_SPEED_LED_FOR_10G,
-   HCLGE_SPEED_LED_FOR_25G,
-   HCLGE_SPEED_LED_FOR_40G,
-   HCLGE_SPEED_LED_FOR_50G,
-   HCLGE_SPEED_LED_FOR_100G,
-};
-
-static u8 hclge_led_get_speed_status(u32 speed)
-{
-   u8 speed_led;
-
-   switch (speed) {
-   case HCLGE_MAC_SPEED_1G:
-   speed_led = HCLGE_SPEED_LED_FOR_1G;
-   break;
-   case HCLGE_MAC_SPEED_10G:
-   speed_led = HCLGE_SPEED_LED_FOR_10G;
-   break;
-   case HCLGE_MAC_SPEED_25G:
-   speed_led = HCLGE_SPEED_LED_FOR_25G;
-   break;
-   case HCLGE_MAC_SPEED_40G:
-   speed_led = HCLGE_SPE

[PATCH net-next 06/12] net: hns3: Fixes the state to indicate client-type initialization

2018-05-25 Thread Salil Mehta
From: Peng Li 

HNAE3 module supports kernel nic driver, user nic driver and roce driver,
and there are 3 client types. Driver uses one bit(HNAE3_CLIENT_INITED_B)
to indicate the client initialization state, it will cause confusion
for 3 client types. This patch fixes it by use 3 bits to indicate the
initialization state.

Fixes: 38caee9d3ee8 ("net: hns3: Add support of the HNAE3 framework")
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.c | 49 +++--
 drivers/net/ethernet/hisilicon/hns3/hnae3.h |  4 ++-
 2 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.c 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
index 63d7dbf..9d79dad 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
@@ -36,6 +36,49 @@ static bool hnae3_client_match(enum hnae3_client_type 
client_type,
return false;
 }
 
+static void hnae3_set_client_init_flag(struct hnae3_client *client,
+  struct hnae3_ae_dev *ae_dev, int inited)
+{
+   switch (client->type) {
+   case HNAE3_CLIENT_KNIC:
+   hnae_set_bit(ae_dev->flag, HNAE3_KNIC_CLIENT_INITED_B, inited);
+   break;
+   case HNAE3_CLIENT_UNIC:
+   hnae_set_bit(ae_dev->flag, HNAE3_UNIC_CLIENT_INITED_B, inited);
+   break;
+   case HNAE3_CLIENT_ROCE:
+   hnae_set_bit(ae_dev->flag, HNAE3_ROCE_CLIENT_INITED_B, inited);
+   break;
+   default:
+   break;
+   }
+}
+
+static int hnae3_get_client_init_flag(struct hnae3_client *client,
+  struct hnae3_ae_dev *ae_dev)
+{
+   int inited = 0;
+
+   switch (client->type) {
+   case HNAE3_CLIENT_KNIC:
+   inited = hnae_get_bit(ae_dev->flag,
+  HNAE3_KNIC_CLIENT_INITED_B);
+   break;
+   case HNAE3_CLIENT_UNIC:
+   inited = hnae_get_bit(ae_dev->flag,
+  HNAE3_UNIC_CLIENT_INITED_B);
+   break;
+   case HNAE3_CLIENT_ROCE:
+   inited = hnae_get_bit(ae_dev->flag,
+ HNAE3_ROCE_CLIENT_INITED_B);
+   break;
+   default:
+   break;
+   }
+
+   return inited;
+}
+
 static int hnae3_match_n_instantiate(struct hnae3_client *client,
 struct hnae3_ae_dev *ae_dev, bool is_reg)
 {
@@ -56,14 +99,14 @@ static int hnae3_match_n_instantiate(struct hnae3_client 
*client,
return ret;
}
 
-   hnae_set_bit(ae_dev->flag, HNAE3_CLIENT_INITED_B, 1);
+   hnae3_set_client_init_flag(client, ae_dev, 1);
return 0;
}
 
-   if (hnae_get_bit(ae_dev->flag, HNAE3_CLIENT_INITED_B)) {
+   if (hnae3_get_client_init_flag(client, ae_dev)) {
ae_dev->ops->uninit_client_instance(client, ae_dev);
 
-   hnae_set_bit(ae_dev->flag, HNAE3_CLIENT_INITED_B, 0);
+   hnae3_set_client_init_flag(client, ae_dev, 0);
}
 
return 0;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index 45c571e..f250c59 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -54,7 +54,9 @@
 #define HNAE3_DEV_INITED_B 0x0
 #define HNAE3_DEV_SUPPORT_ROCE_B   0x1
 #define HNAE3_DEV_SUPPORT_DCB_B0x2
-#define HNAE3_CLIENT_INITED_B  0x3
+#define HNAE3_KNIC_CLIENT_INITED_B 0x3
+#define HNAE3_UNIC_CLIENT_INITED_B 0x4
+#define HNAE3_ROCE_CLIENT_INITED_B 0x5
 
 #define HNAE3_DEV_SUPPORT_ROCE_DCB_BITS (BIT(HNAE3_DEV_SUPPORT_DCB_B) |\
BIT(HNAE3_DEV_SUPPORT_ROCE_B))
-- 
2.7.4




[PATCH net-next 08/12] net: hns3: Removes unnecessary check when clearing TX/RX rings

2018-05-25 Thread Salil Mehta
From: Fuyun Liang 

Our code will ensure that hns3_clear_tx_ring is not used to cleared
RX rings and hns3_clear_rx_ring is not used to cleared TX rings. So
the ring type check is unnecessary.

Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 
SoC")
Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index d1ef104..4c13c52 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -3217,9 +3217,6 @@ static void hns3_recover_hw_addr(struct net_device *ndev)
 
 static void hns3_clear_tx_ring(struct hns3_enet_ring *ring)
 {
-   if (!HNAE3_IS_TX_RING(ring))
-   return;
-
while (ring->next_to_clean != ring->next_to_use) {
hns3_free_buffer_detach(ring, ring->next_to_clean);
ring_ptr_move_fw(ring, next_to_clean);
@@ -3228,9 +3225,6 @@ static void hns3_clear_tx_ring(struct hns3_enet_ring 
*ring)
 
 static void hns3_clear_rx_ring(struct hns3_enet_ring *ring)
 {
-   if (HNAE3_IS_TX_RING(ring))
-   return;
-
while (ring->next_to_use != ring->next_to_clean) {
/* When a buffer is not reused, it's memory has been
 * freed in hns3_handle_rx_bd or will be freed by
-- 
2.7.4




[PATCH net-next 11/12] net: hns3: Adds support for led locate command for copper port

2018-05-25 Thread Salil Mehta
From: Jian Shen 

Firmware now supports control of all leds. Existing HNS3 driver code
only supported led locate command over SFP Fibre ports. But now it
is also supported over copper port.
This patch removes existing not needed code for the led locate
command and updates the led control command between driver and
firmware.

Signed-off-by: Jian Shen 
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h | 12 ++--
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 35 +++---
 2 files changed, 6 insertions(+), 41 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
index de2f6f1..d9aaa76 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -817,21 +817,13 @@ struct hclge_reset_cmd {
 #define HCLGE_NIC_CMQ_DESC_NUM 1024
 #define HCLGE_NIC_CMQ_DESC_NUM_S   3
 
-#define HCLGE_LED_PORT_SPEED_STATE_S   0
-#define HCLGE_LED_PORT_SPEED_STATE_M   GENMASK(5, 0)
-#define HCLGE_LED_ACTIVITY_STATE_S 0
-#define HCLGE_LED_ACTIVITY_STATE_M GENMASK(1, 0)
-#define HCLGE_LED_LINK_STATE_S 0
-#define HCLGE_LED_LINK_STATE_M GENMASK(1, 0)
 #define HCLGE_LED_LOCATE_STATE_S   0
 #define HCLGE_LED_LOCATE_STATE_M   GENMASK(1, 0)
 
 struct hclge_set_led_state_cmd {
-   u8 port_speed_led_config;
-   u8 link_led_config;
-   u8 activity_led_config;
+   u8 rsv1[3];
u8 locate_led_config;
-   u8 rsv[20];
+   u8 rsv2[20];
 };
 
 int hclge_cmd_init(struct hclge_dev *hdev);
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 20988aa..6916685 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -5991,9 +5991,7 @@ static void hclge_get_regs(struct hnae3_handle *handle, 
u32 *version,
"Get 64 bit register failed, ret = %d.\n", ret);
 }
 
-static int hclge_set_led_status_sfp(struct hclge_dev *hdev, u8 
speed_led_status,
-   u8 act_led_status, u8 link_led_status,
-   u8 locate_led_status)
+static int hclge_set_led_status(struct hclge_dev *hdev, u8 locate_led_status)
 {
struct hclge_set_led_state_cmd *req;
struct hclge_desc desc;
@@ -6002,12 +6000,6 @@ static int hclge_set_led_status_sfp(struct hclge_dev 
*hdev, u8 speed_led_status,
hclge_cmd_setup_basic_desc(&desc, HCLGE_OPC_LED_STATUS_CFG, false);
 
req = (struct hclge_set_led_state_cmd *)desc.data;
-   hnae_set_field(req->port_speed_led_config, HCLGE_LED_PORT_SPEED_STATE_M,
-  HCLGE_LED_PORT_SPEED_STATE_S, speed_led_status);
-   hnae_set_field(req->link_led_config, HCLGE_LED_ACTIVITY_STATE_M,
-  HCLGE_LED_ACTIVITY_STATE_S, act_led_status);
-   hnae_set_field(req->activity_led_config, HCLGE_LED_LINK_STATE_M,
-  HCLGE_LED_LINK_STATE_S, link_led_status);
hnae_set_field(req->locate_led_config, HCLGE_LED_LOCATE_STATE_M,
   HCLGE_LED_LOCATE_STATE_S, locate_led_status);
 
@@ -6028,36 +6020,17 @@ enum hclge_led_status {
 static int hclge_set_led_id(struct hnae3_handle *handle,
enum ethtool_phys_id_state status)
 {
-#define BLINK_FREQUENCY2
struct hclge_vport *vport = hclge_get_vport(handle);
struct hclge_dev *hdev = vport->back;
-   struct phy_device *phydev = hdev->hw.mac.phydev;
-   int ret = 0;
-
-   if (phydev || hdev->hw.mac.media_type != HNAE3_MEDIA_TYPE_FIBER)
-   return -EOPNOTSUPP;
 
switch (status) {
case ETHTOOL_ID_ACTIVE:
-   ret = hclge_set_led_status_sfp(hdev,
-  HCLGE_LED_NO_CHANGE,
-  HCLGE_LED_NO_CHANGE,
-  HCLGE_LED_NO_CHANGE,
-  HCLGE_LED_ON);
-   break;
+   return hclge_set_led_status(hdev, HCLGE_LED_ON);
case ETHTOOL_ID_INACTIVE:
-   ret = hclge_set_led_status_sfp(hdev,
-  HCLGE_LED_NO_CHANGE,
-  HCLGE_LED_NO_CHANGE,
-  HCLGE_LED_NO_CHANGE,
-  HCLGE_LED_OFF);
-   break;
+   return hclge_set_led_status(hdev, HCLGE_LED_OFF);
default:
-   ret = -EINVAL;
-   break;
+   return -EINVAL;
}
-
-   return ret;
 }
 
 static void hclge_get_link_mode(struct hnae3_handle *handle,
-- 
2.7.4




[PATCH net-next 12/12] net: hns3: Fixes initalization of RoCE handle and makes it conditional

2018-05-25 Thread Salil Mehta
From: Lijun Ou 

When register a RoCE client with hnae3vf device, it needs to judge
the device whether support RoCE vf function. Otherwise, it will
lead to calltrace when RoCE is not support vf function and remove
roce device.

The calltrace as follows:
[   93.156614] Unable to handle kernel NULL pointer dereference at virtual 
address 0015
 
[   93.278784] Call trace:
[   93.278788]  hnae3_match_n_instantiate+0x24/0xd8 [hnae3]
[   93.278790]  hnae3_register_client+0xcc/0x150 [hnae3]
[   93.278801]  hns_roce_hw_v2_init+0x18/0x1000 [hns_roce_hw_v2]
[   93.278805]  do_one_initcall+0x58/0x160
[   93.278807]  do_init_module+0x64/0x1d8
[   93.278809]  load_module+0x135c/0x15c8
[   93.278811]  SyS_finit_module+0x100/0x118
[   93.278816]  __sys_trace_return+0x0/0x4
[   93.278827] Code: aa0003f5 12001c56 aa1e03e0 d503201f (b9402660)

Fixes: e2cb1dec9779 ("net: hns3: Add HNS3 VF HCL(Hardware Compatibility Layer) 
Support")
Reported-by: Xinwei Kong 
Reported-by: Zhou Wang 
Signed-off-by: Lijun Ou 
Signed-off-by: Zhou Wang 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index 2b0e329..266cdcb 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -1500,10 +1500,12 @@ static int hclgevf_init_instance(struct hclgevf_dev 
*hdev,
return ret;
break;
case HNAE3_CLIENT_ROCE:
-   hdev->roce_client = client;
-   hdev->roce.client = client;
+   if (hnae3_dev_roce_supported(hdev)) {
+   hdev->roce_client = client;
+   hdev->roce.client = client;
+   }
 
-   if (hdev->roce_client && hnae3_dev_roce_supported(hdev)) {
+   if (hdev->roce_client && hdev->nic_client) {
ret = hclgevf_init_roce_base_info(hdev);
if (ret)
return ret;
-- 
2.7.4




[PATCH net-next 04/12] net: hns3: Add support to enable TX/RX promisc mode for H/W rev(0x21)

2018-05-25 Thread Salil Mehta
From: Peng Li 

HCLGE_PROMISC_TX_EN_B and HCLGE_PROMISC_RX_EN_B are not supported
on pdev revision(0x20), new revision(0x21) supports them.

Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h  | 2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 9 -
 2 files changed, 10 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 3fa08f7..e9be6aa 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.h
@@ -484,6 +484,8 @@ struct hclge_promisc_param {
u8 enable;
 };
 
+#define HCLGE_PROMISC_TX_EN_B  BIT(4)
+#define HCLGE_PROMISC_RX_EN_B  BIT(5)
 #define HCLGE_PROMISC_EN_B 1
 #define HCLGE_PROMISC_EN_ALL   0x7
 #define HCLGE_PROMISC_EN_UC0x1
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index c0b8d5a..8ad8f62 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3586,7 +3586,14 @@ int hclge_cmd_set_promisc_mode(struct hclge_dev *hdev,
 
req = (struct hclge_promisc_cfg_cmd *)desc.data;
req->vf_id = param->vf_id;
-   req->flag = (param->enable << HCLGE_PROMISC_EN_B);
+
+   /* HCLGE_PROMISC_TX_EN_B and HCLGE_PROMISC_RX_EN_B are not supported on
+* pdev revision(0x20), new revision support them. The
+* value of this two fields will not return error when driver
+* send command to fireware in revision(0x20).
+*/
+   req->flag = (param->enable << HCLGE_PROMISC_EN_B) |
+   HCLGE_PROMISC_TX_EN_B | HCLGE_PROMISC_RX_EN_B;
 
ret = hclge_cmd_send(&hdev->hw, &desc, 1);
if (ret) {
-- 
2.7.4




[PATCH net-next 3/9] net: hns3: cleanup of return values in hclge_init_client_instance()

2018-05-19 Thread Salil Mehta
From: Jian Shen 

Removes the goto and directly returns in case of errors as part of the
cleanup.

Signed-off-by: Jian Shen 
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 46435c8..46e030c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -5297,7 +5297,7 @@ static int hclge_init_client_instance(struct hnae3_client 
*client,
vport->nic.client = client;
ret = client->ops->init_instance(&vport->nic);
if (ret)
-   goto err;
+   return ret;
 
if (hdev->roce_client &&
hnae3_dev_roce_supported(hdev)) {
@@ -5305,11 +5305,11 @@ static int hclge_init_client_instance(struct 
hnae3_client *client,
 
ret = hclge_init_roce_base_info(vport);
if (ret)
-   goto err;
+   return ret;
 
ret = rc->ops->init_instance(&vport->roce);
if (ret)
-   goto err;
+   return ret;
}
 
break;
@@ -5319,7 +5319,7 @@ static int hclge_init_client_instance(struct hnae3_client 
*client,
 
ret = client->ops->init_instance(&vport->nic);
if (ret)
-   goto err;
+   return ret;
 
break;
case HNAE3_CLIENT_ROCE:
@@ -5331,18 +5331,16 @@ static int hclge_init_client_instance(struct 
hnae3_client *client,
if (hdev->roce_client && hdev->nic_client) {
ret = hclge_init_roce_base_info(vport);
if (ret)
-   goto err;
+   return ret;
 
ret = client->ops->init_instance(&vport->roce);
if (ret)
-   goto err;
+   return ret;
}
}
}
 
return 0;
-err:
-   return ret;
 }
 
 static void hclge_uninit_client_instance(struct hnae3_client *client,
-- 
2.7.4




[PATCH net-next 1/9] net: hns3: Fixes error reported by Kbuild and internal review

2018-05-19 Thread Salil Mehta
This patch fixes the error reported by Intel's kbuild and fixes a
return value in one of the legs, caught during review of the original
patch sent by kbuild.

Fixes: fdb793670a00 ("net: hns3: Add support of .sriov_configure in HNS3 
driver")
Signed-off-by: Fengguang Wu 
Signed-off-by: Salil Mehta 
---
Patch V1:
1. Fixes the errors reported by kbuild - using its fix
Link: https://lkml.org/lkml/2018/5/16/894
2. Places a necessary missed return value of num_vfs figured out
   while reviewing kbuild patch.
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index e85ff38..e75c652 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1579,7 +1579,7 @@ static void hns3_remove(struct pci_dev *pdev)
  * Enable or change the number of VFs. Called when the user updates the number
  * of VFs in sysfs.
  **/
-int hns3_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
+static int hns3_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
 {
int ret;
 
@@ -1592,6 +1592,8 @@ int hns3_pci_sriov_configure(struct pci_dev *pdev, int 
num_vfs)
ret = pci_enable_sriov(pdev, num_vfs);
if (ret)
dev_err(&pdev->dev, "SRIOV enable failed %d\n", ret);
+   else
+   return num_vfs;
} else if (!pci_vfs_assigned(pdev)) {
pci_disable_sriov(pdev);
} else {
-- 
2.7.4




[PATCH net-next 0/9] Misc. bug fixes and cleanup for HNS3 driver

2018-05-19 Thread Salil Mehta
This patch-set presents miscellaneous bug fixes and cleanups found during
internal review, system testing and cleanup.

Fuyun Liang (1):
  net: hns3: Fix for netdev not running problem after calling net_stop
and net_open

Huazhong Tan (1):
  net: hns3: Use enums instead of magic number in
hclge_is_special_opcode

Jian Shen (1):
  net: hns3: cleanup of return values in hclge_init_client_instance()

Peng Li (1):
  net: hns3: Fixes API to fetch ethernet header length with kernel
default

Salil Mehta (1):
  net: hns3: Fixes error reported by Kbuild and internal review

Xi Wang (3):
  net: hns3: Fix the missing client list node initialization
  net: hns3: Fix for hns3 module is loaded multiple times problem
  net: hns3: Fixes kernel panic issue during rmmod hns3 driver

Yunsheng Lin (1):
  net: hns3: Fix for CMDQ and Misc. interrupt init order problem

 drivers/net/ethernet/hisilicon/hns3/hnae3.c|   1 +
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|   2 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 111 ++---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h|   2 +
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c |  10 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c|  17 ++--
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.h|   2 +-
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  |  16 +--
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h  |   2 +-
 9 files changed, 39 insertions(+), 124 deletions(-)

-- 
2.7.4




[PATCH net-next 4/9] net: hns3: Fix the missing client list node initialization

2018-05-19 Thread Salil Mehta
From: Xi Wang 

This patch fixes the missing initialization of the client list node
in the hnae3_register_client() function.

Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 
SoC")
Signed-off-by: Xi Wang 
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 66cbb66..701ae5e 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -3509,6 +3509,8 @@ static int __init hns3_init_module(void)
 
client.ops = &client_ops;
 
+   INIT_LIST_HEAD(&client.node);
+
ret = hnae3_register_client(&client);
if (ret)
return ret;
-- 
2.7.4




[PATCH net-next 2/9] net: hns3: Fixes API to fetch ethernet header length with kernel default

2018-05-19 Thread Salil Mehta
From: Peng Li 

During the RX leg driver needs to fetch the ethernet header
length from the RX'ed Buffer Descriptor. Currently, proprietary
version hns3_nic_get_headlen is being used to fetch the header
length which uses l234info present in the Buffer Descriptor
which might not be valid for the first Buffer Descriptor if the
packet is spanning across multiple descriptors.
Kernel default eth_get_headlen API does the job correctly.

Fixes: 76ad4f0ee747 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 
SoC")
Signed-off-by: Peng Li 
Reviewed-by: Yisen Zhuang 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 104 +---
 1 file changed, 2 insertions(+), 102 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index e75c652..66cbb66 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1954,106 +1954,6 @@ hns3_nic_alloc_rx_buffers(struct hns3_enet_ring *ring, 
int cleand_count)
writel_relaxed(i, ring->tqp->io_base + HNS3_RING_RX_RING_HEAD_REG);
 }
 
-/* hns3_nic_get_headlen - determine size of header for LRO/GRO
- * @data: pointer to the start of the headers
- * @max: total length of section to find headers in
- *
- * This function is meant to determine the length of headers that will
- * be recognized by hardware for LRO, GRO, and RSC offloads.  The main
- * motivation of doing this is to only perform one pull for IPv4 TCP
- * packets so that we can do basic things like calculating the gso_size
- * based on the average data per packet.
- */
-static unsigned int hns3_nic_get_headlen(unsigned char *data, u32 flag,
-unsigned int max_size)
-{
-   unsigned char *network;
-   u8 hlen;
-
-   /* This should never happen, but better safe than sorry */
-   if (max_size < ETH_HLEN)
-   return max_size;
-
-   /* Initialize network frame pointer */
-   network = data;
-
-   /* Set first protocol and move network header forward */
-   network += ETH_HLEN;
-
-   /* Handle any vlan tag if present */
-   if (hnae_get_field(flag, HNS3_RXD_VLAN_M, HNS3_RXD_VLAN_S)
-   == HNS3_RX_FLAG_VLAN_PRESENT) {
-   if ((typeof(max_size))(network - data) > (max_size - VLAN_HLEN))
-   return max_size;
-
-   network += VLAN_HLEN;
-   }
-
-   /* Handle L3 protocols */
-   if (hnae_get_field(flag, HNS3_RXD_L3ID_M, HNS3_RXD_L3ID_S)
-   == HNS3_RX_FLAG_L3ID_IPV4) {
-   if ((typeof(max_size))(network - data) >
-   (max_size - sizeof(struct iphdr)))
-   return max_size;
-
-   /* Access ihl as a u8 to avoid unaligned access on ia64 */
-   hlen = (network[0] & 0x0F) << 2;
-
-   /* Verify hlen meets minimum size requirements */
-   if (hlen < sizeof(struct iphdr))
-   return network - data;
-
-   /* Record next protocol if header is present */
-   } else if (hnae_get_field(flag, HNS3_RXD_L3ID_M, HNS3_RXD_L3ID_S)
-   == HNS3_RX_FLAG_L3ID_IPV6) {
-   if ((typeof(max_size))(network - data) >
-   (max_size - sizeof(struct ipv6hdr)))
-   return max_size;
-
-   /* Record next protocol */
-   hlen = sizeof(struct ipv6hdr);
-   } else {
-   return network - data;
-   }
-
-   /* Relocate pointer to start of L4 header */
-   network += hlen;
-
-   /* Finally sort out TCP/UDP */
-   if (hnae_get_field(flag, HNS3_RXD_L4ID_M, HNS3_RXD_L4ID_S)
-   == HNS3_RX_FLAG_L4ID_TCP) {
-   if ((typeof(max_size))(network - data) >
-   (max_size - sizeof(struct tcphdr)))
-   return max_size;
-
-   /* Access doff as a u8 to avoid unaligned access on ia64 */
-   hlen = (network[12] & 0xF0) >> 2;
-
-   /* Verify hlen meets minimum size requirements */
-   if (hlen < sizeof(struct tcphdr))
-   return network - data;
-
-   network += hlen;
-   } else if (hnae_get_field(flag, HNS3_RXD_L4ID_M, HNS3_RXD_L4ID_S)
-   == HNS3_RX_FLAG_L4ID_UDP) {
-   if ((typeof(max_size))(network - data) >
-   (max_size - sizeof(struct udphdr)))
-   return max_size;
-
-   network += sizeof(struct udphdr);
-   }
-
-   /* If everything has gone correctly network should be the
-* data section of the packet and will be the end of the header.
-* If not then it probably represents the end of the last recognized
-* header.
-*/
-   if ((typeof(max_size))(network - data

[PATCH net-next 9/9] net: hns3: Fix for CMDQ and Misc. interrupt init order problem

2018-05-19 Thread Salil Mehta
From: Yunsheng Lin 

When vf module is loading, the cmd queue initialization should
happen before misc interrupt initialization, otherwise the misc
interrupt handle will cause using uninitialized cmd queue problem.
There is also the same issue when vf module is unloading.

This patch fixes it by adjusting the location of some function.

Fixes: e2cb1dec9779 ("net: hns3: Add HNS3 VF HCL(Hardware Compatibility Layer) 
Support")
Signed-off-by: Yunsheng Lin 
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 .../net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c| 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index f1f4a17..2b0e329 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -1634,6 +1634,10 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev)
 
hclgevf_state_init(hdev);
 
+   ret = hclgevf_cmd_init(hdev);
+   if (ret)
+   goto err_cmd_init;
+
ret = hclgevf_misc_irq_init(hdev);
if (ret) {
dev_err(&pdev->dev, "failed(%d) to init Misc IRQ(vector0)\n",
@@ -1641,10 +1645,6 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev)
goto err_misc_irq_init;
}
 
-   ret = hclgevf_cmd_init(hdev);
-   if (ret)
-   goto err_cmd_init;
-
ret = hclgevf_configure(hdev);
if (ret) {
dev_err(&pdev->dev, "failed(%d) to fetch configuration\n", ret);
@@ -1692,10 +1692,10 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev)
return 0;
 
 err_config:
-   hclgevf_cmd_uninit(hdev);
-err_cmd_init:
hclgevf_misc_irq_uninit(hdev);
 err_misc_irq_init:
+   hclgevf_cmd_uninit(hdev);
+err_cmd_init:
hclgevf_state_uninit(hdev);
hclgevf_uninit_msi(hdev);
 err_irq_init:
@@ -1705,9 +1705,9 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev)
 
 static void hclgevf_uninit_hdev(struct hclgevf_dev *hdev)
 {
-   hclgevf_cmd_uninit(hdev);
-   hclgevf_misc_irq_uninit(hdev);
hclgevf_state_uninit(hdev);
+   hclgevf_misc_irq_uninit(hdev);
+   hclgevf_cmd_uninit(hdev);
hclgevf_uninit_msi(hdev);
hclgevf_pci_uninit(hdev);
 }
-- 
2.7.4




[PATCH net-next 7/9] net: hns3: Fix for netdev not running problem after calling net_stop and net_open

2018-05-19 Thread Salil Mehta
From: Fuyun Liang 

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

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

Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support")
Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 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 46e030c..2f0bbb6 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -3793,6 +3793,9 @@ static void hclge_ae_stop(struct hnae3_handle *handle)
 
/* reset tqp stats */
hclge_reset_tqp_stats(handle);
+   del_timer_sync(&hdev->service_timer);
+   cancel_work_sync(&hdev->service_task);
+   hclge_update_link_status(hdev);
 }
 
 static int hclge_get_mac_vlan_cmd_status(struct hclge_vport *vport,
-- 
2.7.4




[PATCH net-next 8/9] net: hns3: Fixes kernel panic issue during rmmod hns3 driver

2018-05-19 Thread Salil Mehta
From: Xi Wang 

If CONFIG_ARM_SMMU_V3 is enabled, arm64's dma_ops will replace
arm64_swiotlb_dma_ops with iommu_dma_ops. When releasing contiguous
dma memory, the new ops will call the vunmap function which cannot
be run in interrupt context.

Currently, spin_lock_bh is called before vunmap is executed. This
disables BH and causes the interrupt context to be detected to
generate a kernel panic like below:

[ 2831.573400] kernel BUG at mm/vmalloc.c:1621!
[ 2831.577659] Internal error: Oops - BUG: 0 [#1] PREEMPT SMP
...
[ 2831.699907] Process rmmod (pid: 1893, stack limit = 0x55103ee2)
[ 2831.706507] Call trace:
[ 2831.708941]  vunmap+0x48/0x50
[ 2831.711897]  dma_common_free_remap+0x78/0x88
[ 2831.716155]  __iommu_free_attrs+0xa8/0x1c0
[ 2831.720255]  hclge_free_cmd_desc+0xc8/0x118 [hclge]
[ 2831.725128]  hclge_destroy_cmd_queue+0x34/0x68 [hclge]
[ 2831.730261]  hclge_uninit_ae_dev+0x90/0x100 [hclge]
[ 2831.735127]  hnae3_unregister_ae_dev+0xb0/0x868 [hnae3]
[ 2831.740345]  hns3_remove+0x3c/0x90 [hns3]
[ 2831.744344]  pci_device_remove+0x48/0x108
[ 2831.748342]  device_release_driver_internal+0x164/0x200
[ 2831.753553]  driver_detach+0x4c/0x88
[ 2831.757116]  bus_remove_driver+0x60/0xc0
[ 2831.761026]  driver_unregister+0x34/0x60
[ 2831.764935]  pci_unregister_driver+0x30/0xb0
[ 2831.769197]  hns3_exit_module+0x10/0x978 [hns3]
[ 2831.773715]  SyS_delete_module+0x1f8/0x248
[ 2831.99]  el0_svc_naked+0x30/0x34

This patch fixes it by using spin_lock instead of spin_lock_bh.

Fixes: 68c0a5c70614 ("net: hns3: Add HNS3 IMP(Integrated Mgmt Proc) Cmd 
Interface Support")
Signed-off-by: Xi Wang 
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
index 59fb0eb..c36d647 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
@@ -385,9 +385,9 @@ int hclge_cmd_init(struct hclge_dev *hdev)
 
 static void hclge_destroy_queue(struct hclge_cmq_ring *ring)
 {
-   spin_lock_bh(&ring->lock);
+   spin_lock(&ring->lock);
hclge_free_cmd_desc(ring);
-   spin_unlock_bh(&ring->lock);
+   spin_unlock(&ring->lock);
 }
 
 void hclge_destroy_cmd_queue(struct hclge_hw *hw)
-- 
2.7.4




[PATCH net-next 6/9] net: hns3: Use enums instead of magic number in hclge_is_special_opcode

2018-05-19 Thread Salil Mehta
From: Huazhong Tan 

This patch does bit of a clean-up by using already defined enums for
certain values in function hclge_is_special_opcode(). Below enums from
have been used as replacements for magic values:

enum hclge_opcode_type{

HCLGE_OPC_STATS_64_BIT  = 0x0030,
HCLGE_OPC_STATS_32_BIT  = 0x0031,
HCLGE_OPC_STATS_MAC = 0x0032,

};

Signed-off-by: Huazhong Tan 
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
index fab7068..59fb0eb 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
@@ -190,7 +190,11 @@ static int hclge_cmd_csq_done(struct hclge_hw *hw)
 
 static bool hclge_is_special_opcode(u16 opcode)
 {
-   u16 spec_opcode[3] = {0x0030, 0x0031, 0x0032};
+   /* these commands have several descriptors,
+* and use the first one to save opcode and return value
+*/
+   u16 spec_opcode[3] = {HCLGE_OPC_STATS_64_BIT,
+   HCLGE_OPC_STATS_32_BIT, HCLGE_OPC_STATS_MAC};
int i;
 
for (i = 0; i < ARRAY_SIZE(spec_opcode); i++) {
-- 
2.7.4




[PATCH net-next 5/9] net: hns3: Fix for hns3 module is loaded multiple times problem

2018-05-19 Thread Salil Mehta
From: Xi Wang 

If the hns3 driver has been built into kernel and then loaded with
the same driver which built as KLM, it may trigger an error like
below:

[   20.009555] hns3: Hisilicon Ethernet Network Driver for Hip08 Family - 
version
[   20.016789] hns3: Copyright (c) 2017 Huawei Corporation.
[   20.022100] Error: Driver 'hns3' is already registered, aborting...
[   23.517397] Unable to handle kernel NULL pointer dereference at virtual 
address 
...
[   23.691583] Process insmod (pid: 1982, stack limit = 0xcd5f21cb)
[   23.698270] Call trace:
[   23.700705]  __list_del_entry_valid+0x2c/0xd8
[   23.705049]  hnae3_unregister_client+0x68/0xa8
[   23.709487]  hns3_init_module+0x98/0x1000 [hns3]
[   23.714093]  do_one_initcall+0x5c/0x170
[   23.717918]  do_init_module+0x64/0x1f4
[   23.721654]  load_module+0x1d14/0x24b0
[   23.725390]  SyS_init_module+0x158/0x208
[   23.729300]  el0_svc_naked+0x30/0x34

This patch fixes it by adding module version info.

Fixes: 38caee9d3ee8 ("net: hns3: Add support of the HNAE3 framework")
Signed-off-by: Xi Wang 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.c   | 1 +
 drivers/net/ethernet/hisilicon/hns3/hnae3.h   | 2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c   | 1 +
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.h   | 2 ++
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h   | 2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h | 2 +-
 6 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.c 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
index bd3c232..63d7dbf 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
@@ -285,3 +285,4 @@ EXPORT_SYMBOL(hnae3_unregister_ae_dev);
 MODULE_AUTHOR("Huawei Tech. Co., Ltd.");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("HNAE3(Hisilicon Network Acceleration Engine) Framework");
+MODULE_VERSION(HNAE3_MOD_VERSION);
diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index 2f266ef..45c571e 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -36,6 +36,8 @@
 #include 
 #include 
 
+#define HNAE3_MOD_VERSION "1.0"
+
 /* Device IDs */
 #define HNAE3_DEV_ID_GE0xA220
 #define HNAE3_DEV_ID_25GE  0xA221
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 701ae5e..cac5195 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -3538,3 +3538,4 @@ MODULE_DESCRIPTION("HNS3: Hisilicon Ethernet Driver");
 MODULE_AUTHOR("Huawei Tech. Co., Ltd.");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("pci:hns-nic");
+MODULE_VERSION(HNS3_MOD_VERSION);
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
index 98cdbd3..5b40f5a 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.h
@@ -14,6 +14,8 @@
 
 #include "hnae3.h"
 
+#define HNS3_MOD_VERSION "1.0"
+
 extern const char hns3_driver_version[];
 
 enum hns3_nic_state {
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
index af736a4..93177d9 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.h
@@ -17,7 +17,7 @@
 #include "hclge_cmd.h"
 #include "hnae3.h"
 
-#define HCLGE_MOD_VERSION "v1.0"
+#define HCLGE_MOD_VERSION "1.0"
 #define HCLGE_DRIVER_NAME "hclge"
 
 #define HCLGE_INVALID_VPORT 0x
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h
index a477a7c..9763e74 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.h
@@ -9,7 +9,7 @@
 #include "hclgevf_cmd.h"
 #include "hnae3.h"
 
-#define HCLGEVF_MOD_VERSION "v1.0"
+#define HCLGEVF_MOD_VERSION "1.0"
 #define HCLGEVF_DRIVER_NAME "hclgevf"
 
 #define HCLGEVF_ROCEE_VECTOR_NUM   0
-- 
2.7.4




[PATCH net-next 01/10] net: hns3: Fix for deadlock problem occurring when unregistering ae_algo

2018-05-15 Thread Salil Mehta
From: Fuyun Liang 

When hnae3_unregister_ae_algo is called by PF, pci_disable_sriov is
called. And then, hns3_remove is called by VF. We get deadlocked in
this case.

Since VF pci device is dependent on PF pci device, When PF pci device
is removed, VF pci device must be removed. Also, To solve the deadlock
problem, VF pci device should be removed before PF pci device is removed.

This patch moves pci_enable/disable_sriov from hclge to hns3 to solve
the deadlock problem.

Also, we do not need to return EPROBE_DEFER in hnae3_register_ae_dev,
because SRIOV is no longer enabled in the context calling
hnae3_register_ae_dev. Mutex_trylock can be replaced with mutex_lock.

Fixes: 424eb834a9be ("net: hns3: Unified HNS3 {VF|PF} Ethernet Driver for hip08 
SoC")
Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.c| 12 +---
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 74 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 42 ++--
 3 files changed, 79 insertions(+), 49 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.c 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
index 02145f2..1686ceb 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
@@ -196,17 +196,9 @@ int hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev)
const struct pci_device_id *id;
struct hnae3_ae_algo *ae_algo;
struct hnae3_client *client;
-   int ret = 0, lock_acquired;
+   int ret = 0;
 
-   /* we can get deadlocked if SRIOV is being enabled in context to probe
-* and probe gets called again in same context. This can happen when
-* pci_enable_sriov() is called to create VFs from PF probes context.
-* Therefore, for simplicity uniformly defering further probing in all
-* cases where we detect contention.
-*/
-   lock_acquired = mutex_trylock(&hnae3_common_lock);
-   if (!lock_acquired)
-   return -EPROBE_DEFER;
+   mutex_lock(&hnae3_common_lock);
 
list_add_tail(&ae_dev->node, &hnae3_ae_dev_list);
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index 4031174..af9e90f 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1487,6 +1487,68 @@ static const struct net_device_ops hns3_nic_netdev_ops = 
{
.ndo_set_vf_vlan= hns3_ndo_set_vf_vlan,
 };
 
+static bool hns3_is_phys_func(struct pci_dev *pdev)
+{
+   u32 dev_id = pdev->device;
+
+   switch (dev_id) {
+   case HNAE3_DEV_ID_GE:
+   case HNAE3_DEV_ID_25GE:
+   case HNAE3_DEV_ID_25GE_RDMA:
+   case HNAE3_DEV_ID_25GE_RDMA_MACSEC:
+   case HNAE3_DEV_ID_50GE_RDMA:
+   case HNAE3_DEV_ID_50GE_RDMA_MACSEC:
+   case HNAE3_DEV_ID_100G_RDMA_MACSEC:
+   return true;
+   case HNAE3_DEV_ID_100G_VF:
+   case HNAE3_DEV_ID_100G_RDMA_DCB_PFC_VF:
+   return false;
+   default:
+   dev_warn(&pdev->dev, "un-recognized pci device-id %d",
+dev_id);
+   }
+
+   return false;
+}
+
+static int get_num_req_vfs(struct pci_dev *pdev)
+{
+   /* a variable vf num will be supported later */
+   return pci_sriov_get_totalvfs(pdev);
+}
+
+static void hns3_enable_sriov(struct pci_dev *pdev)
+{
+   int num_req_vfs = get_num_req_vfs(pdev);
+   int ret;
+
+   /* Enable SRIOV */
+   if (!num_req_vfs)
+   return;
+
+   dev_info(&pdev->dev, "active VFs(%d) found, enabling SRIOV\n",
+num_req_vfs);
+
+   ret = pci_enable_sriov(pdev, num_req_vfs);
+   if (ret)
+   dev_err(&pdev->dev, "SRIOV enable failed %d\n", ret);
+}
+
+static void hns3_disable_sriov(struct pci_dev *pdev)
+{
+   /* If our VFs are assigned we cannot shut down SR-IOV
+* without causing issues, so just leave the hardware
+* available but disabled
+*/
+   if (pci_vfs_assigned(pdev)) {
+   dev_warn(&pdev->dev,
+"disabling driver while VFs are assigned\n");
+   return;
+   }
+
+   pci_disable_sriov(pdev);
+}
+
 /* hns3_probe - Device initialization routine
  * @pdev: PCI device information struct
  * @ent: entry in hns3_pci_tbl
@@ -1514,7 +1576,14 @@ static int hns3_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
ae_dev->dev_type = HNAE3_DEV_KNIC;
pci_set_drvdata(pdev, ae_dev);
 
-   return hnae3_register_ae_dev(ae_dev);
+   ret = hnae3_register_ae_dev(ae_dev);
+   if (ret)
+   return ret;
+
+   if (hns3_is_phys_func(pdev) && IS_ENABLED(CONFIG_PCI_IOV))
+   hns3_enable_sriov(pdev);

[PATCH net-next 02/10] net: hns3: Fix for the null pointer problem occurring when initializing ae_dev failed

2018-05-15 Thread Salil Mehta
From: Fuyun Liang 

When initializing ae_dev failed during loading hclge.ko, the drvdata will
be set to null. When removing hns3.ko, we get a null ae_dev. It causes the
null pointer problem.

This patch removes pci_set_drvdata from error handle of hclge_init_ae_dev
to fix the bug, since pci_set_drvdata has been called in hns3_remove.
Also, we do not need to uninit the ae_dev which is not initialized. And
it may be the one which is initialized failed.

Fixes: 46a3df9f9718 ("net: hns3: Add HNS3 Acceleration Engine & Compatibility 
Layer Support")
Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.c   | 6 ++
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c   | 5 +
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 6 ++
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.c 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
index 1686ceb..ab2e72c 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
@@ -168,6 +168,9 @@ void hnae3_unregister_ae_algo(struct hnae3_ae_algo *ae_algo)
mutex_lock(&hnae3_common_lock);
/* Check if there are matched ae_dev */
list_for_each_entry(ae_dev, &hnae3_ae_dev_list, node) {
+   if (!hnae_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B))
+   continue;
+
id = pci_match_id(ae_algo->pdev_id_table, ae_dev->pdev);
if (!id)
continue;
@@ -256,6 +259,9 @@ void hnae3_unregister_ae_dev(struct hnae3_ae_dev *ae_dev)
mutex_lock(&hnae3_common_lock);
/* Check if there are matched ae_algo */
list_for_each_entry(ae_algo, &hnae3_ae_algo_list, node) {
+   if (!hnae_get_bit(ae_dev->flag, HNAE3_DEV_INITED_B))
+   continue;
+
id = pci_match_id(ae_algo->pdev_id_table, ae_dev->pdev);
if (!id)
continue;
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index 343197a..c2501b1 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -5379,7 +5379,7 @@ static int hclge_pci_init(struct hclge_dev *hdev)
ret = pci_enable_device(pdev);
if (ret) {
dev_err(&pdev->dev, "failed to enable PCI device\n");
-   goto err_no_drvdata;
+   return ret;
}
 
ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
@@ -5417,8 +5417,6 @@ static int hclge_pci_init(struct hclge_dev *hdev)
pci_release_regions(pdev);
 err_disable_device:
pci_disable_device(pdev);
-err_no_drvdata:
-   pci_set_drvdata(pdev, NULL);
 
return ret;
 }
@@ -5594,7 +5592,6 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
pci_clear_master(pdev);
pci_release_regions(pdev);
pci_disable_device(pdev);
-   pci_set_drvdata(pdev, NULL);
 out:
return ret;
 }
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index 2dbffce..b7578c6 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -1563,7 +1563,7 @@ static int hclgevf_pci_init(struct hclgevf_dev *hdev)
ret = pci_enable_device(pdev);
if (ret) {
dev_err(&pdev->dev, "failed to enable PCI device\n");
-   goto err_no_drvdata;
+   return ret;
}
 
ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
@@ -1595,8 +1595,7 @@ static int hclgevf_pci_init(struct hclgevf_dev *hdev)
pci_release_regions(pdev);
 err_disable_device:
pci_disable_device(pdev);
-err_no_drvdata:
-   pci_set_drvdata(pdev, NULL);
+
return ret;
 }
 
@@ -1608,7 +1607,6 @@ static void hclgevf_pci_uninit(struct hclgevf_dev *hdev)
pci_clear_master(pdev);
pci_release_regions(pdev);
pci_disable_device(pdev);
-   pci_set_drvdata(pdev, NULL);
 }
 
 static int hclgevf_init_hdev(struct hclgevf_dev *hdev)
-- 
2.7.4




[PATCH net-next 00/10] Misc. Bug Fixes and clean-ups for HNS3 Driver

2018-05-15 Thread Salil Mehta
This patch-set mainly introduces various bug fixes, cleanups and one
very small enhancement to existing HN3 driver code.

Fuyun Liang (7):
  net: hns3: Fix for deadlock problem occurring when unregistering
ae_algo
  net: hns3: Fix for the null pointer problem occurring when
initializing ae_dev failed
  net: hns3: Add a check for client instance init state
  net: hns3: Change return type of hnae3_register_ae_dev
  net: hns3: Change return type of hnae3_register_ae_algo
  net: hns3: Change return value in hnae3_register_client
  net: hns3: Fixes the missing PCI iounmap for various legs

Peng Li (1):
  net: hns3: Add support of .sriov_configure in HNS3 driver

Yunsheng Lin (2):
  net: hns3: Fixes the back pressure setting When sriov is enabled
  net: hns3: Fix for fiber link up problem

 drivers/net/ethernet/hisilicon/hns3/hnae3.c| 44 ++--
 drivers/net/ethernet/hisilicon/hns3/hnae3.h|  5 +-
 drivers/net/ethernet/hisilicon/hns3/hns3_enet.c| 78 +-
 .../ethernet/hisilicon/hns3/hns3pf/hclge_main.c| 55 +++
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c  | 45 +++--
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.h  |  5 ++
 .../ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c  | 10 +--
 7 files changed, 164 insertions(+), 78 deletions(-)

-- 
2.7.4




[PATCH net-next 04/10] net: hns3: Change return type of hnae3_register_ae_dev

2018-05-15 Thread Salil Mehta
From: Fuyun Liang 

If hclge.ko has not been inserted, the value of ret always is zero
in hnae3_register_ae_dev. If hclge.ko has been inserted, the value
of ret is zero or non zero. Different execution ways have different
results. It is confusing.

The ae_dev which is initialized failed can be reinitialized when we
remove hclge.ko and insert it again. For the case initializing client
instance, it is just like the case initializing ae_dev. The main function
of hnae3_register_ae_dev is adding the ae_dev to ad_dev list. Because
adding ae_dev is always ok, we does not need to return any in this
function.

This patch changes the return type of hnae3_register_ae_dev from int
to void.

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

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.c 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
index 21cb0c5..cb93295 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
@@ -203,7 +203,7 @@ EXPORT_SYMBOL(hnae3_unregister_ae_algo);
  * @ae_dev: the AE device
  * NOTE: the duplicated name will not be checked
  */
-int hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev)
+void hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev)
 {
const struct pci_device_id *id;
struct hnae3_ae_algo *ae_algo;
@@ -224,7 +224,6 @@ int hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev)
 
if (!ae_dev->ops) {
dev_err(&ae_dev->pdev->dev, "ae_dev ops are null\n");
-   ret = -EOPNOTSUPP;
goto out_err;
}
 
@@ -251,8 +250,6 @@ int hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev)
 
 out_err:
mutex_unlock(&hnae3_common_lock);
-
-   return ret;
 }
 EXPORT_SYMBOL(hnae3_register_ae_dev);
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index ffec231..ea6e6ea 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -515,7 +515,7 @@ struct hnae3_handle {
 #define hnae_get_bit(origin, shift) \
hnae_get_field((origin), (0x1 << (shift)), (shift))
 
-int hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev);
+void hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev);
 void hnae3_unregister_ae_dev(struct hnae3_ae_dev *ae_dev);
 
 void hnae3_unregister_ae_algo(struct hnae3_ae_algo *ae_algo);
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
index af9e90f..ac75b5d 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
@@ -1576,9 +1576,7 @@ static int hns3_probe(struct pci_dev *pdev, const struct 
pci_device_id *ent)
ae_dev->dev_type = HNAE3_DEV_KNIC;
pci_set_drvdata(pdev, ae_dev);
 
-   ret = hnae3_register_ae_dev(ae_dev);
-   if (ret)
-   return ret;
+   hnae3_register_ae_dev(ae_dev);
 
if (hns3_is_phys_func(pdev) && IS_ENABLED(CONFIG_PCI_IOV))
hns3_enable_sriov(pdev);
-- 
2.7.4




[PATCH net-next 03/10] net: hns3: Add a check for client instance init state

2018-05-15 Thread Salil Mehta
From: Fuyun Liang 

If the client instance is initializd failed, we do not need to uninit it.
This patch adds a state check to check init state of client instance.

Fixes: 38caee9d3ee8 ("net: hns3: Add support of the HNAE3 framework")
Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.c | 15 ---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h |  1 +
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.c 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
index ab2e72c..21cb0c5 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
@@ -50,13 +50,22 @@ static int hnae3_match_n_instantiate(struct hnae3_client 
*client,
/* now, (un-)instantiate client by calling lower layer */
if (is_reg) {
ret = ae_dev->ops->init_client_instance(client, ae_dev);
-   if (ret)
+   if (ret) {
dev_err(&ae_dev->pdev->dev,
"fail to instantiate client\n");
-   return ret;
+   return ret;
+   }
+
+   hnae_set_bit(ae_dev->flag, HNAE3_CLIENT_INITED_B, 1);
+   return 0;
+   }
+
+   if (hnae_get_bit(ae_dev->flag, HNAE3_CLIENT_INITED_B)) {
+   ae_dev->ops->uninit_client_instance(client, ae_dev);
+
+   hnae_set_bit(ae_dev->flag, HNAE3_CLIENT_INITED_B, 0);
}
 
-   ae_dev->ops->uninit_client_instance(client, ae_dev);
return 0;
 }
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index 804ea83..ffec231 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -52,6 +52,7 @@
 #define HNAE3_DEV_INITED_B 0x0
 #define HNAE3_DEV_SUPPORT_ROCE_B   0x1
 #define HNAE3_DEV_SUPPORT_DCB_B0x2
+#define HNAE3_CLIENT_INITED_B  0x3
 
 #define HNAE3_DEV_SUPPORT_ROCE_DCB_BITS (BIT(HNAE3_DEV_SUPPORT_DCB_B) |\
BIT(HNAE3_DEV_SUPPORT_ROCE_B))
-- 
2.7.4




[PATCH net-next 05/10] net: hns3: Change return type of hnae3_register_ae_algo

2018-05-15 Thread Salil Mehta
From: Fuyun Liang 

The ae_algo is used by many ae_devs. It is not only belong to just a
ae_dev. Initializing ae_dev failed does not represent registering ae_algo
failed. Because the action of registering ae_algo just is adding ae_algo
to the ae_algo list and it is always is true, it make no sense to define
return type as int.

This patch changes the return type of hnae3_register_ae_algo from int to
void.

Signed-off-by: Fuyun Liang 
Signed-off-by: Peng Li 
Signed-off-by: Salil Mehta 
---
 drivers/net/ethernet/hisilicon/hns3/hnae3.c   | 4 +---
 drivers/net/ethernet/hisilicon/hns3/hnae3.h   | 2 +-
 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c   | 4 +++-
 drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 4 +++-
 4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.c 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
index cb93295..3b1c396 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.c
@@ -121,7 +121,7 @@ EXPORT_SYMBOL(hnae3_unregister_client);
  * @ae_algo: AE algorithm
  * NOTE: the duplicated name will not be checked
  */
-int hnae3_register_ae_algo(struct hnae3_ae_algo *ae_algo)
+void hnae3_register_ae_algo(struct hnae3_ae_algo *ae_algo)
 {
const struct pci_device_id *id;
struct hnae3_ae_dev *ae_dev;
@@ -160,8 +160,6 @@ int hnae3_register_ae_algo(struct hnae3_ae_algo *ae_algo)
}
 
mutex_unlock(&hnae3_common_lock);
-
-   return ret;
 }
 EXPORT_SYMBOL(hnae3_register_ae_algo);
 
diff --git a/drivers/net/ethernet/hisilicon/hns3/hnae3.h 
b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
index ea6e6ea..2f266ef 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hnae3.h
+++ b/drivers/net/ethernet/hisilicon/hns3/hnae3.h
@@ -519,7 +519,7 @@ void hnae3_register_ae_dev(struct hnae3_ae_dev *ae_dev);
 void hnae3_unregister_ae_dev(struct hnae3_ae_dev *ae_dev);
 
 void hnae3_unregister_ae_algo(struct hnae3_ae_algo *ae_algo);
-int hnae3_register_ae_algo(struct hnae3_ae_algo *ae_algo);
+void hnae3_register_ae_algo(struct hnae3_ae_algo *ae_algo);
 
 void hnae3_unregister_client(struct hnae3_client *client);
 int hnae3_register_client(struct hnae3_client *client);
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
index c2501b1..d060903 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
@@ -6250,7 +6250,9 @@ static int hclge_init(void)
 {
pr_info("%s is initializing\n", HCLGE_NAME);
 
-   return hnae3_register_ae_algo(&ae_algo);
+   hnae3_register_ae_algo(&ae_algo);
+
+   return 0;
 }
 
 static void hclge_exit(void)
diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c 
b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
index b7578c6..f1f4a17 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
@@ -1852,7 +1852,9 @@ static int hclgevf_init(void)
 {
pr_info("%s is initializing\n", HCLGEVF_NAME);
 
-   return hnae3_register_ae_algo(&ae_algovf);
+   hnae3_register_ae_algo(&ae_algovf);
+
+   return 0;
 }
 
 static void hclgevf_exit(void)
-- 
2.7.4




  1   2   3   4   5   6   >