diff mbox series

[5/7] memory: renesas-rpc-if: Move resource acquisition to .probe()

Message ID 2fd9b9e3f60fe555d9dcad499c90e3ec869aa96e.1656341824.git.geert+renesas@glider.be (mailing list archive)
State New, archived
Headers show
Series memory: renesas-rpc-if: Rebind and s2ram fixes | expand

Commit Message

Geert Uytterhoeven June 27, 2022, 3:31 p.m. UTC
While the acquired resources are tied to the lifetime of the RPC-IF core
device (through the use of managed resource functions), the actual
resource acquisition is triggered from the HyperBus and SPI child
drivers.  Due to this mismatch, unbinding and rebinding the child
drivers manually fails with -EBUSY:

    # echo rpc-if-hyperflash > /sys/bus/platform/drivers/rpc-if-hyperflash/unbind
    # echo rpc-if-hyperflash > /sys/bus/platform/drivers/rpc-if-hyperflash/bind
    rpc-if ee200000.spi: can't request region for resource [mem 0xee200000-0xee2001ff]
    rpc-if-hyperflash: probe of rpc-if-hyperflash failed with error -16

Fix this by moving all resource acquisition to the core driver's probe
routine.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/memory/renesas-rpc-if.c | 47 ++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 24 deletions(-)

Comments

Krzysztof Kozlowski June 29, 2022, 5:44 p.m. UTC | #1
On 27/06/2022 17:31, Geert Uytterhoeven wrote:
> While the acquired resources are tied to the lifetime of the RPC-IF core
> device (through the use of managed resource functions), the actual
> resource acquisition is triggered from the HyperBus and SPI child
> drivers.  Due to this mismatch, unbinding and rebinding the child
> drivers manually fails with -EBUSY:
> 
>     # echo rpc-if-hyperflash > /sys/bus/platform/drivers/rpc-if-hyperflash/unbind
>     # echo rpc-if-hyperflash > /sys/bus/platform/drivers/rpc-if-hyperflash/bind
>     rpc-if ee200000.spi: can't request region for resource [mem 0xee200000-0xee2001ff]
>     rpc-if-hyperflash: probe of rpc-if-hyperflash failed with error -16
> 
> Fix this by moving all resource acquisition to the core driver's probe
> routine.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

This looks like a fix, so how about putting it as first in the series,
so backporting is easy/automatic? Plus a fixes tag?

Best regards,
Krzysztof
Geert Uytterhoeven June 29, 2022, 5:55 p.m. UTC | #2
Hi Krzysztof,

On Wed, Jun 29, 2022 at 7:44 PM Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:
> On 27/06/2022 17:31, Geert Uytterhoeven wrote:
> > While the acquired resources are tied to the lifetime of the RPC-IF core
> > device (through the use of managed resource functions), the actual
> > resource acquisition is triggered from the HyperBus and SPI child
> > drivers.  Due to this mismatch, unbinding and rebinding the child
> > drivers manually fails with -EBUSY:
> >
> >     # echo rpc-if-hyperflash > /sys/bus/platform/drivers/rpc-if-hyperflash/unbind
> >     # echo rpc-if-hyperflash > /sys/bus/platform/drivers/rpc-if-hyperflash/bind
> >     rpc-if ee200000.spi: can't request region for resource [mem 0xee200000-0xee2001ff]
> >     rpc-if-hyperflash: probe of rpc-if-hyperflash failed with error -16
> >
> > Fix this by moving all resource acquisition to the core driver's probe
> > routine.
> >
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
>
> This looks like a fix, so how about putting it as first in the series,
> so backporting is easy/automatic?

Unfortunately that is not as simple as it sounds, as this really
depends on patch 4.
I agree patches 1-3 could be moved later, if you think it is worthwhile.

> Plus a fixes tag?

It's been like that since forever.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Krzysztof Kozlowski June 29, 2022, 6:25 p.m. UTC | #3
On 29/06/2022 19:55, Geert Uytterhoeven wrote:
> Hi Krzysztof,
> 
> On Wed, Jun 29, 2022 at 7:44 PM Krzysztof Kozlowski
> <krzysztof.kozlowski@linaro.org> wrote:
>> On 27/06/2022 17:31, Geert Uytterhoeven wrote:
>>> While the acquired resources are tied to the lifetime of the RPC-IF core
>>> device (through the use of managed resource functions), the actual
>>> resource acquisition is triggered from the HyperBus and SPI child
>>> drivers.  Due to this mismatch, unbinding and rebinding the child
>>> drivers manually fails with -EBUSY:
>>>
>>>     # echo rpc-if-hyperflash > /sys/bus/platform/drivers/rpc-if-hyperflash/unbind
>>>     # echo rpc-if-hyperflash > /sys/bus/platform/drivers/rpc-if-hyperflash/bind
>>>     rpc-if ee200000.spi: can't request region for resource [mem 0xee200000-0xee2001ff]
>>>     rpc-if-hyperflash: probe of rpc-if-hyperflash failed with error -16
>>>
>>> Fix this by moving all resource acquisition to the core driver's probe
>>> routine.
>>>
>>> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
>>
>> This looks like a fix, so how about putting it as first in the series,
>> so backporting is easy/automatic?
> 
> Unfortunately that is not as simple as it sounds, as this really
> depends on patch 4.

You sure? Except rebasing I don't see that. rpcif_sw_init() received the
rpcif so it had access to all fields.


> I agree patches 1-3 could be moved later, if you think it is worthwhile.

This would not be enough, it has to be first patch to be backportable.

Best regards,
Krzysztof
Geert Uytterhoeven June 29, 2022, 6:48 p.m. UTC | #4
Hi Krzysztof,

On Wed, Jun 29, 2022 at 8:26 PM Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:
> On 29/06/2022 19:55, Geert Uytterhoeven wrote:
> > On Wed, Jun 29, 2022 at 7:44 PM Krzysztof Kozlowski
> > <krzysztof.kozlowski@linaro.org> wrote:
> >> On 27/06/2022 17:31, Geert Uytterhoeven wrote:
> >>> While the acquired resources are tied to the lifetime of the RPC-IF core
> >>> device (through the use of managed resource functions), the actual
> >>> resource acquisition is triggered from the HyperBus and SPI child
> >>> drivers.  Due to this mismatch, unbinding and rebinding the child
> >>> drivers manually fails with -EBUSY:
> >>>
> >>>     # echo rpc-if-hyperflash > /sys/bus/platform/drivers/rpc-if-hyperflash/unbind
> >>>     # echo rpc-if-hyperflash > /sys/bus/platform/drivers/rpc-if-hyperflash/bind
> >>>     rpc-if ee200000.spi: can't request region for resource [mem 0xee200000-0xee2001ff]
> >>>     rpc-if-hyperflash: probe of rpc-if-hyperflash failed with error -16
> >>>
> >>> Fix this by moving all resource acquisition to the core driver's probe
> >>> routine.
> >>>
> >>> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> >>
> >> This looks like a fix, so how about putting it as first in the series,
> >> so backporting is easy/automatic?
> >
> > Unfortunately that is not as simple as it sounds, as this really
> > depends on patch 4.
>
> You sure? Except rebasing I don't see that. rpcif_sw_init() received the
> rpcif so it had access to all fields.

Yes I am, don't be misguided by the name of the local variable.
The rpcif structure is allocated by the HF or SPI child driver,
and thus not available in the RPC core driver's .probe() function.
The rpc_priv structure (as of patch 4) is allocated by the RPC core driver.

> > I agree patches 1-3 could be moved later, if you think it is worthwhile.
>
> This would not be enough, it has to be first patch to be backportable.

I can make it second? ;-)
Note that that still precludes (easily) backporting s2ram support.

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Krzysztof Kozlowski June 30, 2022, 8:48 a.m. UTC | #5
On 29/06/2022 20:48, Geert Uytterhoeven wrote:
>>
>> You sure? Except rebasing I don't see that. rpcif_sw_init() received the
>> rpcif so it had access to all fields.
> 
> Yes I am, don't be misguided by the name of the local variable.
> The rpcif structure is allocated by the HF or SPI child driver,
> and thus not available in the RPC core driver's .probe() function.
> The rpc_priv structure (as of patch 4) is allocated by the RPC core driver.
> 
>>> I agree patches 1-3 could be moved later, if you think it is worthwhile.
>>
>> This would not be enough, it has to be first patch to be backportable.
> 
> I can make it second? ;-)

Why? The point is that this commit should have Fixes or Cc-stable tag.
If you make it depending on other non-backportable commit, stable folks
cannot pull it automatically.

> Note that that still precludes (easily) backporting s2ram support.

But S2R is a feature so it won't be backported...

Best regards,
Krzysztof
Geert Uytterhoeven June 30, 2022, 9:15 a.m. UTC | #6
Hi Krzysztof,

On Thu, Jun 30, 2022 at 10:48 AM Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:
> On 29/06/2022 20:48, Geert Uytterhoeven wrote:
> >> You sure? Except rebasing I don't see that. rpcif_sw_init() received the
> >> rpcif so it had access to all fields.
> >
> > Yes I am, don't be misguided by the name of the local variable.
> > The rpcif structure is allocated by the HF or SPI child driver,
> > and thus not available in the RPC core driver's .probe() function.
> > The rpc_priv structure (as of patch 4) is allocated by the RPC core driver.
> >
> >>> I agree patches 1-3 could be moved later, if you think it is worthwhile.
> >>
> >> This would not be enough, it has to be first patch to be backportable.
> >
> > I can make it second? ;-)
>
> Why? The point is that this commit should have Fixes or Cc-stable tag.
> If you make it depending on other non-backportable commit, stable folks
> cannot pull it automatically.

Because the current driver structure does not allow us to fix the
problem in a simple way.  Hence the need for patch 4 first.

> > Note that that still precludes (easily) backporting s2ram support.
>
> But S2R is a feature so it won't be backported...

Working rebind is a feature, too?

Actually non-working s2ram is worse, as it returns corrupted data
(haven't dared to try writing after s2ram yet ;-),  while non-working
rebind means you just cannot access the device anymore.

But note there are still issues with s2ram...

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
diff mbox series

Patch

diff --git a/drivers/memory/renesas-rpc-if.c b/drivers/memory/renesas-rpc-if.c
index 78e10a7300411191..ef0336cbb4c196fb 100644
--- a/drivers/memory/renesas-rpc-if.c
+++ b/drivers/memory/renesas-rpc-if.c
@@ -276,31 +276,7 @@  static const struct regmap_config rpcif_regmap_config = {
 
 int rpcif_sw_init(struct rpcif *rpcif, struct device *dev)
 {
-	struct platform_device *pdev = to_platform_device(dev);
 	struct rpcif_priv *rpc = dev_get_drvdata(dev);
-	struct resource *res;
-
-	rpc->base = devm_platform_ioremap_resource_byname(pdev, "regs");
-	if (IS_ERR(rpc->base))
-		return PTR_ERR(rpc->base);
-
-	rpc->regmap = devm_regmap_init(dev, NULL, rpc, &rpcif_regmap_config);
-	if (IS_ERR(rpc->regmap)) {
-		dev_err(dev, "failed to init regmap for rpcif, error %ld\n",
-			PTR_ERR(rpc->regmap));
-		return	PTR_ERR(rpc->regmap);
-	}
-
-	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dirmap");
-	rpc->dirmap = devm_ioremap_resource(dev, res);
-	if (IS_ERR(rpc->dirmap))
-		return PTR_ERR(rpc->dirmap);
-	rpc->size = resource_size(res);
-
-	rpc->type = (uintptr_t)of_device_get_match_data(dev);
-	rpc->rstc = devm_reset_control_get_exclusive(dev, NULL);
-	if (IS_ERR(rpc->rstc))
-		return PTR_ERR(rpc->rstc);
 
 	rpcif->dev = dev;
 	rpcif->dirmap = rpc->dirmap;
@@ -707,6 +683,7 @@  static int rpcif_probe(struct platform_device *pdev)
 	struct platform_device *vdev;
 	struct device_node *flash;
 	struct rpcif_priv *rpc;
+	struct resource *res;
 	const char *name;
 	int ret;
 
@@ -731,6 +708,28 @@  static int rpcif_probe(struct platform_device *pdev)
 	if (!rpc)
 		return -ENOMEM;
 
+	rpc->base = devm_platform_ioremap_resource_byname(pdev, "regs");
+	if (IS_ERR(rpc->base))
+		return PTR_ERR(rpc->base);
+
+	rpc->regmap = devm_regmap_init(dev, NULL, rpc, &rpcif_regmap_config);
+	if (IS_ERR(rpc->regmap)) {
+		dev_err(dev, "failed to init regmap for rpcif, error %ld\n",
+			PTR_ERR(rpc->regmap));
+		return	PTR_ERR(rpc->regmap);
+	}
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dirmap");
+	rpc->dirmap = devm_ioremap_resource(dev, res);
+	if (IS_ERR(rpc->dirmap))
+		return PTR_ERR(rpc->dirmap);
+	rpc->size = resource_size(res);
+
+	rpc->type = (uintptr_t)of_device_get_match_data(dev);
+	rpc->rstc = devm_reset_control_get_exclusive(dev, NULL);
+	if (IS_ERR(rpc->rstc))
+		return PTR_ERR(rpc->rstc);
+
 	vdev = platform_device_alloc(name, pdev->id);
 	if (!vdev)
 		return -ENOMEM;