Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp403417imm; Thu, 30 Aug 2018 01:37:47 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbBZIoVRF4D2AocJxNovJdC6yPL9QAppMn1j3CEVRVsNFCghw+QdpPfTj92UYSumCicmO0c X-Received: by 2002:a63:6d4f:: with SMTP id i76-v6mr8786740pgc.215.1535618267634; Thu, 30 Aug 2018 01:37:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535618267; cv=none; d=google.com; s=arc-20160816; b=wxNoBt6Adv4B5Q/mHD7SYG/k/CenBDNMeDZBweHLOllOOnDs+h/4dYszR8fklYShzm bNK2avqeDOhI0lZofgQebYWZt4NUAxhlL1ZCIF7rGDnWV/hE6yq76daXXpVKjG8/Ik7+ wq5HcvV/zweGprQTDCAC3Zk1ZHl2iqfyPmTmq0TyYlkfGjs3XC3pC5i4v0FEYV/512ZL gEUYTSqN0BPxrRmCmFoZ9cv1tMbZ6rQOkfJhPePVIBqfJqmdbzDhwIAKbkq93DEzycsw Pk+piEqHJSUjPPCUcDZQx8KOIC4c0XxsS4DCX9rGWJkM+fSF/pXduQY8+A2wbhGG++uO rK4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:arc-authentication-results; bh=3aE21avEOVo0rb89/e5y4ptR+DKkFzWD27rSXvaREKg=; b=Oo/8ayf/X0NaTeqbGVwblB23l9LTDjvVq3R+8+Sw6gOJF8CLgRvBO7Tnirucmg2lVd ROUKp502K/3Ilkex+rxUAJkNoOphBfLf4uX1hMtehAQHg0PUTGqQJPSR07+liua7oyNu Z6BXfjyMtN71jqaHAO66fwDd4l7/k/hOAVy+efX6IgD+cpll9Aw7nK5LcgEgYN6xvBF1 Ak2JcumLxI8JeP9w9dU8MfDhFfGP/DGl6ROaNPAyb86hb8b0u759/reOq8EfNOtAG/je TPWKga4UkVEhf6esrWkAWKw9M5Z+TmJTDDy1IVubsLmNjSCk9MB0VObl/rUjidCLZo4Q DKaA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ce1-v6si6984609plb.391.2018.08.30.01.37.29; Thu, 30 Aug 2018 01:37:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728075AbeH3Mh1 (ORCPT + 99 others); Thu, 30 Aug 2018 08:37:27 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:32934 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727688AbeH3Mh1 (ORCPT ); Thu, 30 Aug 2018 08:37:27 -0400 Received: from mail-pf1-f200.google.com ([209.85.210.200]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1fvIRC-0003cE-To for linux-kernel@vger.kernel.org; Thu, 30 Aug 2018 08:36:23 +0000 Received: by mail-pf1-f200.google.com with SMTP id q21-v6so4371019pff.21 for ; Thu, 30 Aug 2018 01:36:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=3aE21avEOVo0rb89/e5y4ptR+DKkFzWD27rSXvaREKg=; b=UksGQQ0czaQK2ul6q1hwdtu5N1VRW4Dw614w4uOefR7ydB6/AhGl2Ae+sUSCeB2q5T PyzEsjmq2pzBhGOTqnQMAtmu+XdgNnN+cwSiaqV8SJ5y4j0RT1JJDUKzBrd/+p4XM292 dt64DhZQeqyb/gfyf35sXKZuq2yzHeIM0FHbGchZnFpgCbuNCMjjcqZ8tQiK/aZjgHnK lKGj3EC1NE4Y4nFfrghVIkWi9rSUG9HYOMRuFP9rg9WwQqVFElkC+fhMeVBegAKCksxk 5hLAjgy80qCR0PwLflPFcXPYsedeBRqSd7Xou3C4NOvNeWheDuhnnpVoEU18bYJ1vyUr p2wA== X-Gm-Message-State: APzg51DA9ZI4AZ/vJaIdKAFQHshhXPRgjw+GXYMZCjz9Pj84OfQ5EZ3X Xztpuaktu9sFWm/9YsakF9aaoUuQhbvvVfcgCQez7zWJqHJWT1PF6iCwANVAEwukC99dsfN4kUg rWnEfYNQQQDDtnPN5A1/5r4Etq8Qx6y2csif7PJKqHg== X-Received: by 2002:a17:902:8f8c:: with SMTP id z12-v6mr9235395plo.4.1535618181622; Thu, 30 Aug 2018 01:36:21 -0700 (PDT) X-Received: by 2002:a17:902:8f8c:: with SMTP id z12-v6mr9235374plo.4.1535618181326; Thu, 30 Aug 2018 01:36:21 -0700 (PDT) Received: from [192.168.1.206] (220-133-187-190.HINET-IP.hinet.net. [220.133.187.190]) by smtp.gmail.com with ESMTPSA id v7-v6sm10026401pgh.57.2018.08.30.01.36.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 01:36:20 -0700 (PDT) Content-Type: text/plain; charset=us-ascii; delsp=yes; format=flowed Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: Re: [PATCH 4/5] memstick: rtsx_usb_ms: Support runtime power management From: Kai-Heng Feng In-Reply-To: Date: Thu, 30 Aug 2018 16:36:16 +0800 Cc: Arnd Bergmann , Greg Kroah-Hartman , Alan Stern , "Bauer.Chen" , ricky_wu@realtek.com, Linux Kernel Mailing List , Linux USB List Content-Transfer-Encoding: 7bit Message-Id: <3F123073-8A73-4E4C-B4A6-9777022D9927@canonical.com> References: <20180731061721.15831-1-kai.heng.feng@canonical.com> <20180731061721.15831-5-kai.heng.feng@canonical.com> To: Ulf Hansson X-Mailer: Apple Mail (2.3445.9.1) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org at 14:28, Ulf Hansson wrote: > On 23 August 2018 at 10:03, Kai-Heng Feng > wrote: >> Hi Ulf, >> >> Sorry for the late reply. >> >> >> at 21:14, Ulf Hansson wrote: >> >>> On 31 July 2018 at 08:17, Kai-Heng Feng >>> wrote: >>>> In order to let host's parent device, rtsx_usb, to use USB remote wake >>>> up signaling to do card detection, it needs to be suspended. Hence it's >>>> necessary to add runtime PM support for the memstick host. >>>> >>>> To keep memstick host stays suspended when it's not in use, convert the >>>> card detection function from kthread to delayed_work, which can be >>>> scheduled when the host is resumed and can be canceled when the host is >>>> suspended. >>>> >>>> Use an idle function check if there's no card and the power mode is >>>> MEMSTICK_POWER_OFF. If both criteria are met, put the device to suspend. >>>> >>>> Signed-off-by: Kai-Heng Feng >>>> --- >>>> drivers/memstick/host/rtsx_usb_ms.c | 138 ++++++++++++++-------------- >>>> 1 file changed, 71 insertions(+), 67 deletions(-) >>>> >>>> diff --git a/drivers/memstick/host/rtsx_usb_ms.c >>>> b/drivers/memstick/host/rtsx_usb_ms.c >>>> index cd12f3d1c088..126eb310980a 100644 >>>> --- a/drivers/memstick/host/rtsx_usb_ms.c >>>> +++ b/drivers/memstick/host/rtsx_usb_ms.c >>>> @@ -40,15 +40,14 @@ struct rtsx_usb_ms { >>>> >>>> struct mutex host_mutex; >>>> struct work_struct handle_req; >>>> - >>>> - struct task_struct *detect_ms; >>>> - struct completion detect_ms_exit; >>>> + struct delayed_work poll_card; >>>> >>>> u8 ssc_depth; >>>> unsigned int clock; >>>> int power_mode; >>>> unsigned char ifmode; >>>> bool eject; >>>> + bool suspend; >>>> }; >>>> >>>> static inline struct device *ms_dev(struct rtsx_usb_ms *host) >>>> @@ -524,7 +523,7 @@ static void rtsx_usb_ms_handle_req(struct >>>> work_struct >>>> *work) >>>> int rc; >>>> >>>> if (!host->req) { >>>> - pm_runtime_get_sync(ms_dev(host)); >>>> + pm_runtime_get_noresume(ms_dev(host)); >>> >>> >>> I don't think this is safe. >>> >>> The memstick core doesn't manage runtime PM, hence there are no >>> guarantee that the device is runtime resumed at this point, or is >>> there? >> >> >> No guarantees there. >> Right now this only gets call when the host is powered on. >> >>>> do { >>>> rc = memstick_next_req(msh, &host->req); >>>> dev_dbg(ms_dev(host), "next req %d\n", rc); >>>> @@ -545,7 +544,7 @@ static void rtsx_usb_ms_handle_req(struct >>>> work_struct >>>> *work) >>>> host->req->error); >>>> } >>>> } while (!rc); >>>> - pm_runtime_put(ms_dev(host)); >>>> + pm_runtime_put_noidle(ms_dev(host)); >>> >>> >>> According to the above, I think this should stay as is. Or perhaps you >>> want to use pm_runtime_put_sync() instead, as to avoid the device from >>> being unnecessary resumed and hence also its parent. >> >> >> The tricky part is that pm_runtime_put_sync() calls >> rtsx_usb_ms_set_param() >> which calls pm_runtime_* helpers again > > Why does a pm_runtime_put_sync() triggers a call to > rtsx_usb_ms_set_param()? It should not. > > Ahh, that's because you have implemented the ->runtime_suspend() > callback to wrongly call memstick_suspend_host(). Drop that change, > then you should be able to call pm_runtime_put_sync() here and at > other places correctly. Thanks for the catch! I'll address that. > >> So maybe add runtime PM support to memstick core is the only way to >> support >> it properly? > > It shouldn't be needed, and I wonder about if the effort is worth it, > especially since it seems that the only memstick driver that using > runtime PM is rtsx_usb_ms. > > BTW, are you testing this change by using a memstick card, since I > haven't seen them for ages. :-) Yes, Realtek borrowed me a MMC/MS combo device to let me work on this. Kai-Heng > > [...] > > Kind regards > Uffe