diff mbox series

[nvmem,1/1] nvmem: imx: correct the fuse word index

Message ID 20190704142015.10701-1-fugang.duan@nxp.com (mailing list archive)
State New, archived
Headers show
Series [nvmem,1/1] nvmem: imx: correct the fuse word index | expand

Commit Message

Andy Duan July 4, 2019, 2:20 p.m. UTC
From: Fugang Duan <fugang.duan@nxp.com>

iMX8 fuse word index represent as one 4-bytes word,
it should not be divided by 4.

Exp:
- MAC0 address layout in fuse:
offset 708: MAC[3] MAC[2] MAC[1] MAC[0]
offset 709: XX     xx     MAC[5] MAC[4]

Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
---
 drivers/nvmem/imx-ocotp-scu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Lothar Waßmann July 4, 2019, 3:45 p.m. UTC | #1
Hi,

On Thu,  4 Jul 2019 22:20:15 +0800 fugang.duan@nxp.com wrote:
> From: Fugang Duan <fugang.duan@nxp.com>
> 
> iMX8 fuse word index represent as one 4-bytes word,
> it should not be divided by 4.
> 
> Exp:
> - MAC0 address layout in fuse:
> offset 708: MAC[3] MAC[2] MAC[1] MAC[0]
> offset 709: XX     xx     MAC[5] MAC[4]
> 
> Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
> ---
>  drivers/nvmem/imx-ocotp-scu.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/nvmem/imx-ocotp-scu.c b/drivers/nvmem/imx-ocotp-scu.c
> index d9dc482..be2f5f0 100644
> --- a/drivers/nvmem/imx-ocotp-scu.c
> +++ b/drivers/nvmem/imx-ocotp-scu.c
> @@ -71,8 +71,8 @@ static int imx_scu_ocotp_read(void *context, unsigned int offset,
>  	void *p;
>  	int i, ret;
>  
> -	index = offset >> 2;
> -	num_bytes = round_up((offset % 4) + bytes, 4);
> +	index = offset;
> +	num_bytes = round_up(bytes, 4);
>  	count = num_bytes >> 2;
>  
>  	if (count > (priv->data->nregs - index))
> @@ -100,7 +100,7 @@ static int imx_scu_ocotp_read(void *context, unsigned int offset,
>  		buf++;
>  	}
>  
> -	memcpy(val, (u8 *)p + offset % 4, bytes);
> +	memcpy(val, (u8 *)p, bytes);
>  
>  	kfree(p);
>  
With these changes you could use the 'val' pointer directly
as the destination for ocotp_read() without need for an intermediate
buffer.


Lothar Waßmann
Andy Duan July 4, 2019, 4:07 p.m. UTC | #2
From: Lothar Waßmann <LW@KARO-electronics.de> Sent: Thursday, July 4, 2019 11:46 PM
> Hi,
> 
> On Thu,  4 Jul 2019 22:20:15 +0800 fugang.duan@nxp.com wrote:
> > From: Fugang Duan <fugang.duan@nxp.com>
> >
> > iMX8 fuse word index represent as one 4-bytes word, it should not be
> > divided by 4.
> >
> > Exp:
> > - MAC0 address layout in fuse:
> > offset 708: MAC[3] MAC[2] MAC[1] MAC[0]
> > offset 709: XX     xx     MAC[5] MAC[4]
> >
> > Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
> > ---
> >  drivers/nvmem/imx-ocotp-scu.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/nvmem/imx-ocotp-scu.c
> > b/drivers/nvmem/imx-ocotp-scu.c index d9dc482..be2f5f0 100644
> > --- a/drivers/nvmem/imx-ocotp-scu.c
> > +++ b/drivers/nvmem/imx-ocotp-scu.c
> > @@ -71,8 +71,8 @@ static int imx_scu_ocotp_read(void *context, unsigned
> int offset,
> >       void *p;
> >       int i, ret;
> >
> > -     index = offset >> 2;
> > -     num_bytes = round_up((offset % 4) + bytes, 4);
> > +     index = offset;
> > +     num_bytes = round_up(bytes, 4);
> >       count = num_bytes >> 2;
> >
> >       if (count > (priv->data->nregs - index)) @@ -100,7 +100,7 @@
> > static int imx_scu_ocotp_read(void *context, unsigned int offset,
> >               buf++;
> >       }
> >
> > -     memcpy(val, (u8 *)p + offset % 4, bytes);
> > +     memcpy(val, (u8 *)p, bytes);
> >
> >       kfree(p);
> >
> With these changes you could use the 'val' pointer directly as the destination
> for ocotp_read() without need for an intermediate buffer.
> 
> 
> Lothar Waßmann

You are right, in fact, we can remove "p" and "buf" pointer.
Thanks for your review, I will send out the V2.
Andy Duan July 5, 2019, 2:46 a.m. UTC | #3
From: Andy Duan Sent: Friday, July 5, 2019 12:08 AM
> From: Lothar Waßmann <LW@KARO-electronics.de> Sent: Thursday, July 4,
> 2019 11:46 PM
> > Hi,
> >
> > On Thu,  4 Jul 2019 22:20:15 +0800 fugang.duan@nxp.com wrote:
> > > From: Fugang Duan <fugang.duan@nxp.com>
> > >
> > > iMX8 fuse word index represent as one 4-bytes word, it should not be
> > > divided by 4.
> > >
> > > Exp:
> > > - MAC0 address layout in fuse:
> > > offset 708: MAC[3] MAC[2] MAC[1] MAC[0]
> > > offset 709: XX     xx     MAC[5] MAC[4]
> > >
> > > Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
> > > ---
> > >  drivers/nvmem/imx-ocotp-scu.c | 6 +++---
> > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/drivers/nvmem/imx-ocotp-scu.c
> > > b/drivers/nvmem/imx-ocotp-scu.c index d9dc482..be2f5f0 100644
> > > --- a/drivers/nvmem/imx-ocotp-scu.c
> > > +++ b/drivers/nvmem/imx-ocotp-scu.c
> > > @@ -71,8 +71,8 @@ static int imx_scu_ocotp_read(void *context,
> > > unsigned
> > int offset,
> > >       void *p;
> > >       int i, ret;
> > >
> > > -     index = offset >> 2;
> > > -     num_bytes = round_up((offset % 4) + bytes, 4);
> > > +     index = offset;
> > > +     num_bytes = round_up(bytes, 4);
> > >       count = num_bytes >> 2;
> > >
> > >       if (count > (priv->data->nregs - index)) @@ -100,7 +100,7 @@
> > > static int imx_scu_ocotp_read(void *context, unsigned int offset,
> > >               buf++;
> > >       }
> > >
> > > -     memcpy(val, (u8 *)p + offset % 4, bytes);
> > > +     memcpy(val, (u8 *)p, bytes);
> > >
> > >       kfree(p);
> > >
> > With these changes you could use the 'val' pointer directly as the
> > destination for ocotp_read() without need for an intermediate buffer.
> >
> >
> > Lothar Waßmann
> 
> You are right, in fact, we can remove "p" and "buf" pointer.
> Thanks for your review, I will send out the V2.

Hi Lothar,

It still need intermediate buffer to read out n words (n * 4 bytes) from eFuse.
Because 'val' buffer size is real count parsed from DT, which is not an integer multiple of 4.

For example, cell->bytes is parsed from "reg" property and it is real count like 6.
                        fec_mac0: mac@2c4 {
                                reg = <0x2c4 6>;
                        }; 

So we have to use intermediate buffer here.
Lothar Waßmann July 5, 2019, 7:12 a.m. UTC | #4
Hi,

On Fri, 5 Jul 2019 02:46:32 +0000 Andy Duan wrote:
> From: Andy Duan Sent: Friday, July 5, 2019 12:08 AM
> > From: Lothar Waßmann <LW@KARO-electronics.de> Sent: Thursday, July 4,
> > 2019 11:46 PM  
> > > Hi,
> > >
> > > On Thu,  4 Jul 2019 22:20:15 +0800 fugang.duan@nxp.com wrote:  
> > > > From: Fugang Duan <fugang.duan@nxp.com>
> > > >
> > > > iMX8 fuse word index represent as one 4-bytes word, it should not be
> > > > divided by 4.
> > > >
> > > > Exp:
> > > > - MAC0 address layout in fuse:
> > > > offset 708: MAC[3] MAC[2] MAC[1] MAC[0]
> > > > offset 709: XX     xx     MAC[5] MAC[4]
> > > >
> > > > Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
> > > > ---
> > > >  drivers/nvmem/imx-ocotp-scu.c | 6 +++---
> > > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > > >
> > > > diff --git a/drivers/nvmem/imx-ocotp-scu.c
> > > > b/drivers/nvmem/imx-ocotp-scu.c index d9dc482..be2f5f0 100644
> > > > --- a/drivers/nvmem/imx-ocotp-scu.c
> > > > +++ b/drivers/nvmem/imx-ocotp-scu.c
> > > > @@ -71,8 +71,8 @@ static int imx_scu_ocotp_read(void *context,
> > > > unsigned  
> > > int offset,  
> > > >       void *p;
> > > >       int i, ret;
> > > >
> > > > -     index = offset >> 2;
> > > > -     num_bytes = round_up((offset % 4) + bytes, 4);
> > > > +     index = offset;
> > > > +     num_bytes = round_up(bytes, 4);
> > > >       count = num_bytes >> 2;
> > > >
> > > >       if (count > (priv->data->nregs - index)) @@ -100,7 +100,7 @@
> > > > static int imx_scu_ocotp_read(void *context, unsigned int offset,
> > > >               buf++;
> > > >       }
> > > >
> > > > -     memcpy(val, (u8 *)p + offset % 4, bytes);
> > > > +     memcpy(val, (u8 *)p, bytes);
> > > >
> > > >       kfree(p);
> > > >  
> > > With these changes you could use the 'val' pointer directly as the
> > > destination for ocotp_read() without need for an intermediate buffer.
> > >
> > >
> > > Lothar Waßmann  
> > 
> > You are right, in fact, we can remove "p" and "buf" pointer.
> > Thanks for your review, I will send out the V2.  
> 
> Hi Lothar,
> 
> It still need intermediate buffer to read out n words (n * 4 bytes) from eFuse.
> Because 'val' buffer size is real count parsed from DT, which is not an integer multiple of 4.
> 
> For example, cell->bytes is parsed from "reg" property and it is real count like 6.
>                         fec_mac0: mac@2c4 {
>                                 reg = <0x2c4 6>;
>                         }; 
> 
> So we have to use intermediate buffer here.
>
val is a u32 pointer, so legally it cannot point to any buffer whose
size is not divisible by four!


Lothar Waßmann
Andy Duan July 5, 2019, 7:32 a.m. UTC | #5
From: Lothar Waßmann <LW@KARO-electronics.de> Sent: Friday, July 5, 2019 3:13 PM
> Hi,
> 
> On Fri, 5 Jul 2019 02:46:32 +0000 Andy Duan wrote:
> > From: Andy Duan Sent: Friday, July 5, 2019 12:08 AM
> > > From: Lothar Waßmann <LW@KARO-electronics.de> Sent: Thursday, July
> > > 4,
> > > 2019 11:46 PM
> > > > Hi,
> > > >
> > > > On Thu,  4 Jul 2019 22:20:15 +0800 fugang.duan@nxp.com wrote:
> > > > > From: Fugang Duan <fugang.duan@nxp.com>
> > > > >
> > > > > iMX8 fuse word index represent as one 4-bytes word, it should
> > > > > not be divided by 4.
> > > > >
> > > > > Exp:
> > > > > - MAC0 address layout in fuse:
> > > > > offset 708: MAC[3] MAC[2] MAC[1] MAC[0]
> > > > > offset 709: XX     xx     MAC[5] MAC[4]
> > > > >
> > > > > Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
> > > > > ---
> > > > >  drivers/nvmem/imx-ocotp-scu.c | 6 +++---
> > > > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > > > >
> > > > > diff --git a/drivers/nvmem/imx-ocotp-scu.c
> > > > > b/drivers/nvmem/imx-ocotp-scu.c index d9dc482..be2f5f0 100644
> > > > > --- a/drivers/nvmem/imx-ocotp-scu.c
> > > > > +++ b/drivers/nvmem/imx-ocotp-scu.c
> > > > > @@ -71,8 +71,8 @@ static int imx_scu_ocotp_read(void *context,
> > > > > unsigned
> > > > int offset,
> > > > >       void *p;
> > > > >       int i, ret;
> > > > >
> > > > > -     index = offset >> 2;
> > > > > -     num_bytes = round_up((offset % 4) + bytes, 4);
> > > > > +     index = offset;
> > > > > +     num_bytes = round_up(bytes, 4);
> > > > >       count = num_bytes >> 2;
> > > > >
> > > > >       if (count > (priv->data->nregs - index)) @@ -100,7 +100,7
> > > > > @@ static int imx_scu_ocotp_read(void *context, unsigned int offset,
> > > > >               buf++;
> > > > >       }
> > > > >
> > > > > -     memcpy(val, (u8 *)p + offset % 4, bytes);
> > > > > +     memcpy(val, (u8 *)p, bytes);
> > > > >
> > > > >       kfree(p);
> > > > >
> > > > With these changes you could use the 'val' pointer directly as the
> > > > destination for ocotp_read() without need for an intermediate buffer.
> > > >
> > > >
> > > > Lothar Waßmann
> > >
> > > You are right, in fact, we can remove "p" and "buf" pointer.
> > > Thanks for your review, I will send out the V2.
> >
> > Hi Lothar,
> >
> > It still need intermediate buffer to read out n words (n * 4 bytes) from
> eFuse.
> > Because 'val' buffer size is real count parsed from DT, which is not an integer
> multiple of 4.
> >
> > For example, cell->bytes is parsed from "reg" property and it is real count
> like 6.
> >                         fec_mac0: mac@2c4 {
> >                                 reg = <0x2c4 6>;
> >                         };
> >
> > So we have to use intermediate buffer here.
> >
> val is a u32 pointer, so legally it cannot point to any buffer whose size is not
> divisible by four!
> 
Yes, val is a u32 pointer, as my understand, it point to the 'buf' whose size is cell->bytes
(the size is not parsed from 'reg' property)

The piece of code: 
buf = kzalloc(cell->bytes, GFP_KERNEL);
nvmem_reg_read(nvmem, cell->offset, buf, cell->bytes);
imx_scu_ocotp_read(void *context, unsigned int offset, void *val, size_t bytes);

If so, we still need intermediate buffer to read out eFuse words, and copy 'cell->bytes'
bytes to 'val' buffer. 
May I understand wrong ? Thanks very much!
Andy Duan July 10, 2019, 2:29 a.m. UTC | #6
From: Andy Duan Sent: Friday, July 5, 2019 3:33 PM
> From: Lothar Waßmann <LW@KARO-electronics.de> Sent: Friday, July 5, 2019
> 3:13 PM
> > Hi,
> >
> > On Fri, 5 Jul 2019 02:46:32 +0000 Andy Duan wrote:
> > > From: Andy Duan Sent: Friday, July 5, 2019 12:08 AM
> > > > From: Lothar Waßmann <LW@KARO-electronics.de> Sent: Thursday,
> July
> > > > 4,
> > > > 2019 11:46 PM
> > > > > Hi,
> > > > >
> > > > > On Thu,  4 Jul 2019 22:20:15 +0800 fugang.duan@nxp.com wrote:
> > > > > > From: Fugang Duan <fugang.duan@nxp.com>
> > > > > >
> > > > > > iMX8 fuse word index represent as one 4-bytes word, it should
> > > > > > not be divided by 4.
> > > > > >
> > > > > > Exp:
> > > > > > - MAC0 address layout in fuse:
> > > > > > offset 708: MAC[3] MAC[2] MAC[1] MAC[0]
> > > > > > offset 709: XX     xx     MAC[5] MAC[4]
> > > > > >
> > > > > > Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
> > > > > > ---
> > > > > >  drivers/nvmem/imx-ocotp-scu.c | 6 +++---
> > > > > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > > > > >
> > > > > > diff --git a/drivers/nvmem/imx-ocotp-scu.c
> > > > > > b/drivers/nvmem/imx-ocotp-scu.c index d9dc482..be2f5f0 100644
> > > > > > --- a/drivers/nvmem/imx-ocotp-scu.c
> > > > > > +++ b/drivers/nvmem/imx-ocotp-scu.c
> > > > > > @@ -71,8 +71,8 @@ static int imx_scu_ocotp_read(void *context,
> > > > > > unsigned
> > > > > int offset,
> > > > > >       void *p;
> > > > > >       int i, ret;
> > > > > >
> > > > > > -     index = offset >> 2;
> > > > > > -     num_bytes = round_up((offset % 4) + bytes, 4);
> > > > > > +     index = offset;
> > > > > > +     num_bytes = round_up(bytes, 4);
> > > > > >       count = num_bytes >> 2;
> > > > > >
> > > > > >       if (count > (priv->data->nregs - index)) @@ -100,7
> > > > > > +100,7 @@ static int imx_scu_ocotp_read(void *context, unsigned
> int offset,
> > > > > >               buf++;
> > > > > >       }
> > > > > >
> > > > > > -     memcpy(val, (u8 *)p + offset % 4, bytes);
> > > > > > +     memcpy(val, (u8 *)p, bytes);
> > > > > >
> > > > > >       kfree(p);
> > > > > >
> > > > > With these changes you could use the 'val' pointer directly as
> > > > > the destination for ocotp_read() without need for an intermediate
> buffer.
> > > > >
> > > > >
> > > > > Lothar Waßmann
> > > >
> > > > You are right, in fact, we can remove "p" and "buf" pointer.
> > > > Thanks for your review, I will send out the V2.
> > >
> > > Hi Lothar,
> > >
> > > It still need intermediate buffer to read out n words (n * 4 bytes)
> > > from
> > eFuse.
> > > Because 'val' buffer size is real count parsed from DT, which is not
> > > an integer
> > multiple of 4.
> > >
> > > For example, cell->bytes is parsed from "reg" property and it is
> > > real count
> > like 6.
> > >                         fec_mac0: mac@2c4 {
> > >                                 reg = <0x2c4 6>;
> > >                         };
> > >
> > > So we have to use intermediate buffer here.
> > >
> > val is a u32 pointer, so legally it cannot point to any buffer whose
> > size is not divisible by four!
> >
> Yes, val is a u32 pointer, as my understand, it point to the 'buf' whose size is
> cell->bytes (the size is not parsed from 'reg' property)
> 
> The piece of code:
> buf = kzalloc(cell->bytes, GFP_KERNEL);
> nvmem_reg_read(nvmem, cell->offset, buf, cell->bytes);
> imx_scu_ocotp_read(void *context, unsigned int offset, void *val, size_t
> bytes);
> 
> If so, we still need intermediate buffer to read out eFuse words, and copy
> 'cell->bytes'
> bytes to 'val' buffer.
> May I understand wrong ? Thanks very much!

Lothar, any comment ? Thanks !
Andy Duan July 15, 2019, 5:35 a.m. UTC | #7
Ping ...

> From: Fugang Duan <fugang.duan@nxp.com>
> 
> iMX8 fuse word index represent as one 4-bytes word, it should not be divided
> by 4.
> 
> Exp:
> - MAC0 address layout in fuse:
> offset 708: MAC[3] MAC[2] MAC[1] MAC[0]
> offset 709: XX     xx     MAC[5] MAC[4]
> 
> Signed-off-by: Fugang Duan <fugang.duan@nxp.com>
> ---
>  drivers/nvmem/imx-ocotp-scu.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/nvmem/imx-ocotp-scu.c b/drivers/nvmem/imx-ocotp-scu.c
> index d9dc482..be2f5f0 100644
> --- a/drivers/nvmem/imx-ocotp-scu.c
> +++ b/drivers/nvmem/imx-ocotp-scu.c
> @@ -71,8 +71,8 @@ static int imx_scu_ocotp_read(void *context, unsigned
> int offset,
>  	void *p;
>  	int i, ret;
> 
> -	index = offset >> 2;
> -	num_bytes = round_up((offset % 4) + bytes, 4);
> +	index = offset;
> +	num_bytes = round_up(bytes, 4);
>  	count = num_bytes >> 2;
> 
>  	if (count > (priv->data->nregs - index)) @@ -100,7 +100,7 @@ static int
> imx_scu_ocotp_read(void *context, unsigned int offset,
>  		buf++;
>  	}
> 
> -	memcpy(val, (u8 *)p + offset % 4, bytes);
> +	memcpy(val, (u8 *)p, bytes);
> 
>  	kfree(p);
> 
> --
> 2.7.4
diff mbox series

Patch

diff --git a/drivers/nvmem/imx-ocotp-scu.c b/drivers/nvmem/imx-ocotp-scu.c
index d9dc482..be2f5f0 100644
--- a/drivers/nvmem/imx-ocotp-scu.c
+++ b/drivers/nvmem/imx-ocotp-scu.c
@@ -71,8 +71,8 @@  static int imx_scu_ocotp_read(void *context, unsigned int offset,
 	void *p;
 	int i, ret;
 
-	index = offset >> 2;
-	num_bytes = round_up((offset % 4) + bytes, 4);
+	index = offset;
+	num_bytes = round_up(bytes, 4);
 	count = num_bytes >> 2;
 
 	if (count > (priv->data->nregs - index))
@@ -100,7 +100,7 @@  static int imx_scu_ocotp_read(void *context, unsigned int offset,
 		buf++;
 	}
 
-	memcpy(val, (u8 *)p + offset % 4, bytes);
+	memcpy(val, (u8 *)p, bytes);
 
 	kfree(p);