Skip to content

Commit c112506

Browse files
committed
Merge branch 'ipa-kill-off-ipa_clock_get'
Alex Elder says: ==================== net: ipa: kill off ipa_clock_get() This series replaces the remaining uses of ipa_clock_get() with calls to pm_runtime_get_sync() instead. It replaces all calls to ipa_clock_put() with calls to pm_runtime_put(). This completes the preparation for enabling automated suspend under the control of the power management core code. The next patch (in an upcoming series) enables that. Then the "ipa_clock" files and symbols will switch to using an "ipa_power" naming convention instead. Additional info It is possible for pm_runtime_get_sync() to return an error. There are really three cases, identified by return value: - 1, meaning power was already active - 0, meaning power was not previously active, but is now - EACCES, meaning runtime PM is disabled One additional case is EINVAL, meaning a previous suspend or resume (or idle) call returned an error. But we have always assumed this won't happen (we previously didn't even check for an error). But because we use pm_runtime_force_suspend() to implement system suspend, there's a chance we'd get an EACCES error (the first thing that function does is disable runtime suspend). Individual patches explain what happens in that case, but generally we just accept that it could be an unlikely problem (occurring only at startup time). Similarly, pm_runtime_put() could return an error. There too, we ignore EINVAL, assuming the IPA suspend and resume operations won't produce an error. EBUSY and EPERM are not applicable, EAGAIN is not expected (and harmless). We should never get EACCES (runtime suspend disabled), because pm_runtime_put() calls match prior pm_runtime_get_sync() calls, and a system suspend will not be started while a runtime suspend or resume is underway. In summary, the value returned from pm_runtime_put() is not meaningful, so we explicitly ignore it. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents b8e36e1 + c3f115a commit c112506

File tree

7 files changed

+65
-92
lines changed

7 files changed

+65
-92
lines changed

drivers/net/ipa/ipa_clock.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -272,23 +272,6 @@ static int ipa_runtime_idle(struct device *dev)
272272
return -EAGAIN;
273273
}
274274

275-
/* Get an IPA clock reference. If the reference count is non-zero, it is
276-
* incremented and return is immediate. Otherwise the IPA clock is
277-
* enabled.
278-
*/
279-
int ipa_clock_get(struct ipa *ipa)
280-
{
281-
return pm_runtime_get_sync(&ipa->pdev->dev);
282-
}
283-
284-
/* Attempt to remove an IPA clock reference. If this represents the
285-
* last reference, disable the IPA clock.
286-
*/
287-
int ipa_clock_put(struct ipa *ipa)
288-
{
289-
return pm_runtime_put(&ipa->pdev->dev);
290-
}
291-
292275
static int ipa_suspend(struct device *dev)
293276
{
294277
struct ipa *ipa = dev_get_drvdata(dev);

drivers/net/ipa/ipa_clock.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,4 @@ struct ipa_clock *ipa_clock_init(struct device *dev,
7070
*/
7171
void ipa_clock_exit(struct ipa_clock *clock);
7272

73-
/**
74-
* ipa_clock_get() - Get an IPA clock reference
75-
* @ipa: IPA pointer
76-
*
77-
* Return: 0 if clock started, 1 if clock already running, or a negative
78-
* error code
79-
*
80-
* This call blocks if this is the first reference. A reference is
81-
* taken even if an error occurs starting the IPA clock.
82-
*/
83-
int ipa_clock_get(struct ipa *ipa);
84-
85-
/**
86-
* ipa_clock_put() - Drop an IPA clock reference
87-
* @ipa: IPA pointer
88-
*
89-
* Return: 0 if successful, or a negative error code
90-
*
91-
* This drops a clock reference. If the last reference is being dropped,
92-
* the clock is stopped and RX endpoints are suspended. This call will
93-
* not block unless the last reference is dropped.
94-
*/
95-
int ipa_clock_put(struct ipa *ipa);
96-
9773
#endif /* _IPA_CLOCK_H_ */

drivers/net/ipa/ipa_interrupt.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
#include <linux/types.h>
2323
#include <linux/interrupt.h>
24+
#include <linux/pm_runtime.h>
2425

2526
#include "ipa.h"
26-
#include "ipa_clock.h"
2727
#include "ipa_reg.h"
2828
#include "ipa_endpoint.h"
2929
#include "ipa_interrupt.h"
@@ -80,14 +80,16 @@ static irqreturn_t ipa_isr_thread(int irq, void *dev_id)
8080
struct ipa_interrupt *interrupt = dev_id;
8181
struct ipa *ipa = interrupt->ipa;
8282
u32 enabled = interrupt->enabled;
83+
struct device *dev;
8384
u32 pending;
8485
u32 offset;
8586
u32 mask;
8687
int ret;
8788

88-
ret = ipa_clock_get(ipa);
89+
dev = &ipa->pdev->dev;
90+
ret = pm_runtime_get_sync(dev);
8991
if (WARN_ON(ret < 0))
90-
goto out_clock_put;
92+
goto out_power_put;
9193

9294
/* The status register indicates which conditions are present,
9395
* including conditions whose interrupt is not enabled. Handle
@@ -108,15 +110,13 @@ static irqreturn_t ipa_isr_thread(int irq, void *dev_id)
108110

109111
/* If any disabled interrupts are pending, clear them */
110112
if (pending) {
111-
struct device *dev = &ipa->pdev->dev;
112-
113113
dev_dbg(dev, "clearing disabled IPA interrupts 0x%08x\n",
114114
pending);
115115
offset = ipa_reg_irq_clr_offset(ipa->version);
116116
iowrite32(pending, ipa->reg_virt + offset);
117117
}
118-
out_clock_put:
119-
(void)ipa_clock_put(ipa);
118+
out_power_put:
119+
(void)pm_runtime_put(dev);
120120

121121
return IRQ_HANDLED;
122122
}

drivers/net/ipa/ipa_main.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/of.h>
1616
#include <linux/of_device.h>
1717
#include <linux/of_address.h>
18+
#include <linux/pm_runtime.h>
1819
#include <linux/qcom_scm.h>
1920
#include <linux/soc/qcom/mdt_loader.h>
2021

@@ -737,13 +738,13 @@ static int ipa_probe(struct platform_device *pdev)
737738
goto err_table_exit;
738739

739740
/* The clock needs to be active for config and setup */
740-
ret = ipa_clock_get(ipa);
741+
ret = pm_runtime_get_sync(dev);
741742
if (WARN_ON(ret < 0))
742-
goto err_clock_put;
743+
goto err_power_put;
743744

744745
ret = ipa_config(ipa, data);
745746
if (ret)
746-
goto err_clock_put;
747+
goto err_power_put;
747748

748749
dev_info(dev, "IPA driver initialized");
749750

@@ -765,14 +766,14 @@ static int ipa_probe(struct platform_device *pdev)
765766
if (ret)
766767
goto err_deconfig;
767768
done:
768-
(void)ipa_clock_put(ipa);
769+
(void)pm_runtime_put(dev);
769770

770771
return 0;
771772

772773
err_deconfig:
773774
ipa_deconfig(ipa);
774-
err_clock_put:
775-
(void)ipa_clock_put(ipa);
775+
err_power_put:
776+
(void)pm_runtime_put(dev);
776777
ipa_modem_exit(ipa);
777778
err_table_exit:
778779
ipa_table_exit(ipa);
@@ -798,9 +799,9 @@ static int ipa_remove(struct platform_device *pdev)
798799
struct ipa_clock *clock = ipa->clock;
799800
int ret;
800801

801-
ret = ipa_clock_get(ipa);
802+
ret = pm_runtime_get_sync(&pdev->dev);
802803
if (WARN_ON(ret < 0))
803-
goto out_clock_put;
804+
goto out_power_put;
804805

805806
if (ipa->setup_complete) {
806807
ret = ipa_modem_stop(ipa);
@@ -816,8 +817,8 @@ static int ipa_remove(struct platform_device *pdev)
816817
}
817818

818819
ipa_deconfig(ipa);
819-
out_clock_put:
820-
(void)ipa_clock_put(ipa);
820+
out_power_put:
821+
(void)pm_runtime_put(&pdev->dev);
821822

822823
ipa_modem_exit(ipa);
823824
ipa_table_exit(ipa);

drivers/net/ipa/ipa_modem.c

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,32 @@ static int ipa_open(struct net_device *netdev)
4949
{
5050
struct ipa_priv *priv = netdev_priv(netdev);
5151
struct ipa *ipa = priv->ipa;
52+
struct device *dev;
5253
int ret;
5354

54-
ret = ipa_clock_get(ipa);
55-
if (WARN_ON(ret < 0))
56-
goto err_clock_put;
55+
dev = &ipa->pdev->dev;
56+
ret = pm_runtime_get_sync(dev);
57+
if (ret < 0)
58+
goto err_power_put;
5759

5860
ret = ipa_endpoint_enable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]);
5961
if (ret)
60-
goto err_clock_put;
62+
goto err_power_put;
6163

6264
ret = ipa_endpoint_enable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]);
6365
if (ret)
6466
goto err_disable_tx;
6567

6668
netif_start_queue(netdev);
6769

68-
(void)ipa_clock_put(ipa);
70+
(void)pm_runtime_put(dev);
6971

7072
return 0;
7173

7274
err_disable_tx:
7375
ipa_endpoint_disable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]);
74-
err_clock_put:
75-
(void)ipa_clock_put(ipa);
76+
err_power_put:
77+
(void)pm_runtime_put(dev);
7678

7779
return ret;
7880
}
@@ -82,18 +84,20 @@ static int ipa_stop(struct net_device *netdev)
8284
{
8385
struct ipa_priv *priv = netdev_priv(netdev);
8486
struct ipa *ipa = priv->ipa;
87+
struct device *dev;
8588
int ret;
8689

87-
ret = ipa_clock_get(ipa);
88-
if (WARN_ON(ret < 0))
89-
goto out_clock_put;
90+
dev = &ipa->pdev->dev;
91+
ret = pm_runtime_get_sync(dev);
92+
if (ret < 0)
93+
goto out_power_put;
9094

9195
netif_stop_queue(netdev);
9296

9397
ipa_endpoint_disable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_RX]);
9498
ipa_endpoint_disable_one(ipa->name_map[IPA_ENDPOINT_AP_MODEM_TX]);
95-
out_clock_put:
96-
(void)ipa_clock_put(ipa);
99+
out_power_put:
100+
(void)pm_runtime_put(dev);
97101

98102
return 0;
99103
}
@@ -362,9 +366,11 @@ static void ipa_modem_crashed(struct ipa *ipa)
362366
struct device *dev = &ipa->pdev->dev;
363367
int ret;
364368

365-
ret = ipa_clock_get(ipa);
366-
if (WARN_ON(ret < 0))
367-
goto out_clock_put;
369+
ret = pm_runtime_get_sync(dev);
370+
if (ret < 0) {
371+
dev_err(dev, "error %d getting power to handle crash\n", ret);
372+
goto out_power_put;
373+
}
368374

369375
ipa_endpoint_modem_pause_all(ipa, true);
370376

@@ -391,8 +397,8 @@ static void ipa_modem_crashed(struct ipa *ipa)
391397
if (ret)
392398
dev_err(dev, "error %d zeroing modem memory regions\n", ret);
393399

394-
out_clock_put:
395-
(void)ipa_clock_put(ipa);
400+
out_power_put:
401+
(void)pm_runtime_put(dev);
396402
}
397403

398404
static int ipa_modem_notify(struct notifier_block *nb, unsigned long action,

drivers/net/ipa/ipa_smp2p.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "ipa_smp2p.h"
1717
#include "ipa.h"
1818
#include "ipa_uc.h"
19-
#include "ipa_clock.h"
2019

2120
/**
2221
* DOC: IPA SMP2P communication with the modem
@@ -153,6 +152,7 @@ static void ipa_smp2p_panic_notifier_unregister(struct ipa_smp2p *smp2p)
153152
static irqreturn_t ipa_smp2p_modem_setup_ready_isr(int irq, void *dev_id)
154153
{
155154
struct ipa_smp2p *smp2p = dev_id;
155+
struct device *dev;
156156
int ret;
157157

158158
mutex_lock(&smp2p->mutex);
@@ -161,17 +161,20 @@ static irqreturn_t ipa_smp2p_modem_setup_ready_isr(int irq, void *dev_id)
161161
goto out_mutex_unlock;
162162
smp2p->disabled = true; /* If any others arrive, ignore them */
163163

164-
/* The clock needs to be active for setup */
165-
ret = ipa_clock_get(smp2p->ipa);
166-
if (WARN_ON(ret < 0))
167-
goto out_clock_put;
164+
/* Power needs to be active for setup */
165+
dev = &smp2p->ipa->pdev->dev;
166+
ret = pm_runtime_get_sync(dev);
167+
if (ret < 0) {
168+
dev_err(dev, "error %d getting power for setup\n", ret);
169+
goto out_power_put;
170+
}
168171

169172
/* An error here won't cause driver shutdown, so warn if one occurs */
170173
ret = ipa_setup(smp2p->ipa);
171174
WARN(ret != 0, "error %d from ipa_setup()\n", ret);
172175

173-
out_clock_put:
174-
(void)ipa_clock_put(smp2p->ipa);
176+
out_power_put:
177+
(void)pm_runtime_put(dev);
175178
out_mutex_unlock:
176179
mutex_unlock(&smp2p->mutex);
177180

@@ -211,7 +214,7 @@ static void ipa_smp2p_clock_release(struct ipa *ipa)
211214
if (!ipa->smp2p->clock_on)
212215
return;
213216

214-
(void)ipa_clock_put(ipa);
217+
(void)pm_runtime_put(&ipa->pdev->dev);
215218
ipa->smp2p->clock_on = false;
216219
}
217220

drivers/net/ipa/ipa_uc.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
#include <linux/types.h>
88
#include <linux/io.h>
99
#include <linux/delay.h>
10+
#include <linux/pm_runtime.h>
1011

1112
#include "ipa.h"
12-
#include "ipa_clock.h"
1313
#include "ipa_uc.h"
1414

1515
/**
@@ -154,7 +154,7 @@ static void ipa_uc_response_hdlr(struct ipa *ipa, enum ipa_irq_id irq_id)
154154
case IPA_UC_RESPONSE_INIT_COMPLETED:
155155
if (ipa->uc_clocked) {
156156
ipa->uc_loaded = true;
157-
(void)ipa_clock_put(ipa);
157+
(void)pm_runtime_put(dev);
158158
ipa->uc_clocked = false;
159159
} else {
160160
dev_warn(dev, "unexpected init_completed response\n");
@@ -182,25 +182,29 @@ void ipa_uc_deconfig(struct ipa *ipa)
182182
ipa_interrupt_remove(ipa->interrupt, IPA_IRQ_UC_1);
183183
ipa_interrupt_remove(ipa->interrupt, IPA_IRQ_UC_0);
184184
if (ipa->uc_clocked)
185-
(void)ipa_clock_put(ipa);
185+
(void)pm_runtime_put(&ipa->pdev->dev);
186186
}
187187

188188
/* Take a proxy clock reference for the microcontroller */
189189
void ipa_uc_clock(struct ipa *ipa)
190190
{
191191
static bool already;
192+
struct device *dev;
192193
int ret;
193194

194195
if (already)
195196
return;
196197
already = true; /* Only do this on first boot */
197198

198-
/* This clock reference dropped in ipa_uc_response_hdlr() above */
199-
ret = ipa_clock_get(ipa);
200-
if (WARN(ret < 0, "error %d getting proxy clock\n", ret))
201-
(void)ipa_clock_put(ipa);
202-
203-
ipa->uc_clocked = ret >= 0;
199+
/* This power reference dropped in ipa_uc_response_hdlr() above */
200+
dev = &ipa->pdev->dev;
201+
ret = pm_runtime_get_sync(dev);
202+
if (ret < 0) {
203+
pm_runtime_put_noidle(dev);
204+
dev_err(dev, "error %d getting proxy power\n", ret);
205+
} else {
206+
ipa->uc_clocked = true;
207+
}
204208
}
205209

206210
/* Send a command to the microcontroller */

0 commit comments

Comments
 (0)