Received: by 10.223.185.116 with SMTP id b49csp1625910wrg; Wed, 21 Feb 2018 23:51:23 -0800 (PST) X-Google-Smtp-Source: AH8x226T1ZzBgLnkwl26te72IYpnaWlFq/mK7boEh4vd1pwrBGfVFS9Jp2eHmxcOlBRXlPfX79yn X-Received: by 2002:a17:902:bc3:: with SMTP id 61-v6mr5681990plr.407.1519285883684; Wed, 21 Feb 2018 23:51:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519285883; cv=none; d=google.com; s=arc-20160816; b=Jsp199vN9ebrL+Tj/P8plRIPmB1I7Bx7ZEIeb8WjBh1gXpnBwPhxMSQh4oDAgtpPCE q/3CprApaPmH/6cdhkp9wxaYuIv3VTLW8J9yof/HVAoCkp9mXsUG1VMurfGUloOEi85K tnjApym9TEPqyAY1chaLd+bVuMkBtxBtT9ssi3qQ39ZrcXa89Oj3LfgVXjwPredHEeA8 xjaE2JessPjDkHGXefig8FTvifoG04D80zl9cbnqA7SlfFs6WKyyYhKnV50/lQdLszvj FcAStKwBAhOO6guKSkQjN42Z/chfTyUCPbYH8lnqeY/yx25zFG+NQqy/AleplOdiz58d f3AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:to:cc:in-reply-to:date:subject :mime-version:message-id:from:dkim-signature :arc-authentication-results; bh=vPkp8I0jgqduICbtGdSJ0LKVXYNhAkJqlDVsPljFNww=; b=uvNarwC2yHi82rYPCObODWtijZ+EV9/ZocMTtlG0XgC+6FsMfa67YgyvY2pYS4PMV2 1OwgeIGf1SXIXYxCzpTo90F1h3W0wy1nJs+Pn/UZxRTO5R+XNXmrtzvJS7oehRvxIMFP LN0JgYliKXjozWdcZro6xC4o0ie3XmExZrkpkDfPmiWGQdhPeTwtrhwaJOhGoCQ12UlO S8HoXH9ZgdyBVz3f85/HOzsbAcRv3KpLAS7p5frv0OlPd4w2rh7418D65fkaAST2pVIn hRpEbsn99uLxdWMChXc2DeEHbWqzzGOrsksaVIzVdqWSqeYT0myqxuI6KU4x9NG3otI9 sLWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lightnvm-io.20150623.gappssmtp.com header.s=20150623 header.b=CNqNSADv; 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 o19si4267700pgn.180.2018.02.21.23.51.09; Wed, 21 Feb 2018 23:51:23 -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=CNqNSADv; 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 S1752779AbeBVHt6 (ORCPT + 99 others); Thu, 22 Feb 2018 02:49:58 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:55303 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752627AbeBVHt4 (ORCPT ); Thu, 22 Feb 2018 02:49:56 -0500 Received: by mail-wm0-f66.google.com with SMTP id q83so2041675wme.5 for ; Wed, 21 Feb 2018 23:49:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lightnvm-io.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=vPkp8I0jgqduICbtGdSJ0LKVXYNhAkJqlDVsPljFNww=; b=CNqNSADvTa/2+tW9e/F5HdHdpBPST8mKrktD9454eRZR6R9IadTf98l3/vlzZnnFLj cC48EsnOwcy/44DUDxQqMClkKNycYBK5Ecspbni6KNnJJhX4QvNc2fFyiM1qQ07MViR1 rebfTQg2ArXE3IuAxSmjgAq4bTSY37fMfp+oaCFh4kF9h8JqbxdFimLZWGUGp0sU1NNl wLQY3Vsn05/xUhfyszvX7zLrx26UAOq7IQKEyezRY3eugY4+Tzur6p4nGv2/LQGKuAqO vXhOP6wW8lx4/SuY63KztOiPJctZ4aDSF+R+eLJeRz3jsGyRQz6bQKO1X2Qd/WHjc+8+ u0oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=vPkp8I0jgqduICbtGdSJ0LKVXYNhAkJqlDVsPljFNww=; b=U/UeqfmXzuCgTnRn2rRAmHIC54hKZGfIL6DzMT7OtG4jBOYZOwkaHCUUSZ8OIvKnoL l+KM2LAQSW0eJomwfJbI09GR/1cb4igDF2qEB8cytlywwsVI+HX/mV1EsDJDqRulhYry u0/z4rMMk/E0QpDaLBUbh6QSW5WL6mDyYD1zFSWTNK0XmPnwXgxZcMmSrc0zNKMpotbY 30VIetu4vkqo/rHiT22KAXFmgxha8anFgkE4jBHqQlmVMGf4A0ooAiRbG+mKfiuc3esW pdB0Ivhp9kCtdrUZEP4yOx0WbMYM874+6T0wc5jOrXcuX6e6kWH3s8B+8KqSe8LUBG3l FbxQ== X-Gm-Message-State: APf1xPA7o2cOtQWPl9Sn50+je1AjXdcwZ4lN7CVS1ERlhAWaP4bAOPdK uhbF2vhKrL7bVLbQ7EghgVyWKg== X-Received: by 10.80.159.1 with SMTP id b1mr8188415edf.132.1519285795202; Wed, 21 Feb 2018 23:49:55 -0800 (PST) Received: from mac-halley13.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id i31sm17637913edc.48.2018.02.21.23.49.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 23:49:54 -0800 (PST) From: =?utf-8?Q?Javier_Gonz=C3=A1lez?= Message-Id: <1FE350B9-E8CD-43BC-8AE8-2593A6398D3F@lightnvm.io> Content-Type: multipart/signed; boundary="Apple-Mail=_1CD6AF7F-4ADE-4316-B039-83EA8F609F82"; protocol="application/pgp-signature"; micalg=pgp-sha512 Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: Re: [PATCH 09/20] lightnvm: use generic identify structure Date: Thu, 22 Feb 2018 08:49:51 +0100 In-Reply-To: <6f76c204-847a-2f20-3070-06cb28a66555@lightnvm.io> Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org To: =?utf-8?Q?Matias_Bj=C3=B8rling?= References: <1519205218-26994-1-git-send-email-javier@cnexlabs.com> <1519205218-26994-10-git-send-email-javier@cnexlabs.com> <6f76c204-847a-2f20-3070-06cb28a66555@lightnvm.io> X-Mailer: Apple Mail (2.3445.5.20) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --Apple-Mail=_1CD6AF7F-4ADE-4316-B039-83EA8F609F82 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 22 Feb 2018, at 08.47, Matias Bj=C3=B8rling wrote: >=20 > On 02/21/2018 10:26 AM, Javier Gonz=C3=A1lez wrote: >> 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=C3=A1lez >> --- >> 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 =3D ((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 =3D (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 =3D ((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 =3D (struct nvme_nvm_id20 *)gen_id; >> + >> dev_geo->major_ver_id =3D id->mjr; >> dev_geo->minor_ver_id =3D 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 =3D nvmdev->q->queuedata; >> - struct nvme_nvm_id12 *id; >> + struct nvme_nvm_id *nvme_nvm_id; >> struct nvme_nvm_command c =3D {}; >> int ret; >> c.identity.opcode =3D nvme_nvm_admin_identity; >> c.identity.nsid =3D cpu_to_le32(ns->head->ns_id); >> - id =3D kmalloc(sizeof(struct nvme_nvm_id12), GFP_KERNEL); >> - if (!id) >> + nvme_nvm_id =3D kmalloc(sizeof(struct nvme_nvm_id), GFP_KERNEL); >> + if (!nvme_nvm_id) >> return -ENOMEM; >> ret =3D 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 =3D -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 =3D nvme_nvm_setup_12(id, &nvmdev->dev_geo); >> + ret =3D nvme_nvm_setup_12(nvme_nvm_id, = &nvmdev->dev_geo); >> break; >> case 2: >> - ret =3D nvme_nvm_setup_20((struct nvme_nvm_id20 *)id, >> - = &nvmdev->dev_geo); >> + ret =3D 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 =3D -EINVAL; >> } >> out: >> - kfree(id); >> + kfree(nvme_nvm_id); >> return ret; >> } >>=20 >=20 > Thanks for another way to represent it. I want to keep the original > path. If we are going that down road, then one should maybe look into > unifying the "three" data structures, and have the version as the base > property and the others in each their sub data structure. That's what this structure aims to do, since the version is shared. But you call if you want to cast unrelated structures back an forth. I'll revert it... Javier --Apple-Mail=_1CD6AF7F-4ADE-4316-B039-83EA8F609F82 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEm1mT7zen+vs9+T8kYx8FO3WZGMoFAlqOdh8ACgkQYx8FO3WZ GMrdXRAAtR/o4697/X6iUqg09P6U1J8FFEAPwvddEK/deZm+SelVFkjrVZzjL2vs YXvp0KpuKC/CEGK5KypezQ06IgPTDrVIteJOCvlvhNJH0ALp5GqqBqlYsjEvW0d3 zWeMPNTsvg4RYjwxSjg7e4M+3l9U4dH6r35otGGZOAwfY4kYBTka6HcJjTpqKf0B IuPQlTkciCrvAKVzyYSN6LM9fo61+l+Za7vXYTQWLqb8XriKaGL33fV69f9JGe+j DneTeJLmefB8Q7iwHVRW5sAMphxumEGfK4TNAeXW6leYK/2sj72/YfFMR/2ZiWO3 +FvmtmwwTl8iuvURQXtPNjrDWjEGSn4Eq8AGcXMxkXiO6fmtCjTfja5fm9xkKeVV t1pn/mfS0dKYrhD4zQcTW5ISxjqA+nWC9ITvL1L/ewTYYSqLbzXFmWsyWU7gYj9w T5MMQwtTMERIJ+Gs2EK94iJS/8LLlY3oiXrewjtj/Vda/JDFUN4zuHu4XCGGjXmz jjGiKHKgFrB2jNCz0CTT+H7/z9oXairuaQlj5Srg0kTUjLTWi9EaT8pQYdmTdEIK a0RvuAJviVlSTv6DfGRJc05sK1BoduIse1PNjxZ0WRnPo08TuzRfSqPEGHllBhf5 GCZiqsx8j40hYsh6uwDOk4D9MpKILZaPEBqIQwMSRCpuZG4WU5Q= =piTq -----END PGP SIGNATURE----- --Apple-Mail=_1CD6AF7F-4ADE-4316-B039-83EA8F609F82--