Re: [PATCH v2 6/8] staging: fsl-mc: don't use raw device io functions
On Tue, Jul 18, 2017 at 4:26 PM, Laurentiu Tudorwrote: > > Maybe i made an error in my previous emails, but the hi-lo variant is > the correct one. The command execution is triggered when the _first_ > 32-bit half of the header (header&0x) is written, so that's why > it must be written last. I'm pretty sure I just misremembered it then. Thanks for the clarification. Arnd
Re: [PATCH v2 6/8] staging: fsl-mc: don't use raw device io functions
On Tue, Jul 18, 2017 at 4:26 PM, Laurentiu Tudor wrote: > > Maybe i made an error in my previous emails, but the hi-lo variant is > the correct one. The command execution is triggered when the _first_ > 32-bit half of the header (header&0x) is written, so that's why > it must be written last. I'm pretty sure I just misremembered it then. Thanks for the clarification. Arnd
Re: [PATCH v2 6/8] staging: fsl-mc: don't use raw device io functions
Hi Arnd, On 07/18/2017 05:18 PM, Arnd Bergmann wrote: > On Tue, Jul 18, 2017 at 3:37 PM,wrote: >> From: Laurentiu Tudor >> >> As raw device io functions are not portable and don't handle byte-order >> (triggering suspicion that endianness isn't handled well) switch to >> using the standard api. >> Since MC expects LE byte-order and the upper layers already take care >> of that, we need to trick the device io api by doing a LE -> CPU >> conversion just before calling it. This way, the CPU -> LE conversion >> done in the api puts the data back in the right byte-order. Obviously, >> for reads the extra step is mirrored: there's a CPU -> LE conversion >> following the API call. >> >> Signed-off-by: Laurentiu Tudor >> --- >> Notes: >> -v2 >>-new patch replacing >> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flkml.org%2Flkml%2F2017%2F7%2F17%2F419=01%7C01%7Claurentiu.tudor%40nxp.com%7C77381272b4914c9ac64708d4cde7d94e%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0=FTVLKox6T4i9OFmb%2B5BkSEDQrDrafXznY6nsJ0dgFSk%3D=0 >> >> drivers/staging/fsl-mc/bus/mc-sys.c | 21 +++-- >> 1 file changed, 15 insertions(+), 6 deletions(-) >> >> diff --git a/drivers/staging/fsl-mc/bus/mc-sys.c >> b/drivers/staging/fsl-mc/bus/mc-sys.c >> index 195d9f3..8a6dc47 100644 >> --- a/drivers/staging/fsl-mc/bus/mc-sys.c >> +++ b/drivers/staging/fsl-mc/bus/mc-sys.c >> @@ -126,12 +126,15 @@ static inline void mc_write_command(struct mc_command >> __iomem *portal, >> >> /* copy command parameters into the portal */ >> for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++) >> - __raw_writeq(cmd->params[i], >params[i]); >> - /* ensure command params are committed before submitting it */ >> - wmb(); >> + /* >> +* Data is already in the expected LE byte-order. Do an >> +* extra LE -> CPU conversion so that the CPU -> LE done in >> +* the device io write api puts it back in the right order. >> +*/ >> + writeq_relaxed(le64_to_cpu(cmd->params[i]), >> >params[i]); >> >> /* submit the command by writing the header */ >> - __raw_writeq(cmd->header, >header); >> + writeq(le64_to_cpu(cmd->header), >header); >> } > > Looks good, but just to be sure this is what you intended: > > On 32-bit systems, this will now write val>>32 to cmd->header+4, > followed by writing val&0x to cmd->header. Right. That's how it should happen. > You said earlier that the command is triggered when the final > four bytes are written, but it looks like the order is wrong now. > > Should you use io-64-nonatomic-lo-hi.h instead of > io-64-nonatomic-hi-lo.h then? > Maybe i made an error in my previous emails, but the hi-lo variant is the correct one. The command execution is triggered when the _first_ 32-bit half of the header (header&0x) is written, so that's why it must be written last. --- Thanks & Best Regards, Laurentiu
Re: [PATCH v2 6/8] staging: fsl-mc: don't use raw device io functions
Hi Arnd, On 07/18/2017 05:18 PM, Arnd Bergmann wrote: > On Tue, Jul 18, 2017 at 3:37 PM, wrote: >> From: Laurentiu Tudor >> >> As raw device io functions are not portable and don't handle byte-order >> (triggering suspicion that endianness isn't handled well) switch to >> using the standard api. >> Since MC expects LE byte-order and the upper layers already take care >> of that, we need to trick the device io api by doing a LE -> CPU >> conversion just before calling it. This way, the CPU -> LE conversion >> done in the api puts the data back in the right byte-order. Obviously, >> for reads the extra step is mirrored: there's a CPU -> LE conversion >> following the API call. >> >> Signed-off-by: Laurentiu Tudor >> --- >> Notes: >> -v2 >>-new patch replacing >> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flkml.org%2Flkml%2F2017%2F7%2F17%2F419=01%7C01%7Claurentiu.tudor%40nxp.com%7C77381272b4914c9ac64708d4cde7d94e%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0=FTVLKox6T4i9OFmb%2B5BkSEDQrDrafXznY6nsJ0dgFSk%3D=0 >> >> drivers/staging/fsl-mc/bus/mc-sys.c | 21 +++-- >> 1 file changed, 15 insertions(+), 6 deletions(-) >> >> diff --git a/drivers/staging/fsl-mc/bus/mc-sys.c >> b/drivers/staging/fsl-mc/bus/mc-sys.c >> index 195d9f3..8a6dc47 100644 >> --- a/drivers/staging/fsl-mc/bus/mc-sys.c >> +++ b/drivers/staging/fsl-mc/bus/mc-sys.c >> @@ -126,12 +126,15 @@ static inline void mc_write_command(struct mc_command >> __iomem *portal, >> >> /* copy command parameters into the portal */ >> for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++) >> - __raw_writeq(cmd->params[i], >params[i]); >> - /* ensure command params are committed before submitting it */ >> - wmb(); >> + /* >> +* Data is already in the expected LE byte-order. Do an >> +* extra LE -> CPU conversion so that the CPU -> LE done in >> +* the device io write api puts it back in the right order. >> +*/ >> + writeq_relaxed(le64_to_cpu(cmd->params[i]), >> >params[i]); >> >> /* submit the command by writing the header */ >> - __raw_writeq(cmd->header, >header); >> + writeq(le64_to_cpu(cmd->header), >header); >> } > > Looks good, but just to be sure this is what you intended: > > On 32-bit systems, this will now write val>>32 to cmd->header+4, > followed by writing val&0x to cmd->header. Right. That's how it should happen. > You said earlier that the command is triggered when the final > four bytes are written, but it looks like the order is wrong now. > > Should you use io-64-nonatomic-lo-hi.h instead of > io-64-nonatomic-hi-lo.h then? > Maybe i made an error in my previous emails, but the hi-lo variant is the correct one. The command execution is triggered when the _first_ 32-bit half of the header (header&0x) is written, so that's why it must be written last. --- Thanks & Best Regards, Laurentiu
Re: [PATCH v2 6/8] staging: fsl-mc: don't use raw device io functions
On Tue, Jul 18, 2017 at 3:37 PM,wrote: > From: Laurentiu Tudor > > As raw device io functions are not portable and don't handle byte-order > (triggering suspicion that endianness isn't handled well) switch to > using the standard api. > Since MC expects LE byte-order and the upper layers already take care > of that, we need to trick the device io api by doing a LE -> CPU > conversion just before calling it. This way, the CPU -> LE conversion > done in the api puts the data back in the right byte-order. Obviously, > for reads the extra step is mirrored: there's a CPU -> LE conversion > following the API call. > > Signed-off-by: Laurentiu Tudor > --- > Notes: > -v2 > -new patch replacing https://lkml.org/lkml/2017/7/17/419 > > drivers/staging/fsl-mc/bus/mc-sys.c | 21 +++-- > 1 file changed, 15 insertions(+), 6 deletions(-) > > diff --git a/drivers/staging/fsl-mc/bus/mc-sys.c > b/drivers/staging/fsl-mc/bus/mc-sys.c > index 195d9f3..8a6dc47 100644 > --- a/drivers/staging/fsl-mc/bus/mc-sys.c > +++ b/drivers/staging/fsl-mc/bus/mc-sys.c > @@ -126,12 +126,15 @@ static inline void mc_write_command(struct mc_command > __iomem *portal, > > /* copy command parameters into the portal */ > for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++) > - __raw_writeq(cmd->params[i], >params[i]); > - /* ensure command params are committed before submitting it */ > - wmb(); > + /* > +* Data is already in the expected LE byte-order. Do an > +* extra LE -> CPU conversion so that the CPU -> LE done in > +* the device io write api puts it back in the right order. > +*/ > + writeq_relaxed(le64_to_cpu(cmd->params[i]), > >params[i]); > > /* submit the command by writing the header */ > - __raw_writeq(cmd->header, >header); > + writeq(le64_to_cpu(cmd->header), >header); > } Looks good, but just to be sure this is what you intended: On 32-bit systems, this will now write val>>32 to cmd->header+4, followed by writing val&0x to cmd->header. You said earlier that the command is triggered when the final four bytes are written, but it looks like the order is wrong now. Should you use io-64-nonatomic-lo-hi.h instead of io-64-nonatomic-hi-lo.h then? Arnd
Re: [PATCH v2 6/8] staging: fsl-mc: don't use raw device io functions
On Tue, Jul 18, 2017 at 3:37 PM, wrote: > From: Laurentiu Tudor > > As raw device io functions are not portable and don't handle byte-order > (triggering suspicion that endianness isn't handled well) switch to > using the standard api. > Since MC expects LE byte-order and the upper layers already take care > of that, we need to trick the device io api by doing a LE -> CPU > conversion just before calling it. This way, the CPU -> LE conversion > done in the api puts the data back in the right byte-order. Obviously, > for reads the extra step is mirrored: there's a CPU -> LE conversion > following the API call. > > Signed-off-by: Laurentiu Tudor > --- > Notes: > -v2 > -new patch replacing https://lkml.org/lkml/2017/7/17/419 > > drivers/staging/fsl-mc/bus/mc-sys.c | 21 +++-- > 1 file changed, 15 insertions(+), 6 deletions(-) > > diff --git a/drivers/staging/fsl-mc/bus/mc-sys.c > b/drivers/staging/fsl-mc/bus/mc-sys.c > index 195d9f3..8a6dc47 100644 > --- a/drivers/staging/fsl-mc/bus/mc-sys.c > +++ b/drivers/staging/fsl-mc/bus/mc-sys.c > @@ -126,12 +126,15 @@ static inline void mc_write_command(struct mc_command > __iomem *portal, > > /* copy command parameters into the portal */ > for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++) > - __raw_writeq(cmd->params[i], >params[i]); > - /* ensure command params are committed before submitting it */ > - wmb(); > + /* > +* Data is already in the expected LE byte-order. Do an > +* extra LE -> CPU conversion so that the CPU -> LE done in > +* the device io write api puts it back in the right order. > +*/ > + writeq_relaxed(le64_to_cpu(cmd->params[i]), > >params[i]); > > /* submit the command by writing the header */ > - __raw_writeq(cmd->header, >header); > + writeq(le64_to_cpu(cmd->header), >header); > } Looks good, but just to be sure this is what you intended: On 32-bit systems, this will now write val>>32 to cmd->header+4, followed by writing val&0x to cmd->header. You said earlier that the command is triggered when the final four bytes are written, but it looks like the order is wrong now. Should you use io-64-nonatomic-lo-hi.h instead of io-64-nonatomic-hi-lo.h then? Arnd
[PATCH v2 6/8] staging: fsl-mc: don't use raw device io functions
From: Laurentiu TudorAs raw device io functions are not portable and don't handle byte-order (triggering suspicion that endianness isn't handled well) switch to using the standard api. Since MC expects LE byte-order and the upper layers already take care of that, we need to trick the device io api by doing a LE -> CPU conversion just before calling it. This way, the CPU -> LE conversion done in the api puts the data back in the right byte-order. Obviously, for reads the extra step is mirrored: there's a CPU -> LE conversion following the API call. Signed-off-by: Laurentiu Tudor --- Notes: -v2 -new patch replacing https://lkml.org/lkml/2017/7/17/419 drivers/staging/fsl-mc/bus/mc-sys.c | 21 +++-- 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/staging/fsl-mc/bus/mc-sys.c b/drivers/staging/fsl-mc/bus/mc-sys.c index 195d9f3..8a6dc47 100644 --- a/drivers/staging/fsl-mc/bus/mc-sys.c +++ b/drivers/staging/fsl-mc/bus/mc-sys.c @@ -126,12 +126,15 @@ static inline void mc_write_command(struct mc_command __iomem *portal, /* copy command parameters into the portal */ for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++) - __raw_writeq(cmd->params[i], >params[i]); - /* ensure command params are committed before submitting it */ - wmb(); + /* +* Data is already in the expected LE byte-order. Do an +* extra LE -> CPU conversion so that the CPU -> LE done in +* the device io write api puts it back in the right order. +*/ + writeq_relaxed(le64_to_cpu(cmd->params[i]), >params[i]); /* submit the command by writing the header */ - __raw_writeq(cmd->header, >header); + writeq(le64_to_cpu(cmd->header), >header); } /** @@ -151,14 +154,20 @@ static inline enum mc_cmd_status mc_read_response(struct mc_command __iomem * enum mc_cmd_status status; /* Copy command response header from MC portal: */ - resp->header = __raw_readq(>header); + resp->header = cpu_to_le64(readq_relaxed(>header)); status = mc_cmd_hdr_read_status(resp); if (status != MC_CMD_STATUS_OK) return status; /* Copy command response data from MC portal: */ for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++) - resp->params[i] = __raw_readq(>params[i]); + /* +* Data is expected to be in LE byte-order. Do an +* extra CPU -> LE to revert the LE -> CPU done in +* the device io read api. +*/ + resp->params[i] = + cpu_to_le64(readq_relaxed(>params[i])); return status; } -- 2.9.4
[PATCH v2 6/8] staging: fsl-mc: don't use raw device io functions
From: Laurentiu Tudor As raw device io functions are not portable and don't handle byte-order (triggering suspicion that endianness isn't handled well) switch to using the standard api. Since MC expects LE byte-order and the upper layers already take care of that, we need to trick the device io api by doing a LE -> CPU conversion just before calling it. This way, the CPU -> LE conversion done in the api puts the data back in the right byte-order. Obviously, for reads the extra step is mirrored: there's a CPU -> LE conversion following the API call. Signed-off-by: Laurentiu Tudor --- Notes: -v2 -new patch replacing https://lkml.org/lkml/2017/7/17/419 drivers/staging/fsl-mc/bus/mc-sys.c | 21 +++-- 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/staging/fsl-mc/bus/mc-sys.c b/drivers/staging/fsl-mc/bus/mc-sys.c index 195d9f3..8a6dc47 100644 --- a/drivers/staging/fsl-mc/bus/mc-sys.c +++ b/drivers/staging/fsl-mc/bus/mc-sys.c @@ -126,12 +126,15 @@ static inline void mc_write_command(struct mc_command __iomem *portal, /* copy command parameters into the portal */ for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++) - __raw_writeq(cmd->params[i], >params[i]); - /* ensure command params are committed before submitting it */ - wmb(); + /* +* Data is already in the expected LE byte-order. Do an +* extra LE -> CPU conversion so that the CPU -> LE done in +* the device io write api puts it back in the right order. +*/ + writeq_relaxed(le64_to_cpu(cmd->params[i]), >params[i]); /* submit the command by writing the header */ - __raw_writeq(cmd->header, >header); + writeq(le64_to_cpu(cmd->header), >header); } /** @@ -151,14 +154,20 @@ static inline enum mc_cmd_status mc_read_response(struct mc_command __iomem * enum mc_cmd_status status; /* Copy command response header from MC portal: */ - resp->header = __raw_readq(>header); + resp->header = cpu_to_le64(readq_relaxed(>header)); status = mc_cmd_hdr_read_status(resp); if (status != MC_CMD_STATUS_OK) return status; /* Copy command response data from MC portal: */ for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++) - resp->params[i] = __raw_readq(>params[i]); + /* +* Data is expected to be in LE byte-order. Do an +* extra CPU -> LE to revert the LE -> CPU done in +* the device io read api. +*/ + resp->params[i] = + cpu_to_le64(readq_relaxed(>params[i])); return status; } -- 2.9.4