From: Frederic Konrad <fred.konrad@greensocs.com>
To: minyard@acm.org, qemu-devel@nongnu.org, cminyard@mvista.com
Cc: Peter Maydell <peter.maydell@linaro.org>,
Peter Crosthwaite <crosthwaite.peter@gmail.com>,
Alistair Francis <alistair.francis@xilinx.com>,
Kwon <hyun.kwon@xilinx.com>
Subject: Re: [Qemu-devel] [PATCH v2] i2c: Fix SMBus read transactions to avoid double events
Date: Wed, 6 Jul 2016 08:57:58 +0200 [thread overview]
Message-ID: <577CABF6.7010502@greensocs.com> (raw)
In-Reply-To: <1467142212-29810-1-git-send-email-minyard@acm.org>
On 06/28/2016 09:30 PM, minyard@acm.org wrote:
> From: Corey Minyard <cminyard@mvista.com>
>
> Change 2293c27faddf (i2c: implement broadcast write) added broadcast
> capability to the I2C bus, but it broke SMBus read transactions.
> An SMBus read transaction does two i2c_start_transaction() calls
> without an intervening i2c_end_transfer() call. This will
> result in i2c_start_transfer() adding the same device to the
> current_devs list twice, and then the ->event() for the same
> device gets called twice in the second call to i2c_start_transfer(),
> resulting in the smbus code getting confused.
Hi Corey,
I didn't know that we can do two i2c_start_transfer without an
end_transfert in the middle. Maybe worth a comment in the code?
Otherwise:
Reviewed-by: KONRAD Frederic <fred.konrad@greensocs.com>
Tested-by: KONRAD Frederic <fred.konrad@greensocs.com>
Thanks,
Fred
>
> Note that this happens even with pure I2C devices when simulating
> SMBus over I2C.
>
> This fix only scans the bus if the current set of devices is empty.
> This means that the current set of devices stays fixed until
> i2c_end_transfer() is called, which is really what you want.
>
> This also deletes the empty check from the top of i2c_end_transfer().
> It's unnecessary, and it prevents the broadcast variable from being
> set to false at the end of the transaction if no devices were on
> the bus.
>
> Cc: KONRAD Frederic <fred.konrad@greensocs.com>
> Cc: Alistair Francis <alistair.francis@xilinx.com>
> Cc: Peter Crosthwaite <crosthwaite.peter@gmail.com>
> Cc: Kwon <hyun.kwon@xilinx.com>
> Cc: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Corey Minyard <cminyard@mvista.com>
> ---
> hw/i2c/core.c | 28 +++++++++++++++-------------
> 1 file changed, 15 insertions(+), 13 deletions(-)
>
> This fix should work with I2C devices as well as SMBus devices.
>
> Sorry for not thinking it through all the way before.
>
> diff --git a/hw/i2c/core.c b/hw/i2c/core.c
> index abb3efb..6313d31 100644
> --- a/hw/i2c/core.c
> +++ b/hw/i2c/core.c
> @@ -101,15 +101,21 @@ int i2c_start_transfer(I2CBus *bus, uint8_t address, int recv)
> bus->broadcast = true;
> }
>
> - QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
> - DeviceState *qdev = kid->child;
> - I2CSlave *candidate = I2C_SLAVE(qdev);
> - if ((candidate->address == address) || (bus->broadcast)) {
> - node = g_malloc(sizeof(struct I2CNode));
> - node->elt = candidate;
> - QLIST_INSERT_HEAD(&bus->current_devs, node, next);
> - if (!bus->broadcast) {
> - break;
> + /*
> + * If there are already devices in the list, that means we are in
> + * the middle of a transaction and we shouldn't rescan the bus.
> + */
> + if (QLIST_EMPTY(&bus->current_devs)) {
> + QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) {
> + DeviceState *qdev = kid->child;
> + I2CSlave *candidate = I2C_SLAVE(qdev);
> + if ((candidate->address == address) || (bus->broadcast)) {
> + node = g_malloc(sizeof(struct I2CNode));
> + node->elt = candidate;
> + QLIST_INSERT_HEAD(&bus->current_devs, node, next);
> + if (!bus->broadcast) {
> + break;
> + }
> }
> }
> }
> @@ -134,10 +140,6 @@ void i2c_end_transfer(I2CBus *bus)
> I2CSlaveClass *sc;
> I2CNode *node, *next;
>
> - if (QLIST_EMPTY(&bus->current_devs)) {
> - return;
> - }
> -
> QLIST_FOREACH_SAFE(node, &bus->current_devs, next, next) {
> sc = I2C_SLAVE_GET_CLASS(node->elt);
> if (sc->event) {
>
next prev parent reply other threads:[~2016-07-06 6:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-28 19:30 [Qemu-devel] [PATCH v2] i2c: Fix SMBus read transactions to avoid double events minyard
2016-07-06 6:57 ` Frederic Konrad [this message]
2016-07-06 12:10 ` Corey Minyard
-- strict thread matches above, loose matches on Subject: below --
2016-08-02 16:00 minyard
2016-10-21 17:57 ` Peter Maydell
2016-10-21 18:21 ` Corey Minyard
2016-10-22 9:20 ` Peter Maydell
2016-10-23 21:38 ` Corey Minyard
2016-10-24 14:14 ` Peter Maydell
2016-10-24 14:28 ` Corey Minyard
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=577CABF6.7010502@greensocs.com \
--to=fred.konrad@greensocs.com \
--cc=alistair.francis@xilinx.com \
--cc=cminyard@mvista.com \
--cc=crosthwaite.peter@gmail.com \
--cc=hyun.kwon@xilinx.com \
--cc=minyard@acm.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.