Skip to contentSkip to conversation

PCI: rcar: Use runtime PM to control controller clock

PATCH Applied Marek Vasut 4 participants 21 messages Apr 8, 2018 – May 21, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 PCI: rcar: Use runtime PM to control controller clock

From: Dien Pham <[email protected]>

The controller clock can be switched off during suspend/resume, let runtime PM take care of that.

Cc Geert Uytterhoeven <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Phil Edworthy <[email protected]>
Cc Simon Horman <[email protected]>
Cc Wolfram Sang <[email protected]>

To: [email protected]
---
V2: - Reorder the fail path in rcar_pcie_probe() to cater for the
reordering of function calls in probe
- Dispose of fail_clk in rcar_pcie_get_resources()
V3: - Fix up the failpath in probe function
V4: - Rebase on recent linux-next
V5: - Do not call pci_free_resource_list(&pcie->resources) if
rcar_pcie_parse_request_of_pci_ranges() fails, since that functiona calls pci_free_resource_list() already.

---
 drivers/pci/host/pcie-rcar.c | 38 ++++++++++++--------------------------
 1 file changed, 12 insertions(+), 26 deletions(-)
drivers/pci/host/pcie-rcar.c +12 -26
index 6ab28f29ac6a..25f68305322c 100644
@@ -142,7 +142,6 @@ struct rcar_pcie {
 	void __iomem		*base;
 	struct list_head	resources;
 	int			root_bus_nr;
-	struct clk		*clk;
 	struct clk		*bus_clk;
 	struct			rcar_msi msi;
 };
@@ -914,24 +913,14 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 	if (IS_ERR(pcie->base))
 		return PTR_ERR(pcie->base);
 
-	pcie->clk = devm_clk_get(dev, "pcie");
-	if (IS_ERR(pcie->clk)) {
-		dev_err(dev, "cannot get platform clock\n");
-		return PTR_ERR(pcie->clk);
-	}
-	err = clk_prepare_enable(pcie->clk);
-	if (err)
-		return err;
-
 	pcie->bus_clk = devm_clk_get(dev, "pcie_bus");
 	if (IS_ERR(pcie->bus_clk)) {
 		dev_err(dev, "cannot get pcie bus clock\n");
-		err = PTR_ERR(pcie->bus_clk);
-		goto fail_clk;
+		return PTR_ERR(pcie->bus_clk);
 	}
 	err = clk_prepare_enable(pcie->bus_clk);
 	if (err)
-		goto fail_clk;
+		return err;
 
 	i = irq_of_parse_and_map(dev->of_node, 0);
 	if (!i) {
@@ -953,8 +942,6 @@ static int rcar_pcie_get_resources(struct rcar_pcie *pcie)
 
 err_map_reg:
 	clk_disable_unprepare(pcie->bus_clk);
-fail_clk:
-	clk_disable_unprepare(pcie->clk);
 
 	return err;
 }
@@ -1124,22 +1111,22 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 	if (err)
 		goto err_free_bridge;
 
+	pm_runtime_enable(pcie->dev);
+	err = pm_runtime_get_sync(pcie->dev);
+	if (err < 0) {
+		dev_err(pcie->dev, "pm_runtime_get_sync failed\n");
+		goto err_pm_disable;
+	}
+
 	err = rcar_pcie_get_resources(pcie);
 	if (err < 0) {
 		dev_err(dev, "failed to request resources: %d\n", err);
-		goto err_free_resource_list;
+		goto err_pm_put;
 	}
 
 	err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
 	if (err)
-		goto err_free_resource_list;
-
-	pm_runtime_enable(dev);
-	err = pm_runtime_get_sync(dev);
-	if (err < 0) {
-		dev_err(dev, "pm_runtime_get_sync failed\n");
-		goto err_pm_disable;
-	}
+		goto err_pm_put;
 
 	/* Failure to get a link might just be that no cards are inserted */
 	hw_init_fn = of_device_get_match_data(dev);
@@ -1174,9 +1161,8 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
 err_pm_disable:
 	pm_runtime_disable(dev);
-
-err_free_resource_list:
 	pci_free_resource_list(&pcie->resources);
+
 err_free_bridge:
 	pci_free_host_bridge(bridge);
 
Signature · 1 line
2.16.2
#1 lore raw

Hi Marek,

Quoted 14 lines · Marek Vasut

From: Dien Pham <[email protected]>

The controller clock can be switched off during suspend/resume, let runtime PM take care of that.

Cc Geert Uytterhoeven <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Phil Edworthy <[email protected]>
Cc Simon Horman <[email protected]>
Cc Wolfram Sang <[email protected]>
Quoted 10 lines

To: [email protected]
---
V2: - Reorder the fail path in rcar_pcie_probe() to cater for the
reordering of function calls in probe
- Dispose of fail_clk in rcar_pcie_get_resources()
V3: - Fix up the failpath in probe function
V4: - Rebase on recent linux-next
V5: - Do not call pci_free_resource_list(&pcie->resources) if
rcar_pcie_parse_request_of_pci_ranges() fails, since that functiona calls pci_free_resource_list() already.

Thanks for the update!

Quoted 4 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1120

Quoted 10 lines
drivers/pci/host/pcie-rcar.c +7 -0
@@ -1124,22 +1111,22 @@ static int rcar_pcie_probe(struct platform_device *pdev)
        if (err)
                goto err_free_bridge;
 
+       pm_runtime_enable(pcie->dev);
+       err = pm_runtime_get_sync(pcie->dev);
+       if (err < 0) {
+               dev_err(pcie->dev, "pm_runtime_get_sync failed\n");
+               goto err_pm_disable;
+       }
+

As you moved the pm_runtime setup up...

Quoted 22 lines
drivers/pci/host/pcie-rcar.c +2 -9
        err = rcar_pcie_get_resources(pcie);
        if (err < 0) {
                dev_err(dev, "failed to request resources: %d\n", err);
-               goto err_free_resource_list;
+               goto err_pm_put;
        }
 
        err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
        if (err)
-               goto err_free_resource_list;
-
-       pm_runtime_enable(dev);
-       err = pm_runtime_get_sync(dev);
-       if (err < 0) {
-               dev_err(dev, "pm_runtime_get_sync failed\n");
-               goto err_pm_disable;
-       }
+               goto err_pm_put;
 
        /* Failure to get a link might just be that no cards are inserted */
        hw_init_fn = of_device_get_match_data(dev);

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1163

Quoted 3 lines
drivers/pci/host/pcie-rcar.c +0 -0
@@ -1174,9 +1161,8 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
 err_pm_disable:
        pm_runtime_disable(dev);

... shouldn't it be moved down here, for symmetry?

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1167

Quoted 6 lines
drivers/pci/host/pcie-rcar.c +1 -2
-
-err_free_resource_list:
        pci_free_resource_list(&pcie->resources);
+
 err_free_bridge:
        pci_free_host_bridge(bridge);

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#2 lore raw
Quoted 66 lines · Geert Uytterhoeven

Hi Marek,

Quoted 14 lines · Marek Vasut

From: Dien Pham <[email protected]>

The controller clock can be switched off during suspend/resume, let runtime PM take care of that.

Cc Geert Uytterhoeven <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Phil Edworthy <[email protected]>
Cc Simon Horman <[email protected]>
Cc Wolfram Sang <[email protected]>
Quoted 10 lines

To: [email protected]
---
V2: - Reorder the fail path in rcar_pcie_probe() to cater for the
reordering of function calls in probe
- Dispose of fail_clk in rcar_pcie_get_resources()
V3: - Fix up the failpath in probe function
V4: - Rebase on recent linux-next
V5: - Do not call pci_free_resource_list(&pcie->resources) if
rcar_pcie_parse_request_of_pci_ranges() fails, since that functiona calls pci_free_resource_list() already.

Thanks for the update!

Quoted 4 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1120

Quoted 10 lines
drivers/pci/host/pcie-rcar.c +7 -0
@@ -1124,22 +1111,22 @@ static int rcar_pcie_probe(struct platform_device *pdev)
        if (err)
                goto err_free_bridge;
 
+       pm_runtime_enable(pcie->dev);
+       err = pm_runtime_get_sync(pcie->dev);
+       if (err < 0) {
+               dev_err(pcie->dev, "pm_runtime_get_sync failed\n");
+               goto err_pm_disable;
+       }
+

As you moved the pm_runtime setup up...

Quoted 19 lines
drivers/pci/host/pcie-rcar.c +2 -9
        err = rcar_pcie_get_resources(pcie);
        if (err < 0) {
                dev_err(dev, "failed to request resources: %d\n", err);
-               goto err_free_resource_list;
+               goto err_pm_put;
        }
 
        err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
        if (err)
-               goto err_free_resource_list;
-
-       pm_runtime_enable(dev);
-       err = pm_runtime_get_sync(dev);
-       if (err < 0) {
-               dev_err(dev, "pm_runtime_get_sync failed\n");
-               goto err_pm_disable;
-       }
+               goto err_pm_put;
 
Quoted 8 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1163

Quoted 6 lines
drivers/pci/host/pcie-rcar.c +0 -0
        /* Failure to get a link might just be that no cards are inserted */
        hw_init_fn = of_device_get_match_data(dev);
@@ -1174,9 +1161,8 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
 err_pm_disable:
        pm_runtime_disable(dev);

... shouldn't it be moved down here, for symmetry?

I am reasonably certain the failpath should be correct now. Did I still miss something ?

Signature · 2 lines
Best regards,
Marek Vasut
#3 lore raw
Quoted 71 lines · Marek Vasut
Quoted 70 lines · Geert Uytterhoeven

Hi Marek,

Quoted 14 lines · Marek Vasut

From: Dien Pham <[email protected]>

The controller clock can be switched off during suspend/resume, let runtime PM take care of that.

Cc Geert Uytterhoeven <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Phil Edworthy <[email protected]>
Cc Simon Horman <[email protected]>
Cc Wolfram Sang <[email protected]>
Quoted 10 lines

To: [email protected]
---
V2: - Reorder the fail path in rcar_pcie_probe() to cater for the
reordering of function calls in probe
- Dispose of fail_clk in rcar_pcie_get_resources()
V3: - Fix up the failpath in probe function
V4: - Rebase on recent linux-next
V5: - Do not call pci_free_resource_list(&pcie->resources) if
rcar_pcie_parse_request_of_pci_ranges() fails, since that functiona calls pci_free_resource_list() already.

Thanks for the update!

Quoted 4 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1120

Quoted 10 lines
drivers/pci/host/pcie-rcar.c +7 -0
@@ -1124,22 +1111,22 @@ static int rcar_pcie_probe(struct platform_device *pdev)
        if (err)
                goto err_free_bridge;
 
+       pm_runtime_enable(pcie->dev);
+       err = pm_runtime_get_sync(pcie->dev);
+       if (err < 0) {
+               dev_err(pcie->dev, "pm_runtime_get_sync failed\n");
+               goto err_pm_disable;
+       }
+

As you moved the pm_runtime setup up...

Quoted 23 lines
drivers/pci/host/pcie-rcar.c +2 -9
        err = rcar_pcie_get_resources(pcie);
        if (err < 0) {
                dev_err(dev, "failed to request resources: %d\n", err);
-               goto err_free_resource_list;
+               goto err_pm_put;
        }
 
        err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
        if (err)
-               goto err_free_resource_list;
-
-       pm_runtime_enable(dev);
-       err = pm_runtime_get_sync(dev);
-       if (err < 0) {
-               dev_err(dev, "pm_runtime_get_sync failed\n");
-               goto err_pm_disable;
-       }
+               goto err_pm_put;
 
        /* Failure to get a link might just be that no cards are inserted */
        hw_init_fn = of_device_get_match_data(dev);
@@ -1174,9 +1161,8 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
Quoted 7 lines
Quoted 4 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1163

Quoted 2 lines
drivers/pci/host/pcie-rcar.c +0 -0
 err_pm_disable:
        pm_runtime_disable(dev);

... shouldn't it be moved down here, for symmetry?

I am reasonably certain the failpath should be correct now. Did I still miss something ?

It looks correct to me too. Geert are Marek and I missing something?

#4 lore raw

Hi Simon, Marek,

Quoted 75 lines · Simon Horman
Quoted 74 lines · Marek Vasut
Quoted 72 lines · Geert Uytterhoeven
Quoted 14 lines · Marek Vasut

From: Dien Pham <[email protected]>

The controller clock can be switched off during suspend/resume, let runtime PM take care of that.

Cc Geert Uytterhoeven <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Phil Edworthy <[email protected]>
Cc Simon Horman <[email protected]>
Cc Wolfram Sang <[email protected]>
Quoted 10 lines

To: [email protected]
---
V2: - Reorder the fail path in rcar_pcie_probe() to cater for the
reordering of function calls in probe
- Dispose of fail_clk in rcar_pcie_get_resources()
V3: - Fix up the failpath in probe function
V4: - Rebase on recent linux-next
V5: - Do not call pci_free_resource_list(&pcie->resources) if
rcar_pcie_parse_request_of_pci_ranges() fails, since that functiona calls pci_free_resource_list() already.

Thanks for the update!

Quoted 4 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1120

Quoted 10 lines
drivers/pci/host/pcie-rcar.c +7 -0
@@ -1124,22 +1111,22 @@ static int rcar_pcie_probe(struct platform_device *pdev)
        if (err)
                goto err_free_bridge;
 
+       pm_runtime_enable(pcie->dev);
+       err = pm_runtime_get_sync(pcie->dev);
+       if (err < 0) {
+               dev_err(pcie->dev, "pm_runtime_get_sync failed\n");
+               goto err_pm_disable;
+       }
+

As you moved the pm_runtime setup up...

Quoted 22 lines
drivers/pci/host/pcie-rcar.c +2 -9
        err = rcar_pcie_get_resources(pcie);
        if (err < 0) {
                dev_err(dev, "failed to request resources: %d\n", err);
-               goto err_free_resource_list;
+               goto err_pm_put;
        }
 
        err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
        if (err)
-               goto err_free_resource_list;
-
-       pm_runtime_enable(dev);
-       err = pm_runtime_get_sync(dev);
-       if (err < 0) {
-               dev_err(dev, "pm_runtime_get_sync failed\n");
-               goto err_pm_disable;
-       }
+               goto err_pm_put;
 
        /* Failure to get a link might just be that no cards are inserted */
        hw_init_fn = of_device_get_match_data(dev);

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1163

Quoted 3 lines
drivers/pci/host/pcie-rcar.c +0 -0
@@ -1174,9 +1161,8 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
 err_pm_disable:
        pm_runtime_disable(dev);

... shouldn't it be moved down here, for symmetry?

Quoted 4 lines
Quoted 2 lines

I am reasonably certain the failpath should be correct now. Did I still miss something ?

It looks correct to me too. Geert are Marek and I missing something?

Probably it will still work fine, but after this patch, Runtime PM is enabled early, and disabled early, which is not symmetrical.

I like symmetry ;-)

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#5 lore raw
Quoted 81 lines · Geert Uytterhoeven

Hi Simon, Marek,

Quoted 78 lines · Simon Horman
Quoted 76 lines · Marek Vasut
Quoted 64 lines · Geert Uytterhoeven
Quoted 14 lines · Marek Vasut

From: Dien Pham <[email protected]>

The controller clock can be switched off during suspend/resume, let runtime PM take care of that.

Cc Geert Uytterhoeven <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Phil Edworthy <[email protected]>
Cc Simon Horman <[email protected]>
Cc Wolfram Sang <[email protected]>
Quoted 10 lines

To: [email protected]
---
V2: - Reorder the fail path in rcar_pcie_probe() to cater for the
reordering of function calls in probe
- Dispose of fail_clk in rcar_pcie_get_resources()
V3: - Fix up the failpath in probe function
V4: - Rebase on recent linux-next
V5: - Do not call pci_free_resource_list(&pcie->resources) if
rcar_pcie_parse_request_of_pci_ranges() fails, since that functiona calls pci_free_resource_list() already.

Thanks for the update!

Quoted 4 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1120

Quoted 10 lines
drivers/pci/host/pcie-rcar.c +7 -0
@@ -1124,22 +1111,22 @@ static int rcar_pcie_probe(struct platform_device *pdev)
        if (err)
                goto err_free_bridge;
 
+       pm_runtime_enable(pcie->dev);
+       err = pm_runtime_get_sync(pcie->dev);
+       if (err < 0) {
+               dev_err(pcie->dev, "pm_runtime_get_sync failed\n");
+               goto err_pm_disable;
+       }
+

As you moved the pm_runtime setup up...

Quoted 19 lines
drivers/pci/host/pcie-rcar.c +2 -9
        err = rcar_pcie_get_resources(pcie);
        if (err < 0) {
                dev_err(dev, "failed to request resources: %d\n", err);
-               goto err_free_resource_list;
+               goto err_pm_put;
        }
 
        err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
        if (err)
-               goto err_free_resource_list;
-
-       pm_runtime_enable(dev);
-       err = pm_runtime_get_sync(dev);
-       if (err < 0) {
-               dev_err(dev, "pm_runtime_get_sync failed\n");
-               goto err_pm_disable;
-       }
+               goto err_pm_put;
 
Quoted 8 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1163

Quoted 6 lines
drivers/pci/host/pcie-rcar.c +0 -0
        /* Failure to get a link might just be that no cards are inserted */
        hw_init_fn = of_device_get_match_data(dev);
@@ -1174,9 +1161,8 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
 err_pm_disable:
        pm_runtime_disable(dev);

... shouldn't it be moved down here, for symmetry?

I am reasonably certain the failpath should be correct now. Did I still miss something ?

Quoted 6 lines
Quoted 1 line

It looks correct to me too. Geert are Marek and I missing something?

Probably it will still work fine, but after this patch, Runtime PM is enabled early, and disabled early, which is not symmetrical.

I like symmetry ;-)

Understood. I think that is reasonable.
Marek, would you care to respin?

#6 lore raw
Quoted 84 lines · Simon Horman
Quoted 83 lines · Geert Uytterhoeven

Hi Simon, Marek,

Quoted 79 lines · Simon Horman
Quoted 69 lines · Marek Vasut
Quoted 68 lines · Geert Uytterhoeven
Quoted 14 lines · Marek Vasut

From: Dien Pham <[email protected]>

The controller clock can be switched off during suspend/resume, let runtime PM take care of that.

Cc Geert Uytterhoeven <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Phil Edworthy <[email protected]>
Cc Simon Horman <[email protected]>
Cc Wolfram Sang <[email protected]>
Quoted 10 lines

To: [email protected]
---
V2: - Reorder the fail path in rcar_pcie_probe() to cater for the
reordering of function calls in probe
- Dispose of fail_clk in rcar_pcie_get_resources()
V3: - Fix up the failpath in probe function
V4: - Rebase on recent linux-next
V5: - Do not call pci_free_resource_list(&pcie->resources) if
rcar_pcie_parse_request_of_pci_ranges() fails, since that functiona calls pci_free_resource_list() already.

Thanks for the update!

Quoted 4 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1120

Quoted 10 lines
drivers/pci/host/pcie-rcar.c +7 -0
@@ -1124,22 +1111,22 @@ static int rcar_pcie_probe(struct platform_device *pdev)
        if (err)
                goto err_free_bridge;
 
+       pm_runtime_enable(pcie->dev);
+       err = pm_runtime_get_sync(pcie->dev);
+       if (err < 0) {
+               dev_err(pcie->dev, "pm_runtime_get_sync failed\n");
+               goto err_pm_disable;
+       }
+

As you moved the pm_runtime setup up...

Quoted 23 lines
drivers/pci/host/pcie-rcar.c +2 -9
        err = rcar_pcie_get_resources(pcie);
        if (err < 0) {
                dev_err(dev, "failed to request resources: %d\n", err);
-               goto err_free_resource_list;
+               goto err_pm_put;
        }
 
        err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
        if (err)
-               goto err_free_resource_list;
-
-       pm_runtime_enable(dev);
-       err = pm_runtime_get_sync(dev);
-       if (err < 0) {
-               dev_err(dev, "pm_runtime_get_sync failed\n");
-               goto err_pm_disable;
-       }
+               goto err_pm_put;
 
        /* Failure to get a link might just be that no cards are inserted */
        hw_init_fn = of_device_get_match_data(dev);
@@ -1174,9 +1161,8 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
Quoted 7 lines
Quoted 4 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1163

Quoted 2 lines
drivers/pci/host/pcie-rcar.c +0 -0
 err_pm_disable:
        pm_runtime_disable(dev);

... shouldn't it be moved down here, for symmetry?

I am reasonably certain the failpath should be correct now. Did I still miss something ?

It looks correct to me too. Geert are Marek and I missing something?

Quoted 7 lines
Quoted 4 lines

Probably it will still work fine, but after this patch, Runtime PM is enabled early, and disabled early, which is not symmetrical.

I like symmetry ;-)

Understood. I think that is reasonable.
Marek, would you care to respin?

I am looking into the driver, but I fail to see what Geert is trying to make me change here.

The pairing looks as follows:

.- rcar_pcie_parse_request_of_pci_ranges()

|  (pm_runtime_enable is here)
| .- pm_runtime_get_sync()
| | .- rcar_pcie_get_resources()
| | |
| | '- pm_runtime_put()
| '- pm_runtime_disable() + pci_free_resource_list()

'- pci_free_host_bridge()

It looks symmetric to me ...

Signature · 2 lines
Best regards,
Marek Vasut
#7 lore raw

Hi Marek,

Quoted 94 lines · Marek Vasut
Quoted 82 lines · Simon Horman
Quoted 81 lines · Geert Uytterhoeven
Quoted 79 lines · Simon Horman
Quoted 69 lines · Marek Vasut
Quoted 68 lines · Geert Uytterhoeven
Quoted 14 lines · Marek Vasut

From: Dien Pham <[email protected]>

The controller clock can be switched off during suspend/resume, let runtime PM take care of that.

Cc Geert Uytterhoeven <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Phil Edworthy <[email protected]>
Cc Simon Horman <[email protected]>
Cc Wolfram Sang <[email protected]>
Quoted 10 lines

To: [email protected]
---
V2: - Reorder the fail path in rcar_pcie_probe() to cater for the
reordering of function calls in probe
- Dispose of fail_clk in rcar_pcie_get_resources()
V3: - Fix up the failpath in probe function
V4: - Rebase on recent linux-next
V5: - Do not call pci_free_resource_list(&pcie->resources) if
rcar_pcie_parse_request_of_pci_ranges() fails, since that functiona calls pci_free_resource_list() already.

Thanks for the update!

Quoted 4 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1120

Quoted 10 lines
drivers/pci/host/pcie-rcar.c +7 -0
@@ -1124,22 +1111,22 @@ static int rcar_pcie_probe(struct platform_device *pdev)
        if (err)
                goto err_free_bridge;
 
+       pm_runtime_enable(pcie->dev);
+       err = pm_runtime_get_sync(pcie->dev);
+       if (err < 0) {
+               dev_err(pcie->dev, "pm_runtime_get_sync failed\n");
+               goto err_pm_disable;
+       }
+

As you moved the pm_runtime setup up...

Quoted 23 lines
drivers/pci/host/pcie-rcar.c +2 -9
        err = rcar_pcie_get_resources(pcie);
        if (err < 0) {
                dev_err(dev, "failed to request resources: %d\n", err);
-               goto err_free_resource_list;
+               goto err_pm_put;
        }
 
        err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
        if (err)
-               goto err_free_resource_list;
-
-       pm_runtime_enable(dev);
-       err = pm_runtime_get_sync(dev);
-       if (err < 0) {
-               dev_err(dev, "pm_runtime_get_sync failed\n");
-               goto err_pm_disable;
-       }
+               goto err_pm_put;
 
        /* Failure to get a link might just be that no cards are inserted */
        hw_init_fn = of_device_get_match_data(dev);
@@ -1174,9 +1161,8 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
Quoted 7 lines
Quoted 4 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1163

Quoted 2 lines
drivers/pci/host/pcie-rcar.c +0 -0
 err_pm_disable:
        pm_runtime_disable(dev);

... shouldn't it be moved down here, for symmetry?

I am reasonably certain the failpath should be correct now. Did I still miss something ?

It looks correct to me too. Geert are Marek and I missing something?

Quoted 7 lines
Quoted 4 lines

Probably it will still work fine, but after this patch, Runtime PM is enabled early, and disabled early, which is not symmetrical.

I like symmetry ;-)

Understood. I think that is reasonable.
Marek, would you care to respin?

I am looking into the driver, but I fail to see what Geert is trying to make me change here.

Quoted 6 lines

The pairing looks as follows:

.- rcar_pcie_parse_request_of_pci_ranges()

|  (pm_runtime_enable is here)
| .- pm_runtime_get_sync()
| | .- rcar_pcie_get_resources()

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed

Quoted 3 lines
| | |
| | '- pm_runtime_put()
| '- pm_runtime_disable() + pci_free_resource_list()

pci_free_resource_list() is called while the device is runtime-disabled.

Quoted 3 lines

'- pci_free_host_bridge()

It looks symmetric to me ...

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed,
pci_free_resource_list() is called while the device is runtime-disabled.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#8 lore raw
Quoted 97 lines · Geert Uytterhoeven

Hi Marek,

Quoted 94 lines · Marek Vasut
Quoted 82 lines · Simon Horman
Quoted 81 lines · Geert Uytterhoeven
Quoted 79 lines · Simon Horman
Quoted 69 lines · Marek Vasut
Quoted 68 lines · Geert Uytterhoeven
Quoted 14 lines · Marek Vasut

From: Dien Pham <[email protected]>

The controller clock can be switched off during suspend/resume, let runtime PM take care of that.

Cc Geert Uytterhoeven <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Phil Edworthy <[email protected]>
Cc Simon Horman <[email protected]>
Cc Wolfram Sang <[email protected]>
Quoted 10 lines

To: [email protected]
---
V2: - Reorder the fail path in rcar_pcie_probe() to cater for the
reordering of function calls in probe
- Dispose of fail_clk in rcar_pcie_get_resources()
V3: - Fix up the failpath in probe function
V4: - Rebase on recent linux-next
V5: - Do not call pci_free_resource_list(&pcie->resources) if
rcar_pcie_parse_request_of_pci_ranges() fails, since that functiona calls pci_free_resource_list() already.

Thanks for the update!

Quoted 4 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1120

Quoted 10 lines
drivers/pci/host/pcie-rcar.c +7 -0
@@ -1124,22 +1111,22 @@ static int rcar_pcie_probe(struct platform_device *pdev)
        if (err)
                goto err_free_bridge;
 
+       pm_runtime_enable(pcie->dev);
+       err = pm_runtime_get_sync(pcie->dev);
+       if (err < 0) {
+               dev_err(pcie->dev, "pm_runtime_get_sync failed\n");
+               goto err_pm_disable;
+       }
+

As you moved the pm_runtime setup up...

Quoted 23 lines
drivers/pci/host/pcie-rcar.c +2 -9
        err = rcar_pcie_get_resources(pcie);
        if (err < 0) {
                dev_err(dev, "failed to request resources: %d\n", err);
-               goto err_free_resource_list;
+               goto err_pm_put;
        }
 
        err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
        if (err)
-               goto err_free_resource_list;
-
-       pm_runtime_enable(dev);
-       err = pm_runtime_get_sync(dev);
-       if (err < 0) {
-               dev_err(dev, "pm_runtime_get_sync failed\n");
-               goto err_pm_disable;
-       }
+               goto err_pm_put;
 
        /* Failure to get a link might just be that no cards are inserted */
        hw_init_fn = of_device_get_match_data(dev);
@@ -1174,9 +1161,8 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
Quoted 7 lines
Quoted 4 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1163

Quoted 2 lines
drivers/pci/host/pcie-rcar.c +0 -0
 err_pm_disable:
        pm_runtime_disable(dev);

... shouldn't it be moved down here, for symmetry?

I am reasonably certain the failpath should be correct now. Did I still miss something ?

It looks correct to me too. Geert are Marek and I missing something?

Quoted 7 lines
Quoted 4 lines

Probably it will still work fine, but after this patch, Runtime PM is enabled early, and disabled early, which is not symmetrical.

I like symmetry ;-)

Understood. I think that is reasonable.
Marek, would you care to respin?

I am looking into the driver, but I fail to see what Geert is trying to make me change here.

Quoted 8 lines
Quoted 6 lines

The pairing looks as follows:

.- rcar_pcie_parse_request_of_pci_ranges()

|  (pm_runtime_enable is here)
| .- pm_runtime_get_sync()
| | .- rcar_pcie_get_resources()

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed

Because something may access the device, yes.

Quoted 5 lines
Quoted 3 lines
| | |
| | '- pm_runtime_put()
| '- pm_runtime_disable() + pci_free_resource_list()

pci_free_resource_list() is called while the device is runtime-disabled.

Because nothing will access the device.

Quoted 7 lines
Quoted 3 lines

'- pci_free_host_bridge()

It looks symmetric to me ...

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed,
pci_free_resource_list() is called while the device is runtime-disabled.

At this point, I think I'd rather see a diff of changes which you have in mind rather than this endless discussion. Can you provide one against this patch ?

Signature · 2 lines
Best regards,
Marek Vasut
#9 lore raw

Hi Marek,

Quoted 119 lines · Marek Vasut
Quoted 95 lines · Geert Uytterhoeven
Quoted 94 lines · Marek Vasut
Quoted 82 lines · Simon Horman
Quoted 81 lines · Geert Uytterhoeven
Quoted 79 lines · Simon Horman
Quoted 69 lines · Marek Vasut
Quoted 68 lines · Geert Uytterhoeven
Quoted 14 lines · Marek Vasut

From: Dien Pham <[email protected]>

The controller clock can be switched off during suspend/resume, let runtime PM take care of that.

Cc Geert Uytterhoeven <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Phil Edworthy <[email protected]>
Cc Simon Horman <[email protected]>
Cc Wolfram Sang <[email protected]>
Quoted 10 lines

To: [email protected]
---
V2: - Reorder the fail path in rcar_pcie_probe() to cater for the
reordering of function calls in probe
- Dispose of fail_clk in rcar_pcie_get_resources()
V3: - Fix up the failpath in probe function
V4: - Rebase on recent linux-next
V5: - Do not call pci_free_resource_list(&pcie->resources) if
rcar_pcie_parse_request_of_pci_ranges() fails, since that functiona calls pci_free_resource_list() already.

Thanks for the update!

Quoted 4 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1120

Quoted 10 lines
drivers/pci/host/pcie-rcar.c +7 -0
@@ -1124,22 +1111,22 @@ static int rcar_pcie_probe(struct platform_device *pdev)
        if (err)
                goto err_free_bridge;
 
+       pm_runtime_enable(pcie->dev);
+       err = pm_runtime_get_sync(pcie->dev);
+       if (err < 0) {
+               dev_err(pcie->dev, "pm_runtime_get_sync failed\n");
+               goto err_pm_disable;
+       }
+

As you moved the pm_runtime setup up...

Quoted 23 lines
drivers/pci/host/pcie-rcar.c +2 -9
        err = rcar_pcie_get_resources(pcie);
        if (err < 0) {
                dev_err(dev, "failed to request resources: %d\n", err);
-               goto err_free_resource_list;
+               goto err_pm_put;
        }
 
        err = rcar_pcie_parse_map_dma_ranges(pcie, dev->of_node);
        if (err)
-               goto err_free_resource_list;
-
-       pm_runtime_enable(dev);
-       err = pm_runtime_get_sync(dev);
-       if (err < 0) {
-               dev_err(dev, "pm_runtime_get_sync failed\n");
-               goto err_pm_disable;
-       }
+               goto err_pm_put;
 
        /* Failure to get a link might just be that no cards are inserted */
        hw_init_fn = of_device_get_match_data(dev);
@@ -1174,9 +1161,8 @@ static int rcar_pcie_probe(struct platform_device *pdev)
 
Quoted 7 lines
Quoted 4 lines

drivers/pci/host/pcie-rcar.c static int rcar_pcie_probe(struct platform_device *pdev) · line 1163

Quoted 2 lines
drivers/pci/host/pcie-rcar.c +0 -0
 err_pm_disable:
        pm_runtime_disable(dev);

... shouldn't it be moved down here, for symmetry?

I am reasonably certain the failpath should be correct now. Did I still miss something ?

It looks correct to me too. Geert are Marek and I missing something?

Quoted 7 lines
Quoted 4 lines

Probably it will still work fine, but after this patch, Runtime PM is enabled early, and disabled early, which is not symmetrical.

I like symmetry ;-)

Understood. I think that is reasonable.
Marek, would you care to respin?

I am looking into the driver, but I fail to see what Geert is trying to make me change here.

Quoted 8 lines
Quoted 6 lines

The pairing looks as follows:

.- rcar_pcie_parse_request_of_pci_ranges()

|  (pm_runtime_enable is here)
| .- pm_runtime_get_sync()
| | .- rcar_pcie_get_resources()

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed

Because something may access the device, yes.

Quoted 5 lines
Quoted 3 lines
| | |
| | '- pm_runtime_put()
| '- pm_runtime_disable() + pci_free_resource_list()

pci_free_resource_list() is called while the device is runtime-disabled.

Because nothing will access the device.

Quoted 4 lines
Quoted 3 lines

'- pci_free_host_bridge()

It looks symmetric to me ...

Quoted 7 lines
Quoted 3 lines

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed,
pci_free_resource_list() is called while the device is runtime-disabled.

At this point, I think I'd rather see a diff of changes which you have in mind rather than this endless discussion. Can you provide one against this patch ?

My final comment:

If the steps during probing are A..Z, cleanup and removal should undo them in reverse order (Z..A), unless there's a very good reason not to do so.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#10 lore raw
Quoted 1 line · Geert Uytterhoeven

Hi Marek,

Hi,

[...]

Quoted 27 lines
Quoted 27 lines
Quoted 8 lines
Quoted 6 lines

The pairing looks as follows:

.- rcar_pcie_parse_request_of_pci_ranges()

|  (pm_runtime_enable is here)
| .- pm_runtime_get_sync()
| | .- rcar_pcie_get_resources()

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed

Because something may access the device, yes.

Quoted 5 lines
Quoted 3 lines
| | |
| | '- pm_runtime_put()
| '- pm_runtime_disable() + pci_free_resource_list()

pci_free_resource_list() is called while the device is runtime-disabled.

Because nothing will access the device.

Quoted 7 lines
Quoted 3 lines

'- pci_free_host_bridge()

It looks symmetric to me ...

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed,
pci_free_resource_list() is called while the device is runtime-disabled.

Quoted 8 lines
Quoted 3 lines

At this point, I think I'd rather see a diff of changes which you have in mind rather than this endless discussion. Can you provide one against this patch ?

My final comment:

If the steps during probing are A..Z, cleanup and removal should undo them in reverse order (Z..A), unless there's a very good reason not to do so.

I spent extra time going through the probe function and I just don't see how it is not done in the exact reverse, I checked every single goto statement in probe.

I noticed this though:

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed,
pci_free_resource_list() is called while the device is runtime-disabled.

rcar_pcie_get_resources() is NOT a pair function for pci_free_resource_list() . rcar_pcie_parse_request_of_pci_ranges() is a pair function for pci_free_resource_list().

rcar_pcie_parse_request_of_pci_ranges() calls of_pci_get_host_bridge_resources() internally, so every single function called after successful call of rcar_pcie_parse_request_of_pci_ranges() must call pci_free_resource_list().

Both of_pci_get_host_bridge_resources() and pci_free_resource_list() are called with runtime PM disabled.

The naming of the functions is confusing though.

Signature · 2 lines
Best regards,
Marek Vasut
Reviewed-by
#11 lore raw
Quoted 1 line · Marek Vasut

On 04/10/2018 05:28 PM, Geert Uytterhoeven wrote:

...

Quoted 13 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed,
pci_free_resource_list() is called while the device is runtime-disabled.

rcar_pcie_get_resources() is NOT a pair function for pci_free_resource_list() . rcar_pcie_parse_request_of_pci_ranges() is a pair function for pci_free_resource_list().

rcar_pcie_parse_request_of_pci_ranges() calls of_pci_get_host_bridge_resources() internally, so every single function called after successful call of rcar_pcie_parse_request_of_pci_ranges() must call pci_free_resource_list().

Quoted 4 lines

Both of_pci_get_host_bridge_resources() and pci_free_resource_list() are called with runtime PM disabled.

The naming of the functions is confusing though.

Hi,

thanks everyone for their efforts in preparing/reviewing this patch.

It seems there are some differences of opinion on how best to handle the error paths but unlike earlier versions this one seems correct to me. If that turns out to be false we can address it. But I don't think its likely things will be enhanced by continuing this review.

Lorenzo, please consider taking this patch in its current form.

#12 lore raw
Quoted 25 lines · Simon Horman
Quoted 1 line · Marek Vasut

On 04/10/2018 05:28 PM, Geert Uytterhoeven wrote:

...

Quoted 13 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed,
pci_free_resource_list() is called while the device is runtime-disabled.

rcar_pcie_get_resources() is NOT a pair function for pci_free_resource_list() . rcar_pcie_parse_request_of_pci_ranges() is a pair function for pci_free_resource_list().

rcar_pcie_parse_request_of_pci_ranges() calls of_pci_get_host_bridge_resources() internally, so every single function called after successful call of rcar_pcie_parse_request_of_pci_ranges() must call pci_free_resource_list().

Quoted 4 lines

Both of_pci_get_host_bridge_resources() and pci_free_resource_list() are called with runtime PM disabled.

The naming of the functions is confusing though.

Hi,

Quoted 8 lines

thanks everyone for their efforts in preparing/reviewing this patch.

It seems there are some differences of opinion on how best to handle the error paths but unlike earlier versions this one seems correct to me. If that turns out to be false we can address it. But I don't think its likely things will be enhanced by continuing this review.

Lorenzo, please consider taking this patch in its current form.

I will as soon as we restart queueing patches for v4.18, thanks for the heads-up.

Lorenzo

#13 lore raw
In reply to Simon Horman
Quoted 27 lines · Simon Horman
Quoted 1 line · Marek Vasut

On 04/10/2018 05:28 PM, Geert Uytterhoeven wrote:

...

Quoted 13 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed,
pci_free_resource_list() is called while the device is runtime-disabled.

rcar_pcie_get_resources() is NOT a pair function for pci_free_resource_list() . rcar_pcie_parse_request_of_pci_ranges() is a pair function for pci_free_resource_list().

rcar_pcie_parse_request_of_pci_ranges() calls of_pci_get_host_bridge_resources() internally, so every single function called after successful call of rcar_pcie_parse_request_of_pci_ranges() must call pci_free_resource_list().

Quoted 4 lines

Both of_pci_get_host_bridge_resources() and pci_free_resource_list() are called with runtime PM disabled.

The naming of the functions is confusing though.

Hi,

thanks everyone for their efforts in preparing/reviewing this patch.

Quoted 8 lines

It seems there are some differences of opinion on how best to handle the error paths but unlike earlier versions this one seems correct to me. If that turns out to be false we can address it. But I don't think its likely things will be enhanced by continuing this review.

Lorenzo, please consider taking this patch in its current form.

Applied to pci/rcar for v4.18, thanks.

Lorenzo

#14 lore raw
Quoted 33 lines · Lorenzo Pieralisi
Quoted 32 lines · Simon Horman
Quoted 1 line · Marek Vasut

On 04/10/2018 05:28 PM, Geert Uytterhoeven wrote:

...

Quoted 13 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed,
pci_free_resource_list() is called while the device is runtime-disabled.

rcar_pcie_get_resources() is NOT a pair function for pci_free_resource_list() . rcar_pcie_parse_request_of_pci_ranges() is a pair function for pci_free_resource_list().

rcar_pcie_parse_request_of_pci_ranges() calls of_pci_get_host_bridge_resources() internally, so every single function called after successful call of rcar_pcie_parse_request_of_pci_ranges() must call pci_free_resource_list().

Quoted 4 lines

Both of_pci_get_host_bridge_resources() and pci_free_resource_list() are called with runtime PM disabled.

The naming of the functions is confusing though.

Hi,

thanks everyone for their efforts in preparing/reviewing this patch.

It seems there are some differences of opinion on how best to handle the error paths but unlike earlier versions this one seems correct to me. If that turns out to be false we can address it. But I don't think its likely things will be enhanced by continuing this review.

Quoted 5 lines
Quoted 3 lines

Lorenzo, please consider taking this patch in its current form.

Applied to pci/rcar for v4.18, thanks.

Is there any reason why this patch isnt in next yet ?

Signature · 2 lines
Best regards,
Marek Vasut
#15 lore raw
Quoted 34 lines · Marek Vasut
Quoted 33 lines · Lorenzo Pieralisi
Quoted 32 lines · Simon Horman
Quoted 1 line · Marek Vasut

On 04/10/2018 05:28 PM, Geert Uytterhoeven wrote:

...

Quoted 13 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed,
pci_free_resource_list() is called while the device is runtime-disabled.

rcar_pcie_get_resources() is NOT a pair function for pci_free_resource_list() . rcar_pcie_parse_request_of_pci_ranges() is a pair function for pci_free_resource_list().

rcar_pcie_parse_request_of_pci_ranges() calls of_pci_get_host_bridge_resources() internally, so every single function called after successful call of rcar_pcie_parse_request_of_pci_ranges() must call pci_free_resource_list().

Quoted 4 lines

Both of_pci_get_host_bridge_resources() and pci_free_resource_list() are called with runtime PM disabled.

The naming of the functions is confusing though.

Hi,

thanks everyone for their efforts in preparing/reviewing this patch.

It seems there are some differences of opinion on how best to handle the error paths but unlike earlier versions this one seems correct to me. If that turns out to be false we can address it. But I don't think its likely things will be enhanced by continuing this review.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Lorenzo, please consider taking this patch in its current form.

Applied to pci/rcar for v4.18, thanks.

Is there any reason why this patch isnt in next yet ?

Bjorn will merge it into -next this week.

Thanks,
Lorenzo

#16 lore raw
Quoted 37 lines · Lorenzo Pieralisi
Quoted 36 lines · Marek Vasut
Quoted 35 lines · Lorenzo Pieralisi
Quoted 34 lines · Simon Horman
Quoted 1 line · Marek Vasut

On 04/10/2018 05:28 PM, Geert Uytterhoeven wrote:

...

Quoted 13 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed,
pci_free_resource_list() is called while the device is runtime-disabled.

rcar_pcie_get_resources() is NOT a pair function for pci_free_resource_list() . rcar_pcie_parse_request_of_pci_ranges() is a pair function for pci_free_resource_list().

rcar_pcie_parse_request_of_pci_ranges() calls of_pci_get_host_bridge_resources() internally, so every single function called after successful call of rcar_pcie_parse_request_of_pci_ranges() must call pci_free_resource_list().

Quoted 4 lines

Both of_pci_get_host_bridge_resources() and pci_free_resource_list() are called with runtime PM disabled.

The naming of the functions is confusing though.

Hi,

thanks everyone for their efforts in preparing/reviewing this patch.

It seems there are some differences of opinion on how best to handle the error paths but unlike earlier versions this one seems correct to me. If that turns out to be false we can address it. But I don't think its likely things will be enhanced by continuing this review.

Lorenzo, please consider taking this patch in its current form.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Applied to pci/rcar for v4.18, thanks.

Is there any reason why this patch isnt in next yet ?

Bjorn will merge it into -next this week.

Seems this got missed last week ?

Signature · 2 lines
Best regards,
Marek Vasut
#17 lore raw
Quoted 40 lines · Marek Vasut
Quoted 39 lines · Lorenzo Pieralisi
Quoted 38 lines · Marek Vasut
Quoted 37 lines · Lorenzo Pieralisi
Quoted 35 lines · Simon Horman
Quoted 1 line · Marek Vasut

On 04/10/2018 05:28 PM, Geert Uytterhoeven wrote:

...

Quoted 13 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed,
pci_free_resource_list() is called while the device is runtime-disabled.

rcar_pcie_get_resources() is NOT a pair function for pci_free_resource_list() . rcar_pcie_parse_request_of_pci_ranges() is a pair function for pci_free_resource_list().

rcar_pcie_parse_request_of_pci_ranges() calls of_pci_get_host_bridge_resources() internally, so every single function called after successful call of rcar_pcie_parse_request_of_pci_ranges() must call pci_free_resource_list().

Quoted 4 lines

Both of_pci_get_host_bridge_resources() and pci_free_resource_list() are called with runtime PM disabled.

The naming of the functions is confusing though.

Hi,

thanks everyone for their efforts in preparing/reviewing this patch.

It seems there are some differences of opinion on how best to handle the error paths but unlike earlier versions this one seems correct to me. If that turns out to be false we can address it. But I don't think its likely things will be enhanced by continuing this review.

Lorenzo, please consider taking this patch in its current form.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Applied to pci/rcar for v4.18, thanks.

Is there any reason why this patch isnt in next yet ?

Bjorn will merge it into -next this week.

Seems this got missed last week ?

It will go into -next as soon as a new -next release will be available:

https://marc.info/?l=linux-next&m=152654084627146&w=2

Lorenzo

#18 lore raw
Quoted 45 lines · Lorenzo Pieralisi
Quoted 44 lines · Marek Vasut
Quoted 43 lines · Lorenzo Pieralisi
Quoted 41 lines · Marek Vasut
Quoted 33 lines · Lorenzo Pieralisi
Quoted 32 lines · Simon Horman
Quoted 1 line · Marek Vasut

On 04/10/2018 05:28 PM, Geert Uytterhoeven wrote:

...

Quoted 13 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed,
pci_free_resource_list() is called while the device is runtime-disabled.

rcar_pcie_get_resources() is NOT a pair function for pci_free_resource_list() . rcar_pcie_parse_request_of_pci_ranges() is a pair function for pci_free_resource_list().

rcar_pcie_parse_request_of_pci_ranges() calls of_pci_get_host_bridge_resources() internally, so every single function called after successful call of rcar_pcie_parse_request_of_pci_ranges() must call pci_free_resource_list().

Quoted 4 lines

Both of_pci_get_host_bridge_resources() and pci_free_resource_list() are called with runtime PM disabled.

The naming of the functions is confusing though.

Hi,

thanks everyone for their efforts in preparing/reviewing this patch.

It seems there are some differences of opinion on how best to handle the error paths but unlike earlier versions this one seems correct to me. If that turns out to be false we can address it. But I don't think its likely things will be enhanced by continuing this review.

Quoted 5 lines
Quoted 3 lines

Lorenzo, please consider taking this patch in its current form.

Applied to pci/rcar for v4.18, thanks.

Is there any reason why this patch isnt in next yet ?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Bjorn will merge it into -next this week.

Seems this got missed last week ?

It will go into -next as soon as a new -next release will be available:

https://marc.info/?l=linux-next&m=152654084627146&w=2

Cool, thanks, I have a few more fixes coming.

Signature · 2 lines
Best regards,
Marek Vasut
Reviewed-by
#19 lore raw
In reply to Marek Vasut

Hi Marek,

Quoted 56 lines · Marek Vasut
Quoted 27 lines · Geert Uytterhoeven
Quoted 27 lines
Quoted 8 lines
Quoted 6 lines

The pairing looks as follows:

.- rcar_pcie_parse_request_of_pci_ranges()

|  (pm_runtime_enable is here)
| .- pm_runtime_get_sync()
| | .- rcar_pcie_get_resources()

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed

Because something may access the device, yes.

Quoted 5 lines
Quoted 3 lines
| | |
| | '- pm_runtime_put()
| '- pm_runtime_disable() + pci_free_resource_list()

pci_free_resource_list() is called while the device is runtime-disabled.

Because nothing will access the device.

Quoted 7 lines
Quoted 3 lines

'- pci_free_host_bridge()

It looks symmetric to me ...

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed,
pci_free_resource_list() is called while the device is runtime-disabled.

Quoted 8 lines
Quoted 3 lines

At this point, I think I'd rather see a diff of changes which you have in mind rather than this endless discussion. Can you provide one against this patch ?

My final comment:

If the steps during probing are A..Z, cleanup and removal should undo them in reverse order (Z..A), unless there's a very good reason not to do so.

I spent extra time going through the probe function and I just don't see how it is not done in the exact reverse, I checked every single goto statement in probe.

I noticed this though:

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed,
pci_free_resource_list() is called while the device is runtime-disabled.

rcar_pcie_get_resources() is NOT a pair function for pci_free_resource_list() . rcar_pcie_parse_request_of_pci_ranges() is a pair function for pci_free_resource_list().

rcar_pcie_parse_request_of_pci_ranges() calls of_pci_get_host_bridge_resources() internally, so every single function called after successful call of rcar_pcie_parse_request_of_pci_ranges() must call pci_free_resource_list().

Quoted 4 lines

Both of_pci_get_host_bridge_resources() and pci_free_resource_list() are called with runtime PM disabled.

The naming of the functions is confusing though.

You are right, your changes are correct, and the naming of these functions is confusing. Perhaps it should be changed, to avoid misleading the (not so) casual reviewer?

BTW, while diving deeper, I noticed a few other pre-existing issues in error handling:

1. If anything fails after rcar_pcie_get_resources(), the bus clock is never disabled,
2. The error path of rcar_pcie_enable_msi() does not call irq_dispose_mapping() before irq_domain_remove(),
3. If rcar_pcie_enable() fails, none of the setup done in rcar_pcie_enable_msi() is reverted.
Apart from the IRQ domain handling in 2, that includes freeing msi->pages (should this be allocated using the DMA API?), and undoing the related HW setup, to prevent the HW from scribbling the former MSI page in the future.

Care to fix these, too?
Thanks!

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#20 lore raw
Quoted 83 lines · Geert Uytterhoeven

Hi Marek,

Quoted 56 lines · Marek Vasut
Quoted 27 lines · Geert Uytterhoeven
Quoted 27 lines
Quoted 8 lines
Quoted 6 lines

The pairing looks as follows:

.- rcar_pcie_parse_request_of_pci_ranges()

|  (pm_runtime_enable is here)
| .- pm_runtime_get_sync()
| | .- rcar_pcie_get_resources()

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed

Because something may access the device, yes.

Quoted 5 lines
Quoted 3 lines
| | |
| | '- pm_runtime_put()
| '- pm_runtime_disable() + pci_free_resource_list()

pci_free_resource_list() is called while the device is runtime-disabled.

Because nothing will access the device.

Quoted 7 lines
Quoted 3 lines

'- pci_free_host_bridge()

It looks symmetric to me ...

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed,
pci_free_resource_list() is called while the device is runtime-disabled.

Quoted 8 lines
Quoted 3 lines

At this point, I think I'd rather see a diff of changes which you have in mind rather than this endless discussion. Can you provide one against this patch ?

My final comment:

If the steps during probing are A..Z, cleanup and removal should undo them in reverse order (Z..A), unless there's a very good reason not to do so.

I spent extra time going through the probe function and I just don't see how it is not done in the exact reverse, I checked every single goto statement in probe.

I noticed this though:

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

rcar_pcie_get_resources() is called while the device is runtime-enabled/resumed,
pci_free_resource_list() is called while the device is runtime-disabled.

rcar_pcie_get_resources() is NOT a pair function for pci_free_resource_list() . rcar_pcie_parse_request_of_pci_ranges() is a pair function for pci_free_resource_list().

rcar_pcie_parse_request_of_pci_ranges() calls of_pci_get_host_bridge_resources() internally, so every single function called after successful call of rcar_pcie_parse_request_of_pci_ranges() must call pci_free_resource_list().

Quoted 4 lines

Both of_pci_get_host_bridge_resources() and pci_free_resource_list() are called with runtime PM disabled.

The naming of the functions is confusing though.

You are right, your changes are correct, and the naming of these functions is confusing. Perhaps it should be changed, to avoid misleading the (not so) casual reviewer?

BTW, while diving deeper, I noticed a few other pre-existing issues in error handling:

1. If anything fails after rcar_pcie_get_resources(), the bus clock is never disabled,
2. The error path of rcar_pcie_enable_msi() does not call irq_dispose_mapping() before irq_domain_remove(),
3. If rcar_pcie_enable() fails, none of the setup done in rcar_pcie_enable_msi() is reverted.
Apart from the IRQ domain handling in 2, that includes freeing msi->pages (should this be allocated using the DMA API?), and undoing the related HW setup, to prevent the HW from scribbling the former MSI page in the future.

Quoted 1 line

Care to fix these, too?

Yes, patchset is coming.

Signature · 2 lines
Best regards,
Marek Vasut