diff mbox series

net: macb: ensure the device is available before accessing GEMGXL control registers

Message ID 20210521124859.101012-1-zong.li@sifive.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: macb: ensure the device is available before accessing GEMGXL control registers | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 25 this patch: 25
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 33 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 25 this patch: 25
netdev/header_inline success Link

Commit Message

Zong Li May 21, 2021, 12:48 p.m. UTC
If runtime power menagement is enabled, the gigabit ethernet PLL would
be disabled after macb_probe(). During this period of time, the system
would hang up if we try to access GEMGXL control registers.

We can't put runtime_pm_get/runtime_pm_put/ there due to the issue of
sleep inside atomic section (7fa2955ff70ce453 ("sh_eth: Fix sleeping
function called from invalid context"). Add the similar flag to ensure
the device is available before accessing GEMGXL device.

Signed-off-by: Zong Li <zong.li@sifive.com>
---
 drivers/net/ethernet/cadence/macb.h      | 2 ++
 drivers/net/ethernet/cadence/macb_main.c | 7 +++++++
 2 files changed, 9 insertions(+)

Comments

Florian Fainelli May 21, 2021, 4:51 p.m. UTC | #1
On 5/21/2021 5:48 AM, Zong Li wrote:
> If runtime power menagement is enabled, the gigabit ethernet PLL would
> be disabled after macb_probe(). During this period of time, the system
> would hang up if we try to access GEMGXL control registers.
> 
> We can't put runtime_pm_get/runtime_pm_put/ there due to the issue of
> sleep inside atomic section (7fa2955ff70ce453 ("sh_eth: Fix sleeping
> function called from invalid context"). Add the similar flag to ensure
> the device is available before accessing GEMGXL device.
> 
> Signed-off-by: Zong Li <zong.li@sifive.com>
> ---
>  drivers/net/ethernet/cadence/macb.h      | 2 ++
>  drivers/net/ethernet/cadence/macb_main.c | 7 +++++++
>  2 files changed, 9 insertions(+)
> 
> diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
> index d8d87213697c..acf5242ce715 100644
> --- a/drivers/net/ethernet/cadence/macb.h
> +++ b/drivers/net/ethernet/cadence/macb.h
> @@ -1309,6 +1309,8 @@ struct macb {
>  
>  	u32	rx_intr_mask;
>  
> +	unsigned int is_opened;
> +
>  	struct macb_pm_data pm_data;
>  	const struct macb_usrio_config *usrio;
>  };
> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index 6bc7d41d519b..e079ed10ad91 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -2781,6 +2781,8 @@ static int macb_open(struct net_device *dev)
>  	if (bp->ptp_info)
>  		bp->ptp_info->ptp_init(dev);
>  
> +	bp->is_opened = 1;
> +
>  	return 0;
>  
>  reset_hw:
> @@ -2818,6 +2820,8 @@ static int macb_close(struct net_device *dev)
>  	if (bp->ptp_info)
>  		bp->ptp_info->ptp_remove(dev);
>  
> +	bp->is_opened = 0;
> +
>  	pm_runtime_put(&bp->pdev->dev);
>  
>  	return 0;
> @@ -2867,6 +2871,9 @@ static struct net_device_stats *gem_get_stats(struct macb *bp)
>  	struct gem_stats *hwstat = &bp->hw_stats.gem;
>  	struct net_device_stats *nstat = &bp->dev->stats;
>  
> +	if (!bp->is_opened)
> +		return nstat;

The canonical way to do this check is to use netif_running(), and not
open code a boolean tracking whether a network device is opened or not.
Zong Li May 22, 2021, 9:08 a.m. UTC | #2
On Sat, May 22, 2021 at 12:51 AM Florian Fainelli <f.fainelli@gmail.com> wrote:
>
>
>
> On 5/21/2021 5:48 AM, Zong Li wrote:
> > If runtime power menagement is enabled, the gigabit ethernet PLL would
> > be disabled after macb_probe(). During this period of time, the system
> > would hang up if we try to access GEMGXL control registers.
> >
> > We can't put runtime_pm_get/runtime_pm_put/ there due to the issue of
> > sleep inside atomic section (7fa2955ff70ce453 ("sh_eth: Fix sleeping
> > function called from invalid context"). Add the similar flag to ensure
> > the device is available before accessing GEMGXL device.
> >
> > Signed-off-by: Zong Li <zong.li@sifive.com>
> > ---
> >  drivers/net/ethernet/cadence/macb.h      | 2 ++
> >  drivers/net/ethernet/cadence/macb_main.c | 7 +++++++
> >  2 files changed, 9 insertions(+)
> >
> > diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
> > index d8d87213697c..acf5242ce715 100644
> > --- a/drivers/net/ethernet/cadence/macb.h
> > +++ b/drivers/net/ethernet/cadence/macb.h
> > @@ -1309,6 +1309,8 @@ struct macb {
> >
> >       u32     rx_intr_mask;
> >
> > +     unsigned int is_opened;
> > +
> >       struct macb_pm_data pm_data;
> >       const struct macb_usrio_config *usrio;
> >  };
> > diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> > index 6bc7d41d519b..e079ed10ad91 100644
> > --- a/drivers/net/ethernet/cadence/macb_main.c
> > +++ b/drivers/net/ethernet/cadence/macb_main.c
> > @@ -2781,6 +2781,8 @@ static int macb_open(struct net_device *dev)
> >       if (bp->ptp_info)
> >               bp->ptp_info->ptp_init(dev);
> >
> > +     bp->is_opened = 1;
> > +
> >       return 0;
> >
> >  reset_hw:
> > @@ -2818,6 +2820,8 @@ static int macb_close(struct net_device *dev)
> >       if (bp->ptp_info)
> >               bp->ptp_info->ptp_remove(dev);
> >
> > +     bp->is_opened = 0;
> > +
> >       pm_runtime_put(&bp->pdev->dev);
> >
> >       return 0;
> > @@ -2867,6 +2871,9 @@ static struct net_device_stats *gem_get_stats(struct macb *bp)
> >       struct gem_stats *hwstat = &bp->hw_stats.gem;
> >       struct net_device_stats *nstat = &bp->dev->stats;
> >
> > +     if (!bp->is_opened)
> > +             return nstat;
>
> The canonical way to do this check is to use netif_running(), and not
> open code a boolean tracking whether a network device is opened or not.

Yes, I have tried this and it worked. Let me change it in the next version.

> --
> Florian
diff mbox series

Patch

diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
index d8d87213697c..acf5242ce715 100644
--- a/drivers/net/ethernet/cadence/macb.h
+++ b/drivers/net/ethernet/cadence/macb.h
@@ -1309,6 +1309,8 @@  struct macb {
 
 	u32	rx_intr_mask;
 
+	unsigned int is_opened;
+
 	struct macb_pm_data pm_data;
 	const struct macb_usrio_config *usrio;
 };
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 6bc7d41d519b..e079ed10ad91 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -2781,6 +2781,8 @@  static int macb_open(struct net_device *dev)
 	if (bp->ptp_info)
 		bp->ptp_info->ptp_init(dev);
 
+	bp->is_opened = 1;
+
 	return 0;
 
 reset_hw:
@@ -2818,6 +2820,8 @@  static int macb_close(struct net_device *dev)
 	if (bp->ptp_info)
 		bp->ptp_info->ptp_remove(dev);
 
+	bp->is_opened = 0;
+
 	pm_runtime_put(&bp->pdev->dev);
 
 	return 0;
@@ -2867,6 +2871,9 @@  static struct net_device_stats *gem_get_stats(struct macb *bp)
 	struct gem_stats *hwstat = &bp->hw_stats.gem;
 	struct net_device_stats *nstat = &bp->dev->stats;
 
+	if (!bp->is_opened)
+		return nstat;
+
 	gem_update_stats(bp);
 
 	nstat->rx_errors = (hwstat->rx_frame_check_sequence_errors +