Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D774C2B9F4 for ; Tue, 22 Jun 2021 13:16:56 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 04B6C60FE9 for ; Tue, 22 Jun 2021 13:16:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 04B6C60FE9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1BC49829BE; Tue, 22 Jun 2021 15:16:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Zv+Gif56"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D5EE9829A6; Tue, 22 Jun 2021 15:16:39 +0200 (CEST) Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5B466828EB for ; Tue, 22 Jun 2021 15:16:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=bmeng.cn@gmail.com Received: by mail-pf1-x433.google.com with SMTP id p13so16435366pfw.0 for ; Tue, 22 Jun 2021 06:16:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fRHIjOMv6Oj4xPxRxniZDJiwL2VeSe40CXnRiNImuW4=; b=Zv+Gif56SwTeIOwEH4IuucMF5ch/Qi/mnZbUeC+k7sTOzDpZajvp272484bLtTJxhY VHJy+2eF1Q6+1cBrZ6cNiaDShZ59Q8YvmrdYKfVULqBBNkIdO9cqAYxFEi3vju8ZqSHY n8sH5YsEWv3z9L6ZpJn5TBslNQgI5NWVu/ZWEE44b3kQGr5oJH62adVLyzZqAhgagDOB kNZfFsBiw2l4981bA1NXO+4RzNAi8tduXpiGL4q5Q3HMHwb9eYCjKfmzYB+bhgTc7OjD NEr9oEWLi/sf2tPSyJXaHwsG3sjs5HWefhEI2DsVV9QB59xY/6hkgSFo/MlaVMH25Kpy agRQ== 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=fRHIjOMv6Oj4xPxRxniZDJiwL2VeSe40CXnRiNImuW4=; b=MEjr327Tg3GpJtsI73JFJGAU54iRpPDcZpcq+aKzWPDlyfJ/MUMRvnLNww/RsyOm8x 7LPGaIIUmvmBtRaU/c9BDRfnOPrn0eFAv7211b/v4NeqYuAfSMFnUKSEhMmdc5jn8QRn EXLBLw6u8UlTPAWDJgchqqSQO0p852V8GFRfQ0SXyE6HXGNJ/umYpE2SqAvM4oL9UadG ffS5nF7LZegI5FP095YRYE2BiayxM8MLFOuoxUPKOTtCGyMnemretxw7Ujg3ojBZL0OV uja0CNI2/obmzaV9DPHM4gN8pCxJSsxpqSuuvUlV70rD2l8cAYNmhYz8sxtreBtQxPOB IDfA== X-Gm-Message-State: AOAM5303k30p5ofIs7ibmkNf3Dz9eRuDehXc5r4lejhfKuxr/vgP/3h6 bYtAd890lkDX3QHOLSlLf28= X-Google-Smtp-Source: ABdhPJy4Xcm8Efr8DNhuJj6jKJAolUq6kzLtikRPivufTKL+9Chn4HrPpROze7u5CJqolzQuNa8hpQ== X-Received: by 2002:a62:3344:0:b029:24c:735c:4546 with SMTP id z65-20020a6233440000b029024c735c4546mr3711663pfz.1.1624367794785; Tue, 22 Jun 2021 06:16:34 -0700 (PDT) Received: from i9-aorus-gtx1080.localdomain (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id j24sm18456482pfe.58.2021.06.22.06.16.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Jun 2021 06:16:33 -0700 (PDT) From: Bin Meng To: Tom Rini , u-boot@lists.denx.de Cc: Bin Meng , Heinrich Schuchardt Subject: [PATCH v2 2/7] nvme: Skip block device creation for inactive namespaces Date: Tue, 22 Jun 2021 21:16:18 +0800 Message-Id: <20210622131623.21265-2-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210622131623.21265-1-bmeng.cn@gmail.com> References: <20210622131623.21265-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean At present for each namespace there is a block device created for it. There is no issue if the number of supported namespaces reported from the NVMe device is only 1. Since QEMU commit 7f0f1acedf15 ("hw/block/nvme: support multiple namespaces"), the number of supported namespaces reported has been changed from 1 to 256, but not all of them are active namespaces. The actual active one depends on the QEMU command line parameters. A common case is that namespace 1 being active and all other 255 being inactive. If a namespace is inactive, the namespace identify command returns a zero filled data structure. We can use field NSZE (namespace size) to decide whether a block device should be created for it. Reported-by: Heinrich Schuchardt Signed-off-by: Bin Meng --- (no changes since v1) drivers/nvme/nvme.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/nvme.c b/drivers/nvme/nvme.c index 29735a6ad8..bb24c9cdd3 100644 --- a/drivers/nvme/nvme.c +++ b/drivers/nvme/nvme.c @@ -835,6 +835,7 @@ static int nvme_probe(struct udevice *udev) { int ret; struct nvme_dev *ndev = dev_get_priv(udev); + struct nvme_id_ns *id; ndev->instance = trailing_strtol(udev->name); @@ -880,10 +881,27 @@ static int nvme_probe(struct udevice *udev) nvme_get_info_from_identify(ndev); /* Create a blk device for each namespace */ + + id = memalign(ndev->page_size, sizeof(struct nvme_id_ns)); + if (!id) { + ret = -ENOMEM; + goto free_queue; + } + for (int i = 0; i < ndev->nn; i++) { struct udevice *ns_udev; char name[20]; + memset(id, 0, sizeof(*id)); + if (nvme_identify(ndev, i + 1, 0, (dma_addr_t)(long)id)) { + ret = -EIO; + goto free_id; + } + + /* skip inactive namespace */ + if (!id->nsze) + continue; + /* * Encode the namespace id to the device name so that * we can extract it when doing the probe. @@ -894,11 +912,14 @@ static int nvme_probe(struct udevice *udev) ret = blk_create_devicef(udev, "nvme-blk", name, IF_TYPE_NVME, -1, 512, 0, &ns_udev); if (ret) - goto free_queue; + goto free_id; } + free(id); return 0; +free_id: + free(id); free_queue: free((void *)ndev->queues); free_nvme: -- 2.25.1