Skip to content

Commit 18d366c

Browse files
floatiousgregkh
authored andcommitted
PCI: endpoint: Align pci_epc_set_msix(), pci_epc_ops::set_msix() nr_irqs encoding
[ Upstream commit de0321b ] 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 Stable-dep-of: 271d0b1 ("PCI: dwc: ep: Fix MSI-X Table Size configuration in dw_pcie_ep_set_msix()") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent ac698c4 commit 18d366c

4 files changed

Lines changed: 14 additions & 18 deletions

File tree

drivers/pci/controller/cadence/pcie-cadence-ep.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,21 +285,19 @@ static int cdns_pcie_ep_get_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no)
285285
}
286286

287287
static int cdns_pcie_ep_set_msix(struct pci_epc *epc, u8 fn, u8 vfn,
288-
u16 interrupts, enum pci_barno bir,
289-
u32 offset)
288+
u16 nr_irqs, enum pci_barno bir, u32 offset)
290289
{
291290
struct cdns_pcie_ep *ep = epc_get_drvdata(epc);
292291
struct cdns_pcie *pcie = &ep->pcie;
293292
u32 cap = CDNS_PCIE_EP_FUNC_MSIX_CAP_OFFSET;
294293
u32 val, reg;
295-
u16 actual_interrupts = interrupts + 1;
296294

297295
fn = cdns_pcie_get_fn_from_vfn(pcie, fn, vfn);
298296

299297
reg = cap + PCI_MSIX_FLAGS;
300298
val = cdns_pcie_ep_fn_readw(pcie, fn, reg);
301299
val &= ~PCI_MSIX_FLAGS_QSIZE;
302-
val |= interrupts; /* 0's based value */
300+
val |= nr_irqs - 1; /* encoded as N-1 */
303301
cdns_pcie_ep_fn_writew(pcie, fn, reg, val);
304302

305303
/* Set MSIX BAR and offset */
@@ -309,7 +307,7 @@ static int cdns_pcie_ep_set_msix(struct pci_epc *epc, u8 fn, u8 vfn,
309307

310308
/* Set PBA BAR and offset. BAR must match MSIX BAR */
311309
reg = cap + PCI_MSIX_PBA;
312-
val = (offset + (actual_interrupts * PCI_MSIX_ENTRY_SIZE)) | bir;
310+
val = (offset + (nr_irqs * PCI_MSIX_ENTRY_SIZE)) | bir;
313311
cdns_pcie_ep_fn_writel(pcie, fn, reg, val);
314312

315313
return 0;

drivers/pci/controller/dwc/pcie-designware-ep.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,12 @@ static int dw_pcie_ep_get_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no)
406406
}
407407

408408
static int dw_pcie_ep_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
409-
u16 interrupts, enum pci_barno bir, u32 offset)
409+
u16 nr_irqs, enum pci_barno bir, u32 offset)
410410
{
411411
struct dw_pcie_ep *ep = epc_get_drvdata(epc);
412412
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
413413
struct dw_pcie_ep_func *ep_func;
414414
u32 val, reg;
415-
u16 actual_interrupts = interrupts + 1;
416415

417416
ep_func = dw_pcie_ep_get_func_from_ep(ep, func_no);
418417
if (!ep_func || !ep_func->msix_cap)
@@ -423,15 +422,15 @@ static int dw_pcie_ep_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
423422
reg = ep_func->msix_cap + PCI_MSIX_FLAGS;
424423
val = dw_pcie_ep_readw_dbi(ep, func_no, reg);
425424
val &= ~PCI_MSIX_FLAGS_QSIZE;
426-
val |= interrupts; /* 0's based value */
425+
val |= nr_irqs - 1; /* encoded as N-1 */
427426
dw_pcie_writew_dbi(pci, reg, val);
428427

429428
reg = ep_func->msix_cap + PCI_MSIX_TABLE;
430429
val = offset | bir;
431430
dw_pcie_ep_writel_dbi(ep, func_no, reg, val);
432431

433432
reg = ep_func->msix_cap + PCI_MSIX_PBA;
434-
val = (offset + (actual_interrupts * PCI_MSIX_ENTRY_SIZE)) | bir;
433+
val = (offset + (nr_irqs * PCI_MSIX_ENTRY_SIZE)) | bir;
435434
dw_pcie_ep_writel_dbi(ep, func_no, reg, val);
436435

437436
dw_pcie_dbi_ro_wr_dis(pci);

drivers/pci/endpoint/pci-epc-core.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,29 +382,28 @@ EXPORT_SYMBOL_GPL(pci_epc_get_msix);
382382
* @epc: the EPC device on which MSI-X has to be configured
383383
* @func_no: the physical endpoint function number in the EPC device
384384
* @vfunc_no: the virtual endpoint function number in the physical function
385-
* @interrupts: number of MSI-X interrupts required by the EPF
385+
* @nr_irqs: number of MSI-X interrupts required by the EPF
386386
* @bir: BAR where the MSI-X table resides
387387
* @offset: Offset pointing to the start of MSI-X table
388388
*
389389
* Invoke to set the required number of MSI-X interrupts.
390390
*/
391-
int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
392-
u16 interrupts, enum pci_barno bir, u32 offset)
391+
int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no, u16 nr_irqs,
392+
enum pci_barno bir, u32 offset)
393393
{
394394
int ret;
395395

396396
if (!pci_epc_function_is_valid(epc, func_no, vfunc_no))
397397
return -EINVAL;
398398

399-
if (interrupts < 1 || interrupts > 2048)
399+
if (nr_irqs < 1 || nr_irqs > 2048)
400400
return -EINVAL;
401401

402402
if (!epc->ops->set_msix)
403403
return 0;
404404

405405
mutex_lock(&epc->lock);
406-
ret = epc->ops->set_msix(epc, func_no, vfunc_no, interrupts - 1, bir,
407-
offset);
406+
ret = epc->ops->set_msix(epc, func_no, vfunc_no, nr_irqs, bir, offset);
408407
mutex_unlock(&epc->lock);
409408

410409
return ret;

include/linux/pci-epc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct pci_epc_ops {
103103
u8 interrupts);
104104
int (*get_msi)(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
105105
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);
107107
int (*get_msix)(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
108108
int (*raise_irq)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
109109
unsigned int type, u16 interrupt_num);
@@ -283,8 +283,8 @@ void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
283283
int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
284284
u8 interrupts);
285285
int pci_epc_get_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
286-
int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
287-
u16 interrupts, enum pci_barno, u32 offset);
286+
int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no, u16 nr_irqs,
287+
enum pci_barno, u32 offset);
288288
int pci_epc_get_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
289289
int pci_epc_map_msi_irq(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
290290
phys_addr_t phys_addr, u8 interrupt_num,

0 commit comments

Comments
 (0)