Skip to content

Commit de0321b

Browse files
floatiousbjorn-helgaas
authored andcommitted
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 <[email protected]> Signed-off-by: Manivannan Sadhasivam <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Cc: [email protected] # this is simply a cleanup Link: https://patch.msgid.link/[email protected]
1 parent f62da6e commit de0321b

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

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

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

288288
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)
291290
{
292291
struct cdns_pcie_ep *ep = epc_get_drvdata(epc);
293292
struct cdns_pcie *pcie = &ep->pcie;
294293
u32 cap = CDNS_PCIE_EP_FUNC_MSIX_CAP_OFFSET;
295294
u32 val, reg;
296-
u16 actual_interrupts = interrupts + 1;
297295

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

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

306304
/* 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,
310308

311309
/* Set PBA BAR and offset. BAR must match MSI-X BAR */
312310
reg = cap + PCI_MSIX_PBA;
313-
val = (offset + (actual_interrupts * PCI_MSIX_ENTRY_SIZE)) | bir;
311+
val = (offset + (nr_irqs * PCI_MSIX_ENTRY_SIZE)) | bir;
314312
cdns_pcie_ep_fn_writel(pcie, fn, reg, val);
315313

316314
return 0;

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

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

582582
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)
584584
{
585585
struct dw_pcie_ep *ep = epc_get_drvdata(epc);
586586
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
587587
struct dw_pcie_ep_func *ep_func;
588588
u32 val, reg;
589-
u16 actual_interrupts = interrupts + 1;
590589

591590
ep_func = dw_pcie_ep_get_func_from_ep(ep, func_no);
592591
if (!ep_func || !ep_func->msix_cap)
@@ -597,15 +596,15 @@ static int dw_pcie_ep_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
597596
reg = ep_func->msix_cap + PCI_MSIX_FLAGS;
598597
val = dw_pcie_ep_readw_dbi(ep, func_no, reg);
599598
val &= ~PCI_MSIX_FLAGS_QSIZE;
600-
val |= interrupts; /* 0's based value */
599+
val |= nr_irqs - 1; /* encoded as N-1 */
601600
dw_pcie_writew_dbi(pci, reg, val);
602601

603602
reg = ep_func->msix_cap + PCI_MSIX_TABLE;
604603
val = offset | bir;
605604
dw_pcie_ep_writel_dbi(ep, func_no, reg, val);
606605

607606
reg = ep_func->msix_cap + PCI_MSIX_PBA;
608-
val = (offset + (actual_interrupts * PCI_MSIX_ENTRY_SIZE)) | bir;
607+
val = (offset + (nr_irqs * PCI_MSIX_ENTRY_SIZE)) | bir;
609608
dw_pcie_ep_writel_dbi(ep, func_no, reg, val);
610609

611610
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
@@ -361,29 +361,28 @@ EXPORT_SYMBOL_GPL(pci_epc_get_msix);
361361
* @epc: the EPC device on which MSI-X has to be configured
362362
* @func_no: the physical endpoint function number in the EPC device
363363
* @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
365365
* @bir: BAR where the MSI-X table resides
366366
* @offset: Offset pointing to the start of MSI-X table
367367
*
368368
* Invoke to set the required number of MSI-X interrupts.
369369
*/
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)
372372
{
373373
int ret;
374374

375375
if (!pci_epc_function_is_valid(epc, func_no, vfunc_no))
376376
return -EINVAL;
377377

378-
if (interrupts < 1 || interrupts > 2048)
378+
if (nr_irqs < 1 || nr_irqs > 2048)
379379
return -EINVAL;
380380

381381
if (!epc->ops->set_msix)
382382
return 0;
383383

384384
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);
387386
mutex_unlock(&epc->lock);
388387

389388
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 nr_irqs);
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);
@@ -288,8 +288,8 @@ void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
288288
phys_addr_t phys_addr);
289289
int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no, u8 nr_irqs);
290290
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);
293293
int pci_epc_get_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
294294
int pci_epc_map_msi_irq(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
295295
phys_addr_t phys_addr, u8 interrupt_num,

0 commit comments

Comments
 (0)