Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4628832yba; Mon, 20 May 2019 00:29:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqwN3rSNu8xJz5Je/6YJKuCK1OGzSsHEqOt+b46yntVqZrNr5/B8dpx1PhFUvykzeKB5K6NT X-Received: by 2002:a63:c5b:: with SMTP id 27mr22896977pgm.70.1558337342630; Mon, 20 May 2019 00:29:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558337342; cv=none; d=google.com; s=arc-20160816; b=K+GQL+dFRmK85xHYxqTn+nudCHayUcbNlrJT+IncLMWydR68NbH420jykeC65TG3Wf MSYR+nXXHWNxQTaTXxjhQAZUW5ie0nC+QldaNfMFNxP4QhIcPj4khDNQOMELrnMfOeNq vy43qABrSOp4y8MDXeBQpns+HyqWYx0TbM7mglLtmXhgM8hMBQ6RKC1be5LCaXFxRlWW +DHPhoZqkLzFYOune1m0scPSwWQcHvyhxHiVdJljn+Dy26Dp4L8ucCKyPLfSsp12vghZ /NTpD/lz8m4cULWbYAyaKkqAqPgZoaNU3jA+BF/zDBOD2x7J8osMn0QmZQVm5yll7fjG a/Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:cc:to:from; bh=Iu0HiPNEevyAc3r/xEj+IsNReQMUMv5Oh5a47saJBHw=; b=NCUMVAacbjWuZN9laV9O6l2A3i/xfyPeKFlCN63hJdWJd9FKGFowBujhH9A+77wNMa hf5Kt2KGNrWn61Q2YihRXGW3jdqKgB8+ZtSZXLgNZOoqe9OIz0mFqyEugvuAiTb6Tf7g t3DnwMXDjzpHD+LyPCQRmCPXljZYcUxEd9EoTAl4Po1DO/CFpOGAVnTFSLJWYwHANZ5f MOOtAPRXwU+Bdy5oDK8UJJwVIQLWafAuq+RLS3SOXeqnDBTABx7vBCUOKAQfx3XdCAOV 1XMBfvHJiJhvm2jTqafW4T6e8nLhG7Ille5UT3uUCP4fSgZbVarr+LS7fZUhERq3U3Uy fnCQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=REJECT dis=NONE) header.from=skyboo.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f34si17896150plf.258.2019.05.20.00.28.47; Mon, 20 May 2019 00:29:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=REJECT dis=NONE) header.from=skyboo.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730486AbfETHGN (ORCPT + 99 others); Mon, 20 May 2019 03:06:13 -0400 Received: from skyboo.net ([94.40.87.198]:51496 "EHLO skyboo.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbfETHGM (ORCPT ); Mon, 20 May 2019 03:06:12 -0400 Received: from manio by skyboo.net with local (Exim 4.91) (envelope-from ) id 1hScN7-0005pH-VF; Mon, 20 May 2019 09:06:10 +0200 From: Mariusz Bialonczyk To: linux-kernel@vger.kernel.org, Greg Kroah-Hartman Cc: Mariusz Bialonczyk Date: Mon, 20 May 2019 09:05:56 +0200 Message-Id: <20190520070558.20142-2-manio@skyboo.net> X-Mailer: git-send-email 2.19.0.rc1 In-Reply-To: <20190520070558.20142-1-manio@skyboo.net> References: <20190520070558.20142-1-manio@skyboo.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, greg@kroah.com, manio@skyboo.net X-SA-Exim-Mail-From: manio@skyboo.net X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on nemesis.skyboo.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NO_RELAYS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.1 Subject: [PATCH 2/4] w1: ds2413: add retry support to state_read() X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on skyboo.net) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The state_read() was calling PIO_ACCESS_READ once and bail out if it failed for this first time. This commit is improving this to trying more times before it give up, similarly as the write call is currently doing. Signed-off-by: Mariusz Bialonczyk --- drivers/w1/slaves/w1_ds2413.c | 37 +++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/drivers/w1/slaves/w1_ds2413.c b/drivers/w1/slaves/w1_ds2413.c index cd3763df69ac..d63778c70568 100644 --- a/drivers/w1/slaves/w1_ds2413.c +++ b/drivers/w1/slaves/w1_ds2413.c @@ -30,6 +30,9 @@ static ssize_t state_read(struct file *filp, struct kobject *kobj, size_t count) { struct w1_slave *sl = kobj_to_w1_slave(kobj); + unsigned int retries = W1_F3A_RETRIES; + ssize_t bytes_read = -EIO; + dev_dbg(&sl->dev, "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", bin_attr->attr.name, kobj, (unsigned int)off, count, buf); @@ -42,22 +45,30 @@ static ssize_t state_read(struct file *filp, struct kobject *kobj, mutex_lock(&sl->master->bus_mutex); dev_dbg(&sl->dev, "mutex locked"); - if (w1_reset_select_slave(sl)) { - mutex_unlock(&sl->master->bus_mutex); - return -EIO; - } + if (w1_reset_select_slave(sl)) + goto out; - w1_write_8(sl->master, W1_F3A_FUNC_PIO_ACCESS_READ); - *buf = w1_read_8(sl->master); + while (retries--) { + w1_write_8(sl->master, W1_F3A_FUNC_PIO_ACCESS_READ); - mutex_unlock(&sl->master->bus_mutex); - dev_dbg(&sl->dev, "mutex unlocked"); + *buf = w1_read_8(sl->master); + /* check for correct complement */ + if ((*buf & 0x0F) == ((~*buf >> 4) & 0x0F)) { + bytes_read = 1; + goto out; + } - /* check for correct complement */ - if ((*buf & 0x0F) != ((~*buf >> 4) & 0x0F)) - return -EIO; - else - return 1; + if (w1_reset_resume_command(sl->master)) + goto out; /* unrecoverable error */ + + dev_warn(&sl->dev, "PIO_ACCESS_READ error, retries left: %d\n", retries); + } + +out: + mutex_unlock(&sl->master->bus_mutex); + dev_dbg(&sl->dev, "%s, mutex unlocked, retries: %d\n", + (bytes_read > 0) ? "succeeded" : "error", retries); + return bytes_read; } static BIN_ATTR_RO(state, 1); -- 2.19.0.rc1