From patchwork Wed Nov 23 05:46:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stewart Smith X-Patchwork-Id: 698066 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tNrts2kNYz9svs for ; Wed, 23 Nov 2016 16:46:45 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3tNrts1qYQzDvxH for ; Wed, 23 Nov 2016 16:46:45 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3tNrtG1k9pzDvqk for ; Wed, 23 Nov 2016 16:46:13 +1100 (AEDT) Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uAN5hd2Z132000 for ; Wed, 23 Nov 2016 00:46:11 -0500 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0b-001b2d01.pphosted.com with ESMTP id 26w15ps4v0-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 23 Nov 2016 00:46:11 -0500 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 22 Nov 2016 22:46:09 -0700 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 22 Nov 2016 22:46:08 -0700 Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 0183F19D8040 for ; Tue, 22 Nov 2016 22:45:29 -0700 (MST) Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uAN5k60M43188432; Wed, 23 Nov 2016 05:46:07 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C3291AC043; Wed, 23 Nov 2016 00:46:07 -0500 (EST) Received: from birb.localdomain (unknown [9.185.16.166]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP id 4B81BAC03F; Wed, 23 Nov 2016 00:46:07 -0500 (EST) Received: by birb.localdomain (Postfix, from userid 1000) id CB22B229DB54; Wed, 23 Nov 2016 16:46:03 +1100 (AEDT) From: Stewart Smith To: skiboot@lists.ozlabs.org Date: Wed, 23 Nov 2016 16:46:02 +1100 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479879962-1943-1-git-send-email-stewart@linux.vnet.ibm.com> References: <1479879962-1943-1-git-send-email-stewart@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16112305-8235-0000-0000-000009AB7ED3 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006127; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000189; SDB=6.00784202; UDB=6.00378800; IPR=6.00561820; BA=6.00004904; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013413; XFM=3.00000011; UTC=2016-11-23 05:46:09 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16112305-8236-0000-0000-000036B0C37D Message-Id: <1479879962-1943-4-git-send-email-stewart@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-11-23_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1611230105 Subject: [Skiboot] [PATCH 4/4] tpm_i2c_interface: decouple rc from being done with i2c request X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This ensures the i2c subsystem is done with the i2c request before we continue. Since it handles timeouts, we don't have to here. Signed-off-by: Stewart Smith --- libstb/drivers/tpm_i2c_interface.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libstb/drivers/tpm_i2c_interface.c b/libstb/drivers/tpm_i2c_interface.c index 89f5ba6..133d3a0 100644 --- a/libstb/drivers/tpm_i2c_interface.c +++ b/libstb/drivers/tpm_i2c_interface.c @@ -30,9 +30,16 @@ #define REQ_COMPLETE_POLLING 5 /* Check if req is complete in 5ms interval */ +struct tpm_i2c_userdata { + int rc; + bool done; +}; + void tpm_i2c_request_complete(int rc, struct i2c_request *req) { - *(int*)req->user_data = rc; + struct tpm_i2c_userdata *ud = req->user_data; + ud->rc = rc; + ud->done = true; } /** @@ -58,6 +65,7 @@ int tpm_i2c_request_send(int tpm_bus_id, int tpm_dev_addr, int read_write, struct i2c_request *req; struct i2c_bus *bus; uint64_t time_to_wait = 0; + struct tpm_i2c_userdata ud; bus = i2c_find_bus_by_id(tpm_bus_id); if (!bus) { @@ -91,7 +99,7 @@ int tpm_i2c_request_send(int tpm_bus_id, int tpm_dev_addr, int read_write, req->rw_buf = (void*) buf; req->rw_len = buflen; req->completion = tpm_i2c_request_complete; - req->user_data = &rc; + req->user_data = &ud; /* * Set the request timeout to 10ms per byte. Otherwise, we get @@ -101,7 +109,6 @@ int tpm_i2c_request_send(int tpm_bus_id, int tpm_dev_addr, int read_write, timeout = (buflen + offset_bytes + 2) * I2C_BYTE_TIMEOUT_MS; for (retries = 0; retries <= TPM_MAX_NACK_RETRIES; retries++) { - rc = 1; waited = 0; i2c_set_req_timeout(req, timeout); i2c_queue_req(req); @@ -112,7 +119,9 @@ int tpm_i2c_request_send(int tpm_bus_id, int tpm_dev_addr, int read_write, time_to_wait = REQ_COMPLETE_POLLING; time_wait(time_to_wait); waited += time_to_wait; - } while (tb_to_msecs(waited) < timeout && rc == 1); + } while (!ud.done); + + rc = ud.rc; if (rc == OPAL_I2C_NACK_RCVD) continue;