Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1808389pxb; Fri, 22 Oct 2021 08:04:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcdffcKsdYhwqHVqd0uWOkNydwLLDt56MfLtcauKhOfVg3Dv0HHQT/bqO29ZMZlRlhtNfL X-Received: by 2002:adf:e306:: with SMTP id b6mr500074wrj.244.1634915062344; Fri, 22 Oct 2021 08:04:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634915062; cv=none; d=google.com; s=arc-20160816; b=WHZcvxwRRTjB5Uu2BSAzRQ+xAlK8CHfdWhOv57vXyi4dc5SS0Go+jEszx/40Db/I+l HixGG9cDjrcvg1SdX2CwzZHEn5/ra41XqYs5fIpuw3kaXNBhmyfJ7D4ttLGoD1vNXfDb Z5dF44LCmwPpQzn8RuBFEGDvLq5SK4rDyDMWXwPOd7x2Hy/XA+m0RMs2wtw/dl/FkuuN YpBvl/iPH1GDntCKS7wY9j5zB4F4jPlSG0YzlZOvp/K1PZ6Oj9j3o9QZxXVaISpDNGb6 3Kh29keCwW7Rcijrq1/A3fJcGgJYT1PiotOIHGyub/rZkkUKzogK/axIu6IwTOKz/rjE gAuQ== 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=GIPpv6Q0RJFERejdEdswNrUDirFtVwEww7SCPVpfCjQ=; b=R4gfgU8iQLklquUfxKa8x1sIdIzuga1qoXDYeIKMuyt1Lb7r0KtaT/a1VzkukCrvCe fTflFlajRpiiw7FUhepK4+ZWUxldLbDvnOFAaTghOkseWWVnMhcINEgQMS9eZM0ixxKi CMo9IBac1KKvi4iCOIsR/NyCc73CeqF9MkEhwQlzfco8rYbHogR+q0Htm7OJJM42V4zn Dy5mqFnJnGH6DxvPvs3J/bRFOhfOX31y0abnEHQ9Q2C6JVUWEj1MzBcNLXb0p4hCJr5j SfjIOsJYsMLNjvd8xJkxf9jwmE7Rbzlfw2mTypkTfAwStXf7UzV2EYOnPEqrkTt7QOdy nnCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=O4Vxj1rj; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r20si12238467edd.587.2021.10.22.08.03.41; Fri, 22 Oct 2021 08:04:22 -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=@broadcom.com header.s=google header.b=O4Vxj1rj; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232966AbhJVPDd (ORCPT + 99 others); Fri, 22 Oct 2021 11:03:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232842AbhJVPDc (ORCPT ); Fri, 22 Oct 2021 11:03:32 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1AE1C061764 for ; Fri, 22 Oct 2021 08:01:14 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id y132-20020a1c7d8a000000b0032ca5765d6cso427084wmc.0 for ; Fri, 22 Oct 2021 08:01:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GIPpv6Q0RJFERejdEdswNrUDirFtVwEww7SCPVpfCjQ=; b=O4Vxj1rjyTbXhumLouMUWEvAckNJE/a15KBm+8m57gyA9GZFix4TLEWN6e1KUFHIUz z5y57C92vtUV+Z7ZXLcg7SXc2cTMnAH4Dz4UrlNCuMaG9dztkQlbkuShtxJPUKgaOWB9 JCO8j/8yvLOCsEgrPoygGB7dHNU2+DynHUvdI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GIPpv6Q0RJFERejdEdswNrUDirFtVwEww7SCPVpfCjQ=; b=12nkMTlThFJILJWDk3hhyG82LMms6oURNiXppnwTQLngmHir9smG8RKSE0DwL4OQKF SBHqLswLya6c/M5nlX7hr31fhKzyuzv2HokC/dNwCbEZZZkFToODrKIka5sUN5aCzVMf cdjdXmYVgvEa5SA1GvvPyNJiajEjTlHBtySlS1kmDRSFC9kETR7N0uMXZ+LyCbVGMbEb Etb52iySHZQTj+Wtqu7xyxJYNLPysez42/rnf7qiZLkbeROUyL2bDYn7glaIw+EhOEbc aPD90IkGPO1+VTEP+dehEy3PnIP45QZaNcbx4AZML+yp9ZKnQPXeYdl5uzaUMDwz4Km2 gwNw== X-Gm-Message-State: AOAM533jUjE1exR0Ch8h7w8+kqpCNL+agHaVSFvEzZrjnDIBPSuKgdzd /G6etdeHtsFd+IYcTNUb4aNoYh5iRKBpSP2pQlGLvA== X-Received: by 2002:a1c:2b04:: with SMTP id r4mr30503767wmr.48.1634914872995; Fri, 22 Oct 2021 08:01:12 -0700 (PDT) MIME-Version: 1.0 References: <20211022140714.28767-1-jim2101024@gmail.com> <20211022140714.28767-3-jim2101024@gmail.com> In-Reply-To: From: Jim Quinlan Date: Fri, 22 Oct 2021 11:01:01 -0400 Message-ID: Subject: Re: [PATCH v5 2/6] PCI: allow for callback to prepare nascent subdev To: Greg Kroah-Hartman Cc: Jim Quinlan , "open list:PCI NATIVE HOST BRIDGE AND ENDPOINT DRIVERS" , Nicolas Saenz Julienne , Rob Herring , Mark Brown , "maintainer:BROADCOM BCM7XXX ARM ARCHITECTURE" , "Rafael J. Wysocki" , Bjorn Helgaas , Saravana Kannan , Thomas Gleixner , Konrad Rzeszutek Wilk , Rajat Jain , Bhaskar Chowdhury , Claire Chang , Andy Shevchenko , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 22, 2021 at 10:34 AM Greg Kroah-Hartman wrote: > > On Fri, Oct 22, 2021 at 10:06:55AM -0400, Jim Quinlan wrote: > > We would like the Broadcom STB PCIe root complex driver to be able to turn > > off/on regulators[1] that provide power to endpoint[2] devices. Typically, > > the drivers of these endpoint devices are stock Linux drivers that are not > > aware that these regulator(s) exist and must be turned on for the driver to > > be probed. The simple solution of course is to turn these regulators on at > > boot and keep them on. However, this solution does not satisfy at least > > three of our usage modes: > > > > 1. For example, one customer uses multiple PCIe controllers, but wants the > > ability to, by script, turn any or all of them by and their subdevices off > > to save power, e.g. when in battery mode. > > > > 2. Another example is when a watchdog script discovers that an endpoint > > device is in an unresponsive state and would like to unbind, power toggle, > > and re-bind just the PCIe endpoint and controller. > > > > 3. Of course we also want power turned off during suspend mode. However, > > some endpoint devices may be able to "wake" during suspend and we need to > > recognise this case and veto the nominal act of turning off its regulator. > > Such is the case with Wake-on-LAN and Wake-on-WLAN support where PCIe > > end-point device needs to be kept powered on in order to receive network > > packets and wake-up the system. > > > > In all of these cases it is advantageous for the PCIe controller to govern > > the turning off/on the regulators needed by the endpoint device. The first > > two cases can be done by simply unbinding and binding the PCIe controller, > > if the controller has control of these regulators. > > > > This commit solves the "chicken-and-egg" problem by providing a callback to > > the RC driver when a downstream device is "discovered" by inspecting its > > DT, and allowing said driver to allocate the device object prematurely in > > order to get the regulator(s) and turn them on before the device's ID is > > read. > > > > [1] These regulators typically govern the actual power supply to the > > endpoint chip. Sometimes they may be a the official PCIe socket > > power -- such as 3.3v or aux-3.3v. Sometimes they are truly > > the regulator(s) that supply power to the EP chip. > > > > [2] The 99% configuration of our boards is a single endpoint device > > attached to the PCIe controller. I use the term endpoint but it could > > possible mean a switch as well. > > > > Signed-off-by: Jim Quinlan > > --- > > drivers/base/core.c | 5 +++++ > > drivers/pci/probe.c | 47 ++++++++++++++++++++++++++++++++---------- > > include/linux/device.h | 3 +++ > > include/linux/pci.h | 3 +++ > > 4 files changed, 47 insertions(+), 11 deletions(-) > > > > diff --git a/drivers/base/core.c b/drivers/base/core.c > > index 249da496581a..62d9ac123ae5 100644 > > --- a/drivers/base/core.c > > +++ b/drivers/base/core.c > > @@ -2864,6 +2864,10 @@ static void klist_children_put(struct klist_node *n) > > */ > > void device_initialize(struct device *dev) > > { > > + /* Return if this has been called already. */ > > + if (dev->device_initialized) > > + return; > > + > > Ick, no! Who would ever be calling this function more than once? That > "should" be impossible. > > This function should only be called by a bus when it first creates the > structure and before anything is done with it. As the bus itself > controls the creation, it already "knows" when the structure was > initialzed so it should not have to be called again. > > Please fix the bus logic that requires this, it is broken. Got it, thanks for the prompt reply. JimQ > > Consider this a NACK for this patch, sorry. > > greg k-h