* [PATCH] davinci_emac: Add cpu_freq support
@ 2012-04-09 10:49 Manjunathappa, Prakash
[not found] ` <1333968549-3282-1-git-send-email-prakash.pm-l0cyMroinI0@public.gmane.org>
2012-04-09 15:56 ` Ben Hutchings
0 siblings, 2 replies; 4+ messages in thread
From: Manjunathappa, Prakash @ 2012-04-09 10:49 UTC (permalink / raw)
To: netdev
Cc: davem, linux-kernel, davinci-linux-open-source,
Manjunathappa, Prakash
Reconfigure interrupt coalesce parameter for changed emac bus_freq
due to DVFS.
Signed-off-by: Manjunathappa, Prakash <prakash.pm@ti.com>
---
drivers/net/ethernet/ti/davinci_emac.c | 60 ++++++++++++++++++++++++++++++++
1 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c
index 174a334..11d3bd7 100644
--- a/drivers/net/ethernet/ti/davinci_emac.c
+++ b/drivers/net/ethernet/ti/davinci_emac.c
@@ -50,6 +50,7 @@
#include <linux/ctype.h>
#include <linux/spinlock.h>
#include <linux/dma-mapping.h>
+#include <linux/cpufreq.h>
#include <linux/clk.h>
#include <linux/platform_device.h>
#include <linux/semaphore.h>
@@ -344,6 +345,9 @@ struct emac_priv {
/*platform specific members*/
void (*int_enable) (void);
void (*int_disable) (void);
+#ifdef CONFIG_CPU_FREQ
+ struct notifier_block freq_transition;
+#endif
};
/* clock frequency for EMAC */
@@ -1761,6 +1765,46 @@ static const struct net_device_ops emac_netdev_ops = {
#endif
};
+#ifdef CONFIG_CPU_FREQ
+static int davinci_emac_cpufreq_transition(struct notifier_block *nb,
+ unsigned long val, void *data)
+{
+ int ret = 0;
+ struct emac_priv *priv;
+
+ priv = container_of(nb, struct emac_priv, freq_transition);
+ if (priv->coal_intvl != 0) {
+ if (val == CPUFREQ_POSTCHANGE) {
+ if (emac_bus_frequency != clk_get_rate(emac_clk)) {
+ struct ethtool_coalesce coal;
+
+ emac_bus_frequency = clk_get_rate(emac_clk);
+
+ priv->bus_freq_mhz = (u32)(emac_bus_frequency /
+ 1000000);
+ coal.rx_coalesce_usecs = (priv->coal_intvl
+ << 4);
+ ret = emac_set_coalesce(priv->ndev, &coal);
+ }
+ }
+ }
+ return ret;
+}
+
+static inline int davinci_emac_cpufreq_register(struct emac_priv *priv)
+{
+ priv->freq_transition.notifier_call = davinci_emac_cpufreq_transition;
+ return cpufreq_register_notifier(&priv->freq_transition,
+ CPUFREQ_TRANSITION_NOTIFIER);
+}
+
+static inline void davinci_emac_cpufreq_deregister(struct emac_priv *priv)
+{
+ cpufreq_unregister_notifier(&priv->freq_transition,
+ CPUFREQ_TRANSITION_NOTIFIER);
+}
+#endif
+
/**
* davinci_emac_probe: EMAC device probe
* @pdev: The DaVinci EMAC device that we are removing
@@ -1925,8 +1969,21 @@ static int __devinit davinci_emac_probe(struct platform_device *pdev)
"(regs: %p, irq: %d)\n",
(void *)priv->emac_base_phys, ndev->irq);
}
+
+#ifdef CONFIG_CPU_FREQ
+ rc = davinci_emac_cpufreq_register(priv);
+ if (rc) {
+ dev_err(&pdev->dev, "error in register_netdev\n");
+ rc = -ENODEV;
+ goto cpufreq_reg_err;
+ }
+#endif
return 0;
+#ifdef CONFIG_CPU_FREQ
+cpufreq_reg_err:
+ unregister_netdev(ndev);
+#endif
netdev_reg_err:
clk_disable(emac_clk);
no_irq_res:
@@ -1973,6 +2030,9 @@ static int __devexit davinci_emac_remove(struct platform_device *pdev)
release_mem_region(res->start, resource_size(res));
+#ifdef CONFIG_CPU_FREQ
+ davinci_emac_cpufreq_deregister(priv);
+#endif
unregister_netdev(ndev);
iounmap(priv->remap_addr);
free_netdev(ndev);
--
1.7.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] davinci_emac: Add cpu_freq support
[not found] ` <1333968549-3282-1-git-send-email-prakash.pm-l0cyMroinI0@public.gmane.org>
@ 2012-04-09 11:29 ` Sergei Shtylyov
2012-04-10 5:16 ` Manjunathappa, Prakash
0 siblings, 1 reply; 4+ messages in thread
From: Sergei Shtylyov @ 2012-04-09 11:29 UTC (permalink / raw)
To: Manjunathappa, Prakash
Cc: netdev-u79uwXL29TY76Z2rM5mHXA,
davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/,
davem-fT/PcQaiUtIeIZ0/mPfg9Q, linux-kernel-u79uwXL29TY76Z2rM5mHXA
Hello.
On 09-04-2012 14:49, Manjunathappa, Prakash wrote:
> Reconfigure interrupt coalesce parameter for changed emac bus_freq
> due to DVFS.
> Signed-off-by: Manjunathappa, Prakash<prakash.pm-l0cyMroinI0@public.gmane.org>
> ---
> drivers/net/ethernet/ti/davinci_emac.c | 60 ++++++++++++++++++++++++++++++++
> 1 files changed, 60 insertions(+), 0 deletions(-)
> diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c
> index 174a334..11d3bd7 100644
> --- a/drivers/net/ethernet/ti/davinci_emac.c
> +++ b/drivers/net/ethernet/ti/davinci_emac.c
[...]
> @@ -1761,6 +1765,46 @@ static const struct net_device_ops emac_netdev_ops = {
> #endif
> };
>
> +#ifdef CONFIG_CPU_FREQ
> +static int davinci_emac_cpufreq_transition(struct notifier_block *nb,
> + unsigned long val, void *data)
> +{
> + int ret = 0;
> + struct emac_priv *priv;
> +
> + priv = container_of(nb, struct emac_priv, freq_transition);
> + if (priv->coal_intvl != 0) {
> + if (val == CPUFREQ_POSTCHANGE) {
> + if (emac_bus_frequency != clk_get_rate(emac_clk)) {
These 3 *if*s could be collapsed into one, and so indentation level
lowered significantly.
> + struct ethtool_coalesce coal;
> +
> + emac_bus_frequency = clk_get_rate(emac_clk);
> +
> + priv->bus_freq_mhz = (u32)(emac_bus_frequency /
> + 1000000);
> + coal.rx_coalesce_usecs = (priv->coal_intvl
> + << 4);
> + ret = emac_set_coalesce(priv->ndev,&coal);
> + }
> + }
> + }
> + return ret;
> +}
> +
> +static inline int davinci_emac_cpufreq_register(struct emac_priv *priv)
> +{
> + priv->freq_transition.notifier_call = davinci_emac_cpufreq_transition;
> + return cpufreq_register_notifier(&priv->freq_transition,
> + CPUFREQ_TRANSITION_NOTIFIER);
> +}
> +
> +static inline void davinci_emac_cpufreq_deregister(struct emac_priv *priv)
> +{
> + cpufreq_unregister_notifier(&priv->freq_transition,
> + CPUFREQ_TRANSITION_NOTIFIER);
> +}
> +#endif
> +
> /**
> * davinci_emac_probe: EMAC device probe
> * @pdev: The DaVinci EMAC device that we are removing
> @@ -1925,8 +1969,21 @@ static int __devinit davinci_emac_probe(struct platform_device *pdev)
> "(regs: %p, irq: %d)\n",
> (void *)priv->emac_base_phys, ndev->irq);
> }
> +
> +#ifdef CONFIG_CPU_FREQ
> + rc = davinci_emac_cpufreq_register(priv);
> + if (rc) {
> + dev_err(&pdev->dev, "error in register_netdev\n");
Really?
> + rc = -ENODEV;
> + goto cpufreq_reg_err;
> + }
> +#endif
> return 0;
>
> +#ifdef CONFIG_CPU_FREQ
> +cpufreq_reg_err:
> + unregister_netdev(ndev);
> +#endif
> netdev_reg_err:
> clk_disable(emac_clk);
> no_irq_res:
> @@ -1973,6 +2030,9 @@ static int __devexit davinci_emac_remove(struct platform_device *pdev)
>
> release_mem_region(res->start, resource_size(res));
>
> +#ifdef CONFIG_CPU_FREQ
> + davinci_emac_cpufreq_deregister(priv);
> +#endif
This is considered a bad practice to use #ifdef in the body of function.
Define the faunction you call here as empty inline in case CONFIG_CPU_FREQ is
not defined instead. The same about davinci_emac_cpufreq_register().
WBR, Sergei
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] davinci_emac: Add cpu_freq support
2012-04-09 10:49 [PATCH] davinci_emac: Add cpu_freq support Manjunathappa, Prakash
[not found] ` <1333968549-3282-1-git-send-email-prakash.pm-l0cyMroinI0@public.gmane.org>
@ 2012-04-09 15:56 ` Ben Hutchings
1 sibling, 0 replies; 4+ messages in thread
From: Ben Hutchings @ 2012-04-09 15:56 UTC (permalink / raw)
To: Manjunathappa, Prakash
Cc: netdev, davem, linux-kernel, davinci-linux-open-source
On Mon, 2012-04-09 at 16:19 +0530, Manjunathappa, Prakash wrote:
> Reconfigure interrupt coalesce parameter for changed emac bus_freq
> due to DVFS.
>
> Signed-off-by: Manjunathappa, Prakash <prakash.pm@ti.com>
> ---
> drivers/net/ethernet/ti/davinci_emac.c | 60 ++++++++++++++++++++++++++++++++
> 1 files changed, 60 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c
> index 174a334..11d3bd7 100644
> --- a/drivers/net/ethernet/ti/davinci_emac.c
> +++ b/drivers/net/ethernet/ti/davinci_emac.c
> @@ -50,6 +50,7 @@
> #include <linux/ctype.h>
> #include <linux/spinlock.h>
> #include <linux/dma-mapping.h>
> +#include <linux/cpufreq.h>
> #include <linux/clk.h>
> #include <linux/platform_device.h>
> #include <linux/semaphore.h>
> @@ -344,6 +345,9 @@ struct emac_priv {
> /*platform specific members*/
> void (*int_enable) (void);
> void (*int_disable) (void);
> +#ifdef CONFIG_CPU_FREQ
> + struct notifier_block freq_transition;
> +#endif
> };
>
> /* clock frequency for EMAC */
> @@ -1761,6 +1765,46 @@ static const struct net_device_ops emac_netdev_ops = {
> #endif
> };
>
> +#ifdef CONFIG_CPU_FREQ
> +static int davinci_emac_cpufreq_transition(struct notifier_block *nb,
> + unsigned long val, void *data)
> +{
> + int ret = 0;
> + struct emac_priv *priv;
> +
> + priv = container_of(nb, struct emac_priv, freq_transition);
> + if (priv->coal_intvl != 0) {
> + if (val == CPUFREQ_POSTCHANGE) {
> + if (emac_bus_frequency != clk_get_rate(emac_clk)) {
> + struct ethtool_coalesce coal;
> +
> + emac_bus_frequency = clk_get_rate(emac_clk);
> +
> + priv->bus_freq_mhz = (u32)(emac_bus_frequency /
> + 1000000);
> + coal.rx_coalesce_usecs = (priv->coal_intvl
> + << 4);
> + ret = emac_set_coalesce(priv->ndev, &coal);
[...]
Ick. Why don't you break up emac_set_coalesce() so that you can push
this one value to the hardware without faking up a struct
ethtool_coalesce? Don't you need to push it on reset/resume anyway?
Ben.
--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH] davinci_emac: Add cpu_freq support
2012-04-09 11:29 ` Sergei Shtylyov
@ 2012-04-10 5:16 ` Manjunathappa, Prakash
0 siblings, 0 replies; 4+ messages in thread
From: Manjunathappa, Prakash @ 2012-04-10 5:16 UTC (permalink / raw)
To: Sergei Shtylyov
Cc: netdev@vger.kernel.org,
davinci-linux-open-source@linux.davincidsp.com,
davem@davemloft.net
Hi Sergei,
On Mon, Apr 09, 2012 at 16:59:52, Sergei Shtylyov wrote:
> Hello.
>
> On 09-04-2012 14:49, Manjunathappa, Prakash wrote:
>
> > Reconfigure interrupt coalesce parameter for changed emac bus_freq
> > due to DVFS.
>
> > Signed-off-by: Manjunathappa, Prakash<prakash.pm@ti.com>
> > ---
> > drivers/net/ethernet/ti/davinci_emac.c | 60 ++++++++++++++++++++++++++++++++
> > 1 files changed, 60 insertions(+), 0 deletions(-)
>
> > diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c
> > index 174a334..11d3bd7 100644
> > --- a/drivers/net/ethernet/ti/davinci_emac.c
> > +++ b/drivers/net/ethernet/ti/davinci_emac.c
> [...]
> > @@ -1761,6 +1765,46 @@ static const struct net_device_ops emac_netdev_ops = {
> > #endif
> > };
> >
> > +#ifdef CONFIG_CPU_FREQ
> > +static int davinci_emac_cpufreq_transition(struct notifier_block *nb,
> > + unsigned long val, void *data)
> > +{
> > + int ret = 0;
> > + struct emac_priv *priv;
> > +
> > + priv = container_of(nb, struct emac_priv, freq_transition);
> > + if (priv->coal_intvl != 0) {
> > + if (val == CPUFREQ_POSTCHANGE) {
> > + if (emac_bus_frequency != clk_get_rate(emac_clk)) {
>
> These 3 *if*s could be collapsed into one, and so indentation level
> lowered significantly.
>
Ok I will tie them with "&&".
> > + struct ethtool_coalesce coal;
> > +
> > + emac_bus_frequency = clk_get_rate(emac_clk);
> > +
> > + priv->bus_freq_mhz = (u32)(emac_bus_frequency /
> > + 1000000);
> > + coal.rx_coalesce_usecs = (priv->coal_intvl
> > + << 4);
> > + ret = emac_set_coalesce(priv->ndev,&coal);
> > + }
> > + }
> > + }
> > + return ret;
> > +}
> > +
> > +static inline int davinci_emac_cpufreq_register(struct emac_priv *priv)
> > +{
> > + priv->freq_transition.notifier_call = davinci_emac_cpufreq_transition;
> > + return cpufreq_register_notifier(&priv->freq_transition,
> > + CPUFREQ_TRANSITION_NOTIFIER);
> > +}
> > +
> > +static inline void davinci_emac_cpufreq_deregister(struct emac_priv *priv)
> > +{
> > + cpufreq_unregister_notifier(&priv->freq_transition,
> > + CPUFREQ_TRANSITION_NOTIFIER);
> > +}
> > +#endif
> > +
> > /**
> > * davinci_emac_probe: EMAC device probe
> > * @pdev: The DaVinci EMAC device that we are removing
> > @@ -1925,8 +1969,21 @@ static int __devinit davinci_emac_probe(struct platform_device *pdev)
> > "(regs: %p, irq: %d)\n",
> > (void *)priv->emac_base_phys, ndev->irq);
> > }
> > +
> > +#ifdef CONFIG_CPU_FREQ
> > + rc = davinci_emac_cpufreq_register(priv);
> > + if (rc) {
> > + dev_err(&pdev->dev, "error in register_netdev\n");
>
> Really?
>
Ahh, my bad... I will fix this.
> > + rc = -ENODEV;
> > + goto cpufreq_reg_err;
> > + }
> > +#endif
> > return 0;
> >
> > +#ifdef CONFIG_CPU_FREQ
> > +cpufreq_reg_err:
> > + unregister_netdev(ndev);
> > +#endif
> > netdev_reg_err:
> > clk_disable(emac_clk);
> > no_irq_res:
> > @@ -1973,6 +2030,9 @@ static int __devexit davinci_emac_remove(struct platform_device *pdev)
> >
> > release_mem_region(res->start, resource_size(res));
> >
> > +#ifdef CONFIG_CPU_FREQ
> > + davinci_emac_cpufreq_deregister(priv);
> > +#endif
>
> This is considered a bad practice to use #ifdef in the body of function.
> Define the faunction you call here as empty inline in case CONFIG_CPU_FREQ is
> not defined instead. The same about davinci_emac_cpufreq_register().
>
Ok. I will correct this as you suggested.
Thanks,
Prakash
> WBR, Sergei
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-04-10 5:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-09 10:49 [PATCH] davinci_emac: Add cpu_freq support Manjunathappa, Prakash
[not found] ` <1333968549-3282-1-git-send-email-prakash.pm-l0cyMroinI0@public.gmane.org>
2012-04-09 11:29 ` Sergei Shtylyov
2012-04-10 5:16 ` Manjunathappa, Prakash
2012-04-09 15:56 ` Ben Hutchings
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).