[dpdk-dev] lib/librte_ether: error handling on MAC address replay
diff mbox

Message ID 20170119184721.22348-1-jonshin@cisco.com
State Superseded, archived
Headers show

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel compilation success Compilation OK

Commit Message

Steve Shin Jan. 19, 2017, 6:47 p.m. UTC
This patch fixes a bug in replaying MAC address to the hardware
in rte_eth_dev_config_restore() routine.

Signed-off-by: Steve Shin <jonshin@cisco.com>
---
 lib/librte_ether/rte_ethdev.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Steve Shin Jan. 19, 2017, 7:35 p.m. UTC | #1
Dear maintainer, 

Sorry that I forgot to add “Fixes:” line as follows:

       Fixes: 4bdefaade6d1 ("ethdev: VMDQ enhancements")

Can you please add the above line as part of comment?

Thanks,
Steve

On 1/19/17, 10:47 AM, "Steve Shin (jonshin)" <jonshin@cisco.com> wrote:

    This patch fixes a bug in replaying MAC address to the hardware
    in rte_eth_dev_config_restore() routine.
    
    Signed-off-by: Steve Shin <jonshin@cisco.com>

    ---
     lib/librte_ether/rte_ethdev.c | 10 ++++++----
     1 file changed, 6 insertions(+), 4 deletions(-)
    
    diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
    index 4790faf..7e01f10 100644
    --- a/lib/librte_ether/rte_ethdev.c
    +++ b/lib/librte_ether/rte_ethdev.c
    @@ -951,10 +951,12 @@ rte_eth_dev_config_restore(uint8_t port_id)
     			continue;
     
     		/* add address to the hardware */
    -		if  (*dev->dev_ops->mac_addr_add &&
    -			(dev->data->mac_pool_sel[i] & (1ULL << pool)))
    -			(*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
    -		else {
    +		if  (*dev->dev_ops->mac_addr_add) {
    +			if (dev->data->mac_pool_sel[i] & (1ULL << pool))
    +				(*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
    +			else
    +				continue;
    +		} else {
     			RTE_PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
     					port_id);
     			/* exit the loop but not return an error */
    -- 
    2.9.3
Igor Ryzhov Jan. 19, 2017, 10:39 p.m. UTC | #2
Hello Steve,

Thank you for the patch.

I think a couple of improvements can be done:
1. Function existence check – if (*dev->dev_ops->mac_addr_add) – can be
taken out of the loop. We don't need to check it on each iteration.
2. I'm not completely sure, but I think loop can be started from 1, not
from 0, because mac_pool_sel[0] is always zero. Am I right?

Best regards,
Igor

On Thu, Jan 19, 2017 at 10:35 PM, Steve Shin (jonshin) <jonshin@cisco.com>
wrote:

> Dear maintainer,
>
> Sorry that I forgot to add “Fixes:” line as follows:
>
>        Fixes: 4bdefaade6d1 ("ethdev: VMDQ enhancements")
>
> Can you please add the above line as part of comment?
>
> Thanks,
> Steve
>
> On 1/19/17, 10:47 AM, "Steve Shin (jonshin)" <jonshin@cisco.com> wrote:
>
>     This patch fixes a bug in replaying MAC address to the hardware
>     in rte_eth_dev_config_restore() routine.
>
>     Signed-off-by: Steve Shin <jonshin@cisco.com>
>     ---
>      lib/librte_ether/rte_ethdev.c | 10 ++++++----
>      1 file changed, 6 insertions(+), 4 deletions(-)
>
>     diff --git a/lib/librte_ether/rte_ethdev.c
> b/lib/librte_ether/rte_ethdev.c
>     index 4790faf..7e01f10 100644
>     --- a/lib/librte_ether/rte_ethdev.c
>     +++ b/lib/librte_ether/rte_ethdev.c
>     @@ -951,10 +951,12 @@ rte_eth_dev_config_restore(uint8_t port_id)
>                         continue;
>
>                 /* add address to the hardware */
>     -           if  (*dev->dev_ops->mac_addr_add &&
>     -                   (dev->data->mac_pool_sel[i] & (1ULL << pool)))
>     -                   (*dev->dev_ops->mac_addr_add)(dev, &addr, i,
> pool);
>     -           else {
>     +           if  (*dev->dev_ops->mac_addr_add) {
>     +                   if (dev->data->mac_pool_sel[i] & (1ULL << pool))
>     +                           (*dev->dev_ops->mac_addr_add)(dev, &addr,
> i, pool);
>     +                   else
>     +                           continue;
>     +           } else {
>                         RTE_PMD_DEBUG_TRACE("port %d: MAC address array
> not supported\n",
>                                         port_id);
>                         /* exit the loop but not return an error */
>     --
>     2.9.3
>
>
>
>
Steve Shin Jan. 20, 2017, 2:30 a.m. UTC | #3
Thanks Igor for your comments!

A good point on the first item.
For the second question, I walked through device initialization routines to see any other potential issue.
I found one case where index 0 is still required to replay MAC address; ex) MAC address change on the PHY port – index 0
No code path was found to restore a changed MAC value with index 0. Therefore, we may have to use the existing rte_eth_dev_config_restore() function to replay 0 indexed MAC.
Currently rte_eth_dev_default_mac_addr_set() is called to program PHY MAC without setting mac_pool_sel for 0 index.
So the following code is also required inside rte_eth_dev_default_mac_addr_set() routine as a complete solution:
@@ -2237,6 +2234,9 @@ struct rte_eth_dev *

        (*dev->dev_ops->mac_addr_set)(dev, addr);

+       /* Update pool bitmap in NIC data structure */
+       dev->data->mac_pool_sel[0] = 1;
+
        return 0;

Any thoughts would be appreciated.

Regards,
Steve

From: Igor Ryzhov <iryzhov@nfware.com>

Date: Thursday, January 19, 2017 at 2:39 PM
To: Steve Shin <jonshin@cisco.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>, "ferruh.yigit@intel.com" <ferruh.yigit@intel.com>
Subject: Re: [dpdk-dev] [PATCH] lib/librte_ether: error handling on MAC address replay

Hello Steve,

Thank you for the patch.

I think a couple of improvements can be done:
1. Function existence check – if (*dev->dev_ops->mac_addr_add) – can be taken out of the loop. We don't need to check it on each iteration.
2. I'm not completely sure, but I think loop can be started from 1, not from 0, because mac_pool_sel[0] is always zero. Am I right?

Best regards,
Igor

On Thu, Jan 19, 2017 at 10:35 PM, Steve Shin (jonshin) <jonshin@cisco.com<mailto:jonshin@cisco.com>> wrote:
Dear maintainer,

Sorry that I forgot to add “Fixes:” line as follows:

       Fixes: 4bdefaade6d1 ("ethdev: VMDQ enhancements")

Can you please add the above line as part of comment?

Thanks,
Steve

On 1/19/17, 10:47 AM, "Steve Shin (jonshin)" <jonshin@cisco.com<mailto:jonshin@cisco.com>> wrote:

    This patch fixes a bug in replaying MAC address to the hardware
    in rte_eth_dev_config_restore() routine.

    Signed-off-by: Steve Shin <jonshin@cisco.com<mailto:jonshin@cisco.com>>

    ---
     lib/librte_ether/rte_ethdev.c | 10 ++++++----
     1 file changed, 6 insertions(+), 4 deletions(-)

    diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
    index 4790faf..7e01f10 100644
    --- a/lib/librte_ether/rte_ethdev.c
    +++ b/lib/librte_ether/rte_ethdev.c
    @@ -951,10 +951,12 @@ rte_eth_dev_config_restore(uint8_t port_id)
                        continue;

                /* add address to the hardware */
    -           if  (*dev->dev_ops->mac_addr_add &&
    -                   (dev->data->mac_pool_sel[i] & (1ULL << pool)))
    -                   (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
    -           else {
    +           if  (*dev->dev_ops->mac_addr_add) {
    +                   if (dev->data->mac_pool_sel[i] & (1ULL << pool))
    +                           (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
    +                   else
    +                           continue;
    +           } else {
                        RTE_PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
                                        port_id);
                        /* exit the loop but not return an error */
    --
    2.9.3
Igor Ryzhov Jan. 20, 2017, 12:17 p.m. UTC | #4
Hello Steve,

I think it's not the right solution, because if we want to restore default
MAC address, it should be done using dev->dev_ops->mac_addr_set(), not
using dev->dev_ops->mac_addr_add().

I think that right solution may be to store default MAC address in separate
variable dev->data->default_mac_addr, not in dev->data->mac_addrs array.
And, accordingly, restore default_mac_addr using mac_addr_set(), and
restore mac_addrs array using mac_addr_add().

Best regards,
Igor

On Fri, Jan 20, 2017 at 5:30 AM, Steve Shin (jonshin) <jonshin@cisco.com>
wrote:

> Thanks Igor for your comments!
>
>
>
> A good point on the first item.
>
> For the second question, I walked through device initialization routines
> to see any other potential issue.
>
> I found one case where index 0 is still required to replay MAC address;
> ex) MAC address change on the PHY port – index 0
>
> No code path was found to restore a changed MAC value with index 0.
> Therefore, we may have to use the existing rte_eth_dev_config_restore()
> function to replay 0 indexed MAC.
>
> Currently rte_eth_dev_default_mac_addr_set() is called to program PHY MAC
> without setting mac_pool_sel for 0 index.
>
> So the following code is also required inside rte_eth_dev_default_mac_addr_set()
> routine as a complete solution:
>
> @@ -2237,6 +2234,9 @@ struct rte_eth_dev *
>
>
>
>         (*dev->dev_ops->mac_addr_set)(dev, addr);
>
>
>
> +       /* Update pool bitmap in NIC data structure */
>
> +       dev->data->mac_pool_sel[0] = 1;
>
> +
>
>         return 0;
>
>
>
> Any thoughts would be appreciated.
>
>
>
> Regards,
>
> Steve
>
>
>
> *From: *Igor Ryzhov <iryzhov@nfware.com>
> *Date: *Thursday, January 19, 2017 at 2:39 PM
> *To: *Steve Shin <jonshin@cisco.com>
> *Cc: *"dev@dpdk.org" <dev@dpdk.org>, "ferruh.yigit@intel.com" <
> ferruh.yigit@intel.com>
> *Subject: *Re: [dpdk-dev] [PATCH] lib/librte_ether: error handling on MAC
> address replay
>
>
>
> Hello Steve,
>
>
>
> Thank you for the patch.
>
>
>
> I think a couple of improvements can be done:
>
> 1. Function existence check – if (*dev->dev_ops->mac_addr_add) – can be
> taken out of the loop. We don't need to check it on each iteration.
>
> 2. I'm not completely sure, but I think loop can be started from 1, not
> from 0, because mac_pool_sel[0] is always zero. Am I right?
>
>
>
> Best regards,
>
> Igor
>
>
>
> On Thu, Jan 19, 2017 at 10:35 PM, Steve Shin (jonshin) <jonshin@cisco.com>
> wrote:
>
> Dear maintainer,
>
> Sorry that I forgot to add “Fixes:” line as follows:
>
>        Fixes: 4bdefaade6d1 ("ethdev: VMDQ enhancements")
>
> Can you please add the above line as part of comment?
>
> Thanks,
> Steve
>
>
> On 1/19/17, 10:47 AM, "Steve Shin (jonshin)" <jonshin@cisco.com> wrote:
>
>     This patch fixes a bug in replaying MAC address to the hardware
>     in rte_eth_dev_config_restore() routine.
>
>     Signed-off-by: Steve Shin <jonshin@cisco.com>
>     ---
>      lib/librte_ether/rte_ethdev.c | 10 ++++++----
>      1 file changed, 6 insertions(+), 4 deletions(-)
>
>     diff --git a/lib/librte_ether/rte_ethdev.c
> b/lib/librte_ether/rte_ethdev.c
>     index 4790faf..7e01f10 100644
>     --- a/lib/librte_ether/rte_ethdev.c
>     +++ b/lib/librte_ether/rte_ethdev.c
>     @@ -951,10 +951,12 @@ rte_eth_dev_config_restore(uint8_t port_id)
>                         continue;
>
>                 /* add address to the hardware */
>     -           if  (*dev->dev_ops->mac_addr_add &&
>     -                   (dev->data->mac_pool_sel[i] & (1ULL << pool)))
>     -                   (*dev->dev_ops->mac_addr_add)(dev, &addr, i,
> pool);
>     -           else {
>     +           if  (*dev->dev_ops->mac_addr_add) {
>     +                   if (dev->data->mac_pool_sel[i] & (1ULL << pool))
>     +                           (*dev->dev_ops->mac_addr_add)(dev, &addr,
> i, pool);
>     +                   else
>     +                           continue;
>     +           } else {
>                         RTE_PMD_DEBUG_TRACE("port %d: MAC address array
> not supported\n",
>                                         port_id);
>                         /* exit the loop but not return an error */
>     --
>     2.9.3
>
>
>
>
Steve Shin Jan. 20, 2017, 7:12 p.m. UTC | #5
Dear Igor,

That makes sense to use mac_addr_set() for default MAC address replay.

As default MAC is kept in dev->data->mac_addrs[0], we may not need to create a separate variable for default one.
Will run some unit test with new change and upload a new diff for your review.

FYI: Ferruh recommended to change tag in patch subject title. So next patch will have a different tile as “ethdev: fix MAC address replay”.

Thanks & Regards,
Steve

From: Igor Ryzhov <iryzhov@nfware.com>

Date: Friday, January 20, 2017 at 4:17 AM
To: Steve Shin <jonshin@cisco.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>, "ferruh.yigit@intel.com" <ferruh.yigit@intel.com>
Subject: Re: [dpdk-dev] [PATCH] lib/librte_ether: error handling on MAC address replay

Hello Steve,

I think it's not the right solution, because if we want to restore default MAC address, it should be done using dev->dev_ops->mac_addr_set(), not using dev->dev_ops->mac_addr_add().

I think that right solution may be to store default MAC address in separate variable dev->data->default_mac_addr, not in dev->data->mac_addrs array.
And, accordingly, restore default_mac_addr using mac_addr_set(), and restore mac_addrs array using mac_addr_add().

Best regards,
Igor

On Fri, Jan 20, 2017 at 5:30 AM, Steve Shin (jonshin) <jonshin@cisco.com<mailto:jonshin@cisco.com>> wrote:
Thanks Igor for your comments!

A good point on the first item.
For the second question, I walked through device initialization routines to see any other potential issue.
I found one case where index 0 is still required to replay MAC address; ex) MAC address change on the PHY port – index 0
No code path was found to restore a changed MAC value with index 0. Therefore, we may have to use the existing rte_eth_dev_config_restore() function to replay 0 indexed MAC.
Currently rte_eth_dev_default_mac_addr_set() is called to program PHY MAC without setting mac_pool_sel for 0 index.
So the following code is also required inside rte_eth_dev_default_mac_addr_set() routine as a complete solution:
@@ -2237,6 +2234,9 @@ struct rte_eth_dev *

        (*dev->dev_ops->mac_addr_set)(dev, addr);

+       /* Update pool bitmap in NIC data structure */
+       dev->data->mac_pool_sel[0] = 1;
+
        return 0;

Any thoughts would be appreciated.

Regards,
Steve

From: Igor Ryzhov <iryzhov@nfware.com<mailto:iryzhov@nfware.com>>

Date: Thursday, January 19, 2017 at 2:39 PM
To: Steve Shin <jonshin@cisco.com<mailto:jonshin@cisco.com>>
Cc: "dev@dpdk.org<mailto:dev@dpdk.org>" <dev@dpdk.org<mailto:dev@dpdk.org>>, "ferruh.yigit@intel.com<mailto:ferruh.yigit@intel.com>" <ferruh.yigit@intel.com<mailto:ferruh.yigit@intel.com>>
Subject: Re: [dpdk-dev] [PATCH] lib/librte_ether: error handling on MAC address replay

Hello Steve,

Thank you for the patch.

I think a couple of improvements can be done:
1. Function existence check – if (*dev->dev_ops->mac_addr_add) – can be taken out of the loop. We don't need to check it on each iteration.
2. I'm not completely sure, but I think loop can be started from 1, not from 0, because mac_pool_sel[0] is always zero. Am I right?

Best regards,
Igor

On Thu, Jan 19, 2017 at 10:35 PM, Steve Shin (jonshin) <jonshin@cisco.com<mailto:jonshin@cisco.com>> wrote:
Dear maintainer,

Sorry that I forgot to add “Fixes:” line as follows:

       Fixes: 4bdefaade6d1 ("ethdev: VMDQ enhancements")

Can you please add the above line as part of comment?

Thanks,
Steve

On 1/19/17, 10:47 AM, "Steve Shin (jonshin)" <jonshin@cisco.com<mailto:jonshin@cisco.com>> wrote:

    This patch fixes a bug in replaying MAC address to the hardware
    in rte_eth_dev_config_restore() routine.

    Signed-off-by: Steve Shin <jonshin@cisco.com<mailto:jonshin@cisco.com>>

    ---
     lib/librte_ether/rte_ethdev.c | 10 ++++++----
     1 file changed, 6 insertions(+), 4 deletions(-)

    diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
    index 4790faf..7e01f10 100644
    --- a/lib/librte_ether/rte_ethdev.c
    +++ b/lib/librte_ether/rte_ethdev.c
    @@ -951,10 +951,12 @@ rte_eth_dev_config_restore(uint8_t port_id)
                        continue;

                /* add address to the hardware */
    -           if  (*dev->dev_ops->mac_addr_add &&
    -                   (dev->data->mac_pool_sel[i] & (1ULL << pool)))
    -                   (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
    -           else {
    +           if  (*dev->dev_ops->mac_addr_add) {
    +                   if (dev->data->mac_pool_sel[i] & (1ULL << pool))
    +                           (*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
    +                   else
    +                           continue;
    +           } else {
                        RTE_PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
                                        port_id);
                        /* exit the loop but not return an error */
    --
    2.9.3

Patch
diff mbox

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 4790faf..7e01f10 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -951,10 +951,12 @@  rte_eth_dev_config_restore(uint8_t port_id)
 			continue;
 
 		/* add address to the hardware */
-		if  (*dev->dev_ops->mac_addr_add &&
-			(dev->data->mac_pool_sel[i] & (1ULL << pool)))
-			(*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
-		else {
+		if  (*dev->dev_ops->mac_addr_add) {
+			if (dev->data->mac_pool_sel[i] & (1ULL << pool))
+				(*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
+			else
+				continue;
+		} else {
 			RTE_PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
 					port_id);
 			/* exit the loop but not return an error */