Skip to content

Commit 48d19fc

Browse files
damien-lemoalbjorn-helgaas
authored andcommitted
PCI: epf-test: Simplify IRQ test commands execution
For the commands COMMAND_RAISE_LEGACY_IRQ, COMMAND_RAISE_MSI_IRQ and COMMAND_RAISE_MSIX_IRQ, the function pci_epf_test_cmd_handler() sets the STATUS_IRQ_RAISED status flag and calls the epc function pci_epc_raise_irq() directly. However, this is also exactly what the pci_epf_test_raise_irq() function does. Avoid duplicating these operations by directly using pci_epf_test_raise_irq() for the IRQ test commands. It is OK to do so as the host side endpoint test driver always set the correct IRQ type for the IRQ test commands. At the same time, move the IRQ number check done for the COMMAND_RAISE_MSI_IRQ and COMMAND_RAISE_MSIX_IRQ commands to pci_epf_test_raise_irq(), to also check the IRQ number requested by the host for other test commands. This significantly simplifies pci_epf_test_cmd_handler(). Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Damien Le Moal <[email protected]> Signed-off-by: Lorenzo Pieralisi <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]>
1 parent 5444737 commit 48d19fc

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

drivers/pci/endpoint/functions/pci-epf-test.c

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test,
613613
struct pci_epf *epf = epf_test->epf;
614614
struct device *dev = &epf->dev;
615615
struct pci_epc *epc = epf->epc;
616+
int count;
616617

617618
reg->status |= STATUS_IRQ_RAISED;
618619

@@ -622,10 +623,22 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test,
622623
PCI_EPC_IRQ_LEGACY, 0);
623624
break;
624625
case IRQ_TYPE_MSI:
626+
count = pci_epc_get_msi(epc, epf->func_no, epf->vfunc_no);
627+
if (reg->irq_number > count || count <= 0) {
628+
dev_err(dev, "Invalid MSI IRQ number %d / %d\n",
629+
reg->irq_number, count);
630+
return;
631+
}
625632
pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no,
626633
PCI_EPC_IRQ_MSI, reg->irq_number);
627634
break;
628635
case IRQ_TYPE_MSIX:
636+
count = pci_epc_get_msix(epc, epf->func_no, epf->vfunc_no);
637+
if (reg->irq_number > count || count <= 0) {
638+
dev_err(dev, "Invalid MSIX IRQ number %d / %d\n",
639+
reg->irq_number, count);
640+
return;
641+
}
629642
pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no,
630643
PCI_EPC_IRQ_MSIX, reg->irq_number);
631644
break;
@@ -638,13 +651,11 @@ static void pci_epf_test_raise_irq(struct pci_epf_test *epf_test,
638651
static void pci_epf_test_cmd_handler(struct work_struct *work)
639652
{
640653
int ret;
641-
int count;
642654
u32 command;
643655
struct pci_epf_test *epf_test = container_of(work, struct pci_epf_test,
644656
cmd_handler.work);
645657
struct pci_epf *epf = epf_test->epf;
646658
struct device *dev = &epf->dev;
647-
struct pci_epc *epc = epf->epc;
648659
enum pci_barno test_reg_bar = epf_test->test_reg_bar;
649660
struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar];
650661

@@ -660,10 +671,10 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
660671
goto reset_handler;
661672
}
662673

663-
if (command & COMMAND_RAISE_LEGACY_IRQ) {
664-
reg->status = STATUS_IRQ_RAISED;
665-
pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no,
666-
PCI_EPC_IRQ_LEGACY, 0);
674+
if ((command & COMMAND_RAISE_LEGACY_IRQ) ||
675+
(command & COMMAND_RAISE_MSI_IRQ) ||
676+
(command & COMMAND_RAISE_MSIX_IRQ)) {
677+
pci_epf_test_raise_irq(epf_test, reg);
667678
goto reset_handler;
668679
}
669680

@@ -697,26 +708,6 @@ static void pci_epf_test_cmd_handler(struct work_struct *work)
697708
goto reset_handler;
698709
}
699710

700-
if (command & COMMAND_RAISE_MSI_IRQ) {
701-
count = pci_epc_get_msi(epc, epf->func_no, epf->vfunc_no);
702-
if (reg->irq_number > count || count <= 0)
703-
goto reset_handler;
704-
reg->status = STATUS_IRQ_RAISED;
705-
pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no,
706-
PCI_EPC_IRQ_MSI, reg->irq_number);
707-
goto reset_handler;
708-
}
709-
710-
if (command & COMMAND_RAISE_MSIX_IRQ) {
711-
count = pci_epc_get_msix(epc, epf->func_no, epf->vfunc_no);
712-
if (reg->irq_number > count || count <= 0)
713-
goto reset_handler;
714-
reg->status = STATUS_IRQ_RAISED;
715-
pci_epc_raise_irq(epc, epf->func_no, epf->vfunc_no,
716-
PCI_EPC_IRQ_MSIX, reg->irq_number);
717-
goto reset_handler;
718-
}
719-
720711
reset_handler:
721712
queue_delayed_work(kpcitest_workqueue, &epf_test->cmd_handler,
722713
msecs_to_jiffies(1));

0 commit comments

Comments
 (0)