Skip to content

Commit 907912c

Browse files
Hans Zhangbjorn-helgaas
authored andcommitted
PCI: cadence: Use cdns_pcie_find_*capability() to avoid hardcoding offsets
The PCI capability/extended capability offsets are not guaranteed to be the same across all SoCs integrating the Cadence PCIe IP. Use the cdns_pcie_find_{ext}_capability() APIs to find the capabilities, which avoids hardcoding the offsets in the driver. Signed-off-by: Hans Zhang <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]> Acked-by: Manivannan Sadhasivam <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 18ac51a commit 907912c

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

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

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121

2222
static u8 cdns_pcie_get_fn_from_vfn(struct cdns_pcie *pcie, u8 fn, u8 vfn)
2323
{
24-
u32 cap = CDNS_PCIE_EP_FUNC_SRIOV_CAP_OFFSET;
2524
u32 first_vf_offset, stride;
25+
u16 cap;
2626

2727
if (vfn == 0)
2828
return fn;
2929

30+
cap = cdns_pcie_find_ext_capability(pcie, PCI_EXT_CAP_ID_SRIOV);
3031
first_vf_offset = cdns_pcie_ep_fn_readw(pcie, fn, cap + PCI_SRIOV_VF_OFFSET);
3132
stride = cdns_pcie_ep_fn_readw(pcie, fn, cap + PCI_SRIOV_VF_STRIDE);
3233
fn = fn + first_vf_offset + ((vfn - 1) * stride);
@@ -38,10 +39,11 @@ static int cdns_pcie_ep_write_header(struct pci_epc *epc, u8 fn, u8 vfn,
3839
struct pci_epf_header *hdr)
3940
{
4041
struct cdns_pcie_ep *ep = epc_get_drvdata(epc);
41-
u32 cap = CDNS_PCIE_EP_FUNC_SRIOV_CAP_OFFSET;
4242
struct cdns_pcie *pcie = &ep->pcie;
4343
u32 reg;
44+
u16 cap;
4445

46+
cap = cdns_pcie_find_ext_capability(pcie, PCI_EXT_CAP_ID_SRIOV);
4547
if (vfn > 1) {
4648
dev_err(&epc->dev, "Only Virtual Function #1 has deviceID\n");
4749
return -EINVAL;
@@ -227,9 +229,10 @@ static int cdns_pcie_ep_set_msi(struct pci_epc *epc, u8 fn, u8 vfn, u8 nr_irqs)
227229
struct cdns_pcie_ep *ep = epc_get_drvdata(epc);
228230
struct cdns_pcie *pcie = &ep->pcie;
229231
u8 mmc = order_base_2(nr_irqs);
230-
u32 cap = CDNS_PCIE_EP_FUNC_MSI_CAP_OFFSET;
231232
u16 flags;
233+
u8 cap;
232234

235+
cap = cdns_pcie_find_capability(pcie, PCI_CAP_ID_MSI);
233236
fn = cdns_pcie_get_fn_from_vfn(pcie, fn, vfn);
234237

235238
/*
@@ -249,9 +252,10 @@ static int cdns_pcie_ep_get_msi(struct pci_epc *epc, u8 fn, u8 vfn)
249252
{
250253
struct cdns_pcie_ep *ep = epc_get_drvdata(epc);
251254
struct cdns_pcie *pcie = &ep->pcie;
252-
u32 cap = CDNS_PCIE_EP_FUNC_MSI_CAP_OFFSET;
253255
u16 flags, mme;
256+
u8 cap;
254257

258+
cap = cdns_pcie_find_capability(pcie, PCI_CAP_ID_MSIX);
255259
fn = cdns_pcie_get_fn_from_vfn(pcie, fn, vfn);
256260

257261
/* Validate that the MSI feature is actually enabled. */
@@ -272,9 +276,10 @@ static int cdns_pcie_ep_get_msix(struct pci_epc *epc, u8 func_no, u8 vfunc_no)
272276
{
273277
struct cdns_pcie_ep *ep = epc_get_drvdata(epc);
274278
struct cdns_pcie *pcie = &ep->pcie;
275-
u32 cap = CDNS_PCIE_EP_FUNC_MSIX_CAP_OFFSET;
276279
u32 val, reg;
280+
u8 cap;
277281

282+
cap = cdns_pcie_find_capability(pcie, PCI_CAP_ID_MSIX);
278283
func_no = cdns_pcie_get_fn_from_vfn(pcie, func_no, vfunc_no);
279284

280285
reg = cap + PCI_MSIX_FLAGS;
@@ -292,9 +297,10 @@ static int cdns_pcie_ep_set_msix(struct pci_epc *epc, u8 fn, u8 vfn,
292297
{
293298
struct cdns_pcie_ep *ep = epc_get_drvdata(epc);
294299
struct cdns_pcie *pcie = &ep->pcie;
295-
u32 cap = CDNS_PCIE_EP_FUNC_MSIX_CAP_OFFSET;
296300
u32 val, reg;
301+
u8 cap;
297302

303+
cap = cdns_pcie_find_capability(pcie, PCI_CAP_ID_MSIX);
298304
fn = cdns_pcie_get_fn_from_vfn(pcie, fn, vfn);
299305

300306
reg = cap + PCI_MSIX_FLAGS;
@@ -380,11 +386,11 @@ static int cdns_pcie_ep_send_msi_irq(struct cdns_pcie_ep *ep, u8 fn, u8 vfn,
380386
u8 interrupt_num)
381387
{
382388
struct cdns_pcie *pcie = &ep->pcie;
383-
u32 cap = CDNS_PCIE_EP_FUNC_MSI_CAP_OFFSET;
384389
u16 flags, mme, data, data_mask;
385-
u8 msi_count;
386390
u64 pci_addr, pci_addr_mask = 0xff;
391+
u8 msi_count, cap;
387392

393+
cap = cdns_pcie_find_capability(pcie, PCI_CAP_ID_MSI);
388394
fn = cdns_pcie_get_fn_from_vfn(pcie, fn, vfn);
389395

390396
/* Check whether the MSI feature has been enabled by the PCI host. */
@@ -432,14 +438,14 @@ static int cdns_pcie_ep_map_msi_irq(struct pci_epc *epc, u8 fn, u8 vfn,
432438
u32 *msi_addr_offset)
433439
{
434440
struct cdns_pcie_ep *ep = epc_get_drvdata(epc);
435-
u32 cap = CDNS_PCIE_EP_FUNC_MSI_CAP_OFFSET;
436441
struct cdns_pcie *pcie = &ep->pcie;
437442
u64 pci_addr, pci_addr_mask = 0xff;
438443
u16 flags, mme, data, data_mask;
439-
u8 msi_count;
444+
u8 msi_count, cap;
440445
int ret;
441446
int i;
442447

448+
cap = cdns_pcie_find_capability(pcie, PCI_CAP_ID_MSI);
443449
fn = cdns_pcie_get_fn_from_vfn(pcie, fn, vfn);
444450

445451
/* Check whether the MSI feature has been enabled by the PCI host. */
@@ -482,16 +488,16 @@ static int cdns_pcie_ep_map_msi_irq(struct pci_epc *epc, u8 fn, u8 vfn,
482488
static int cdns_pcie_ep_send_msix_irq(struct cdns_pcie_ep *ep, u8 fn, u8 vfn,
483489
u16 interrupt_num)
484490
{
485-
u32 cap = CDNS_PCIE_EP_FUNC_MSIX_CAP_OFFSET;
486491
u32 tbl_offset, msg_data, reg;
487492
struct cdns_pcie *pcie = &ep->pcie;
488493
struct pci_epf_msix_tbl *msix_tbl;
489494
struct cdns_pcie_epf *epf;
490495
u64 pci_addr_mask = 0xff;
491496
u64 msg_addr;
497+
u8 bir, cap;
492498
u16 flags;
493-
u8 bir;
494499

500+
cap = cdns_pcie_find_capability(pcie, PCI_CAP_ID_MSIX);
495501
epf = &ep->epf[fn];
496502
if (vfn > 0)
497503
epf = &epf->epf[vfn - 1];
@@ -565,7 +571,9 @@ static int cdns_pcie_ep_start(struct pci_epc *epc)
565571
int max_epfs = sizeof(epc->function_num_map) * 8;
566572
int ret, epf, last_fn;
567573
u32 reg, value;
574+
u8 cap;
568575

576+
cap = cdns_pcie_find_capability(pcie, PCI_CAP_ID_EXP);
569577
/*
570578
* BIT(0) is hardwired to 1, hence function 0 is always enabled
571579
* and can't be disabled anyway.
@@ -589,12 +597,10 @@ static int cdns_pcie_ep_start(struct pci_epc *epc)
589597
continue;
590598

591599
value = cdns_pcie_ep_fn_readl(pcie, epf,
592-
CDNS_PCIE_EP_FUNC_DEV_CAP_OFFSET +
593-
PCI_EXP_DEVCAP);
600+
cap + PCI_EXP_DEVCAP);
594601
value &= ~PCI_EXP_DEVCAP_FLR;
595602
cdns_pcie_ep_fn_writel(pcie, epf,
596-
CDNS_PCIE_EP_FUNC_DEV_CAP_OFFSET +
597-
PCI_EXP_DEVCAP, value);
603+
cap + PCI_EXP_DEVCAP, value);
598604
}
599605
}
600606

drivers/pci/controller/cadence/pcie-cadence.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,6 @@
125125
*/
126126
#define CDNS_PCIE_EP_FUNC_BASE(fn) (((fn) << 12) & GENMASK(19, 12))
127127

128-
#define CDNS_PCIE_EP_FUNC_MSI_CAP_OFFSET 0x90
129-
#define CDNS_PCIE_EP_FUNC_MSIX_CAP_OFFSET 0xb0
130-
#define CDNS_PCIE_EP_FUNC_DEV_CAP_OFFSET 0xc0
131-
#define CDNS_PCIE_EP_FUNC_SRIOV_CAP_OFFSET 0x200
132-
133128
/*
134129
* Endpoint PF Registers
135130
*/

0 commit comments

Comments
 (0)