Skip to content

Commit 3532a74

Browse files
Gavin Shanozbenh
authored andcommitted
powerpc/powernv: Use pci_dn, not device_node, in PCI config accessor
The PCI config accessors previously relied on device_node. Unfortunately, VFs don't have a corresponding device_node, so change the accessors to use pci_dn instead. [bhelgaas: changelog] Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent cca87d3 commit 3532a74

File tree

3 files changed

+40
-47
lines changed

3 files changed

+40
-47
lines changed

arch/powerpc/platforms/powernv/eeh-powernv.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,21 +1038,31 @@ static inline bool pnv_eeh_cfg_blocked(struct device_node *dn)
10381038
static int pnv_eeh_read_config(struct device_node *dn,
10391039
int where, int size, u32 *val)
10401040
{
1041+
struct pci_dn *pdn = PCI_DN(dn);
1042+
1043+
if (!pdn)
1044+
return PCIBIOS_DEVICE_NOT_FOUND;
1045+
10411046
if (pnv_eeh_cfg_blocked(dn)) {
10421047
*val = 0xFFFFFFFF;
10431048
return PCIBIOS_SET_FAILED;
10441049
}
10451050

1046-
return pnv_pci_cfg_read(dn, where, size, val);
1051+
return pnv_pci_cfg_read(pdn, where, size, val);
10471052
}
10481053

10491054
static int pnv_eeh_write_config(struct device_node *dn,
10501055
int where, int size, u32 val)
10511056
{
1057+
struct pci_dn *pdn = PCI_DN(dn);
1058+
1059+
if (!pdn)
1060+
return PCIBIOS_DEVICE_NOT_FOUND;
1061+
10521062
if (pnv_eeh_cfg_blocked(dn))
10531063
return PCIBIOS_SET_FAILED;
10541064

1055-
return pnv_pci_cfg_write(dn, where, size, val);
1065+
return pnv_pci_cfg_write(pdn, where, size, val);
10561066
}
10571067

10581068
static void pnv_eeh_dump_hub_diag_common(struct OpalIoP7IOCErrorData *data)

arch/powerpc/platforms/powernv/pci.c

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,9 @@ static void pnv_pci_handle_eeh_config(struct pnv_phb *phb, u32 pe_no)
366366
spin_unlock_irqrestore(&phb->lock, flags);
367367
}
368368

369-
static void pnv_pci_config_check_eeh(struct pnv_phb *phb,
370-
struct device_node *dn)
369+
static void pnv_pci_config_check_eeh(struct pci_dn *pdn)
371370
{
371+
struct pnv_phb *phb = pdn->phb->private_data;
372372
u8 fstate;
373373
__be16 pcierr;
374374
int pe_no;
@@ -379,7 +379,7 @@ static void pnv_pci_config_check_eeh(struct pnv_phb *phb,
379379
* setup that yet. So all ER errors should be mapped to
380380
* reserved PE.
381381
*/
382-
pe_no = PCI_DN(dn)->pe_number;
382+
pe_no = pdn->pe_number;
383383
if (pe_no == IODA_INVALID_PE) {
384384
if (phb->type == PNV_PHB_P5IOC2)
385385
pe_no = 0;
@@ -407,8 +407,7 @@ static void pnv_pci_config_check_eeh(struct pnv_phb *phb,
407407
}
408408

409409
cfg_dbg(" -> EEH check, bdfn=%04x PE#%d fstate=%x\n",
410-
(PCI_DN(dn)->busno << 8) | (PCI_DN(dn)->devfn),
411-
pe_no, fstate);
410+
(pdn->busno << 8) | (pdn->devfn), pe_no, fstate);
412411

413412
/* Clear the frozen state if applicable */
414413
if (fstate == OPAL_EEH_STOPPED_MMIO_FREEZE ||
@@ -425,10 +424,9 @@ static void pnv_pci_config_check_eeh(struct pnv_phb *phb,
425424
}
426425
}
427426

428-
int pnv_pci_cfg_read(struct device_node *dn,
427+
int pnv_pci_cfg_read(struct pci_dn *pdn,
429428
int where, int size, u32 *val)
430429
{
431-
struct pci_dn *pdn = PCI_DN(dn);
432430
struct pnv_phb *phb = pdn->phb->private_data;
433431
u32 bdfn = (pdn->busno << 8) | pdn->devfn;
434432
s64 rc;
@@ -462,10 +460,9 @@ int pnv_pci_cfg_read(struct device_node *dn,
462460
return PCIBIOS_SUCCESSFUL;
463461
}
464462

465-
int pnv_pci_cfg_write(struct device_node *dn,
463+
int pnv_pci_cfg_write(struct pci_dn *pdn,
466464
int where, int size, u32 val)
467465
{
468-
struct pci_dn *pdn = PCI_DN(dn);
469466
struct pnv_phb *phb = pdn->phb->private_data;
470467
u32 bdfn = (pdn->busno << 8) | pdn->devfn;
471468

@@ -489,18 +486,17 @@ int pnv_pci_cfg_write(struct device_node *dn,
489486
}
490487

491488
#if CONFIG_EEH
492-
static bool pnv_pci_cfg_check(struct pci_controller *hose,
493-
struct device_node *dn)
489+
static bool pnv_pci_cfg_check(struct pci_dn *pdn)
494490
{
495491
struct eeh_dev *edev = NULL;
496-
struct pnv_phb *phb = hose->private_data;
492+
struct pnv_phb *phb = pdn->phb->private_data;
497493

498494
/* EEH not enabled ? */
499495
if (!(phb->flags & PNV_PHB_FLAG_EEH))
500496
return true;
501497

502498
/* PE reset or device removed ? */
503-
edev = of_node_to_eeh_dev(dn);
499+
edev = pdn->edev;
504500
if (edev) {
505501
if (edev->pe &&
506502
(edev->pe->state & EEH_PE_CFG_BLOCKED))
@@ -513,8 +509,7 @@ static bool pnv_pci_cfg_check(struct pci_controller *hose,
513509
return true;
514510
}
515511
#else
516-
static inline pnv_pci_cfg_check(struct pci_controller *hose,
517-
struct device_node *dn)
512+
static inline pnv_pci_cfg_check(struct pci_dn *pdn)
518513
{
519514
return true;
520515
}
@@ -524,32 +519,26 @@ static int pnv_pci_read_config(struct pci_bus *bus,
524519
unsigned int devfn,
525520
int where, int size, u32 *val)
526521
{
527-
struct device_node *dn, *busdn = pci_bus_to_OF_node(bus);
528522
struct pci_dn *pdn;
529523
struct pnv_phb *phb;
530-
bool found = false;
531524
int ret;
532525

533526
*val = 0xFFFFFFFF;
534-
for (dn = busdn->child; dn; dn = dn->sibling) {
535-
pdn = PCI_DN(dn);
536-
if (pdn && pdn->devfn == devfn) {
537-
phb = pdn->phb->private_data;
538-
found = true;
539-
break;
540-
}
541-
}
527+
pdn = pci_get_pdn_by_devfn(bus, devfn);
528+
if (!pdn)
529+
return PCIBIOS_DEVICE_NOT_FOUND;
542530

543-
if (!found || !pnv_pci_cfg_check(pdn->phb, dn))
531+
if (!pnv_pci_cfg_check(pdn))
544532
return PCIBIOS_DEVICE_NOT_FOUND;
545533

546-
ret = pnv_pci_cfg_read(dn, where, size, val);
547-
if (phb->flags & PNV_PHB_FLAG_EEH) {
534+
ret = pnv_pci_cfg_read(pdn, where, size, val);
535+
phb = pdn->phb->private_data;
536+
if (phb->flags & PNV_PHB_FLAG_EEH && pdn->edev) {
548537
if (*val == EEH_IO_ERROR_VALUE(size) &&
549-
eeh_dev_check_failure(of_node_to_eeh_dev(dn)))
538+
eeh_dev_check_failure(pdn->edev))
550539
return PCIBIOS_DEVICE_NOT_FOUND;
551540
} else {
552-
pnv_pci_config_check_eeh(phb, dn);
541+
pnv_pci_config_check_eeh(pdn);
553542
}
554543

555544
return ret;
@@ -559,27 +548,21 @@ static int pnv_pci_write_config(struct pci_bus *bus,
559548
unsigned int devfn,
560549
int where, int size, u32 val)
561550
{
562-
struct device_node *dn, *busdn = pci_bus_to_OF_node(bus);
563551
struct pci_dn *pdn;
564552
struct pnv_phb *phb;
565-
bool found = false;
566553
int ret;
567554

568-
for (dn = busdn->child; dn; dn = dn->sibling) {
569-
pdn = PCI_DN(dn);
570-
if (pdn && pdn->devfn == devfn) {
571-
phb = pdn->phb->private_data;
572-
found = true;
573-
break;
574-
}
575-
}
555+
pdn = pci_get_pdn_by_devfn(bus, devfn);
556+
if (!pdn)
557+
return PCIBIOS_DEVICE_NOT_FOUND;
576558

577-
if (!found || !pnv_pci_cfg_check(pdn->phb, dn))
559+
if (!pnv_pci_cfg_check(pdn))
578560
return PCIBIOS_DEVICE_NOT_FOUND;
579561

580-
ret = pnv_pci_cfg_write(dn, where, size, val);
562+
ret = pnv_pci_cfg_write(pdn, where, size, val);
563+
phb = pdn->phb->private_data;
581564
if (!(phb->flags & PNV_PHB_FLAG_EEH))
582-
pnv_pci_config_check_eeh(phb, dn);
565+
pnv_pci_config_check_eeh(pdn);
583566

584567
return ret;
585568
}

arch/powerpc/platforms/powernv/pci.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ extern struct pci_ops pnv_pci_ops;
196196

197197
void pnv_pci_dump_phb_diag_data(struct pci_controller *hose,
198198
unsigned char *log_buff);
199-
int pnv_pci_cfg_read(struct device_node *dn,
199+
int pnv_pci_cfg_read(struct pci_dn *pdn,
200200
int where, int size, u32 *val);
201-
int pnv_pci_cfg_write(struct device_node *dn,
201+
int pnv_pci_cfg_write(struct pci_dn *pdn,
202202
int where, int size, u32 val);
203203
extern void pnv_pci_setup_iommu_table(struct iommu_table *tbl,
204204
void *tce_mem, u64 tce_size,

0 commit comments

Comments
 (0)