From patchwork Wed Feb 21 09:26:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= X-Patchwork-Id: 10231657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4E38360209 for ; Wed, 21 Feb 2018 09:31:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 564CA28AA6 for ; Wed, 21 Feb 2018 09:31:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AD3928AAA; Wed, 21 Feb 2018 09:31:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E72AE28AA6 for ; Wed, 21 Feb 2018 09:31:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932368AbeBUJau (ORCPT ); Wed, 21 Feb 2018 04:30:50 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:42805 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753311AbeBUJ1U (ORCPT ); Wed, 21 Feb 2018 04:27:20 -0500 Received: by mail-wr0-f195.google.com with SMTP id k9so2432255wre.9 for ; Wed, 21 Feb 2018 01:27:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lightnvm-io.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=285YcAG85Fx2gGUIuxTZgYdAgo1Ygj/5uwHg+RPtZew=; b=yuOj6oEyRgSVe4r95Aa7EsdZmiBmIW8La72ibxAUI7PdRviUaimFD4i6wNNSsGkVuG 1SlMO+D8IKVHJ83p0H9umKCEv6LJwgxfSt6/aNOVlrPGMrjtkTXRWxQgtcUL5/lx/zjm eLniL4kYziW+MqICyK3Q1Tp3JcrkPhhCIceE44Cox1wQz0zme4D0JVqd+Ef4y2W8NBfK ZV9ulMJHqkI+g0rCxIv1D6GPVEvfzfblgfWdwTzo23cgTETVf+KQFrnLD1Kvv/aI3Vjm 8qAArAZl7vLIlP6Ci57FSzT20I18pb+Vz2dYeoWiKZpgyi+AeKey/hahTLt0ridJBeK8 W63Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=285YcAG85Fx2gGUIuxTZgYdAgo1Ygj/5uwHg+RPtZew=; b=EWzxx26EphTEcmQ5M8A0GA8J4kHGkYvega4JEd9IkIOE/TV5+bPnznTYHHBq5NjgTQ iA6YTmBBNsdzesOXCXNUNH5rDUFBNlVhZcJkNFZJrRVTtfrePSg05+JkDaIUqlWKZN04 J9UxdCqzu3hCl7ux/ajPzxXTNXXmZh+I4OE47GtlwUcGJbH0owZTYNM78LuJalHbhZiq u08XiTjhOlE+GVJse07jCGIsUl5AcxRywlqvWpPTkAcpMD1l99HImZrceetkmjWJPMpJ LjvNMcEoJE4jPwvqLMC/5b2VTr2AYuaSyB5iJcdDvxp7TegDkgNkLm1drnlcsOUmViL8 /SZg== X-Gm-Message-State: APf1xPB8unMlnT7FSL6tzV9xNANKyUDwdYHpbLPkci9bBrL8mk74SEkj pY57mn83OQxWXHkpWsqvPtZcdN/F X-Google-Smtp-Source: AH8x22432l7mt+iO1fiM9Dnlwd0Itj5x8m2yTS12TYGHPk/FqxW7AAQg/pz9Aov/kSH2BJIapX1zOw== X-Received: by 10.80.186.202 with SMTP id x68mr4090844ede.264.1519205239156; Wed, 21 Feb 2018 01:27:19 -0800 (PST) Received: from uHalley.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id a17sm3389955eda.42.2018.02.21.01.27.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Feb 2018 01:27:18 -0800 (PST) From: "=?UTF-8?q?Javier=20Gonz=C3=A1lez?=" X-Google-Original-From: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= To: mb@lightnvm.io Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= Subject: [PATCH 09/20] lightnvm: use generic identify structure Date: Wed, 21 Feb 2018 10:26:47 +0100 Message-Id: <1519205218-26994-10-git-send-email-javier@cnexlabs.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519205218-26994-1-git-send-email-javier@cnexlabs.com> References: <1519205218-26994-1-git-send-email-javier@cnexlabs.com> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Create a generic identify structure to collect the identify information before knowing the spec. version. This forces different version paths to cast the structure to their spec structure, thus making the code less error prone and more maintainable. Signed-off-by: Javier González --- drivers/nvme/host/lightnvm.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/drivers/nvme/host/lightnvm.c b/drivers/nvme/host/lightnvm.c index 9c1f8225c4e1..70dc4740f0d3 100644 --- a/drivers/nvme/host/lightnvm.c +++ b/drivers/nvme/host/lightnvm.c @@ -170,6 +170,12 @@ struct nvme_nvm_id12 { __u8 resv2[2880]; } __packed; +/* Generic identification structure */ +struct nvme_nvm_id { + __u8 ver_id; + __u8 resv[4095]; +} __packed; + struct nvme_nvm_bb_tbl { __u8 tblid[4]; __le16 verid; @@ -279,9 +285,10 @@ static void nvme_nvm_set_addr_12(struct nvm_addr_format_12 *dst, dst->sec_mask = ((1ULL << dst->sec_len) - 1) << dst->sec_offset; } -static int nvme_nvm_setup_12(struct nvme_nvm_id12 *id, +static int nvme_nvm_setup_12(struct nvme_nvm_id *gen_id, struct nvm_dev_geo *dev_geo) { + struct nvme_nvm_id12 *id = (struct nvme_nvm_id12 *)gen_id; struct nvme_nvm_id12_grp *src; int sec_per_pg, sec_per_pl, pg_per_blk; @@ -380,9 +387,11 @@ static void nvme_nvm_set_addr_20(struct nvm_addr_format *dst, dst->sec_mask = ((1ULL << dst->sec_len) - 1) << dst->sec_offset; } -static int nvme_nvm_setup_20(struct nvme_nvm_id20 *id, +static int nvme_nvm_setup_20(struct nvme_nvm_id *gen_id, struct nvm_dev_geo *dev_geo) { + struct nvme_nvm_id20 *id = (struct nvme_nvm_id20 *)gen_id; + dev_geo->major_ver_id = id->mjr; dev_geo->minor_ver_id = id->mnr; @@ -427,19 +436,19 @@ static int nvme_nvm_setup_20(struct nvme_nvm_id20 *id, static int nvme_nvm_identity(struct nvm_dev *nvmdev) { struct nvme_ns *ns = nvmdev->q->queuedata; - struct nvme_nvm_id12 *id; + struct nvme_nvm_id *nvme_nvm_id; struct nvme_nvm_command c = {}; int ret; c.identity.opcode = nvme_nvm_admin_identity; c.identity.nsid = cpu_to_le32(ns->head->ns_id); - id = kmalloc(sizeof(struct nvme_nvm_id12), GFP_KERNEL); - if (!id) + nvme_nvm_id = kmalloc(sizeof(struct nvme_nvm_id), GFP_KERNEL); + if (!nvme_nvm_id) return -ENOMEM; ret = nvme_submit_sync_cmd(ns->ctrl->admin_q, (struct nvme_command *)&c, - id, sizeof(struct nvme_nvm_id12)); + nvme_nvm_id, sizeof(struct nvme_nvm_id)); if (ret) { ret = -EIO; goto out; @@ -449,22 +458,21 @@ static int nvme_nvm_identity(struct nvm_dev *nvmdev) * The 1.2 and 2.0 specifications share the first byte in their geometry * command to make it possible to know what version a device implements. */ - switch (id->ver_id) { + switch (nvme_nvm_id->ver_id) { case 1: - ret = nvme_nvm_setup_12(id, &nvmdev->dev_geo); + ret = nvme_nvm_setup_12(nvme_nvm_id, &nvmdev->dev_geo); break; case 2: - ret = nvme_nvm_setup_20((struct nvme_nvm_id20 *)id, - &nvmdev->dev_geo); + ret = nvme_nvm_setup_20(nvme_nvm_id, &nvmdev->dev_geo); break; default: dev_err(ns->ctrl->device, "OCSSD revision not supported (%d)\n", - id->ver_id); + nvme_nvm_id->ver_id); ret = -EINVAL; } out: - kfree(id); + kfree(nvme_nvm_id); return ret; }