External ECC engines & Macronix support
Subsystems (4)
Miquel Raynal
maintainerv9 cover External ECC engines & Macronix support
Hello all,
I've applied the beginning of the series (bindings + ECC part) in a branch named spi-mem-ecc on the MTD korg repository. After discussing a bit more some details, I decided not to rush and did not apply the second halve of the series for v5.17. Here is now the second halve again in a hopefully better shape. I am expecting a few acks on this one and I'll then rebase spi-mem-ecc on top of v5.18-rc1, apply these patches and share them with the spi tree.
Cheers,
Miquèl
Changes in v9:
* Dropped the patch from Pratyush, keeping the DTR check in spi_mem_dtr_supports_op() as it was before the series. Pratyush will later reroll its entire series on top of this.
* Changed the location of the spi_controller_mem_caps capabilities to be in the spi-controller structure, as initially advised by Mark, then repeated by Boris and Pratyush.
Changes in v8:
* Applied this patch from Pratyush at the beginning of my series:
https://lore.kernel.org/all/[email protected]/
Made the necessary changes in the following commits.
* Changed the spi-mem-op ecc_en parameter to become ecc and match the dtr parameter. Changed its type to "u8 : 1" as well for the same reason. Moved it to the data sub-structure as advised by Pratyush.
* Added the received Acks/R-by.
Changes in v7:
* Added a macro to check if the caps are present or not before accessing them. This allows for optional caps.
* Dropped the 'no-caps' instance created in v6.
* Reworked a bit all the patches using these caps to have a nice and bisectable series, like adding missing static keywords.
Changes in v6:
* Re-include the first patches because a few things have changed in the bindings. These are only style changes as Rob asked to group every property above or below the description field, which I applied to all the binding commits, but without any further update.
* Created a spi-mem capabilities structure. Put that one in the spi-mem ops strucure and ensured that all the controllers provided one.
* Created a default "no-caps" empty instance that controller drivers can point to by default.
* Dropped the spi_mem_generic_defaults_op() intermediate helper entirely (not needed anymore).
Changes in v5:
* Moved a helper in the core as it seems that it will be useful for other ECC engines as well (Xiangsheng Hou for Mediatek will need it).
* Changed the parameters of the spi_mem_generic_supports_op() function in order to take a structure as input instead of a list of arguments, which will be much easier to complement in the future if ever needed.
Changes in v4:
* The first half of the series has been left aside (all the binding changes + the external mode in the Macronix driver), now let's focus on the pipelined mode.
* Added the ecc_en spi_mem_op structure parameter in a dedicated commit.
* Introduced a new helper for supporting generically the supported ops.
* Used this new helper in the macronix driver.
* By default all the other drivers would refuse a spi_mem_op with ecc_en enabled.
Changes in v3:
* Added Mark's R-by.
* Added a commit changing the initialization order between the dirmaps and the ECC engine so that the core might now if we are using a pipelined engine or not.
* Stopped creating additional dirmaps with ECC if the engine is not a pipelined engine.
* Solved the kernel test robot reports. In particular, I added a dependency on MTD_NAND_ECC to Macronix SPI controller driver.
* Added a patch to clean the NAND controller yaml file before moving some bits to nand-chip.yaml. This addresses the comments made by Rob about the useless allOf's.
* Used platform_get_irq_byname_optional() in order to avoid useless warnings when there is no IRQ.
Changes in v2:
* Fixed the bindings and added Rob's acks when relevant.
* Added locking in the ECC engine driver.
* Brought more changes in the core in order to bring the ECC information into the spi_mem_op structure with the idea of avoiding any races between parallel calls on the same engine.
* Reorganized the ECC driver entirely in order to have a per-engine mxic structure plus a per-NAND context. This lead to a number of changes internally which cannot all be listed.
Changes since the RFC:
* Rebased on top of v5.15-rc1.
* Fixed the dirmap configuration.
* Added the various tags received.
* Fixed the bindings as reported by the robots.
* Fixed the return value of the helper counting bitflips.
* Included a fix from Jaime Liao in the external pattern logic.
* Added the yaml conversion of Macronix SPI controller description.
* Added the yaml conversion of the SPI-NAND description.
* Created a nand-chip.yaml file to share properties between SPI-NAND and raw NAND.
Miquel Raynal (13):
spi: spi-mem: Introduce a capability structure
spi: spi-mem: Check the controller extra capabilities
spi: cadence-quadspi: Provide a capability structure
spi: mxic: Provide a capability structure
spi: spi-mem: Kill the spi_mem_dtr_supports_op() helper
spi: spi-mem: Add an ecc parameter to the spi_mem_op structure
mtd: spinand: Delay a little bit the dirmap creation
mtd: spinand: Create direct mapping descriptors for ECC operations
spi: mxic: Fix the transmit path
spi: mxic: Create a helper to configure the controller before an
operation
spi: mxic: Create a helper to ease the start of an operation
spi: mxic: Add support for direct mapping
spi: mxic: Add support for pipelined ECC operations
drivers/mtd/nand/spi/core.c | 51 ++++- drivers/spi/Kconfig | 2 +- drivers/spi/spi-cadence-quadspi.c | 10 +- drivers/spi/spi-mem.c | 32 +-- drivers/spi/spi-mxic.c | 340 ++++++++++++++++++++++++------ include/linux/mtd/spinand.h | 2 + include/linux/spi/spi-mem.h | 27 ++- include/linux/spi/spi.h | 3 + 8 files changed, 367 insertions(+), 100 deletions(-)
Signature · 1 line
2.27.0
Miquel Raynal
maintainerPATCH v9 1/13 spi: spi-mem: Introduce a capability structure
Create a spi_controller_mem_caps structure and put it within the spi_controller structure close to the spi_controller_mem_ops strucure. So far the only field in this structure is the support for dtr operations, but soon we will add another parameter.
Also create a helper to parse the capabilities and check if the requested capability has been set or not.
--- include/linux/spi/spi-mem.h | 11 +++++++++++ include/linux/spi/spi.h | 3 +++ 2 files changed, 14 insertions(+)
include/linux/spi/spi-mem.h +11 -0
@@ -285,6 +285,17 @@ struct spi_controller_mem_ops { unsigned long timeout_ms); }; +/** +* struct spi_controller_mem_caps - SPI memory controller capabilities +* @dtr: Supports DTR operations +*/ +struct spi_controller_mem_caps { +bool dtr; +}; + +#define spi_mem_controller_is_capable (ctlr, cap) \ + ((ctlr)->mem_caps && (ctlr)->mem_caps->cap) +/** * struct spi_mem_driver - SPI memory driver * @spidrv: inherit from a SPI driver
include/linux/spi/spi.h +3 -0
@@ -23,6 +23,7 @@ struct software_node;struct spi_controller ;struct spi_transfer ;struct spi_controller_mem_ops ; +struct spi_controller_mem_caps ;/* * INTERFACES between SPI master-side drivers and SPI slave protocol handlers,
@@ -419,6 +420,7 @@ extern struct spi_device *spi_new_ancillary_device(struct spi_device *spi, u8 ch* @mem_ops: optimized/dedicated operations for interactions with SPI memory. * This field is optional and should only be implemented if the * controller has native support for memory like operations. +* @mem_caps: controller capabilities for the handling of memory operations. * @unprepare_message: undo any work done by prepare_message(). * @slave_abort: abort the ongoing transfer request on an SPI slave controller * @cs_gpios: LEGACY: array of GPIO descs to use as chip select lines; one per
@@ -640,6 +642,7 @@ struct spi_controller {/* Optimized handlers for SPI memory-like operations. */ const struct spi_controller_mem_ops *mem_ops; +const struct spi_controller_mem_caps *mem_caps;/* gpio chip select */ int *cs_gpios;
Signature · 1 line
2.27.0
Re: [PATCH v9 01/13] spi: spi-mem: Introduce a capability structure
Quoted 9 lines · Miquel Raynal
Create a
spi_controller_mem_capsstructure and put it within thespi_controllerstructure close to thespi_controller_mem_opsstrucure. So far the only field in this structure is the support for dtr operations, but soon we will add another parameter.Also create a helper to parse the capabilities and check if the requested capability has been set or not.
Signed-off-by Miquel Raynal <[email protected]>
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments Inc.
Re: [PATCH v9 01/13] spi: spi-mem: Introduce a capability structure
In reply to Miquel RaynalQuoted 10 lines · Miquel Raynal
Create a
spi_controller_mem_capsstructure and put it within thespi_controllerstructure close to thespi_controller_mem_opsstrucure. So far the only field in this structure is the support for dtr operations, but soon we will add another parameter.Also create a helper to parse the capabilities and check if the requested capability has been set or not.
Signed-off-by Miquel Raynal <[email protected]>Reviewed-by Pratyush Yadav <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-mem-ecc.
Miquel
Mark Brown
maintainerRe: [PATCH v9 01/13] spi: spi-mem: Introduce a capability structure
Quoted 1 line · Miquel Raynal
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-mem-ecc.
I was hoping to review this stuff? I think I was expecting it to be rebased after the merge window...
Miquel Raynal
maintainerRe: [PATCH v9 01/13] spi: spi-mem: Introduce a capability structure
Hi Mark,
[email protected] wrote on Wed, 26 Jan 2022 16:35:30 +0000:
Quoted 6 lines · Miquel Raynal
Quoted 2 lines
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-mem-ecc.
I was hoping to review this stuff? I think I was expecting it to be rebased after the merge window...
Sorry for the misunderstanding, I thought you were fine with these spi bits so I didn't ping you before applying. Can you review the v9 then? There is nothing different in the series I applied.
Depending on the outcome I'll either fix inline if you ack the patches or drop the patches from that branch and send a v10 otherwise.
Thanks,
Miquèl
Mark Brown
maintainerRe: [PATCH v9 01/13] spi: spi-mem: Introduce a capability structure
Quoted 9 lines · Miquel Raynal
Quoted 2 lines
I was hoping to review this stuff? I think I was expecting it to be rebased after the merge window...
Sorry for the misunderstanding, I thought you were fine with these spi bits so I didn't ping you before applying. Can you review the v9 then? There is nothing different in the series I applied.
Depending on the outcome I'll either fix inline if you ack the patches or drop the patches from that branch and send a v10 otherwise.
I don't recall seeing anything but I'd dropped them due to the merge window, like I say I was expecting a repost for -rc1. I'll try to fish them out and have a look tomorrow.
Miquel Raynal
maintainerRe: [PATCH v9 01/13] spi: spi-mem: Introduce a capability structure
Hi Mark,
[email protected] wrote on Wed, 26 Jan 2022 17:41:31 +0000:
Quoted 9 lines · Miquel Raynal
Quoted 7 lines
Quoted 3 lines
I was hoping to review this stuff? I think I was expecting it to be rebased after the merge window...
Sorry for the misunderstanding, I thought you were fine with these spi bits so I didn't ping you before applying. Can you review the v9 then? There is nothing different in the series I applied.
Quoted 6 lines
Quoted 2 lines
Depending on the outcome I'll either fix inline if you ack the patches or drop the patches from that branch and send a v10 otherwise.
I don't recall seeing anything but I'd dropped them due to the merge window, like I say I was expecting a repost for -rc1. I'll try to fish them out and have a look tomorrow.
No worries, I've re-sent exactly the patches currently applied on the spi-mem-ecc branch (so the rebased ones). Take your time for reviewing them and depending on how it goes I will introduce your Acks inline or send a v11 if it is needed.
Thanks,
Miquèl
Miquel Raynal
maintainerRe: [PATCH v9 01/13] spi: spi-mem: Introduce a capability structure
In reply to Mark BrownHi Mark,
[email protected] wrote on Wed, 26 Jan 2022 17:41:31 +0000:
Quoted 9 lines · Miquel Raynal
Quoted 7 lines
Quoted 3 lines
I was hoping to review this stuff? I think I was expecting it to be rebased after the merge window...
Sorry for the misunderstanding, I thought you were fine with these spi bits so I didn't ping you before applying. Can you review the v9 then? There is nothing different in the series I applied.
Quoted 6 lines
Quoted 2 lines
Depending on the outcome I'll either fix inline if you ack the patches or drop the patches from that branch and send a v10 otherwise.
I don't recall seeing anything but I'd dropped them due to the merge window, like I say I was expecting a repost for -rc1. I'll try to fish them out and have a look tomorrow.
No worries, I've re-sent exactly the patches currently applied on the spi-mem-ecc branch (so the rebased ones). Take your time for reviewing them and depending on how it goes I will introduce your Acks inline or send a v11 if it is needed.
Thanks,
Miquèl
Miquel Raynal
maintainerPATCH v9 2/13 spi: spi-mem: Check the controller extra capabilities
In reply to Miquel RaynalControllers can now provide a spi-mem capabilities structure. Let's make use of it in spi_mem_controller_default_supports_op(). As we want to check for DTR operations as well as normal operations in a single helper, let's pull the necessary checks from spi_mem_dtr_supports_op() for now.
However, because no controller provide these extra capabilities, this change has no effect so far.
--- drivers/spi/spi-mem.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/spi/spi-mem.c +13 -4
@@ -173,11 +173,20 @@ EXPORT_SYMBOL_GPL(spi_mem_dtr_supports_op);bool spi_mem_default_supports_op (struct spi_mem *mem,const struct spi_mem_op *op) { -if (op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr) -return false; +struct spi_controller *ctlr = mem->spi->controller; +bool op_is_dtr = + op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr; -if (op->cmd.nbytes !=1 ) -return false; +if (op_is_dtr) { +if (!spi_mem_controller_is_capable (ctlr, dtr)) +return false; + +if (op->cmd.nbytes !=2 ) +return false; + }else { +if (op->cmd.nbytes !=1 ) +return false; + }return spi_mem_check_buswidth (mem, op); }
Signature · 1 line
2.27.0
Re: [PATCH v9 02/13] spi: spi-mem: Check the controller extra capabilities
Quoted 10 lines · Miquel Raynal
Controllers can now provide a spi-mem capabilities structure. Let's make use of it in
spi_mem_controller_default_supports_op(). As we want to check for DTR operations as well as normal operations in a single helper, let's pull the necessary checks fromspi_mem_dtr_supports_op()for now.However, because no controller provide these extra capabilities, this change has no effect so far.
Signed-off-by Miquel Raynal <[email protected]>
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments Inc.
Re: [PATCH v9 02/13] spi: spi-mem: Check the controller extra capabilities
In reply to Miquel RaynalQuoted 11 lines · Miquel Raynal
Controllers can now provide a spi-mem capabilities structure. Let's make use of it in
spi_mem_controller_default_supports_op(). As we want to check for DTR operations as well as normal operations in a single helper, let's pull the necessary checks fromspi_mem_dtr_supports_op()for now.However, because no controller provide these extra capabilities, this change has no effect so far.
Signed-off-by Miquel Raynal <[email protected]>Reviewed-by Pratyush Yadav <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-mem-ecc.
Miquel
Miquel Raynal
maintainerPATCH v9 3/13 spi: cadence-quadspi: Provide a capability structure
In reply to Miquel RaynalThis controller has DTR support, so advertize it with a capability now that the spi-controller structure contains this new field. This will later be used by the core to discriminate whether an operation is supported or not, in a more generic way than having different helpers.
--- drivers/spi/spi-cadence-quadspi.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/spi/spi-cadence-quadspi.c +5 -0
@@ -1394,6 +1394,10 @@ static const struct spi_controller_mem_ops cqspi_mem_ops = { .supports_op = cqspi_supports_mem_op, }; +static const struct spi_controller_mem_caps cqspi_mem_caps = { + .dtr = true, +}; +static int cqspi_setup_flash (struct cqspi_st *cqspi) {struct platform_device *pdev = cqspi->pdev;
@@ -1451,6 +1455,7 @@ static int cqspi_probe(struct platform_device *pdev) } master->mode_bits =SPI_RX_QUAD |SPI_RX_DUAL ; master->mem_ops = &cqspi_mem_ops; + master->mem_caps = &cqspi_mem_caps; master->dev.of_node = pdev->dev.of_node; cqspi =spi_master_get_devdata (master);
Signature · 1 line
2.27.0
Re: [PATCH v9 03/13] spi: cadence-quadspi: Provide a capability structure
Quoted 7 lines · Miquel Raynal
This controller has DTR support, so advertize it with a capability now that the spi-controller structure contains this new field. This will later be used by the core to discriminate whether an operation is supported or not, in a more generic way than having different helpers.
Signed-off-by Miquel Raynal <[email protected]>Reviewed-by Pratyush Yadav <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-mem-ecc.
Miquel
Miquel Raynal
maintainerPATCH v9 4/13 spi: mxic: Provide a capability structure
In reply to Miquel RaynalThis controller has DTR support, so advertize it with a capability now that the spi-controller structure contains this new field. This will later be used by the core to discriminate whether an operation is supported or not, in a more generic way than having different helpers.
--- drivers/spi/spi-mxic.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/spi/spi-mxic.c +5 -0
@@ -448,6 +448,10 @@ static const struct spi_controller_mem_ops mxic_spi_mem_ops = { .exec_op = mxic_spi_mem_exec_op, }; +static const struct spi_controller_mem_caps mxic_spi_mem_caps = { + .dtr = true, +}; +static void mxic_spi_set_cs (struct spi_device *spi,bool lvl) {struct mxic_spi *mxic =spi_master_get_devdata (spi->master);
@@ -580,6 +584,7 @@ static int mxic_spi_probe(struct platform_device *pdev) master->num_chipselect =1 ; master->mem_ops = &mxic_spi_mem_ops; + master->mem_caps = &mxic_spi_mem_caps; master->set_cs = mxic_spi_set_cs; master->transfer_one = mxic_spi_transfer_one;
Signature · 1 line
2.27.0
Re: [PATCH v9 04/13] spi: mxic: Provide a capability structure
Quoted 6 lines · Miquel Raynal
This controller has DTR support, so advertize it with a capability now that the spi-controller structure contains this new field. This will later be used by the core to discriminate whether an operation is supported or not, in a more generic way than having different helpers.
Signed-off-by Miquel Raynal <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-mem-ecc.
Miquel
Miquel Raynal
maintainerPATCH v9 5/13 spi: spi-mem: Kill the spi_mem_dtr_supports_op() helper
In reply to Miquel RaynalNow that spi_mem_default_supports_op() has access to the static controller capabilities (relating to memory operations), and now that these capabilities have been filled by the relevant controllers, there is no need for a specific helper checking only DTR operations, so let's just kill spi_mem_dtr_supports_op() and simply use spi_mem_default_supports_op() instead.
--- drivers/spi/spi-cadence-quadspi.c | 5 +---- drivers/spi/spi-mem.c | 10 ---------- drivers/spi/spi-mxic.c | 10 +--------- include/linux/spi/spi-mem.h | 11 ----------- 4 files changed, 2 insertions(+), 34 deletions(-)
drivers/spi/spi-cadence-quadspi.c +1 -4
@@ -1252,10 +1252,7 @@ static bool cqspi_supports_mem_op(struct spi_mem *mem,if (!(all_true || all_false))return false; -if (all_true) -return spi_mem_dtr_supports_op (mem, op); -else -return spi_mem_default_supports_op (mem, op); +return spi_mem_default_supports_op (mem, op); } static int cqspi_of_get_flash_pdata(struct platform_device *pdev,
drivers/spi/spi-mem.c +0 -10
@@ -160,16 +160,6 @@ static bool spi_mem_check_buswidth(struct spi_mem *mem,return true; } -bool spi_mem_dtr_supports_op (struct spi_mem *mem, -const struct spi_mem_op *op) -{ -if (op->cmd.nbytes !=2 ) -return false; - -return spi_mem_check_buswidth (mem, op); -} -EXPORT_SYMBOL_GPL (spi_mem_dtr_supports_op); -bool spi_mem_default_supports_op (struct spi_mem *mem,const struct spi_mem_op *op) {
drivers/spi/spi-mxic.c +1 -9
@@ -335,8 +335,6 @@ static int mxic_spi_data_xfer(struct mxic_spi *mxic, const void *txbuf,static bool mxic_spi_mem_supports_op (struct spi_mem *mem,const struct spi_mem_op *op) { -bool all_false; -if (op->data.buswidth >8 || op->addr.buswidth >8 || op->dummy.buswidth >8 || op->cmd.buswidth >8 )return false;
@@ -348,13 +346,7 @@ static bool mxic_spi_mem_supports_op(struct spi_mem *mem,if (op->addr.nbytes >7 )return false; - all_false = !op->cmd.dtr && !op->addr.dtr && !op->dummy.dtr && - !op->data.dtr; - -if (all_false) -return spi_mem_default_supports_op (mem, op); -else -return spi_mem_dtr_supports_op (mem, op); +return spi_mem_default_supports_op (mem, op); } static int mxic_spi_mem_exec_op(struct spi_mem *mem,
include/linux/spi/spi-mem.h +0 -11
@@ -330,10 +330,6 @@ void spi_controller_dma_unmap_mem_op_data(struct spi_controller *ctlr,bool spi_mem_default_supports_op (struct spi_mem *mem,const struct spi_mem_op *op); - -bool spi_mem_dtr_supports_op (struct spi_mem *mem, -const struct spi_mem_op *op); -#else static inline int spi_controller_dma_map_mem_op_data(struct spi_controller *ctlr,
@@ -356,13 +352,6 @@ bool spi_mem_default_supports_op(struct spi_mem *mem, {return false; } - -static inline -bool spi_mem_dtr_supports_op (struct spi_mem *mem, -const struct spi_mem_op *op) -{ -return false; -}#endif /* CONFIG_SPI_MEM */ int spi_mem_adjust_op_size (struct spi_mem *mem,struct spi_mem_op *op);
Signature · 1 line
2.27.0
Re: [PATCH v9 05/13] spi: spi-mem: Kill the spi_mem_dtr_supports_op() helper
Quoted 9 lines · Miquel Raynal
Now that
spi_mem_default_supports_op()has access to the static controller capabilities (relating to memory operations), and now that these capabilities have been filled by the relevant controllers, there is no need for a specific helper checking only DTR operations, so let's just killspi_mem_dtr_supports_op()and simply usespi_mem_default_supports_op()instead.Signed-off-by Miquel Raynal <[email protected]>Reviewed-by Pratyush Yadav <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-mem-ecc.
Miquel
Miquel Raynal
maintainerPATCH v9 6/13 spi: spi-mem: Add an ecc parameter to the spi_mem_op structure
In reply to Miquel RaynalSoon the SPI-NAND core will need a way to request a SPI controller to enable ECC support for a given operation. This is because of the pipelined integration of certain ECC engines, which are directly managed by the SPI controller itself.
Introduce a spi_mem_op additional field for this purpose: ecc.
So far this field is left unset and checked to be false by all the SPI controller drivers in their ->supports_op() hook, as they all call spi_mem_default_supports_op().
--- drivers/spi/spi-mem.c | 5 +++++ include/linux/spi/spi-mem.h | 5 +++++ 2 files changed, 10 insertions(+)
drivers/spi/spi-mem.c +5 -0
@@ -178,6 +178,11 @@ bool spi_mem_default_supports_op(struct spi_mem *mem,return false; } +if (op->data.ecc) { +if (!spi_mem_controller_is_capable (ctlr, ecc)) +return false; + } +return spi_mem_check_buswidth (mem, op); }EXPORT_SYMBOL_GPL (spi_mem_default_supports_op);
include/linux/spi/spi-mem.h +5 -0
@@ -89,6 +89,7 @@ enum spi_mem_data_dir {* @dummy.dtr: whether the dummy bytes should be sent in DTR mode or not * @data.buswidth: number of IO lanes used to send/receive the data * @data.dtr: whether the data should be sent in DTR mode or not +* @data.ecc: whether error correction is required or not * @data.dir: direction of the transfer * @data.nbytes: number of data bytes to send/receive. Can be zero if the * operation does not involve transferring data
@@ -119,6 +120,7 @@ struct spi_mem_op {struct {u8 buswidth;u8 dtr :1 ; +u8 ecc :1 ;enum spi_mem_data_dir dir;unsigned int nbytes;union {
@@ -126,6 +128,7 @@ struct spi_mem_op {const void *out; } buf; } data; + };#define SPI_MEM_OP (__cmd, __addr, __dummy, __data) \
@@ -288,9 +291,11 @@ struct spi_controller_mem_ops {/** * struct spi_controller_mem_caps - SPI memory controller capabilities * @dtr: Supports DTR operations +* @ecc: Supports operations with error correction */ struct spi_controller_mem_caps {bool dtr; +bool ecc; };#define spi_mem_controller_is_capable (ctlr, cap) \
Signature · 1 line
2.27.0
Re: [PATCH v9 06/13] spi: spi-mem: Add an ecc parameter to the spi_mem_op structure
Quoted 23 lines · On Tue, 4 Jan 2022 09:36:24 +0100 Miquel Raynal <[email protected]>…
Soon the SPI-NAND core will need a way to request a SPI controller to enable ECC support for a given operation. This is because of the pipelined integration of certain ECC engines, which are directly managed by the SPI controller itself.
Introduce a
spi_mem_opadditional field for this purpose: ecc.So far this field is left unset and checked to be false by all the SPI controller drivers in their ->supports_op() hook, as they all call
spi_mem_default_supports_op().Signed-off-by Miquel Raynal <[email protected]>Acked-by Pratyush Yadav <[email protected]>--- drivers/spi/spi-mem.c | 5 +++++ include/linux/spi/spi-mem.h | 5 +++++ 2 files changed, 10 insertions(+)drivers/spi/spi-mem.c +0
-0
drivers/spi/spi-mem.c bool spi_mem_default_supports_op(struct spi_mem *mem, · line 184
Quoted 7 lines
drivers/spi/spi-mem.c +4
-0@@ -178,6 +178,11 @@ bool spi_mem_default_supports_op(struct spi_mem *mem,return false; } +if (op->data.ecc) { +if (!spi_mem_controller_is_capable (ctlr, ecc)) +return false; + }
Nit:
if (op->data.ecc && !spi_mem_controller_is_capable(ctlr, ecc)) return false;
Quoted 44 lines
drivers/spi/spi-mem.c +1
-0+return spi_mem_check_buswidth (mem, op); }EXPORT_SYMBOL_GPL (spi_mem_default_supports_op);include/linux/spi/spi-mem.h +5
-0@@ -89,6 +89,7 @@ enum spi_mem_data_dir {* @dummy.dtr: whether the dummy bytes should be sent in DTR mode or not * @data.buswidth: number of IO lanes used to send/receive the data * @data.dtr: whether the data should be sent in DTR mode or not +* @data.ecc: whether error correction is required or not * @data.dir: direction of the transfer * @data.nbytes: number of data bytes to send/receive. Can be zero if the * operation does not involve transferring data @@ -119,6 +120,7 @@ struct spi_mem_op {struct {u8 buswidth;u8 dtr :1 ; +u8 ecc :1 ;enum spi_mem_data_dir dir;unsigned int nbytes;union {@@ -126,6 +128,7 @@ struct spi_mem_op {const void *out; } buf; } data; + };#define SPI_MEM_OP (__cmd, __addr, __dummy, __data) \@@ -288,9 +291,11 @@ struct spi_controller_mem_ops {/** * struct spi_controller_mem_caps - SPI memory controller capabilities * @dtr: Supports DTR operations +* @ecc: Supports operations with error correction */ struct spi_controller_mem_caps {bool dtr; +bool ecc; };#define spi_mem_controller_is_capable (ctlr, cap) \
Miquel Raynal
maintainerRe: [PATCH v9 06/13] spi: spi-mem: Add an ecc parameter to the spi_mem_op structure
Hello Boris,
[email protected] wrote on Tue, 4 Jan 2022 10:02:30 +0100:
Quoted 36 lines
Quoted 23 lines · On Tue, 4 Jan 2022 09:36:24 +0100 Miquel Raynal <[email protected]>…
Soon the SPI-NAND core will need a way to request a SPI controller to enable ECC support for a given operation. This is because of the pipelined integration of certain ECC engines, which are directly managed by the SPI controller itself.
Introduce a
spi_mem_opadditional field for this purpose: ecc.So far this field is left unset and checked to be false by all the SPI controller drivers in their ->supports_op() hook, as they all call
spi_mem_default_supports_op().Signed-off-by Miquel Raynal <[email protected]>Acked-by Pratyush Yadav <[email protected]>--- drivers/spi/spi-mem.c | 5 +++++ include/linux/spi/spi-mem.h | 5 +++++ 2 files changed, 10 insertions(+)drivers/spi/spi-mem.c +0
-0drivers/spi/spi-mem.c bool spi_mem_default_supports_op(struct spi_mem *mem, · line 184
Quoted 7 lines
drivers/spi/spi-mem.c +4
-0@@ -178,6 +178,11 @@ bool spi_mem_default_supports_op(struct spi_mem *mem,return false; } +if (op->data.ecc) { +if (!spi_mem_controller_is_capable (ctlr, ecc)) +return false; + }Nit:
Quoted 4 lines
if (op->data.ecc && !spi_mem_controller_is_capable(ctlr, ecc)) return false;
Actually I wanted on purpose to distinguish the different checks:
if (dtr) {
do something here;
}if (ecc) {
do something else;
}return;
and in order to keep them tidy I used independent if statements within each of these :)
Quoted 43 lines
Quoted 43 lines
drivers/spi/spi-mem.c +1
-0+return spi_mem_check_buswidth (mem, op); }EXPORT_SYMBOL_GPL (spi_mem_default_supports_op);include/linux/spi/spi-mem.h +5
-0@@ -89,6 +89,7 @@ enum spi_mem_data_dir {* @dummy.dtr: whether the dummy bytes should be sent in DTR mode or not * @data.buswidth: number of IO lanes used to send/receive the data * @data.dtr: whether the data should be sent in DTR mode or not +* @data.ecc: whether error correction is required or not * @data.dir: direction of the transfer * @data.nbytes: number of data bytes to send/receive. Can be zero if the * operation does not involve transferring data @@ -119,6 +120,7 @@ struct spi_mem_op {struct {u8 buswidth;u8 dtr :1 ; +u8 ecc :1 ;enum spi_mem_data_dir dir;unsigned int nbytes;union {@@ -126,6 +128,7 @@ struct spi_mem_op {const void *out; } buf; } data; + };#define SPI_MEM_OP (__cmd, __addr, __dummy, __data) \@@ -288,9 +291,11 @@ struct spi_controller_mem_ops {/** * struct spi_controller_mem_caps - SPI memory controller capabilities * @dtr: Supports DTR operations +* @ecc: Supports operations with error correction */ struct spi_controller_mem_caps {bool dtr; +bool ecc; };
Quoted 2 lines
include/linux/spi/spi-mem.h struct spi_controller_mem_ops { · line 301
Quoted 1 line
include/linux/spi/spi-mem.h +0
-0#define spi_mem_controller_is_capable (ctlr, cap) \
Thanks,
Miquèl
Re: [PATCH v9 06/13] spi: spi-mem: Add an ecc parameter to the spi_mem_op structure
In reply to Miquel RaynalQuoted 5 lines · Miquel Raynal
Soon the SPI-NAND core will need a way to request a SPI controller to enable ECC support for a given operation. This is because of the pipelined integration of certain ECC engines, which are directly managed by the SPI controller itself.
Quoted 8 lines
Introduce a
spi_mem_opadditional field for this purpose: ecc.So far this field is left unset and checked to be false by all the SPI controller drivers in their ->supports_op() hook, as they all call
spi_mem_default_supports_op().Signed-off-by Miquel Raynal <[email protected]>Acked-by Pratyush Yadav <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-mem-ecc.
Miquel
Miquel Raynal
maintainerPATCH v9 7/13 mtd: spinand: Delay a little bit the dirmap creation
In reply to Miquel RaynalAs we will soon tweak the dirmap creation to act a little bit differently depending on the picked ECC engine, we need to initialize dirmaps after ECC engines. This should not have any effect as dirmaps are not yet used at this point.
--- drivers/mtd/nand/spi/core.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/mtd/nand/spi/core.c +8 -8
@@ -1209,14 +1209,6 @@ static int spinand_init(struct spinand_device *spinand)if (ret) goto err_free_bufs; - ret =spinand_create_dirmaps (spinand); -if (ret) { -dev_err (dev, -"Failed to create direct mappings for read/write operations (err = %d)\n" , - ret); - goto err_manuf_cleanup; - } - ret =nanddev_init (nand, &spinand_ops,THIS_MODULE );if (ret) goto err_manuf_cleanup;
@@ -1251,6 +1243,14 @@ static int spinand_init(struct spinand_device *spinand) mtd->ecc_strength =nanddev_get_ecc_conf (nand)->strength; mtd->ecc_step_size =nanddev_get_ecc_conf (nand)->step_size; + ret =spinand_create_dirmaps (spinand); +if (ret) { +dev_err (dev, +"Failed to create direct mappings for read/write operations (err = %d)\n" , + ret); + goto err_cleanup_ecc_engine; + } +return 0 ; err_cleanup_ecc_engine:
Signature · 1 line
2.27.0
Re: [PATCH v9 07/13] mtd: spinand: Delay a little bit the dirmap creation
Quoted 6 lines · Miquel Raynal
As we will soon tweak the dirmap creation to act a little bit differently depending on the picked ECC engine, we need to initialize dirmaps after ECC engines. This should not have any effect as dirmaps are not yet used at this point.
Signed-off-by Miquel Raynal <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-mem-ecc.
Miquel
Miquel Raynal
maintainerPATCH v9 8/13 mtd: spinand: Create direct mapping descriptors for ECC operations
In reply to Miquel RaynalIn order for pipelined ECC engines to be able to enable/disable the ECC engine only when needed and avoid races when future parallel-operations will be supported, we need to provide the information about the use of the ECC engine in the direct mapping hooks. As direct mapping configurations are meant to be static, it is best to create two new
mappings: one for regular 'raw' accesses and one for accesses involving correction. It is up to the driver to use or not the new ECC enable boolean contained in the spi-mem operation.
As dirmaps are not free (they consume a few pages of MMIO address space) and because these extra entries are only meant to be used by pipelined engines, let's limit their use to this specific type of engine and save a bit of memory with all the other setups.
--- drivers/mtd/nand/spi/core.c | 35 +++++++++++++++++++++++++++++++++-- include/linux/mtd/spinand.h | 2 ++ 2 files changed, 35 insertions(+), 2 deletions(-)
drivers/mtd/nand/spi/core.c +33 -2
@@ -381,7 +381,10 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand, } } - rdesc = spinand->dirmaps[req->pos.plane].rdesc; +if (req->mode ==MTD_OPS_RAW ) + rdesc = spinand->dirmaps[req->pos.plane].rdesc; +else + rdesc = spinand->dirmaps[req->pos.plane].rdesc_ecc;while (nbytes) { ret =spi_mem_dirmap_read (rdesc, column, nbytes, buf);
@@ -452,7 +455,10 @@ static int spinand_write_to_cache_op(struct spinand_device *spinand, req->ooblen); } - wdesc = spinand->dirmaps[req->pos.plane].wdesc; +if (req->mode ==MTD_OPS_RAW ) + wdesc = spinand->dirmaps[req->pos.plane].wdesc; +else + wdesc = spinand->dirmaps[req->pos.plane].wdesc_ecc;while (nbytes) { ret =spi_mem_dirmap_write (wdesc, column, nbytes, buf);
@@ -866,6 +872,31 @@ static int spinand_create_dirmap(struct spinand_device *spinand, spinand->dirmaps[plane].rdesc = desc; +if (nand->ecc.engine->integration !=NAND_ECC_ENGINE_INTEGRATION_PIPELINED ) { + spinand->dirmaps[plane].wdesc_ecc = spinand->dirmaps[plane].wdesc; + spinand->dirmaps[plane].rdesc_ecc = spinand->dirmaps[plane].rdesc; + +return 0 ; + } + + info.op_tmpl = *spinand->op_templates.update_cache; + info.op_tmpl.data.ecc = true; + desc =devm_spi_mem_dirmap_create (&spinand->spimem->spi->dev, + spinand->spimem, &info); +if (IS_ERR (desc)) +return PTR_ERR (desc); + + spinand->dirmaps[plane].wdesc_ecc = desc; + + info.op_tmpl = *spinand->op_templates.read_cache; + info.op_tmpl.data.ecc = true; + desc =devm_spi_mem_dirmap_create (&spinand->spimem->spi->dev, + spinand->spimem, &info); +if (IS_ERR (desc)) +return PTR_ERR (desc); + + spinand->dirmaps[plane].rdesc_ecc = desc; +return 0 ; }
include/linux/mtd/spinand.h +2 -0
@@ -389,6 +389,8 @@ struct spinand_info {struct spinand_dirmap {struct spi_mem_dirmap_desc *wdesc;struct spi_mem_dirmap_desc *rdesc; +struct spi_mem_dirmap_desc *wdesc_ecc; +struct spi_mem_dirmap_desc *rdesc_ecc; };/**
Signature · 1 line
2.27.0
Re: [PATCH v9 08/13] mtd: spinand: Create direct mapping descriptors for ECC operations
Quoted 9 lines · Miquel Raynal
In order for pipelined ECC engines to be able to enable/disable the ECC engine only when needed and avoid races when future parallel-operations will be supported, we need to provide the information about the use of the ECC engine in the direct mapping hooks. As direct mapping configurations are meant to be static, it is best to create two new
mappings: one for regular 'raw' accesses and one for accesses involving correction. It is up to the driver to use or not the new ECC enable boolean contained in the spi-mem operation.
Quoted 6 lines
As dirmaps are not free (they consume a few pages of MMIO address space) and because these extra entries are only meant to be used by pipelined engines, let's limit their use to this specific type of engine and save a bit of memory with all the other setups.
Signed-off-by Miquel Raynal <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-mem-ecc.
Miquel
Miquel Raynal
maintainerPATCH v9 9/13 spi: mxic: Fix the transmit path
In reply to Miquel RaynalBy working with external hardware ECC engines, we figured out that Under certain circumstances, it is needed for the SPI controller to check INT_TX_EMPTY and INT_RX_NOT_EMPTY in both receive and transmit path (not only in the receive path). The delay penalty being negligible, move this code in the common path.
--- drivers/spi/spi-mxic.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-)
drivers/spi/spi-mxic.c +12 -16
@@ -304,25 +304,21 @@ static int mxic_spi_data_xfer(struct mxic_spi *mxic, const void *txbuf,writel (data, mxic->regs +TXD (nbytes %4 )); + ret =readl_poll_timeout (mxic->regs +INT_STS , sts, + sts &INT_TX_EMPTY ,0 ,USEC_PER_SEC ); +if (ret) +return ret; + + ret =readl_poll_timeout (mxic->regs +INT_STS , sts, + sts &INT_RX_NOT_EMPTY ,0 , +USEC_PER_SEC ); +if (ret) +return ret; + + data =readl (mxic->regs +RXD );if (rxbuf) { - ret =readl_poll_timeout (mxic->regs +INT_STS , sts, - sts &INT_TX_EMPTY ,0 , -USEC_PER_SEC ); -if (ret) -return ret; - - ret =readl_poll_timeout (mxic->regs +INT_STS , sts, - sts &INT_RX_NOT_EMPTY ,0 , -USEC_PER_SEC ); -if (ret) -return ret; - - data =readl (mxic->regs +RXD ); data >>= (8 * (4 - nbytes));memcpy (rxbuf + pos, &data, nbytes); -WARN_ON (readl (mxic->regs +INT_STS ) &INT_RX_NOT_EMPTY ); - }else { -readl (mxic->regs +RXD ); }WARN_ON (readl (mxic->regs +INT_STS ) &INT_RX_NOT_EMPTY );
Signature · 1 line
2.27.0
Re: [PATCH v9 09/13] spi: mxic: Fix the transmit path
Quoted 6 lines · Miquel Raynal
By working with external hardware ECC engines, we figured out that Under certain circumstances, it is needed for the SPI controller to check
INT_TX_EMPTYandINT_RX_NOT_EMPTYin both receive and transmit path (not only in the receive path). The delay penalty being negligible, move this code in the common path.
Quoted 6 lines
Fixes b942d80b0a39 ("spi: Add MXIC controller driver")Suggested-by Mason Yang <[email protected]>Signed-off-by Miquel Raynal <[email protected]>Reviewed-by Zhengxun Li <[email protected]>Reviewed-by Mark Brown <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-mem-ecc.
Miquel
Miquel Raynal
maintainerPATCH v9 10/13 spi: mxic: Create a helper to configure the controller before an operation
In reply to Miquel RaynalCreate the mxic_spi_set_hc_cfg() helper to configure the HC_CFG register. This helper will soon be used by the dirmap implementation and having this code factorized out earlier will clarify this addition.
--- drivers/spi/spi-mxic.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-)
drivers/spi/spi-mxic.c +19 -12
@@ -280,6 +280,22 @@ static void mxic_spi_hw_init(struct mxic_spi *mxic) mxic->regs + HC_CFG); } +static u32 mxic_spi_prep_hc_cfg (struct spi_device *spi,u32 flags) +{ +int nio =1 ; + +if (spi->mode & (SPI_TX_OCTAL |SPI_RX_OCTAL )) + nio =8 ; +else if (spi->mode & (SPI_TX_QUAD |SPI_RX_QUAD )) + nio =4 ; +else if (spi->mode & (SPI_TX_DUAL |SPI_RX_DUAL )) + nio =2 ; + +return flags |HC_CFG_NIO (nio) | +HC_CFG_TYPE (spi->chip_select,HC_CFG_TYPE_SPI_NOR ) | +HC_CFG_SLV_ACT (spi->chip_select) |HC_CFG_IDLE_SIO_LVL (1 ); +} +static int mxic_spi_data_xfer (struct mxic_spi *mxic,const void *txbuf,void *rxbuf,unsigned int len) {
@@ -349,7 +365,7 @@ static int mxic_spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) {struct mxic_spi *mxic =spi_master_get_devdata (mem->spi->master); -int nio =1 , i, ret; +int i, ret;u32 ss_ctrl;u8 addr[8 ], cmd[2 ];
@@ -357,18 +373,9 @@ static int mxic_spi_mem_exec_op(struct spi_mem *mem,if (ret)return ret; -if (mem->spi->mode & (SPI_TX_OCTAL |SPI_RX_OCTAL )) - nio =8 ; -else if (mem->spi->mode & (SPI_TX_QUAD |SPI_RX_QUAD )) - nio =4 ; -else if (mem->spi->mode & (SPI_TX_DUAL |SPI_RX_DUAL )) - nio =2 ; - -writel (HC_CFG_NIO (nio) | -HC_CFG_TYPE (mem->spi->chip_select,HC_CFG_TYPE_SPI_NOR ) | -HC_CFG_SLV_ACT (mem->spi->chip_select) |HC_CFG_IDLE_SIO_LVL (1 ) | -HC_CFG_MAN_CS_EN , +writel (mxic_spi_prep_hc_cfg (mem->spi,HC_CFG_MAN_CS_EN ), mxic->regs +HC_CFG ); +writel (HC_EN_BIT , mxic->regs +HC_EN ); ss_ctrl = OP_CMD_BYTES(op->cmd.nbytes) |
Signature · 1 line
2.27.0
Re: [PATCH v9 10/13] spi: mxic: Create a helper to configure the controller before an operation
Quoted 6 lines · Miquel Raynal
Create the
mxic_spi_set_hc_cfg()helper to configure theHC_CFGregister. This helper will soon be used by the dirmap implementation and having this code factorized out earlier will clarify this addition.Signed-off-by Miquel Raynal <[email protected]>Reviewed-by Mark Brown <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-mem-ecc.
Miquel
Miquel Raynal
maintainerPATCH v9 11/13 spi: mxic: Create a helper to ease the start of an operation
In reply to Miquel RaynalCreate the mxic_spi_mem_prep_op_cfg() helper to provide the content to write to the register controlling the next IO command. This helper will soon be used by the dirmap implementation and having this code factorized out earlier will clarify this addition.
--- drivers/spi/spi-mxic.c | 53 +++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 24 deletions(-)
drivers/spi/spi-mxic.c +29 -24
@@ -296,6 +296,33 @@ static u32 mxic_spi_prep_hc_cfg(struct spi_device *spi, u32 flags)HC_CFG_SLV_ACT (spi->chip_select) |HC_CFG_IDLE_SIO_LVL (1 ); } +static u32 mxic_spi_mem_prep_op_cfg (const struct spi_mem_op *op) +{ +u32 cfg =OP_CMD_BYTES (op->cmd.nbytes) | +OP_CMD_BUSW (fls (op->cmd.buswidth) -1 ) | + (op->cmd.dtr ?OP_CMD_DDR :0 ); + +if (op->addr.nbytes) + cfg |=OP_ADDR_BYTES (op->addr.nbytes) | +OP_ADDR_BUSW (fls (op->addr.buswidth) -1 ) | + (op->addr.dtr ?OP_ADDR_DDR :0 ); + +if (op->dummy.nbytes) + cfg |=OP_DUMMY_CYC (op->dummy.nbytes); + +if (op->data.nbytes) { + cfg |=OP_DATA_BUSW (fls (op->data.buswidth) -1 ) | + (op->data.dtr ?OP_DATA_DDR :0 ); +if (op->data.dir ==SPI_MEM_DATA_IN ) { + cfg |=OP_READ ; +if (op->data.dtr) + cfg |=OP_DQS_EN ; + } + } + +return cfg; +} +static int mxic_spi_data_xfer (struct mxic_spi *mxic,const void *txbuf,void *rxbuf,unsigned int len) {
@@ -366,7 +393,6 @@ static int mxic_spi_mem_exec_op(struct spi_mem *mem, {struct mxic_spi *mxic =spi_master_get_devdata (mem->spi->master);int i, ret; -u32 ss_ctrl;u8 addr[8 ], cmd[2 ]; ret =mxic_spi_set_freq (mxic, mem->spi->max_speed_hz);
@@ -378,29 +404,8 @@ static int mxic_spi_mem_exec_op(struct spi_mem *mem,writel (HC_EN_BIT , mxic->regs +HC_EN ); - ss_ctrl =OP_CMD_BYTES (op->cmd.nbytes) | -OP_CMD_BUSW (fls (op->cmd.buswidth) -1 ) | - (op->cmd.dtr ?OP_CMD_DDR :0 ); - -if (op->addr.nbytes) - ss_ctrl |=OP_ADDR_BYTES (op->addr.nbytes) | -OP_ADDR_BUSW (fls (op->addr.buswidth) -1 ) | - (op->addr.dtr ?OP_ADDR_DDR :0 ); - -if (op->dummy.nbytes) - ss_ctrl |=OP_DUMMY_CYC (op->dummy.nbytes); - -if (op->data.nbytes) { - ss_ctrl |=OP_DATA_BUSW (fls (op->data.buswidth) -1 ) | - (op->data.dtr ?OP_DATA_DDR :0 ); -if (op->data.dir ==SPI_MEM_DATA_IN ) { - ss_ctrl |=OP_READ ; -if (op->data.dtr) - ss_ctrl |=OP_DQS_EN ; - } - } - -writel (ss_ctrl, mxic->regs +SS_CTRL (mem->spi->chip_select)); +writel (mxic_spi_mem_prep_op_cfg (op), + mxic->regs +SS_CTRL (mem->spi->chip_select));writel (readl (mxic->regs +HC_CFG ) |HC_CFG_MAN_CS_ASSERT , mxic->regs +HC_CFG );
Signature · 1 line
2.27.0
Re: [PATCH v9 11/13] spi: mxic: Create a helper to ease the start of an operation
Quoted 7 lines · Miquel Raynal
Create the
mxic_spi_mem_prep_op_cfg()helper to provide the content to write to the register controlling the next IO command. This helper will soon be used by the dirmap implementation and having this code factorized out earlier will clarify this addition.Signed-off-by Miquel Raynal <[email protected]>Reviewed-by Mark Brown <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-mem-ecc.
Miquel
Miquel Raynal
maintainerPATCH v9 12/13 spi: mxic: Add support for direct mapping
In reply to Miquel RaynalImplement the ->dirmap_create() and ->dirmap_read/write() hooks to provide a fast path for read and write accesses.
--- drivers/spi/spi-mxic.c | 112 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 109 insertions(+), 3 deletions(-)
drivers/spi/spi-mxic.c +109 -3
@@ -172,6 +172,11 @@ struct mxic_spi {struct clk *send_dly_clk;void __iomem *regs;u32 cur_speed_hz; +struct { +void __iomem *map; +dma_addr_t dma; +size_t size; + } linear; };static int mxic_spi_clk_enable (struct mxic_spi *mxic)
@@ -296,7 +301,8 @@ static u32 mxic_spi_prep_hc_cfg(struct spi_device *spi, u32 flags)HC_CFG_SLV_ACT (spi->chip_select) |HC_CFG_IDLE_SIO_LVL (1 ); } -static u32 mxic_spi_mem_prep_op_cfg (const struct spi_mem_op *op) +static u32 mxic_spi_mem_prep_op_cfg (const struct spi_mem_op *op, +unsigned int data_len) {u32 cfg =OP_CMD_BYTES (op->cmd.nbytes) | OP_CMD_BUSW(fls(op->cmd.buswidth) - 1) |
@@ -310,7 +316,8 @@ static u32 mxic_spi_mem_prep_op_cfg(const struct spi_mem_op *op)if (op->dummy.nbytes) cfg |=OP_DUMMY_CYC (op->dummy.nbytes); -if (op->data.nbytes) { +/* Direct mapping data.nbytes field is not populated */ +if (data_len) { cfg |=OP_DATA_BUSW (fls (op->data.buswidth) -1 ) | (op->data.dtr ?OP_DATA_DDR :0 );if (op->data.dir ==SPI_MEM_DATA_IN ) {
@@ -371,6 +378,77 @@ static int mxic_spi_data_xfer(struct mxic_spi *mxic, const void *txbuf,return 0 ; } +static ssize_t mxic_spi_mem_dirmap_read (struct spi_mem_dirmap_desc *desc, +u64 offs,size_t len,void *buf) +{ +struct mxic_spi *mxic =spi_master_get_devdata (desc->mem->spi->master); +int ret; +u32 sts; + +if (WARN_ON (offs + desc->info.offset + len >U32_MAX )) +return -EINVAL ; + +writel (mxic_spi_prep_hc_cfg (desc->mem->spi,0 ), mxic->regs +HC_CFG ); + +writel (mxic_spi_mem_prep_op_cfg (&desc->info.op_tmpl, len), + mxic->regs +LRD_CFG ); +writel (desc->info.offset + offs, mxic->regs +LRD_ADDR ); + len =min_t (size_t, len, mxic->linear.size); +writel (len, mxic->regs +LRD_RANGE ); +writel (LMODE_CMD0 (desc->info.op_tmpl.cmd.opcode) | +LMODE_SLV_ACT (desc->mem->spi->chip_select) | +LMODE_EN , + mxic->regs +LRD_CTRL ); + +memcpy_fromio (buf, mxic->linear.map, len); + +writel (INT_LRD_DIS , mxic->regs +INT_STS ); +writel (0 , mxic->regs +LRD_CTRL ); + + ret =readl_poll_timeout (mxic->regs +INT_STS , sts, + sts &INT_LRD_DIS ,0 ,USEC_PER_SEC ); +if (ret) +return ret; + +return len; +} + +static ssize_t mxic_spi_mem_dirmap_write (struct spi_mem_dirmap_desc *desc, +u64 offs,size_t len, +const void *buf) +{ +struct mxic_spi *mxic =spi_master_get_devdata (desc->mem->spi->master); +u32 sts; +int ret; + +if (WARN_ON (offs + desc->info.offset + len >U32_MAX )) +return -EINVAL ; + +writel (mxic_spi_prep_hc_cfg (desc->mem->spi,0 ), mxic->regs +HC_CFG ); + +writel (mxic_spi_mem_prep_op_cfg (&desc->info.op_tmpl, len), + mxic->regs +LWR_CFG ); +writel (desc->info.offset + offs, mxic->regs +LWR_ADDR ); + len =min_t (size_t, len, mxic->linear.size); +writel (len, mxic->regs +LWR_RANGE ); +writel (LMODE_CMD0 (desc->info.op_tmpl.cmd.opcode) | +LMODE_SLV_ACT (desc->mem->spi->chip_select) | +LMODE_EN , + mxic->regs +LWR_CTRL ); + +memcpy_toio (mxic->linear.map, buf, len); + +writel (INT_LWR_DIS , mxic->regs +INT_STS ); +writel (0 , mxic->regs +LWR_CTRL ); + + ret =readl_poll_timeout (mxic->regs +INT_STS , sts, + sts &INT_LWR_DIS ,0 ,USEC_PER_SEC ); +if (ret) +return ret; + +return len; +} +static bool mxic_spi_mem_supports_op (struct spi_mem *mem,const struct spi_mem_op *op) {
@@ -388,6 +466,22 @@ static bool mxic_spi_mem_supports_op(struct spi_mem *mem,return spi_mem_default_supports_op (mem, op); } +static int mxic_spi_mem_dirmap_create (struct spi_mem_dirmap_desc *desc) +{ +struct mxic_spi *mxic =spi_master_get_devdata (desc->mem->spi->master); + +if (!mxic->linear.map) +return -EINVAL ; + +if (desc->info.offset + desc->info.length >U32_MAX ) +return -EINVAL ; + +if (!mxic_spi_mem_supports_op (desc->mem, &desc->info.op_tmpl)) +return -EOPNOTSUPP ; + +return 0 ; +} +static int mxic_spi_mem_exec_op (struct spi_mem *mem,const struct spi_mem_op *op) {
@@ -404,7 +498,7 @@ static int mxic_spi_mem_exec_op(struct spi_mem *mem,writel (HC_EN_BIT , mxic->regs +HC_EN ); -writel (mxic_spi_mem_prep_op_cfg (op), +writel (mxic_spi_mem_prep_op_cfg (op, op->data.nbytes), mxic->regs +SS_CTRL (mem->spi->chip_select)); writel(readl(mxic->regs + HC_CFG) | HC_CFG_MAN_CS_ASSERT,
@@ -446,6 +540,9 @@ static int mxic_spi_mem_exec_op(struct spi_mem *mem,static const struct spi_controller_mem_ops mxic_spi_mem_ops = { .supports_op = mxic_spi_mem_supports_op, .exec_op = mxic_spi_mem_exec_op, + .dirmap_create = mxic_spi_mem_dirmap_create, + .dirmap_read = mxic_spi_mem_dirmap_read, + .dirmap_write = mxic_spi_mem_dirmap_write, };static const struct spi_controller_mem_caps mxic_spi_mem_caps = {
@@ -579,6 +676,15 @@ static int mxic_spi_probe(struct platform_device *pdev)if (IS_ERR (mxic->regs))return PTR_ERR (mxic->regs); + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"dirmap" ); + mxic->linear.map =devm_ioremap_resource (&pdev->dev, res); +if (!IS_ERR (mxic->linear.map)) { + mxic->linear.dma = res->start; + mxic->linear.size =resource_size (res); + }else { + mxic->linear.map =NULL ; + } +pm_runtime_enable (&pdev->dev); master->auto_runtime_pm = true;
Signature · 1 line
2.27.0
Re: [PATCH v9 12/13] spi: mxic: Add support for direct mapping
Quoted 7 lines · Miquel Raynal
Implement the ->dirmap_create() and ->dirmap_read/write() hooks to provide a fast path for read and write accesses.
Signed-off-by Miquel Raynal <[email protected]>Tested-by Zhengxun Li <[email protected]>Reviewed-by Zhengxun Li <[email protected]>Reviewed-by Mark Brown <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-mem-ecc.
Miquel
Miquel Raynal
maintainerPATCH v9 13/13 spi: mxic: Add support for pipelined ECC operations
In reply to Miquel RaynalSome SPI-NAND chips do not have a proper on-die ECC engine providing error correction/detection. This is particularly an issue on embedded devices with limited resources because all the computations must happen in software, unless an external hardware engine is provided.
These external engines are new and can be of two categories: external or pipelined. Macronix is providing both, the former being already supported. The second, however, is very SoC implementation dependent and must be instantiated by the SPI host controller directly.
An entire subsystem has been contributed to support these engines which makes the insertion into another subsystem such as SPI quite straightforward without the need for a lot of specific functions.
--- drivers/spi/Kconfig | 2 +- drivers/spi/spi-mxic.c | 113 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 112 insertions(+), 3 deletions(-)
drivers/spi/Kconfig +1 -1
@@ -856,7 +856,7 @@ config SPI_SYNQUACER config SPI_MXIC tristate "Macronix MX25F0A SPI controller" - depends on SPI_MASTER + depends on SPI_MASTER && MTD_NAND_ECC help This selects the Macronix MX25F0A SPI controller driver.
drivers/spi/spi-mxic.c +111 -2
175 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [PATCH v9 13/13] spi: mxic: Add support for pipelined ECC operations
Quoted 10 lines · Miquel Raynal
Some SPI-NAND chips do not have a proper on-die ECC engine providing error correction/detection. This is particularly an issue on embedded devices with limited resources because all the computations must happen in software, unless an external hardware engine is provided.
These external engines are new and can be of two categories: external or pipelined. Macronix is providing both, the former being already supported. The second, however, is very SoC implementation dependent and must be instantiated by the SPI host controller directly.
Quoted 6 lines
An entire subsystem has been contributed to support these engines which makes the insertion into another subsystem such as SPI quite straightforward without the need for a lot of specific functions.
Signed-off-by Miquel Raynal <[email protected]>Reviewed-by Mark Brown <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-mem-ecc.
Miquel
Quoted 7 lines · On Tue, 4 Jan 2022 09:36:18 +0100 Miquel Raynal <[email protected]>…
Miquel Raynal (13):
spi: spi-mem: Introduce a capability structure
spi: spi-mem: Check the controller extra capabilities
spi: cadence-quadspi: Provide a capability structure
spi: mxic: Provide a capability structure
spi: spi-mem: Kill thespi_mem_dtr_supports_op()helper
spi: spi-mem: Add an ecc parameter to thespi_mem_opstructure
Quoted 8 lines
mtd: spinand: Delay a little bit the dirmap creation
mtd: spinand: Create direct mapping descriptors for ECC operations
spi: mxic: Fix the transmit path
spi: mxic: Create a helper to configure the controller before an
operation
spi: mxic: Create a helper to ease the start of an operation
spi: mxic: Add support for direct mapping
spi: mxic: Add support for pipelined ECC operations
All core changes (patches 1 to 8) are
Miquel Raynal
maintainerHello,
[email protected] wrote on Tue, 4 Jan 2022 09:36:18 +0100:
Quoted 9 lines
Hello all,
I've applied the beginning of the series (bindings + ECC part) in a branch named spi-mem-ecc on the MTD korg repository. After discussing a bit more some details, I decided not to rush and did not apply the second halve of the series for v5.17. Here is now the second halve again in a hopefully better shape. I am expecting a few acks on this one and I'll then rebase spi-mem-ecc on top of v5.18-rc1, apply these patches and share them with the spi tree.
Series applied in its own branch, I will share it next week with the spi tree.
Thanks,
Miquèl