linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Viresh Kumar <viresh.kumar@linaro.org>
To: Wolfram Sang <wsa@kernel.org>, Jie Deng <jie.deng@intel.com>,
	linux-i2c@vger.kernel.org,
	virtualization@lists.linux-foundation.org,
	linux-kernel@vger.kernel.org, mst@redhat.com,
	jasowang@redhat.com, andriy.shevchenko@linux.intel.com,
	conghui.chen@intel.com, arnd@arndb.de, kblaiech@mellanox.com,
	jarkko.nikula@linux.intel.com, Sergey.Semin@baikalelectronics.ru,
	rppt@kernel.org, loic.poulain@linaro.org, tali.perry1@gmail.com,
	u.kleine-koenig@pengutronix.de, bjorn.andersson@linaro.org,
	yu1.wang@intel.com, shuo.a.liu@intel.com, stefanha@redhat.com,
	pbonzini@redhat.com
Subject: Re: [PATCH v10] i2c: virtio: add a virtio i2c frontend driver
Date: Mon, 5 Jul 2021 17:48:32 +0530	[thread overview]
Message-ID: <20210705121832.fmye5xnlbydoc5ir@vireshk-i7> (raw)
In-Reply-To: <YNr5ZRhT3qn+e9/m@ninjato>

On 29-06-21, 12:43, Wolfram Sang wrote:
> 
> > From the spec:
> > 
> > The case when ``length of \field{write_buf}''=0, and at the same time,
> > ``length of \field{read_buf}''=0 doesn't make any sense.
> > 
> > I mentioned this in my first reply and to my understanding I did not get
> > a reply that this has changed meanwhile.
> > 
> 
> Also, this code as mentioned before:
> 
> > +             if (!msgs[i].len)
> > +                     break;
> 
> I hope this can extended in the future to allow zero-length messages. If
> this is impossible we need to set an adapter quirk instead.

Wolfram,

I stumbled again upon this while working at the backend implementation.

If you look at i2c_smbus_xfer_emulated(), the command is always sent via
msgbuf0[0]. Even in the case of I2C_SMBUS_QUICK, where we set msg[0].len = 0, we
still send the buf. This is really confusing :(

Do I understand correctly that we always need to send msg[0].buf even when
msg[0].len is 0 ?

If so, it would be difficult to implement this with the current i2c virtio
specification, as the msg.len isn't really passed from guest to host, rather it
is inferred using the length of the buffer itself. And so we can't really pass a
buffer if length is 0.

Moreover, the driver uses i2c_get_dma_safe_msg_buf(), which also depends on the
length parameter here to allocate the buffer and copy data to it.

All in all, the latest version of the driver doesn't work with "i2cdetect -q <bus>".

To make it work, I had to add this:

diff --git a/drivers/i2c/busses/i2c-virtio.c b/drivers/i2c/busses/i2c-virtio.c
index 731267d42292..5b8bd98ae38e 100644
--- a/drivers/i2c/busses/i2c-virtio.c
+++ b/drivers/i2c/busses/i2c-virtio.c
@@ -73,6 +73,9 @@ static int virtio_i2c_prepare_reqs(struct virtqueue *vq,
                sg_init_one(&out_hdr, &reqs[i].out_hdr, sizeof(reqs[i].out_hdr));
                sgs[outcnt++] = &out_hdr;

+               if (!msgs[i].len)
+                       msgs[i].len = 1;
+
                if (msgs[i].len) {
                        reqs[i].buf = i2c_get_dma_safe_msg_buf(&msgs[i], 1);
                        if (!reqs[i].buf)

which made it I2C_SMBUS_BYTE instead of I2C_SMBUS_QUICK.

What should we do here Wolfram?


Jie, while wolfram comes back and replies to this, I think you need to switch
back to NOT supporting zero length transfer and set update virtio_i2c_func() to
return:

        I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);

Support for zero-length transfers and I2C_FUNC_SMBUS_QUICK can be added
separately.

Thanks.

-- 
viresh

  parent reply	other threads:[~2021-07-05 12:18 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-23 14:19 [PATCH v10] i2c: virtio: add a virtio i2c frontend driver Jie Deng
2021-03-23  7:27 ` Viresh Kumar
2021-03-23  8:33   ` Jie Deng
2021-03-23  8:37     ` Viresh Kumar
2021-03-23  9:27     ` Arnd Bergmann
2021-03-24  1:17       ` Jie Deng
2021-03-24  4:00         ` Viresh Kumar
2021-04-15  6:45       ` Viresh Kumar
2021-04-15  6:56         ` Jie Deng
2021-04-15  7:15           ` Viresh Kumar
2021-04-15  7:21           ` Wolfram Sang
2021-04-15  7:24             ` Viresh Kumar
2021-04-15  7:28               ` Wolfram Sang
2021-04-15  7:37                 ` Viresh Kumar
2021-04-15  8:15                 ` Jie Deng
2021-04-15  8:18                   ` Wolfram Sang
2021-04-15  8:20                     ` Jie Deng
2021-05-27  6:49                     ` Jie Deng
2021-05-12  1:37             ` Jie Deng
2021-03-23  9:01 ` Viresh Kumar
2021-03-23  9:38   ` Viresh Kumar
2021-03-24  0:53     ` Jie Deng
2021-03-24  3:52       ` Viresh Kumar
2021-03-24  4:00         ` Jie Deng
2021-03-24  4:02           ` Viresh Kumar
2021-03-24  4:20 ` Viresh Kumar
2021-03-24  6:05   ` Jie Deng
2021-03-24  6:09     ` Viresh Kumar
2021-03-24  6:41       ` Jie Deng
2021-03-24  6:44         ` Viresh Kumar
2021-04-14  2:07 ` Jie Deng
2021-04-14  3:52   ` Viresh Kumar
2021-04-15  6:25     ` Jie Deng
2021-04-15  3:51 ` Jason Wang
2021-04-15  6:17   ` Jie Deng
2021-06-28  8:39 ` Wolfram Sang
2021-06-28  9:01   ` Arnd Bergmann
2021-06-28  9:25     ` Wolfram Sang
2021-06-28  9:51       ` Arnd Bergmann
2021-06-28 10:13         ` Wolfram Sang
2021-06-28 11:50           ` Arnd Bergmann
2021-06-28 14:58             ` Wolfram Sang
2021-06-29  3:04               ` Jie Deng
2021-06-29  8:30                 ` Wolfram Sang
2021-06-29  9:13                   ` Viresh Kumar
2021-06-29  9:36                     ` Wolfram Sang
2021-06-29  4:10               ` Viresh Kumar
2021-06-29  8:27                 ` Wolfram Sang
2021-06-29  8:52                   ` Viresh Kumar
2021-06-29  9:07                     ` Wolfram Sang
2021-06-30 14:38                 ` Wolfram Sang
2021-06-30 15:09                   ` Viresh Kumar
2021-06-29  3:03     ` Jie Deng
2021-06-29 10:07 ` Wolfram Sang
2021-06-29 10:16   ` Viresh Kumar
2021-06-29 10:23     ` Wolfram Sang
2021-06-29 10:30       ` Viresh Kumar
2021-06-29 10:42         ` Wolfram Sang
2021-06-29 10:43           ` Wolfram Sang
2021-06-29 10:56             ` Viresh Kumar
2021-06-29 11:11               ` Wolfram Sang
2021-06-29 11:16                 ` Viresh Kumar
2021-06-29 11:48                   ` Wolfram Sang
2021-07-05 12:18             ` Viresh Kumar [this message]
2021-07-06  1:50               ` Jie Deng
2021-07-22 15:15               ` Wolfram Sang
2021-07-23  2:28                 ` Viresh Kumar
2021-07-23  5:28                   ` Viresh Kumar
2021-06-30  6:45   ` Jie Deng
2021-06-30  7:32     ` Wolfram Sang
2021-06-30  7:51       ` Jie Deng
2021-06-30  7:55         ` Arnd Bergmann
2021-06-30  8:04           ` Wolfram Sang
2021-06-30  8:07           ` Andy Shevchenko
2021-06-30  8:29             ` Arnd Bergmann

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=20210705121832.fmye5xnlbydoc5ir@vireshk-i7 \
    --to=viresh.kumar@linaro.org \
    --cc=Sergey.Semin@baikalelectronics.ru \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=bjorn.andersson@linaro.org \
    --cc=conghui.chen@intel.com \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=jasowang@redhat.com \
    --cc=jie.deng@intel.com \
    --cc=kblaiech@mellanox.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loic.poulain@linaro.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rppt@kernel.org \
    --cc=shuo.a.liu@intel.com \
    --cc=stefanha@redhat.com \
    --cc=tali.perry1@gmail.com \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=wsa@kernel.org \
    --cc=yu1.wang@intel.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;
as well as URLs for NNTP newsgroup(s).