Skip to content

Commit f62da6e

Browse files
floatiousbjorn-helgaas
authored andcommitted
PCI: endpoint: Align pci_epc_set_msi(), pci_epc_ops::set_msi() nr_irqs encoding
The kdoc for pci_epc_set_msi() says: "Invoke to set the required number of MSI interrupts." The kdoc for the callback pci_epc_ops::set_msi() says: "ops to set the requested number of MSI interrupts in the MSI capability register" pci_epc_ops::set_msi() does however expect the parameter 'interrupts' to be in the encoding as defined by the Multiple Message Capable (MMC) field of the MSI capability structure. Nowhere in the kdoc does it say that the number of interrupts should be in MMC encoding. It is very confusing that the API pci_epc_set_msi() and the callback function pci_epc_ops::set_msi() 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 0917ed8 commit f62da6e

File tree

6 files changed

+17
-18
lines changed

6 files changed

+17
-18
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,11 @@ static void cdns_pcie_ep_unmap_addr(struct pci_epc *epc, u8 fn, u8 vfn,
220220
clear_bit(r, &ep->ob_region_map);
221221
}
222222

223-
static int cdns_pcie_ep_set_msi(struct pci_epc *epc, u8 fn, u8 vfn, u8 mmc)
223+
static int cdns_pcie_ep_set_msi(struct pci_epc *epc, u8 fn, u8 vfn, u8 nr_irqs)
224224
{
225225
struct cdns_pcie_ep *ep = epc_get_drvdata(epc);
226226
struct cdns_pcie *pcie = &ep->pcie;
227+
u8 mmc = order_base_2(nr_irqs);
227228
u32 cap = CDNS_PCIE_EP_FUNC_MSI_CAP_OFFSET;
228229
u16 flags;
229230

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,12 @@ static int dw_pcie_ep_get_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no)
536536
}
537537

538538
static int dw_pcie_ep_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
539-
u8 interrupts)
539+
u8 nr_irqs)
540540
{
541541
struct dw_pcie_ep *ep = epc_get_drvdata(epc);
542542
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
543543
struct dw_pcie_ep_func *ep_func;
544+
u8 mmc = order_base_2(nr_irqs);
544545
u32 val, reg;
545546

546547
ep_func = dw_pcie_ep_get_func_from_ep(ep, func_no);
@@ -550,7 +551,7 @@ static int dw_pcie_ep_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
550551
reg = ep_func->msi_cap + PCI_MSI_FLAGS;
551552
val = dw_pcie_ep_readw_dbi(ep, func_no, reg);
552553
val &= ~PCI_MSI_FLAGS_QMASK;
553-
val |= FIELD_PREP(PCI_MSI_FLAGS_QMASK, interrupts);
554+
val |= FIELD_PREP(PCI_MSI_FLAGS_QMASK, mmc);
554555
dw_pcie_dbi_ro_wr_en(pci);
555556
dw_pcie_ep_writew_dbi(ep, func_no, reg, val);
556557
dw_pcie_dbi_ro_wr_dis(pci);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,15 @@ static void rcar_pcie_ep_clear_bar(struct pci_epc *epc, u8 fn, u8 vfn,
256256
clear_bit(atu_index + 1, ep->ib_window_map);
257257
}
258258

259-
static int rcar_pcie_ep_set_msi(struct pci_epc *epc, u8 fn, u8 vfn,
260-
u8 interrupts)
259+
static int rcar_pcie_ep_set_msi(struct pci_epc *epc, u8 fn, u8 vfn, u8 nr_irqs)
261260
{
262261
struct rcar_pcie_endpoint *ep = epc_get_drvdata(epc);
263262
struct rcar_pcie *pcie = &ep->pcie;
263+
u8 mmc = order_base_2(nr_irqs);
264264
u32 flags;
265265

266266
flags = rcar_pci_read_reg(pcie, MSICAP(fn));
267-
flags |= interrupts << MSICAP0_MMESCAP_OFFSET;
267+
flags |= mmc << MSICAP0_MMESCAP_OFFSET;
268268
rcar_pci_write_reg(pcie, flags, MSICAP(fn));
269269

270270
return 0;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,19 @@ static void rockchip_pcie_ep_unmap_addr(struct pci_epc *epc, u8 fn, u8 vfn,
308308
}
309309

310310
static int rockchip_pcie_ep_set_msi(struct pci_epc *epc, u8 fn, u8 vfn,
311-
u8 multi_msg_cap)
311+
u8 nr_irqs)
312312
{
313313
struct rockchip_pcie_ep *ep = epc_get_drvdata(epc);
314314
struct rockchip_pcie *rockchip = &ep->rockchip;
315+
u8 mmc = order_base_2(nr_irqs);
315316
u32 flags;
316317

317318
flags = rockchip_pcie_read(rockchip,
318319
ROCKCHIP_PCIE_EP_FUNC_BASE(fn) +
319320
ROCKCHIP_PCIE_EP_MSI_CTRL_REG);
320321
flags &= ~ROCKCHIP_PCIE_EP_MSI_CTRL_MMC_MASK;
321322
flags |=
322-
(multi_msg_cap << ROCKCHIP_PCIE_EP_MSI_CTRL_MMC_OFFSET) |
323+
(mmc << ROCKCHIP_PCIE_EP_MSI_CTRL_MMC_OFFSET) |
323324
(PCI_MSI_FLAGS_64BIT << ROCKCHIP_PCIE_EP_MSI_FLAGS_OFFSET);
324325
flags &= ~ROCKCHIP_PCIE_EP_MSI_CTRL_MASK_MSI_CAP;
325326
rockchip_pcie_write(rockchip, flags,

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,28 +302,25 @@ EXPORT_SYMBOL_GPL(pci_epc_get_msi);
302302
* @epc: the EPC device on which MSI has to be configured
303303
* @func_no: the physical endpoint function number in the EPC device
304304
* @vfunc_no: the virtual endpoint function number in the physical function
305-
* @interrupts: number of MSI interrupts required by the EPF
305+
* @nr_irqs: number of MSI interrupts required by the EPF
306306
*
307307
* Invoke to set the required number of MSI interrupts.
308308
*/
309-
int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no, u8 interrupts)
309+
int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no, u8 nr_irqs)
310310
{
311311
int ret;
312-
u8 encode_int;
313312

314313
if (!pci_epc_function_is_valid(epc, func_no, vfunc_no))
315314
return -EINVAL;
316315

317-
if (interrupts < 1 || interrupts > 32)
316+
if (nr_irqs < 1 || nr_irqs > 32)
318317
return -EINVAL;
319318

320319
if (!epc->ops->set_msi)
321320
return 0;
322321

323-
encode_int = order_base_2(interrupts);
324-
325322
mutex_lock(&epc->lock);
326-
ret = epc->ops->set_msi(epc, func_no, vfunc_no, encode_int);
323+
ret = epc->ops->set_msi(epc, func_no, vfunc_no, nr_irqs);
327324
mutex_unlock(&epc->lock);
328325

329326
return ret;

include/linux/pci-epc.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct pci_epc_ops {
100100
void (*unmap_addr)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
101101
phys_addr_t addr);
102102
int (*set_msi)(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
103-
u8 interrupts);
103+
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,
106106
u16 interrupts, enum pci_barno, u32 offset);
@@ -286,8 +286,7 @@ int pci_epc_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
286286
u64 pci_addr, size_t size);
287287
void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
288288
phys_addr_t phys_addr);
289-
int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
290-
u8 interrupts);
289+
int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no, u8 nr_irqs);
291290
int pci_epc_get_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no);
292291
int pci_epc_set_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
293292
u16 interrupts, enum pci_barno, u32 offset);

0 commit comments

Comments
 (0)