From patchwork Mon Oct 12 02:53:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 1380597 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C8jxp28Kwz9s0b for ; Mon, 12 Oct 2020 13:56:46 +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.a=rsa-sha256 header.s=20161025 header.b=AuXT0Qo5; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4C8jxp1RcPzDqs2 for ; Mon, 12 Oct 2020 13:56:46 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::429; helo=mail-pf1-x429.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.a=rsa-sha256 header.s=20161025 header.b=AuXT0Qo5; dkim-atps=neutral Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4C8jtF4crMzDqZX for ; Mon, 12 Oct 2020 13:53:41 +1100 (AEDT) Received: by mail-pf1-x429.google.com with SMTP id n14so12218171pff.6 for ; Sun, 11 Oct 2020 19:53:41 -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=4ypS3YS/L1qtZOxW4zyab06JNSdK52odx6fGK0zNIyo=; b=AuXT0Qo51UHUh2AoZv4+9ZJ/EVb1DVn5B1eTGRHcsGYhieDqn5KsxLJ4+ydr5Imk5d z6wvAyxJND4nOLLAdmmH9/GIfAG5JCrtmfLxWGmhWW6NgmINzWGBO6AiBOusa+Siw46C mswRR/QjbiftnW5vR1lmHVxyq/w3nAfBc+NNS2arXucEJJTCyI4JPTcDsX2j5kWHvp/2 zLYKoywZCIjAnHOl8gWwLyzzL4s2l8rFQsVt/WbZnKd/gQjMKNRXo7yc+P9rdIRIvHap 7GVGHnSsf6DMKfGhG4/Dh37TjO4g/BzfSFJCNo+XV9OXEnOCQIJW4MtidtUC4J7vcBLg GZTQ== 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=4ypS3YS/L1qtZOxW4zyab06JNSdK52odx6fGK0zNIyo=; b=Mnm70fV2uCqIBEZ7nGYhq68lOFgGuqk8gCJb15by70eVnsN3A65s/A8eo3j8/LUkPF sQ+sEAmAt5UqzYrhcShwVvR3vyB8CHVQY/UoO72If+puJLhg3qf0tJgTJzO0TY2CZ93X P0cEw0npC2X32/1oqhaIchPZVfBYj13cA0Mwwf0A4Rro0aBvJBXQ+vFFShbmlWpZY7ds bQLCPNeGkKDfj2G0D75SR9jiwgvD51hIlo4vUAE/n9Eo0xsbJMHZz1P8k5yFuWo1fRii SQM2QT/JIsYb1HxgN8wuKA6uJ3o5sH0zlr8FnHw+ypMkGYir9EBik6jh0sryw0jYneJh uKhA== X-Gm-Message-State: AOAM531vaHsiMuW/jsz3VQSWIw4Yst4sIMlvNXSpJ/Imv9m3VrgjSJBH GGyzRo6AQjw5YTWOpo4IG6AZBSbdmgvbqA== X-Google-Smtp-Source: ABdhPJzyZ0lecWGQMRhdHKCSnRq+MN4uXNcz03XwaTT+yL3je3Syvrq2d5pRnsGJuuGNL4o6V8DtsA== X-Received: by 2002:a17:90b:1644:: with SMTP id il4mr17120250pjb.151.1602471219209; Sun, 11 Oct 2020 19:53:39 -0700 (PDT) Received: from localhost.ibm.com (14-200-206-90.tpgi.com.au. [14.200.206.90]) by smtp.gmail.com with ESMTPSA id g4sm17909258pgg.75.2020.10.11.19.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Oct 2020 19:53:38 -0700 (PDT) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Mon, 12 Oct 2020 13:53:08 +1100 Message-Id: <20201012025314.1070230-4-oohall@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201012025314.1070230-1-oohall@gmail.com> References: <20201012025314.1070230-1-oohall@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH 04/10] i2c,trace: Add I2C operation trace events 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" Add support for tracing I2C transactions performed by skiboot. This covers both internally initiated I2C ops and those that requested by the kernel via the OPAL API. Signed-off-by: Oliver O'Halloran --- core/i2c.c | 32 ++++++++++++++++++++++++++++++++ external/trace/dump_trace.c | 33 +++++++++++++++++++++++++++++++++ include/i2c.h | 9 +-------- include/trace_types.h | 12 ++++++++++++ 4 files changed, 78 insertions(+), 8 deletions(-) diff --git a/core/i2c.c b/core/i2c.c index fd9308126d64..b4313d430f3e 100644 --- a/core/i2c.c +++ b/core/i2c.c @@ -13,6 +13,7 @@ #include #include #include +#include static LIST_HEAD(i2c_bus_list); @@ -38,6 +39,34 @@ struct i2c_bus *i2c_find_bus_by_id(uint32_t opal_id) return NULL; } +static inline void i2c_trace_req(struct i2c_request *req, int rc) +{ + struct trace_i2c t; + + memset(&t, 0, sizeof(t)); + + t.bus = req->bus->opal_id; + t.type = req->op | (req->offset_bytes << 4); + t.i2c_addr = req->dev_addr; + t.smbus_reg = req->offset & 0xffff; // FIXME: log whole offset + t.size = req->rw_len; + t.rc = rc; + + /* FIXME: trace should not be a union... */ + trace_add((void *)&t, TRACE_I2C, sizeof(t)); +} + +int64_t i2c_queue_req(struct i2c_request *req) +{ + int64_t ret = req->bus->queue_req(req); + + i2c_trace_req(req, OPAL_ASYNC_COMPLETION); + + if (!ret) + req->req_state = i2c_req_queued; + return ret; +} + static void opal_i2c_request_complete(int rc, struct i2c_request *req) { uint64_t token = (uint64_t)(unsigned long)req->user_data; @@ -45,6 +74,8 @@ static void opal_i2c_request_complete(int rc, struct i2c_request *req) opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, cpu_to_be64(token), cpu_to_be64(rc)); + i2c_trace_req(req, rc); + free(req); } @@ -177,6 +208,7 @@ int64_t i2c_request_sync(struct i2c_request *req) req->req_state = i2c_req_new; } + i2c_trace_req(req, rc); count = 0; for (i = 0; i < req->rw_len && count < sizeof(buf); i++) { count += snprintf(buf+count, sizeof(buf)-count, "%02x", diff --git a/external/trace/dump_trace.c b/external/trace/dump_trace.c index c68eea894715..f54dfa08130d 100644 --- a/external/trace/dump_trace.c +++ b/external/trace/dump_trace.c @@ -149,6 +149,36 @@ static void dump_uart(struct trace_uart *t) } } +static void dump_i2c(struct trace_i2c *t) +{ + uint16_t type = be16_to_cpu(t->type); + + printf("I2C: bus: %d dev: %02x len: %x ", + be16_to_cpu(t->bus), + be16_to_cpu(t->i2c_addr), + be16_to_cpu(t->size) + ); + + switch (type & 0x3) { + case 0: + printf("read"); + break; + case 1: + printf("write"); + break; + case 2: + printf("smbus read from %x", be16_to_cpu(t->smbus_reg)); + break; + case 3: + printf("smbus write to %x", be16_to_cpu(t->smbus_reg)); + break; + default: + printf("u wot?"); + } + + printf(", rc = %hd\n", (int16_t) be16_to_cpu(t->rc)); +} + static void load_traces(struct trace_reader *trs, int count) { struct trace_entry *te; @@ -189,6 +219,9 @@ static void print_trace(union trace *t) case TRACE_UART: dump_uart(&t->uart); break; + case TRACE_I2C: + dump_i2c(&t->i2c); + break; default: printf("UNKNOWN(%u) CPU %u length %u\n", t->hdr.type, be16_to_cpu(t->hdr.cpu), diff --git a/include/i2c.h b/include/i2c.h index c4ad805d4451..2c67a0ea22ea 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -61,14 +61,7 @@ struct i2c_request { extern void i2c_add_bus(struct i2c_bus *bus); extern struct i2c_bus *i2c_find_bus_by_id(uint32_t opal_id); -static inline int64_t i2c_queue_req(struct i2c_request *req) -{ - int64_t ret = req->bus->queue_req(req); - - if (!ret) - req->req_state = i2c_req_queued; - return ret; -} +int64_t i2c_queue_req(struct i2c_request *req); static inline uint64_t i2c_run_req(struct i2c_request *req) { diff --git a/include/trace_types.h b/include/trace_types.h index 5942a1fa46ed..4ebf5a0a8357 100644 --- a/include/trace_types.h +++ b/include/trace_types.h @@ -16,6 +16,7 @@ #define TRACE_FSP_MSG 4 /* FSP message sent/received */ #define TRACE_FSP_EVENT 5 /* FSP driver event */ #define TRACE_UART 6 /* UART driver traces */ +#define TRACE_I2C 7 /* I2C driver traces */ /* One per cpu, plus one for NMIs */ struct tracebuf { @@ -107,6 +108,16 @@ struct trace_uart { __be16 in_count; }; +struct trace_i2c { + struct trace_hdr hdr; + u16 bus; + u16 type; + u16 i2c_addr; + u16 smbus_reg; + u16 size; + s16 rc; +}; + union trace { struct trace_hdr hdr; /* Trace types go here... */ @@ -116,6 +127,7 @@ union trace { struct trace_fsp_msg fsp_msg; struct trace_fsp_event fsp_evt; struct trace_uart uart; + struct trace_i2c i2c; }; #endif /* __TRACE_TYPES_H */