From patchwork Tue Apr 26 10:31:06 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: 8937471 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 CDA20BF29F for ; Tue, 26 Apr 2016 10:32:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C6CB92010C for ; Tue, 26 Apr 2016 10:32:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CF67D20103 for ; Tue, 26 Apr 2016 10:32:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752140AbcDZKcb (ORCPT ); Tue, 26 Apr 2016 06:32:31 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:36101 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751815AbcDZKbZ (ORCPT ); Tue, 26 Apr 2016 06:31:25 -0400 Received: by mail-wm0-f45.google.com with SMTP id v188so118788286wme.1 for ; Tue, 26 Apr 2016 03:31:24 -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=RGgOnCmY7tqE9o5XxryMi92WqKDQoChk/jsgtJ97Xt7puk6h9Cdu1U9lJAYcMp+rsc tSNMvjfQq1wHqNvf/eqwwYw4xESKJITVX+LiIRQl5KXIC7iZqpSpdKATy8bR4Sh0EeDg X8teSqJg61ZizDzqZrJSTFIzI1bNQQjmfkaTw= 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=GFUjkHUBCOZzT9k/uaMgSEAyPoPKB5ac55oPA2QwQ82gC/RMofUJkN6EadO8v7rLdv vcDnQKR+AQcK9ovULfHukp6yHuidbWXno5c/D9tlWAv2om4razbtPYMaEiCqXZvmKg6q GhcmOq8vt7jx3w7kgBqRh2h9+8J02YKP8bFR2CEPHOBOr1ssOEON5skptmvYAPOkU+v+ iUKVsezEP4qR9fyAJ8qa9P0E82Vh4fr6jWX1QjgBULDwaXbuwaEtYxnD9UKAor1JxS/c P+fp8RG+DOZJCLE6bwPQ5Ro690QRqxRz/oCe4d9q7VvSjG2piYCdkWcq1NiPLsNntc3j r43A== X-Gm-Message-State: AOPr4FXxlKJ/7E9C5mHv+QW68R/dknnv6JHSe2aToSqHpOyltnuwNf7hj21Aj7wZ1Z9R4g== X-Received: by 10.194.96.10 with SMTP id do10mr2535632wjb.113.1461666683726; Tue, 26 Apr 2016 03:31:23 -0700 (PDT) Received: from Macroninja.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id c4sm28125193wjm.24.2016.04.26.03.31.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Apr 2016 03:31:23 -0700 (PDT) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 1/5] lightnvm: introduce nvm_for_each_lun_ppa() macro Date: Tue, 26 Apr 2016 12:31:06 +0200 Message-Id: <1461666670-30996-2-git-send-email-m@bjorling.me> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1461666670-30996-1-git-send-email-m@bjorling.me> References: <1461666670-30996-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=-7.8 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;