Re: [PATCH] serial: 8250: Default SERIAL_OF_PLATFORM to SERIAL_8250

2018-12-20 Thread Florian Fainelli
Le 12/20/18 à 9:38 AM, Guenter Roeck a écrit :
> On Thu, Dec 20, 2018 at 04:21:11PM +0100, Greg Kroah-Hartman wrote:
>> On Wed, Nov 14, 2018 at 05:11:25PM -0800, Guenter Roeck wrote:
>>> On Thu, Nov 01, 2018 at 11:26:06AM -0700, Florian Fainelli wrote:
 It is way too easy to miss enabling SERIAL_OF_PLATFORM which would
 result in the inability for the kernel to have a valid console device,
 which can be seen with:

 Warning: unable to open an initial console.

 and then:

 Run /init as init process
 Kernel panic - not syncing: Attempted to kill init! exitcode=0x0100

 Since SERIAL_OF_PLATFORM already depends on SERIAL_8250 && OF there
 really is no drawback to defaulting this config to the value of
 SERIAL_8250.

 Signed-off-by: Florian Fainelli 
 Signed-off-by: Greg Kroah-Hartman 
>>>
>>> This patch results in situations where CONFIG_SERIAL_OF_PLATFORM is now
>>> defined where it was not previously. Example mpc85xx_defconfig. This in
>>> turn results in boot failures for those configurations, with an error
>>> message of
>>>
>>> of_serial: probe of e0004500.serial failed with error -22
>>>
>>> which wasn't seen before.
>>>
>>> Not sure if replacing a potential problem with a real one is really an
>>> improvement.`
>>
>> What ever was the result of this long thread?  Should I revert
>> something?  Or was a patch proposed?
>>
> The problem still exists in next-20181220.

I submitted a tentative patch to fix the problem, discussed it with
Michael and he had an alternative patch to 8250_core.c that should work
equally well though I was worried more breakage could be created that
way. Since clearly we have not been able to make much progress, maybe a
reversion of the original patch is appropriate, yes it's now sent a as a
reply to this mail! 

> 
> Unfortunately this is now just one failure of many in -next. I see more
> than 90 boot failures (out of ~330) there, not counting the build failures.
> And that is on a good day.
> 
> Guenter
> 


-- 
Florian


Re: [PATCH] serial: 8250: Default SERIAL_OF_PLATFORM to SERIAL_8250

2018-12-05 Thread Florian Fainelli
On 12/4/18 9:47 PM, Michael Ellerman wrote:
> Hi Florian,
> 
> Florian Fainelli  writes:
>> +PPC folks
>>
>> On 11/23/18 10:20 AM, Guenter Roeck wrote:
>>> On Mon, Nov 19, 2018 at 12:50:50PM -0800, Guenter Roeck wrote:
 On Mon, Nov 19, 2018 at 10:44:30AM -0800, Florian Fainelli wrote:
> On 11/15/18 5:16 PM, Guenter Roeck wrote:
>> On Thu, Nov 15, 2018 at 11:48:20AM -0800, Florian Fainelli wrote:
>>>
>>> OK, would you mind testing this below? It seems to me that 8250_of.c is
>>> incompatible with arch/powerpc/kernel/legacy_serial.c and that is what
>>> is causing the issue here.
>>>
>>> diff --git a/drivers/tty/serial/8250/Kconfig
>>> b/drivers/tty/serial/8250/Kconfig
>>> index d7737dca0e48..21cb14cbd34a 100644
>>> --- a/drivers/tty/serial/8250/Kconfig
>>> +++ b/drivers/tty/serial/8250/Kconfig
>>> @@ -483,7 +483,7 @@ config SERIAL_8250_PXA
>>>
>>>  config SERIAL_OF_PLATFORM
>>> tristate "Devicetree based probing for 8250 ports"
>>> -   depends on SERIAL_8250 && OF
>>> +   depends on SERIAL_8250 && OF && !(PPC && PPC_UDBG_16550)
>>> default SERIAL_8250
>>> help
>>>   This option is used for all 8250 compatible serial ports that
>>
>> 44x/virtex5_defconfig has both PPC_UDBG_16550 and SERIAL_OF_PLATFORM 
>> enabled
>> and fails to boot (or display anything on the console) with this patch 
>> applied.
>
> Thanks for trying, can you either share or provide a link to the mpc85xx
> and ml507 qemu command lines that you use? I spent a good chunk of my
> time trying to get a kernel to boot but has failed so far.
>

>>>
>>> Any update ? I still see the boot failures in next-20181123.
>>
>> Yes, took most of last week's off sorry for the delay. I have finally
>> been able to boot a kernel using your instructions, thanks. The problem
>> is the following call chain:
>>
>> of_platform_serial_probe()
>>  -> serial8250_register_8250_port()
>> -> up->port.uartclk == 0, return -EINVAL
>>  -> irq_dispose_mapping()
>>
>> and then we basically unwind what we just did with
>> of_platform_serial_probe() including disabling the UART's IRQ, comment
>> out the irq_dispose_mapping() and you will have a functional console
>> again. 8250_of.c is clearly not a full replacement for legacy_serial.c
>> (that was a first attempt), so we need to keep that code around. Making
>> the depends even more conditional also does not sound too appealing,
>> because while we have identified mpc85xx as being problematic, who knows
>> about other platforms. So the best I have that does not involve a revert
>> is this below.
>>
>> Ben, Michael, would that sound reasonable to you? It seems to me that
>> there is a million ways to shoot the legacy_serial 8250 registration in
>> the foot in any cases, and having CONFIG_SERIAL_OF_PLATFORM just made it
>> painfully obvious.
> 
> We generally try to avoid changing the device tree from inside Linux,
> it's meant to describe the hardware as we're given it, not the state of
> Linux drivers etc. Perhaps this is an exceptional case but it still
> seems fishy.

Technically this is changing the Linux internal representation of a
Device Tree node reference (device_node), which is a bit away from
actual HW representation.

> 
> I also worry that marking the device node disabled might break something
> else, but that's maybe me being paranoid.

The code as it is today only makes use of device_node pointers/Device
Tree to find out about the UART base address and a bunch of properties,
but it registers the UART as platform_device without making use of the
existing OF infrastructure to do that (historical reasons really).

> 
> I guess I don't really understand how things are supposed to work
> though. We have the 8250 driver and also the OF platform driver, the
> former has already setup the device and then the OF driver just comes
> along and takes over?

When the OF platform driver comes along it tries to register the same
device instance, fails to do so because the port->clk is 0, which the
8250 core thinks is an error, and then it starts unwinding the 8250 port
structure, which in turns steps on the instance that was registered
manually by legacy_serial.c

> 
> eg. in the boot log from the mpc8544ds you see:
> 
>   serial8250.0: ttyS0 at MMIO 0xe0004500 (irq = 42, base_baud = 115200) is a 
> 16550A
>   printk: console [ttyS0] enabled
>   printk: console [ttyS0] enabled
>   printk: bootconsole [udbg0] disabled
>   printk: bootconsole [udbg0] disabled
>   of_serial: probe of e0004500.serial failed with error -22
> 
> ie. the 8250 core has already setup the device, so there should really
> be nothing to do?
> 
> If the 8250 code could detect that it already has this port registered
> then maybe things would work.
> 
> The patch below works for me with mpc8544ds. Whether it's worth changing
> the 8250 code this much to accomodate legacy_serial 

Re: [PATCH] serial: 8250: Default SERIAL_OF_PLATFORM to SERIAL_8250

2018-12-04 Thread Michael Ellerman
Hi Florian,

Florian Fainelli  writes:
> +PPC folks
>
> On 11/23/18 10:20 AM, Guenter Roeck wrote:
>> On Mon, Nov 19, 2018 at 12:50:50PM -0800, Guenter Roeck wrote:
>>> On Mon, Nov 19, 2018 at 10:44:30AM -0800, Florian Fainelli wrote:
 On 11/15/18 5:16 PM, Guenter Roeck wrote:
> On Thu, Nov 15, 2018 at 11:48:20AM -0800, Florian Fainelli wrote:
>>
>> OK, would you mind testing this below? It seems to me that 8250_of.c is
>> incompatible with arch/powerpc/kernel/legacy_serial.c and that is what
>> is causing the issue here.
>>
>> diff --git a/drivers/tty/serial/8250/Kconfig
>> b/drivers/tty/serial/8250/Kconfig
>> index d7737dca0e48..21cb14cbd34a 100644
>> --- a/drivers/tty/serial/8250/Kconfig
>> +++ b/drivers/tty/serial/8250/Kconfig
>> @@ -483,7 +483,7 @@ config SERIAL_8250_PXA
>>
>>  config SERIAL_OF_PLATFORM
>> tristate "Devicetree based probing for 8250 ports"
>> -   depends on SERIAL_8250 && OF
>> +   depends on SERIAL_8250 && OF && !(PPC && PPC_UDBG_16550)
>> default SERIAL_8250
>> help
>>   This option is used for all 8250 compatible serial ports that
>
> 44x/virtex5_defconfig has both PPC_UDBG_16550 and SERIAL_OF_PLATFORM 
> enabled
> and fails to boot (or display anything on the console) with this patch 
> applied.

 Thanks for trying, can you either share or provide a link to the mpc85xx
 and ml507 qemu command lines that you use? I spent a good chunk of my
 time trying to get a kernel to boot but has failed so far.

>>>
>> 
>> Any update ? I still see the boot failures in next-20181123.
>
> Yes, took most of last week's off sorry for the delay. I have finally
> been able to boot a kernel using your instructions, thanks. The problem
> is the following call chain:
>
> of_platform_serial_probe()
>  -> serial8250_register_8250_port()
> -> up->port.uartclk == 0, return -EINVAL
>   -> irq_dispose_mapping()
>
> and then we basically unwind what we just did with
> of_platform_serial_probe() including disabling the UART's IRQ, comment
> out the irq_dispose_mapping() and you will have a functional console
> again. 8250_of.c is clearly not a full replacement for legacy_serial.c
> (that was a first attempt), so we need to keep that code around. Making
> the depends even more conditional also does not sound too appealing,
> because while we have identified mpc85xx as being problematic, who knows
> about other platforms. So the best I have that does not involve a revert
> is this below.
>
> Ben, Michael, would that sound reasonable to you? It seems to me that
> there is a million ways to shoot the legacy_serial 8250 registration in
> the foot in any cases, and having CONFIG_SERIAL_OF_PLATFORM just made it
> painfully obvious.

We generally try to avoid changing the device tree from inside Linux,
it's meant to describe the hardware as we're given it, not the state of
Linux drivers etc. Perhaps this is an exceptional case but it still
seems fishy.

I also worry that marking the device node disabled might break something
else, but that's maybe me being paranoid.

I guess I don't really understand how things are supposed to work
though. We have the 8250 driver and also the OF platform driver, the
former has already setup the device and then the OF driver just comes
along and takes over?

eg. in the boot log from the mpc8544ds you see:

  serial8250.0: ttyS0 at MMIO 0xe0004500 (irq = 42, base_baud = 115200) is a 
16550A
  printk: console [ttyS0] enabled
  printk: console [ttyS0] enabled
  printk: bootconsole [udbg0] disabled
  printk: bootconsole [udbg0] disabled
  of_serial: probe of e0004500.serial failed with error -22

ie. the 8250 core has already setup the device, so there should really
be nothing to do?

If the 8250 code could detect that it already has this port registered
then maybe things would work.

The patch below works for me with mpc8544ds. Whether it's worth changing
the 8250 code this much to accomodate legacy_serial I'm not sure.

cheers


diff --git a/drivers/tty/serial/8250/8250_core.c 
b/drivers/tty/serial/8250/8250_core.c
index 94f3e1c64490..c7d7858fdb3d 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -905,7 +905,7 @@ static struct platform_device *serial8250_isa_devs;
  */
 static DEFINE_MUTEX(serial_mutex);
 
-static struct uart_8250_port *serial8250_find_match_or_unused(struct uart_port 
*port)
+static struct uart_8250_port *serial8250_find_existing(struct uart_port *port)
 {
int i;
 
@@ -921,10 +921,17 @@ static struct uart_8250_port 
*serial8250_find_match_or_unused(struct uart_port *
if (i < nr_uarts && serial8250_ports[i].port.type == PORT_UNKNOWN &&
serial8250_ports[i].port.iobase == 0)
return _ports[i];
+
+   return NULL;
+}
+
+static struct uart_8250_port *serial8250_find_unused(struct uart_port *port)
+{
+  

Re: [PATCH] serial: 8250: Default SERIAL_OF_PLATFORM to SERIAL_8250

2018-11-26 Thread Florian Fainelli
+PPC folks

On 11/23/18 10:20 AM, Guenter Roeck wrote:
> On Mon, Nov 19, 2018 at 12:50:50PM -0800, Guenter Roeck wrote:
>> On Mon, Nov 19, 2018 at 10:44:30AM -0800, Florian Fainelli wrote:
>>> On 11/15/18 5:16 PM, Guenter Roeck wrote:
 On Thu, Nov 15, 2018 at 11:48:20AM -0800, Florian Fainelli wrote:
>
> OK, would you mind testing this below? It seems to me that 8250_of.c is
> incompatible with arch/powerpc/kernel/legacy_serial.c and that is what
> is causing the issue here.
>
> diff --git a/drivers/tty/serial/8250/Kconfig
> b/drivers/tty/serial/8250/Kconfig
> index d7737dca0e48..21cb14cbd34a 100644
> --- a/drivers/tty/serial/8250/Kconfig
> +++ b/drivers/tty/serial/8250/Kconfig
> @@ -483,7 +483,7 @@ config SERIAL_8250_PXA
>
>  config SERIAL_OF_PLATFORM
> tristate "Devicetree based probing for 8250 ports"
> -   depends on SERIAL_8250 && OF
> +   depends on SERIAL_8250 && OF && !(PPC && PPC_UDBG_16550)
> default SERIAL_8250
> help
>   This option is used for all 8250 compatible serial ports that

 44x/virtex5_defconfig has both PPC_UDBG_16550 and SERIAL_OF_PLATFORM 
 enabled
 and fails to boot (or display anything on the console) with this patch 
 applied.
>>>
>>> Thanks for trying, can you either share or provide a link to the mpc85xx
>>> and ml507 qemu command lines that you use? I spent a good chunk of my
>>> time trying to get a kernel to boot but has failed so far.
>>>
>>
> 
> Any update ? I still see the boot failures in next-20181123.

Yes, took most of last week's off sorry for the delay. I have finally
been able to boot a kernel using your instructions, thanks. The problem
is the following call chain:

of_platform_serial_probe()
 -> serial8250_register_8250_port()
-> up->port.uartclk == 0, return -EINVAL
-> irq_dispose_mapping()

and then we basically unwind what we just did with
of_platform_serial_probe() including disabling the UART's IRQ, comment
out the irq_dispose_mapping() and you will have a functional console
again. 8250_of.c is clearly not a full replacement for legacy_serial.c
(that was a first attempt), so we need to keep that code around. Making
the depends even more conditional also does not sound too appealing,
because while we have identified mpc85xx as being problematic, who knows
about other platforms. So the best I have that does not involve a revert
is this below.

Ben, Michael, would that sound reasonable to you? It seems to me that
there is a million ways to shoot the legacy_serial 8250 registration in
the foot in any cases, and having CONFIG_SERIAL_OF_PLATFORM just made it
painfully obvious.

diff --git a/arch/powerpc/kernel/legacy_serial.c
b/arch/powerpc/kernel/legacy_serial.c
index 33b34a58fc62..31353a27d714 100644
--- a/arch/powerpc/kernel/legacy_serial.c
+++ b/arch/powerpc/kernel/legacy_serial.c
@@ -16,7 +16,7 @@
 #include 
 #include 

-#undef DEBUG
+#define DEBUG

 #ifdef DEBUG
 #define DBG(fmt...) do { printk(fmt); } while(0)
@@ -70,6 +70,29 @@ static void tsi_serial_out(struct uart_port *p, int
offset, int value)
writeb(value, p->membase + offset);
 }

+#ifdef CONFIG_SERIAL_OF_PLATFORM
+static struct property uart_prop = {
+   .value = "disabled",
+   .name = "status",
+   .length = strlen("disabled"),
+};
+
+static void __init disable_uart_node(struct device_node *np)
+{
+   /* To avoid having 8250_of.c attempt to register the same device
+* and failing to do, and calling irq_dispose_mapping(), just
+* disable the device_node for now.
+*/
+   of_update_property(np, _prop);
+   pr_info("%s: disabled UART node\n", __func__);
+}
+#else
+static inline int disable_uart_node(struct device_node *np)
+{
+   return 0;
+}
+#endif
+
 static int __init add_legacy_port(struct device_node *np, int want_index,
  int iotype, phys_addr_t base,
  phys_addr_t taddr, unsigned long irq,
@@ -80,6 +103,8 @@ static int __init add_legacy_port(struct device_node
*np, int want_index,
u32 shift = 0;
int index;

+   disable_uart_node(np);
+
/* get clock freq. if present */
clk = of_get_property(np, "clock-frequency", NULL);
if (clk && *clk)



-- 
Florian