From patchwork Thu Sep 26 07:01:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 1167766 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 46f5Ss57n6z9sNk for ; Thu, 26 Sep 2019 17:01:49 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=jms.id.au Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="TslCfTWe"; 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 46f5Ss3ZCTzDqgB for ; Thu, 26 Sep 2019 17:01:49 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::52e; helo=mail-pg1-x52e.google.com; envelope-from=joel.stan@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=jms.id.au Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="TslCfTWe"; dkim-atps=neutral Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) (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 46f5Sl4PtCzDqf2 for ; Thu, 26 Sep 2019 17:01:43 +1000 (AEST) Received: by mail-pg1-x52e.google.com with SMTP id a3so973866pgm.13 for ; Thu, 26 Sep 2019 00:01:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=rwt3jFdhZbFNRARFvzJXNDid0i3mTIYYxRrjeYeZnxU=; b=TslCfTWeUacmFyqB40+9y+xMfzhbQBPtuxOWNEbA+O3FKZnBnaGGK4y5nAAvUMRBkQ T1HgCslAM7uIl9UFFMcbsxygXCFSUaD9O7nTSPG6vVHx+nuqVsA25wXRZ72iYp7wvCuP FDGbqvCoMprfAf5lq1vSY2TuLtPrnwYuv18OYWKlcu8D49SxM3m2a3VlKPu/aSpm6XJj tz4k9z9I2yxmgMEJPa3YUxBE7ZfwQU0lkKgbYtPQM2N/iaSHTaJhI/PAyDihomy4Meol fKN7nH16sufTLlI/Av6LTcCvserWcF5ogQU6D4sj0AzCWkgxJ2cgusA/+AmsEQX0CxDk W1QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :mime-version:content-transfer-encoding; bh=rwt3jFdhZbFNRARFvzJXNDid0i3mTIYYxRrjeYeZnxU=; b=XY7cbM8rKxG6ou7gVRpO2bEIXv5UvOcjA/d7Yxp5Nd40FEJrabuEGJl1+y6cLXOjK0 wFQcOhf+JXEIunLUIgtD2Y82kjad8QDHVp62ihr5Oq6rSDYpJAV0c/8RPBseAguzQ88Z DvGblkJdSXrIVbBWv7fyUs+o00pe0Iq40zsvcaOt2VNRXVeNCDRnpi8OvgigEUOoo66F ASR3P6m5NUhqUgy4YNXqvzO3tT5IRtL0z6qSJDXrPaNzZxHwY8sufAUybzLeTiWI4TGW rOwERLtQwdLilyiXxypQ145dNZfodJNRj3p+PCbOjHqSgKzQP6imMJKRyIGi8XR6Knea kzcg== X-Gm-Message-State: APjAAAUcuNcjiewOAcdPHtIJAOjUQIL79+AgV2wDt5pIjTM+ltg5+OiN N++7cVmKnp95Zg8jK8NLo2TVkeW+ X-Google-Smtp-Source: APXvYqwrtn09G03lai6h6EC474ictdaS4YLbGvQooiGK+Wa8ZhcsXGP7Z5bqsJj0GDquFNcdOlzfUQ== X-Received: by 2002:a17:90a:ba94:: with SMTP id t20mr1992744pjr.8.1569481298944; Thu, 26 Sep 2019 00:01:38 -0700 (PDT) Received: from voyager.ibm.com ([36.255.48.244]) by smtp.gmail.com with ESMTPSA id h6sm1553746pfg.123.2019.09.26.00.01.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2019 00:01:38 -0700 (PDT) From: Joel Stanley To: pdbg@lists.ozlabs.org Date: Thu, 26 Sep 2019 16:31:33 +0930 Message-Id: <20190926070133.26053-1-joel@jms.id.au> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3] kernel: Use FSI master 'class' path 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: , Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" The paths to sysfs entries depend on the master driver used. This means pdbg needs to use a different path when running against the hardware FSI master present in the ast2600. Instead of adding to an ever growing list of paths to check, the kernel has created a 'fsi-master' class that any driver can add itself to. On a kernel runnign this code, userspace only needs to check under /sys/class/fsi-master for any platform. This patch adds support for the class based path from a common accessor in kernel.c. It retains support for the existing gpio-fsi master. At some point in the distant future the gpio-fsi code could be deleted. Signed-off-by: Joel Stanley --- v3: - fix probe bug - add newlines to all of the print statements - no need to call access() at the in dtb.c, just check if we have a valid path v2: - Test for new path first so that code is being tested/used - Print a debug message when no devices found --- libpdbg/dtb.c | 15 ++++++++-- libpdbg/kernel.c | 71 +++++++++++++++++++++++++++++++++++++++-------- libpdbg/libpdbg.h | 2 ++ 3 files changed, 73 insertions(+), 15 deletions(-) diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c index 6c4beeda4fe6..53e9b7351e1b 100644 --- a/libpdbg/dtb.c +++ b/libpdbg/dtb.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#define _GNU_SOURCE #include #include #include @@ -68,8 +69,7 @@ static enum pdbg_backend default_backend(void) if (rc == 0) /* AMI BMC */ return PDBG_BACKEND_I2C; - rc = access(OPENFSI_BMC, F_OK); - if (rc == 0) /* Kernel interface. OpenBMC */ + if (kernel_get_fsi_path() != NULL) /* Kernel interface. OpenBMC */ return PDBG_BACKEND_KERNEL; return PDBG_BACKEND_FAKE; @@ -134,7 +134,16 @@ static void *bmc_target(void) if (!pdbg_backend_option) { /* Try and determine the correct device type */ - cfam_id_file = fopen(FSI_CFAM_ID, "r"); + char *path; + + rc = asprintf(&path, "%s/fsi0/slave@00:00/cfam_id", kernel_get_fsi_path()); + if (rc < 0) { + pdbg_log(PDBG_ERROR, "Unable create fsi path"); + return NULL; + } + + cfam_id_file = fopen(path, "r"); + free(path); if (!cfam_id_file) { pdbg_log(PDBG_ERROR, "Unabled to open CFAM ID file\n"); return NULL; diff --git a/libpdbg/kernel.c b/libpdbg/kernel.c index 4cc0334d7eb3..476531e6297d 100644 --- a/libpdbg/kernel.c +++ b/libpdbg/kernel.c @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#define _GNU_SOURCE #include #include #include @@ -29,10 +30,36 @@ #include "operations.h" #include "hwunit.h" -#define FSI_SCAN_PATH "/sys/bus/platform/devices/gpio-fsi/fsi0/rescan" -#define FSI_CFAM_PATH "/sys/devices/platform/gpio-fsi/fsi0/slave@00:00/raw" +#define OPENFSI_LEGACY_PATH "/sys/bus/platform/devices/gpio-fsi/" +#define OPENFSI_PATH "/sys/class/fsi-master/" int fsi_fd; +const char *fsi_base; + +const char *kernel_get_fsi_path(void) +{ + int rc; + + if (fsi_base) + return fsi_base; + + rc = access(OPENFSI_PATH, F_OK); + if (rc == 0) { + fsi_base = OPENFSI_PATH; + return fsi_base; + } + + rc = access(OPENFSI_LEGACY_PATH, F_OK); + if (rc == 0) { + fsi_base = OPENFSI_LEGACY_PATH; + return fsi_base; + } + + /* This is an error, but callers use this function when probing */ + PR_DEBUG("Failed to find kernel FSI path\n"); + + return NULL; +} static int kernel_fsi_getcfam(struct fsi *fsi, uint32_t addr64, uint32_t *value) { @@ -42,7 +69,7 @@ static int kernel_fsi_getcfam(struct fsi *fsi, uint32_t addr64, uint32_t *value) rc = lseek(fsi_fd, addr, SEEK_SET); if (rc < 0) { rc = errno; - PR_WARNING("Failed to seek %s", FSI_CFAM_PATH); + PR_WARNING("seek failed: %s\n", strerror(errno)); return rc; } @@ -53,7 +80,7 @@ static int kernel_fsi_getcfam(struct fsi *fsi, uint32_t addr64, uint32_t *value) /* We expect reads of 0xc09 to occasionally * fail as the probing code uses it to see * if anything is present on the link. */ - PR_ERROR("Failed to read from 0x%08" PRIx32 " (%016" PRIx32 ")", (uint32_t) addr, addr64); + PR_ERROR("Failed to read from 0x%08" PRIx32 " (%016" PRIx32 ")\n", (uint32_t) addr, addr64); return rc; } *value = be32toh(tmp); @@ -69,7 +96,7 @@ static int kernel_fsi_putcfam(struct fsi *fsi, uint32_t addr64, uint32_t data) rc = lseek(fsi_fd, addr, SEEK_SET); if (rc < 0) { rc = errno; - PR_WARNING("Failed to seek %s", FSI_CFAM_PATH); + PR_WARNING("seek failed: %s\n", strerror(errno)); return rc; } @@ -77,7 +104,7 @@ static int kernel_fsi_putcfam(struct fsi *fsi, uint32_t addr64, uint32_t data) rc = write(fsi_fd, &tmp, 4); if (rc < 0) { rc = errno; - PR_ERROR("Failed to write to 0x%08" PRIx32 " (%016" PRIx32 ")", addr, addr64); + PR_ERROR("Failed to write to 0x%08" PRIx32 " (%016" PRIx32 ")\n", addr, addr64); return rc; } @@ -97,18 +124,27 @@ static void kernel_fsi_destroy(struct pdbg_target *target) static void kernel_fsi_scan_devices(void) { const char one = '1'; + char *path; int rc, fd; - fd = open(FSI_SCAN_PATH, O_WRONLY | O_SYNC); + rc = asprintf(&path, "%s/fsi0/rescan", kernel_get_fsi_path()); + if (rc < 0) { + PR_ERROR("Unable create fsi path\n"); + return; + } + + fd = open(path, O_WRONLY | O_SYNC); if (fd < 0) { - PR_ERROR("Unable to open %s", FSI_SCAN_PATH); + PR_ERROR("Unable to open %s\n", path); + free(path); return; } rc = write(fd, &one, sizeof(one)); if (rc < 0) - PR_ERROR("Unable to write to %s", FSI_SCAN_PATH); + PR_ERROR("Unable to write to %s\n", path); + free(path); close(fd); } @@ -116,12 +152,22 @@ int kernel_fsi_probe(struct pdbg_target *target) { if (!fsi_fd) { int tries = 5; + int rc; + char *path; + + rc = asprintf(&path, "%s/fsi0/slave@00:00/raw", kernel_get_fsi_path()); + if (rc < 0) { + PR_ERROR("Unable create fsi path\n"); + return rc; + } while (tries) { /* Open first raw device */ - fsi_fd = open(FSI_CFAM_PATH, O_RDWR | O_SYNC); - if (fsi_fd >= 0) + fsi_fd = open(path, O_RDWR | O_SYNC); + if (fsi_fd >= 0) { + free(path); return 0; + } tries--; /* Scan */ @@ -129,7 +175,8 @@ int kernel_fsi_probe(struct pdbg_target *target) sleep(1); } if (fsi_fd < 0) { - PR_ERROR("Unable to open %s", FSI_CFAM_PATH); + PR_ERROR("Unable to open %s\n", path); + free(path); return -1; } diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index 235ff85abdc6..468553bbf4b5 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -121,6 +121,8 @@ void pdbg_target_priv_set(struct pdbg_target *target, void *priv); struct pdbg_target *pdbg_target_root(void); bool pdbg_target_compatible(struct pdbg_target *target, const char *compatible); +const char *kernel_get_fsi_path(void); + /* Translate an address offset for a target to absolute address in address * space of a "base" target. */ struct pdbg_target *pdbg_address_absolute(struct pdbg_target *target, uint64_t *addr);