From patchwork Sun Mar 20 19:34:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Ricard X-Patchwork-Id: 599893 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qSq1J0LmKz9s9G for ; Mon, 21 Mar 2016 06:35:16 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ahj83-00063c-AQ; Sun, 20 Mar 2016 19:35:11 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ahj82-00063T-Ne for tpmdd-devel@lists.sourceforge.net; Sun, 20 Mar 2016 19:35:10 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of gmail.com designates 74.125.82.42 as permitted sender) client-ip=74.125.82.42; envelope-from=christophe.ricard@gmail.com; helo=mail-wm0-f42.google.com; Received: from mail-wm0-f42.google.com ([74.125.82.42]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1ahj81-0007Lo-Qy for tpmdd-devel@lists.sourceforge.net; Sun, 20 Mar 2016 19:35:10 +0000 Received: by mail-wm0-f42.google.com with SMTP id l68so129124142wml.0 for ; Sun, 20 Mar 2016 12:35:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/oVlnDUfqQggEcMv91PnddeNJiznPlX8t/535H9K2nM=; b=IaIU+dpg1YG/y17CUGFq8WmAzegpJyv6IahRyXki5VsHznT2AOmOCCO0+tW8ApbgFj ls1ydN98+k2tsOhc76yrmwWeILluQbsNRy70iaHafBJSsljnFF8TY6a0A1JcET67t1vj sGO7P6LLBrngt7ZBseZrapeWwMvpNNmGUg3DdY2OEvEQy6454jF4wv0A54qyVXR8fp4/ N4T+cgyJrhYNE2vnQ9FOlp7ixim8H3zDGxIEjVKZzVLu+LY5GE4HEfGWYuDN2jZaz4fd u9fF+YVVFEfc03XJUWyRfIPQJWUogSsM975YUj9JY44G0PI4AMuDQZJBM1HDTbfaHhfH xKng== X-Gm-Message-State: AD7BkJKrViFnygJrebnu0NvURExBOsuwv1JjBT1nk7fmf4J20tOjpqqrzSYnTWhBYs1JEg== X-Received: by 10.28.99.6 with SMTP id x6mr10552905wmb.46.1458502503857; Sun, 20 Mar 2016 12:35:03 -0700 (PDT) Received: from localhost.localdomain (AMarseille-654-1-498-218.w86-210.abo.wanadoo.fr. [86.210.138.218]) by smtp.gmail.com with ESMTPSA id w203sm7560646wmg.14.2016.03.20.12.35.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 20 Mar 2016 12:35:02 -0700 (PDT) From: Christophe Ricard X-Google-Original-From: Christophe Ricard To: jarkko.sakkinen@linux.intel.com Date: Sun, 20 Mar 2016 20:34:40 +0100 Message-Id: <1458502483-16887-10-git-send-email-christophe-h.ricard@st.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1458502483-16887-1-git-send-email-christophe-h.ricard@st.com> References: <1458502483-16887-1-git-send-email-christophe-h.ricard@st.com> X-Spam-Score: -1.6 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (christophe.ricard[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1ahj81-0007Lo-Qy Cc: jean-luc.blanc@st.com, ashley@ashleylai.com, tpmdd-devel@lists.sourceforge.net, christophe-h.ricard@st.com, benoit.houyere@st.com Subject: [tpmdd-devel] [PATCH 09/12] tpm/tpm_tis: Rework interrupt management for phy compatibility X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net Rework interrupt handling in order to be compatible with every phy. Signed-off-by: Christophe Ricard --- drivers/char/tpm/tpm-interface.c | 11 ++++++++--- drivers/char/tpm/tpm.h | 1 + drivers/char/tpm/tpm_tis_core.c | 24 +++++++++++++++++++----- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index 5397b64..c06378b 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -881,7 +881,9 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, unsigned long stop; long rc; u8 status; + u32 cur_intrs; bool canceled = false; + bool condition; /* check current status */ status = chip->ops->status(chip); @@ -892,14 +894,17 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, if (chip->vendor.irq) { again: + cur_intrs = chip->vendor.intrs; timeout = stop - jiffies; if ((long)timeout <= 0) return -ETIME; rc = wait_event_interruptible_timeout(*queue, - wait_for_tpm_stat_cond(chip, mask, check_cancel, - &canceled), + cur_intrs != chip->vendor.intrs, timeout); - if (rc > 0) { + condition = wait_for_tpm_stat_cond(chip, mask, + check_cancel, + &canceled); + if (rc > 0 && condition) { if (canceled) return -ECANCELED; return 0; diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 3ec04f4..32c17f4 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -139,6 +139,7 @@ struct tpm_vendor_specific { unsigned long base; /* TPM base address */ int irq; + u32 intrs; int region_size; int have_region; diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index b9cc61f..baa9ab1 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -41,6 +41,18 @@ struct tpm_info { int irq; }; +static void tpm_tis_clear_int(struct tpm_chip *chip) +{ + u32 interrupt; + + if (chip->vendor.irq) { + interrupt = tpm_read_dword(chip, + TPM_INT_STATUS(chip->vendor.locality)); + tpm_write_dword(chip, TPM_INT_STATUS(chip->vendor.locality), + interrupt); + } +} + /* Before we attempt to access the TPM we must see that the valid bit is set. * The specification says that this bit is 0 at reset and remains 0 until the * 'TPM has gone through its self test and initialization and has established @@ -192,6 +204,8 @@ int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) goto out; } + tpm_tis_clear_int(chip); + /* read first 10 bytes, including tag, paramsize, and result */ size = recv_data(chip, buf, TPM_HEADER_SIZE); if (size < TPM_HEADER_SIZE) { @@ -313,6 +327,8 @@ static int tpm_tis_send_main(struct tpm_chip *chip, u8 *buf, size_t len) u32 ordinal; unsigned long dur; + tpm_tis_clear_int(chip); + rc = tpm_tis_send_data(chip, buf, len); if (rc < 0) return rc; @@ -455,6 +471,7 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) return IRQ_NONE; chip->vendor.irq_tested = true; + chip->vendor.intrs++; if (interrupt & TPM_INTF_DATA_AVAIL_INT) wake_up_interruptible(&chip->vendor.read_queue); if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT) @@ -466,9 +483,6 @@ static irqreturn_t tis_int_handler(int dummy, void *dev_id) TPM_INTF_CMD_READY_INT)) wake_up_interruptible(&chip->vendor.int_queue); - /* Clear interrupts handled with TPM_EOI */ - tpm_write_dword(chip, TPM_INT_STATUS(chip->vendor.locality), interrupt); - tpm_read_dword(chip, TPM_INT_STATUS(chip->vendor.locality)); return IRQ_HANDLED; } @@ -481,8 +495,8 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, { u8 original_int_vec; - if (devm_request_irq(&chip->dev, irq, tis_int_handler, flags, - dev_name(&chip->dev), chip) != 0) { + if (devm_request_threaded_irq(&chip->dev, irq, NULL, tis_int_handler, flags, + dev_name(&chip->dev), chip) != 0) { dev_info(&chip->dev, "Unable to request irq: %d for probe\n", irq); return -1;