From patchwork Wed Jul 3 03:46:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1126602 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 45dn8q14bXz9s3Z for ; Wed, 3 Jul 2019 13:46:35 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="idu2kXmj"; 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 45dn8p1kFvzDqS7 for ; Wed, 3 Jul 2019 13:46:34 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 45dn8g06T9zDqQl for ; Wed, 3 Jul 2019 13:46:27 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="idu2kXmj"; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (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 mail.ozlabs.org (Postfix) with ESMTPSA id 45dn8f335sz9s8m; Wed, 3 Jul 2019 13:46:26 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1562125586; bh=WuPms55qsQOAWpuL4fIYm7gmrUtZRNs7SqC+SI5TPbU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=idu2kXmjRjOiGtQ0Ov8my/EOK9qUj22Pj7wVp74cNn8mCIx0msAPPbubzkV9EcWuk zHwMRA2ekn1tKREqTR3olnxDAJtWnA67/ylJqtomfYJB/wlMMWrr9TfAX4mHHxZbpu k+JlvRZnIojPJzEXMx/QHXkTziOccU33ylGftDXGnja5rxleli0ayukxpnZKxg3GNs eFEou58xt02FWAdzV09moWawV6jk9Nylov0FZPmp1Ur3wKBGiH1+U8dvQeEWeSjzVt xJ6r0++/FHKAJU5MqG4f2V/ZmOhmSYii2rIM6EwYYMxtRDMekHv/wK7SZ1sU/DMo// 85lv6WNxlZjUQ== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 3 Jul 2019 13:46:10 +1000 Message-Id: <20190703034619.2410-2-amitay@ozlabs.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190703034619.2410-1-amitay@ozlabs.org> References: <20190703034619.2410-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH 01/10] sbefifo: Refactor ffdc parsing code to store ffdc data X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Instead of dumping ffdc data, store it so an application can query it in case of chip-op failures. FFDC data is stored only for the last chip-op. Signed-off-by: Amitay Isaacs --- libpdbg/hwunit.h | 3 ++ libpdbg/sbefifo.c | 116 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 91 insertions(+), 28 deletions(-) diff --git a/libpdbg/hwunit.h b/libpdbg/hwunit.h index b816ae3..0b0c62b 100644 --- a/libpdbg/hwunit.h +++ b/libpdbg/hwunit.h @@ -71,6 +71,9 @@ struct sbefifo { int (*mem_read)(struct sbefifo *, uint64_t, uint8_t *, uint64_t, bool); int (*mem_write)(struct sbefifo *, uint64_t, uint8_t *, uint64_t, bool); int fd; + uint32_t status; + uint8_t *ffdc; + uint32_t ffdc_len; }; #define target_to_sbefifo(x) container_of(x, struct sbefifo, target) diff --git a/libpdbg/sbefifo.c b/libpdbg/sbefifo.c index 284d3d5..a23d0b4 100644 --- a/libpdbg/sbefifo.c +++ b/libpdbg/sbefifo.c @@ -69,22 +69,76 @@ static int sbefifo_op_write(struct sbefifo *sbefifo, void *buf, size_t buflen) return 0; } -static int sbefifo_op_ffdc_read(uint8_t *buf, uint32_t buflen) +static void sbefifo_ffdc_clear(struct sbefifo *sbefifo) { - int offset = 0; + sbefifo->status = 0; + if (sbefifo->ffdc) { + free(sbefifo->ffdc); + sbefifo->ffdc = NULL; + sbefifo->ffdc_len = 0; + } +} + +static void sbefifo_ffdc_set(struct sbefifo *sbefifo, uint8_t *buf, uint32_t buflen, uint32_t status) +{ + sbefifo->status = status; + + sbefifo->ffdc = malloc(buflen); + if (!sbefifo->ffdc) { + PR_ERROR("sbefifo: Failed to store FFDC data\n"); + return; + } + + memcpy(sbefifo->ffdc, buf, buflen); + sbefifo->ffdc_len = buflen; +} + +static int sbefifo_ffdc_get_uint32(struct sbefifo *sbefifo, uint32_t offset, uint32_t *value) +{ + uint32_t v; + + if (offset + 4 > sbefifo->ffdc_len) + return -1; + + memcpy(&v, sbefifo->ffdc + offset, 4); + *value = be32toh(v); + + return 0; +} + +static int sbefifo_ffdc_dump_pkg(struct sbefifo *sbefifo, uint32_t offset) +{ + uint32_t offset2 = offset; uint32_t header, value; uint16_t magic, len_words; - int i; + int i, rc; - if (buflen < 4) + rc = sbefifo_ffdc_get_uint32(sbefifo, offset2, &header); + if (rc < 0) return -1; + offset2 += 4; - /* End of ffdc data */ - if (buflen == 4) - return 0; - - header = be32toh(*(uint32_t *)(buf + offset)); - offset += 4; + /* + * FFDC package structure + * + * +----------+----------+----------+----------+ + * | Byte 0 | Byte 1 | Byte 2 | Byte 3 | + * +----------+----------+----------+----------+----------+ + * | word 0 | magic | length in words (N) | + * +----------+---------------------+---------------------+ + * | word 1 | sequence id | command | + * +----------+---------------------+---------------------+ + * | word 2 | return code | + * +----------+-------------------------------------------+ + * | word 3 | FFDC Data - word 0 | + * +----------+-------------------------------------------+ + * | word 4 | FFDC Data - word 1 | + * +----------+-------------------------------------------+ + * | ... | ... | + * +----------+-------------------------------------------+ + * | word N | FFDC Data - word N-3 | + * +----------+----------+----------+----------+----------+ + */ magic = header >> 16; if (magic != 0xffdc) { @@ -93,44 +147,47 @@ static int sbefifo_op_ffdc_read(uint8_t *buf, uint32_t buflen) } len_words = header & 0xffff; - if (offset + len_words * 4 > buflen) - return -1; - value = be32toh(*(uint32_t *)(buf + offset)); - offset += 4; + rc = sbefifo_ffdc_get_uint32(sbefifo, offset2, &value); + if (rc < 0) + return -1; + offset2 += 4; PR_ERROR("FFDC: Sequence = %u\n", value >> 16); PR_ERROR("FFDC: Command = 0x%08x\n", value & 0xffff); - value = be32toh(*(uint32_t *)(buf + offset)); - offset += 4; + rc = sbefifo_ffdc_get_uint32(sbefifo, offset2, &value); + if (rc < 0) + return -1; + offset2 += 4; PR_ERROR("FFDC: RC = 0x%08x\n", value); for (i=0; iffdc_len) { + int n; + + n = sbefifo_ffdc_dump_pkg(sbefifo, offset); + if (n <= 0) break; - offset += rc; + offset += n; } - - return rc; } static int sbefifo_op(struct sbefifo *sbefifo, @@ -144,6 +201,8 @@ static int sbefifo_op(struct sbefifo *sbefifo, uint16_t value; int rc; + sbefifo_ffdc_clear(sbefifo); + assert(msg_len > 0); /* Allocate extra memory for FFDC (SBEFIFO_MAX_FFDC_SIZE = 0x2000) */ @@ -200,7 +259,8 @@ static int sbefifo_op(struct sbefifo *sbefifo, return 0; } else { PR_ERROR("sbefifo: Operation failed, response=0x%08x\n", resp[1]); - sbefifo_op_ffdc(buf + offset, buflen - offset); + sbefifo_ffdc_set(sbefifo, buf + offset, buflen - offset - 4, resp[1]); + sbefifo_ffdc_dump(sbefifo); } fail: