diff mbox series

[7/7] PCI: aardvark: Reset PCIe card and disable PHY at driver unbind

Message ID 20211031181233.9976-8-kabel@kernel.org
State New
Headers show
Series PCI: aardvark controller fixes BATCH 3 | expand

Commit Message

Marek Behún Oct. 31, 2021, 6:12 p.m. UTC
From: Pali Rohár <pali@kernel.org>

When unbinding driver, assert PERST# signal which prepares PCIe card for
power down. Then disable link training and PHY.

Fixes: 526a76991b7b ("PCI: aardvark: Implement driver 'remove' function and allow to build it as module")
Signed-off-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Marek Behún <kabel@kernel.org>
Cc: stable@vger.kernel.org
---
 drivers/pci/controller/pci-aardvark.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Lorenzo Pieralisi Nov. 29, 2021, 4:40 p.m. UTC | #1
On Sun, Oct 31, 2021 at 07:12:33PM +0100, Marek Behún wrote:
> From: Pali Rohár <pali@kernel.org>
> 
> When unbinding driver, assert PERST# signal which prepares PCIe card for
> power down. Then disable link training and PHY.

This reads as three actions. If we carry them out as a single patch we
have to explain why they are related and what problem they are solving
as a _single_ commit.

Otherwise we have to split this patch into three and explain each of
them as a separate fix.

I understand it is tempting to coalesce missing code in one single
change but every commit must implement a single logical change.

Thanks,
Lorenzo

> Fixes: 526a76991b7b ("PCI: aardvark: Implement driver 'remove' function and allow to build it as module")
> Signed-off-by: Pali Rohár <pali@kernel.org>
> Signed-off-by: Marek Behún <kabel@kernel.org>
> Cc: stable@vger.kernel.org
> ---
>  drivers/pci/controller/pci-aardvark.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
> index b3d89cb449b6..2a82c4652c28 100644
> --- a/drivers/pci/controller/pci-aardvark.c
> +++ b/drivers/pci/controller/pci-aardvark.c
> @@ -1737,10 +1737,22 @@ static int advk_pcie_remove(struct platform_device *pdev)
>  	/* Free config space for emulated root bridge */
>  	pci_bridge_emul_cleanup(&pcie->bridge);
>  
> +	/* Assert PERST# signal which prepares PCIe card for power down */
> +	if (pcie->reset_gpio)
> +		gpiod_set_value_cansleep(pcie->reset_gpio, 1);
> +
> +	/* Disable link training */
> +	val = advk_readl(pcie, PCIE_CORE_CTRL0_REG);
> +	val &= ~LINK_TRAINING_EN;
> +	advk_writel(pcie, val, PCIE_CORE_CTRL0_REG);
> +
>  	/* Disable outbound address windows mapping */
>  	for (i = 0; i < OB_WIN_COUNT; i++)
>  		advk_pcie_disable_ob_win(pcie, i);
>  
> +	/* Disable phy */
> +	advk_pcie_disable_phy(pcie);
> +
>  	return 0;
>  }
>  
> -- 
> 2.32.0
>
Marek Behún Nov. 29, 2021, 5:15 p.m. UTC | #2
On Mon, 29 Nov 2021 16:40:43 +0000
Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> wrote:

> On Sun, Oct 31, 2021 at 07:12:33PM +0100, Marek Behún wrote:
> > From: Pali Rohár <pali@kernel.org>
> > 
> > When unbinding driver, assert PERST# signal which prepares PCIe card for
> > power down. Then disable link training and PHY.  
> 
> This reads as three actions. If we carry them out as a single patch we
> have to explain why they are related and what problem they are solving
> as a _single_ commit.
> 
> Otherwise we have to split this patch into three and explain each of
> them as a separate fix.
> 
> I understand it is tempting to coalesce missing code in one single
> change but every commit must implement a single logical change.

Hi Lorenzo,

this is a fix for driver remove function. Although each of these things
could be introduced in separate commits, IMO it doesn't make sense to
split it. It should have been done this way in the first place when the
driver removal support was introduced. I guess we could rewrite the
commit message to:

  PCI: aardvark: Disable controller entirely at driver unbind

  Add the following to driver unbind to disable the controller entirely:
  - asserting PERST# signal
  - disabling link training
  - disable PHY

Would this be okay?

Marek
Lorenzo Pieralisi Nov. 30, 2021, 10:31 a.m. UTC | #3
On Mon, Nov 29, 2021 at 06:15:53PM +0100, Marek Behún wrote:
> On Mon, 29 Nov 2021 16:40:43 +0000
> Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> wrote:
> 
> > On Sun, Oct 31, 2021 at 07:12:33PM +0100, Marek Behún wrote:
> > > From: Pali Rohár <pali@kernel.org>
> > > 
> > > When unbinding driver, assert PERST# signal which prepares PCIe card for
> > > power down. Then disable link training and PHY.  
> > 
> > This reads as three actions. If we carry them out as a single patch we
> > have to explain why they are related and what problem they are solving
> > as a _single_ commit.
> > 
> > Otherwise we have to split this patch into three and explain each of
> > them as a separate fix.
> > 
> > I understand it is tempting to coalesce missing code in one single
> > change but every commit must implement a single logical change.
> 
> Hi Lorenzo,
> 
> this is a fix for driver remove function. Although each of these things
> could be introduced in separate commits, IMO it doesn't make sense to
> split it. It should have been done this way in the first place when the
> driver removal support was introduced. I guess we could rewrite the
> commit message to:
> 
>   PCI: aardvark: Disable controller entirely at driver unbind

"PCI: aardvark: Fix the controller disabling sequence"

>   Add the following to driver unbind to disable the controller entirely:
>   - asserting PERST# signal
>   - disabling link training
>   - disable PHY
> 
> Would this be okay?

Yes, that's what I meant. I would describe the change in its entirety
not as three fixes - it makes sense to have one single patch as long
as we describe it properly.

Thanks,
Lorenzo
Marek Behún Nov. 30, 2021, 12:22 p.m. UTC | #4
On Tue, 30 Nov 2021 10:31:57 +0000
Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> wrote:

> On Mon, Nov 29, 2021 at 06:15:53PM +0100, Marek Behún wrote:
> > On Mon, 29 Nov 2021 16:40:43 +0000
> > Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> wrote:
> >   
> > > On Sun, Oct 31, 2021 at 07:12:33PM +0100, Marek Behún wrote:  
> > > > From: Pali Rohár <pali@kernel.org>
> > > > 
> > > > When unbinding driver, assert PERST# signal which prepares PCIe card for
> > > > power down. Then disable link training and PHY.    
> > > 
> > > This reads as three actions. If we carry them out as a single patch we
> > > have to explain why they are related and what problem they are solving
> > > as a _single_ commit.
> > > 
> > > Otherwise we have to split this patch into three and explain each of
> > > them as a separate fix.
> > > 
> > > I understand it is tempting to coalesce missing code in one single
> > > change but every commit must implement a single logical change.  
> > 
> > Hi Lorenzo,
> > 
> > this is a fix for driver remove function. Although each of these things
> > could be introduced in separate commits, IMO it doesn't make sense to
> > split it. It should have been done this way in the first place when the
> > driver removal support was introduced. I guess we could rewrite the
> > commit message to:
> > 
> >   PCI: aardvark: Disable controller entirely at driver unbind  
> 
> "PCI: aardvark: Fix the controller disabling sequence"
> 
> >   Add the following to driver unbind to disable the controller entirely:
> >   - asserting PERST# signal
> >   - disabling link training
> >   - disable PHY
> > 
> > Would this be okay?  
> 
> Yes, that's what I meant. I would describe the change in its entirety
> not as three fixes - it makes sense to have one single patch as long
> as we describe it properly.

After I went through it again, I think it would be better to split it
into 3 patches. I am going to do that this way.

Marek
diff mbox series

Patch

diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c
index b3d89cb449b6..2a82c4652c28 100644
--- a/drivers/pci/controller/pci-aardvark.c
+++ b/drivers/pci/controller/pci-aardvark.c
@@ -1737,10 +1737,22 @@  static int advk_pcie_remove(struct platform_device *pdev)
 	/* Free config space for emulated root bridge */
 	pci_bridge_emul_cleanup(&pcie->bridge);
 
+	/* Assert PERST# signal which prepares PCIe card for power down */
+	if (pcie->reset_gpio)
+		gpiod_set_value_cansleep(pcie->reset_gpio, 1);
+
+	/* Disable link training */
+	val = advk_readl(pcie, PCIE_CORE_CTRL0_REG);
+	val &= ~LINK_TRAINING_EN;
+	advk_writel(pcie, val, PCIE_CORE_CTRL0_REG);
+
 	/* Disable outbound address windows mapping */
 	for (i = 0; i < OB_WIN_COUNT; i++)
 		advk_pcie_disable_ob_win(pcie, i);
 
+	/* Disable phy */
+	advk_pcie_disable_phy(pcie);
+
 	return 0;
 }