RE: Possible ACPI abuse in Mellanox BlueField Gigabit Ethernet driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




-----Original Message-----
From: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> 
Sent: Thursday, August 12, 2021 12:26 PM
To: Asmaa Mnebhi <asmaa@xxxxxxxxxx>
Cc: Linux GPIO <linux-gpio@xxxxxxxxxxxxxxx>; linux-acpi@xxxxxxxxxxxxxxx; Rafael J. Wysocki <rjw@xxxxxxxxxxxxx>; Linus Walleij <linus.walleij@xxxxxxxxxx>; Bartosz Golaszewski <bgolaszewski@xxxxxxxxxxxx>; David Thompson <davthompson@xxxxxxxxxx>; Liming Sun <limings@xxxxxxxxxx>; David S. Miller <davem@xxxxxxxxxxxxx>
Subject: Re: Possible ACPI abuse in Mellanox BlueField Gigabit Ethernet driver

On Thu, Aug 12, 2021 at 03:54:26PM +0000, Asmaa Mnebhi wrote:
> Hi Andy,

Thanks for prompt response!
My first question, is it already firmware in the wild that does this?
I.o.w. is there any time to amend it if needed?

Asmaa> Are you asking if it is possible to change the ACPI table's GPIO pin on the fly at boot time in UEFI code?

> We have 1 image common to all our board types. The ACPI tables are 
> selected based on the board id. Some board types have PHY_INT pin 
> connected to GPIO pin 9 and other boards have it connected to GPIO pin 
> 12. So we have 2 ssdt.asl files:

Okay (You may have one and actually choose it based on some [NVS] variable)

Asmaa> Ok!

> // first file: PHY_INT -> GPIO pin 12
> Device(OOB) {
>         Name(_HID, "MLNXBF17")
>         Name(_UID, 0)
>         Name(_CCA, 1)
>         Name (_CRS, ResourceTemplate () {
>            // OOB Ethernet
>            Memory32Fixed (ReadWrite, 0x03000000, 0x00000600)
>            // mdio[9]
>            Memory32Fixed (ReadWrite, 0x028004C8, 0x00000008)
>            // gpio[0]
>            Memory32Fixed (ReadWrite, 0x0280c000, 0x00000100)
>            // OOB LLU
>            Memory32Fixed (ReadWrite, 0x039C0000, 0x0000A100)
>            // OOB PLU
>            Memory32Fixed (ReadWrite, 0x04000000, 0x00001100)
>            Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { BF_RSH0_DEVICE_OOB_INT }
>            Interrupt (ResourceConsumer, Edge, ActiveHigh, Exclusive) { BF_RSH0_DEVICE_OOB_LLU_INT }
>            Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { BF_RSH0_DEVICE_OOB_PLU_INT }
>            Interrupt (ResourceConsumer, Edge, ActiveHigh, Shared) { BF_RSH0_DEVICE_YU_INT }
>   
>            // GPIO PHY interrupt
>            GpioInt (Edge, ActiveHigh, Exclusive, PullUp, , " 
> \\_SB.GPI0") {12}

PullUp with Edge/Rise seems a bit awkward. Recently I have added a corresponding paragraph to the https://www.kernel.org/doc/html/latest/firmware-guide/acpi/gpio-properties.html.
But it's just to double check that you got the idea how your hardware works (maybe it uses open-drain or so and it's indeed the correct setting).

Asmaa> I forgot to cp/paste one more line from the ACPI tables. I have created a DSD entry and named the gpio (although as you pointed below, it is not really needed in this case):
Name (_DSD, Package () {
           ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */,
           Package ()
           {
              Package () { "phy-gpios", Package() {^OOB, 0, 0, 0 }},
           }
       })

The interrupt that we care about (which signals link up/link down events) is actually the shared HW irq BF_RSH0_DEVICE_YU_INT (edge triggered, active high whenever there is an i2c, mdio or gpio interrupt). 
We get that interrupt value from the ACPI table as follows:
priv->hw_phy_irq = platform_get_irq(pdev, MLXBF_GIGE_PHY_INT_N);

Although it is overkill, I only used "GpioInt (Edge, ActiveHigh, Exclusive, PullUp, \\_SB.GPI0") {12}" to retrieve the GPIO pin number (12 or 9) in mlxbf-gige. 
We could also have created a property (phy-gpio-pin) to pass the GPIO pin and that would enable us to remove all code related to "GpioInt" code in the acpi and mlxbf-gige driver. But I thought that properties are in general not the preferred approach?

So whenever that shared interrupt is triggered, this routine is executed mlxbf_gige_gpio_handler:
ret = devm_request_irq(dev, priv->hw_phy_irq, mlxbf_gige_gpio_handler,
                                IRQF_ONESHOT | IRQF_SHARED, "mlxbf_gige_phy", priv);
It checks whether the interrupt is for GPIO pin 9 or 12 (depending on the board). If it is, it clears the interrupt accordingly and triggers the generic phy_interrupt routine (in phy.c)
phy_interrupt is registered via phy_connect_direct.

What I have seen here is a regular GpioInt() resource with a single pin.

Asmaa> Yes we only use one GPIO pin.

As far as I can see in the code it has the flaw that it actually will use the last GpioInt() resource available in _CRS.

Besides that, why do you need to know the pin name and can't simply request an IRQ as every other driver does (the exception is only yours in the entire kernel)? The acpi_dev_gpio_irq_get() call can get Linux vIRQ for you same way you have got it for Interrupt() resources via platform_get_irq().

To understand better this piece, can you point out to the GPIO driver code, which implements the driver for _SB.GPI0 in the kernel?

>         }) // Name(_CRS)
> 
> // Second file: PHY_INT -> GPIO pin 9
> Device(OOB) {
>         Name(_HID, "MLNXBF17")
>         Name(_UID, 0)
>         Name(_CCA, 1)
>         Name (_CRS, ResourceTemplate () {
>            // OOB Ethernet
>            Memory32Fixed (ReadWrite, 0x03000000, 0x00000600)
>            // mdio[9]
>            Memory32Fixed (ReadWrite, 0x028004C8, 0x00000008)
>            // gpio[0]
>            Memory32Fixed (ReadWrite, 0x0280c000, 0x00000100)
>            // OOB LLU
>            Memory32Fixed (ReadWrite, 0x039C0000, 0x0000A100)
>            // OOB PLU
>            Memory32Fixed (ReadWrite, 0x04000000, 0x00001100)
>            Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { BF_RSH0_DEVICE_OOB_INT }
>            Interrupt (ResourceConsumer, Edge, ActiveHigh, Exclusive) { BF_RSH0_DEVICE_OOB_LLU_INT }
>            Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { BF_RSH0_DEVICE_OOB_PLU_INT }
>            Interrupt (ResourceConsumer, Edge, ActiveHigh, Shared) { 
> BF_RSH0_DEVICE_YU_INT }
>   
>            // GPIO PHY interrupt
>            GpioInt (Edge, ActiveHigh, Exclusive, PullUp, , " \\_SB.GPI0") {9}
>         }) // Name(_CRS)
> 
> -----Original Message-----
> From: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> Sent: Thursday, August 12, 2021 10:14 AM
> To: Linux GPIO <linux-gpio@xxxxxxxxxxxxxxx>; 
> linux-acpi@xxxxxxxxxxxxxxx; Rafael J. Wysocki <rjw@xxxxxxxxxxxxx>; 
> Linus Walleij <linus.walleij@xxxxxxxxxx>; Bartosz Golaszewski 
> <bgolaszewski@xxxxxxxxxxxx>
> Cc: David Thompson <davthompson@xxxxxxxxxx>; Asmaa Mnebhi 
> <asmaa@xxxxxxxxxx>; Liming Sun <limings@xxxxxxxxxx>; David S. Miller 
> <davem@xxxxxxxxxxxxx>
> Subject: Possible ACPI abuse in Mellanox BlueField Gigabit Ethernet 
> driver
> 
> Hi!
> 
> From time to time I do grep kernel for ACPI_RESOURCE_TYPE_GPIO usage.
> Recently the 
> drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_gpio.c
> caught my eye.
> 
> Looking into the code I see that it looks like misunderstanding of how ACPI works with GPIOs. First of all, I would like to inform that this code has been properly reviewed neither by GPIO nor by ACPI maintainers. Second, before going it to the real conclusions (and potential revert of this), I would like to see the real ACPI tables for this and some explanations from the authors of the driver about GPIO usage here (from hw and sw perspectives).
> 
> It makes sense to discuss ASAP, otherwise I would really want to revert it.
> 
> --
> With Best Regards,
> Andy Shevchenko
> 
> 

--
With Best Regards,
Andy Shevchenko






[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux