devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
To: Christophe RICARD
	<christophe.ricard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: peterhuewe-Mmb7MZpHnFY@public.gmane.org,
	ashley-fm2HMyfA2y6tG0bUXCXiUA@public.gmane.org,
	tpmdd-yWjUBOtONefk1uMJSBkQmQ@public.gmane.org,
	tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	christophe-h.ricard-qxv4g6HH51o@public.gmane.org,
	jean-luc.blanc-qxv4g6HH51o@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v3 11/15] tpm/tpm_i2c_stm_st33: Replace wait_for_serirq_timeout by wait_for_tpm_stat
Date: Tue, 14 Oct 2014 15:15:53 -0600	[thread overview]
Message-ID: <20141014211553.GA30570@obsidianresearch.com> (raw)
In-Reply-To: <20141014224425.45b5de03@toffy-MacBookPro>

On Tue, Oct 14, 2014 at 10:44:25PM +0200, Christophe RICARD wrote:

> > > +		r =
> > > wait_event_interruptible_timeout(chip->vendor.read_queue,
> > > +					check_locality(chip) >= 0,
> > > +					timeout);
> > 
> > Can it use wait_for_stat?
> It actually cannot use wait_for_stat because wait_for_stat is waiting
> for a mask condition on the status register. Here we are addressing the
> TPM_ACCESS register.

It would be cleaner if wait_for_stat handled all sleep-for-irq
actions.

> > This seqence is racy, the reason the nuvoton driver has the counter is
> > because wake_up_interruptible only wakes sleeping threads, so the
> > driver has to use the counter to close the race between the enable_irq
> > and the actual sleep:
> > 
> > 		unsigned int cur_intrs = priv->intrs;
> > 		enable_irq(chip->vendor.irq);
> > 		rc = wait_event_interruptible_timeout(*queue,
> > 						      cur_intrs !=
> > priv->intrs, timeout);
> If my understanding is correct the counter prevent the case where the
> irq is raised before entering into the wait_event_interruptible_timeout.
> wait_for_tpm_stat will check before going into sleep the status
> register in order to make sure the condition is not already satisfied
> and should fulfill this requirement.

Yes, your analysis is correct - removing the extra I2C polling would
be the goal of using the counter rather than an I2C read.

> As i could get different kind of interruption i think i cannot avoid an
> i2c check here. The other solution would be to activate only the right
> interruption in the INT_ENABLE tis register but still with an i2c
> transaction.

But there is a problem with the wrong interruption no matter what, the
wait_event_ loop does not ever re-enable_irq() - any generated IRQ
must already be exactly the IRQ that is being waited for. Basically,
the driver must remain synchronized with the chip and it must know
what IRQs can be generated at any point.

When I read the driver I assumed this was already happening, and the
auditing was going to be done to make sure it is the case, hence my
comments on the idle state.

The advantage is clearly that many I2C transactions can be eliminated
by relying on the IRQ line to signal progress.

The alternative is to have the wait_event loops clear the pending bits
and re-enable the IRQ every time they go around, but this is more
transactions.

Jason
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2014-10-14 21:15 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-13 20:23 [PATCH v3 00/15] ST33 I2C TPM driver cleanup Christophe Ricard
     [not found] ` <1413231817-5174-1-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-10-13 20:23   ` [PATCH v3 01/15] tpm/tpm_i2c_stm_st33: Update Kconfig in order to be inline to other similar product Christophe Ricard
2014-10-13 20:23   ` [PATCH v3 02/15] tpm/tpm_i2c_stm_st33: Fix few coding style error reported by scripts/checkpatch.pl Christophe Ricard
2014-10-13 20:23   ` [PATCH v3 03/15] tpm/tpm_i2c_stm_st33: Move tpm registers to tpm_i2c_stm_st33.c Christophe Ricard
2014-10-13 20:23   ` [PATCH v3 04/15] tpm/tpm_i2c_stm_st33: Add new tpm_stm_dev structure and remove tpm_i2c_buffer[0], [1] buffer Christophe Ricard
2014-10-13 20:23   ` [PATCH v3 05/15] tpm/tpm_i2c_stm_st33: Remove reference to io_serirq Christophe Ricard
2014-10-13 20:23   ` [PATCH v3 06/15] tpm/tpm_i2c_stm_st33: Replace err/rc/ret by r for a function return code Christophe Ricard
2014-10-13 20:23   ` [PATCH v3 07/15] tpm/tpm_i2c_stm_st33: Replace tpm_st33_* function with tpm_stm_* Christophe Ricard
2014-10-13 20:23   ` [PATCH v3 08/15] tpm/tpm_i2c_stm_st33: Add devicetree structure Christophe Ricard
     [not found]     ` <1413231817-5174-9-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-10-14 17:32       ` Jason Gunthorpe
     [not found]         ` <20141014173209.GD27232-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-14 19:59           ` Christophe RICARD
2014-10-13 20:23   ` [PATCH v3 09/15] tpm/tpm_i2c_stm_st33/dts/st33zp24_i2c: Add DTS Documentation Christophe Ricard
2014-10-13 20:23   ` [PATCH v3 10/15] tpm/tpm_i2c_stm_st33: Few code cleanup Christophe Ricard
2014-10-13 20:23   ` [PATCH v3 11/15] tpm/tpm_i2c_stm_st33: Replace wait_for_serirq_timeout by wait_for_tpm_stat Christophe Ricard
     [not found]     ` <1413231817-5174-12-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-10-14 18:09       ` Jason Gunthorpe
     [not found]         ` <20141014180914.GE27232-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-14 20:44           ` Christophe RICARD
2014-10-14 21:15             ` Jason Gunthorpe [this message]
2014-10-13 20:23   ` [PATCH v3 12/15] tpm/tpm_i2c_stm_st33: Remove useless i2c read on interrupt registers Christophe Ricard
     [not found]     ` <1413231817-5174-13-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-10-14  8:17       ` [tpmdd-devel] " Marcin Obara
     [not found]         ` <CAPxFvEPT8wEt4BfZ7112aFpsowXV2WUHvsN5W9=iKUvmRpcBFw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-10-14  8:34           ` Christophe Henri RICARD
2014-10-13 20:23   ` [PATCH v3 13/15] tpm/tpm_i2c_stm_st33: Fix potential bug in tpm_stm_i2c_send Christophe Ricard
2014-10-13 20:23   ` [PATCH v3 14/15] tpm/tpm_i2c_stm_st33: Change License header to have up to date address information Christophe Ricard
2014-10-13 20:23   ` [PATCH v3 15/15] tpm/tpm_i2c_stm_st33: Increment driver version to 1.2.1 Christophe Ricard
2014-10-14 18:51   ` [PATCH v3 00/15] ST33 I2C TPM driver cleanup Jason Gunthorpe

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=20141014211553.GA30570@obsidianresearch.com \
    --to=jgunthorpe-epgobjl8dl3ta4ec/59zmfatqe2ktcn/@public.gmane.org \
    --cc=ashley-fm2HMyfA2y6tG0bUXCXiUA@public.gmane.org \
    --cc=christophe-h.ricard-qxv4g6HH51o@public.gmane.org \
    --cc=christophe.ricard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=jean-luc.blanc-qxv4g6HH51o@public.gmane.org \
    --cc=peterhuewe-Mmb7MZpHnFY@public.gmane.org \
    --cc=tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=tpmdd-yWjUBOtONefk1uMJSBkQmQ@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).