Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp604862pxk; Wed, 16 Sep 2020 12:01:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4QIn5MCp6DuVGc7fjYUnwxi1g/p+PAeKqFDZEpDjqo/BMIG07RMs+NwAYBUAhxZ4PRWUL X-Received: by 2002:a17:906:ae45:: with SMTP id lf5mr26215302ejb.339.1600282883111; Wed, 16 Sep 2020 12:01:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600282883; cv=none; d=google.com; s=arc-20160816; b=BeohVoMCslU+kLKM34gvMXeAZa1OgkklEt2QcTmqiYh79Nh9/BBw4TSTe/e0ubp2jw 8kFeT7NvMe6FwNQhHo7zU4oDXztiHm5P5LMYpDxeO6LopbqisJvK3woc8uT1IEqHkn9E TtPNlaATv4OMYzTdThqqDjXT7JWUBx/PfBDriU1GfhROTMnzqDHmyL33VdhyOVvh7P9H HwabFax5D1Nmua4UYK+0u4vu3ewXZ1K/VLVP7ROP5FYplCy8/96bGc+Z7kgvuf8/kexH b6ErMlrF9iLH7ttbLqD20cVG7//ludhqiBVZfJ3gnZZCWXbf4BblQYTel4GGqF8RHJh1 3S8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:message-id:subject:cc:to:from:date :dkim-signature; bh=Vj4UdEDTbARKdxT7nPJFQpHdeb2oMmdsjrEq2LYAxxM=; b=hHH1nHwUhvAXHOLWqtQMU2MNUzKS+CoGhVZ4vULhQ70tb8eHIzZR+rMrRiOr0kYnKn W8qXQGArdS02/ANW5jJp3slLU8ismD1On7TgMOS5ycl9fwNz5q0ljsxZtIEa7PyJLTNH Q+/LQJH/ywF7DGVPG5qWoHNeQOWw8N0kElZSYhAvVibjxbHVwUibAVibTN//LrXQ0MCG cvHlNOR6lBvq5PQGiVWHYarM8b+ISpT47gtO4+1Gox6Q/FveS2yu+ycjcy3qX5Sx4SNi J4p1vLbrw8hP65EtQJJrqsXK2uRMyerThZo4mzzOcA2Q/B5vppjfYmfGP5ygS46ABtv4 CXnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z48pIJfc; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u13si12733758ejt.286.2020.09.16.12.01.00; Wed, 16 Sep 2020 12:01:23 -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=@kernel.org header.s=default header.b=z48pIJfc; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728231AbgIPS6d (ORCPT + 99 others); Wed, 16 Sep 2020 14:58:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:42628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726510AbgIPRv5 (ORCPT ); Wed, 16 Sep 2020 13:51:57 -0400 Received: from localhost (52.sub-72-107-123.myvzw.com [72.107.123.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 020BB2226B; Wed, 16 Sep 2020 13:32:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600263148; bh=P5+9y5YPJYqYEjECRpUtjvOQwwt4I7Fj+UkwXLuICGs=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=z48pIJfclM+hfht+C1CKW+UEw+JO92g5uVFvv4dS/YfhkEkydYr8dV3kkNpAWepJy +nZX5lrIZfTZcK9QOfih5PT633yj/8sHug0694+ni4j1OuoCw2dWJln+Yeoq7b8S/r 2szLTr2GHiSV4RKdGPew7PxCuTeTpgsw90pmzbLY= Date: Wed, 16 Sep 2020 08:32:26 -0500 From: Bjorn Helgaas To: "gregkh@linuxfoundation.org" Cc: =?utf-8?B?5ZCz5piK5r6E?= Ricky , "arnd@arndb.de" , "bhelgaas@google.com" , "ulf.hansson@linaro.org" , "rui_feng@realsil.com.cn" , "linux-kernel@vger.kernel.org" , "puranjay12@gmail.com" , "linux-pci@vger.kernel.org" , "vailbhavgupta40@gmail.com" Subject: Re: [PATCH v5 2/2] misc: rtsx: Add power saving functions and fix driving parameter Message-ID: <20200916133226.GA1535437@bjorn-Precision-5520> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200916123020.GA2796266@kroah.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 16, 2020 at 02:30:20PM +0200, gregkh@linuxfoundation.org wrote: > On Tue, Sep 15, 2020 at 10:28:11AM -0500, Bjorn Helgaas wrote: > > On Tue, Sep 15, 2020 at 08:24:50AM +0000, 吳昊澄 Ricky wrote: > > > > -----Original Message----- > > > > From: Bjorn Helgaas [mailto:helgaas@kernel.org] > > > > Sent: Friday, September 11, 2020 10:56 PM > > > > To: 吳昊澄 Ricky > > > > Cc: arnd@arndb.de; gregkh@linuxfoundation.org; bhelgaas@google.com; > > > > ulf.hansson@linaro.org; rui_feng@realsil.com.cn; linux-kernel@vger.kernel.org; > > > > puranjay12@gmail.com; linux-pci@vger.kernel.org; > > > > vailbhavgupta40@gamail.com > > > > Subject: Re: [PATCH v5 2/2] misc: rtsx: Add power saving functions and fix driving > > > > parameter > > > > > > > > On Fri, Sep 11, 2020 at 08:18:22AM +0000, 吳昊澄 Ricky wrote: > > > > > > -----Original Message----- > > > > > > From: Bjorn Helgaas [mailto:helgaas@kernel.org] > > > > > > Sent: Thursday, September 10, 2020 1:44 AM > > > > > > To: 吳昊澄 Ricky > > > > > > Cc: arnd@arndb.de; gregkh@linuxfoundation.org; bhelgaas@google.com; > > > > > > ulf.hansson@linaro.org; rui_feng@realsil.com.cn; > > > > linux-kernel@vger.kernel.org; > > > > > > puranjay12@gmail.com; linux-pci@vger.kernel.org; > > > > > > vailbhavgupta40@gamail.com > > > > > > Subject: Re: [PATCH v5 2/2] misc: rtsx: Add power saving functions and fix > > > > driving > > > > > > parameter > > > > > > > > > > > > On Wed, Sep 09, 2020 at 07:10:19AM +0000, 吳昊澄 Ricky wrote: > > > > > > > > -----Original Message----- > > > > > > > > From: Bjorn Helgaas [mailto:helgaas@kernel.org] > > > > > > > > Sent: Wednesday, September 09, 2020 6:29 AM > > > > > > > > To: 吳昊澄 Ricky > > > > > > > > Cc: arnd@arndb.de; gregkh@linuxfoundation.org; > > > > bhelgaas@google.com; > > > > > > > > ulf.hansson@linaro.org; rui_feng@realsil.com.cn; > > > > > > linux-kernel@vger.kernel.org; > > > > > > > > puranjay12@gmail.com; linux-pci@vger.kernel.org; > > > > > > > > vailbhavgupta40@gamail.com > > > > > > > > Subject: Re: [PATCH v5 2/2] misc: rtsx: Add power saving functions and fix > > > > > > driving > > > > > > > > parameter > > > > > > > > > > > > > > > > On Mon, Sep 07, 2020 at 06:07:31PM +0800, ricky_wu@realtek.com > > > > wrote: > > > > > > > > > From: Ricky Wu > > > > > > > > > > > > > > > > > > v4: > > > > > > > > > split power down flow and power saving function to two patch > > > > > > > > > > > > > > > > > > v5: > > > > > > > > > fix up modified change under the --- line > > > > > > > > > > > > > > > > Hehe, this came out *above* the "---" line :) > > > > > > > > > > > > > > > > > Add rts522a L1 sub-state support > > > > > > > > > Save more power on rts5227 rts5249 rts525a rts5260 > > > > > > > > > Fix rts5260 driving parameter > > > > > > > > > > > > > > > > > > Signed-off-by: Ricky Wu > > > > > > > > > --- > > > > > > > > > drivers/misc/cardreader/rts5227.c | 112 +++++++++++++++++++++- > > > > > > > > > drivers/misc/cardreader/rts5249.c | 145 > > > > > > > > ++++++++++++++++++++++++++++- > > > > > > > > > drivers/misc/cardreader/rts5260.c | 28 +++--- > > > > > > > > > drivers/misc/cardreader/rtsx_pcr.h | 17 ++++ > > > > > > > > > 4 files changed, 283 insertions(+), 19 deletions(-) > > > > > > > > > > > > > > > > > > diff --git a/drivers/misc/cardreader/rts5227.c > > > > > > > > b/drivers/misc/cardreader/rts5227.c > > > > > > > > > index 747391e3fb5d..8859011672cb 100644 > > > > > > > > > --- a/drivers/misc/cardreader/rts5227.c > > > > > > > > > +++ b/drivers/misc/cardreader/rts5227.c > > > > > > > > > @@ -72,15 +72,80 @@ static void > > > > rts5227_fetch_vendor_settings(struct > > > > > > > > rtsx_pcr *pcr) > > > > > > > > > > > > > > > > > > pci_read_config_dword(pdev, PCR_SETTING_REG2, ®); > > > > > > > > > pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG2, reg); > > > > > > > > > + if (rtsx_check_mmc_support(reg)) > > > > > > > > > + pcr->extra_caps |= EXTRA_CAPS_NO_MMC; > > > > > > > > > pcr->sd30_drive_sel_3v3 = rtsx_reg_to_sd30_drive_sel_3v3(reg); > > > > > > > > > if (rtsx_reg_check_reverse_socket(reg)) > > > > > > > > > pcr->flags |= PCR_REVERSE_SOCKET; > > > > > > > > > } > > > > > > > > > > > > > > > > > > +static void rts5227_init_from_cfg(struct rtsx_pcr *pcr) > > > > > > > > > +{ > > > > > > > > > + struct pci_dev *pdev = pcr->pci; > > > > > > > > > + int l1ss; > > > > > > > > > + u32 lval; > > > > > > > > > + struct rtsx_cr_option *option = &pcr->option; > > > > > > > > > + > > > > > > > > > + l1ss = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_L1SS); > > > > > > > > > + if (!l1ss) > > > > > > > > > + return; > > > > > > > > > + > > > > > > > > > + pci_read_config_dword(pdev, l1ss + PCI_L1SS_CTL1, &lval); > > > > > > > > > > > > > > > > This looks a little problematic. PCI_L1SS_CTL1 is an architected > > > > > > > > register in the ASPM L1 PM Substates capability, and its value may > > > > > > > > change at runtime because drivers/pci/pcie/aspm.c manages it. > > > > > > > > > > > > > > > > It looks like the code below does device-specific configuration based > > > > > > > > on the current PCI_L1SS_CTL1 value. But what happens if aspm.c > > > > > > > > changes PCI_L1SS_CTL1 later? > > > > > > > > > > > > > > We are going to make sure and set the best configuration on the > > > > > > > current time, if host change the capability later, it doesn't affect > > > > > > > function, only affect a little power saving > > > > > > > > > > > > Why don't you unconditionally do the following? > > > > > > > > > > > > rtsx_set_dev_flag(pcr, ASPM_L1_1_EN); > > > > > > rtsx_set_dev_flag(pcr, ASPM_L1_2_EN); > > > > > > rtsx_set_dev_flag(pcr, PM_L1_1_EN); > > > > > > rtsx_set_dev_flag(pcr, PM_L1_2_EN); > > > > > > > > > > Our power saving function have 2 different flow L1 and L1substate, > > > > > so we need to check it for which flow we are going to > > > > > Detail to see below reply > > > > > > > > > > > Let's assume the generic code in aspm.c has cleared all these bits: > > > > > > > > > > > > PCI_L1SS_CTL1_ASPM_L1_1 > > > > > > PCI_L1SS_CTL1_ASPM_L1_2 > > > > > > PCI_L1SS_CTL1_PCIPM_L1_1 > > > > > > PCI_L1SS_CTL1_PCIPM_L1_2 > > > > > > > > > > > > in the L1 PM Substates capability. > > > > > > > > > > > > I think you are saying that if you *also* clear ASPM_L1_1_EN, > > > > > > ASPM_L1_2_EN, PM_L1_1_EN, and PM_L1_2_EN in your device-specific > > > > > > registers, it uses less power than if you set those device-specific > > > > > > bits. Right? > > > > > > > > > > > > And moreover, I think you're saying that if aspm.c subsequently *sets* > > > > > > some of those bits in the L1 PM Substates capability, those substates > > > > > > *work* even though the device-specific ASPM_L1_1_EN, ASPM_L1_2_EN, > > > > > > PM_L1_1_EN, and PM_L1_2_EN bits are not set. Right? > > > > > > > > > > > > I do not feel good about this as a general strategy. I think we > > > > > > should program the device so the behavior is completely predictable, > > > > > > regardless of the generic enable bits happened to be set at > > > > > > probe-time. > > > > > > > > > > > > The current approach means that if we enable L1 substates after the > > > > > > driver probe, the device is configured differently than if we enabled > > > > > > L1 substates before probe. That's not a reliable way to operate it. > > > > > > > > > > Talk about our power saving function > > > > > a) basic L1 power saving > > > > > b) advance L1 power saving > > > > > c) advance L1 substate power saving > > > > > > > > I have no idea what the difference between "basic L1 power saving" and > > > > "advance L1 power saving" is, so I assume those are device-specific > > > > things. If not, please use the same terminology as the PCIe spec. > > > > > > > > > at initial, we check pci port support L1 subs or not, if not we are > > > > > going to b) otherwise going to c). > > > > > > > > You're not checking whether the port *supports* L1 substates. You > > > > would look at PCI_L1SS_CAP to learn that. You're looking at > > > > PCI_L1SS_CTL1, which tells you whether L1 substates are *enabled*. > > > > > > > > > Assume aspm.c change bit of L1 PM Substates capability after our > > > > > driver probe, we are going to a) > > > > > > > > > > So far we did not see any platform change L1 PM Substates capability > > > > > after our driver probe. > > > > > > > > You should expect that aspm.c will change bits in the L1 PM *control* > > > > register (PCI_L1SS_CTL1) after probe. > > > > > > > > You might not actually see it change, depending on how you tested, but > > > > you cannot rely on PCI_L1SS_CTL1 being constant. It may change based > > > > on power/performance tradeoffs, e.g., whether the system is plugged > > > > into AC power, whether it's idle, etc. > > > > > > > > > > Our ASPM function is a HW solution follow the PCIe SPEC. don’t worry > > > about crash the system If HOST change our device config space > > > setting at run time our HW will do the corresponding things which > > > follows the SPEC. At initial time we set these parameter just good > > > for more power saving > > > > OK. It would be better if your hardware would notice the > > PCI_L1SS_CTL1 change and set its own device-specific power-saving > > parameters. The drivers would be simpler, and the device behavior > > would be more consistent. > > > > Drivers *writing* to standard PCI config things (64-byte config header > > or Capabilities like PCIe, PM, ASPM, L1 Substates) is a definite > > problem because the PCI core owns those and writes from drivers need > > to be mediated somehow. AFAICT your drivers don't write to these > > things. > > > > Drivers *reading* these things (as your drivers do) shouldn't cause > > problems, but it does violate the interface abstractions that the PCI > > core should provide. > > So is it ok to take this patch now, or does it need to be changed any? Yes, it's OK with me if you take this patch. The ASPM hardware feature is designed to work without any driver support. It does need to be configured, which involves both the device and the upstream bridge, so it should be done by the BIOS or the PCI core. There are a few drivers (amdgpu, radeon, hfi1, e1000e, iwlegacy, ath10k, ath9k, mt76, rtlwifi, rtw88, and these rts cardreader drivers) that do it themselves, incorrectly. But this particular patch only *reads* the ASPM control registers, without writing them, so it shouldn't make anything worse. Bjorn