Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp950294pxj; Fri, 11 Jun 2021 16:29:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4VpcsdDihQB3JJo9cRMes3dJTEUc9Ld1Tz6vCMg0eC9WDyf+IILKgnEYst0ea82ao6vRc X-Received: by 2002:a17:906:d1d2:: with SMTP id bs18mr5754896ejb.56.1623454173703; Fri, 11 Jun 2021 16:29:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623454173; cv=none; d=google.com; s=arc-20160816; b=eLC1rtGcXhtZnCQjmVlQo1Q/zSGcT3kwBb8/hWNv2HJlyS+XbjkvjFafv6NIusWXh3 au+utbUN/BO5vddcQZuj/K4mn8+SdBn/tyJW19dJuPaT9sRt8dIYp3hwYql5w/BSD+bL VH4bjjk4b8ZuUBP7HUr3iQBY9oDRkSuxaLTEunsUrpAOUR/gD9C0ATyce8iyZcUCfOY4 ozfZcjJbI0gG2MpPUy3cl4PrRD9QuloEwxn/DKpbzPVyHkv+dkrdaXmda34is3/Bw//j SGfUXDUcg9ht5ls36Bf9CGSJfCF/DcNmoJfC0U2PWbVu9CemVUvW8YJ7p3LE/LTDf1nR H4hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=NRPaXiyWw09i4FXsXzqTGbFV36hQVYFvFNIq5L13HVo=; b=bNVYuiHW+oiWsRRrhPRFLDMWA6vVeH9wQZIJJ1C93WdeL3OOoXWGnMw3hX08qz9/Rv qiGJA2p6X6Kkb6u9u+aOpdhL1lyx8Qnpxr7qS9vV2CMyWob3Xc+d2Cp81kxipu9Z0HOg ct6HEENJKHdSUFJGZTq/hpWhOOHTgX6dWwMOlMCSxgWw4RwJJddxApyS1TJR3QmBZxpc cJ2+UYYjsITxrgxT86UN/m7ZiQ/EzRDotuiUN+t759by9d1r008K4U1gqnmxMhui4maX nbfBYrKkcFK+wYyguW//C2DXNvvlCgr5DTQgC3MzWmvhLRUcvfDzNv2x/HxCTcy/Iita feMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=FecO0yDt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id md14si6208099ejb.89.2021.06.11.16.29.10; Fri, 11 Jun 2021 16:29:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=FecO0yDt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229540AbhFKX2R (ORCPT + 99 others); Fri, 11 Jun 2021 19:28:17 -0400 Received: from mail-pj1-f50.google.com ([209.85.216.50]:45652 "EHLO mail-pj1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230017AbhFKX2P (ORCPT ); Fri, 11 Jun 2021 19:28:15 -0400 Received: by mail-pj1-f50.google.com with SMTP id z3-20020a17090a3983b029016bc232e40bso6835675pjb.4 for ; Fri, 11 Jun 2021 16:26:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NRPaXiyWw09i4FXsXzqTGbFV36hQVYFvFNIq5L13HVo=; b=FecO0yDtUwufaEcPlqy4EvBDXv0RG+KrLKiBFSYxjyG7826p3FI0Txr93bsf36KUql u0VSY9bYf99yfiKwO+k+AzZmcy/w9wrpq7BYt9y68w1sXDlJWBizWLI0o1821dq+ULgY EbXCr/9vx+C7B15jLrA+pNMz2HQRnjA7bMMof5WdQ6gvr48bjQnME8zYbD6uOKEyd5B4 mH0lCxV0HaR59FNvBiJd/JLBWYD+6y/mQ7Eo8ZteR56oXA0xaQ33oVjXT3LIWigiqQC5 VgE/Ol9IydQU4zzsl44R5qssD7KLzrI53xjwE3XEiRA+QECuAlLxKKLJwFms6ClAsmy9 WM7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NRPaXiyWw09i4FXsXzqTGbFV36hQVYFvFNIq5L13HVo=; b=OC0o+YWtAvXtRojSFQfWC41F++m9pU7e9tzFCErihnUrfx4grD0ENGzHzMtg6ymFXf gVlSUdR1YppuzAc3wlfljsQ+rcq14tBlHXRl/392n594DG6woDQmBD6uNa9Ih1Cr9dlT LLr88MDRHqr888fdmzJalKUV/6PLX06ajMchxGY6DvUs5vMg6mBoQlNrZSghoKALH3aN XXhVSXH7EcISD7jGQjGBZz8a86HN2NAWXG4bJBA87eFniXEPYGPTM364j9IwXNztLcXz Xzfdi92z4XUK04AyGt8/bHnWk76FCfM7gWGW/y82p0OlxD+/ihfjARdeCQk1cNOk1/PD ATJA== X-Gm-Message-State: AOAM530ELqiIAHBVKAGS8HUIFdNsOpQc1YuSek3C02AOMhhT2tcjEHuz tSkiHpBxln4HoPbHtU4v+YeNmsfErnPAN3syyiztuA== X-Received: by 2002:a17:902:b497:b029:115:e287:7b55 with SMTP id y23-20020a170902b497b0290115e2877b55mr5941567plr.79.1623453916871; Fri, 11 Jun 2021 16:25:16 -0700 (PDT) MIME-Version: 1.0 References: <162336395765.2462439.11368504490069925374.stgit@dwillia2-desk3.amr.corp.intel.com> <162336396329.2462439.16556923116284874437.stgit@dwillia2-desk3.amr.corp.intel.com> <20210611174736.ttzpk5uniyoyd4vw@intel.com> <20210611192829.bwdj322uwlsbdrjs@intel.com> In-Reply-To: <20210611192829.bwdj322uwlsbdrjs@intel.com> From: Dan Williams Date: Fri, 11 Jun 2021 16:25:05 -0700 Message-ID: Subject: Re: [PATCH 1/5] cxl/core: Add cxl-bus driver infrastructure To: Ben Widawsky Cc: linux-cxl@vger.kernel.org, Linux NVDIMM , "Schofield, Alison" , Vishal L Verma , "Weiny, Ira" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 11, 2021 at 12:28 PM Ben Widawsky wrote: > > On 21-06-11 11:55:39, Dan Williams wrote: > > On Fri, Jun 11, 2021 at 10:47 AM Ben Widawsky wrote: > > > > > > On 21-06-10 15:26:03, Dan Williams wrote: > > > > Enable devices on the 'cxl' bus to be attached to drivers. The initial > > > > user of this functionality is a driver for an 'nvdimm-bridge' device > > > > that anchors a libnvdimm hierarchy attached to CXL persistent memory > > > > resources. Other device types that will leverage this include: > > > > > > > > cxl_port: map and use component register functionality (HDM Decoders) > > > > > > Since I'm looking at this now, perhaps I can open the discussion here. Have you > > > thought about how this works yet? Right now I'm thinking there are two "drivers": > > > cxl_port: Switches (and ACPI0016) > > > cxl_mem: The memory device's HDM decoders > > > > > > For port, probe() will figure out that the thing is an upstream port, call > > > cxl_probe_component_regs and then call devm_cxl_add_port(). I think that's > > > straight forward. > > > > I was expecting cxl_port_driver.probe() comes *after* port discovery. > > Think of it like PCI discovery. Some agent does the hardware topology > > scan to add devices, in this case devm_cxl_add_port(), and that > > triggers cxl_port_driver to load. So the initial enumeration done by > > the cxl_acpi driver will populate the first two levels of the port > > hierarchy with port objects and populate their component register > > physical base addresses. For any other port deeper in the hierarchy I > > was expecting that to be scanned after the discovery of a cxl_memdev > > that is not attached to the current hierarchy. So, for example imagine > > a config like: > > > > Platform --> Host Bridge --> Switch --> Endpoint > > > > ...where in sysfs that's modeled as: > > > > root0 --> port1 --> port2 --> port3 > > > > Where port3 is assuming that the CXL core models the device's > > connection to the topology as yet another cxl_port. At the beginning > > of time after cxl_acpi has loaded but before cxl_pci has discovered > > the endpoint the topology is: > > > > root0 --> port1 > > > > Upon the detection of the endpoint the CXL core can assume that all > > intermediary switches between the root and this device have been > > registered as PCI devices. So, it follows that endpoint device arrival > > triggers "cxl_bus_rescan()" that goes and enumerates all the CXL > > resources in the topology to produce: > > > > root0 --> port1 --> port2 --> port3 > > > > Ah, I had written about scan/rescan in an earlier version of my email but > dropped it. I was actually going to suggest it being a sysfs attr, but I'm fine > with it being implicit so long as... > > How do we assert that cxl_pci doesn't run before cxl_acpi has done anything? I don't think we need to, or it's broken if the driver load order matters. The nvdimm enabling code is an example of how to handle this. The cxl_nvdimm object can be registered before the cxl_nvdimm_bridge, or after, does not matter. If the cxl_nvdimm comes first it will trigger the cxl_nvdimm_driver to load. The cxl_nvdimm_driver.probe() routine finds no bridge present and probe() returns with a failure. When the bridge arrives it does a rescan of the cxl_bus_type device list and if it finds a cxl_nvdimm it re-triggers cxl_nvdimm_driver.probe(). This time through cxl_nvdimm_driver.probe() finds the bridge and registers the real nvdimm on the nvdimm_bus. > I > like the idea that the endpoint device can simply ask cxl_acpi to rescan, I just > don't see how it works. I suppose we can queue up the requests to rescan in > cxl_acpi if the ordering can't be guaranteed. I think this means that the devm_cxl_add_port() would be triggered by cxl_memdev_driver.probe() if and only if the parent pci_device of the CXL endpoint is listed as a dport. If the cxl_memdev is registered first the search it will search for the CXL root port on the cxl_bus_type device list. If that fails then cxl_memdev_driver.probe() fails. If that succeeds it asks the root to scan to the CXL endpoint parent pci_device and return the confirmation that it is registered as a dport. If that fails then the device is plugged into a pure PCIe slot. When cxl_acpi loads it retriggers all cxl_memdev_driver.probe() to reconsider all cxl_memdev instances that failed to probe previously. > > > > For the memory device we've already probed the thing via class code so there is > > > no need to use this driver registration, however, I think it would be nice to do > > > so. Is there a clean way to do that? > > > > The PCI device associated with the endpoint is already probed, but the > > cxl_memdev itself can have a driver on the CXL bus. So I think the > > cxl_memdev driver should try to register a cxl_port after telling > > cxl_acpi to rescan. If a check like "is_cxl_dport(pdev->dev.parent)" > > for the endpoint returns false it means that the cxl_bus_rescan() > > failed to enumerate the CXL topology to this endpoint and this > > endpoint is limited to only CXL.io operation. > > What is going to invoke the memdev driver's probe? That is where we're talking > about putting that is_cxl_dport(...) right? That is the part that tripped me up > and inspired the original email FWIW. I *think* I worked that out above, but yes please do poke at it to see if it holds up.