From patchwork Tue May 26 05:12:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1297695 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49WMYP38Rmz9sSk for ; Tue, 26 May 2020 15:13:13 +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.a=rsa-sha256 header.s=201707 header.b=pXTCL57Z; 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 49WMYP1wRPzDqMN for ; Tue, 26 May 2020 15:13:13 +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 49WMXn6mCJzDqHl for ; Tue, 26 May 2020 15:12:41 +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.a=rsa-sha256 header.s=201707 header.b=pXTCL57Z; 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 49WMXn4DrVz9sRY; Tue, 26 May 2020 15:12:41 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1590469961; bh=NrsATHm5D79+rY4ugZWHD6wv1eup4QuFrf2nUvN+qs4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pXTCL57ZxHMVb6Ogn1uzBElPUOzJLb3wqWPx3u2djMz65q/FIzfP/mWFDeiaLSg7Z F0WoOehEgAL7PxZ3WIyEXHp05PTykMKPWW1071chqIEzX/LtBqKMJmsvV6asntuTRP +XjhnkzFRxzhoh6yux1m5QdQm8Mz3NJbmWtrI0Cd0k7TaTlU68xUTmcVVT14fWa85l mDBIPtU6+S5sSdFo7a8x2vIQFZzUP8BM4/Hrd2101Ilebl4pLF2hpuAtu1oCAB7err 5YyrvXLm/n6+JJ0BXlHpKHA4K5hV3idG/woRYd2pYoNhB9HzKKKFC+68ZIB043/Aye MKG2mh9YoS7Qw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Tue, 26 May 2020 15:12:24 +1000 Message-Id: <20200526051226.70904-6-amitay@ozlabs.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200526051226.70904-1-amitay@ozlabs.org> References: <20200526051226.70904-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH 5/7] libpdbg: Rescan fsi bus only once 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" On rescan, kernel driver re-creates all the slave devices. This invalidates all the slave deviced opened before the scan. Signed-off-by: Amitay Isaacs --- libpdbg/kernel.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/libpdbg/kernel.c b/libpdbg/kernel.c index 2cc81f2..912895a 100644 --- a/libpdbg/kernel.c +++ b/libpdbg/kernel.c @@ -116,6 +116,15 @@ static void kernel_fsi_scan_devices(void) const char *kernel_path = kernel_get_fsi_path(); char *path; int rc, fd; + static bool scanned = false; + + /* + * On fsi bus rescan, kernel re-creates all the slave device entries. + * It means any currently open devices will be invalid and need to be + * re-opened. So avoid scanning multiple times. + */ + if (scanned) + return; if (!kernel_path) return; @@ -139,12 +148,13 @@ static void kernel_fsi_scan_devices(void) free(path); close(fd); + + scanned = true; } int kernel_fsi_probe(struct pdbg_target *target) { struct fsi *fsi = target_to_fsi(target); - int tries = 5; int rc; const char *kernel_path = kernel_get_fsi_path(); const char *fsi_path; @@ -162,24 +172,19 @@ int kernel_fsi_probe(struct pdbg_target *target) return rc; } - while (tries) { - /* Open first raw device */ - fsi->fd = open(path, O_RDWR | O_SYNC); - if (fsi->fd >= 0) { - free(path); - return 0; - } - tries--; - - /* Scan */ - kernel_fsi_scan_devices(); - sleep(1); - } - if (fsi->fd < 0) { - PR_ERROR("Unable to open %s\n", path); + /* Always scan the fsi bus once */ + kernel_fsi_scan_devices(); + sleep(1); + + /* Open first raw device */ + fsi->fd = open(path, O_RDWR | O_SYNC); + if (fsi->fd >= 0) { free(path); + return 0; } + PR_ERROR("Unable to open %s\n", path); + free(path); return -1; }