linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: Neil Horman <nhorman-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org>
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Bill Brown <bill.e.brown-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
	Seth Heasley
	<seth.heasley-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Subject: Re: [PATCH v5] i2c: Adding support for Intel iSMT SMBus 2.0 host controller
Date: Tue, 29 Jan 2013 23:10:28 +0100	[thread overview]
Message-ID: <20130129231028.41b04fc9@endymion.delvare> (raw)
In-Reply-To: <20130129153253.GA14044-B26myB8xz7F8NnZeBjwnZQMhkBWG/bsMQH7oEaQurus@public.gmane.org>

On Tue, 29 Jan 2013 10:32:53 -0500, Neil Horman wrote:
> On Tue, Jan 29, 2013 at 03:05:51PM +0100, Jean Delvare wrote:
> > On Mon, 28 Jan 2013 14:43:52 -0500, Neil Horman wrote:
> > > +		if (size != I2C_SMBUS_QUICK)
> > > +			memcpy(data, dma_buffer,
> > > +			       min(sizeof(*data), (size_t)I2C_SMBUS_BLOCK_MAX));
> > 
> > This computation looks wrong. We already know that sizeof(*data) ==
> > sizeof(union i2c_smbus_data) > I2C_SMBUS_BLOCK_MAX, so the min() above
> > will always return I2C_SMBUS_BLOCK_MAX. Which may be insufficient as
> > the first byte holds the length, and at the same time it will be more
> > than needed in most cases.
> 
> Gah!  Sorry, you're right, I wasn't paying attention and though that data was
> just an allocated buffer, I need to fix that.
> 
> > My original suggestion to limit the size of the copy was meant as a
> > run-time optimization, i.e. copying exactly the number of bytes that
> > were received from the slave. That would be 1 or 2 for non-block reads,
> > and the block length for block reads. Unfortunately I'm not sure is the
> > block length is available. See my comment about this below in
> > ismt_access().
> 
> We don't currently have the dma_size, no, but the only calling function computes
> it (either from the block header or sets it appropriately for non-block
> transfers).  We can pass that into the process_desc function and fix this.

This won't fix it, unless the hardware happens to update dma_size when
receiving a block from a slave. If not then dma_size will always be
I2C_SMBUS_BLOCK_MAX, while what we need is the number of bytes actually
received.

> > > +static int ismt_access(struct i2c_adapter *adap, u16 addr,
> > > +		       unsigned short flags, char read_write, u8 command,
> > > +		       int size, union i2c_smbus_data *data)
> > > +{
> > > +	int ret;
> > > +	dma_addr_t dma_addr = 0; /* address of the data buffer */
> > > +	u8 dma_size = 0;
> > > +	enum dma_data_direction dma_direction = 0;
> > > +	struct ismt_desc *desc;
> > > +	struct ismt_priv *priv = i2c_get_adapdata(adap);
> > > +	struct device *dev = &priv->pci_dev->dev;
> > > +
> > > +	desc = &priv->hw[priv->head];
> > > +
> > > +	/* Initialize the descriptor */
> > > +	memset(desc, 0, sizeof(struct ismt_desc));
> > > +	desc->tgtaddr_rw = ISMT_DESC_ADDR_RW(addr, read_write);
> > > +
> > > +	/* Create a temporary buffer for the DMA transaction */
> > > +	/* and insert the command at the beginning of the buffer */
> > > +	if ((read_write == I2C_SMBUS_WRITE) &&
> > > +	    (size != I2C_SMBUS_QUICK)) {
> > 
> > If I read the code below properly, this can be skipped for size ==
> > I2C_SMBUS_BYTE too, right?
> I don't think so.  The command field contains the data, and that is right below
> the memcpy in that if clause.  We can certainly optimize this however, given
> that I need to fix the memcpy sizes anyway.

Precisely, I'm not sure the priv->dma_buffer[0] = command is needed in
this specific case, because later on we have:

			desc->control |= ISMT_DESC_CWRL;
			desc->wr_len_cmd = command;

and dma_size isn't set, which suggests that priv->dma_buffer won't even
be used. Honestly this "presetting" of priv->dma_buffer causes more
confusion than it helps, and performance-wise it makes little sense, so
I wouldn't object to you exploding it to the relevant code paths in the
switch statement.

I'll take a look at the datasheet tomorrow to check if I got it right
or you did. Or neither of us ^^ I'll also look for test hardware, I
don't have that at home obviously, but at work maybe.

-- 
Jean Delvare

  parent reply	other threads:[~2013-01-29 22:10 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-07  0:36 [PATCH v4] i2c: Adding support for Intel iSMT SMBus 2.0 host controller Bill E Brown
     [not found] ` <1354840604-8160-1-git-send-email-bill.e.brown-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2012-12-07  0:34   ` Brown, Bill E
2012-12-18 14:03   ` Jean Delvare
     [not found]     ` <20121218150337.5b861ae3-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2013-01-28 19:43       ` [PATCH v5] " Neil Horman
     [not found]         ` <1359402232-21369-1-git-send-email-nhorman-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org>
2013-01-29 14:05           ` Jean Delvare
     [not found]             ` <20130129150551.498b2a9b-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2013-01-29 15:32               ` Neil Horman
     [not found]                 ` <20130129153253.GA14044-B26myB8xz7F8NnZeBjwnZQMhkBWG/bsMQH7oEaQurus@public.gmane.org>
2013-01-29 22:10                   ` Jean Delvare [this message]
     [not found]                     ` <20130129231028.41b04fc9-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2013-01-30 14:15                       ` Neil Horman
     [not found]                         ` <20130130141504.GA2968-0o1r3XBGOEbbgkc5XkKeNuvMHUBZFtU3YPYVAmT7z5s@public.gmane.org>
2013-01-30 21:55                           ` Jean Delvare
2013-01-29 16:57               ` Heasley, Seth
     [not found]                 ` <DEC3922D1904474A8862C7BFF516EA9A59B47EB2-P5GAC/sN6hmkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2013-01-29 18:52                   ` Jean Delvare
2013-01-29 14:29           ` Jean Delvare
2013-02-01 19:48           ` [PATCH v6] " Neil Horman
     [not found]             ` <1359748083-24423-1-git-send-email-nhorman-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org>
2013-02-04  9:47               ` Jean Delvare
     [not found]                 ` <20130204104744.5f83541e-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2013-02-04 17:19                   ` Jean Delvare
     [not found]                     ` <20130204181902.06c247ad-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2013-02-04 17:28                       ` Neil Horman
     [not found]                         ` <20130204172851.GA24749-B26myB8xz7F8NnZeBjwnZQMhkBWG/bsMQH7oEaQurus@public.gmane.org>
2013-02-05  7:21                           ` Jean Delvare
2013-02-04 19:54           ` [PATCH v7] " Neil Horman
     [not found]             ` <1360007650-26272-1-git-send-email-nhorman-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org>
2013-02-05  1:13               ` Heasley, Seth
     [not found]                 ` <DEC3922D1904474A8862C7BFF516EA9A59B4A8B8-P5GAC/sN6hmkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2013-02-05  7:16                   ` Jean Delvare
     [not found]                     ` <20130205081642.5349bd1a-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2013-02-05 14:52                       ` Neil Horman
     [not found]                         ` <20130205145230.GA4511-B26myB8xz7F8NnZeBjwnZQMhkBWG/bsMQH7oEaQurus@public.gmane.org>
2013-02-05 16:41                           ` Jean Delvare
2013-02-05 16:41               ` Jean Delvare
2013-02-10 15:02               ` Wolfram Sang
     [not found]                 ` <20130210150205.GB6282-8EAEigeeuNG034pCzgS/Qg7AFbiQbgqx@public.gmane.org>
2013-03-05 14:22                   ` Neil Horman
     [not found]                     ` <20130305142225.GA23095-B26myB8xz7F8NnZeBjwnZQMhkBWG/bsMQH7oEaQurus@public.gmane.org>
2013-03-05 14:42                       ` Jean Delvare
     [not found]                         ` <20130305154253.317bd23a-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2013-03-05 16:09                           ` Neil Horman

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=20130129231028.41b04fc9@endymion.delvare \
    --to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
    --cc=bill.e.brown-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=nhorman-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org \
    --cc=seth.heasley-ral2JQCrhuEAvxtiuMwx3w@public.gmane.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 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).