From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Stefan Agner <stefan@agner.ch>
Cc: Boris Brezillon <boris.brezillon@bootlin.com>,
marcel.ziswiler@toradex.com, richard@nod.at,
bpringlemeir@gmail.com, marek.vasut@gmail.com,
linux-mtd@lists.infradead.org, cyrille.pitchen@wedev4u.fr,
computersforpeace@gmail.com, dwmw2@infradead.org
Subject: Re: [RFC PATCH v3 2/3] mtd: nand: vf610_nfc: make use of ->exec_op()
Date: Wed, 21 Feb 2018 11:09:11 +0100 [thread overview]
Message-ID: <20180221110911.4fe46b8c@xps13> (raw)
In-Reply-To: <e5d20aa9a17caaa79a3618367f22637f@agner.ch>
Hi Stefan,
> >> >> +{
> >> >> + vf610_nfc_set_field(nfc, NFC_COL_ADDR, COL_ADDR_MASK,
> >> >> + COL_ADDR_SHIFT, col);
> >> >> +
> >> >> + vf610_nfc_set_field(nfc, NFC_ROW_ADDR, ROW_ADDR_MASK,
> >> >> + ROW_ADDR_SHIFT, row);
> >> >> +
> >> >> + vf610_nfc_write(nfc, NFC_SECTOR_SIZE, trfr_sz);
> >> >> + vf610_nfc_write(nfc, NFC_FLASH_CMD1, cmd1);
> >> >> + vf610_nfc_write(nfc, NFC_FLASH_CMD2, cmd2);
> >> >> +
> >> >> + dev_dbg(nfc->dev, "col 0x%08x, row 0x%08x, cmd1 0x%08x, cmd2 0x%08x, trfr_sz %d\n",
> >> >> + col, row, cmd1, cmd2, trfr_sz);
> >> >> +
> >> >> + vf610_nfc_done(nfc);
> >> >> +}
> >> >> +
> >> >> +static inline const struct nand_op_instr *vf610_get_next_instr(
> >> >> + const struct nand_subop *subop, int *op_id)
> >> >> +{
> >> >> + if (*op_id + 1 >= subop->ninstrs)
> >> >> + return NULL;
> >> >> +
> >> >> + (*op_id)++;
> >> >> +
> >> >> + return &subop->instrs[*op_id];
> >> >> +}
> >> >> +
> >> >> +static int vf610_nfc_cmd(struct nand_chip *chip,
> >> >> + const struct nand_subop *subop)
> >> >> +{
> >> >> + const struct nand_op_instr *instr;
> >> >> + struct vf610_nfc *nfc = chip_to_nfc(chip);
> >> >> + struct mtd_info *mtd = nand_to_mtd(chip);
> >> >> + int op_id = -1, addr = 0, trfr_sz = 0;
> >> >> + u32 col = 0, row = 0, cmd1 = 0, cmd2 = 0, code = 0;
> >> >> +
> >> >> + /* Some ops are optional, but they need to be in order */
> >> >> + instr = vf610_get_next_instr(subop, &op_id);
> >> >> + if (!instr)
> >> >> + return -EINVAL;
> >> >> +
> >> >> + if (instr && instr->type == NAND_OP_CMD_INSTR) {
> >> >> + dev_dbg(nfc->dev, "OP_CMD: code 0x%02x\n", instr->ctx.cmd.opcode);
> >> >> + cmd2 |= instr->ctx.cmd.opcode << CMD_BYTE1_SHIFT;
> >> >> + code |= COMMAND_CMD_BYTE1;
> >> >> +
> >> >> + instr = vf610_get_next_instr(subop, &op_id);
> >> >> + }
> >> >> +
> >> >> + if (instr && instr->type == NAND_OP_ADDR_INSTR) {
> >> >> +
> >> >
> >> > Hm, you're still checking the sequencing consistency here. This should
> >> > have been taken care by the core parser already, so really, this is not
> >> > needed.
> >> >
> >>
> >> Since those operations are optional, I have to check...
> >
> > Looks like my previous pastebin was not containing all the changes I
> > wanted to share with you, so here is the full version [1].
> >
> > Hm, what do these checks add to the checks done in the parser? Even if
> > all instructions are optional in your pattern the core parser still
> > check that when they appear in the proper order. So, you can for
> > example never have CMD1+CMD2+ADDR*5 passed to vf610_nfc_cmd().
>
> Sure...
>
> >
> > The only exception I can think of is when you have DATA_OUT+CMD. In
> > this case, you probably want to skip CMD_BYTE1 and use CMD_BYTE2
> > directly, but that can easily be taken care of in the alternative
> > implementation I proposed:
> >
> > if (instr->type == NAND_OP_DATA_OUT_INSTR) {
> > /*
> > * If there was no CMD instruction before the
> > * DATA_OUT one, we must skip CMD_BYTE1 and use
> > * CMD_BYTE2 directly so that the CMD cycle is
> > * really placed after the DATA_OUT one.
> > */
> > if (!ncmds)
> > ncmds++;
> > ....
> > }
> >
> >
>
> I fully understand, I do not have to enforce order since I can rely on
> the order passed by the stack.
>
> It is also not what I am after. I just check which operation is going to
> be next. Like your switch statement.
>
> I just see don't see a real advantage in using a for loop. It makes it
> harder to read, since the order of operations will no more be obvious.
> It makes this ncmd work around necessary.
Well, the aim of ->exec_op() was initially to get rid of the controller
specificities and be free to implement new NAND operations without
having to check every controller driver in the world, so doing it this
way freezes the possibilities to a reduced set of operations (ie. what
we do today). This is wrong from my point of view and I would really
welcome a for-loop approach instead.
Thanks,
Miquèl
>
> Using a for loop just because we can? I haven't seen a convincing
> argument so far.
>
>
--
Miquel Raynal, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2018-02-21 10:09 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-08 23:59 [RFC PATCH v3 0/3] mtd: nand: vf610_nfc: make use of ->exec_op() Stefan Agner
2018-02-08 23:59 ` [RFC PATCH v3 1/3] mtd: nand: vf610_nfc: remove unused function Stefan Agner
2018-02-12 21:32 ` Boris Brezillon
2018-02-08 23:59 ` [RFC PATCH v3 2/3] mtd: nand: vf610_nfc: make use of ->exec_op() Stefan Agner
2018-02-09 8:20 ` Miquel Raynal
2018-02-09 12:41 ` Stefan Agner
2018-02-11 10:54 ` Boris Brezillon
2018-02-20 23:15 ` Stefan Agner
2018-02-20 23:34 ` Miquel Raynal
2018-02-21 7:18 ` Boris Brezillon
2018-02-21 8:30 ` Stefan Agner
2018-02-21 9:03 ` Boris Brezillon
2018-02-21 9:39 ` Stefan Agner
2018-02-21 10:09 ` Miquel Raynal [this message]
2018-02-21 12:32 ` Stefan Agner
2018-02-21 8:28 ` Boris Brezillon
2018-02-21 8:35 ` Boris Brezillon
2018-02-21 12:24 ` Stefan Agner
2018-02-21 12:46 ` Boris Brezillon
2018-02-21 21:18 ` Stefan Agner
2018-02-21 23:23 ` Stefan Agner
2018-02-22 9:13 ` Boris Brezillon
2018-02-08 23:59 ` [RFC PATCH v3 3/3] mtd: nand: vf610_nfc: remove old hooks Stefan Agner
2018-02-11 10:55 ` [RFC PATCH v3 0/3] mtd: nand: vf610_nfc: make use of ->exec_op() Boris Brezillon
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=20180221110911.4fe46b8c@xps13 \
--to=miquel.raynal@bootlin.com \
--cc=boris.brezillon@bootlin.com \
--cc=bpringlemeir@gmail.com \
--cc=computersforpeace@gmail.com \
--cc=cyrille.pitchen@wedev4u.fr \
--cc=dwmw2@infradead.org \
--cc=linux-mtd@lists.infradead.org \
--cc=marcel.ziswiler@toradex.com \
--cc=marek.vasut@gmail.com \
--cc=richard@nod.at \
--cc=stefan@agner.ch \
/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