Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp582673pxu; Thu, 26 Nov 2020 06:21:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJwvPOqWa27EanpgtkOvtDTONWFc1ha3Xgu7vi666rXQg03vW+XgmRWT3RcvcBhCOyhpw/qi X-Received: by 2002:a17:906:1498:: with SMTP id x24mr461266ejc.170.1606400499391; Thu, 26 Nov 2020 06:21:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606400499; cv=none; d=google.com; s=arc-20160816; b=PGknHhi0j0Qe9S01NkT4Y286/LXTUPDqbvX3oyS3JX0woWWrNETUd4gW7hFED6MIlh e17G4lj8rY3Xlt5/QsdxoOEdEikXruLalDsMZhnlA1TEGmThj3JtrwbCeDL5+s2g5P5E gJVeQwBFzHBXNbUyDbpcuTOkSx7CeS+jBtA5oLP+rFxDCIviVcZE6z+osAjombvdXOna gAHCphQ2MC35BfvnqdmsdreL4V4lqZKzhgASIrnU4GIi1+nFQvjqiDJLnbGloN62X7wE 6iB/nQXQomS4Q00sryo1xGXbL6T+Fq7UOozW/BHdNx5IJ2UPQWFmm73cxzkGIhqdqy8F hsGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=MiNfyVP7coTAoGepwYY+mWXuyRbuXfN1JF+BE2kB4gk=; b=FH1Mqj5TJCyV7Zyu2Hvffta6aIa77MNJhQcKQv8C9tpr/bjsEVN85r9tFv3VORSB7N WSj/H7okMSiMceECKAuZWzLgGPDP0UZZhminV5lQoyRTxcVbB9qOBVaRrsuWF5DZz1q1 /QxDGOAN203Y116FYnQiSDBmsaN6J4Im+3KcmK8In8I/a8quyZIsxmu6G2ifzdLekbiP YgpAltUm1HXEy9m6yDUKxK+gfTjenc4dEklahsYxtsVymnMeEJz83QwfOnVh5BugYC5r 7DhvG4V9hjFlmKffDuuLvcI/h6mS3w/DOSG9/VIY9Zqo1taWLo8eN0Y0tzmczhZM80GV 9X5w== ARC-Authentication-Results: i=1; mx.google.com; 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 d2si3784973ejm.675.2020.11.26.06.21.15; Thu, 26 Nov 2020 06:21:39 -0800 (PST) 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; 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 S2390912AbgKZOTm convert rfc822-to-8bit (ORCPT + 99 others); Thu, 26 Nov 2020 09:19:42 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:45131 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390022AbgKZOTm (ORCPT ); Thu, 26 Nov 2020 09:19:42 -0500 Received: by mail-ot1-f65.google.com with SMTP id k3so1967449otp.12; Thu, 26 Nov 2020 06:19:40 -0800 (PST) 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:content-transfer-encoding; bh=GwppLtz9RbhQVBUuzUzdKLtehGW1M1Jg+Up1fL9r49Q=; b=JGjbv1SvOWoSeGXIbMYRwBmgytqlFk9VSQw0tlrdNVV0/M1DiRVU+RYKNPu6eGJu22 aZPdYohR/E//CoG4j9C+BGnbW3R9YUdm8AQ+P53CtpYcpJezCX/EaQsusYs3p3jF4i2B U1GzOzCeMdcNJASv7VMAQSOunQ6902vpWPWf6bIyPn1iBTp+97EhaRJ9T0E5QooLG9nk m5FZFBm3sOz7EPqeTSIPhrJNVGtliqVRx1eEll3hK1idPR/IbGBb8AqlGRNUzW7PchuY AJoUg1puFL21OrIopVBriaIeySEzlzw3fyHWnVulTkJajP+dSJDg0j6MjFQ+hBq7aPo2 j55Q== X-Gm-Message-State: AOAM530F7+ADQFwtSacRhFDQwNd9ognybu21c2Jtm9VgHP4Q55i4F2MZ DhQv8AoOR5FZlmF2dnqD0N36AY+rMTNmCse5qLw= X-Received: by 2002:a05:6830:2385:: with SMTP id l5mr2425799ots.321.1606400379939; Thu, 26 Nov 2020 06:19:39 -0800 (PST) MIME-Version: 1.0 References: <20201124060202.776-1-ricky_wu@realtek.com> <20201124204915.GA585306@bjorn-Precision-5520> <6f721ea4d5a84f45b0249b932d742367@realtek.com> In-Reply-To: <6f721ea4d5a84f45b0249b932d742367@realtek.com> From: "Rafael J. Wysocki" Date: Thu, 26 Nov 2020 15:19:26 +0100 Message-ID: Subject: Re: [PATCH] misc: rtsx: rts5249 support runtime PM To: =?UTF-8?B?5ZCz5piK5r6EIFJpY2t5?= Cc: "Rafael J. Wysocki" , Bjorn Helgaas , Arnd Bergmann , Greg Kroah-Hartman , Ulf Hansson , Bjorn Helgaas , "vaibhavgupta40@gmail.com" , "kdlnx@doth.eu" , Doug Anderson , "rmfrfs@gmail.com" , Lee Jones , Linux Kernel Mailing List , linux-mmc , "Rafael J. Wysocki" , Linux PM Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 26, 2020 at 4:07 AM 吳昊澄 Ricky wrote: > > > -----Original Message----- > > From: Rafael J. Wysocki [mailto:rafael@kernel.org] > > Sent: Wednesday, November 25, 2020 10:04 PM > > To: Bjorn Helgaas; 吳昊澄 Ricky [cut] > > > > +static void rtsx_pci_rtd3_work(struct work_struct *work) > > > > +{ > > > > + struct delayed_work *dwork = to_delayed_work(work); > > > > + struct rtsx_pcr *pcr = container_of(dwork, struct rtsx_pcr, > > rtd3_work); > > > > + > > > > + pcr_dbg(pcr, "--> %s\n", __func__); > > > > + > > > > + while (pcr->pci->dev.power.usage_count.counter > 0) { > > > > + if (pm_runtime_active(&(pcr->pci->dev))) > > > > + pm_runtime_put(&(pcr->pci->dev)); > > > > > > I'm not a runtime PM expert, but this looks fishy. AFAICT this is the > > > only driver in the tree that uses usage_count.counter this way, which > > > is a pretty big hint that this needs a closer look. Cc'd Rafael. > > > > You are right, this is not correct from the PM-runtime POV. > > > > It looks like this attempts to force the PM-runtime usage counter down > > to 0 and it's kind of hard to say why this is done (and it shouldn't > > be done in the first place, because it destroys the usage counter > > balance). > > > > Ricky, is this an attempt to work around an issue of some sort? > > > > Thanks Bjorn and Rafael > I found when we boot up, our dev pcr->pci->dev.power.usage_count.counter always is 2, > Don’t know how to make it to 0 because we need to support D3 and run runtime_suspended callback function > Is there something wrong with us to enable runtime PM? That is possible. If you want it to be enabled by default, you need to call pm_runtime_allow() from the driver at probe time, in addition to pm_runtime_enable(), in the first place, but that only drops one reference, so question is where the other one comes from. Are the pm_runtime_get*() and pm_runtime_put*() calls balanced?