Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fil Dunsky" <filipp.dunsky@gmail.com>,
	"Miquel Raynal" <miquel.raynal@bootlin.com>,
	"Richard Weinberger" <richard@nod.at>,
	"Vignesh Raghavendra" <vigneshr@ti.com>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Philipp Zabel" <p.zabel@pengutronix.de>
Cc: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v8 3/4] mtd: rawnand: Add Cortina CS7542 controller support
Date: Fri, 04 Dec 2026 15:05:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-250058@kernel.org> (raw)
In-Reply-To: <20261204-b4-cs7542-nand-v8-3-bb068644f71f@gmail.com>

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] mtd: rawnand: cs752x_nand_probe() takes and pulses shared reset
  exclusively
- [Medium] mtd: rawnand: missing FSM reset on timeout in
  cs752x_nand_pio() and ECC
- [Medium] mtd: rawnand: sleeping readl_poll_timeout() in
  mtd_panic_write() context
- [Medium] mtd: rawnand: cs752x: per-word udelay(1) in
  cs752x_nand_words()
- [Medium] mtd: rawnand: cs752x: zero-slack usleep_range(1, 1) hrtimer
  storms
- [Low] mtd: rawnand: cs752x_nand_exec_op() rejects op->cs on check_only
  probes
--

commit 65996877e86929ea6a1fd88c61cb2bb3794c71d1
Author: Fil Dunsky <filipp.dunsky@gmail.com>

mtd: rawnand: Add Cortina CS7542 controller support

This commit adds a raw NAND controller driver for the Cortina CS7542
using programmed I/O, software ECC, and 256-byte hardware Hamming ECC.

> diff --git a/drivers/mtd/nand/raw/cs752x_nand.c b/drivers/mtd/nand/raw/cs752x_nand.c
> new file mode 100644
> index 0000000000000..690067b9bafa7
> --- /dev/null
> +++ b/drivers/mtd/nand/raw/cs752x_nand.c
> @@ -0,0 +1,756 @@

[ ... ]

> +static int check_flash_ctrl_status(struct cs752x_nand_host *h)
> +{
> +	u32 val;
> +	int ret;
> +
> +	ret = readl_poll_timeout(h->iobase_fl + FLASH_STATUS, val,
> +				 !(val & FLASH_STATUS_NSTATE_MASK), 1, 1000000);
> +	if (ret)
> +		dev_err(h->dev, "FLASH_STATUS busy: 0x%x\n", val);
> +	return ret;
> +}
> +
> +static int wait_reg(struct cs752x_nand_host *h, u32 reg, u32 bit, const char *what)
> +{
> +	u32 val;
> +	int ret;
> +
> +	ret = readl_poll_timeout(h->iobase_fl + reg, val, val & bit, 1, 2000000);
> +	if (ret)
> +		dev_err(h->dev, "%s timeout\n", what);
> +	return ret;
> +}

[Severity: Medium]
Can check_flash_ctrl_status(), wait_reg(), and cs752x_nand_wait_ready()
sleep in atomic context during mtd_panic_write()?

nand_scan_tail() sets mtd->_panic_write = panic_nand_write, which reaches
these helpers via nand_do_write_ops() during a panic dump (e.g. mtdoops).
With sleep_us = 1, readl_poll_timeout() invokes might_sleep_if() and
usleep_range(), risking scheduling-while-atomic warnings or a hang.

Checking mtd->oops_panic_write to use readl_poll_timeout_atomic() (or
clearing mtd->_panic_write if panic writes are not supported) avoids this.

[ ... ]

> +		fl_writel(h, FLASH_FLASH_ACCESS_START,
> +			  FLASH_START_REGREQ | FLASH_START_CMD(write ? FLASH_WT : FLASH_RD));
> +		ret = readl_poll_timeout_atomic(h->iobase_fl + FLASH_FLASH_ACCESS_START,
> +						value, !(value & FLASH_START_REGREQ) ||
> +						ktime_get_ns() >= deadline, 1, 10000);

[Severity: Medium]
Does passing delay_us = 1 to readl_poll_timeout_atomic() force a udelay(1)
busy-wait on every 4-byte word in cs752x_nand_words()?

Four 8-bit NAND bus cycles take longer than one MMIO turnaround, so the
first read usually sees FLASH_START_REGREQ set and stalls in udelay(1),
adding over 1 ms of busy-waiting per 4KB+128B page.  Tight-polling with
delay_us = 0, as in cs752x_nand_pio(), avoids this per-word stall.

[ ... ]

> +static int cs752x_nand_wait_ready(struct cs752x_nand_host *h,
> +				  unsigned int timeout_ms)
> +{
> +	const struct nand_interface_config *conf;
> +	u32 value;
> +
> +	/* R/B can remain high for tWB after a command has been issued. */
> +	conf = nand_get_interface_config(&h->chip);
> +	ndelay(NAND_COMMON_TIMING_NS(conf, tWB_max));
> +
> +	/* nflash_rbIn_d is the sampled NAND R/B input, not the FSM state. */
> +	return readl_poll_timeout(h->iobase_fl + FLASH_STATUS, value,
> +				 value & BIT(26), 1, (u64)timeout_ms * 1000);
> +}

[Severity: Medium]
Will passing sleep_us = 1 to readl_poll_timeout() here (and in
check_flash_ctrl_status() and wait_reg()) cause hrtimer interrupt storms?

poll_timeout_us() converts sleep_us = 1 to usleep_range(1, 1), which arms
a zero-slack hrtimer 1 us ahead on every iteration.  Across a multi-ms
block erase or multi-hundred-us page program, that fires hundreds to
thousands of back-to-back timer interrupts and context switches.

Using a larger sleep_us (such as 20 us, giving usleep_range(6, 20) with
slack) reduces timer overhead while waiting on R/B.

[ ... ]

> +static int cs752x_nand_pio(struct cs752x_nand_host *h,
> +			   const struct cs752x_nand_op *p, u8 *buf,
> +			   unsigned int len, bool write)
> +{
> +	u64 deadline;
> +	u32 value;
> +	unsigned int i, step = write && len ? sizeof(u32) : 1;
> +	int ret;
> +
> +	ret = check_flash_ctrl_status(h);
> +	if (ret)
> +		return ret;
> +	reset_ecc_bch_registers(h);

[Severity: Medium]
Should cs752x_nand_pio() use cs752x_page_op_begin() so a busy timeout
resets the controller FSM?

Unlike cs752x_page_op_begin(), returning directly here skips writing
ECC_RESET_NF_RESET to FLASH_NF_ECC_RESET.  If the FSM wedges busy (for
example in software-ECC mode where cs752x_page_op_begin() is never
called), subsequent PIO and nand_reset_op() calls fail with -ETIMEDOUT.

Similarly, if wait_reg() times out in hamming_correct(), it returns early
without clearing ECC_CTL_EN or asserting FLASH_NF_ECC_RESET, leaving the
ECC engine active after cs752x_nand_hwecc_op().

[ ... ]

> +static int cs752x_nand_exec_op(struct nand_chip *chip,
> +			       const struct nand_operation *op, bool check_only)
> +{
> +	unsigned int i;
> +	int ret;
> +
> +	if (op->cs || !op->ninstrs)
> +		return -EOPNOTSUPP;

[Severity: Low]
Does rejecting non-zero op->cs unconditionally break nand_check_op()
probes when no target is selected?

nand_scan_tail() deselects the target (chip->cur_cs = -1) before
rawnand_late_check_supported_ops() probes continuous cached reads via
nand_check_op().  Checking op->cs only when !check_only avoids silently
disabling continuous reads on read-cache-capable chips under software ECC.

[ ... ]

> +	reset = devm_reset_control_get_optional_exclusive(dev, NULL);
> +	if (IS_ERR(reset))
> +		return dev_err_probe(dev, PTR_ERR(reset), "flash reset\n");
> +
> +	if (reset) {
> +		err = reset_control_assert(reset);
> +		if (err)
> +			return dev_err_probe(dev, err, "assert flash reset\n");
> +
> +		udelay(2);
> +		err = reset_control_deassert(reset);
> +		if (err)
> +			return dev_err_probe(dev, err, "release flash reset\n");
> +	}

[Severity: High]
Can cs752x_nand_probe() request and pulse the flash controller reset
exclusively when the DT binding documents it as shared?

Documentation/devicetree/bindings/mtd/cortina,cs7542-nand.yaml defines
resets as "Shared flash controller reset".  When another driver shares the
line, __reset_control_get_internal() triggers WARN_ON() and returns
-EBUSY; if this driver probes first, it blocks and resets active siblings.

Asserting the reset before validating the NAND child node also pulses the
shared line even on an invalid DT configuration.  Requesting a shared
reset (e.g. devm_reset_control_get_optional_shared()) matches the binding.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-b4-cs7542-nand-v8-0-bb068644f71f@gmail.com?part=3

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  parent reply	other threads:[~2026-12-04 15:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 14:03 [PATCH v8 0/4] Add Cortina Systems CS7542 NAND controller support Fil Dunsky via B4 Relay
2026-12-04 14:03 ` [PATCH v8 1/4] mtd: rawnand: Honor controller raw page callbacks in ECC_NONE Fil Dunsky via B4 Relay
2026-12-04 14:03 ` [PATCH v8 2/4] dt-bindings: mtd: Add Cortina CS7542 NAND controller Fil Dunsky via B4 Relay
2026-12-04 14:12   ` Philipp Zabel
2026-12-04 14:38   ` sashiko-bot
2026-12-04 14:03 ` [PATCH v8 3/4] mtd: rawnand: Add Cortina CS7542 controller support Fil Dunsky via B4 Relay
2026-12-04 14:12   ` Philipp Zabel
2026-12-04 15:37     ` Fil Dunsky
2026-12-04 15:05   ` sashiko-bot [this message]
2026-12-04 14:03 ` [PATCH v8 4/4] MAINTAINERS: Add Cortina CS7542 NAND controller entry Fil Dunsky via B4 Relay

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=sashiko-outbox-250058@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=filipp.dunsky@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=p.zabel@pengutronix.de \
    --cc=richard@nod.at \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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