All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Fabio Estevam <festevam@gmail.com>
Cc: Schrempf Frieder <frieder.schrempf@kontron.de>,
	Martyn Welch <martyn.welch@collabora.com>,
	Marek Vasut <marex@denx.de>, USB list <linux-usb@vger.kernel.org>,
	oneukum@suse.com, Adam Ford <aford173@gmail.com>,
	peter.chen@kernel.org,
	Steve Glendinning <steve.glendinning@shawell.net>,
	fntoth@gmail.com
Subject: Re: smsc9511: Register access happens after unregistration
Date: Sat, 5 Mar 2022 00:59:55 +0100	[thread overview]
Message-ID: <YiKn+yJlaovkEGTR@lunn.ch> (raw)
In-Reply-To: <CAOMZO5D_875KnWVK+P+-D8zOQyCTzwKDfoXbZWfi01fSKRSSew@mail.gmail.com>

On Fri, Mar 04, 2022 at 03:01:28PM -0300, Fabio Estevam wrote:
> On Fri, Mar 4, 2022 at 12:57 PM Fabio Estevam <festevam@gmail.com> wrote:
> >
> > On Fri, Mar 4, 2022 at 11:51 AM Andrew Lunn <andrew@lunn.ch> wrote:
> >
> > > But why does it return ENODEV? It seems to me, ignoring it is papering
> > > over the cracks. Why cannot we access to the PHY?
> >
> > The -ENODEV is returned by usb_control_msg():
> >
> > __smsc95xx_read_reg: -19
> >          usbnet_read_cmd: -19
> >               usb_control_msg: -19
> 
> I added a WARN_ON() inside usb_control_msg() that triggers when
> usb_control_msg() returns -ENODEV.

https://elixir.bootlin.com/linux/v5.17-rc6/source/include/linux/usb.h#L1126

say:

 * @disconnect: Called when the interface is no longer accessible, usually
 *	because its device has been (or is being) disconnected or the
 *	driver module is being unloaded.

So i guess the USB core has disconnected the device, and is blocking
further control messages. I guess it handles shutdown the same as hot
unplug. So there are a couple things that can be done to make this
better.

Make __smsc95xx_phy_wait_not_busy(), __smsc95xx_mdio_read() and
__smsc95xx_mdio_write() not print a message on -ENODEV. I would
continue printing the warning for other error codes. The phylib and
phy drivers should be O.K. if they get -ENODEV.

Non-USB Ethernet drivers follow one of two patterns:

1) The PHY is connected in probe, started in open, stopped in close,
   and disconnected in remove.

2) The PHY is both connected and started in open, and stopped and
   disconnected in close.

Depending on what userspace you are using, i think it is normal for
userspace to ifdown interfaces during shutdown. So if you make use of
2) the PHY should be disconnected by the time the USB subsystem calls
the USB disconnect callback. However, for hot unplug, there will not
be an ifdown, so the disconnect callback needs to look at state
information and stop and disconnect the PHY if it is currently
connected and started.

	Andrew

      reply	other threads:[~2022-03-05  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-03 13:14 smsc9511: Register access happens after unregistration Fabio Estevam
2022-03-04 13:58 ` Fabio Estevam
2022-03-04 14:11   ` Andrew Lunn
2022-03-04 14:18     ` Martyn Welch
2022-03-04 14:45       ` Andrew Lunn
2022-03-04 14:40     ` Fabio Estevam
2022-03-04 14:51       ` Andrew Lunn
2022-03-04 15:57         ` Fabio Estevam
2022-03-04 18:01           ` Fabio Estevam
2022-03-04 23:59             ` Andrew Lunn [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YiKn+yJlaovkEGTR@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=aford173@gmail.com \
    --cc=festevam@gmail.com \
    --cc=fntoth@gmail.com \
    --cc=frieder.schrempf@kontron.de \
    --cc=linux-usb@vger.kernel.org \
    --cc=marex@denx.de \
    --cc=martyn.welch@collabora.com \
    --cc=oneukum@suse.com \
    --cc=peter.chen@kernel.org \
    --cc=steve.glendinning@shawell.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.