From patchwork Fri May 6 18:03:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Matias_Bj=C3=B8rling?= X-Patchwork-Id: 9035581 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id ADA05BF29F for ; Fri, 6 May 2016 18:11:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 75750203A1 for ; Fri, 6 May 2016 18:11:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8500E2024D for ; Fri, 6 May 2016 18:11:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758856AbcEFSL1 (ORCPT ); Fri, 6 May 2016 14:11:27 -0400 Received: from mail-wm0-f52.google.com ([74.125.82.52]:37125 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758693AbcEFSDp (ORCPT ); Fri, 6 May 2016 14:03:45 -0400 Received: by mail-wm0-f52.google.com with SMTP id a17so89985805wme.0 for ; Fri, 06 May 2016 11:03:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bjorling.me; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ECI54dgU4M13pMNvUOrp7ej+H8YKgnYk+k0iSUxEoFI=; b=CRM5kgmk7P95nlxMqKjJ1BqYhCb5YJ+IH9UyDh0FzkkYmjescPxnxB0VM5EAa+VNpF kJ3G4FRV/jfywUkWKqPwHXLnQGhxzdyv5hGLBQKxpHA/PBbo1g2HkDm5ILbK/CPvg29Y 7R4/9Ug7myNDy/+a/2jAyVovzyr2fJgwI/qgw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ECI54dgU4M13pMNvUOrp7ej+H8YKgnYk+k0iSUxEoFI=; b=FxSQfn0Bj0BbpbxH36EJej4WPFZ6CXY9Y7qjjvuce6rCCeAWyHen5ZRtBjl975ovCV TknHx5BokqjVkFuoaV6yzYNW0Xp/CowktSrXrjieLl8czx5xlzC44J4sTRSynntjLftX SIcNHzsY/YdR/XuyEW7f7KwLf+k0ahqcjAtwwPqsGx6ObOLPmgFROlxRFgA6hNvOzSGr ySE/wCOpC58Wd8Hhqidw81xJkDjunxWzH7XG2wfeA/aafWa+P++GjeNWB1gv8Kvt1Yiu ysoy3XgEeJiXo/vnkOb8D4HGWIUdSjQ4+YoqUaop3QRRVWdG1G4iJbxW50YZHK/SW/pr U5Qg== X-Gm-Message-State: AOPr4FWRaJIpyWJA2IqmqUnjME9+jkC8gXX3Y/tNZqn24ZTzvgke/yL1QASE9X6pPartGQ== X-Received: by 10.194.5.101 with SMTP id r5mr22187605wjr.47.1462557824103; Fri, 06 May 2016 11:03:44 -0700 (PDT) Received: from Macroninja.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id kz1sm16076559wjc.46.2016.05.06.11.03.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 May 2016 11:03:43 -0700 (PDT) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, axboe@fb.com Cc: =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 11/28] lightnvm: introduce nvm_for_each_lun_ppa() macro Date: Fri, 6 May 2016 20:03:04 +0200 Message-Id: <1462557801-24974-12-git-send-email-m@bjorling.me> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1462557801-24974-1-git-send-email-m@bjorling.me> References: <1462557801-24974-1-git-send-email-m@bjorling.me> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Users that wish to iterate all luns on a device. Must create a struct ppa_addr and separate iterators for channels and luns. To set the iterators, two loops are required, one to iterate channels, and another to iterate luns. This leads to decrease in readability. Introduce nvm_for_each_lun_ppa, which implements the nested loop and sets ppa, channel, and lun variable for each loop body, eliminating the boilerplate code. Signed-off-by: Matias Bjørling --- drivers/lightnvm/sysblk.c | 56 +++++++++++++++++++---------------------------- include/linux/lightnvm.h | 7 ++++++ 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/drivers/lightnvm/sysblk.c b/drivers/lightnvm/sysblk.c index 7fce588..a48093d 100644 --- a/drivers/lightnvm/sysblk.c +++ b/drivers/lightnvm/sysblk.c @@ -631,33 +631,28 @@ static int nvm_fact_get_blks(struct nvm_dev *dev, struct ppa_addr *erase_list, while (!done) { done = 1; - for (ch = 0; ch < dev->nr_chnls; ch++) { - for (lun = 0; lun < dev->luns_per_chnl; lun++) { - idx = factory_blk_offset(dev, ch, lun); - offset = &f->blks[idx]; + nvm_for_each_lun_ppa(dev, ppa, ch, lun) { + idx = factory_blk_offset(dev, ch, lun); + offset = &f->blks[idx]; - blkid = find_first_zero_bit(offset, - dev->blks_per_lun); - if (blkid >= dev->blks_per_lun) - continue; - set_bit(blkid, offset); + blkid = find_first_zero_bit(offset, + dev->blks_per_lun); + if (blkid >= dev->blks_per_lun) + continue; + set_bit(blkid, offset); - ppa.ppa = 0; - ppa.g.ch = ch; - ppa.g.lun = lun; - ppa.g.blk = blkid; - pr_debug("nvm: erase ppa (%u %u %u)\n", - ppa.g.ch, - ppa.g.lun, - ppa.g.blk); + ppa.g.blk = blkid; + pr_debug("nvm: erase ppa (%u %u %u)\n", + ppa.g.ch, + ppa.g.lun, + ppa.g.blk); - erase_list[ppa_cnt] = ppa; - ppa_cnt++; - done = 0; + erase_list[ppa_cnt] = ppa; + ppa_cnt++; + done = 0; - if (ppa_cnt == max_ppas) - return ppa_cnt; - } + if (ppa_cnt == max_ppas) + return ppa_cnt; } } @@ -684,17 +679,10 @@ static int nvm_fact_select_blks(struct nvm_dev *dev, struct factory_blks *f) int ch, lun, ret; struct ppa_addr ppa; - ppa.ppa = 0; - for (ch = 0; ch < dev->nr_chnls; ch++) { - for (lun = 0; lun < dev->luns_per_chnl; lun++) { - ppa.g.ch = ch; - ppa.g.lun = lun; - - ret = nvm_fact_get_bb_tbl(dev, ppa, nvm_factory_blks, - f); - if (ret) - return ret; - } + nvm_for_each_lun_ppa(dev, ppa, ch, lun) { + ret = nvm_fact_get_bb_tbl(dev, ppa, nvm_factory_blks, f); + if (ret) + return ret; } return 0; diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index 5eabdba..3f25635 100644 --- a/include/linux/lightnvm.h +++ b/include/linux/lightnvm.h @@ -559,6 +559,13 @@ extern int nvm_update_sysblock(struct nvm_dev *, struct nvm_sb_info *); extern int nvm_init_sysblock(struct nvm_dev *, struct nvm_sb_info *); extern int nvm_dev_factory(struct nvm_dev *, int flags); + +#define nvm_for_each_lun_ppa(dev, ppa, chid, lunid) \ + for ((chid) = 0, (ppa).ppa = 0; (chid) < (dev)->nr_chnls; \ + (chid)++, (ppa).g.ch = (chid)) \ + for ((lunid) = 0; (lunid) < (dev)->luns_per_chnl; \ + (lunid)++, (ppa).g.lun = (lunid)) + #else /* CONFIG_NVM */ struct nvm_dev_ops;