From patchwork Tue Mar 26 08:18:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 1065300 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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44T3tX30f1z9sSX for ; Tue, 26 Mar 2019 19:18:44 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="NHwXFUNo"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 44T3tX0XqtzDqKR for ; Tue, 26 Mar 2019 19:18:44 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::544; helo=mail-pg1-x544.google.com; envelope-from=oohall@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="NHwXFUNo"; dkim-atps=neutral Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) (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 44T3tN6SVSzDqGM for ; Tue, 26 Mar 2019 19:18:36 +1100 (AEDT) Received: by mail-pg1-x544.google.com with SMTP id v12so7925506pgq.1 for ; Tue, 26 Mar 2019 01:18:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ez+uvqgSSMSRTitU+KTBgLYb5Yy4CCHiIFqxBWiMyWQ=; b=NHwXFUNo15R6sWudZ39l0u50KE5hL5TcXPjW+dltiFKEI3e0zDq0u7OR2aKrZTrbpC lkn9Zlw1FUsYUH/XwZN5APMKD/2v+sL+pyUPXWwCcXLA38eKd+jiYUFqIJ3RwEN1e4wk mvLU9U1vNXUU0KhWk8n14Mo0l7LkBP7Cz8ZwuUmWxARjzmxg+lUoJyjTscjc4quoXg/p NNqZqpV5DszC2dg+iggq2tR45u5GV0XKqST2sQFo6ocq03gkaej4B3NtbaIgcVWGrvy9 Giziu6HP1xRUs619OjLVdZKXSLD06ZG6+KsCnmGsE6O8SZYVnVFmSWmaRpNxQg5XmXlj 0EsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ez+uvqgSSMSRTitU+KTBgLYb5Yy4CCHiIFqxBWiMyWQ=; b=Wo4wxqb3LpHU7MuX5ORlHa8Kgh4TfVqXtJY6d5d8dRjut7XJ56MtMeP9gO+o6NtcFu PDj8Ip+iNSgobuWFN7S7EQUcV0A4vSVUnutVUKKZfEKBNg5toBCETAwe2q0RhW46FYAd hGEFnOT/3uWvYMO9/tzfv3+Zx7xlov3lz4G9S6XNgrPUfRAG8VU+SUYAwKmamUk/DpTI 5rNaONdTpUw31pJ80zuCjq5rD8YdNMz46BhTsgSPQtVkv5a4PfJF/H5FGKfKMg6Z/IQv 5JDUFG0Esd64/o4KtXSATM6ZdeBCfmDn7d7Ou+E5JDti8YYzNR1fAUr/z+swz0jMDTt0 vGMA== X-Gm-Message-State: APjAAAUd+uqwAXGJZ58F3WCRsfZDVakzze4AXamfe//cbcPD/Aau5Huy Jj+IZe8LmUGMnsBJ//DW8VG+dOM+ X-Google-Smtp-Source: APXvYqwzwXZ6pXmlYHZlZ7W+tyenco1hgE56i9cbH58J5clP6A9n7CX9FjxRtJuclAjIa4YJ2H+wYg== X-Received: by 2002:a65:6489:: with SMTP id e9mr12574529pgv.364.1553588314599; Tue, 26 Mar 2019 01:18:34 -0700 (PDT) Received: from wafer.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id g64sm28651658pfg.13.2019.03.26.01.18.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Mar 2019 01:18:34 -0700 (PDT) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Tue, 26 Mar 2019 19:18:17 +1100 Message-Id: <20190326081819.9570-2-oohall@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190326081819.9570-1-oohall@gmail.com> References: <20190326081819.9570-1-oohall@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH 2/4] core/i2c: Poll on request state in i2c_request_send() X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Use the new built-in state variable rather than a single-use completion function. Makes things a bit cleaner. Signed-off-by: Oliver O'Halloran --- core/i2c.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/core/i2c.c b/core/i2c.c index 00dac0d12abb..e78b6b616494 100644 --- a/core/i2c.c +++ b/core/i2c.c @@ -140,20 +140,6 @@ opal_call(OPAL_I2C_REQUEST, opal_i2c_request, 3); #define MAX_NACK_RETRIES 2 #define REQ_COMPLETE_POLLING 5 /* Check if req is complete in 5ms interval */ - -struct i2c_sync_userdata { - int rc; - bool done; -}; - -static void i2c_sync_request_complete(int rc, struct i2c_request *req) -{ - struct i2c_sync_userdata *ud = req->user_data; - ud->rc = rc; - lwsync(); - ud->done = true; -} - /** * i2c_request_send - send request to i2c bus synchronously * @bus_id: i2c bus id @@ -177,7 +163,6 @@ int i2c_request_send(int bus_id, int dev_addr, int read_write, struct i2c_request *req; struct i2c_bus *bus; uint64_t time_to_wait = 0; - struct i2c_sync_userdata ud; uint64_t timer_period = msecs_to_tb(5), timer_count; bus = i2c_find_bus_by_id(bus_id); @@ -210,10 +195,7 @@ int i2c_request_send(int bus_id, int dev_addr, int read_write, req->offset_bytes = offset_bytes; req->rw_buf = (void*) buf; req->rw_len = buflen; - req->completion = i2c_sync_request_complete; req->timeout = timeout; - ud.done = false; - req->user_data = &ud; for (retries = 0; retries <= MAX_NACK_RETRIES; retries++) { waited = 0; @@ -240,15 +222,15 @@ int i2c_request_send(int bus_id, int dev_addr, int read_write, check_timers(false); timer_count = 0; } - } while (!ud.done); + } while (req->req_state != i2c_req_done); lwsync(); - rc = ud.rc; + rc = req->result; - /* error or success */ + /* retry on NACK, otherwise exit */ if (rc != OPAL_I2C_NACK_RCVD) break; - ud.done = false; + req->req_state = i2c_req_new; } prlog(PR_DEBUG, "I2C: %s req op=%x offset=%x buf=%016llx buflen=%d "