linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/1] NET: mcan: Move runtime PM enable/disable to  m_can_platform
@ 2020-08-25 10:17 Patrik Flykt
  2020-08-25 10:17 ` [PATCH 1/1] " Patrik Flykt
  0 siblings, 1 reply; 6+ messages in thread
From: Patrik Flykt @ 2020-08-25 10:17 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, dmurphy, sriram.dash, jarkko.nikula


	Hi,

This is a preparatory patch for modifying PM enabling due to PCI based
M_CAN devices. As the functionality is right now, adding a PCI based
M_CAN driver causes the core PCI functionality to call
pm_runtime_enable() from pci_pm_init() when the PCI device is added.
When the device is added, it is registered with m_can_class_register(),
which ends up calling pm_runtime_enable() once more and causes the
kernel to log an angry 'Unbalanced pm_runtime_enable!' message, as
dev->power.disable_depth has gone down to zero.

To resolve this situation, I have added a patch that moves runtime PM
enabling from m_can.c to the m_can_platform.c driver, which currently
is the only driver that ends up enabling runtime PM. Would this
approach be appropriate, or should PM be enabled in some other way
with PCI based M_CAN devices?

Now, the actual sticky point is that there aren't yet any PCI based
M_CAN devices upstream, but one is in the works. So if the change
proposed works out, should this patch actually be sent in the patch
set providing a PCI based M_CAN device?


Thanks,

	Patrik


Patrik Flykt (1):
  NET: mcan: Move runtime PM enable/disable to m_can_platform

 drivers/net/can/m_can/m_can.c          | 6 +-----
 drivers/net/can/m_can/m_can_platform.c | 3 +++
 2 files changed, 4 insertions(+), 5 deletions(-)

-- 
2.27.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/1] NET: mcan: Move runtime PM enable/disable to m_can_platform
  2020-08-25 10:17 [PATCH 0/1] NET: mcan: Move runtime PM enable/disable to m_can_platform Patrik Flykt
@ 2020-08-25 10:17 ` Patrik Flykt
  2020-09-01 18:22   ` Dan Murphy
  2020-10-19 15:47   ` Marc Kleine-Budde
  0 siblings, 2 replies; 6+ messages in thread
From: Patrik Flykt @ 2020-08-25 10:17 UTC (permalink / raw)
  To: linux-can; +Cc: wg, mkl, dmurphy, sriram.dash, jarkko.nikula

This is a preparatory patch for upcoming PCI based M_CAN devices.
The current PM implementation would cause PCI based drivers to
enable PM twice, once when the pci device is added and a second
time in m_can_class_register(). This will cause 'Unbalanced
pm_runtime_enable!' to be logged, and is a situation that should
be avoided.

Therefore, in anticipation of PCI devices, move PM enabling out
from M_CAN class registration to its currently only user, the
m_can_platform driver.


Signed-off-by: Patrik Flykt <patrik.flykt@linux.intel.com>
---
 drivers/net/can/m_can/m_can.c          | 6 +-----
 drivers/net/can/m_can/m_can_platform.c | 3 +++
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 02c5795b7393..2c4d74113443 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -1817,7 +1817,6 @@ int m_can_class_register(struct m_can_classdev *m_can_dev)
 	int ret;
 
 	if (m_can_dev->pm_clock_support) {
-		pm_runtime_enable(m_can_dev->dev);
 		ret = m_can_clk_start(m_can_dev);
 		if (ret)
 			goto pm_runtime_fail;
@@ -1847,11 +1846,8 @@ int m_can_class_register(struct m_can_classdev *m_can_dev)
 clk_disable:
 	m_can_clk_stop(m_can_dev);
 pm_runtime_fail:
-	if (ret) {
-		if (m_can_dev->pm_clock_support)
-			pm_runtime_disable(m_can_dev->dev);
+	if (ret)
 		free_candev(m_can_dev->net);
-	}
 
 	return ret;
 }
diff --git a/drivers/net/can/m_can/m_can_platform.c b/drivers/net/can/m_can/m_can_platform.c
index 38ea5e600fb8..1260e99b9322 100644
--- a/drivers/net/can/m_can/m_can_platform.c
+++ b/drivers/net/can/m_can/m_can_platform.c
@@ -111,7 +111,10 @@ static int m_can_plat_probe(struct platform_device *pdev)
 
 	m_can_init_ram(mcan_class);
 
+	pm_runtime_enable(mcan_class->dev);
 	ret = m_can_class_register(mcan_class);
+	if (ret)
+		pm_runtime_disable(mcan_class->dev);
 
 failed_ret:
 	return ret;
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] NET: mcan: Move runtime PM enable/disable to m_can_platform
  2020-08-25 10:17 ` [PATCH 1/1] " Patrik Flykt
@ 2020-09-01 18:22   ` Dan Murphy
  2020-10-19 15:01     ` Patrik Flykt
  2020-10-19 15:47   ` Marc Kleine-Budde
  1 sibling, 1 reply; 6+ messages in thread
From: Dan Murphy @ 2020-09-01 18:22 UTC (permalink / raw)
  To: Patrik Flykt, linux-can; +Cc: wg, mkl, sriram.dash, jarkko.nikula

Patrik

On 8/25/20 5:17 AM, Patrik Flykt wrote:
> This is a preparatory patch for upcoming PCI based M_CAN devices.
> The current PM implementation would cause PCI based drivers to
> enable PM twice, once when the pci device is added and a second
> time in m_can_class_register(). This will cause 'Unbalanced
> pm_runtime_enable!' to be logged, and is a situation that should
> be avoided.
>
> Therefore, in anticipation of PCI devices, move PM enabling out
> from M_CAN class registration to its currently only user, the
> m_can_platform driver.
>
>
> Signed-off-by: Patrik Flykt <patrik.flykt@linux.intel.com>
> ---
>   drivers/net/can/m_can/m_can.c          | 6 +-----
>   drivers/net/can/m_can/m_can_platform.c | 3 +++
>   2 files changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
> index 02c5795b7393..2c4d74113443 100644
> --- a/drivers/net/can/m_can/m_can.c
> +++ b/drivers/net/can/m_can/m_can.c
> @@ -1817,7 +1817,6 @@ int m_can_class_register(struct m_can_classdev *m_can_dev)
>   	int ret;
>   
>   	if (m_can_dev->pm_clock_support) {
> -		pm_runtime_enable(m_can_dev->dev);
>   		ret = m_can_clk_start(m_can_dev);
>   		if (ret)
>   			goto pm_runtime_fail;
> @@ -1847,11 +1846,8 @@ int m_can_class_register(struct m_can_classdev *m_can_dev)
>   clk_disable:
>   	m_can_clk_stop(m_can_dev);
>   pm_runtime_fail:
> -	if (ret) {
> -		if (m_can_dev->pm_clock_support)
> -			pm_runtime_disable(m_can_dev->dev);
> +	if (ret)
>   		free_candev(m_can_dev->net);
> -	}
>   
>   	return ret;
>   }
> diff --git a/drivers/net/can/m_can/m_can_platform.c b/drivers/net/can/m_can/m_can_platform.c
> index 38ea5e600fb8..1260e99b9322 100644
> --- a/drivers/net/can/m_can/m_can_platform.c
> +++ b/drivers/net/can/m_can/m_can_platform.c
> @@ -111,7 +111,10 @@ static int m_can_plat_probe(struct platform_device *pdev)
>   
>   	m_can_init_ram(mcan_class);
>   
> +	pm_runtime_enable(mcan_class->dev);
>   	ret = m_can_class_register(mcan_class);
> +	if (ret)
> +		pm_runtime_disable(mcan_class->dev);
>   
>   failed_ret:
>   	return ret;
Reviewed-by: Dan Murphy <dmurphy@ti.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] NET: mcan: Move runtime PM enable/disable to m_can_platform
  2020-09-01 18:22   ` Dan Murphy
@ 2020-10-19 15:01     ` Patrik Flykt
  0 siblings, 0 replies; 6+ messages in thread
From: Patrik Flykt @ 2020-10-19 15:01 UTC (permalink / raw)
  To: Dan Murphy, linux-can; +Cc: wg, mkl, sriram.dash, jarkko.nikula

On Tue, 2020-09-01 at 13:22 -0500, Dan Murphy wrote:
> Patrik
> 
> On 8/25/20 5:17 AM, Patrik Flykt wrote:
> > This is a preparatory patch for upcoming PCI based M_CAN devices.
> > The current PM implementation would cause PCI based drivers to
> > enable PM twice, once when the pci device is added and a second
> > time in m_can_class_register(). This will cause 'Unbalanced
> > pm_runtime_enable!' to be logged, and is a situation that should
> > be avoided.
> > 
> > Therefore, in anticipation of PCI devices, move PM enabling out
> > from M_CAN class registration to its currently only user, the
> > m_can_platform driver.

> Reviewed-by: Dan Murphy <dmurphy@ti.com>

Ping?

Can this patch be added as-is or should it be sent in the patch set
providing a PCI based M_CAN device?

Cheers,

	Patrik


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] NET: mcan: Move runtime PM enable/disable to m_can_platform
  2020-08-25 10:17 ` [PATCH 1/1] " Patrik Flykt
  2020-09-01 18:22   ` Dan Murphy
@ 2020-10-19 15:47   ` Marc Kleine-Budde
  2020-10-23 11:58     ` Patrik Flykt
  1 sibling, 1 reply; 6+ messages in thread
From: Marc Kleine-Budde @ 2020-10-19 15:47 UTC (permalink / raw)
  To: Patrik Flykt, linux-can; +Cc: wg, dmurphy, sriram.dash, jarkko.nikula


[-- Attachment #1.1: Type: text/plain, Size: 2625 bytes --]

On 8/25/20 12:17 PM, Patrik Flykt wrote:
> This is a preparatory patch for upcoming PCI based M_CAN devices.
> The current PM implementation would cause PCI based drivers to
> enable PM twice, once when the pci device is added and a second
> time in m_can_class_register(). This will cause 'Unbalanced
> pm_runtime_enable!' to be logged, and is a situation that should
> be avoided.
> 
> Therefore, in anticipation of PCI devices, move PM enabling out
> from M_CAN class registration to its currently only user, the
> m_can_platform driver.

Makes sense.

> Signed-off-by: Patrik Flykt <patrik.flykt@linux.intel.com>

Please rebase this patch onto linux-can/m_can

https://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git/log/?h=m_can

> ---
>  drivers/net/can/m_can/m_can.c          | 6 +-----
>  drivers/net/can/m_can/m_can_platform.c | 3 +++
>  2 files changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
> index 02c5795b7393..2c4d74113443 100644
> --- a/drivers/net/can/m_can/m_can.c
> +++ b/drivers/net/can/m_can/m_can.c
> @@ -1817,7 +1817,6 @@ int m_can_class_register(struct m_can_classdev *m_can_dev)
>  	int ret;
>  
>  	if (m_can_dev->pm_clock_support) {

I think pm_clock_support can be removed altogether now.

> -		pm_runtime_enable(m_can_dev->dev);
>  		ret = m_can_clk_start(m_can_dev);
>  		if (ret)
>  			goto pm_runtime_fail;
> @@ -1847,11 +1846,8 @@ int m_can_class_register(struct m_can_classdev *m_can_dev)
>  clk_disable:
>  	m_can_clk_stop(m_can_dev);
>  pm_runtime_fail:
> -	if (ret) {
> -		if (m_can_dev->pm_clock_support)
> -			pm_runtime_disable(m_can_dev->dev);
> +	if (ret)
>  		free_candev(m_can_dev->net);
> -	}
>  
>  	return ret;
>  }
> diff --git a/drivers/net/can/m_can/m_can_platform.c b/drivers/net/can/m_can/m_can_platform.c
> index 38ea5e600fb8..1260e99b9322 100644
> --- a/drivers/net/can/m_can/m_can_platform.c
> +++ b/drivers/net/can/m_can/m_can_platform.c
> @@ -111,7 +111,10 @@ static int m_can_plat_probe(struct platform_device *pdev)
>  
>  	m_can_init_ram(mcan_class);
>  
> +	pm_runtime_enable(mcan_class->dev);
>  	ret = m_can_class_register(mcan_class);
> +	if (ret)
> +		pm_runtime_disable(mcan_class->dev);
>  
>  failed_ret:
>  	return ret;
> 

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] NET: mcan: Move runtime PM enable/disable to m_can_platform
  2020-10-19 15:47   ` Marc Kleine-Budde
@ 2020-10-23 11:58     ` Patrik Flykt
  0 siblings, 0 replies; 6+ messages in thread
From: Patrik Flykt @ 2020-10-23 11:58 UTC (permalink / raw)
  To: Marc Kleine-Budde, linux-can; +Cc: wg, dmurphy, sriram.dash, jarkko.nikula

On Mon, 2020-10-19 at 17:47 +0200, Marc Kleine-Budde wrote:
> > Therefore, in anticipation of PCI devices, move PM enabling out
> > from M_CAN class registration to its currently only user, the
> > m_can_platform driver.
> 
> Makes sense.
> 
> > Signed-off-by: Patrik Flykt <patrik.flykt@linux.intel.com>
> 
> Please rebase this patch onto linux-can/m_can
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can.git/log/?h=m_can

Rebased and sent as v2.

Thanks!

	Patrik


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-10-23 11:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-25 10:17 [PATCH 0/1] NET: mcan: Move runtime PM enable/disable to m_can_platform Patrik Flykt
2020-08-25 10:17 ` [PATCH 1/1] " Patrik Flykt
2020-09-01 18:22   ` Dan Murphy
2020-10-19 15:01     ` Patrik Flykt
2020-10-19 15:47   ` Marc Kleine-Budde
2020-10-23 11:58     ` Patrik Flykt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).