linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Naga Sureshkumar Relli <nagasure@xilinx.com>
Cc: "boris.brezillon@bootlin.com" <boris.brezillon@bootlin.com>,
	"richard@nod.at" <richard@nod.at>,
	"dwmw2@infradead.org" <dwmw2@infradead.org>,
	"computersforpeace@gmail.com" <computersforpeace@gmail.com>,
	"marek.vasut@gmail.com" <marek.vasut@gmail.com>,
	"f.fainelli@gmail.com" <f.fainelli@gmail.com>,
	"mmayer@broadcom.com" <mmayer@broadcom.com>,
	"rogerq@ti.com" <rogerq@ti.com>,
	"ladis@linux-mips.org" <ladis@linux-mips.org>,
	"ada@thorsis.co" <ada@thorsis.co>,
	"honghui.zhang@mediatek.com" <honghui.zhang@mediatek.com>,
	"linus.walleij@linaro.org" <linus.walleij@linaro.org>,
	"linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"nagasureshkumarrelli@gmail.com" <nagasureshkumarrelli@gmail.com>,
	Michal Simek <michals@xilinx.com>
Subject: Re: [LINUX PATCH v11 3/3] mtd: rawnand: pl353: Add basic driver for arm pl353 smc nand interface
Date: Sat, 4 Aug 2018 11:56:02 +0200	[thread overview]
Message-ID: <20180804115602.2f44c007@xps13> (raw)
In-Reply-To: <MWHPR02MB26231B9223265E914250FACCAF2E0@MWHPR02MB2623.namprd02.prod.outlook.com>

Hi Naga,

> > > +/**
> > > + * pl353_nand_read_data_op - read chip data into buffer
> > > + * @chip:	Pointer to the NAND chip info structure
> > > + * @in:		Pointer to the buffer to store read data
> > > + * @len:	Number of bytes to read
> > > + * Return:	Always return zero
> > > + */
> > > +static int pl353_nand_read_data_op(struct nand_chip *chip,
> > > +				   u8 *in,
> > > +				   unsigned int len)
> > > +{
> > > +	int i;
> > > +	struct pl353_nand_info *xnfc =
> > > +		container_of(chip, struct pl353_nand_info, chip);
> > > +
> > > +	if (IS_ALIGNED((uint32_t)in, sizeof(uint32_t)) &&
> > > +	    IS_ALIGNED(len, sizeof(uint32_t))) {
> > > +		u32 *ptr = (u32 *)in;
> > > +
> > > +		len /= 4;
> > > +		for (i = 0; i < len; i++)
> > > +			ptr[i] = readl(xnfc->nandaddr);
> > > +	} else {
> > > +		for (i = 0; i < len; i++)
> > > +			in[i] = readb(xnfc->nandaddr);
> > > +	}  
> > 
> > What about reading 0-3 bytes with readb if the driver is not aligned, then doing aligned
> > access with readl until readb must be used again for the last 0-3 bytes?  
> The else case is handling that right?

No it's not. The else case reads byte per byte, always.

[...]

> > > +static int pl353_nand_calculate_hwecc(struct mtd_info *mtd,
> > > +				      const u8 *data, u8 *ecc)
> > > +{
> > > +	u32 ecc_value;
> > > +	u8 ecc_reg, ecc_byte, ecc_status;
> > > +	unsigned long timeout = jiffies + PL353_NAND_ECC_BUSY_TIMEOUT;
> > > +
> > > +	/* Wait till the ECC operation is complete or timeout */
> > > +	do {
> > > +		if (pl353_smc_ecc_is_busy())
> > > +			cpu_relax();
> > > +		else
> > > +			break;
> > > +	} while (!time_after_eq(jiffies, timeout));
> > > +
> > > +	if (time_after_eq(jiffies, timeout)) {
> > > +		pr_err("%s timed out\n", __func__);
> > > +		return -ETIMEDOUT;
> > > +	}  
> > 
> > All of this should be done by the function calling nand_calculate_hwecc(), not here.  
> Ok, I will update it.
> > 
> > Plus, it should deserve a function on its own.  
> Ok, will add new one.
> >   
> > > +
> > > +	for (ecc_reg = 0; ecc_reg < 4; ecc_reg++) {
> > > +		/* Read ECC value for each block */  
> > 
> > So you assume here that there are 4, and only 4 "blocks" (I prefer "ECC chunks" or
> > "subpages"). Is it always the case? Or is it just how it works in your situation? I would rather
> > prefer a to define this value anyway.  
> Sure, I will define a macro as ECC chunks to represent 4.
> And there are always 4 ECC registers as per the controller. And there is no assumption here.

What about smaller or larger NAND chips? Maybe there are some
limitations in what chips are actually supported, then they should be
rejected.


[...]

> > > +static void pl353_prepare_cmd(struct mtd_info *mtd, struct
nand_chip *chip,
> > > +			      int page, int column, int start_cmd, int end_cmd,
> > > +			      bool read)
> > > +{
> > > +	unsigned long data_phase_addr;
> > > +	u32 end_cmd_valid = 0;
> > > +	unsigned long cmd_phase_addr = 0, cmd_data = 0;
> > > +
> > > +	struct pl353_nand_info *xnfc =
> > > +		container_of(chip, struct pl353_nand_info, chip);
> > > +
> > > +	end_cmd_valid = read ? 1 : 0;
> > > +
> > > +	cmd_phase_addr = (unsigned long __force)xnfc->nand_base +  
> > 
> > do you really need this cast?  
> As I said above, during command and data phases, we have to update the AXI Read/Write addresses with cycles, start command, end command
> And some extra info. Hence I am converting it to a value and then adding the above values and then again converting back as an
> Address.
> 
> >   
> > > +			 ((xnfc->addr_cycles
> > > +			 << ADDR_CYCLES_SHIFT) |
> > > +			 (end_cmd_valid << END_CMD_VALID_SHIFT) |
> > > +			 (COMMAND_PHASE) |
> > > +			 (end_cmd << END_CMD_SHIFT) |
> > > +			 (start_cmd << START_CMD_SHIFT));  
> > 
> > So the number of address cycles changes the address where you should write the address
> > cycles? that's weird, no?  
> I agree, but the implementation of PL353 is like that.
> As I pointed the spec above, for every transfer we have to frame AXI Write address and Read address.
> 
> >   
> > > +
> > > +	/* Get the data phase address */
> > > +	data_phase_addr = (unsigned long __force)xnfc->nand_base +
> > > +			  ((0x0 << CLEAR_CS_SHIFT) |
> > > +			  (0 << END_CMD_VALID_SHIFT) |
> > > +			  (DATA_PHASE) |
> > > +			  (end_cmd << END_CMD_SHIFT) |
> > > +			  (0x0 << ECC_LAST_SHIFT));
> > > +  
> > Same question here?
> >   
> > > +	xnfc->nandaddr = (void __iomem * __force)data_phase_addr;  
> > 
> > This should be done only once in the probe  
> No, as explained above, once we frame the Axi Write address/Read address with valid data, then we
> Are converting back as memory address with the casting.
> Do you see any issues with that?
> Let me know, is there an alternative to achieve the same. 
> All is about, constructing AXI Write address and Read address during command and data phases.

Ok, I'll ask Boris to also review your next version, once -rc1 is out.

Thanks,
Miquèl

      reply	other threads:[~2018-08-04  9:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-11  7:36 [LINUX PATCH v11 0/3] Add arm pl353 smc memory and nand driver for xilinx zynq soc Naga Sureshkumar Relli
2018-07-11  7:36 ` [LINUX PATCH v11 1/3] dt-bindings: memory: Add pl353 smc controller devicetree binding information Naga Sureshkumar Relli
2018-07-13  7:37   ` Linus Walleij
2018-09-11  5:24     ` Naga Sureshkumar Relli
2018-07-11  7:36 ` [LINUX PATCH v11 2/3] memory: pl353: Add driver for arm pl353 static memory controller Naga Sureshkumar Relli
2018-07-13  7:38   ` Linus Walleij
2018-07-11  7:36 ` [LINUX PATCH v11 3/3] mtd: rawnand: pl353: Add basic driver for arm pl353 smc nand interface Naga Sureshkumar Relli
2018-07-22  7:04   ` Naga Sureshkumar Relli
2018-07-23  7:30     ` Miquel Raynal
2018-07-23  9:05       ` Naga Sureshkumar Relli
2018-07-29 19:15   ` Miquel Raynal
2018-07-31  7:50     ` Naga Sureshkumar Relli
2018-08-04  9:56       ` Miquel Raynal [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180804115602.2f44c007@xps13 \
    --to=miquel.raynal@bootlin.com \
    --cc=ada@thorsis.co \
    --cc=boris.brezillon@bootlin.com \
    --cc=computersforpeace@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=f.fainelli@gmail.com \
    --cc=honghui.zhang@mediatek.com \
    --cc=ladis@linux-mips.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=michals@xilinx.com \
    --cc=mmayer@broadcom.com \
    --cc=nagasure@xilinx.com \
    --cc=nagasureshkumarrelli@gmail.com \
    --cc=richard@nod.at \
    --cc=rogerq@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).