2020-03-05 22:28:28 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
|
2024-04-16 18:10:13 -05:00
|
|
|
* Copyright (C) 2019-2024 Linaro Ltd.
|
2020-03-05 22:28:28 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/notifier.h>
|
2021-06-30 18:54:59 -07:00
|
|
|
#include <linux/panic_notifier.h>
|
2024-04-16 18:10:18 -05:00
|
|
|
#include <linux/platform_device.h>
|
2021-08-10 14:27:04 -05:00
|
|
|
#include <linux/pm_runtime.h>
|
2024-04-16 18:10:18 -05:00
|
|
|
#include <linux/types.h>
|
|
|
|
|
2020-03-05 22:28:28 -06:00
|
|
|
#include <linux/soc/qcom/smem_state.h>
|
|
|
|
|
|
|
|
#include "ipa.h"
|
2024-04-16 18:10:18 -05:00
|
|
|
#include "ipa_smp2p.h"
|
2020-03-05 22:28:28 -06:00
|
|
|
#include "ipa_uc.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DOC: IPA SMP2P communication with the modem
|
|
|
|
*
|
|
|
|
* SMP2P is a primitive communication mechanism available between the AP and
|
|
|
|
* the modem. The IPA driver uses this for two purposes: to enable the modem
|
|
|
|
* to state that the GSI hardware is ready to use; and to communicate the
|
2021-08-20 11:01:28 -05:00
|
|
|
* state of IPA power in the event of a crash.
|
2020-03-05 22:28:28 -06:00
|
|
|
*
|
|
|
|
* GSI needs to have early initialization completed before it can be used.
|
|
|
|
* This initialization is done either by Trust Zone or by the modem. In the
|
|
|
|
* latter case, the modem uses an SMP2P interrupt to tell the AP IPA driver
|
|
|
|
* when the GSI is ready to use.
|
|
|
|
*
|
2021-08-20 11:01:28 -05:00
|
|
|
* The modem is also able to inquire about the current state of IPA
|
|
|
|
* power by trigging another SMP2P interrupt to the AP. We communicate
|
|
|
|
* whether power is enabled using two SMP2P state bits--one to indicate
|
|
|
|
* the power state (on or off), and a second to indicate the power state
|
|
|
|
* bit is valid. The modem will poll the valid bit until it is set, and
|
|
|
|
* at that time records whether the AP has IPA power enabled.
|
2020-03-05 22:28:28 -06:00
|
|
|
*
|
|
|
|
* Finally, if the AP kernel panics, we update the SMP2P state bits even if
|
|
|
|
* we never receive an interrupt from the modem requesting this.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct ipa_smp2p - IPA SMP2P information
|
|
|
|
* @ipa: IPA pointer
|
|
|
|
* @valid_state: SMEM state indicating enabled state is valid
|
2021-08-20 11:01:28 -05:00
|
|
|
* @enabled_state: SMEM state to indicate power is enabled
|
2020-03-05 22:28:28 -06:00
|
|
|
* @valid_bit: Valid bit in 32-bit SMEM state mask
|
|
|
|
* @enabled_bit: Enabled bit in 32-bit SMEM state mask
|
|
|
|
* @enabled_bit: Enabled bit in 32-bit SMEM state mask
|
2021-08-20 11:01:28 -05:00
|
|
|
* @clock_query_irq: IPA interrupt triggered by modem for power query
|
2020-03-05 22:28:28 -06:00
|
|
|
* @setup_ready_irq: IPA interrupt triggered by modem to signal GSI ready
|
2021-08-20 11:01:28 -05:00
|
|
|
* @power_on: Whether IPA power is on
|
|
|
|
* @notified: Whether modem has been notified of power state
|
2021-11-22 18:15:54 -06:00
|
|
|
* @setup_disabled: Whether setup ready interrupt handler is disabled
|
2020-05-14 04:02:22 -07:00
|
|
|
* @mutex: Mutex protecting ready-interrupt/shutdown interlock
|
2020-03-05 22:28:28 -06:00
|
|
|
* @panic_notifier: Panic notifier structure
|
|
|
|
*/
|
|
|
|
struct ipa_smp2p {
|
|
|
|
struct ipa *ipa;
|
|
|
|
struct qcom_smem_state *valid_state;
|
|
|
|
struct qcom_smem_state *enabled_state;
|
|
|
|
u32 valid_bit;
|
|
|
|
u32 enabled_bit;
|
|
|
|
u32 clock_query_irq;
|
|
|
|
u32 setup_ready_irq;
|
2021-08-20 11:01:28 -05:00
|
|
|
bool power_on;
|
2020-03-05 22:28:28 -06:00
|
|
|
bool notified;
|
2021-11-22 18:15:54 -06:00
|
|
|
bool setup_disabled;
|
2020-03-05 22:28:28 -06:00
|
|
|
struct mutex mutex;
|
|
|
|
struct notifier_block panic_notifier;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-08-20 11:01:28 -05:00
|
|
|
* ipa_smp2p_notify() - use SMP2P to tell modem about IPA power state
|
2020-03-05 22:28:28 -06:00
|
|
|
* @smp2p: SMP2P information
|
|
|
|
*
|
|
|
|
* This is called either when the modem has requested it (by triggering
|
2021-08-20 11:01:28 -05:00
|
|
|
* the modem power query IPA interrupt) or whenever the AP is shutting down
|
2020-03-05 22:28:28 -06:00
|
|
|
* (via a panic notifier). It sets the two SMP2P state bits--one saying
|
2021-08-20 11:01:28 -05:00
|
|
|
* whether the IPA power is on, and the other indicating the first bit
|
2020-03-05 22:28:28 -06:00
|
|
|
* is valid.
|
|
|
|
*/
|
|
|
|
static void ipa_smp2p_notify(struct ipa_smp2p *smp2p)
|
|
|
|
{
|
|
|
|
u32 value;
|
|
|
|
u32 mask;
|
|
|
|
|
|
|
|
if (smp2p->notified)
|
|
|
|
return;
|
|
|
|
|
Power management updates for 6.9-rc1
- Allow the Energy Model to be updated dynamically (Lukasz Luba).
- Add support for LZ4 compression algorithm to the hibernation image
creation and loading code (Nikhil V).
- Fix and clean up system suspend statistics collection (Rafael
Wysocki).
- Simplify device suspend and resume handling in the power management
core code (Rafael Wysocki).
- Fix PCI hibernation support description (Yiwei Lin).
- Make hibernation take set_memory_ro() return values into account as
appropriate (Christophe Leroy).
- Set mem_sleep_current during kernel command line setup to avoid an
ordering issue with handling it (Maulik Shah).
- Fix wake IRQs handling when pm_runtime_force_suspend() is used as a
driver's system suspend callback (Qingliang Li).
- Simplify pm_runtime_get_if_active() usage and add a replacement for
pm_runtime_put_autosuspend() (Sakari Ailus).
- Add a tracepoint for runtime_status changes tracking (Vilas Bhat).
- Fix section title markdown in the runtime PM documentation (Yiwei
Lin).
- Enable preferred core support in the amd-pstate cpufreq driver (Meng
Li).
- Fix min_perf assignment in amd_pstate_adjust_perf() and make the
min/max limit perf values in amd-pstate always stay within the
(highest perf, lowest perf) range (Tor Vic, Meng Li).
- Allow intel_pstate to assign model-specific values to strings used in
the EPP sysfs interface and make it do so on Meteor Lake (Srinivas
Pandruvada).
- Drop long-unused cpudata::prev_cummulative_iowait from the
intel_pstate cpufreq driver (Jiri Slaby).
- Prevent scaling_cur_freq from exceeding scaling_max_freq when the
latter is an inefficient frequency (Shivnandan Kumar).
- Change default transition delay in cpufreq to 2ms (Qais Yousef).
- Remove references to 10ms minimum sampling rate from comments in the
cpufreq code (Pierre Gondois).
- Honour transition_latency over transition_delay_us in cpufreq (Qais
Yousef).
- Stop unregistering cpufreq cooling on CPU hot-remove (Viresh Kumar).
- General enhancements / cleanups to ARM cpufreq drivers (tianyu2,
Nícolas F. R. A. Prado, Erick Archer, Arnd Bergmann, Anastasia
Belova).
- Update cpufreq-dt-platdev to block/approve devices (Richard Acayan).
- Make the SCMI cpufreq driver get a transition delay value from
firmware (Pierre Gondois).
- Prevent the haltpoll cpuidle governor from shrinking guest
poll_limit_ns below grow_start (Parshuram Sangle).
- Avoid potential overflow in integer multiplication when computing
cpuidle state parameters (C Cheng).
- Adjust MWAIT hint target C-state computation in the ACPI cpuidle
driver and in intel_idle to return a correct value for C0 (He
Rongguang).
- Address multiple issues in the TPMI RAPL driver and add support for
new platforms (Lunar Lake-M, Arrow Lake) to Intel RAPL (Zhang Rui).
- Fix freq_qos_add_request() return value check in dtpm_cpu (Daniel
Lezcano).
- Fix kernel-doc for dtpm_create_hierarchy() (Yang Li).
- Fix file leak in get_pkg_num() in x86_energy_perf_policy (Samasth
Norway Ananda).
- Fix cpupower-frequency-info.1 man page typo (Jan Kratochvil).
- Fix a couple of warnings in the OPP core code related to W=1
builds (Viresh Kumar).
- Move dev_pm_opp_{init|free}_cpufreq_table() to pm_opp.h (Viresh
Kumar).
- Extend dev_pm_opp_data with turbo support (Sibi Sankar).
- dt-bindings: drop maxItems from inner items (David Heidelberg).
-----BEGIN PGP SIGNATURE-----
iQJGBAABCAAwFiEE4fcc61cGeeHD/fCwgsRv/nhiVHEFAmXvI/ISHHJqd0Byand5
c29ja2kubmV0AAoJEILEb/54YlRx24sP/jxg6fOGme8raHQvpTXG3/H56wlGzQ4P
YUvvKUXnfD3yf1zNISsUl7VQebZqDt8rygkwSdymXlUVZX1eubN0RpCFc0F8GZuc
THG/YQhYQr/9zro3FpKhfDj5evk21PCQzjf+dGvfQF9qVMxNPG1JzEFK6PnolT5X
2BvkonY1XFWZjCMbZ83B/jt35lTDb0cmeNbCpfD5UJgcnxmMOtZYpORdyfPWTJpG
GVCwmAFVVXxXlust/AIpt3mmOpKzSA9GnrtJkhtQe5GN+Y4OjnJiFJmTC7EfCctj
JlWgVUA716mtFMUrjXgjfI54firF2oQpqaSa2HG/V/A96JWQqjarGz5dAV1IrPEt
ZmYpvMe4E90S411wF1OWyrEqjXUuDnH1OWUvUdWSt4E7DhFw3esDi/jLW2tyVKAT
hIy+/O4wzbDSTX/h9Cgt1Qjhew6lKUIwvhEXclB3fuJ+JoviWNkC9lnK93e2H0A3
VYfkd/lpUD74035l0FrCJ/49MjX9kqrsn+TipHsIlSXAi8ZRdKbVvxOTD8RYudcI
GvCiDDrkMgNwGlyedgbtTBUepCvSg93b+vVmRj7YMPtBhioOUo3qCn6wpqhxfnth
9BCnPW7JxqUw/NJdlk9hKumaUZq+MK8G+kdYcIDg6xmAkWSUVP2QKlWavfMCxqRP
+dN6T2iHsKFe
=UePT
-----END PGP SIGNATURE-----
Merge tag 'pm-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull power management updates from Rafael Wysocki:
"From the functional perspective, the most significant change here is
the addition of support for Energy Models that can be updated
dynamically at run time.
There is also the addition of LZ4 compression support for hibernation,
the new preferred core support in amd-pstate, new platforms support in
the Intel RAPL driver, new model-specific EPP handling in intel_pstate
and more.
Apart from that, the cpufreq default transition delay is reduced from
10 ms to 2 ms (along with some related adjustments), the system
suspend statistics code undergoes a significant rework and there is a
usual bunch of fixes and code cleanups all over.
Specifics:
- Allow the Energy Model to be updated dynamically (Lukasz Luba)
- Add support for LZ4 compression algorithm to the hibernation image
creation and loading code (Nikhil V)
- Fix and clean up system suspend statistics collection (Rafael
Wysocki)
- Simplify device suspend and resume handling in the power management
core code (Rafael Wysocki)
- Fix PCI hibernation support description (Yiwei Lin)
- Make hibernation take set_memory_ro() return values into account as
appropriate (Christophe Leroy)
- Set mem_sleep_current during kernel command line setup to avoid an
ordering issue with handling it (Maulik Shah)
- Fix wake IRQs handling when pm_runtime_force_suspend() is used as a
driver's system suspend callback (Qingliang Li)
- Simplify pm_runtime_get_if_active() usage and add a replacement for
pm_runtime_put_autosuspend() (Sakari Ailus)
- Add a tracepoint for runtime_status changes tracking (Vilas Bhat)
- Fix section title markdown in the runtime PM documentation (Yiwei
Lin)
- Enable preferred core support in the amd-pstate cpufreq driver
(Meng Li)
- Fix min_perf assignment in amd_pstate_adjust_perf() and make the
min/max limit perf values in amd-pstate always stay within the
(highest perf, lowest perf) range (Tor Vic, Meng Li)
- Allow intel_pstate to assign model-specific values to strings used
in the EPP sysfs interface and make it do so on Meteor Lake
(Srinivas Pandruvada)
- Drop long-unused cpudata::prev_cummulative_iowait from the
intel_pstate cpufreq driver (Jiri Slaby)
- Prevent scaling_cur_freq from exceeding scaling_max_freq when the
latter is an inefficient frequency (Shivnandan Kumar)
- Change default transition delay in cpufreq to 2ms (Qais Yousef)
- Remove references to 10ms minimum sampling rate from comments in
the cpufreq code (Pierre Gondois)
- Honour transition_latency over transition_delay_us in cpufreq (Qais
Yousef)
- Stop unregistering cpufreq cooling on CPU hot-remove (Viresh Kumar)
- General enhancements / cleanups to ARM cpufreq drivers (tianyu2,
Nícolas F. R. A. Prado, Erick Archer, Arnd Bergmann, Anastasia
Belova)
- Update cpufreq-dt-platdev to block/approve devices (Richard Acayan)
- Make the SCMI cpufreq driver get a transition delay value from
firmware (Pierre Gondois)
- Prevent the haltpoll cpuidle governor from shrinking guest
poll_limit_ns below grow_start (Parshuram Sangle)
- Avoid potential overflow in integer multiplication when computing
cpuidle state parameters (C Cheng)
- Adjust MWAIT hint target C-state computation in the ACPI cpuidle
driver and in intel_idle to return a correct value for C0 (He
Rongguang)
- Address multiple issues in the TPMI RAPL driver and add support for
new platforms (Lunar Lake-M, Arrow Lake) to Intel RAPL (Zhang Rui)
- Fix freq_qos_add_request() return value check in dtpm_cpu (Daniel
Lezcano)
- Fix kernel-doc for dtpm_create_hierarchy() (Yang Li)
- Fix file leak in get_pkg_num() in x86_energy_perf_policy (Samasth
Norway Ananda)
- Fix cpupower-frequency-info.1 man page typo (Jan Kratochvil)
- Fix a couple of warnings in the OPP core code related to W=1 builds
(Viresh Kumar)
- Move dev_pm_opp_{init|free}_cpufreq_table() to pm_opp.h (Viresh
Kumar)
- Extend dev_pm_opp_data with turbo support (Sibi Sankar)
- dt-bindings: drop maxItems from inner items (David Heidelberg)"
* tag 'pm-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (95 commits)
dt-bindings: opp: drop maxItems from inner items
OPP: debugfs: Fix warning around icc_get_name()
OPP: debugfs: Fix warning with W=1 builds
cpufreq: Move dev_pm_opp_{init|free}_cpufreq_table() to pm_opp.h
OPP: Extend dev_pm_opp_data with turbo support
Fix cpupower-frequency-info.1 man page typo
cpufreq: scmi: Set transition_delay_us
firmware: arm_scmi: Populate fast channel rate_limit
firmware: arm_scmi: Populate perf commands rate_limit
cpuidle: ACPI/intel: fix MWAIT hint target C-state computation
PM: sleep: wakeirq: fix wake irq warning in system suspend
powercap: dtpm: Fix kernel-doc for dtpm_create_hierarchy() function
cpufreq: Don't unregister cpufreq cooling on CPU hotplug
PM: suspend: Set mem_sleep_current during kernel command line setup
cpufreq: Honour transition_latency over transition_delay_us
cpufreq: Limit resolving a frequency to policy min/max
Documentation: PM: Fix runtime_pm.rst markdown syntax
cpufreq: amd-pstate: adjust min/max limit perf
cpufreq: Remove references to 10ms min sampling rate
cpufreq: intel_pstate: Update default EPPs for Meteor Lake
...
2024-03-13 11:40:06 -07:00
|
|
|
smp2p->power_on = pm_runtime_get_if_active(smp2p->ipa->dev) > 0;
|
2020-03-05 22:28:28 -06:00
|
|
|
|
2021-08-20 11:01:28 -05:00
|
|
|
/* Signal whether the IPA power is enabled */
|
2020-03-05 22:28:28 -06:00
|
|
|
mask = BIT(smp2p->enabled_bit);
|
2021-08-20 11:01:28 -05:00
|
|
|
value = smp2p->power_on ? mask : 0;
|
2020-03-05 22:28:28 -06:00
|
|
|
qcom_smem_state_update_bits(smp2p->enabled_state, mask, value);
|
|
|
|
|
|
|
|
/* Now indicate that the enabled flag is valid */
|
|
|
|
mask = BIT(smp2p->valid_bit);
|
|
|
|
value = mask;
|
|
|
|
qcom_smem_state_update_bits(smp2p->valid_state, mask, value);
|
|
|
|
|
|
|
|
smp2p->notified = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Threaded IRQ handler for modem "ipa-clock-query" SMP2P interrupt */
|
|
|
|
static irqreturn_t ipa_smp2p_modem_clk_query_isr(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct ipa_smp2p *smp2p = dev_id;
|
|
|
|
|
|
|
|
ipa_smp2p_notify(smp2p);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ipa_smp2p_panic_notifier(struct notifier_block *nb,
|
|
|
|
unsigned long action, void *data)
|
|
|
|
{
|
|
|
|
struct ipa_smp2p *smp2p;
|
|
|
|
|
|
|
|
smp2p = container_of(nb, struct ipa_smp2p, panic_notifier);
|
|
|
|
|
|
|
|
ipa_smp2p_notify(smp2p);
|
|
|
|
|
2021-08-20 11:01:28 -05:00
|
|
|
if (smp2p->power_on)
|
2020-03-05 22:28:28 -06:00
|
|
|
ipa_uc_panic_notifier(smp2p->ipa);
|
|
|
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ipa_smp2p_panic_notifier_register(struct ipa_smp2p *smp2p)
|
|
|
|
{
|
|
|
|
/* IPA panic handler needs to run before modem shuts down */
|
|
|
|
smp2p->panic_notifier.notifier_call = ipa_smp2p_panic_notifier;
|
|
|
|
smp2p->panic_notifier.priority = INT_MAX; /* Do it early */
|
|
|
|
|
|
|
|
return atomic_notifier_chain_register(&panic_notifier_list,
|
|
|
|
&smp2p->panic_notifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ipa_smp2p_panic_notifier_unregister(struct ipa_smp2p *smp2p)
|
|
|
|
{
|
|
|
|
atomic_notifier_chain_unregister(&panic_notifier_list,
|
|
|
|
&smp2p->panic_notifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Threaded IRQ handler for modem "ipa-setup-ready" SMP2P interrupt */
|
|
|
|
static irqreturn_t ipa_smp2p_modem_setup_ready_isr(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct ipa_smp2p *smp2p = dev_id;
|
2024-03-01 11:02:42 -06:00
|
|
|
struct ipa *ipa = smp2p->ipa;
|
2021-08-19 17:19:24 -05:00
|
|
|
struct device *dev;
|
net: ipa: have ipa_clock_get() return a value
We currently assume no errors occur when enabling or disabling the
IPA core clock and interconnects. And although this commit exposes
errors that could occur, we generally assume this won't happen in
practice.
This commit changes ipa_clock_get() and ipa_clock_put() so each
returns a value. The values returned are meant to mimic what the
runtime power management functions return, so we can set up error
handling here before we make the switch. Have ipa_clock_get()
increment the reference count even if it returns an error, to match
the behavior of pm_runtime_get().
More details follow.
When taking a reference in ipa_clock_get(), return 0 for the first
reference, 1 for subsequent references, or a negative error code if
an error occurs. Note that if ipa_clock_get() returns an error, we
must not touch hardware; in some cases such errors now cause entire
blocks of code to be skipped.
When dropping a reference in ipa_clock_put(), we return 0 or an
error code. The error would come from ipa_clock_disable(), which
now returns what ipa_interconnect_disable() returns (either 0 or a
negative error code). For now, callers ignore the return value;
if an error occurs, a message will have already been logged, and
little more can actually be done to improve the situation.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-08-10 14:26:58 -05:00
|
|
|
int ret;
|
2020-03-05 22:28:28 -06:00
|
|
|
|
2021-11-22 18:15:54 -06:00
|
|
|
/* Ignore any (spurious) interrupts received after the first */
|
2024-03-01 11:02:42 -06:00
|
|
|
if (ipa->setup_complete)
|
2021-11-22 18:15:54 -06:00
|
|
|
return IRQ_HANDLED;
|
2021-07-27 16:19:30 -05:00
|
|
|
|
2021-08-19 17:19:24 -05:00
|
|
|
/* Power needs to be active for setup */
|
2024-03-01 11:02:42 -06:00
|
|
|
dev = ipa->dev;
|
2021-08-19 17:19:24 -05:00
|
|
|
ret = pm_runtime_get_sync(dev);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "error %d getting power for setup\n", ret);
|
|
|
|
goto out_power_put;
|
|
|
|
}
|
2021-07-27 16:19:30 -05:00
|
|
|
|
net: ipa: have ipa_clock_get() return a value
We currently assume no errors occur when enabling or disabling the
IPA core clock and interconnects. And although this commit exposes
errors that could occur, we generally assume this won't happen in
practice.
This commit changes ipa_clock_get() and ipa_clock_put() so each
returns a value. The values returned are meant to mimic what the
runtime power management functions return, so we can set up error
handling here before we make the switch. Have ipa_clock_get()
increment the reference count even if it returns an error, to match
the behavior of pm_runtime_get().
More details follow.
When taking a reference in ipa_clock_get(), return 0 for the first
reference, 1 for subsequent references, or a negative error code if
an error occurs. Note that if ipa_clock_get() returns an error, we
must not touch hardware; in some cases such errors now cause entire
blocks of code to be skipped.
When dropping a reference in ipa_clock_put(), we return 0 or an
error code. The error would come from ipa_clock_disable(), which
now returns what ipa_interconnect_disable() returns (either 0 or a
negative error code). For now, callers ignore the return value;
if an error occurs, a message will have already been logged, and
little more can actually be done to improve the situation.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-08-10 14:26:58 -05:00
|
|
|
/* An error here won't cause driver shutdown, so warn if one occurs */
|
2024-03-01 11:02:42 -06:00
|
|
|
ret = ipa_setup(ipa);
|
net: ipa: have ipa_clock_get() return a value
We currently assume no errors occur when enabling or disabling the
IPA core clock and interconnects. And although this commit exposes
errors that could occur, we generally assume this won't happen in
practice.
This commit changes ipa_clock_get() and ipa_clock_put() so each
returns a value. The values returned are meant to mimic what the
runtime power management functions return, so we can set up error
handling here before we make the switch. Have ipa_clock_get()
increment the reference count even if it returns an error, to match
the behavior of pm_runtime_get().
More details follow.
When taking a reference in ipa_clock_get(), return 0 for the first
reference, 1 for subsequent references, or a negative error code if
an error occurs. Note that if ipa_clock_get() returns an error, we
must not touch hardware; in some cases such errors now cause entire
blocks of code to be skipped.
When dropping a reference in ipa_clock_put(), we return 0 or an
error code. The error would come from ipa_clock_disable(), which
now returns what ipa_interconnect_disable() returns (either 0 or a
negative error code). For now, callers ignore the return value;
if an error occurs, a message will have already been logged, and
little more can actually be done to improve the situation.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-08-10 14:26:58 -05:00
|
|
|
WARN(ret != 0, "error %d from ipa_setup()\n", ret);
|
2020-03-05 22:28:28 -06:00
|
|
|
|
2021-08-19 17:19:24 -05:00
|
|
|
out_power_put:
|
2021-08-20 11:01:27 -05:00
|
|
|
pm_runtime_mark_last_busy(dev);
|
|
|
|
(void)pm_runtime_put_autosuspend(dev);
|
2020-03-05 22:28:28 -06:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize SMP2P interrupts */
|
2024-03-01 11:02:40 -06:00
|
|
|
static int ipa_smp2p_irq_init(struct ipa_smp2p *smp2p,
|
|
|
|
struct platform_device *pdev,
|
|
|
|
const char *name, irq_handler_t handler)
|
2020-03-05 22:28:28 -06:00
|
|
|
{
|
2024-03-01 11:02:40 -06:00
|
|
|
struct device *dev = &pdev->dev;
|
2020-03-05 22:28:28 -06:00
|
|
|
unsigned int irq;
|
|
|
|
int ret;
|
|
|
|
|
2024-03-01 11:02:40 -06:00
|
|
|
ret = platform_get_irq_byname(pdev, name);
|
2021-06-10 22:01:18 +08:00
|
|
|
if (ret <= 0)
|
2020-03-05 22:28:28 -06:00
|
|
|
return ret ? : -EINVAL;
|
|
|
|
irq = ret;
|
|
|
|
|
|
|
|
ret = request_threaded_irq(irq, NULL, handler, 0, name, smp2p);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "error %d requesting \"%s\" IRQ\n", ret, name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ipa_smp2p_irq_exit(struct ipa_smp2p *smp2p, u32 irq)
|
|
|
|
{
|
|
|
|
free_irq(irq, smp2p);
|
|
|
|
}
|
|
|
|
|
2021-08-20 11:01:28 -05:00
|
|
|
/* Drop the power reference if it was taken in ipa_smp2p_notify() */
|
|
|
|
static void ipa_smp2p_power_release(struct ipa *ipa)
|
2020-03-05 22:28:28 -06:00
|
|
|
{
|
2024-03-01 11:02:42 -06:00
|
|
|
struct device *dev = ipa->dev;
|
2021-08-20 11:01:27 -05:00
|
|
|
|
2021-08-20 11:01:28 -05:00
|
|
|
if (!ipa->smp2p->power_on)
|
2020-03-05 22:28:28 -06:00
|
|
|
return;
|
|
|
|
|
2021-08-20 11:01:27 -05:00
|
|
|
pm_runtime_mark_last_busy(dev);
|
|
|
|
(void)pm_runtime_put_autosuspend(dev);
|
2021-08-20 11:01:28 -05:00
|
|
|
ipa->smp2p->power_on = false;
|
2020-03-05 22:28:28 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the IPA SMP2P subsystem */
|
2024-03-01 11:02:41 -06:00
|
|
|
int
|
|
|
|
ipa_smp2p_init(struct ipa *ipa, struct platform_device *pdev, bool modem_init)
|
2020-03-05 22:28:28 -06:00
|
|
|
{
|
|
|
|
struct qcom_smem_state *enabled_state;
|
2024-03-01 11:02:41 -06:00
|
|
|
struct device *dev = &pdev->dev;
|
2020-03-05 22:28:28 -06:00
|
|
|
struct qcom_smem_state *valid_state;
|
|
|
|
struct ipa_smp2p *smp2p;
|
|
|
|
u32 enabled_bit;
|
|
|
|
u32 valid_bit;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
valid_state = qcom_smem_state_get(dev, "ipa-clock-enabled-valid",
|
|
|
|
&valid_bit);
|
|
|
|
if (IS_ERR(valid_state))
|
|
|
|
return PTR_ERR(valid_state);
|
|
|
|
if (valid_bit >= 32) /* BITS_PER_U32 */
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
enabled_state = qcom_smem_state_get(dev, "ipa-clock-enabled",
|
|
|
|
&enabled_bit);
|
|
|
|
if (IS_ERR(enabled_state))
|
|
|
|
return PTR_ERR(enabled_state);
|
|
|
|
if (enabled_bit >= 32) /* BITS_PER_U32 */
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
smp2p = kzalloc(sizeof(*smp2p), GFP_KERNEL);
|
|
|
|
if (!smp2p)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
smp2p->ipa = ipa;
|
|
|
|
|
2021-08-20 11:01:28 -05:00
|
|
|
/* These fields are needed by the power query interrupt
|
2020-03-05 22:28:28 -06:00
|
|
|
* handler, so initialize them now.
|
|
|
|
*/
|
|
|
|
mutex_init(&smp2p->mutex);
|
|
|
|
smp2p->valid_state = valid_state;
|
|
|
|
smp2p->valid_bit = valid_bit;
|
|
|
|
smp2p->enabled_state = enabled_state;
|
|
|
|
smp2p->enabled_bit = enabled_bit;
|
|
|
|
|
|
|
|
/* We have enough information saved to handle notifications */
|
|
|
|
ipa->smp2p = smp2p;
|
|
|
|
|
2024-03-01 11:02:41 -06:00
|
|
|
ret = ipa_smp2p_irq_init(smp2p, pdev, "ipa-clock-query",
|
2020-03-05 22:28:28 -06:00
|
|
|
ipa_smp2p_modem_clk_query_isr);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err_null_smp2p;
|
|
|
|
smp2p->clock_query_irq = ret;
|
|
|
|
|
|
|
|
ret = ipa_smp2p_panic_notifier_register(smp2p);
|
|
|
|
if (ret)
|
|
|
|
goto err_irq_exit;
|
|
|
|
|
|
|
|
if (modem_init) {
|
|
|
|
/* Result will be non-zero (negative for error) */
|
2024-03-01 11:02:41 -06:00
|
|
|
ret = ipa_smp2p_irq_init(smp2p, pdev, "ipa-setup-ready",
|
2020-03-05 22:28:28 -06:00
|
|
|
ipa_smp2p_modem_setup_ready_isr);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err_notifier_unregister;
|
|
|
|
smp2p->setup_ready_irq = ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_notifier_unregister:
|
|
|
|
ipa_smp2p_panic_notifier_unregister(smp2p);
|
|
|
|
err_irq_exit:
|
|
|
|
ipa_smp2p_irq_exit(smp2p, smp2p->clock_query_irq);
|
|
|
|
err_null_smp2p:
|
|
|
|
ipa->smp2p = NULL;
|
|
|
|
mutex_destroy(&smp2p->mutex);
|
|
|
|
kfree(smp2p);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ipa_smp2p_exit(struct ipa *ipa)
|
|
|
|
{
|
|
|
|
struct ipa_smp2p *smp2p = ipa->smp2p;
|
|
|
|
|
|
|
|
if (smp2p->setup_ready_irq)
|
|
|
|
ipa_smp2p_irq_exit(smp2p, smp2p->setup_ready_irq);
|
|
|
|
ipa_smp2p_panic_notifier_unregister(smp2p);
|
|
|
|
ipa_smp2p_irq_exit(smp2p, smp2p->clock_query_irq);
|
2021-08-20 11:01:28 -05:00
|
|
|
/* We won't get notified any more; drop power reference (if any) */
|
|
|
|
ipa_smp2p_power_release(ipa);
|
2020-03-05 22:28:28 -06:00
|
|
|
ipa->smp2p = NULL;
|
|
|
|
mutex_destroy(&smp2p->mutex);
|
|
|
|
kfree(smp2p);
|
|
|
|
}
|
|
|
|
|
net: ipa: separate disabling setup from modem stop
The IPA setup_complete flag is set at the end of ipa_setup(), when
the setup phase of initialization has completed successfully. This
occurs as part of driver probe processing, or (if "modem-init" is
specified in the DTS file) it is triggered by the "ipa-setup-ready"
SMP2P interrupt generated by the modem.
In the latter case, it's possible for driver shutdown (or remove) to
begin while setup processing is underway, and this can't be allowed.
The problem is that the setup_complete flag is not adequate to signal
that setup is underway.
If setup_complete is set, it will never be un-set, so that case is
not a problem. But if setup_complete is false, there's a chance
setup is underway.
Because setup is triggered by an interrupt on a "modem-init" system,
there is a simple way to ensure the value of setup_complete is safe
to read. The threaded handler--if it is executing--will complete as
part of a request to disable the "ipa-modem-ready" interrupt. This
means that ipa_setup() (which is called from the handler) will run
to completion if it was underway, or will never be called otherwise.
The request to disable the "ipa-setup-ready" interrupt is currently
made within ipa_modem_stop(). Instead, disable the interrupt
outside that function in the two places it's called. In the case of
ipa_remove(), this ensures the setup_complete flag is safe to read
before we read it.
Rename ipa_smp2p_disable() to be ipa_smp2p_irq_disable_setup(), to be
more specific about its effect.
Fixes: 530f9216a953 ("soc: qcom: ipa: AP/modem communications")
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-11-22 18:15:55 -06:00
|
|
|
void ipa_smp2p_irq_disable_setup(struct ipa *ipa)
|
2020-03-05 22:28:28 -06:00
|
|
|
{
|
|
|
|
struct ipa_smp2p *smp2p = ipa->smp2p;
|
|
|
|
|
|
|
|
if (!smp2p->setup_ready_irq)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mutex_lock(&smp2p->mutex);
|
|
|
|
|
2021-11-22 18:15:54 -06:00
|
|
|
if (!smp2p->setup_disabled) {
|
|
|
|
disable_irq(smp2p->setup_ready_irq);
|
|
|
|
smp2p->setup_disabled = true;
|
|
|
|
}
|
2020-03-05 22:28:28 -06:00
|
|
|
|
|
|
|
mutex_unlock(&smp2p->mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset state tracking whether we have notified the modem */
|
|
|
|
void ipa_smp2p_notify_reset(struct ipa *ipa)
|
|
|
|
{
|
|
|
|
struct ipa_smp2p *smp2p = ipa->smp2p;
|
|
|
|
u32 mask;
|
|
|
|
|
|
|
|
if (!smp2p->notified)
|
|
|
|
return;
|
|
|
|
|
2021-08-20 11:01:28 -05:00
|
|
|
ipa_smp2p_power_release(ipa);
|
2020-03-05 22:28:28 -06:00
|
|
|
|
2021-08-20 11:01:28 -05:00
|
|
|
/* Reset the power enabled valid flag */
|
2020-03-05 22:28:28 -06:00
|
|
|
mask = BIT(smp2p->valid_bit);
|
|
|
|
qcom_smem_state_update_bits(smp2p->valid_state, mask, 0);
|
|
|
|
|
2021-08-20 11:01:28 -05:00
|
|
|
/* Mark the power disabled for good measure... */
|
2020-03-05 22:28:28 -06:00
|
|
|
mask = BIT(smp2p->enabled_bit);
|
|
|
|
qcom_smem_state_update_bits(smp2p->enabled_state, mask, 0);
|
|
|
|
|
|
|
|
smp2p->notified = false;
|
|
|
|
}
|