linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: macb: Write only necessary bits in NCR in macb reset
@ 2016-11-28  9:23 Harini Katakam
  2016-11-28  9:31 ` Nicolas Ferre
  2016-11-30  0:05 ` David Miller
  0 siblings, 2 replies; 5+ messages in thread
From: Harini Katakam @ 2016-11-28  9:23 UTC (permalink / raw)
  To: nicolas.ferre, davem, harinikatakamlinux
  Cc: netdev, linux-kernel, harinik, michals

In macb_reset_hw, use read-modify-write to disable RX and TX.
This way exiting settings and reserved bits wont be disturbed.
Use the same method for clearing statistics as well.

Signed-off-by: Harini Katakam <harinik@xilinx.com>
---
 drivers/net/ethernet/cadence/macb.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index 0e489bb..80ccfc4 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -1743,15 +1743,18 @@ static void macb_init_rings(struct macb *bp)
 static void macb_reset_hw(struct macb *bp)
 {
 	struct macb_queue *queue;
-	unsigned int q;
+	unsigned int q, ctrl;
 
 	/* Disable RX and TX (XXX: Should we halt the transmission
 	 * more gracefully?)
 	 */
-	macb_writel(bp, NCR, 0);
+	ctrl = macb_readl(bp, NCR);
+	ctrl &= ~(MACB_BIT(RE) | MACB_BIT(TE));
+	macb_writel(bp, NCR, ctrl);
 
 	/* Clear the stats registers (XXX: Update stats first?) */
-	macb_writel(bp, NCR, MACB_BIT(CLRSTAT));
+	ctrl |= MACB_BIT(CLRSTAT);
+	macb_writel(bp, NCR, ctrl);
 
 	/* Clear all status flags */
 	macb_writel(bp, TSR, -1);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: macb: Write only necessary bits in NCR in macb reset
  2016-11-28  9:23 [PATCH] net: macb: Write only necessary bits in NCR in macb reset Harini Katakam
@ 2016-11-28  9:31 ` Nicolas Ferre
  2016-11-28  9:40   ` Harini Katakam
  2016-11-30  0:05 ` David Miller
  1 sibling, 1 reply; 5+ messages in thread
From: Nicolas Ferre @ 2016-11-28  9:31 UTC (permalink / raw)
  To: Harini Katakam, davem, harinikatakamlinux
  Cc: netdev, linux-kernel, harinik, michals

Le 28/11/2016 à 10:23, Harini Katakam a écrit :
> In macb_reset_hw, use read-modify-write to disable RX and TX.
> This way exiting settings and reserved bits wont be disturbed.

Yes, indeed... but I would have liked a line about how you discovered it
was an issue for you ;  what did it break, etc...

> Use the same method for clearing statistics as well.
> 
> Signed-off-by: Harini Katakam <harinik@xilinx.com>
> ---
>  drivers/net/ethernet/cadence/macb.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
> index 0e489bb..80ccfc4 100644
> --- a/drivers/net/ethernet/cadence/macb.c
> +++ b/drivers/net/ethernet/cadence/macb.c
> @@ -1743,15 +1743,18 @@ static void macb_init_rings(struct macb *bp)
>  static void macb_reset_hw(struct macb *bp)
>  {
>  	struct macb_queue *queue;
> -	unsigned int q;
> +	unsigned int q, ctrl;

I would have preferred a different line with u32 type.


>  	/* Disable RX and TX (XXX: Should we halt the transmission
>  	 * more gracefully?)
>  	 */
> -	macb_writel(bp, NCR, 0);
> +	ctrl = macb_readl(bp, NCR);
> +	ctrl &= ~(MACB_BIT(RE) | MACB_BIT(TE));
> +	macb_writel(bp, NCR, ctrl);
>  
>  	/* Clear the stats registers (XXX: Update stats first?) */
> -	macb_writel(bp, NCR, MACB_BIT(CLRSTAT));
> +	ctrl |= MACB_BIT(CLRSTAT);
> +	macb_writel(bp, NCR, ctrl);
>  
>  	/* Clear all status flags */
>  	macb_writel(bp, TSR, -1);
> 


-- 
Nicolas Ferre

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: macb: Write only necessary bits in NCR in macb reset
  2016-11-28  9:31 ` Nicolas Ferre
@ 2016-11-28  9:40   ` Harini Katakam
  0 siblings, 0 replies; 5+ messages in thread
From: Harini Katakam @ 2016-11-28  9:40 UTC (permalink / raw)
  To: Nicolas Ferre; +Cc: Harini Katakam, davem, netdev, linux-kernel, michals

Hi Nicolas,

On Mon, Nov 28, 2016 at 3:01 PM, Nicolas Ferre <nicolas.ferre@atmel.com> wrote:
> Le 28/11/2016 à 10:23, Harini Katakam a écrit :
>> In macb_reset_hw, use read-modify-write to disable RX and TX.
>> This way exiting settings and reserved bits wont be disturbed.
>
> Yes, indeed... but I would have liked a line about how you discovered it
> was an issue for you ;  what did it break, etc...

Thanks for the review.
It did not necessarily break anything but we noticed
during some experiments that management port was being
enabled and disabled.
In addition, I thought it would be good to do
just because there were reserved read only bits in
the register.

>
>> Use the same method for clearing statistics as well.
>>
>> Signed-off-by: Harini Katakam <harinik@xilinx.com>
>> ---
>>  drivers/net/ethernet/cadence/macb.c | 9 ++++++---
>>  1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
>> index 0e489bb..80ccfc4 100644
>> --- a/drivers/net/ethernet/cadence/macb.c
>> +++ b/drivers/net/ethernet/cadence/macb.c
>> @@ -1743,15 +1743,18 @@ static void macb_init_rings(struct macb *bp)
>>  static void macb_reset_hw(struct macb *bp)
>>  {
>>       struct macb_queue *queue;
>> -     unsigned int q;
>> +     unsigned int q, ctrl;
>
> I would have preferred a different line with u32 type.

Sure, I'll add and send a v2

Regards,
Harini

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: macb: Write only necessary bits in NCR in macb reset
  2016-11-28  9:23 [PATCH] net: macb: Write only necessary bits in NCR in macb reset Harini Katakam
  2016-11-28  9:31 ` Nicolas Ferre
@ 2016-11-30  0:05 ` David Miller
  2016-11-30  4:17   ` Harini Katakam
  1 sibling, 1 reply; 5+ messages in thread
From: David Miller @ 2016-11-30  0:05 UTC (permalink / raw)
  To: harini.katakam
  Cc: nicolas.ferre, harinikatakamlinux, netdev, linux-kernel, harinik,
	michals

From: Harini Katakam <harini.katakam@xilinx.com>
Date: Mon, 28 Nov 2016 14:53:49 +0530

> In macb_reset_hw, use read-modify-write to disable RX and TX.
> This way exiting settings and reserved bits wont be disturbed.
> Use the same method for clearing statistics as well.
> 
> Signed-off-by: Harini Katakam <harinik@xilinx.com>

This doesn't make much sense to me.

Consider the two callers of this function.

macb_init_hw() is going to do a non-masking write to the NCR
register:

	/* Enable TX and RX */
	macb_writel(bp, NCR, MACB_BIT(RE) | MACB_BIT(TE) | MACB_BIT(MPE));

So obviously no other writable fields matter at all for programming
the chip properly, otherwise macb_init_hw() would "or" in the bits
after a read of NCR.  But that's not what this code does, it
writes "RE | TE | MPE" directly.

And the other caller is macb_close() which is shutting down the
chip so can zero out all the other bits and it can't possibly
matter, also due to the assertion above about macb_init_hw()
showing that only the RE, TE, and MPE bits matter for proper
functioning of the chip.

You haven't shown a issue caused by the way the code works now, so
this patch isn't fixing a bug.  In fact, the "bit preserving" would
even be misleading to someone reading the code.  They will ask
themselves what bits need to be preserved, and as shown above none of
them need to be.

I'm not applying this, sorry.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: macb: Write only necessary bits in NCR in macb reset
  2016-11-30  0:05 ` David Miller
@ 2016-11-30  4:17   ` Harini Katakam
  0 siblings, 0 replies; 5+ messages in thread
From: Harini Katakam @ 2016-11-30  4:17 UTC (permalink / raw)
  To: David Miller; +Cc: Harini Katakam, Nicolas Ferre, netdev, linux-kernel, michals

Hi David,

On Wed, Nov 30, 2016 at 5:35 AM, David Miller <davem@davemloft.net> wrote:
> From: Harini Katakam <harini.katakam@xilinx.com>
> Date: Mon, 28 Nov 2016 14:53:49 +0530
>
>> In macb_reset_hw, use read-modify-write to disable RX and TX.
>> This way exiting settings and reserved bits wont be disturbed.
>> Use the same method for clearing statistics as well.
>>
>> Signed-off-by: Harini Katakam <harinik@xilinx.com>
>
> This doesn't make much sense to me.
>
> Consider the two callers of this function.
>
> macb_init_hw() is going to do a non-masking write to the NCR
> register:
>
>         /* Enable TX and RX */
>         macb_writel(bp, NCR, MACB_BIT(RE) | MACB_BIT(TE) | MACB_BIT(MPE));
>
> So obviously no other writable fields matter at all for programming
> the chip properly, otherwise macb_init_hw() would "or" in the bits
> after a read of NCR.  But that's not what this code does, it
> writes "RE | TE | MPE" directly.
>
> And the other caller is macb_close() which is shutting down the
> chip so can zero out all the other bits and it can't possibly
> matter, also due to the assertion above about macb_init_hw()
> showing that only the RE, TE, and MPE bits matter for proper
> functioning of the chip.
>
> You haven't shown a issue caused by the way the code works now, so
> this patch isn't fixing a bug.  In fact, the "bit preserving" would
> even be misleading to someone reading the code.  They will ask
> themselves what bits need to be preserved, and as shown above none of
> them need to be.
>
> I'm not applying this, sorry.
>

Thanks for the detailed analysis.
I noticed an issue with respect to management port enable bit
when working on the patch series for macb mdio driver for
multi MAC - multi PHY access via same mdio bus.
MPE bit of the MAC (whose phy management register
is used) was being reset. But that is a separate
series still in review.
You are right, there is no existing bug that this
patch addresses. I will come back to this later if
required.

Regards,
Harini

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-11-30  4:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-28  9:23 [PATCH] net: macb: Write only necessary bits in NCR in macb reset Harini Katakam
2016-11-28  9:31 ` Nicolas Ferre
2016-11-28  9:40   ` Harini Katakam
2016-11-30  0:05 ` David Miller
2016-11-30  4:17   ` Harini Katakam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).