From patchwork Thu Mar 16 06:47:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?UGV0ZXIgUGFuIOa9mOagiyAocGV0ZXJwYW5kb25nKQ==?= X-Patchwork-Id: 739570 X-Patchwork-Delegate: boris.brezillon@free-electrons.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vkJgL6k99z9s03 for ; Thu, 16 Mar 2017 17:37:34 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="XYfxxyiH"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Hpfh+JtbuNXVgedm1UHrFhXoA/ouOEj9oRJht/qKPsk=; b=XYfxxyiHfd/SVr 8rKt+s8DVzKSG43LL7RwnIlT4VodXRMdNM1K417fsz/EloFCrOSdWJuA/Rj1OS27D+1IvsLA0nvLc uPbxpta1Zbdd3Fq7YshWhuHOpmWsKcI6JP1t/EMU91hqxXjCAT09yzbDRnq2Z+im921bxs/O8yj8m 17gToYntFrhId4hq55+ytJhvj8J0hITBCH9Yq66x+osjVdFE9hfUZWJady/svy3Nz3Ao5O1ISa3A7 p596YawKf1mCge19LK9yb5VfBtEOXAjuyeRAXpsz4HKTug90kHT7UlzD8/Mrlnw2xXdvAH1PFq9bU owSo80Ykwvsz2ZsJ3Lmw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1coP2R-0000Wv-Q1; Thu, 16 Mar 2017 06:37:31 +0000 Received: from mailout.micron.com ([137.201.242.129]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1coP1S-0008SE-Px for linux-mtd@lists.infradead.org; Thu, 16 Mar 2017 06:36:33 +0000 Received: from mail.micron.com (bowex17e.micron.com [137.201.21.213]) by mailout.micron.com (8.14.4/8.14.6) with ESMTP id v2G6Zsir003291; Thu, 16 Mar 2017 00:35:55 -0600 Received: from SIWEX5F.sing.micron.com (10.160.29.64) by bowex17e.micron.com (137.201.21.213) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Thu, 16 Mar 2017 00:35:54 -0600 Received: from BOWEX17H.micron.com (137.201.20.32) by SIWEX5F.sing.micron.com (10.160.29.64) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Thu, 16 Mar 2017 14:35:52 +0800 Received: from peterpan-Linux-Desktop.micron.com (10.66.12.56) by BOWEX17H.micron.com (137.201.20.32) with Microsoft SMTP Server id 15.0.1263.5 via Frontend Transport; Thu, 16 Mar 2017 00:35:50 -0600 From: Peter Pan To: , , , , , Subject: [PATCH v3 2/8] mtd: nand: add oob iterator in nand_for_each_page Date: Thu, 16 Mar 2017 14:47:31 +0800 Message-ID: <1489646857-10112-3-git-send-email-peterpandong@micron.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1489646857-10112-1-git-send-email-peterpandong@micron.com> References: <1489646857-10112-1-git-send-email-peterpandong@micron.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-12.0.0.1464-8.100.1062-22944.005 X-TM-AS-Result: No--5.531300-0.000000-31 X-TM-AS-MatchedID: 703399-863432-700648-188019-700264-706290-708712-851458-7 01384-148004-148036-10010-42000-42003 X-TM-AS-User-Approved-Sender: Yes X-TM-AS-User-Blocked-Sender: No X-MT-CheckInternalSenderRule: True X-Scanned-By: MIMEDefang 2.78 on 137.201.130.65 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170315_233630_995507_1AC79CD7 X-CRM114-Status: GOOD ( 10.33 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [137.201.242.129 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterpansjtu@gmail.com, linshunquan1@hisilicon.com, peterpandong@micron.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Iterate nand pages by both page and oob operation. Signed-off-by: Peter Pan --- include/linux/mtd/nand.h | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h index 4a812e6..822547e 100644 --- a/include/linux/mtd/nand.h +++ b/include/linux/mtd/nand.h @@ -87,6 +87,9 @@ struct nand_page_iter { loff_t offs; int page; int pageoffs; + int ooboffs; + int oobsize; + size_t oobleft; }; /** @@ -194,6 +197,7 @@ static inline int nand_per_page_oobsize(struct nand_device *nand) * @iter: page iterator */ static inline void nand_page_iter_init(struct nand_device *nand, loff_t offs, + u32 ooboffs, size_t ooblen, u32 oobsize, struct nand_page_iter *iter) { u64 page = offs; @@ -201,6 +205,9 @@ static inline void nand_page_iter_init(struct nand_device *nand, loff_t offs, iter->pageoffs = do_div(page, nand->memorg.pagesize); iter->page = page; iter->offs = offs; + iter->ooboffs = ooboffs; + iter->oobsize = oobsize; + iter->oobleft = ooblen; } /** @@ -214,11 +221,26 @@ static inline void nand_page_iter_next(struct nand_device *nand, iter->page++; iter->offs += nand_page_size(nand) - iter->pageoffs; iter->pageoffs = 0; + if (iter->oobleft) + iter->oobleft -= min_t(int, iter->oobsize - iter->ooboffs, + iter->oobleft); +} + +static inline bool nand_page_iter_end(struct nand_device *nand, loff_t offs, + u32 len, struct nand_page_iter *iter) +{ + if (iter->offs < offs + len) + return false; + if (iter->oobleft) + return false; + return true; } -#define nand_for_each_page(nand, start, len, iter) \ - for (nand_page_iter_init(nand, start, iter); \ - (iter)->offs < (start) + (len); \ +#define nand_for_each_page(nand, start, len, ooboffs, ooblen, \ + oobsize, iter) \ + for (nand_page_iter_init(nand, start, ooboffs, \ + ooblen, oobsize, iter); \ + !nand_page_iter_end(nand, start, len, iter); \ nand_page_iter_next(nand, iter)) /**