On Thu, Jun 06, 2019 at 12:06:17PM -0600, Robert Hancock wrote:
> SFP device polling can cause problems during the shutdown process if the
> parent devices of the network controller have been shut down already.
> This problem was seen on the iMX6 platform with PCIe devices, where
> accessing the device after the bus is shut down causes a hang.
> 
> Stop all delayed work in the SFP driver during the shutdown process, and
> set a flag which causes any further state checks or state machine events
> (possibly triggered by previous GPIO IRQs) to be skipped.
> 
> Signed-off-by: Robert Hancock <hanc...@sedsystems.ca>
> ---
> 
> This is an updated version of a previous patch "net: sfp: Stop SFP polling
> during shutdown" with the addition of stopping handling of GPIO-triggered
> interrupts as well, as pointed out by Russell King.
> 
>  drivers/net/phy/sfp.c | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
> 
> diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
> index 554acc8..5fdf573 100644
> --- a/drivers/net/phy/sfp.c
> +++ b/drivers/net/phy/sfp.c
> @@ -191,6 +191,7 @@ struct sfp {
>       struct delayed_work poll;
>       struct delayed_work timeout;
>       struct mutex sm_mutex;
> +     bool shutdown;
>       unsigned char sm_mod_state;
>       unsigned char sm_dev_state;
>       unsigned short sm_state;
> @@ -1466,6 +1467,11 @@ static void sfp_sm_mod_remove(struct sfp *sfp)
>  static void sfp_sm_event(struct sfp *sfp, unsigned int event)
>  {
>       mutex_lock(&sfp->sm_mutex);
> +     if (unlikely(sfp->shutdown)) {
> +             /* Do not handle any more state machine events. */
> +             mutex_unlock(&sfp->sm_mutex);
> +             return;
> +     }
>  
>       dev_dbg(sfp->dev, "SM: enter %s:%s:%s event %s\n",
>               mod_state_to_str(sfp->sm_mod_state),
> @@ -1704,6 +1710,13 @@ static void sfp_check_state(struct sfp *sfp)
>  {
>       unsigned int state, i, changed;
>  
> +     mutex_lock(&sfp->sm_mutex);
> +     if (unlikely(sfp->shutdown)) {
> +             /* No more state checks */
> +             mutex_unlock(&sfp->sm_mutex);
> +             return;
> +     }
> +

I don't think you need to add the mutex locking - just check for
sfp->shutdown and be done with it...

> +static void sfp_shutdown(struct platform_device *pdev)
> +{
> +     struct sfp *sfp = platform_get_drvdata(pdev);
> +
> +     mutex_lock(&sfp->sm_mutex);
> +     sfp->shutdown = true;
> +     mutex_unlock(&sfp->sm_mutex);
> +
> +     cancel_delayed_work_sync(&sfp->poll);
> +     cancel_delayed_work_sync(&sfp->timeout);

Since the work cancellation will ensure that the works are not running
at the point they return, and should they then run again, they'll hit
the sfp->shutdown condition.

> +}
> +
>  static struct platform_driver sfp_driver = {
>       .probe = sfp_probe,
>       .remove = sfp_remove,
> +     .shutdown = sfp_shutdown,
>       .driver = {
>               .name = "sfp",
>               .of_match_table = sfp_of_match,
> -- 
> 1.8.3.1
> 
> 

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up

Reply via email to