diff mbox series

[net-next:,08/12] ACPI: scan: prevent double enumeration of MDIO bus children

Message ID 20220620150225.1307946-9-mw@semihalf.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series ACPI support for DSA | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers success CCed 3 of 3 maintainers
netdev/build_clang fail Errors and warnings before: 10 this patch: 10
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 27 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Marcin Wojtas June 20, 2022, 3:02 p.m. UTC
The MDIO bus is responsible for probing and registering its respective
children, such as PHYs or other kind of devices.

It is required that ACPI scan code should not enumerate such
devices, leaving this task for the generic MDIO bus routines,
which are initiated by the controller driver.

This patch prevents unwanted enumeration of the devices by setting
'enumeration_by_parent' flag, depending on whether their parent
device is a member of a known list of MDIO controllers. For now,
the Marvell MDIO controllers' IDs are added.

Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 drivers/acpi/scan.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Andy Shevchenko June 20, 2022, 5:53 p.m. UTC | #1
On Mon, Jun 20, 2022 at 05:02:21PM +0200, Marcin Wojtas wrote:
> The MDIO bus is responsible for probing and registering its respective
> children, such as PHYs or other kind of devices.
> 
> It is required that ACPI scan code should not enumerate such
> devices, leaving this task for the generic MDIO bus routines,
> which are initiated by the controller driver.
> 
> This patch prevents unwanted enumeration of the devices by setting
> 'enumeration_by_parent' flag, depending on whether their parent
> device is a member of a known list of MDIO controllers. For now,
> the Marvell MDIO controllers' IDs are added.

This flag is used for serial buses that are not self-discoverable. Not sure
about MDIO, but the current usage has a relation to the _CRS. Have you
considered to propose the MdioSerialBus() resource type to ACPI specification?
Andrew Lunn June 20, 2022, 7:08 p.m. UTC | #2
On Mon, Jun 20, 2022 at 05:02:21PM +0200, Marcin Wojtas wrote:
> The MDIO bus is responsible for probing and registering its respective
> children, such as PHYs or other kind of devices.
> 
> It is required that ACPI scan code should not enumerate such
> devices, leaving this task for the generic MDIO bus routines,
> which are initiated by the controller driver.

I suppose the question is, should you ignore the ACPI way of doing
things, or embrace the ACPI way?

At least please add a comment why the ACPI way is wrong, despite this
being an ACPI binding.

      Andrew
Marcin Wojtas June 20, 2022, 11:04 p.m. UTC | #3
pon., 20 cze 2022 o 19:53 Andy Shevchenko
<andriy.shevchenko@linux.intel.com> napisał(a):
>
> On Mon, Jun 20, 2022 at 05:02:21PM +0200, Marcin Wojtas wrote:
> > The MDIO bus is responsible for probing and registering its respective
> > children, such as PHYs or other kind of devices.
> >
> > It is required that ACPI scan code should not enumerate such
> > devices, leaving this task for the generic MDIO bus routines,
> > which are initiated by the controller driver.
> >
> > This patch prevents unwanted enumeration of the devices by setting
> > 'enumeration_by_parent' flag, depending on whether their parent
> > device is a member of a known list of MDIO controllers. For now,
> > the Marvell MDIO controllers' IDs are added.
>
> This flag is used for serial buses that are not self-discoverable. Not sure
> about MDIO, but the current usage has a relation to the _CRS. Have you
> considered to propose the MdioSerialBus() resource type to ACPI specification?
>

Indeed, one of the cases checked in the
acpi_device_enumeration_by_parent() is checking _CRS (of the bus child
device) for being of the serial bus type. Currently I see
I2C/SPI/UARTSerialBus resource descriptors in the specification. Since
MDIO doesn't seem to require any special description macros like the
mentioned ones (for instance see I2CSerialBusV2 [1]), Based on
example: dfda4492322ed ("ACPI / scan: Do not enumerate Indirect IO
host children"), I thought of similar one perhaps being applicable.

Maybe there is some different, more proper solution, I'd be happy to
hear from the ACPI Maintainers.

[1] https://uefi.org/specs/ACPI/6.4/19_ASL_Reference/ACPI_Source_Language_Reference.html?highlight=i2cserialbus#i2cserialbusterm

Best regards,
Marcin
Rafael J. Wysocki June 22, 2022, 12:05 p.m. UTC | #4
On Mon, Jun 20, 2022 at 9:08 PM Andrew Lunn <andrew@lunn.ch> wrote:
>
> On Mon, Jun 20, 2022 at 05:02:21PM +0200, Marcin Wojtas wrote:
> > The MDIO bus is responsible for probing and registering its respective
> > children, such as PHYs or other kind of devices.
> >
> > It is required that ACPI scan code should not enumerate such
> > devices, leaving this task for the generic MDIO bus routines,
> > which are initiated by the controller driver.
>
> I suppose the question is, should you ignore the ACPI way of doing
> things, or embrace the ACPI way?

What do you mean by "the ACPI way"?

> At least please add a comment why the ACPI way is wrong, despite this
> being an ACPI binding.

The question really is whether or not it is desirable to create
platform devices for all of the objects found in the ACPI tables that
correspond to the devices on the MDIO bus.

I don't think it is, so it should be avoided.
Rafael J. Wysocki June 22, 2022, 12:09 p.m. UTC | #5
On Tue, Jun 21, 2022 at 1:05 AM Marcin Wojtas <mw@semihalf.com> wrote:
>
> pon., 20 cze 2022 o 19:53 Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> napisał(a):
> >
> > On Mon, Jun 20, 2022 at 05:02:21PM +0200, Marcin Wojtas wrote:
> > > The MDIO bus is responsible for probing and registering its respective
> > > children, such as PHYs or other kind of devices.
> > >
> > > It is required that ACPI scan code should not enumerate such
> > > devices, leaving this task for the generic MDIO bus routines,
> > > which are initiated by the controller driver.
> > >
> > > This patch prevents unwanted enumeration of the devices by setting
> > > 'enumeration_by_parent' flag, depending on whether their parent
> > > device is a member of a known list of MDIO controllers. For now,
> > > the Marvell MDIO controllers' IDs are added.
> >
> > This flag is used for serial buses that are not self-discoverable. Not sure
> > about MDIO, but the current usage has a relation to the _CRS. Have you
> > considered to propose the MdioSerialBus() resource type to ACPI specification?
> >
>
> Indeed, one of the cases checked in the
> acpi_device_enumeration_by_parent() is checking _CRS (of the bus child
> device) for being of the serial bus type. Currently I see
> I2C/SPI/UARTSerialBus resource descriptors in the specification. Since
> MDIO doesn't seem to require any special description macros like the
> mentioned ones (for instance see I2CSerialBusV2 [1]), Based on
> example: dfda4492322ed ("ACPI / scan: Do not enumerate Indirect IO
> host children"), I thought of similar one perhaps being applicable.
>
> Maybe there is some different, more proper solution, I'd be happy to
> hear from the ACPI Maintainers.
>
> [1] https://uefi.org/specs/ACPI/6.4/19_ASL_Reference/ACPI_Source_Language_Reference.html?highlight=i2cserialbus#i2cserialbusterm

Well, the approach based on lists of device IDs is not scalable and
generally used as the last resort one.

It would be a lot better to have a way of representing connections to
the MDIO bus as resources in _CRS.
Marcin Wojtas June 22, 2022, 3:05 p.m. UTC | #6
śr., 22 cze 2022 o 14:09 Rafael J. Wysocki <rafael@kernel.org> napisał(a):
>
> On Tue, Jun 21, 2022 at 1:05 AM Marcin Wojtas <mw@semihalf.com> wrote:
> >
> > pon., 20 cze 2022 o 19:53 Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> napisał(a):
> > >
> > > On Mon, Jun 20, 2022 at 05:02:21PM +0200, Marcin Wojtas wrote:
> > > > The MDIO bus is responsible for probing and registering its respective
> > > > children, such as PHYs or other kind of devices.
> > > >
> > > > It is required that ACPI scan code should not enumerate such
> > > > devices, leaving this task for the generic MDIO bus routines,
> > > > which are initiated by the controller driver.
> > > >
> > > > This patch prevents unwanted enumeration of the devices by setting
> > > > 'enumeration_by_parent' flag, depending on whether their parent
> > > > device is a member of a known list of MDIO controllers. For now,
> > > > the Marvell MDIO controllers' IDs are added.
> > >
> > > This flag is used for serial buses that are not self-discoverable. Not sure
> > > about MDIO, but the current usage has a relation to the _CRS. Have you
> > > considered to propose the MdioSerialBus() resource type to ACPI specification?
> > >
> >
> > Indeed, one of the cases checked in the
> > acpi_device_enumeration_by_parent() is checking _CRS (of the bus child
> > device) for being of the serial bus type. Currently I see
> > I2C/SPI/UARTSerialBus resource descriptors in the specification. Since
> > MDIO doesn't seem to require any special description macros like the
> > mentioned ones (for instance see I2CSerialBusV2 [1]), Based on
> > example: dfda4492322ed ("ACPI / scan: Do not enumerate Indirect IO
> > host children"), I thought of similar one perhaps being applicable.
> >
> > Maybe there is some different, more proper solution, I'd be happy to
> > hear from the ACPI Maintainers.
> >
> > [1] https://uefi.org/specs/ACPI/6.4/19_ASL_Reference/ACPI_Source_Language_Reference.html?highlight=i2cserialbus#i2cserialbusterm
>
> Well, the approach based on lists of device IDs is not scalable and
> generally used as the last resort one.
>
> It would be a lot better to have a way of representing connections to
> the MDIO bus as resources in _CRS.

Thank you for your input. I will submit a proposal for MDIOSerialBus
_CRS resource macro then.

Best regards,
Marcin
Florian Fainelli June 22, 2022, 4:12 p.m. UTC | #7
On 6/22/22 05:05, Rafael J. Wysocki wrote:
> On Mon, Jun 20, 2022 at 9:08 PM Andrew Lunn <andrew@lunn.ch> wrote:
>>
>> On Mon, Jun 20, 2022 at 05:02:21PM +0200, Marcin Wojtas wrote:
>>> The MDIO bus is responsible for probing and registering its respective
>>> children, such as PHYs or other kind of devices.
>>>
>>> It is required that ACPI scan code should not enumerate such
>>> devices, leaving this task for the generic MDIO bus routines,
>>> which are initiated by the controller driver.
>>
>> I suppose the question is, should you ignore the ACPI way of doing
>> things, or embrace the ACPI way?
> 
> What do you mean by "the ACPI way"?
> 
>> At least please add a comment why the ACPI way is wrong, despite this
>> being an ACPI binding.
> 
> The question really is whether or not it is desirable to create
> platform devices for all of the objects found in the ACPI tables that
> correspond to the devices on the MDIO bus.

If we have devices hanging off a MDIO bus then they are mdio_device (and 
possibly a more specialized object with the phy_device which does embedd 
a mdio_device object), not platform devices, since MDIO is a bus in itself.
Rafael J. Wysocki June 22, 2022, 4:21 p.m. UTC | #8
On Wed, Jun 22, 2022 at 6:12 PM Florian Fainelli <f.fainelli@gmail.com> wrote:
>
> On 6/22/22 05:05, Rafael J. Wysocki wrote:
> > On Mon, Jun 20, 2022 at 9:08 PM Andrew Lunn <andrew@lunn.ch> wrote:
> >>
> >> On Mon, Jun 20, 2022 at 05:02:21PM +0200, Marcin Wojtas wrote:
> >>> The MDIO bus is responsible for probing and registering its respective
> >>> children, such as PHYs or other kind of devices.
> >>>
> >>> It is required that ACPI scan code should not enumerate such
> >>> devices, leaving this task for the generic MDIO bus routines,
> >>> which are initiated by the controller driver.
> >>
> >> I suppose the question is, should you ignore the ACPI way of doing
> >> things, or embrace the ACPI way?
> >
> > What do you mean by "the ACPI way"?
> >
> >> At least please add a comment why the ACPI way is wrong, despite this
> >> being an ACPI binding.
> >
> > The question really is whether or not it is desirable to create
> > platform devices for all of the objects found in the ACPI tables that
> > correspond to the devices on the MDIO bus.
>
> If we have devices hanging off a MDIO bus then they are mdio_device (and
> possibly a more specialized object with the phy_device which does embedd
> a mdio_device object), not platform devices, since MDIO is a bus in itself.

Well, that's what I'm saying.

And when the ACPI subsystem finds those device objects present in the
ACPI tables, the mdio_device things have not been created yet and it
doesn't know which ACPI device object will correspond to mdio_device
eventually unless it is told about that somehow.  One way of doing
that is to use a list of device IDs in the kernel.  The other is to
have the firmware tell it about that which is what we are discussing.
Andrew Lunn June 23, 2022, 7:41 a.m. UTC | #9
> And when the ACPI subsystem finds those device objects present in the
> ACPI tables, the mdio_device things have not been created yet and it
> doesn't know which ACPI device object will correspond to mdio_device
> eventually unless it is told about that somehow.  One way of doing
> that is to use a list of device IDs in the kernel.  The other is to
> have the firmware tell it about that which is what we are discussing.

Device IDs is a complex subject with MDIO devices. It has somewhat
evolved over time, and it could also be that ACPI decides to do
something different, or simpler, to what DT does.

If the device is an Ethernet PHY, and it follows C22, it has two
registers in a well defined location, which when combined give you a
vendor model and version. So we scan the bus, look at each address on
the bus, try to read these registers and if we don't get 0xffff back,
we assume it is a PHY, create an mdio_device, sub type it to
phy_device, and then load and probe the driver based on the ID
registers.

If the device is using C45, we currently will not be able to enumerate
it this way. We have a number of MDIO bus drivers which don't
implement C45, but also don't return -EOPNOTSUPP. They will perform a
malformed C22 transaction, or go wrong in some other horrible way. So
in DT, we have a compatible string to indicate there is a C45 devices
at the address. We then do look around in the C45 address space at the
different locations where the ID registers can be, and if we get a
valid looking ID, probe the driver using that.

We also have some chicken/egg problems. Some PHYs won't respond when
you read there ID registers until you have turned on clocks, disabled
reset lines, enable regulators etc. For these devices, we place the ID
as you would read from the ID registers in DT as the compatible
string. The mdio_device is created, sub-types as a PHY and the probe
happens using the ID register found in DT. The driver can then do what
it needs to do to get the device to respond on the bus.

Then we have devices on the bus which are not PHYs, but generic
mdio_devices. These are mostly Ethernet switches, but Broadcom have
some other MDIO devices which are not switches. For these, we have
compatible strings which identifies the device as a normal string,
which then probes the correct driver in the normal way for a
compatible string.

So giving the kernel a list of device IDs is not simple. I expect
dealing with this will be a big part of defining how MDIOSerialBus
works.

   Andrew
Marcin Wojtas June 23, 2022, 11:07 p.m. UTC | #10
czw., 23 cze 2022 o 09:42 Andrew Lunn <andrew@lunn.ch> napisał(a):
>
> > And when the ACPI subsystem finds those device objects present in the
> > ACPI tables, the mdio_device things have not been created yet and it
> > doesn't know which ACPI device object will correspond to mdio_device
> > eventually unless it is told about that somehow.  One way of doing
> > that is to use a list of device IDs in the kernel.  The other is to
> > have the firmware tell it about that which is what we are discussing.
>
> Device IDs is a complex subject with MDIO devices. It has somewhat
> evolved over time, and it could also be that ACPI decides to do
> something different, or simpler, to what DT does.
>
> If the device is an Ethernet PHY, and it follows C22, it has two
> registers in a well defined location, which when combined give you a
> vendor model and version. So we scan the bus, look at each address on
> the bus, try to read these registers and if we don't get 0xffff back,
> we assume it is a PHY, create an mdio_device, sub type it to
> phy_device, and then load and probe the driver based on the ID
> registers.
>
> If the device is using C45, we currently will not be able to enumerate
> it this way. We have a number of MDIO bus drivers which don't
> implement C45, but also don't return -EOPNOTSUPP. They will perform a
> malformed C22 transaction, or go wrong in some other horrible way. So
> in DT, we have a compatible string to indicate there is a C45 devices
> at the address. We then do look around in the C45 address space at the
> different locations where the ID registers can be, and if we get a
> valid looking ID, probe the driver using that.
>
> We also have some chicken/egg problems. Some PHYs won't respond when
> you read there ID registers until you have turned on clocks, disabled
> reset lines, enable regulators etc. For these devices, we place the ID
> as you would read from the ID registers in DT as the compatible
> string. The mdio_device is created, sub-types as a PHY and the probe
> happens using the ID register found in DT. The driver can then do what
> it needs to do to get the device to respond on the bus.
>

Currently the PHY detection (based on compatible string property in
_DSD) and handling of both ACPI and DT paths are shared by calling the
same routine fwnode_mdiobus_register_phy() and all the following
generic code. No ID's involved.

With MDIOSerialBus property we can probably pass additional
information about PHY's via one of the fields in _CRS, however, this
will implicate deviating from the common code with DT. Let's discuss
it under ECR.

> Then we have devices on the bus which are not PHYs, but generic
> mdio_devices. These are mostly Ethernet switches, but Broadcom have
> some other MDIO devices which are not switches. For these, we have
> compatible strings which identifies the device as a normal string,
> which then probes the correct driver in the normal way for a
> compatible string.

_HID/_CID fields will be used for that, as in any other driver. In
case Broadcom decides to support ACPI, they will have to define their
own ACPI ID and update the relevant driver (extend struct mdio_driver
with  .acpi_match_table field) - see patch 12/12 as an example.

>
> So giving the kernel a list of device IDs is not simple. I expect
> dealing with this will be a big part of defining how MDIOSerialBus
> works.
>

Actually the _HID/_CID fields values will still be required for the
devices on the bus and the relevant drivers will use it for matching,
which is analogous for the compatible string handling. The
MDIOSerialBus _CRS macro will not be used for this purpose, same as
already existing examples of I2CSerialBus or SPISerialBus (although
the child devices use them, they also have _HID/_CID for
identification).

What we agreed for is to get rid of is a static list of MDIO
controllers ID's, which I proposed in this patch, whose intention was
to prevent its enumeration by the default ACPI scan routines, in case
the device's parent is a listed MDIO bus. Instead, just the presence
of MDIOSerialBus macro in the _CRS method of the child device will
suffice to get it skipped at that point. Any other data in this macro
will be in fact something extra that we can use for any purpose.

Best regards,
Marcin
diff mbox series

Patch

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 762b61f67e6c..d703c35dc218 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1716,6 +1716,18 @@  static bool acpi_is_indirect_io_slave(struct acpi_device *device)
 	return parent && !acpi_match_device_ids(parent, indirect_io_hosts);
 }
 
+static bool acpi_is_mdio_child(struct acpi_device *device)
+{
+	struct acpi_device *parent = device->parent;
+	static const struct acpi_device_id mdio_controllers[] = {
+		{"MRVL0100", 0},
+		{"MRVL0101", 0},
+		{}
+	};
+
+	return parent && !acpi_match_device_ids(parent, mdio_controllers);
+}
+
 static bool acpi_device_enumeration_by_parent(struct acpi_device *device)
 {
 	struct list_head resource_list;
@@ -1756,6 +1768,9 @@  static bool acpi_device_enumeration_by_parent(struct acpi_device *device)
 	if (acpi_is_indirect_io_slave(device))
 		return true;
 
+	if (acpi_is_mdio_child(device))
+		return true;
+
 	/* Macs use device properties in lieu of _CRS resources */
 	if (x86_apple_machine &&
 	    (fwnode_property_present(&device->fwnode, "spiSclkPeriod") ||