lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <a563cb0b-0bc5-4dbe-b570-4d45c1b14641@broadcom.com>
Date: Tue, 13 May 2025 10:42:24 +0200
From: Florian Fainelli <florian.fainelli@...adcom.com>
To: Álvaro Fernández Rojas <noltari@...il.com>,
 linux-mtd@...ts.infradead.org, dregan@...adcom.com,
 miquel.raynal@...tlin.com, bcm-kernel-feedback-list@...adcom.com,
 rafal@...ecki.pl, computersforpeace@...il.com, kamal.dasu@...adcom.com,
 dan.beygelman@...adcom.com, william.zhang@...adcom.com,
 frieder.schrempf@...tron.de, linux-kernel@...r.kernel.org, vigneshr@...com,
 richard@....at, bbrezillon@...nel.org, kdasu.kdev@...il.com,
 jaimeliao.tw@...il.com, kilobyte@...band.pl, jonas.gorski@...il.com,
 dgcbueu@...il.com
Subject: Re: [PATCH v2] mtd: rawnand: brcmnand: legacy exec_op implementation



On 5/13/2025 10:01 AM, Álvaro Fernández Rojas wrote:
> Commit 3c8260ce7663 ("mtd: rawnand: brcmnand: exec_op implementation")
> removed legacy interface functions, breaking < v5.0 controllers support.
> In order to fix older controllers we need to add an alternative exec_op
> implementation which doesn't rely on low level registers.
> 
> Fixes: 3c8260ce7663 ("mtd: rawnand: brcmnand: exec_op implementation")
> Signed-off-by: Álvaro Fernández Rojas <noltari@...il.com>
> ---
>   drivers/mtd/nand/raw/brcmnand/brcmnand.c | 160 ++++++++++++++++++++++-
>   1 file changed, 154 insertions(+), 6 deletions(-)
> 
>   v2: multiple improvements:
>    - Use proper native commands for checks.
>    - Fix NAND_CMD_PARAM/NAND_CMD_RNDOUT addr calculation.
>    - Remove host->last_addr usage.
>    - Remove sector_size_1k since it only applies to v5.0+ controllers.
>    - Remove brcmnand_wp since it doesn't exist for < v5.0 controllers.
>    - Use j instead of i for flash_cache loop.
> 
> diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> index 17f6d9723df9..2b519dfcac5d 100644
> --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
> @@ -2490,14 +2490,163 @@ static int brcmnand_op_is_reset(const struct nand_operation *op)
>   	return 0;
>   }
>   
> +static int brcmnand_exec_instructions(struct nand_chip *chip,
> +				      const struct nand_operation *op)
> +{
> +	struct brcmnand_host *host = nand_get_controller_data(chip);
> +	unsigned int i;
> +	int ret = 0;
> +
> +	for (i = 0; i < op->ninstrs; i++) {
> +		ret = brcmnand_exec_instr(host, i, op);
> +		if (ret)
> +			break;
> +	}
> +
> +	return ret;
> +}
> +
> +static int brcmnand_exec_instructions_legacy(struct nand_chip *chip,
> +					     const struct nand_operation *op)
> +{
> +	struct mtd_info *mtd = nand_to_mtd(chip);
> +	struct brcmnand_host *host = nand_get_controller_data(chip);
> +	struct brcmnand_controller *ctrl = host->ctrl;
> +	const struct nand_op_instr *instr;
> +	unsigned int i, j;
> +	int cmd = CMD_NULL, last_cmd = CMD_NULL;
> +	int ret = 0;
> +	u64 last_addr;
> +
> +	for (i = 0; i < op->ninstrs; i++) {
> +		instr = &op->instrs[i];
> +
> +		if (instr->type == NAND_OP_CMD_INSTR) {
> +			if (instr->ctx.cmd.opcode == NAND_CMD_READID) {
> +				cmd = CMD_DEVICE_ID_READ;
> +			} else if (instr->ctx.cmd.opcode == NAND_CMD_READOOB) {
> +				cmd = CMD_SPARE_AREA_READ;
> +			} else if (instr->ctx.cmd.opcode == NAND_CMD_ERASE1) {
> +				cmd = CMD_BLOCK_ERASE;
> +			} else if (instr->ctx.cmd.opcode == NAND_CMD_ERASE2) {
> +				cmd = CMD_NULL;
> +			} else if (instr->ctx.cmd.opcode == NAND_CMD_PARAM) {
> +				cmd = CMD_PARAMETER_READ;
> +			} else if (instr->ctx.cmd.opcode == NAND_CMD_RNDOUT) {
> +				cmd = CMD_PARAMETER_CHANGE_COL;
> +			} else if (instr->ctx.cmd.opcode == NAND_CMD_RNDOUTSTART) {
> +				cmd = CMD_NULL;
> +			} else {
> +				dev_err(ctrl->dev, "unsupported cmd=%d\n",
> +					instr->ctx.cmd.opcode);
> +				ret = -EOPNOTSUPP;
> +				break;
> +			}

You could probably use an associative array here to limit the amount of 
lines?

[snip]

> -	for (i = 0; i < op->ninstrs; i++) {
> -		ret = brcmnand_exec_instr(host, i, op);
> -		if (ret)
> -			break;
> -	}
> +	if (ctrl->nand_version >= 0x500)
> +		brcmnand_exec_instructions(chip, op);
> +	else
> +		brcmnand_exec_instructions_legacy(chip, op);

I would add a new function pointer member to brcmnand_controller in 
order to avoid doing this test every time we call brcmnand_exec_op().

Thanks for doing this work!
-- 
Florian


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ