{"id":813163,"url":"http://patchwork.ozlabs.org/api/1.2/patches/813163/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-mtd/patch/1505280046-16608-7-git-send-email-yamada.masahiro@socionext.com/","project":{"id":3,"url":"http://patchwork.ozlabs.org/api/1.2/projects/3/?format=json","name":"Linux MTD development","link_name":"linux-mtd","list_id":"linux-mtd.lists.infradead.org","list_email":"linux-mtd@lists.infradead.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1505280046-16608-7-git-send-email-yamada.masahiro@socionext.com>","list_archive_url":null,"date":"2017-09-13T05:20:43","name":"[6/9] mtd: nand: denali: clean up macros with <linux/bitfield.h>","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"a2752f39cdf6c0a2286f5469f0a4e2ff9454a5f1","submitter":{"id":65882,"url":"http://patchwork.ozlabs.org/api/1.2/people/65882/?format=json","name":"Masahiro Yamada","email":"yamada.masahiro@socionext.com"},"delegate":{"id":58324,"url":"http://patchwork.ozlabs.org/api/1.2/users/58324/?format=json","username":"bbrezillon","first_name":"Boris","last_name":"Brezillon","email":"boris.brezillon@free-electrons.com"},"mbox":"http://patchwork.ozlabs.org/project/linux-mtd/patch/1505280046-16608-7-git-send-email-yamada.masahiro@socionext.com/mbox/","series":[{"id":2809,"url":"http://patchwork.ozlabs.org/api/1.2/series/2809/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-mtd/list/?series=2809","date":"2017-09-13T05:20:39","name":"mtd: nand: denali: more clean-ups","version":1,"mbox":"http://patchwork.ozlabs.org/series/2809/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/813163/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/813163/checks/","tags":{},"related":[],"headers":{"Return-Path":"<linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org; spf=none (mailfrom)\n\tsmtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133;\n\thelo=bombadil.infradead.org;\n\tenvelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=lists.infradead.org\n\theader.i=@lists.infradead.org header.b=\"e9spEIDI\"; \n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=nifty.com header.i=@nifty.com\n\theader.b=\"mB0Gc+Db\"; dkim-atps=neutral"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n\t[65.50.211.133])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xsVVF4Bg4z9sMN\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 13 Sep 2017 15:25:09 +1000 (AEST)","from localhost ([127.0.0.1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux))\n\tid 1ds0AW-0000b5-6J; Wed, 13 Sep 2017 05:25:00 +0000","from conuserg-12.nifty.com ([210.131.2.79])\n\tby bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux))\n\tid 1ds07J-0006Xq-NK\n\tfor linux-mtd@lists.infradead.org; Wed, 13 Sep 2017 05:21:53 +0000","from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp\n\t[153.142.97.92]) (authenticated)\n\tby conuserg-12.nifty.com with ESMTP id v8D5Kpx5010397;\n\tWed, 13 Sep 2017 14:20:56 +0900"],"DKIM-Signature":["v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20170209; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe:\n\tList-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References:\n\tIn-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID:\n\tContent-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc\n\t:Resent-Message-ID:List-Owner;\n\tbh=OOdJqL7ELjtEkdwPhG2WbaRnoIdv/IJGY2A9zSGFQVo=;\n\tb=e9spEIDInY4baHiDIzUq46IDcs\n\tyFnMVfKVopzizlEMLnogiwUoBUpVfxdDiLaTmw3gRPsfGyT+AGEuIv/59fxFYVHBsbVCrIezaj6s5\n\tF5GYVbEufD7ebfH+8CeyLL+BMFfvFJYpjbg3AAVqcQDd+dPPcRfyPk6dRUH2ST9QCKgOJ10d8Dhhz\n\tQVLzFCPAyLiT/wWHMmqgYkPrQlmgJ2qbrDEEOK//5RG/lfIDhroh8N2mQ3jagj2PB6RJ5o6QzWpzh\n\tqUzdJAVf7kSvyW7kh5DeK6LxekMRIK86JiYBDqpx+yUuh0TdzeRPtdQ0yY4xoQWaqNVrRQOb6oCgg\n\tqOirqiyQ==;","v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com;\n\ts=dec2015msa; t=1505280057;\n\tbh=rPYi00FdhFvB5jlz8bzB2Hvp8WgSMWRgU9fFEH4ZVXE=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=mB0Gc+Db66kuo8WJM0ZtwJ0DC/0QZyF5FiEEggJxrFoVCbBuN31oC1ydHEs9qdvbB\n\t+nCAwDY1x1vFq/zVJCn7BGEbALuj2PdrJsT29jtOhbnyAO1kTYMWtsh1POk2EDUVRe\n\tsi8tF9W6GdWlPUKyHPBpbJFcoSjqZ6Ws2XzN4LynaxR1BkPpSWypvdYtzSqizp6d2W\n\tL+r9CE9uQpLwxv3gdpV9eqTBqV1mgfzq1IEVlFBai8nRS+1D1ZlTSYEr8iADoYnSky\n\tZ7T7zEB35BI+BN1f90/hy0ShTVN86NEX/rj9LAw7NyCSN8r1yeab9+ffhz81ywRWD/\n\tgGN6rM1EGEExA=="],"DKIM-Filter":"OpenDKIM Filter v2.10.3 conuserg-12.nifty.com v8D5Kpx5010397","X-Nifty-SrcIP":"[153.142.97.92]","From":"Masahiro Yamada <yamada.masahiro@socionext.com>","To":"linux-mtd@lists.infradead.org","Subject":"[PATCH 6/9] mtd: nand: denali: clean up macros with\n\t<linux/bitfield.h>","Date":"Wed, 13 Sep 2017 14:20:43 +0900","Message-Id":"<1505280046-16608-7-git-send-email-yamada.masahiro@socionext.com>","X-Mailer":"git-send-email 2.7.4","In-Reply-To":"<1505280046-16608-1-git-send-email-yamada.masahiro@socionext.com>","References":"<1505280046-16608-1-git-send-email-yamada.masahiro@socionext.com>","X-CRM114-Version":"20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20170912_222142_307151_37AE7C06 ","X-CRM114-Status":"GOOD (  13.31  )","X-Spam-Score":"-1.2 (-)","X-Spam-Report":"SpamAssassin version 3.4.1 on bombadil.infradead.org summary:\n\tContent analysis details:   (-1.2 points)\n\tpts rule name              description\n\t---- ----------------------\n\t--------------------------------------------------\n\t0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail)\n\t-1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%\n\t[score: 0.0000]\n\t-0.1 DKIM_VALID Message has at least one valid DKIM or DK signature\n\t0.1 DKIM_SIGNED            Message has a DKIM or DK signature,\n\tnot necessarily valid","X-BeenThere":"linux-mtd@lists.infradead.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"Linux MTD discussion mailing list <linux-mtd.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/linux-mtd>,\n\t<mailto:linux-mtd-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/linux-mtd/>","List-Post":"<mailto:linux-mtd@lists.infradead.org>","List-Help":"<mailto:linux-mtd-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/linux-mtd>,\n\t<mailto:linux-mtd-request@lists.infradead.org?subject=subscribe>","Cc":"Boris Brezillon <boris.brezillon@free-electrons.com>,\n\tMarek Vasut <marek.vasut@gmail.com>,\n\tRichard Weinberger <richard@nod.at>, linux-kernel@vger.kernel.org,\n\tMasahiro Yamada <yamada.masahiro@socionext.com>, \n\tCyrille Pitchen <cyrille.pitchen@wedev4u.fr>,\n\tBrian Norris <computersforpeace@gmail.com>,\n\tDavid Woodhouse <dwmw2@infradead.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"linux-mtd\" <linux-mtd-bounces@lists.infradead.org>","Errors-To":"linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"},"content":"All the register offsets and bitfield masks are defined in denali.h,\nbut the driver code ended up with additional crappy macros such as\nMAKE_ECC_CORRECTION(), ECC_SECTOR(), etc.\n\nThe reason is apparent - accessing a register field requires mask and\nshift pair.  The denali.h only provides mask.  However, defining both\nis tedious.\n\n<linux/bitfield.h> provides a convenient way to get register fields\nonly with a single shifted mask.  Now use it.\n\nWhile I am here, I shortened some macros.\n\nSigned-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>\n---\n\n drivers/mtd/nand/denali.c | 25 +++++++++++--------------\n drivers/mtd/nand/denali.h | 13 +++++--------\n 2 files changed, 16 insertions(+), 22 deletions(-)","diff":"diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c\nindex 3cc56de..1525c4e 100644\n--- a/drivers/mtd/nand/denali.c\n+++ b/drivers/mtd/nand/denali.c\n@@ -17,6 +17,7 @@\n  *\n  */\n \n+#include <linux/bitfield.h>\n #include <linux/completion.h>\n #include <linux/dma-mapping.h>\n #include <linux/interrupt.h>\n@@ -386,13 +387,6 @@ static int denali_hw_ecc_fixup(struct mtd_info *mtd,\n \treturn max_bitflips;\n }\n \n-#define ECC_SECTOR(x)\t(((x) & ECC_ERROR_ADDRESS__SECTOR_NR) >> 12)\n-#define ECC_BYTE(x)\t(((x) & ECC_ERROR_ADDRESS__OFFSET))\n-#define ECC_CORRECTION_VALUE(x) ((x) & ERR_CORRECTION_INFO__BYTEMASK)\n-#define ECC_ERROR_UNCORRECTABLE(x) ((x) & ERR_CORRECTION_INFO__ERROR_TYPE)\n-#define ECC_ERR_DEVICE(x)\t(((x) & ERR_CORRECTION_INFO__DEVICE_NR) >> 8)\n-#define ECC_LAST_ERR(x)\t\t((x) & ERR_CORRECTION_INFO__LAST_ERR_INFO)\n-\n static int denali_sw_ecc_fixup(struct mtd_info *mtd,\n \t\t\t       struct denali_nand_info *denali,\n \t\t\t       unsigned long *uncor_ecc_flags, uint8_t *buf)\n@@ -410,18 +404,20 @@ static int denali_sw_ecc_fixup(struct mtd_info *mtd,\n \n \tdo {\n \t\terr_addr = ioread32(denali->reg + ECC_ERROR_ADDRESS);\n-\t\terr_sector = ECC_SECTOR(err_addr);\n-\t\terr_byte = ECC_BYTE(err_addr);\n+\t\terr_sector = FIELD_GET(ECC_ERROR_ADDRESS__SECTOR, err_addr);\n+\t\terr_byte = FIELD_GET(ECC_ERROR_ADDRESS__OFFSET, err_addr);\n \n \t\terr_cor_info = ioread32(denali->reg + ERR_CORRECTION_INFO);\n-\t\terr_cor_value = ECC_CORRECTION_VALUE(err_cor_info);\n-\t\terr_device = ECC_ERR_DEVICE(err_cor_info);\n+\t\terr_cor_value = FIELD_GET(ERR_CORRECTION_INFO__BYTE,\n+\t\t\t\t\t  err_cor_info);\n+\t\terr_device = FIELD_GET(ERR_CORRECTION_INFO__DEVICE,\n+\t\t\t\t       err_cor_info);\n \n \t\t/* reset the bitflip counter when crossing ECC sector */\n \t\tif (err_sector != prev_sector)\n \t\t\tbitflips = 0;\n \n-\t\tif (ECC_ERROR_UNCORRECTABLE(err_cor_info)) {\n+\t\tif (err_cor_info & ERR_CORRECTION_INFO__UNCOR) {\n \t\t\t/*\n \t\t\t * Check later if this is a real ECC error, or\n \t\t\t * an erased sector.\n@@ -451,7 +447,7 @@ static int denali_sw_ecc_fixup(struct mtd_info *mtd,\n \t\t}\n \n \t\tprev_sector = err_sector;\n-\t} while (!ECC_LAST_ERR(err_cor_info));\n+\t} while (!(err_cor_info & ERR_CORRECTION_INFO__LAST_ERR));\n \n \t/*\n \t * Once handle all ecc errors, controller will trigger a\n@@ -1351,7 +1347,8 @@ int denali_init(struct denali_nand_info *denali)\n \t\t\"chosen ECC settings: step=%d, strength=%d, bytes=%d\\n\",\n \t\tchip->ecc.size, chip->ecc.strength, chip->ecc.bytes);\n \n-\tiowrite32(MAKE_ECC_CORRECTION(chip->ecc.strength, 1),\n+\tiowrite32(FIELD_PREP(ECC_CORRECTION__ERASE_THRESHOLD, 1) |\n+\t\t  FIELD_PREP(ECC_CORRECTION__VALUE, chip->ecc.strength),\n \t\t  denali->reg + ECC_CORRECTION);\n \tiowrite32(mtd->erasesize / mtd->writesize,\n \t\t  denali->reg + PAGES_PER_BLOCK);\ndiff --git a/drivers/mtd/nand/denali.h b/drivers/mtd/nand/denali.h\nindex dc3f970..73aad3a 100644\n--- a/drivers/mtd/nand/denali.h\n+++ b/drivers/mtd/nand/denali.h\n@@ -114,9 +114,6 @@\n #define ECC_CORRECTION\t\t\t\t0x1b0\n #define     ECC_CORRECTION__VALUE\t\t\tGENMASK(4, 0)\n #define     ECC_CORRECTION__ERASE_THRESHOLD\t\tGENMASK(31, 16)\n-#define     MAKE_ECC_CORRECTION(val, thresh)\t\t\\\n-\t\t\t(((val) & (ECC_CORRECTION__VALUE)) | \\\n-\t\t\t(((thresh) << 16) & (ECC_CORRECTION__ERASE_THRESHOLD)))\n \n #define READ_MODE\t\t\t\t0x1c0\n #define     READ_MODE__VALUE\t\t\t\tGENMASK(3, 0)\n@@ -258,13 +255,13 @@\n \n #define ECC_ERROR_ADDRESS\t\t\t0x630\n #define     ECC_ERROR_ADDRESS__OFFSET\t\t\tGENMASK(11, 0)\n-#define     ECC_ERROR_ADDRESS__SECTOR_NR\t\tGENMASK(15, 12)\n+#define     ECC_ERROR_ADDRESS__SECTOR\t\t\tGENMASK(15, 12)\n \n #define ERR_CORRECTION_INFO\t\t\t0x640\n-#define     ERR_CORRECTION_INFO__BYTEMASK\t\tGENMASK(7, 0)\n-#define     ERR_CORRECTION_INFO__DEVICE_NR\t\tGENMASK(11, 8)\n-#define     ERR_CORRECTION_INFO__ERROR_TYPE\t\tBIT(14)\n-#define     ERR_CORRECTION_INFO__LAST_ERR_INFO\t\tBIT(15)\n+#define     ERR_CORRECTION_INFO__BYTE\t\t\tGENMASK(7, 0)\n+#define     ERR_CORRECTION_INFO__DEVICE\t\t\tGENMASK(11, 8)\n+#define     ERR_CORRECTION_INFO__UNCOR\t\t\tBIT(14)\n+#define     ERR_CORRECTION_INFO__LAST_ERR\t\tBIT(15)\n \n #define ECC_COR_INFO(bank)\t\t\t(0x650 + (bank) / 2 * 0x10)\n #define     ECC_COR_INFO__SHIFT(bank)\t\t\t((bank) % 2 * 8)\n","prefixes":["6/9"]}