Received: by 10.223.185.116 with SMTP id b49csp481795wrg; Wed, 21 Feb 2018 01:32:29 -0800 (PST) X-Google-Smtp-Source: AH8x224DLNE1dR4QVUQu789C5Tf7aPlEGkiZEWhR6YOg4ueIITBlBS4Go8k8vrFrRX12bgYYxjte X-Received: by 2002:a17:902:26a:: with SMTP id 97-v6mr2575856plc.3.1519205548987; Wed, 21 Feb 2018 01:32:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519205548; cv=none; d=google.com; s=arc-20160816; b=sCLLXVG5b4tfvKAHOFDv0JrlOjVEzumt+DBhe0qyPCeftkoWQgH7klQfk+uzgFQ6Pf 4SqgDMGzTCOwv//4naoCp7Vo1c+Z8OUc1IZs1icqk/76mSLv7NPmIJGN8a9b1JC5m4p0 5qpeaz0tr9czEJLLRkfwNuWFbWacOxel1Wwyu0fm7AxB++gFSCaSoh4GfaETwoGcJ+CS eadyPNq9W5E6lxKGJCYaDoiCLjLegOCOAWfHhkNHkXE43atoqmGFG0MT7B7hTjUjedFn FDyXVzRzTtviZm3D0hmPvjACmP+CPBwQswc2Jj05sLZ2c6pPTFht0ukwGxXAAUz0YueL hbYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=285YcAG85Fx2gGUIuxTZgYdAgo1Ygj/5uwHg+RPtZew=; b=zc8lxsj/Q9/ORUAdtH85oFrTtI1mXb5C1aRAToV5/IgAMtObIQ+jtt90mdyXCVcDU5 5Fm3eRUrlaEAa7Pry9SyJPsZspjz8Uc3N2xy//PPA9vUeMs10tNZT8zJaoMrHp0TP30u MxZyAEkgI5VHNz2wMyPsJaRURCLXkDTJ4xmN6kTFGla8kGjWfS5kjEMudpSjqry9CDVc YCrPAZs3ubdsKqDmYmhKoYhP41nZc9WRIHv9+HTd1mevknmeb9gEPrMsHS0ECxm6e4J3 9VP3ByoWacSF+aMX7vQZ1G/MB2FtEvx8OvIX6ZBfzlgoBXXIB21AIoAsuu2R1IaVTvMQ /oVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lightnvm-io.20150623.gappssmtp.com header.s=20150623 header.b=yuOj6oEy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l26si1108417pfj.401.2018.02.21.01.32.15; Wed, 21 Feb 2018 01:32:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@lightnvm-io.20150623.gappssmtp.com header.s=20150623 header.b=yuOj6oEy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932418AbeBUJav (ORCPT + 99 others); Wed, 21 Feb 2018 04:30:51 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:39695 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753310AbeBUJ1U (ORCPT ); Wed, 21 Feb 2018 04:27:20 -0500 Received: by mail-wr0-f196.google.com with SMTP id w77so2439178wrc.6 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=a40OZJe4c2yXJ+nKBeZyUcM4Y1UMBMCZ2Ao0YoNuFEauvvELOqrXyIJoGmq/UYy95J XrFNmDFH6xii6JCbrXUh3UZ+0siBP3UVO0uR+dDRdgnn79aO/M3fIq8MCS9b6BBYd5v6 lYtRWKpPLx0uIiJpPEXaYgdCw3nu5csG27FTTlUHo/zhLYha4e1vruKv8ahuBMT0tdmY Jj3oR6Nu34f5hgIvbwLOIKoR1Bq96KRGlIHP9md9rSlxNTMoK9j+qBEDAAgbM64xKBHj 3Z+Nq62UavAM4aOXsBO97+XktRw/A+BdLZWA0aAyFG2tav6W7eykH1gp5HHTZKvaqAVp AEkA== X-Gm-Message-State: APf1xPCH4h7EQ3SK9tZIRv7jCPiWRMa+Ritkf8Fv9L5rGFY8jb46Qj/5 KxlaeBTopzODVyY7A+yDI296Xg== 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.7.4