Skip to contentSkip to conversation

serial: 8250_exar: derive nr_ports from ID for Acces I/O cards

PATCH Superseded Andy Shevchenko 3 participants 4 messages Dec 22, 2021 – Dec 23, 2021 TTY layer and serial drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: 8250_exar: derive nr_ports from ID for Acces I/O cards

In the similar way how it's done in 8250_pericom, derive number of UART ports from PCI ID for Acces I/O cards.

---
 drivers/tty/serial/8250/8250_exar.c | 37 ++++++++++-------------------
 1 file changed, 13 insertions(+), 24 deletions(-)
drivers/tty/serial/8250/8250_exar.c +13 -24
index a4508ac0cac9..cf16bd889abd 100644
@@ -611,7 +611,12 @@ exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
 
 	maxnr = pci_resource_len(pcidev, bar) >> (board->reg_shift + 3);
 
-	nr_ports = board->num_ports ? board->num_ports : pcidev->device & 0x0f;
+	if (pcidev->vendor == PCI_VENDOR_ID_ACCESSIO)
+		nr = BIT(((pcidev->device & 0x38) >> 3) - 1);
+	else if (board->num_ports)
+		nr_ports = board->num_ports;
+	else
+		nr_ports = pcidev->device & 0x0f;
 
 	priv = devm_kzalloc(&pcidev->dev, struct_size(priv, line, nr_ports), GFP_KERNEL);
 	if (!priv)
@@ -710,22 +715,6 @@ static int __maybe_unused exar_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(exar_pci_pm, exar_suspend, exar_resume);
 
-static const struct exar8250_board acces_com_2x = {
-	.num_ports	= 2,
-	.setup		= pci_xr17c154_setup,
-};
-
-static const struct exar8250_board acces_com_4x = {
-	.num_ports	= 4,
-	.setup		= pci_xr17c154_setup,
-};
-
-static const struct exar8250_board acces_com_8x = {
-	.num_ports	= 8,
-	.setup		= pci_xr17c154_setup,
-};
-
-
 static const struct exar8250_board pbn_fastcom335_2 = {
 	.num_ports	= 2,
 	.setup		= pci_fastcom335_setup,
@@ -810,13 +799,13 @@ static const struct exar8250_board pbn_exar_XR17V8358 = {
 	}
 
 static const struct pci_device_id exar_pci_tbl[] = {
-	EXAR_DEVICE(ACCESSIO, COM_2S, acces_com_2x),
-	EXAR_DEVICE(ACCESSIO, COM_4S, acces_com_4x),
-	EXAR_DEVICE(ACCESSIO, COM_8S, acces_com_8x),
-	EXAR_DEVICE(ACCESSIO, COM232_8, acces_com_8x),
-	EXAR_DEVICE(ACCESSIO, COM_2SM, acces_com_2x),
-	EXAR_DEVICE(ACCESSIO, COM_4SM, acces_com_4x),
-	EXAR_DEVICE(ACCESSIO, COM_8SM, acces_com_8x),
+	EXAR_DEVICE(ACCESSIO, COM_2S, pbn_exar_XR17C15x),
+	EXAR_DEVICE(ACCESSIO, COM_4S, pbn_exar_XR17C15x),
+	EXAR_DEVICE(ACCESSIO, COM_8S, pbn_exar_XR17C15x),
+	EXAR_DEVICE(ACCESSIO, COM232_8, pbn_exar_XR17C15x),
+	EXAR_DEVICE(ACCESSIO, COM_2SM, pbn_exar_XR17C15x),
+	EXAR_DEVICE(ACCESSIO, COM_4SM, pbn_exar_XR17C15x),
+	EXAR_DEVICE(ACCESSIO, COM_8SM, pbn_exar_XR17C15x),
 
 	CONNECT_DEVICE(XR17C152, UART_2_232, pbn_connect),
 	CONNECT_DEVICE(XR17C154, UART_4_232, pbn_connect),
Signature · 1 line
2.34.1
#1 lore raw
I love your patch! Yet something to improve:

Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on tty/tty-testing]
[also build test ERROR on v5.16-rc6 next-20211222]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/serial-8250_exar-derive-nr_ports-from-ID-for-Acces-I-O-cards/20211223-034500
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing
config: riscv-randconfig-r042-20211222 (https://download.01.org/0day-ci/archive/20211223/202112230724.7vFjZf3K-lkp(a)intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project de4e0195ae1c39f1c3b07834b8e32c113f4f20eb)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/0day-ci/linux/commit/533949cbef2191c3b9dd62584b56648987bc1e5b
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Andy-Shevchenko/serial-8250_exar-derive-nr_ports-from-ID-for-Acces-I-O-cards/20211223-034500 git checkout 533949cbef2191c3b9dd62584b56648987bc1e5b
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash drivers/tty/serial/8250/

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

>> drivers/tty/serial/8250/8250_exar.c:627:3: error: use of undeclared identifier 'nr'
                   nr = BIT(((pcidev->device & 0x38) >> 3) - 1);
                   ^

1 error generated.

vim +/nr +627 drivers/tty/serial/8250/8250_exar.c

606
607 static int
608 exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
609 {
610 unsigned int nr_ports, i, bar = 0, maxnr;
611 struct exar8250_board *board;
612 struct uart_8250_port uart;
613 struct exar8250 *priv;
614 int rc;
615
616 board = (struct exar8250_board *)ent->driver_data;
617 if (!board)
618 return -EINVAL;
619
620 rc = pcim_enable_device(pcidev);
621 if (rc)
622 return rc;
623
624 maxnr = pci_resource_len(pcidev, bar) >> (board->reg_shift + 3);
625
626 if (pcidev->vendor == PCI_VENDOR_ID_ACCESSIO)

 > 627			nr = BIT(((pcidev->device & 0x38) >> 3) - 1);

628 else if (board->num_ports)
629 nr_ports = board->num_ports;
630 else
631 nr_ports = pcidev->device & 0x0f;
632
633 priv = devm_kzalloc(&pcidev->dev, struct_size(priv, line, nr_ports), GFP_KERNEL);
634 if (!priv)
635 return -ENOMEM;
636
637 priv->board = board;
638 priv->virt = pcim_iomap(pcidev, bar, 0);
639 if (!priv->virt)
640 return -ENOMEM;
641
642 pci_set_master(pcidev);
643
644 rc = pci_alloc_irq_vectors(pcidev, 1, 1, PCI_IRQ_ALL_TYPES);
645 if (rc < 0)
646 return rc;
647
648 memset(&uart, 0, sizeof(uart));
649 uart.port.flags = UPF_SHARE_IRQ | UPF_EXAR_EFR | UPF_FIXED_TYPE | UPF_FIXED_PORT;
650 uart.port.irq = pci_irq_vector(pcidev, 0);
651 uart.port.dev = &pcidev->dev;
652
653 rc = devm_request_irq(&pcidev->dev, uart.port.irq, exar_misc_handler,
654 IRQF_SHARED, "exar_uart", priv);
655 if (rc)
656 return rc;
657
658 /* Clear interrupts */
659 exar_misc_clear(priv);
660
661 for (i = 0; i < nr_ports && i < maxnr; i++) {
662 rc = board->setup(priv, pcidev, &uart, i);
663 if (rc) {
664 dev_err(&pcidev->dev, "Failed to setup port %u\n", i);
665 break;
666 }
667
668 dev_dbg(&pcidev->dev, "Setup PCI port: port %lx, irq %d, type %d\n",
669 uart.port.iobase, uart.port.irq, uart.port.iotype);
670
671 priv->line[i] = serial8250_register_8250_port(&uart);
672 if (priv->line[i] < 0) {
673 dev_err(&pcidev->dev,
674 "Couldn't register serial port %lx, irq %d, type %d, error %d\n",
675 uart.port.iobase, uart.port.irq,
676 uart.port.iotype, priv->line[i]);
677 break;
678 }
679 }
680 priv->nr = i;
681 pci_set_drvdata(pcidev, priv);
682 return 0;
683 }
684

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#2 lore raw
In reply to Andy Shevchenko
Quoted 13 lines · Andy Shevchenko

In the similar way how it's done in 8250_pericom, derive number of UART ports from PCI ID for Acces I/O cards.

---
 drivers/tty/serial/8250/8250_exar.c | 37 ++++++++++-------------------
 1 file changed, 13 insertions(+), 24 deletions(-)
drivers/tty/serial/8250/8250_exar.c +0 -0
index a4508ac0cac9..cf16bd889abd 100644

drivers/tty/serial/8250/8250_exar.c exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent) · line 615

Quoted 6 lines
drivers/tty/serial/8250/8250_exar.c +2 -1
@@ -611,7 +611,12 @@ exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
 
 	maxnr = pci_resource_len(pcidev, bar) >> (board->reg_shift + 3);
 
-	nr_ports = board->num_ports ? board->num_ports : pcidev->device & 0x0f;
+	if (pcidev->vendor == PCI_VENDOR_ID_ACCESSIO)
+		nr = BIT(((pcidev->device & 0x38) >> 3) - 1);

Shouldn't this be nr_ports = ...

Signature · 1 line
 i.
Quoted 52 lines
drivers/tty/serial/8250/8250_exar.c +11 -23
+	else if (board->num_ports)
+		nr_ports = board->num_ports;
+	else
+		nr_ports = pcidev->device & 0x0f;
 
 	priv = devm_kzalloc(&pcidev->dev, struct_size(priv, line, nr_ports), GFP_KERNEL);
 	if (!priv)
@@ -710,22 +715,6 @@ static int __maybe_unused exar_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(exar_pci_pm, exar_suspend, exar_resume);
 
-static const struct exar8250_board acces_com_2x = {
-	.num_ports	= 2,
-	.setup		= pci_xr17c154_setup,
-};
-
-static const struct exar8250_board acces_com_4x = {
-	.num_ports	= 4,
-	.setup		= pci_xr17c154_setup,
-};
-
-static const struct exar8250_board acces_com_8x = {
-	.num_ports	= 8,
-	.setup		= pci_xr17c154_setup,
-};
-
-
 static const struct exar8250_board pbn_fastcom335_2 = {
 	.num_ports	= 2,
 	.setup		= pci_fastcom335_setup,
@@ -810,13 +799,13 @@ static const struct exar8250_board pbn_exar_XR17V8358 = {
 	}
 
 static const struct pci_device_id exar_pci_tbl[] = {
-	EXAR_DEVICE(ACCESSIO, COM_2S, acces_com_2x),
-	EXAR_DEVICE(ACCESSIO, COM_4S, acces_com_4x),
-	EXAR_DEVICE(ACCESSIO, COM_8S, acces_com_8x),
-	EXAR_DEVICE(ACCESSIO, COM232_8, acces_com_8x),
-	EXAR_DEVICE(ACCESSIO, COM_2SM, acces_com_2x),
-	EXAR_DEVICE(ACCESSIO, COM_4SM, acces_com_4x),
-	EXAR_DEVICE(ACCESSIO, COM_8SM, acces_com_8x),
+	EXAR_DEVICE(ACCESSIO, COM_2S, pbn_exar_XR17C15x),
+	EXAR_DEVICE(ACCESSIO, COM_4S, pbn_exar_XR17C15x),
+	EXAR_DEVICE(ACCESSIO, COM_8S, pbn_exar_XR17C15x),
+	EXAR_DEVICE(ACCESSIO, COM232_8, pbn_exar_XR17C15x),
+	EXAR_DEVICE(ACCESSIO, COM_2SM, pbn_exar_XR17C15x),
+	EXAR_DEVICE(ACCESSIO, COM_4SM, pbn_exar_XR17C15x),
+	EXAR_DEVICE(ACCESSIO, COM_8SM, pbn_exar_XR17C15x),
 
 	CONNECT_DEVICE(XR17C152, UART_2_232, pbn_connect),
 	CONNECT_DEVICE(XR17C154, UART_4_232, pbn_connect),
#3 lore raw
Quoted 1 line · Ilpo Järvinen

On Wed, 22 Dec 2021, Andy Shevchenko wrote:

...

Quoted 5 lines

drivers/tty/serial/8250/8250_exar.c exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent) · line 615

Quoted 3 lines
drivers/tty/serial/8250/8250_exar.c +2 -1
-	nr_ports = board->num_ports ? board->num_ports : pcidev->device & 0x0f;
+	if (pcidev->vendor == PCI_VENDOR_ID_ACCESSIO)
+		nr = BIT(((pcidev->device & 0x38) >> 3) - 1);

Shouldn't this be nr_ports = ...

Yeah, sorry for that. By some reason I have no such config option enabled and my builds haven't failed.

Signature · 2 lines
With Best Regards,
Andy Shevchenko