From patchwork Tue Apr 26 10:31:08 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: 8937391 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 1EEB5BF29F for ; Tue, 26 Apr 2016 10:31:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1E102201EC for ; Tue, 26 Apr 2016 10:31:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B54942013A for ; Tue, 26 Apr 2016 10:31:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752203AbcDZKbn (ORCPT ); Tue, 26 Apr 2016 06:31:43 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:35048 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752171AbcDZKb0 (ORCPT ); Tue, 26 Apr 2016 06:31:26 -0400 Received: by mail-wm0-f45.google.com with SMTP id e201so104272202wme.0 for ; Tue, 26 Apr 2016 03:31:26 -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=BtyDO/kkUmXqibXhUYLOiKI8LP/C9lEvlrUKMoaTqP8=; b=OrSPGAYThvoCdKCaz26+q6Fuj1Tvq+Ocbf0Lbc3Jnpm9yIa+0RyhykoyS+B64skyIy GTM+TIoa3C01/s1F9rxsrNeg3WsIXuLHw6RftOVC41KO0dKXkEGhy9a41EEz7DG2f2Ln KxCwJHCpb8X/do769T7quJtZ2r3xp407q8Rdk= 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=BtyDO/kkUmXqibXhUYLOiKI8LP/C9lEvlrUKMoaTqP8=; b=j39Xesau6+oQFCKGMZRVHQYyT8IF58iZxwSVDWb8jhc5uBRgfmEI82C2oOJLUxJshV zjCrV2lmf+j1Z0NkoqR/cRodU/7eU0ye3K1EhvcCtswEbnWJe46BBEKHzoChNrPPdCG/ ULTMvVRKfoW8rKMcrpa6paDqsxbvvvUzBrf9gvRhasaV2g0b5Pu/5PfNGRTtiSGxCDIS gRwGu/XPZIsGi01SdsKdN2nWE8GnySPqk2hxQMOXSIIMC5sLdhgPm5nsW/4uogwc4qB0 34BwMBbNb9wRAjxj3US3ocpkjBSxJzRK0KYQ3/HoFo1KUrA61R0NKsIOh9fGUYPvkmhS UuRA== X-Gm-Message-State: AOPr4FVmS6Lp5TyjIRoSLKJ9qU6OmCxrRezsWphuBbvksnUJeUvZ9SqHr5fVaT471H/jgw== X-Received: by 10.195.6.65 with SMTP id cs1mr2163081wjd.8.1461666685222; Tue, 26 Apr 2016 03:31:25 -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.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Apr 2016 03:31:24 -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 3/5] lightnvm: remove struct factory_blks Date: Tue, 26 Apr 2016 12:31:08 +0200 Message-Id: <1461666670-30996-4-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=ham 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 Now that device ops->get_bb_table no longer uses a callback, the struct factory_blks can be removed. Signed-off-by: Matias Bjørling --- drivers/lightnvm/sysblk.c | 62 +++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/drivers/lightnvm/sysblk.c b/drivers/lightnvm/sysblk.c index dc99c0a..bca6902 100644 --- a/drivers/lightnvm/sysblk.c +++ b/drivers/lightnvm/sysblk.c @@ -582,29 +582,23 @@ err_mark: return ret; } -struct factory_blks { - struct nvm_dev *dev; - int flags; - unsigned long *blks; -}; - static int factory_nblks(int nblks) { /* Round up to nearest BITS_PER_LONG */ return (nblks + (BITS_PER_LONG - 1)) & ~(BITS_PER_LONG - 1); } -static unsigned int factory_blk_offset(struct nvm_dev *dev, int ch, int lun) +static unsigned int factory_blk_offset(struct nvm_dev *dev, struct ppa_addr ppa) { int nblks = factory_nblks(dev->blks_per_lun); - return ((ch * dev->luns_per_chnl * nblks) + (lun * nblks)) / + return ((ppa.g.ch * dev->luns_per_chnl * nblks) + (ppa.g.lun * nblks)) / BITS_PER_LONG; } static int nvm_factory_blks(struct nvm_dev *dev, struct ppa_addr ppa, u8 *blks, int nr_blks, - struct factory_blks *f) + unsigned long *blk_bitmap, int flags) { int i, lunoff; @@ -612,25 +606,25 @@ static int nvm_factory_blks(struct nvm_dev *dev, struct ppa_addr ppa, if (nr_blks < 0) return nr_blks; - lunoff = factory_blk_offset(dev, ppa.g.ch, ppa.g.lun); + lunoff = factory_blk_offset(dev, ppa); /* non-set bits correspond to the block must be erased */ for (i = 0; i < nr_blks; i++) { switch (blks[i]) { case NVM_BLK_T_FREE: - if (f->flags & NVM_FACTORY_ERASE_ONLY_USER) - set_bit(i, &f->blks[lunoff]); + if (flags & NVM_FACTORY_ERASE_ONLY_USER) + set_bit(i, &blk_bitmap[lunoff]); break; case NVM_BLK_T_HOST: - if (!(f->flags & NVM_FACTORY_RESET_HOST_BLKS)) - set_bit(i, &f->blks[lunoff]); + if (!(flags & NVM_FACTORY_RESET_HOST_BLKS)) + set_bit(i, &blk_bitmap[lunoff]); break; case NVM_BLK_T_GRWN_BAD: - if (!(f->flags & NVM_FACTORY_RESET_GRWN_BBLKS)) - set_bit(i, &f->blks[lunoff]); + if (!(flags & NVM_FACTORY_RESET_GRWN_BBLKS)) + set_bit(i, &blk_bitmap[lunoff]); break; default: - set_bit(i, &f->blks[lunoff]); + set_bit(i, &blk_bitmap[lunoff]); break; } } @@ -639,7 +633,7 @@ static int nvm_factory_blks(struct nvm_dev *dev, struct ppa_addr ppa, } static int nvm_fact_get_blks(struct nvm_dev *dev, struct ppa_addr *erase_list, - int max_ppas, struct factory_blks *f) + int max_ppas, unsigned long *blk_bitmap) { struct ppa_addr ppa; int ch, lun, blkid, idx, done = 0, ppa_cnt = 0; @@ -648,8 +642,8 @@ static int nvm_fact_get_blks(struct nvm_dev *dev, struct ppa_addr *erase_list, while (!done) { done = 1; nvm_for_each_lun_ppa(dev, ppa, ch, lun) { - idx = factory_blk_offset(dev, ch, lun); - offset = &f->blks[idx]; + idx = factory_blk_offset(dev, ppa); + offset = &blk_bitmap[idx]; blkid = find_first_zero_bit(offset, dev->blks_per_lun); @@ -675,10 +669,11 @@ static int nvm_fact_get_blks(struct nvm_dev *dev, struct ppa_addr *erase_list, return ppa_cnt; } -static int nvm_fact_select_blks(struct nvm_dev *dev, struct factory_blks *f) +static int nvm_fact_select_blks(struct nvm_dev *dev, unsigned long *blk_bitmap, + int flags) { struct ppa_addr ppa; - int ch, lun, nr_blks, ret; + int ch, lun, nr_blks, ret = 0; u8 *blks; nr_blks = dev->blks_per_lun * dev->plane_mode; @@ -692,43 +687,42 @@ static int nvm_fact_select_blks(struct nvm_dev *dev, struct factory_blks *f) pr_err("nvm: failed bb tbl for ch%u lun%u\n", ppa.g.ch, ppa.g.blk); - ret = nvm_factory_blks(dev, ppa, blks, nr_blks, f); + ret = nvm_factory_blks(dev, ppa, blks, nr_blks, blk_bitmap, + flags); if (ret) - return ret; + break; } kfree(blks); - return 0; + return ret; } int nvm_dev_factory(struct nvm_dev *dev, int flags) { - struct factory_blks f; struct ppa_addr *ppas; int ppa_cnt, ret = -ENOMEM; int max_ppas = dev->ops->max_phys_sect / dev->nr_planes; struct ppa_addr sysblk_ppas[MAX_SYSBLKS]; struct sysblk_scan s; + unsigned long *blk_bitmap; - f.blks = kzalloc(factory_nblks(dev->blks_per_lun) * dev->nr_luns, + blk_bitmap = kzalloc(factory_nblks(dev->blks_per_lun) * dev->nr_luns, GFP_KERNEL); - if (!f.blks) + if (!blk_bitmap) return ret; ppas = kcalloc(max_ppas, sizeof(struct ppa_addr), GFP_KERNEL); if (!ppas) goto err_blks; - f.dev = dev; - f.flags = flags; - /* create list of blks to be erased */ - ret = nvm_fact_select_blks(dev, &f); + ret = nvm_fact_select_blks(dev, blk_bitmap, flags); if (ret) goto err_ppas; /* continue to erase until list of blks until empty */ - while ((ppa_cnt = nvm_fact_get_blks(dev, ppas, max_ppas, &f)) > 0) + while ((ppa_cnt = + nvm_fact_get_blks(dev, ppas, max_ppas, blk_bitmap)) > 0) nvm_erase_ppa(dev, ppas, ppa_cnt); /* mark host reserved blocks free */ @@ -743,7 +737,7 @@ int nvm_dev_factory(struct nvm_dev *dev, int flags) err_ppas: kfree(ppas); err_blks: - kfree(f.blks); + kfree(blk_bitmap); return ret; } EXPORT_SYMBOL(nvm_dev_factory);