2024-06-07 11:44:02

by Crescent CY Hsieh

[permalink] [raw]
Subject: [PATCH 1/6] tty: serial: 8250: Fix the amount of ports doesn't match the device

Normally, the amount of ports is written at the third digit of device ID
of Moxa PCI boards, for example: `0x1121` indicates a 2 ports device.

However, `CP116E_A_A` and `CP116E_A_B` are two exceptions, which has 8
ports but the third digit of device ID is `6`.

This patch fixes the issue above by adding checks.

Signed-off-by: Crescent Hsieh <[email protected]>
---
drivers/tty/serial/8250/8250_pci.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index 40af74b55933..4e88ee07e548 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -2041,6 +2041,10 @@ static int pci_moxa_init(struct pci_dev *dev)
unsigned int num_ports = (device & 0x00F0) >> 4, i;
u8 val, init_mode = MOXA_RS232;

+ if (device == PCI_DEVICE_ID_MOXA_CP116E_A_A ||
+ device == PCI_DEVICE_ID_MOXA_CP116E_A_B)
+ num_ports = 8;
+
if (!(pci_moxa_supported_rs(dev) & MOXA_SUPP_RS232)) {
init_mode = MOXA_RS422;
}
--
2.34.1



2024-06-08 09:58:49

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 1/6] tty: serial: 8250: Fix the amount of ports doesn't match the device

Fri, Jun 07, 2024 at 07:43:31PM +0800, Crescent Hsieh kirjoitti:
> Normally, the amount of ports is written at the third digit of device ID
> of Moxa PCI boards, for example: `0x1121` indicates a 2 ports device.
>
> However, `CP116E_A_A` and `CP116E_A_B` are two exceptions, which has 8
> ports but the third digit of device ID is `6`.
>
> This patch fixes the issue above by adding checks.

Can you send this patch separately and add Fixes tag?
I will give my tag on it, but the rest needs some additional work
I think.

--
With Best Regards,
Andy Shevchenko



2024-06-11 07:59:08

by Jiri Slaby

[permalink] [raw]
Subject: Re: [PATCH 1/6] tty: serial: 8250: Fix the amount of ports doesn't match the device

On 07. 06. 24, 13:43, Crescent Hsieh wrote:
> Normally, the amount of ports is written at the third digit of device ID
> of Moxa PCI boards, for example: `0x1121` indicates a 2 ports device.
>
> However, `CP116E_A_A` and `CP116E_A_B` are two exceptions, which has 8
> ports but the third digit of device ID is `6`.
>
> This patch fixes the issue above by adding checks.
>
> Signed-off-by: Crescent Hsieh <[email protected]>
> ---
> drivers/tty/serial/8250/8250_pci.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
> index 40af74b55933..4e88ee07e548 100644
> --- a/drivers/tty/serial/8250/8250_pci.c
> +++ b/drivers/tty/serial/8250/8250_pci.c
> @@ -2041,6 +2041,10 @@ static int pci_moxa_init(struct pci_dev *dev)
> unsigned int num_ports = (device & 0x00F0) >> 4, i;
> u8 val, init_mode = MOXA_RS232;
>
> + if (device == PCI_DEVICE_ID_MOXA_CP116E_A_A ||
> + device == PCI_DEVICE_ID_MOXA_CP116E_A_B)
> + num_ports = 8;

Can you perhaps introduce a helper like:
static unsigned short mxser_get_nports(struct pci_dev *pdev)
{
switch (pdev->device) {
case ...CP116E_A_A:
case ...CP116E_A_B:
return 8;
}

return FIELD_GET(0x00F0, pdev->device);
}

?

> +
> if (!(pci_moxa_supported_rs(dev) & MOXA_SUPP_RS232)) {
> init_mode = MOXA_RS422;
> }

--
js
suse labs