mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: William Zhang <william.zhang@broadcom.com>
To: Miquel Raynal <miquel.raynal@bootlin.com>, dregan@mail.com
Cc: bcm-kernel-feedback-list@broadcom.com,
	linux-mtd@lists.infradead.org, f.fainelli@gmail.com,
	rafal@milecki.pl, joel.peshkin@broadcom.com,
	computersforpeace@gmail.com, dan.beygelman@broadcom.com,
	frieder.schrempf@kontron.de, linux-kernel@vger.kernel.org,
	vigneshr@ti.com, richard@nod.at, bbrezillon@kernel.org,
	kdasu.kdev@gmail.com
Subject: Re: [PATCH v2] mtd: rawnand: brcmnand: Initial exec_op implementation
Date: Mon, 2 Oct 2023 12:57:01 -0700	[thread overview]
Message-ID: <04350e70-6ef0-4998-664f-20b96b63b0f4@broadcom.com> (raw)
In-Reply-To: <20231002143527.4ccf254a@xps-13>

[-- Attachment #1: Type: text/plain, Size: 4532 bytes --]

Hi Miquel,

On 10/02/2023 05:35 AM, Miquel Raynal wrote:
> Hi David,
> 
> dregan@mail.com wrote on Sat, 30 Sep 2023 03:57:35 +0200:
> 
>> Initial exec_op implementation for Broadcom STB, Broadband and iProc SoC
>> This adds exec_op and removes the legacy interface.
>>
>> Signed-off-by: David Regan <dregan@mail.com>
>> Reviewed-by: William Zhang <william.zhang@broadcom.com>
>>
>> ---
>>
> 
> ...
> 
>> +static int brcmnand_parser_exec_matched_op(struct nand_chip *chip,
>> +					 const struct nand_subop *subop)
>> +{
>> +	struct brcmnand_host *host = nand_get_controller_data(chip);
>> +	struct brcmnand_controller *ctrl = host->ctrl;
>> +	struct mtd_info *mtd = nand_to_mtd(chip);
>> +	const struct nand_op_instr *instr = &subop->instrs[0];
>> +	unsigned int i;
>> +	int ret = 0;
>> +
>> +	for (i = 0; i < subop->ninstrs; i++) {
>> +		instr = &subop->instrs[i];
>> +
>> +		if ((instr->type == NAND_OP_CMD_INSTR) &&
>> +			(instr->ctx.cmd.opcode == NAND_CMD_STATUS))
>> +			ctrl->status_cmd = 1;
>> +		else if (ctrl->status_cmd && (instr->type == NAND_OP_DATA_IN_INSTR)) {
>> +			/*
>> +			 * need to fake the nand device write protect because nand_base does a
>> +			 * nand_check_wp which calls nand_status_op NAND_CMD_STATUS which checks
>> +			 * that the nand is not write protected before an operation starts.
>> +			 * The problem with this is it's done outside exec_op so the nand is
>> +			 * write protected and this check will fail until the write or erase
>> +			 * or write back operation actually happens where we turn off wp.
>> +			 */
>> +			u8 *in;
>> +
>> +			ctrl->status_cmd = 0;
>> +
>> +			instr = &subop->instrs[i];
>> +			in = instr->ctx.data.buf.in;
>> +			in[0] = brcmnand_status(host) | NAND_STATUS_WP; /* hide WP status */
> 
> I don't understand why you are faking the WP bit. If it's set,
> brcmnand_status() should return it and you should not care about it. If
> it's not however, can you please give me the path used when we have
> this issue? Either we need to modify the core or we need to provide
> additional helpers in this driver to circumvent the faulty path.

The reason we have to hide wp status for status command is because
nand_base calls nand_check_wp at the very beginning of write and erase
function. This applies to both exec_op path and legacy path. With
Broadcom nand controller and most of our board design using the WP pin
and have it asserted by default, the nand_check_wp function will fail
and write/erase aborts.  This workaround has been there before this
exec_op patch.

I agree it is ugly and better to be addressed in the nand base code. And
I understand Broadcom's WP approach may sound a bit over cautious but we
want to make sure no spurious erase/write can happen under any
circumstance except software explicitly want to write and erase.  WP is
standard nand chip pin and I think most the nand controller has that
that pin in the design too but it is possible it is not used and
bootloader can de-assert the pin and have a always-writable nand flash
for linux. So maybe we can add nand controller dts option "nand-use-wp".
If this property exist and set to 1,  wp control is in use and nand
driver need to control the pin on/ff as needed when doing write and
erase function. Also nand base code should not call nand_check_wp when
wp is in use. Then we can remove the faking WP status workaround.

> 
>> +		} else if (instr->type == NAND_OP_WAITRDY_INSTR) {
>> +			ret = bcmnand_ctrl_poll_status(host, NAND_CTRL_RDY, NAND_CTRL_RDY, 0);
>> +			if (ctrl->wp_cmd) {
>> +				ctrl->wp_cmd = 0;
>> +				brcmnand_wp(mtd, 1);
> 
> This ideally should disappear.
> 
Maybe we can have the destructive operation patch from Borris.
Controller driver still need to assert/deassert the pin if it uses nand
wp feature but at least it does not need to guess the op code.

>> +			}
>> +		} else { /* otherwise pass to low level implementation */
>> +			if ((instr->type == NAND_OP_CMD_INSTR) &&
>> +				(instr->ctx.cmd.opcode == NAND_CMD_RESET)) {
>> +				brcmnand_status(host);
>> +				ctrl->status_cmd = 0;
>> +				ctrl->wp_cmd = 0;
>> +				brcmnand_wp(mtd, 1);
> 
> Same
> 
>> +			}
>> +
>> +			if ((instr->type == NAND_OP_CMD_INSTR) &&
>> +				((instr->ctx.cmd.opcode == NAND_CMD_ERASE1) ||
>> +				(instr->ctx.cmd.opcode == NAND_CMD_SEQIN))) {
>> +				brcmnand_wp(mtd, 0);
>> +				ctrl->wp_cmd = 1;
> 
> Same
> 
>> +			}
>> +
>> +			ret = brcmnand_exec_instr(host, instr, i == (subop->ninstrs - 1));
>> +		}
>> +	}
>> +
>> +	return ret;
>> +}
> 
> 
> 
> Thanks,
> Miquèl
> 

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4212 bytes --]

  reply	other threads:[~2023-10-02 19:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <trinity-bb7db9f1-d34d-4fe2-bed3-814d3a63476a-1694571881792@3c-app-mailcom-lxa03>
2023-09-15 18:45 ` [PATCH] " William Zhang
2023-09-15 19:21 ` William Zhang
2023-09-22 14:24 ` Miquel Raynal
     [not found]   ` <trinity-ad65aa5d-e930-4f11-ac86-e18f90f5092c-1696016842791@3c-app-mailcom-lxa02>
2023-10-02 12:12     ` Miquel Raynal
     [not found]   ` <trinity-06dd34f4-ab26-4c60-bcf8-f986f1d08058-1696039055941@3c-app-mailcom-lxa04>
2023-10-02 12:35     ` [PATCH v2] " Miquel Raynal
2023-10-02 19:57       ` William Zhang [this message]
2023-10-03  9:28         ` Miquel Raynal
2023-10-03 18:46           ` William Zhang
2023-10-03 22:55             ` Miquel Raynal
2023-10-04  4:47               ` William Zhang
2023-10-06  0:42                 ` William Zhang
2023-10-06  7:42                   ` Miquel Raynal
2023-10-08 23:46                     ` William Zhang

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=04350e70-6ef0-4998-664f-20b96b63b0f4@broadcom.com \
    --to=william.zhang@broadcom.com \
    --cc=bbrezillon@kernel.org \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=computersforpeace@gmail.com \
    --cc=dan.beygelman@broadcom.com \
    --cc=dregan@mail.com \
    --cc=f.fainelli@gmail.com \
    --cc=frieder.schrempf@kontron.de \
    --cc=joel.peshkin@broadcom.com \
    --cc=kdasu.kdev@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=rafal@milecki.pl \
    --cc=richard@nod.at \
    --cc=vigneshr@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

all inboxes | Powered by JetHome®