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 0B3F9C4743C for ; Mon, 21 Jun 2021 14:56:51 +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 DB77B610C7 for ; Mon, 21 Jun 2021 14:56:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB77B610C7 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 4D9538298E; Mon, 21 Jun 2021 16:56:47 +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="CvUUml7V"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 529AA829A1; Mon, 21 Jun 2021 16:56:45 +0200 (CEST) Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (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 279CB8295C for ; Mon, 21 Jun 2021 16:56:41 +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-pl1-x62d.google.com with SMTP id f10so6577294plg.0 for ; Mon, 21 Jun 2021 07:56:41 -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:mime-version :content-transfer-encoding; bh=HYL5eA5PCAA2593Lm6q1zRn8YcsEoiiW7L0TBL0rPqU=; b=CvUUml7VT++N6Q6Li7gSANMq5SDS0IoEIt7hNO81+DH94k6IG/+lUbw9G3ftM2/so+ b0ZAQSVa/c5SPgAMXpPoOCk5g9M9FcAvVP8qlgETjVqTdlRzxDqkwh3UI3F1+azqcwpd yA2W6HVTdMH1R9DfGJaxSRMOPdXB0BwvK/8feRb8OP88Ig5jk+cxWbmLfoXtE3GktqNO QDpF3mhs3UsWKG9AC4OVjFJuAlzd9PPNyd6mtl7866SvkSGICMqVMdGim1oAGQ2Z4GyT E6uf0xcqZ5vYy+EhWjEs5bGnzF0hgyn/nmxJf+IohRO0cnabqxi9rTqpVoKw4iO6QwiQ MPOQ== 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:mime-version :content-transfer-encoding; bh=HYL5eA5PCAA2593Lm6q1zRn8YcsEoiiW7L0TBL0rPqU=; b=QFWF/wutNW7Cc9lxBxjU7kVL/fLnXXWpTqN+HWK2Zk8Mu2MKveqZp1pZMY+/3o+AQO wsq6AMZuHrxYsaiBZHl04kHkzcZM2+cB0f3QRuG5bInJyoFGCWU9OJPYJ0JLRDHhX2kX PnKkxv0skzuB8f6fcQWTJtcTW7Nv76MHwXA8KfLuhqChIPaED4NBYBlw1wxao3tQW2VE RuD8Xh7sxk8epOGhiUax7Ii9MIIlp3LMEC3C1/B/wkQh/6XVaRb7H1CjWuF7/ZyJ3mmn 6o9g0RiJrGysRuxqidM3TxMnaaIm2cty4MVFblcakLhgVvFT1PuwMS7rD868qVsPIDc2 8sVA== X-Gm-Message-State: AOAM531EsllWMtTGbpbyS5mVBchC+GSn4XZhUjJkNeWpKvbBjmCBUtUO VFhUWoikI5jp3N76GxNCEmBggXDXrqQ= X-Google-Smtp-Source: ABdhPJyRfZc3vckDTvQr48nZ9IAR1xORv8XS2oQj1VaWNtyOH/Joe/0Q2UapYrUH1UPSR/WQGg3Wjg== X-Received: by 2002:a17:903:2482:b029:124:896b:6ac3 with SMTP id p2-20020a1709032482b0290124896b6ac3mr6137144plw.21.1624287399190; Mon, 21 Jun 2021 07:56:39 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 07:56:38 -0700 (PDT) From: Bin Meng To: u-boot@lists.denx.de Cc: Bin Meng Subject: [PATCH 1/2] nvme: Move block dev creation from uclass post probe to driver probe Date: Mon, 21 Jun 2021 22:56:28 +0800 Message-Id: <20210621145629.18635-1-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 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 the block device creation happens in the NVMe uclass driver post probe phase. Move it to driver probe phase instead. A per-child platdata is added to store the namespace id, so that we can obtain it in the block driver probe phase, without the assumption that the ns id is encoded in the block device name. Signed-off-by: Bin Meng --- drivers/nvme/nvme-uclass.c | 30 ------------------------------ drivers/nvme/nvme.c | 30 +++++++++++++++++++++++++----- drivers/nvme/nvme.h | 14 ++++++++++++++ 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/drivers/nvme/nvme-uclass.c b/drivers/nvme/nvme-uclass.c index 277e31e1f3..610166d76e 100644 --- a/drivers/nvme/nvme-uclass.c +++ b/drivers/nvme/nvme-uclass.c @@ -5,39 +5,9 @@ */ #include -#include -#include #include -#include -#include "nvme.h" - -static int nvme_uclass_post_probe(struct udevice *udev) -{ - char name[20]; - struct udevice *ns_udev; - int i, ret; - struct nvme_dev *ndev = dev_get_priv(udev); - - /* Create a blk device for each namespace */ - for (i = 0; i < ndev->nn; i++) { - /* - * Encode the namespace id to the device name so that - * we can extract it when doing the probe. - */ - 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) - return ret; - } - - return 0; -} UCLASS_DRIVER(nvme) = { .name = "nvme", .id = UCLASS_NVME, - .post_probe = nvme_uclass_post_probe, }; diff --git a/drivers/nvme/nvme.c b/drivers/nvme/nvme.c index c61dab20c5..0b4a73d170 100644 --- a/drivers/nvme/nvme.c +++ b/drivers/nvme/nvme.c @@ -696,10 +696,11 @@ int nvme_scan_namespace(void) static int nvme_blk_probe(struct udevice *udev) { struct nvme_dev *ndev = dev_get_priv(udev->parent); + struct nvme_child_plat *nvme_pplat = dev_get_parent_plat(udev); struct blk_desc *desc = dev_get_uclass_plat(udev); struct nvme_ns *ns = dev_get_priv(udev); u8 flbas; - struct pci_child_plat *pplat; + struct pci_child_plat *pci_pplat; struct nvme_id_ns *id; id = memalign(ndev->page_size, sizeof(struct nvme_id_ns)); @@ -708,8 +709,7 @@ static int nvme_blk_probe(struct udevice *udev) memset(ns, 0, sizeof(*ns)); ns->dev = ndev; - /* extract the namespace id from the block device name */ - ns->ns_id = trailing_strtol(udev->name) + 1; + ns->ns_id = nvme_pplat->ns_id; if (nvme_identify(ndev, ns->ns_id, 0, (dma_addr_t)(long)id)) { free(id); return -EIO; @@ -727,8 +727,8 @@ static int nvme_blk_probe(struct udevice *udev) desc->log2blksz = ns->lba_shift; desc->blksz = 1 << ns->lba_shift; desc->bdev = udev; - pplat = dev_get_parent_plat(udev->parent); - sprintf(desc->vendor, "0x%.4x", pplat->vendor); + pci_pplat = dev_get_parent_plat(udev->parent); + sprintf(desc->vendor, "0x%.4x", pci_pplat->vendor); memcpy(desc->product, ndev->serial, sizeof(ndev->serial)); memcpy(desc->revision, ndev->firmware_rev, sizeof(ndev->firmware_rev)); @@ -879,6 +879,25 @@ static int nvme_probe(struct udevice *udev) nvme_get_info_from_identify(ndev); + /* Create a blk device for each namespace */ + for (int i = 1; i <= ndev->nn; i++) { + struct udevice *ns_udev; + struct nvme_child_plat *pplat; + char name[20]; + + 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; + + /* Update the platform data */ + pplat = dev_get_parent_plat(ns_udev); + pplat->ns_id = i; + } + return 0; free_queue: @@ -893,6 +912,7 @@ U_BOOT_DRIVER(nvme) = { .bind = nvme_bind, .probe = nvme_probe, .priv_auto = sizeof(struct nvme_dev), + .per_child_plat_auto = sizeof(struct nvme_child_plat), }; struct pci_device_id nvme_supported[] = { diff --git a/drivers/nvme/nvme.h b/drivers/nvme/nvme.h index aa4b3bac67..11b3ab6872 100644 --- a/drivers/nvme/nvme.h +++ b/drivers/nvme/nvme.h @@ -637,4 +637,18 @@ struct nvme_ns { u32 mode_select_block_len; }; +/** + * An NVM Express child (namespace) platdata + * + * Every blk device on a NVMe bus has this per-child data. + * + * It can be accessed using dev_get_parent_plat(dev) if dev->parent is a + * NVMe device (i.e. UCLASS_NVME) + * + * @ns_id: namespace id + */ +struct nvme_child_plat { + unsigned ns_id; +}; + #endif /* __DRIVER_NVME_H__ */ -- 2.25.1