]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
PCI: endpoint: Align pci_epc_set_msix(), pci_epc_ops::set_msix() nr_irqs encoding
authorNiklas Cassel <cassel@kernel.org>
Wed, 14 May 2025 07:43:19 +0000 (09:43 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 28 May 2025 21:47:56 +0000 (16:47 -0500)
The kdoc for pci_epc_set_msix() says:
"Invoke to set the required number of MSI-X interrupts."

The kdoc for the callback pci_epc_ops->set_msix() says:
"ops to set the requested number of MSI-X interrupts in the MSI-X
capability register"

pci_epc_ops::set_msix() does however expect the parameter 'interrupts' to
be in the encoding as defined by the Table Size field. Nowhere in the
kdoc does it say that the number of interrupts should be in Table Size
encoding.

It is very confusing that the API pci_epc_set_msix() and the callback
function pci_epc_ops::set_msix() both take a parameter named 'interrupts',
but they expect completely different encodings.

Clean up the API and the callback function to have the same semantics,
i.e. the parameter represents the number of interrupts, regardless of the
internal encoding of that value.

Also rename the parameter 'interrupts' to 'nr_irqs', in both the wrapper
function and the callback function, such that the name is unambiguous.

[bhelgaas: more specific subject]

Signed-off-by: Niklas Cassel <cassel@kernel.org>
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: stable+noautosel@kernel.org # this is simply a cleanup
Link: https://patch.msgid.link/20250514074313.283156-14-cassel@kernel.org
drivers/pci/controller/cadence/pcie-cadence-ep.c
drivers/pci/controller/dwc/pcie-designware-ep.c
drivers/pci/endpoint/pci-epc-core.c
include/linux/pci-epc.h

index f09f29ed27edb92e331c3dbfebd532fffd716063..0e9ebe956e7af9c1a942577795a1c532461dc3ec 100644 (file)
@@ -286,21 +286,19 @@ static int cdns_pcie_ep_get_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no)
 }
 
 static int cdns_pcie_ep_set_msix(struct pci_epc *epc, u8 fn, u8 vfn,
-                                u16 interrupts, enum pci_barno bir,
-                                u32 offset)
+                                u16 nr_irqs, enum pci_barno bir, u32 offset)
 {
        struct cdns_pcie_ep *ep = epc_get_drvdata(epc);
        struct cdns_pcie *pcie = &ep->pcie;
        u32 cap = CDNS_PCIE_EP_FUNC_MSIX_CAP_OFFSET;
        u32 val, reg;
-       u16 actual_interrupts = interrupts + 1;
 
        fn = cdns_pcie_get_fn_from_vfn(pcie, fn, vfn);
 
        reg = cap + PCI_MSIX_FLAGS;
        val = cdns_pcie_ep_fn_readw(pcie, fn, reg);
        val &= ~PCI_MSIX_FLAGS_QSIZE;
-       val |= interrupts; /* 0's based value */
+       val |= nr_irqs - 1; /* encoded as N-1 */
        cdns_pcie_ep_fn_writew(pcie, fn, reg, val);
 
        /* Set MSI-X BAR and offset */
@@ -310,7 +308,7 @@ static int cdns_pcie_ep_set_msix(struct pci_epc *epc, u8 fn, u8 vfn,
 
        /* Set PBA BAR and offset.  BAR must match MSI-X BAR */
        reg = cap + PCI_MSIX_PBA;
-       val = (offset + (actual_interrupts * PCI_MSIX_ENTRY_SIZE)) | bir;
+       val = (offset + (nr_irqs * PCI_MSIX_ENTRY_SIZE)) | bir;
        cdns_pcie_ep_fn_writel(pcie, fn, reg, val);
 
        return 0;
index 230e82674591240e90a3385466d3b763ef4d1be9..6770318c0636293d8a7fa4263a4d1747b963a070 100644 (file)
@@ -580,13 +580,12 @@ static int dw_pcie_ep_get_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no)
 }
 
 static int dw_pcie_ep_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
-                              u16 interrupts, enum pci_barno bir, u32 offset)
+                              u16 nr_irqs, enum pci_barno bir, u32 offset)
 {
        struct dw_pcie_ep *ep = epc_get_drvdata(epc);
        struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
        struct dw_pcie_ep_func *ep_func;
        u32 val, reg;
-       u16 actual_interrupts = interrupts + 1;
 
        ep_func = dw_pcie_ep_get_func_from_ep(ep, func_no);
        if (!ep_func || !ep_func->msix_cap)
@@ -597,7 +596,7 @@ static int dw_pcie_ep_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
        reg = ep_func->msix_cap + PCI_MSIX_FLAGS;
        val = dw_pcie_ep_readw_dbi(ep, func_no, reg);
        val &= ~PCI_MSIX_FLAGS_QSIZE;
-       val |= interrupts; /* 0's based value */
+       val |= nr_irqs - 1; /* encoded as N-1 */
        dw_pcie_writew_dbi(pci, reg, val);
 
        reg = ep_func->msix_cap + PCI_MSIX_TABLE;
@@ -605,7 +604,7 @@ static int dw_pcie_ep_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
        dw_pcie_ep_writel_dbi(ep, func_no, reg, val);
 
        reg = ep_func->msix_cap + PCI_MSIX_PBA;
-       val = (offset + (actual_interrupts * PCI_MSIX_ENTRY_SIZE)) | bir;
+       val = (offset + (nr_irqs * PCI_MSIX_ENTRY_SIZE)) | bir;
        dw_pcie_ep_writel_dbi(ep, func_no, reg, val);
 
        dw_pcie_dbi_ro_wr_dis(pci);
index ea698551f9d87bd746157368c258bd32b9c68fc2..ca7f19cc973a43ed9d0be062a1fcd40f82a4ac7a 100644 (file)
@@ -361,29 +361,28 @@ EXPORT_SYMBOL_GPL(pci_epc_get_msix);
  * @epc: the EPC device on which MSI-X has to be configured
  * @func_no: the physical endpoint function number in the EPC device
  * @vfunc_no: the virtual endpoint function number in the physical function
- * @interrupts: number of MSI-X interrupts required by the EPF
+ * @nr_irqs: number of MSI-X interrupts required by the EPF
  * @bir: BAR where the MSI-X table resides
  * @offset: Offset pointing to the start of MSI-X table
  *
  * Invoke to set the required number of MSI-X interrupts.
  */
-int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
-                    u16 interrupts, enum pci_barno bir, u32 offset)
+int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no, u16 nr_irqs,
+                    enum pci_barno bir, u32 offset)
 {
        int ret;
 
        if (!pci_epc_function_is_valid(epc, func_no, vfunc_no))
                return -EINVAL;
 
-       if (interrupts < 1 || interrupts > 2048)
+       if (nr_irqs < 1 || nr_irqs > 2048)
                return -EINVAL;
 
        if (!epc->ops->set_msix)
                return 0;
 
        mutex_lock(&epc->lock);
-       ret = epc->ops->set_msix(epc, func_no, vfunc_no, interrupts - 1, bir,
-                                offset);
+       ret = epc->ops->set_msix(epc, func_no, vfunc_no, nr_irqs, bir, offset);
        mutex_unlock(&epc->lock);
 
        return ret;
index 15d10c07c9f13bc63a8392b3bba98eb098d70e51..4286bfdbfdfad2754d763be2b8474e5d2d403a1f 100644 (file)
@@ -103,7 +103,7 @@ struct pci_epc_ops {
                           u8 nr_irqs);
        int     (*get_msi)(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
        int     (*set_msix)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
-                           u16 interrupts, enum pci_barno, u32 offset);
+                           u16 nr_irqs, enum pci_barno, u32 offset);
        int     (*get_msix)(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
        int     (*raise_irq)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
                             unsigned int type, u16 interrupt_num);
@@ -288,8 +288,8 @@ void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
                        phys_addr_t phys_addr);
 int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no, u8 nr_irqs);
 int pci_epc_get_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
-int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
-                    u16 interrupts, enum pci_barno, u32 offset);
+int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no, u16 nr_irqs,
+                    enum pci_barno, u32 offset);
 int pci_epc_get_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
 int pci_epc_map_msi_irq(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
                        phys_addr_t phys_addr, u8 interrupt_num,