Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4264755pxb; Tue, 25 Jan 2022 07:00:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzns2htLZ9Ay0UQshpjvGn5YR3GzqISnr84d7vgK6m47Yriw1X3JoSzRGbWWJrpU+Wuhq38 X-Received: by 2002:a17:906:7310:: with SMTP id di16mr691535ejc.438.1643122825948; Tue, 25 Jan 2022 07:00:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643122825; cv=none; d=google.com; s=arc-20160816; b=Yo48bpEkxHbnLfZ+XlTeG5AoU5TNgumuc1+zpi38pUry47lwYOfD7b2Bdx5a3wcWz3 ZQxoIu2UH11k+g4I5Kcxzov/4+oP85/m/JmYweHdBowY7QJ9sm63xZ8abWfBbz8Zr2iI mCXaAV6GNuuoMIvsgCc1oGz4ZdpNQuJcFX1KwrsM4r4u0nhL36hDPpmL3wq7EINGlqFG bIJL1lX4J3IH+wAz8wMiyX7g4GiatuWmhQy7vch4ucODgxwtL91Fr5tD+ZA+oi0wrLZh wSZjr6t+bDTYtEhQTGVt3tNdXiibJ6gy61BvROSW+fPJVv1qbViXRKWJlwehUgFvOqE1 t+Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=d9xG9ybZ2bk07KpDBvmq82bns44VBsEgiEAlMx6te1s=; b=uOWjuPxuBCMsoCLOBqLSsFIFmc2MppIDfnZEEbvhIPPfciMmPud2m6gqP3vb1bix2X m2O1+DTNmJoHHG5LR+2w3ZjFAfcsxZGPHvDVZDO0jUwxbjxR8SqZUZPBQW3hz9z3cGR5 HHiIx3MXV8hvtmEhZwMhjz7iA6i9sOImP8tHUUWfYm6tJWhbVakvCRNA67lUaAbn+fZc JyIyiRSW9ngcmWydz12N9CQu8OYHUN8XVrKOLjERRiWTfb/aULmA3rf+zqcLOXyqWrHv O4no9vVGRCTZKjRWee0bdoY6E1nQjANtnShsGN/PF4CaXihWQBdfVIJVkHeEAog3kq7y tZkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kempniu.pl header.s=google header.b=eTJDRtWM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=kempniu.pl Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gn27si4594869ejc.879.2022.01.25.06.59.53; Tue, 25 Jan 2022 07:00:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kempniu.pl header.s=google header.b=eTJDRtWM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=kempniu.pl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378291AbiAYKvR (ORCPT + 99 others); Tue, 25 Jan 2022 05:51:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377101AbiAYKse (ORCPT ); Tue, 25 Jan 2022 05:48:34 -0500 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D8D8C061755 for ; Tue, 25 Jan 2022 02:48:34 -0800 (PST) Received: by mail-lf1-x134.google.com with SMTP id x11so55966421lfa.2 for ; Tue, 25 Jan 2022 02:48:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kempniu.pl; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=d9xG9ybZ2bk07KpDBvmq82bns44VBsEgiEAlMx6te1s=; b=eTJDRtWMkEvwumN/PwbV2huigDmLkT28unqbUV95ieTvhEIBFIBcQmS5F3rAP4iw0T u2NLpilk2JA7ikJHhtF8x48nDW44SgBjQq1lwptwzdVZ3DekZna5erMk1hsHWGC0Z6Xe vWakmhEdOvQ+Y5hDQHdKBPfF9FUoH3rmjwS+c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=d9xG9ybZ2bk07KpDBvmq82bns44VBsEgiEAlMx6te1s=; b=Pt3Btzv1nYVLCKhBHJc19N9wWwfIzG/KCSRcJq1HmQv2X0R6FNIUmMIg9PtmBPBjs1 Uujc2HCeaL/gsyLOyG5rxbe1hRy6FK/xZFKv08cNbpEdpOqvREq8ZMWAsRr4Xq7op5XG xV3KoSfyRiHf1JeMc9zoPGytdaA0znvlUKEejKU65vZrYqepNn92jCxlLIp9CXrlKCW+ 8K/vcqphhNZgOnj0njtU6gI6ewS3PRT3lUCnqUgUuMYO73bzvsDabW8Y/P9zddv7t+sI 1b5Kde1qKaHy79Nzrwv1/CYCP8ex5DoTJM72kirQx+lTF1/0gIsEE1PmXYc7UPv6y5HU Olvw== X-Gm-Message-State: AOAM533uPqxhzgDlOPFTq92AnQ1Pg9jmobbVgmny7fzm0bsm4aXAyCtC 8jF3G030RjkNRo0BVH24nVSqVA== X-Received: by 2002:a19:500c:: with SMTP id e12mr8091350lfb.18.1643107712251; Tue, 25 Jan 2022 02:48:32 -0800 (PST) Received: from larwa.hq.kempniu.pl ([2001:470:64df:111::221]) by smtp.gmail.com with ESMTPSA id d16sm461896ljj.74.2022.01.25.02.48.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 02:48:31 -0800 (PST) From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Boris Brezillon , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/4] mtd: track maximum number of bitflips for each read request Date: Tue, 25 Jan 2022 11:48:19 +0100 Message-Id: <20220125104822.8420-2-kernel@kempniu.pl> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220125104822.8420-1-kernel@kempniu.pl> References: <20220125104822.8420-1-kernel@kempniu.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org mtd_read_oob() callers are currently oblivious to the details of ECC errors detected during the read operation - they only learn (through the return value) whether any corrected bitflips or uncorrectable errors occurred. More detailed ECC information can be useful to user-space applications for making better-informed choices about moving data around. Extend struct mtd_oob_ops with a pointer to a newly-introduced struct mtd_req_stats and set its 'max_bitflips' field to the maximum number of bitflips found in a single ECC step during the read operation performed by mtd_read_oob(). This is a prerequisite for ultimately passing that value back to user space. Suggested-by: Boris Brezillon Signed-off-by: Michał Kępień --- drivers/mtd/mtdcore.c | 5 +++++ include/linux/mtd/mtd.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 70f492dce158..9423af6db385 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -1575,6 +1575,9 @@ int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops) if (!master->_read_oob && (!master->_read || ops->oobbuf)) return -EOPNOTSUPP; + if (ops->stats) + memset(ops->stats, 0, sizeof(*ops->stats)); + if (mtd->flags & MTD_SLC_ON_MLC_EMULATION) ret_code = mtd_io_emulated_slc(mtd, from, true, ops); else @@ -1592,6 +1595,8 @@ int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops) return ret_code; if (mtd->ecc_strength == 0) return 0; /* device lacks ecc */ + if (ops->stats) + ops->stats->max_bitflips = ret_code; return ret_code >= mtd->bitflip_threshold ? -EUCLEAN : 0; } EXPORT_SYMBOL_GPL(mtd_read_oob); diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 1ffa933121f6..f976aabcb378 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -40,6 +40,10 @@ struct mtd_erase_region_info { unsigned long *lockmap; /* If keeping bitmap of locks */ }; +struct mtd_req_stats { + unsigned int max_bitflips; +}; + /** * struct mtd_oob_ops - oob operation operands * @mode: operation mode @@ -70,6 +74,7 @@ struct mtd_oob_ops { uint32_t ooboffs; uint8_t *datbuf; uint8_t *oobbuf; + struct mtd_req_stats *stats; }; /** -- 2.34.1