From patchwork Tue May 30 09:51:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Honza_Petrou=C5=A1?= X-Patchwork-Id: 768532 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 3wcTmP2rcQz9ryv for ; Tue, 30 May 2017 20:07:01 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ZA0AP6LY"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="O2MgE7Ys"; 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=xNm1qeZMSmeMtnubcyBXbcuJjfdAoTyOr5WZ/Wk4OsI=; b=ZA0 AP6LYULgzsfPZrbTwxh/w0jg71Fbzp9sg9df7+8223PQMta6+koJVeXV9kW1sM9CGgplMD3sS/hzK wJck+Xqa01rfBY2IIz8h7YmdJpSJU7aHCSxXbsueRjZ6qcqi6WNRwUuXCE9KclWRGWP1Q/XeXdNhW cbeazK1RnAfYbhD67JA+AoawxJL0AorZhQY+Mhs+fhTqVPV1ZTx3J/VNpsNcCP+yk6Ys9hpb/dXPK ZY18SCsR70Hq/3+iNzAmfQ4dev+9mZwtsCxOAS5aOUPtO8jSe7y87SHvQxuVum7aQoF97DC0M2Yip ynS02Nlnp3qBP2i2KxvAyU7/f4UYs7Q==; 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 1dFe2L-00085d-1R; Tue, 30 May 2017 10:06:01 +0000 Received: from mail-qk0-x241.google.com ([2607:f8b0:400d:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dFdoY-0007Pv-36 for linux-mtd@lists.infradead.org; Tue, 30 May 2017 09:51:52 +0000 Received: by mail-qk0-x241.google.com with SMTP id y128so11359186qka.3 for ; Tue, 30 May 2017 02:51:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=5fBeQna9WM5YxTnjfd3xIKbupthkmilvERxb2/drUZ0=; b=O2MgE7Ys/3zaivTBwGuOdyUFd9G8pfWnxQ6XT2hsR0afDyp9yPjke43ra3tNVE/WRw cGTX8U9dO73xePdle+5mo2e1gHixk49lS62GZ5UKI0C1YnrHQcY0FZMjti1Ch1vEZbYy rzNLLXbFmh9vHfBZmVPB1SEjo7tWsv9EY14nfGtMqp8dbHHeDbjTSpkljm/mByhMqv2R 868X6WpgbBjhfLIvR+mPKwpSOmLkwM7Na6uIsoVXOfYSV+nRmyXPTNqsOg+YTY3xo9xw GWhqZ5rxwx/342fGNfFGZoJ8BdLDyNr38X+mDnj2uNwiP2E/n4bapXKqBM8VfMcbfBm7 qHzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=5fBeQna9WM5YxTnjfd3xIKbupthkmilvERxb2/drUZ0=; b=NTJ8pfa8dkdk6LsPdnkeLHU9W9TvPirZL4WtnNVj+fSUGda39TZR7B5UJRsgrMOEbH xlpRSgV2xsJu9+bd24XaOWRLPkjH5KCZzv/A1zTQ/x+4JeGe24i1elc8JBVuKg7GTQ29 MlxKQ/Bub8iBf7l89H6Zzn4SZFiLgSIHKUjuJRQT9MCxKPS3B6cIG+DF4vX8FUwS3Hoh Agpfss5wwowHo8/S9YaLYTUKHXiap7h2adba2QCLmvwTNr/CjLiY/v8seox6C4ijxwie IPCco04PIGdiXBk2EmBn1c0c5CnDoQXxuoL4CQpc6v3rWyWontEwwsiD2vDe//lZA28+ AUpQ== X-Gm-Message-State: AODbwcALj2tlIWSse2vV6OKHrAWKEtwEJsJtnLfL8taJVK237qtPFHEW 1zdncstlLmOLib2zny955CDn9gnong== X-Received: by 10.55.49.136 with SMTP id x130mr8614840qkx.161.1496137888236; Tue, 30 May 2017 02:51:28 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.96.79 with HTTP; Tue, 30 May 2017 02:51:27 -0700 (PDT) From: =?UTF-8?Q?Honza_Petrou=C5=A1?= Date: Tue, 30 May 2017 11:51:27 +0200 Message-ID: Subject: [PATCH v2 3/3] mtd:nor:ppb_unlock: remove repeated chip unlock To: Boris Brezillon , David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Cyrille Pitchen , linux-mtd@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170530_025146_616800_361BC1C4 X-CRM114-Status: GOOD ( 14.67 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2607:f8b0:400d:c09:0:0:0:241 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (jpetrous[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The Persistent Protection Bits (PPB) locking of cfi_cmdset_0002.c doesn't support per-sector-unlocking, so any unlock request unlocks the whole chip. Because of that limitation the driver does the unlock in three steps: 1) remember all locked sector 2) do the whole chip unlock 3) lock back only the necessary sectors Unfortunately in step 2 (unlocking the chip) there is used cfi_varsize_frob() for per-sector unlock, what ends up in multiple chip unlocking calls (exactly the chip unlock is called for every sector in the unlock area) even the only one unlock per chip is enough. Also optimized processing only inside necessary chip array in case of multi-chip setting. Signed-off-by: Honza Petrous --- drivers/mtd/chips/cfi_cmdset_0002.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) }; @@ -2635,6 +2635,8 @@ static int __maybe_unused cfi_ppb_unlock(struct mtd_info *mtd, loff_t ofs, int i; int sectors; int ret; + int fromchip; + int tochip; /* * PPB unlocking always unlocks all sectors of the flash chip. @@ -2656,6 +2658,8 @@ static int __maybe_unused cfi_ppb_unlock(struct mtd_info *mtd, loff_t ofs, sectors = 0; offset = 0; length = mtd->size; + fromchip = ofs >> cfi->chipshift; + tochip = (ofs + len - 1) >> cfi->chipshift; while (length) { int size = regions[i].erasesize; @@ -2676,8 +2680,8 @@ static int __maybe_unused cfi_ppb_unlock(struct mtd_info *mtd, loff_t ofs, if (sectors >= MAX_SECTORS) { printk(KERN_ERR "Only %d sectors for PPB locking supported!\n", MAX_SECTORS); - kfree(sect); - return -EINVAL; + ret = -EINVAL; + goto out; } } @@ -2697,12 +2701,13 @@ static int __maybe_unused cfi_ppb_unlock(struct mtd_info *mtd, loff_t ofs, } } - /* Now unlock the whole chip */ - ret = cfi_varsize_frob(mtd, do_ppb_xxlock, ofs, len, - DO_XXLOCK_ONEBLOCK_UNLOCK); - if (ret) { - kfree(sect); - return ret; + /* Now unlock the all necessary chips (full unlock) */ + for (chipnum = fromchip; chipnum <= tochip; chipnum++) { + ret = do_ppb_xxlock(map, &cfi->chips[chipnum], + 0, 1 << cfi->chipshift, + DO_XXLOCK_ONEBLOCK_UNLOCK); + if (ret) + goto out; } /* @@ -2710,11 +2715,14 @@ static int __maybe_unused cfi_ppb_unlock(struct mtd_info *mtd, loff_t ofs, * We need to re-lock all previously locked sectors. */ for (i = 0; i < sectors; i++) { - if (sect[i].locked) - do_ppb_xxlock(map, sect[i].chip, sect[i].offset, 0, + if (sect[i].locked && + (sect[i].chipid >= fromchip && sect[i].chipid <= tochip)) + do_ppb_xxlock(map, &cfi->chips[sect[i].chipid], + sect[i].offset, 0, DO_XXLOCK_ONEBLOCK_LOCK); } +out: kfree(sect); return ret; } diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c index 29a0b7f..22a27c8 100644 --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c @@ -2531,7 +2531,7 @@ static int cfi_atmel_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) */ struct ppb_lock { - struct flchip *chip; + int chipid; loff_t offset; int locked;