All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Luis R. Rodriguez" <mcgrof@kernel.org>
To: "Li, Yi" <yi1.li@linux.intel.com>
Cc: "Luis R. Rodriguez" <mcgrof@kernel.org>,
	atull@kernel.org, gregkh@linuxfoundation.org, wagi@monom.org,
	dwmw2@infradead.org, rafal@milecki.pl,
	arend.vanspriel@broadcom.com, rjw@rjwysocki.net,
	moritz.fischer@ettus.com, pmladek@suse.com,
	johannes.berg@intel.com, emmanuel.grumbach@intel.com,
	luciano.coelho@intel.com, kvalo@codeaurora.org, luto@kernel.org,
	takahiro.akashi@linaro.org, dhowells@redhat.com,
	pjones@redhat.com, linux-kernel@vger.kernel.org,
	linux-fpga@vger.kernel.org
Subject: Re: [PATCHv2 0/3] Enable no_cache flag to driver_data
Date: Thu, 8 Jun 2017 01:02:04 +0200	[thread overview]
Message-ID: <20170607230204.GO27288@wotan.suse.de> (raw)
In-Reply-To: <917cb457-d0ae-aee6-246e-b3d80e6a9c45@linux.intel.com>

On Wed, Jun 07, 2017 at 04:00:42PM -0500, Li, Yi wrote:
> On 6/7/2017 12:59 PM, Luis R. Rodriguez wrote:
> > Ah, consider adding PM to driver_data_test_device ?
> 
> That's what I am looking now. But per my understanding, the misc_device does
> not have the hook to add PM support like those platform device drivers do.
> Please let me know if there is a way to do that.

Ah, hrm. Yeah I'd have to look into it, why does misc devs not have support?

Otherwise you could see if you can just modify the test driver to be a platform
driver, these are easy to register, see. For a simple example see
platform_device_register_simple() use on net/wireless/reg.c.

> > > device_uncache_fw_images_delay() will be called for PM_POST_RESTORE, which
> > > means the hibernation restore got error. How about the successful restore
> > > case, calling driver will free its firmware_buf after loading?
> > 
> > As it is on my latest 20170605-driver-data [0] (but should be just as yours if you
> > used a recent branch of mine), fw_pm_notify() uses:
> > 
> > static int fw_pm_notify(struct notifier_block *notify_block,
> > 			unsigned long mode, void *unused)
> > {
> > 	switch (mode) {
> > 	...
> > 	case PM_POST_SUSPEND:
> > 	case PM_POST_HIBERNATION:
> > 	case PM_POST_RESTORE:
> > 		/*
> > 		 * In case that system sleep failed and syscore_suspend is
> > 		 * not called.
> > 		 */
> > 		mutex_lock(&fw_lock);
> > 		fw_cache.state = FW_LOADER_NO_CACHE;
> > 		mutex_unlock(&fw_lock);
> > 		enable_firmware();
> > 
> > 		device_uncache_fw_images_delay(10 * MSEC_PER_SEC);
> > 		break;
> >         }
> > }
> > 
> > So it uses also PM_POST_RESTORE. I think that covers it all ? As it
> > is today we handle the firmware cache for all drivers, it should be
> > transparent to drivers.
> 
> Ah, the comment of "sleep failed" mislead me. :)

Ah no that comment is about more of a brain fuck with the internals of suspend
on Linux, this may be very confusing. Its for this reason why I recently
submitted a patch which helps explain all this more, the patch was recently
merged by Greg KH, it expands on the documentation of fw_pm_notify() so let me
paste the diagram which is relevant form the documentation added:

/**
 * fw_pm_notify - notifier for suspend/resume
 * @notify_block: unused
 * @mode: mode we are switching to
 * @unused: unused
 *
 * Used to modify the firmware_class state as we move in between states.
 * The firmware_class implements a firmware cache to enable device driver
 * to fetch firmware upon resume before the root filesystem is ready. We
 * disable API calls which do not use the built-in firmware or the firmware
 * cache when we know these calls will not work.
 *
 * The inner logic behind all this is a bit complex so it is worth summarizing
 * the kernel's own suspend/resume process with context and focus on how this
 * can impact the firmware API.
 *
 * First a review on how we go to suspend::
 *
 *	pm_suspend() --> enter_state() -->
 *	sys_sync()
 *	suspend_prepare() -->
 *		__pm_notifier_call_chain(PM_SUSPEND_PREPARE, ...);
 *		suspend_freeze_processes() -->
 *			freeze_processes() -->
 *				__usermodehelper_set_disable_depth(UMH_DISABLED);
 *				freeze all tasks ...
 *			freeze_kernel_threads()
 *	suspend_devices_and_enter() -->
 *		dpm_suspend_start() -->
 *				dpm_prepare()
 *				dpm_suspend()
 *		suspend_enter()  -->
 *			platform_suspend_prepare()
 *			dpm_suspend_late()
 *			freeze_enter()
 *			syscore_suspend()
 *
 * When we resume we bail out of a loop from suspend_devices_and_enter() and
 * unwind back out to the caller enter_state() where we were before as follows::
 *
 * 	enter_state() -->
 *	suspend_devices_and_enter() --> (bail from loop)
 *		dpm_resume_end() -->
 *			dpm_resume()
 *			dpm_complete()
 *	suspend_finish() -->
 *		suspend_thaw_processes() -->
 *			thaw_processes() -->
 *				__usermodehelper_set_disable_depth(UMH_FREEZING);
 *				thaw_workqueues();
 *				thaw all processes ...
 *				usermodehelper_enable();
 *		pm_notifier_call_chain(PM_POST_SUSPEND);
 *
 * fw_pm_notify() works through pm_notifier_call_chain().
 */

The key is that even if we fail at syscore_suspend() we will bail out of the
loop on suspend_devices_and_enter() and eventually get our notifier called
with PM_POST_SUSPEND, in the case of suspend/resume. The reason the
comment is there is that even though we have the notifier we also have
the fw_syscore_ops, and our fw_suspend(). If our fw_suspend() fails to
get called then this does not happen:

static int fw_suspend(void)
{
	fw_cache.state = FW_LOADER_NO_CACHE;
	return 0;                                                               
}

  Luis

      reply	other threads:[~2017-06-07 23:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-20  6:46 [PATCHv2 0/3] Enable no_cache flag to driver_data yi1.li
2017-05-20  6:46 ` [PATCHv2 1/3] firmware_class: move NO_CACHE from private to driver_data_req_params yi1.li
2017-05-20  6:46 ` [PATCHv2 2/3] iwlwifi: use DRIVER_DATA_REQ_NO_CACHE for driver_data yi1.li
2017-05-20  6:46 ` [PATCHv2 3/3] test: add no_cache to driver_data load tester yi1.li
2017-05-24 19:03 ` [PATCHv2 0/3] Enable no_cache flag to driver_data Luis R. Rodriguez
2017-05-24 20:32   ` Luis R. Rodriguez
2017-05-25 22:30   ` Li, Yi
2017-05-25 22:43     ` Luis R. Rodriguez
2017-05-26 21:05       ` Li, Yi
2017-05-26 21:13         ` Luis R. Rodriguez
2017-06-06 19:31   ` Li, Yi
2017-06-07 17:59     ` Luis R. Rodriguez
2017-06-07 21:00       ` Li, Yi
2017-06-07 23:02         ` Luis R. Rodriguez [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170607230204.GO27288@wotan.suse.de \
    --to=mcgrof@kernel.org \
    --cc=arend.vanspriel@broadcom.com \
    --cc=atull@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=dwmw2@infradead.org \
    --cc=emmanuel.grumbach@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=johannes.berg@intel.com \
    --cc=kvalo@codeaurora.org \
    --cc=linux-fpga@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luciano.coelho@intel.com \
    --cc=luto@kernel.org \
    --cc=moritz.fischer@ettus.com \
    --cc=pjones@redhat.com \
    --cc=pmladek@suse.com \
    --cc=rafal@milecki.pl \
    --cc=rjw@rjwysocki.net \
    --cc=takahiro.akashi@linaro.org \
    --cc=wagi@monom.org \
    --cc=yi1.li@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.