Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI: endpoint: Align pci_epc_set_msix(), pci_epc_ops::set_msix() nr_irqs encoding

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

authored by

Niklas Cassel and committed by
Bjorn Helgaas
de0321bc f62da6e7

+14 -18
+3 -5
drivers/pci/controller/cadence/pcie-cadence-ep.c
··· 286 286 } 287 287 288 288 static int cdns_pcie_ep_set_msix(struct pci_epc *epc, u8 fn, u8 vfn, 289 - u16 interrupts, enum pci_barno bir, 290 - u32 offset) 289 + u16 nr_irqs, enum pci_barno bir, u32 offset) 291 290 { 292 291 struct cdns_pcie_ep *ep = epc_get_drvdata(epc); 293 292 struct cdns_pcie *pcie = &ep->pcie; 294 293 u32 cap = CDNS_PCIE_EP_FUNC_MSIX_CAP_OFFSET; 295 294 u32 val, reg; 296 - u16 actual_interrupts = interrupts + 1; 297 295 298 296 fn = cdns_pcie_get_fn_from_vfn(pcie, fn, vfn); 299 297 300 298 reg = cap + PCI_MSIX_FLAGS; 301 299 val = cdns_pcie_ep_fn_readw(pcie, fn, reg); 302 300 val &= ~PCI_MSIX_FLAGS_QSIZE; 303 - val |= interrupts; /* 0's based value */ 301 + val |= nr_irqs - 1; /* encoded as N-1 */ 304 302 cdns_pcie_ep_fn_writew(pcie, fn, reg, val); 305 303 306 304 /* Set MSI-X BAR and offset */ ··· 308 310 309 311 /* Set PBA BAR and offset. BAR must match MSI-X BAR */ 310 312 reg = cap + PCI_MSIX_PBA; 311 - val = (offset + (actual_interrupts * PCI_MSIX_ENTRY_SIZE)) | bir; 313 + val = (offset + (nr_irqs * PCI_MSIX_ENTRY_SIZE)) | bir; 312 314 cdns_pcie_ep_fn_writel(pcie, fn, reg, val); 313 315 314 316 return 0;
+3 -4
drivers/pci/controller/dwc/pcie-designware-ep.c
··· 580 580 } 581 581 582 582 static int dw_pcie_ep_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no, 583 - u16 interrupts, enum pci_barno bir, u32 offset) 583 + u16 nr_irqs, enum pci_barno bir, u32 offset) 584 584 { 585 585 struct dw_pcie_ep *ep = epc_get_drvdata(epc); 586 586 struct dw_pcie *pci = to_dw_pcie_from_ep(ep); 587 587 struct dw_pcie_ep_func *ep_func; 588 588 u32 val, reg; 589 - u16 actual_interrupts = interrupts + 1; 590 589 591 590 ep_func = dw_pcie_ep_get_func_from_ep(ep, func_no); 592 591 if (!ep_func || !ep_func->msix_cap) ··· 596 597 reg = ep_func->msix_cap + PCI_MSIX_FLAGS; 597 598 val = dw_pcie_ep_readw_dbi(ep, func_no, reg); 598 599 val &= ~PCI_MSIX_FLAGS_QSIZE; 599 - val |= interrupts; /* 0's based value */ 600 + val |= nr_irqs - 1; /* encoded as N-1 */ 600 601 dw_pcie_writew_dbi(pci, reg, val); 601 602 602 603 reg = ep_func->msix_cap + PCI_MSIX_TABLE; ··· 604 605 dw_pcie_ep_writel_dbi(ep, func_no, reg, val); 605 606 606 607 reg = ep_func->msix_cap + PCI_MSIX_PBA; 607 - val = (offset + (actual_interrupts * PCI_MSIX_ENTRY_SIZE)) | bir; 608 + val = (offset + (nr_irqs * PCI_MSIX_ENTRY_SIZE)) | bir; 608 609 dw_pcie_ep_writel_dbi(ep, func_no, reg, val); 609 610 610 611 dw_pcie_dbi_ro_wr_dis(pci);
+5 -6
drivers/pci/endpoint/pci-epc-core.c
··· 361 361 * @epc: the EPC device on which MSI-X has to be configured 362 362 * @func_no: the physical endpoint function number in the EPC device 363 363 * @vfunc_no: the virtual endpoint function number in the physical function 364 - * @interrupts: number of MSI-X interrupts required by the EPF 364 + * @nr_irqs: number of MSI-X interrupts required by the EPF 365 365 * @bir: BAR where the MSI-X table resides 366 366 * @offset: Offset pointing to the start of MSI-X table 367 367 * 368 368 * Invoke to set the required number of MSI-X interrupts. 369 369 */ 370 - int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no, 371 - u16 interrupts, enum pci_barno bir, u32 offset) 370 + int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no, u16 nr_irqs, 371 + enum pci_barno bir, u32 offset) 372 372 { 373 373 int ret; 374 374 375 375 if (!pci_epc_function_is_valid(epc, func_no, vfunc_no)) 376 376 return -EINVAL; 377 377 378 - if (interrupts < 1 || interrupts > 2048) 378 + if (nr_irqs < 1 || nr_irqs > 2048) 379 379 return -EINVAL; 380 380 381 381 if (!epc->ops->set_msix) 382 382 return 0; 383 383 384 384 mutex_lock(&epc->lock); 385 - ret = epc->ops->set_msix(epc, func_no, vfunc_no, interrupts - 1, bir, 386 - offset); 385 + ret = epc->ops->set_msix(epc, func_no, vfunc_no, nr_irqs, bir, offset); 387 386 mutex_unlock(&epc->lock); 388 387 389 388 return ret;
+3 -3
include/linux/pci-epc.h
··· 103 103 u8 nr_irqs); 104 104 int (*get_msi)(struct pci_epc *epc, u8 func_no, u8 vfunc_no); 105 105 int (*set_msix)(struct pci_epc *epc, u8 func_no, u8 vfunc_no, 106 - u16 interrupts, enum pci_barno, u32 offset); 106 + u16 nr_irqs, enum pci_barno, u32 offset); 107 107 int (*get_msix)(struct pci_epc *epc, u8 func_no, u8 vfunc_no); 108 108 int (*raise_irq)(struct pci_epc *epc, u8 func_no, u8 vfunc_no, 109 109 unsigned int type, u16 interrupt_num); ··· 288 288 phys_addr_t phys_addr); 289 289 int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no, u8 nr_irqs); 290 290 int pci_epc_get_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no); 291 - int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no, 292 - u16 interrupts, enum pci_barno, u32 offset); 291 + int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no, u16 nr_irqs, 292 + enum pci_barno, u32 offset); 293 293 int pci_epc_get_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no); 294 294 int pci_epc_map_msi_irq(struct pci_epc *epc, u8 func_no, u8 vfunc_no, 295 295 phys_addr_t phys_addr, u8 interrupt_num,