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,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 0CE68C4743C for ; Mon, 21 Jun 2021 14:57:03 +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 11DB7610C7 for ; Mon, 21 Jun 2021 14:57:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 11DB7610C7 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 1D2CA829AE; Mon, 21 Jun 2021 16:57:00 +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="gB7VVm3/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4DA37829A6; Mon, 21 Jun 2021 16:56:47 +0200 (CEST) Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) (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 542CE82976 for ; Mon, 21 Jun 2021 16:56:43 +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-x42c.google.com with SMTP id k6so13819538pfk.12 for ; Mon, 21 Jun 2021 07:56:43 -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=KdaAalLg7IHgbb27hJiJaE2KIVivVZuaTZzfXVcT6WA=; b=gB7VVm3/374AUPQbXg7fJoePGz0DQM8veT4+TXdnDUNtwi6sAzjR/BCc/EvnR6SBot iDIH+ddRZjB8j2C2v44zjAJOpElk0qkK1bdtgwXF4rNqVr/tidj5UQQBSa1yVemIjQGJ zO51DiYDQ/7hPXHXeXFmIV/uJrjcztZw1mvKfbCWpgK4MUT0Olaz0P6xUwdWXxVlfEWt 18nzfflh9edpA4j09kIcX4kjt/TeJ6eGAUYls/Q19gAQYz2SklW2f59I7I5qemb/Hfge ac6FfeQ813DdVu207dl8+wKQGZbNNw8tAYIDnK0gFYMla/3AxqR6a6lsN5s/dNW8LoF4 1XRg== 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=KdaAalLg7IHgbb27hJiJaE2KIVivVZuaTZzfXVcT6WA=; b=hvYWmm7xocasG2ru/uy0H32DlSJzzvcl75Q2jl4e9dSvoMxvCE2t8IVdNT9fxwM76U sl/OIIvZ+iD9lTX0hwwU7/5BRQBPGvBwdVHTNgB8agK0i8aAENQSbTONFJet6qraBgZD z/WYvmdGpBl98RIDI3WZJoIMbJ0W83uJj9oino4P6nX4NMcmkZ41Lf8A9EwuNAVvPFub 8Bw+QhxcnQBGu4O7Ncul4MV4rEvGL94lfog1o2KTr32PNm21YS1h5qq/G5KrDMR9Ex+G cjOBMSDbf4n/y8aswXCo93vzwzmyltEYGaxr9uNsltuMR7TuTlBcfHwyYTf0eXnOly73 AKKw== X-Gm-Message-State: AOAM532Ef1XdThcly9oWQxqfZIeNzNABJUdVGy/onHOIRg0ba6ji3xYv W/AjmVOU8POkD9qvN7GEiCOew4mq8X4= X-Google-Smtp-Source: ABdhPJyF/LusbBM7/30xXklkv2aFox6hQT1OSoJ4z1ft39v99xGdlBxIoop9Zi0rNh/STMGhrxQOLQ== X-Received: by 2002:a63:d053:: with SMTP id s19mr24438964pgi.326.1624287401392; Mon, 21 Jun 2021 07:56:41 -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 g17sm11202319pfj.158.2021.06.21.07.56.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 07:56:41 -0700 (PDT) From: Bin Meng To: u-boot@lists.denx.de Cc: Bin Meng , Heinrich Schuchardt Subject: [PATCH 2/2] nvme: Skip block device creation for inactive namespaces Date: Mon, 21 Jun 2021 22:56:29 +0800 Message-Id: <20210621145629.18635-2-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210621145629.18635-1-bmeng.cn@gmail.com> References: <20210621145629.18635-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 won't be any 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 the active namespace depends on the command line parameters passed to QEMU, with the most common case that namespace 1 being active and all other 255 inactive. If a namespace is not active, the namespace identify command returns a zero filled data structure. We can use field NSZE (namespace size) to decide if a block device should be created. Reported-by: Heinrich Schuchardt Signed-off-by: Bin Meng --- 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 0b4a73d170..5ec5eaca16 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,26 +881,46 @@ 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 = 1; i <= ndev->nn; i++) { struct udevice *ns_udev; struct nvme_child_plat *pplat; char name[20]; + memset(id, 0, sizeof(*id)); + if (nvme_identify(ndev, i, 0, (dma_addr_t)(long)id)) { + ret = -EIO; + goto free_id; + } + + /* skip inactive namespace */ + if (!id->nsze) + continue; + sprintf(name, "blk#%d", i); /* The real blksz and size will be set by nvme_blk_probe() */ ret = blk_create_devicef(udev, "nvme-blk", name, IF_TYPE_NVME, -1, 512, 0, &ns_udev); if (ret) - goto free_queue; + goto free_id; /* Update the platform data */ pplat = dev_get_parent_plat(ns_udev); pplat->ns_id = i; } + free(id); return 0; +free_id: + free(id); free_queue: free((void *)ndev->queues); free_nvme: -- 2.25.1