From patchwork Tue Jan 12 06:49:20 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: 8014271 X-Patchwork-Delegate: axboe@kernel.dk Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7C3929F6FA for ; Tue, 12 Jan 2016 06:57:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 922AB20379 for ; Tue, 12 Jan 2016 06:57:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A7EC5201F4 for ; Tue, 12 Jan 2016 06:57:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761073AbcALGvL (ORCPT ); Tue, 12 Jan 2016 01:51:11 -0500 Received: from mail-wm0-f51.google.com ([74.125.82.51]:33491 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760910AbcALGuC (ORCPT ); Tue, 12 Jan 2016 01:50:02 -0500 Received: by mail-wm0-f51.google.com with SMTP id f206so240785850wmf.0 for ; Mon, 11 Jan 2016 22:50:01 -0800 (PST) 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-type:content-transfer-encoding; bh=GfC/EcNW9LQakXSxNTqsyLinOtxQ/M2Dc0LZq2s74d0=; b=Za++E+Ui+lA0H/OHc95fP6T9bSgUq/2rFmVNSCGDB4rEx3egKpYxeTPfaCw/qS0r7G LjBGamMxqrMDZCfAgKTNYXvecPNBCgfDHPkl2DhKFmEXT07lCbZWMZEdEYqonzjT7iIq u/I3aLgZsi+k0lbS47RbWxdz4HKpa4ZedV6Qg= 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-type:content-transfer-encoding; bh=GfC/EcNW9LQakXSxNTqsyLinOtxQ/M2Dc0LZq2s74d0=; b=bwiMTE0hmlBgFWvaLqQrRDp/uDs8qlTgxvZzy7s5zNMFxc8u6LaVglgKWl4JOHmePw cmZJ0bwickX5dEKf709QvS5xbD27wBRPgDfz65n42b26T9amK5ipsKo6iBpbIHp0CdwI JtDW+EgaK6/Dz5Aj4ywTgmPUjT07Zkj4U2qZykHeD1NtMtAw5URIgSClJEpOyCNbHJb2 WawKqvWX/fYd+qIYdBg5m1YOO6mNV2n7I5T4/GJVVhuyr3di1xtPsEsRKW/YGpNnyfzH dMrqXZ6u4SggcCEkZe9z83ZgfFA5OFaXvLWfmof9jzHmKnY8wguHyu3TJZO4K/tpgDdX i5ow== X-Gm-Message-State: ALoCoQkds0DRMUKv4x6eZNIf03/T8m5SEHP/tN3ZaBFJjHadSBvn+ojdt+FAiScn/03FG1UViQm34NXYO++0Muf09ECc6vgcHQ== X-Received: by 10.28.88.210 with SMTP id m201mr18309018wmb.76.1452581400568; Mon, 11 Jan 2016 22:50:00 -0800 (PST) Received: from localhost.localdomain (6164198-cl69.boa.fiberby.dk. [193.106.164.198]) by smtp.gmail.com with ESMTPSA id yz5sm70776886wjc.36.2016.01.11.22.49.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Jan 2016 22:49:59 -0800 (PST) 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 06/25] lightnvm: refactor rqd ppa list into set/free Date: Tue, 12 Jan 2016 07:49:20 +0100 Message-Id: <1452581379-18162-7-git-send-email-m@bjorling.me> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1452581379-18162-1-git-send-email-m@bjorling.me> References: <1452581379-18162-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=-6.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 A device may be driven in single, double or quad plane mode. In that case, the rqd must have either one, two, or four PPAs set for a single PPA sent to the device. Refactor this logic into their own functions to be shared by program/erase/read in the core. Signed-off-by: Matias Bjørling --- drivers/lightnvm/core.c | 71 ++++++++++++++++++++++++++++++++++-------------- include/linux/lightnvm.h | 3 ++ 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 6134339..081b0f5 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -220,40 +220,69 @@ void nvm_generic_to_addr_mode(struct nvm_dev *dev, struct nvm_rq *rqd) } EXPORT_SYMBOL(nvm_generic_to_addr_mode); +int nvm_set_rqd_ppalist(struct nvm_dev *dev, struct nvm_rq *rqd, + struct ppa_addr *ppas, int nr_ppas) +{ + int i, plane_cnt, pl_idx; + + if (dev->plane_mode == NVM_PLANE_SINGLE && nr_ppas == 1) { + rqd->nr_pages = 1; + rqd->ppa_addr = ppas[0]; + + return 0; + } + + plane_cnt = (1 << dev->plane_mode); + rqd->nr_pages = plane_cnt * nr_ppas; + + if (dev->ops->max_phys_sect < rqd->nr_pages) + return -EINVAL; + + rqd->ppa_list = nvm_dev_dma_alloc(dev, GFP_KERNEL, &rqd->dma_ppa_list); + if (!rqd->ppa_list) { + pr_err("nvm: failed to allocate dma memory\n"); + return -ENOMEM; + } + + for (i = 0; i < nr_ppas; i++) { + for (pl_idx = 0; pl_idx < plane_cnt; pl_idx++) { + ppas[i].g.pl = pl_idx; + rqd->ppa_list[(i * plane_cnt) + pl_idx] = ppas[i]; + } + } + + return 0; +} +EXPORT_SYMBOL(nvm_set_rqd_ppalist); + +void nvm_free_rqd_ppalist(struct nvm_dev *dev, struct nvm_rq *rqd) +{ + if (!rqd->ppa_list) + return; + + nvm_dev_dma_free(dev, rqd->ppa_list, rqd->dma_ppa_list); +} +EXPORT_SYMBOL(nvm_free_rqd_ppalist); + int nvm_erase_ppa(struct nvm_dev *dev, struct ppa_addr ppa) { - int plane_cnt = 0, pl_idx, ret; struct nvm_rq rqd; + int ret; if (!dev->ops->erase_block) return 0; - if (dev->plane_mode == NVM_PLANE_SINGLE) { - rqd.nr_pages = 1; - rqd.ppa_addr = ppa; - } else { - plane_cnt = (1 << dev->plane_mode); - rqd.nr_pages = plane_cnt; + memset(&rqd, 0, sizeof(struct nvm_rq)); - rqd.ppa_list = nvm_dev_dma_alloc(dev, GFP_KERNEL, - &rqd.dma_ppa_list); - if (!rqd.ppa_list) { - pr_err("nvm: failed to allocate dma memory\n"); - return -ENOMEM; - } - - for (pl_idx = 0; pl_idx < plane_cnt; pl_idx++) { - ppa.g.pl = pl_idx; - rqd.ppa_list[pl_idx] = ppa; - } - } + ret = nvm_set_rqd_ppalist(dev, &rqd, &ppa, 1); + if (ret) + return ret; nvm_generic_to_addr_mode(dev, &rqd); ret = dev->ops->erase_block(dev, &rqd); - if (plane_cnt) - nvm_dev_dma_free(dev, rqd.ppa_list, rqd.dma_ppa_list); + nvm_free_rqd_ppalist(dev, &rqd); return ret; } diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index c228dbc..2fd6871 100644 --- a/include/linux/lightnvm.h +++ b/include/linux/lightnvm.h @@ -429,6 +429,9 @@ extern void nvm_unregister(char *); extern int nvm_submit_io(struct nvm_dev *, struct nvm_rq *); extern void nvm_generic_to_addr_mode(struct nvm_dev *, struct nvm_rq *); extern void nvm_addr_to_generic_mode(struct nvm_dev *, struct nvm_rq *); +extern int nvm_set_rqd_ppalist(struct nvm_dev *, struct nvm_rq *, + struct ppa_addr *, int); +extern void nvm_free_rqd_ppalist(struct nvm_dev *, struct nvm_rq *); extern int nvm_erase_ppa(struct nvm_dev *, struct ppa_addr); extern int nvm_erase_blk(struct nvm_dev *, struct nvm_block *); #else /* CONFIG_NVM */