devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
To: Christophe Henri RICARD
	<christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
Cc: Christophe RICARD
	<christophe.ricard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	"peterhuewe-Mmb7MZpHnFY@public.gmane.org"
	<peterhuewe-Mmb7MZpHnFY@public.gmane.org>,
	"ashley-fm2HMyfA2y6tG0bUXCXiUA@public.gmane.org"
	<ashley-fm2HMyfA2y6tG0bUXCXiUA@public.gmane.org>,
	"tpmdd-yWjUBOtONefk1uMJSBkQmQ@public.gmane.org"
	<tpmdd-yWjUBOtONefk1uMJSBkQmQ@public.gmane.org>,
	"devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org"
	<tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
	Jean-Luc BLANC <jean-luc.blanc-qxv4g6HH51o@public.gmane.org>
Subject: Re: [tpmdd-devel] [PATCH 11/16] tpm/tpm_i2c_stm_st33: Remove useless i2c read on interrupt registers
Date: Thu, 9 Oct 2014 12:20:29 -0600	[thread overview]
Message-ID: <20141009182029.GB26675@obsidianresearch.com> (raw)
In-Reply-To: <0B9F1C5B86169C4EA9D042C251022E4938EC504B46-+EwDPpWUVoSRc5Omjj0epdBPR1lH4CV8@public.gmane.org>

On Thu, Oct 09, 2014 at 07:35:07PM +0200, Christophe Henri RICARD wrote:
> Hi Jason,
> 
> > If your chip is sane like other TPMs the IRQ pin will *only* be
> > asserted while there is data pending in the out command FIFO,
> > reading the FIFO *should naturally clear the IRQ *and the acking
> > process may be entirely unnecessary and can be removed.

> I believe this assessment is wrong according to existing
> specifications and current implementation and I will explain you
> why:

It does sound like it is not how the ST33 chip operates.

> Our TPM is managing the TPM TIS registers Interrupt Enable and
> Interrupt Status.

The TIS register mapping was intended for environments where register
access is not expensive, and can be done from an ISR. I2C is not such
an environment, which is why other vendors are not using such a strict
mapping of the TIS registers.

That doesn't really change anything, it just means the driver has to
do more I2C transactions to manage this extra chip state.

> According to which one is triggered, the wait queue to wake up is
> different it could be chip->vendor.read_queue or
> chip->vendor.int_queue.

These different queues are not needed, the driver knows what it is
waiting for when it enables the interrupt handler, and can manipulate
the interrupt mask if necessary for special cases. Multiple queues
make more sense when the ISR can cheaply read the status register,
which is not true for I2C.

> I would point out as well the int_queue initialization in the
> i2c_nuvoton_probe which is never used in the tpm_i2c_nuvoton.c nor
> in any tpm core file.

Chip structure members that are not used in the core code are hold
overs from the ancient core design. Drivers ideally should not use
them, favoring their own structures in their driver private
allocation. Someday that will get cleaned up.

Don't get confused that int_queue and read_queue are in the global
chip, they have no special meaning, modern drivers should not use
them at all.

> However, I am not in favor to change to non-threaded irq unless I
> have a clear and convincing argument to do so.

The need for the udelay should be all the convincing required. The
reason for the udelay clearly shows the driver has a synchronization
problem - and sleeping to solve synchronization problem is rarely
correct.

This is especially true since I've already explained how to design so
everything is synchronous and solve the issue.

Again:

In TPM the interrupt is not delivering an asynchronous notification,
everything is synchronous to the driver state, ISRs happen only to
indicate completion of driver initiated actions.

This is why the synchronous flow I suggested is much safer and better,
the driver just can't get the situation where the IRQ cannot safely
run because the main driver thread has changed the TPM state.

To summarize, the flow for an interrupt wait becomes very
simple, ie to wait for command ready:

 - Do write to clear all interrupts
 - do read on command ready
 - if not ready then write to enable only the command ready occured interrupt
 - enable_irq
 - wait for irq w/ timer
 - do read on command ready
 - if not ready and no timeout, do write to clear all interrupts,
   enable_irq, loop.
 - if not ready and timeout, disable irq, return error

All sleepables follow the same synchronous pattern. This makes the
driver compeltely single threaded so no analysis for thread problems
is need. No locking primitives are needed. The inter-locking problem
with request_locality goes away.

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

  parent reply	other threads:[~2014-10-09 18:20 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-07 20:02 [PATCH 00/16] ST33 I2C TPM driver cleanup Christophe Ricard
     [not found] ` <1412712189-1234-1-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-10-07 20:02   ` [PATCH 01/16] tpm/tpm_i2c_stm_st33: Update Kconfig in order to be inline to other similar product Christophe Ricard
     [not found]     ` <1412712189-1234-2-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-10-07 21:40       ` [tpmdd-devel] " Jason Gunthorpe
2014-10-07 20:02   ` [PATCH 02/16] tpm/tpm_i2c_stm_st33: Fix few coding style error reported by scripts/checkpatch.pl Christophe Ricard
2014-10-07 20:02   ` [PATCH 03/16] tpm/tpm_i2c_stm_st33: Move tpm registers to tpm_i2c_stm_st33.c Christophe Ricard
2014-10-07 20:02   ` [PATCH 04/16] tpm/tpm_i2c_stm_st33: Add new tpm_stm_dev structure and remove tpm_i2c_buffer[0], [1] buffer Christophe Ricard
2014-10-07 20:02   ` [PATCH 05/16] tpm/tpm_i2c_stm_st33: Replace err/rc/ret by r for a function return code Christophe Ricard
2014-10-07 20:02   ` [PATCH 06/16] tpm/tpm_i2c_stm_st33: Replace tpm_st33_* function with tpm_stm_* Christophe Ricard
2014-10-07 20:03   ` [PATCH 07/16] tpm/tpm_i2c_stm_st33: Add devicetree structure Christophe Ricard
     [not found]     ` <1412712189-1234-8-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-10-07 22:30       ` [tpmdd-devel] " Jason Gunthorpe
     [not found]         ` <20141007223025.GE2366-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-08  5:47           ` Christophe RICARD
     [not found]             ` <5434D00E.7000602-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-10-08 16:29               ` Jason Gunthorpe
     [not found]                 ` <20141008162922.GC4153-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-08 20:41                   ` Christophe Henri RICARD
     [not found]                     ` <0B9F1C5B86169C4EA9D042C251022E4938EC504766-+EwDPpWUVoSRc5Omjj0epdBPR1lH4CV8@public.gmane.org>
2014-10-08 20:51                       ` Jason Gunthorpe
     [not found]                         ` <20141008205116.GA13867-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-08 21:14                           ` Christophe Henri RICARD
     [not found]                             ` <0B9F1C5B86169C4EA9D042C251022E4938EC50476E-+EwDPpWUVoSRc5Omjj0epdBPR1lH4CV8@public.gmane.org>
2014-10-08 21:37                               ` Jason Gunthorpe
2014-10-07 20:03   ` [PATCH 08/16] tpm: dts: st33zp24_i2c: Add DTS Documentation Christophe Ricard
2014-10-07 20:03   ` [PATCH 09/16] tpm/tpm_i2c_stm_st33: Few code cleanup Christophe Ricard
2014-10-07 20:03   ` [PATCH 10/16] tpm/tpm_i2c_stm_st33: Replace wait_for_serirq_timeout by wait_for_tpm_stat Christophe Ricard
     [not found]     ` <1412712189-1234-11-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-10-07 22:11       ` [tpmdd-devel] " Jason Gunthorpe
     [not found]         ` <20141007221146.GC2366-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-08  5:38           ` Christophe RICARD
     [not found]             ` <5434CDD6.4050200-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-10-08 16:26               ` Jason Gunthorpe
     [not found]                 ` <20141008162609.GA4153-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-08 20:26                   ` Christophe Henri RICARD
     [not found]                     ` <0B9F1C5B86169C4EA9D042C251022E4938EC504762-+EwDPpWUVoSRc5Omjj0epdBPR1lH4CV8@public.gmane.org>
2014-10-08 20:41                       ` Jason Gunthorpe
2014-10-07 20:03   ` [PATCH 11/16] tpm/tpm_i2c_stm_st33: Remove useless i2c read on interrupt registers Christophe Ricard
     [not found]     ` <1412712189-1234-12-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-10-07 22:09       ` [tpmdd-devel] " Jason Gunthorpe
     [not found]         ` <20141007220917.GC10616-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-08  5:36           ` Christophe RICARD
     [not found]             ` <5434CD44.9090606-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-10-08 17:11               ` Jason Gunthorpe
     [not found]                 ` <20141008171140.GD4153-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-09 17:35                   ` Christophe Henri RICARD
     [not found]                     ` <0B9F1C5B86169C4EA9D042C251022E4938EC504B46-+EwDPpWUVoSRc5Omjj0epdBPR1lH4CV8@public.gmane.org>
2014-10-09 18:20                       ` Jason Gunthorpe [this message]
2014-10-07 20:03   ` [PATCH 12/16] tpm/tpm_i2c_stm_st33: Change License header to have up to date address information Christophe Ricard
2014-10-07 20:03   ` [PATCH 13/16] tpm/tpm_i2c_stm_st33: Add tpm_lock mutex for safe irq management Christophe Ricard
     [not found]     ` <1412712189-1234-14-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-10-07 21:56       ` [tpmdd-devel] " Jason Gunthorpe
     [not found]         ` <20141007215630.GB2366-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-08  5:21           ` Christophe RICARD
2014-10-07 20:03   ` [PATCH 14/16] tpm/tpm_i2c_stm_st33: Fix potential bug in tpm_stm_i2c_send Christophe Ricard
     [not found]     ` <1412712189-1234-15-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-10-07 22:04       ` [tpmdd-devel] " Jason Gunthorpe
     [not found]         ` <20141007220425.GB10616-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-08  5:31           ` Christophe RICARD
     [not found]             ` <CALD+uuxM2018GrkDL+6fUbWijYTRYbqB-YFNQRkCj=ZEkPkgng@mail.gmail.com>
     [not found]               ` <CALD+uuxM2018GrkDL+6fUbWijYTRYbqB-YFNQRkCj=ZEkPkgng-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-10-08 16:27                 ` Jason Gunthorpe
2014-10-07 20:03   ` [PATCH 15/16] tpm/tpm_i2c_stm_st33: Add delay before release_locality to make sure irq are cleared Christophe Ricard
     [not found]     ` <1412712189-1234-16-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-10-07 21:56       ` [tpmdd-devel] " Jason Gunthorpe
2014-10-07 20:03   ` [PATCH 16/16] tpm: Increment driver version to 1.2.1 Christophe Ricard
2014-10-07 20:30   ` [PATCH 00/16] ST33 I2C TPM driver cleanup Peter Hüwe
2014-10-07 22:25   ` [tpmdd-devel] " Jason Gunthorpe
     [not found]     ` <20141007222525.GD2366-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2014-10-08  5:45       ` Christophe RICARD

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=20141009182029.GB26675@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).