Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2484790imm; Thu, 23 Aug 2018 23:29:36 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZaxCcJCb4QmsrC0E3eEMqd9FVF3okHbXQ7hr+AyHauJVBSYxxjXHLI3FBNqyxbd91IckEk X-Received: by 2002:a17:902:3324:: with SMTP id a33-v6mr310747plc.221.1535092176146; Thu, 23 Aug 2018 23:29:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535092176; cv=none; d=google.com; s=arc-20160816; b=L8OuJd9sWJHc6/a0WHntWdngzYuPsuUaYHTUZzngLaI+O4oGQaKHkr31CjEsEmmdu4 yEKj2poKKZ6Z4cCfgkF4L5XujtmKqRt4V9jfX3f/NtZiuZX0yuBtiwGPftUbDKr5InvA dl1UIo6v+8rD71u3ZLAX66FXYgQYJHPf6r4Go4LS6XWeWrT4cr8nszDss8Lgo/E1tnTa imKjTfw3YZkKU833QHV/kqiYJWWr9vwFFw6sgkm8C0cw9s3I5LZ5v03i5hGSSghsru0M dZoytZbnw0SFgj5OVvZdWTLEc3cIuYuHWENUZrwbQusEvL2xNf02gQxCZLu/P6OusOIq ryeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=W8ijDITyOtqKv6E4f3ebHKT/0a/MA/1Zilrht7nVXMI=; b=rTkv+csi9sWYfTJj3KPRcuVF0TDFvsJgZSntarJ/4VL3/q6rezS2uk1LVjRQ6zbXKb YcmCRl5qVJ+SxR2Cn8WD9oWe7oVroMWZ07OOqnHHuOK/CoDRbCd+uFfANEQ0KXS1zEHa 7usxiqrlZae15or9szWjugGncGr5L+yjewmfJBsGUk5TXx62WAc0Gc7ZiTmjoXVQD08D hR6/e6cIYJKBi6gTWqkKIs7oO8XDroEFuUY4mwdB84C+AqdCo0LWa1yD91rWWG5/YcrR 0C5Bsm60BvdIE/w8duQ73gST44jp0zShlmU58EMY1NP7gHblRaScZ/e3Wy1DJTaP55k3 esuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KGyKDbvn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p67-v6si6899909pfg.295.2018.08.23.23.29.18; Thu, 23 Aug 2018 23:29:36 -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; dkim=pass header.i=@linaro.org header.s=google header.b=KGyKDbvn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727134AbeHXKBS (ORCPT + 99 others); Fri, 24 Aug 2018 06:01:18 -0400 Received: from mail-it0-f67.google.com ([209.85.214.67]:32909 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726393AbeHXKBR (ORCPT ); Fri, 24 Aug 2018 06:01:17 -0400 Received: by mail-it0-f67.google.com with SMTP id j198-v6so3955332ita.0 for ; Thu, 23 Aug 2018 23:28:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=W8ijDITyOtqKv6E4f3ebHKT/0a/MA/1Zilrht7nVXMI=; b=KGyKDbvn5BDPeMlxrFf5dYbBmejqD253nPKcOwa0qEv7h3hfGBxdBHB9nJVkjprwE6 LR5uyaYJymIHGqiinxhwiBr+1LYQXLw8ZBc4MWJO9pvqTUe0lPcdqQPBu5ehEksmbaEF vifl3MK1U0mzf5Gxq/L771Of9ZXqyzEoPlIY0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=W8ijDITyOtqKv6E4f3ebHKT/0a/MA/1Zilrht7nVXMI=; b=gOgATkJ6RH6nIYXnLMNV0TETGLZ6oKXe7A6cxDBIF2oN8sdLta5VHcNpYp3UT07Gdh vG0Pdj1dOnzKhQEe6arvsZjJgCyqlxvXPgxY/ngSSBdNfOtSs81hPR2i2FPj7bXt/l1e pOYOqJ9axwgUJv1s3x3db9ljDUeQfzT4dlLV7+ftSOTO8jSuvgNu1fGZOJRehbuwZw0V 1ONIscvhd6zt6/mZ7TDIfcDssQwDh1YEYDr4GCO3pDgo28GoRrPGIRSiRAtXvcpnoyJV FhutpQZ43z26+LtV26ytmmtdOKOuSfH00iobHAId5RIL+KgDg9hdsZLD7RfL9Oq/Tk1Y FRFA== X-Gm-Message-State: APzg51DhG4dNlcXsU1IaY7r5pMiyknR04Q5tB7CkdBEKLkzAJ9YI3WCv g1uk/pN/QUhWTWEotP9XcvjajXuyL0jgbS/2P0qJE2VQ2HM= X-Received: by 2002:a24:3fc6:: with SMTP id d189-v6mr414707ita.64.1535092087141; Thu, 23 Aug 2018 23:28:07 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:2b03:0:0:0:0:0 with HTTP; Thu, 23 Aug 2018 23:28:06 -0700 (PDT) In-Reply-To: References: <20180731061721.15831-1-kai.heng.feng@canonical.com> <20180731061721.15831-5-kai.heng.feng@canonical.com> From: Ulf Hansson Date: Fri, 24 Aug 2018 08:28:06 +0200 Message-ID: Subject: Re: [PATCH 4/5] memstick: rtsx_usb_ms: Support runtime power management To: Kai-Heng Feng Cc: Arnd Bergmann , Greg Kroah-Hartman , Alan Stern , "Bauer.Chen" , ricky_wu@realtek.com, Linux Kernel Mailing List , Linux USB List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > 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. :-) [...] Kind regards Uffe