LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] powerpc/powernv: Cleanup unused MCE definitions/declarations.
From: Mahesh J Salgaonkar @ 2014-11-24 16:29 UTC (permalink / raw)
  To: Michael Ellerman, linuxppc-dev, Benjamin Herrenschmidt

From: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>

Cleanup OpalMCE_* definitions/declarations and other related code which
is not used anymore.

Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
---
 arch/powerpc/include/asm/opal.h       |  104 ---------------------------------
 arch/powerpc/include/asm/paca.h       |    7 --
 arch/powerpc/kernel/asm-offsets.c     |    7 --
 arch/powerpc/kernel/exceptions-64s.S  |   17 -----
 arch/powerpc/platforms/powernv/opal.c |    1 
 5 files changed, 136 deletions(-)

diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 9124b0e..1c0814f0 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -284,62 +284,6 @@ enum OpalMessageType {
 	OPAL_MSG_TYPE_MAX,
 };
 
-/* Machine check related definitions */
-enum OpalMCE_Version {
-	OpalMCE_V1 = 1,
-};
-
-enum OpalMCE_Severity {
-	OpalMCE_SEV_NO_ERROR = 0,
-	OpalMCE_SEV_WARNING = 1,
-	OpalMCE_SEV_ERROR_SYNC = 2,
-	OpalMCE_SEV_FATAL = 3,
-};
-
-enum OpalMCE_Disposition {
-	OpalMCE_DISPOSITION_RECOVERED = 0,
-	OpalMCE_DISPOSITION_NOT_RECOVERED = 1,
-};
-
-enum OpalMCE_Initiator {
-	OpalMCE_INITIATOR_UNKNOWN = 0,
-	OpalMCE_INITIATOR_CPU = 1,
-};
-
-enum OpalMCE_ErrorType {
-	OpalMCE_ERROR_TYPE_UNKNOWN = 0,
-	OpalMCE_ERROR_TYPE_UE = 1,
-	OpalMCE_ERROR_TYPE_SLB = 2,
-	OpalMCE_ERROR_TYPE_ERAT = 3,
-	OpalMCE_ERROR_TYPE_TLB = 4,
-};
-
-enum OpalMCE_UeErrorType {
-	OpalMCE_UE_ERROR_INDETERMINATE = 0,
-	OpalMCE_UE_ERROR_IFETCH = 1,
-	OpalMCE_UE_ERROR_PAGE_TABLE_WALK_IFETCH = 2,
-	OpalMCE_UE_ERROR_LOAD_STORE = 3,
-	OpalMCE_UE_ERROR_PAGE_TABLE_WALK_LOAD_STORE = 4,
-};
-
-enum OpalMCE_SlbErrorType {
-	OpalMCE_SLB_ERROR_INDETERMINATE = 0,
-	OpalMCE_SLB_ERROR_PARITY = 1,
-	OpalMCE_SLB_ERROR_MULTIHIT = 2,
-};
-
-enum OpalMCE_EratErrorType {
-	OpalMCE_ERAT_ERROR_INDETERMINATE = 0,
-	OpalMCE_ERAT_ERROR_PARITY = 1,
-	OpalMCE_ERAT_ERROR_MULTIHIT = 2,
-};
-
-enum OpalMCE_TlbErrorType {
-	OpalMCE_TLB_ERROR_INDETERMINATE = 0,
-	OpalMCE_TLB_ERROR_PARITY = 1,
-	OpalMCE_TLB_ERROR_MULTIHIT = 2,
-};
-
 enum OpalThreadStatus {
 	OPAL_THREAD_INACTIVE = 0x0,
 	OPAL_THREAD_STARTED = 0x1,
@@ -452,54 +396,6 @@ struct opal_msg {
 	__be64 params[8];
 };
 
-struct opal_machine_check_event {
-	enum OpalMCE_Version	version:8;	/* 0x00 */
-	uint8_t			in_use;		/* 0x01 */
-	enum OpalMCE_Severity	severity:8;	/* 0x02 */
-	enum OpalMCE_Initiator	initiator:8;	/* 0x03 */
-	enum OpalMCE_ErrorType	error_type:8;	/* 0x04 */
-	enum OpalMCE_Disposition disposition:8; /* 0x05 */
-	uint8_t			reserved_1[2];	/* 0x06 */
-	uint64_t		gpr3;		/* 0x08 */
-	uint64_t		srr0;		/* 0x10 */
-	uint64_t		srr1;		/* 0x18 */
-	union {					/* 0x20 */
-		struct {
-			enum OpalMCE_UeErrorType ue_error_type:8;
-			uint8_t		effective_address_provided;
-			uint8_t		physical_address_provided;
-			uint8_t		reserved_1[5];
-			uint64_t	effective_address;
-			uint64_t	physical_address;
-			uint8_t		reserved_2[8];
-		} ue_error;
-
-		struct {
-			enum OpalMCE_SlbErrorType slb_error_type:8;
-			uint8_t		effective_address_provided;
-			uint8_t		reserved_1[6];
-			uint64_t	effective_address;
-			uint8_t		reserved_2[16];
-		} slb_error;
-
-		struct {
-			enum OpalMCE_EratErrorType erat_error_type:8;
-			uint8_t		effective_address_provided;
-			uint8_t		reserved_1[6];
-			uint64_t	effective_address;
-			uint8_t		reserved_2[16];
-		} erat_error;
-
-		struct {
-			enum OpalMCE_TlbErrorType tlb_error_type:8;
-			uint8_t		effective_address_provided;
-			uint8_t		reserved_1[6];
-			uint64_t	effective_address;
-			uint8_t		reserved_2[16];
-		} tlb_error;
-	} u;
-};
-
 /* FSP memory errors handling */
 enum OpalMemErr_Version {
 	OpalMemErr_V1 = 1,
diff --git a/arch/powerpc/include/asm/paca.h b/arch/powerpc/include/asm/paca.h
index a5139ea..24a386c 100644
--- a/arch/powerpc/include/asm/paca.h
+++ b/arch/powerpc/include/asm/paca.h
@@ -42,7 +42,6 @@ extern unsigned int debug_smp_processor_id(void); /* from linux/smp.h */
 #define get_slb_shadow()	(get_paca()->slb_shadow_ptr)
 
 struct task_struct;
-struct opal_machine_check_event;
 
 /*
  * Defines the layout of the paca.
@@ -153,12 +152,6 @@ struct paca_struct {
 	u64 tm_scratch;                 /* TM scratch area for reclaim */
 #endif
 
-#ifdef CONFIG_PPC_POWERNV
-	/* Pointer to OPAL machine check event structure set by the
-	 * early exception handler for use by high level C handler
-	 */
-	struct opal_machine_check_event *opal_mc_evt;
-#endif
 #ifdef CONFIG_PPC_BOOK3S_64
 	/* Exclusive emergency stack pointer for machine check exception. */
 	void *mc_emergency_sp;
diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
index 9d7dede..c161ef3 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -726,12 +726,5 @@ int main(void)
 					arch.timing_last_enter.tv32.tbl));
 #endif
 
-#ifdef CONFIG_PPC_POWERNV
-	DEFINE(OPAL_MC_GPR3, offsetof(struct opal_machine_check_event, gpr3));
-	DEFINE(OPAL_MC_SRR0, offsetof(struct opal_machine_check_event, srr0));
-	DEFINE(OPAL_MC_SRR1, offsetof(struct opal_machine_check_event, srr1));
-	DEFINE(PACA_OPAL_MC_EVT, offsetof(struct paca_struct, opal_mc_evt));
-#endif
-
 	return 0;
 }
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 72e783e..b7a30bd 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -1301,23 +1301,6 @@ hmi_exception_after_realmode:
 	EXCEPTION_PROLOG_0(PACA_EXGEN)
 	b	hmi_exception_hv
 
-#ifdef CONFIG_PPC_POWERNV
-_GLOBAL(opal_mc_secondary_handler)
-	HMT_MEDIUM_PPR_DISCARD
-	SET_SCRATCH0(r13)
-	GET_PACA(r13)
-	clrldi	r3,r3,2
-	tovirt(r3,r3)
-	std	r3,PACA_OPAL_MC_EVT(r13)
-	ld	r13,OPAL_MC_SRR0(r3)
-	mtspr	SPRN_SRR0,r13
-	ld	r13,OPAL_MC_SRR1(r3)
-	mtspr	SPRN_SRR1,r13
-	ld	r3,OPAL_MC_GPR3(r3)
-	GET_SCRATCH0(r13)
-	b	machine_check_pSeries
-#endif /* CONFIG_PPC_POWERNV */
-
 
 #define MACHINE_CHECK_HANDLER_WINDUP			\
 	/* Clear MSR_RI before setting SRR0 and SRR1. */\
diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c
index d019b08..544b9b7 100644
--- a/arch/powerpc/platforms/powernv/opal.c
+++ b/arch/powerpc/platforms/powernv/opal.c
@@ -50,7 +50,6 @@ static int mc_recoverable_range_len;
 
 struct device_node *opal_node;
 static DEFINE_SPINLOCK(opal_write_lock);
-extern u64 opal_mc_secondary_handler[];
 static unsigned int *opal_irqs;
 static unsigned int opal_irq_count;
 static ATOMIC_NOTIFIER_HEAD(opal_notifier_head);

^ permalink raw reply related

* Re: [PATCH v2 6/6] pseries: Implement memory hotplug remove in the kernel
From: Cyril Bur @ 2014-11-24 22:05 UTC (permalink / raw)
  To: Nathan Fontenot; +Cc: linuxppc-dev@lists.ozlabs.org
In-Reply-To: <547348D4.7050506@linux.vnet.ibm.com>

On Mon, 2014-11-24 at 09:03 -0600, Nathan Fontenot wrote:
> 
> On 11/21/2014 01:49 AM, Cyril Bur wrote:
> > 
> > On Mon, 2014-11-17 at 15:56 -0600, Nathan Fontenot wrote:
> >> Move handling of memory hotplug remove on pseries completely into the kernel.
> >>
> >> The current memory hotplug remove path involves the drmgr command doing part
> >> of this work in userspace and requesting the kernel to do additional pieces.
> >> This patch allows us to handle the act completely in the kernel via rtas
> >> hotplug events. This allows us to perform the operation faster and provide
> >> a common memory hotplug remove path for PowerVM and PowerKVM systems.
> >>
> >> Signed-off-by: Nathan Fontenot <nfont@linux.vnet.ibm.com>
> >> ---
> >>  arch/powerpc/platforms/pseries/hotplug-memory.c |  206 ++++++++++++++++++++++-
> >>  1 file changed, 201 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
> >> index b57d42b..c8189e8 100644
> >> --- a/arch/powerpc/platforms/pseries/hotplug-memory.c
> >> +++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
> >> @@ -173,6 +173,179 @@ static int pseries_remove_mem_node(struct device_node *np)
> >>  	pseries_remove_memblock(base, lmb_size);
> >>  	return 0;
> >>  }
> >> +
> >> +static int lmb_is_removable(struct of_drconf_cell *lmb)
> >> +{
> >> +	int i, scns_per_block;
> >> +	int rc = 1;
> >> +	unsigned long pfn, block_sz;
> >> +	u64 phys_addr;
> >> +
> >> +	if (!(be32_to_cpu(lmb->flags) & DRCONF_MEM_ASSIGNED))
> >> +		return -1;
> > This makes me kind of nervous. You're using the return value of
> > lmb_is_removable as a boolean but it returns three possible values -1,0
> > and 1. Functionally it looks correct to me so its not a massive issue
> 
> Oh yuck. this should be a boolean return. I'll fix that.
> 
> >> +
> >> +	phys_addr = be64_to_cpu(lmb->base_addr);
> >> +	block_sz = memory_block_size_bytes();
> >> +	scns_per_block = block_sz / MIN_MEMORY_BLOCK_SIZE;
> >> +
> >> +	for (i = 0; i < scns_per_block; i++) {
> >> +		pfn = PFN_DOWN(phys_addr);
> >> +		if (!pfn_present(pfn))
> >> +			continue;
> >> +
> >> +		rc &= is_mem_section_removable(pfn, PAGES_PER_SECTION);
> >> +		phys_addr += MIN_MEMORY_BLOCK_SIZE;
> >> +	}
> >> +
> >> +	return rc;
> >> +}
> >> +
> >> +static int dlpar_add_lmb(struct of_drconf_cell *);
> >> +
> >> +static int dlpar_remove_lmb(struct of_drconf_cell *lmb)
> >> +{
> >> +	struct memory_block *mem_block;
> >> +	unsigned long block_sz;
> >> +	u64 phys_addr;
> >> +	uint32_t drc_index;
> >> +	int nid, rc;
> >> +
> >> +	if (!lmb_is_removable(lmb))
> >> +		return -EINVAL;
> >> +
> >> +	phys_addr = be64_to_cpu(lmb->base_addr);
> >> +	drc_index = be32_to_cpu(lmb->drc_index);
> >> +
> >> +	mem_block = lmb_to_memblock(lmb);
> >> +	if (!mem_block)
> >> +		return -EINVAL;
> >> +
> >> +	rc = device_offline(&mem_block->dev);
> >> +	put_device(&mem_block->dev);
> >> +	if (rc)
> >> +		return rc;
> >> +
> >> +	block_sz = pseries_memory_block_size();
> >> +	nid = memory_add_physaddr_to_nid(phys_addr);
> >> +
> >> +	remove_memory(nid, phys_addr, block_sz);
> >> +
> >> +	/* Update memory regions for memory remove */
> >> +	memblock_remove(phys_addr, block_sz);
> >> +
> >> +	dlpar_release_drc(drc_index);
> >> +
> >> +	lmb->flags &= cpu_to_be32(~DRCONF_MEM_ASSIGNED);
> >> +	pr_info("Memory at %llx (drc index %x) has been hot-removed\n",
> >> +		be64_to_cpu(lmb->base_addr), drc_index);
> > dlpar_add_lmb doesn't print anything but dlpar_remove_lmb does? Related
> > to my comment about printing a 'hot-add' messages prematurely, perhaps
> > move this to the callers
> 
> Yes, I'll update the remove mem messages also.
> 
> >> +
> >> +	return 0;
> >> +}
> >> +
> >> +static int dlpar_memory_remove_by_count(struct pseries_hp_errorlog *hp_elog,
> >> +					struct property *prop)
> >> +{
> >> +	struct of_drconf_cell *lmbs;
> >> +	int lmbs_to_remove, lmbs_removed = 0;
> >> +	int lmbs_available = 0;
> >> +	uint32_t num_lmbs;
> >> +	__be32 *p;
> >> +	int i, rc;
> >> +
> >> +	lmbs_to_remove = be32_to_cpu(hp_elog->_drc_u.drc_count);
> > Didn't you already do the endian conversion back in
> > handle_dlpar_errorlog?
> >> +	pr_info("Attempting to hot-remove %d LMB(s)\n", lmbs_to_remove);
> >> +
> >> +	if (lmbs_to_remove == 0)
> >> +		return -EINVAL;
> >> +
> >> +	p = prop->value;
> >> +	num_lmbs = be32_to_cpu(*p++);
> >> +	lmbs = (struct of_drconf_cell *)p;
> >> +
> >> +	/* Validate that there are enough LMBs to satisfy the request */
> >> +	for (i = 0; i < num_lmbs; i++) {
> >> +		if (be32_to_cpu(lmbs[i].flags) & DRCONF_MEM_ASSIGNED)
> >> +			lmbs_available++;
> >> +	}
> >> +
> >> +	if (lmbs_available < lmbs_to_remove)
> >> +		return -EINVAL;
> >> +
> >> +	for (i = 0; i < num_lmbs; i++) {
> >> +		if (lmbs_to_remove == lmbs_removed)
> >> +			break;
> >> +
> >> +		rc = dlpar_remove_lmb(&lmbs[i]);
> >> +		if (rc)
> >> +			continue;
> >> +
> >> +		lmbs_removed++;
> >> +
> >> +		/* Mark this lmb so we can add it later if all of the
> >> +		 * requested LMBs cannot be removed.
> >> +		 */
> >> +		lmbs[i].reserved = 1;
> >> +	}
> >> +
> >> +	if (lmbs_removed != lmbs_to_remove) {
> >> +		pr_err("Memory hot-remove failed, adding LMB's back\n");
> >> +
> >> +		for (i = 0; i < num_lmbs; i++) {
> >> +			if (!lmbs[i].reserved)
> >> +				continue;
> >> +
> >> +			rc = dlpar_add_lmb(&lmbs[i]);
> >> +			if (rc)
> > If this happens you this will leave an LMB removed but an error code
> > from this function will cause dlpar_memory to discard the dn prop that
> > it passed in. If you couldn't roll back completely the caller should
> > still update the dn property with the ones that it has left
> > removed/failed to re-add. Perhaps this function needs a mechanism to
> > report success/failure (as it currently does) and a mechanism to say
> > whether or not the dn property is dirty or not.
> 
> Good catch. The device tree should be updated to denote lmb's that were
> added but we failed to remove because of some error.
> 
> >> +				pr_err("Failed to add LMB back, drc index %x\n",
> >> +				       be32_to_cpu(lmbs[i].drc_index));
> >> +
> > On a clean (everything rolled back successfully) failure, I don't think
> > you _need_ to bother although this is nice cleanup, you didn't do it
> > dlpar_memory_add_by_count - I'm in favour of being clean especially
> > since on an 'unclean' failure you should clear that flag - if you're
> > going to still update the device tree.
> 
> I'll re-visit the cleanup code to make sure the device tree property is left
> in the correct state on a failure during roll-back.
> 
> >> +			lmbs[i].reserved = 0;
> >> +		}
> >> +		rc = -EINVAL;
> >> +	} else {
> >> +		/* remove any reserved markings */
> >> +		for (i = 0; i < num_lmbs; i++)
> >> +			lmbs[i].reserved = 0;
> >> +	}
> > Hmmmm since the if statements are checking for failures. It might be
> > more clear to return -EINVAL (rather than setting rc) and the code in
> > the else block can be moved out of it and come to think of it, return 0.
> > Otherwise it looks odd to me with the 'normal' success case code being
> > in an else statement.
> 
> I like this.
> 
> >> +
> >> +	return rc;
> >> +}
> >> +
> >> +static int dlpar_memory_remove_by_index(struct pseries_hp_errorlog *hp_elog,
> >> +					struct property *prop)
> >> +{
> >> +	struct of_drconf_cell *lmbs;
> >> +	uint32_t num_lmbs, drc_index;
> >> +	int lmb_found;
> >> +	__be32 *p;
> >> +	int i, rc;
> >> +
> >> +	drc_index = be32_to_cpu(hp_elog->_drc_u.drc_index);
> > Didn't you already do the endian conversion back in
> > handle_dlpar_errorlog?
> >> +	pr_info("Attempting to hot-remove LMB, drc index %x\n", drc_index);
> >> +
> >> +	p = prop->value;
> >> +	num_lmbs = be32_to_cpu(*p++);
> >> +	lmbs = (struct of_drconf_cell *)p;
> >> +
> >> +	lmb_found = 0;
> >> +	for (i = 0; i < num_lmbs; i++) {
> >> +		if (lmbs[i].drc_index == hp_elog->_drc_u.drc_index) {
> >> +			lmb_found = 1;
> >> +			rc = dlpar_remove_lmb(&lmbs[i]);
> >> +			break;
> >> +		}
> >> +	}
> >> +
> >> +	if (!lmb_found)
> >> +		rc = -EINVAL;
> >> +
> >> +	if (rc)
> >> +		pr_info("Failed to hot-remove memory, drc index %x\n",
> >> +			drc_index);
> >> +
> >> +	return rc;
> >> +}
> >> +
> >>  #else
> >>  static inline int pseries_remove_memblock(unsigned long base,
> >>  					  unsigned int memblock_size)
> >> @@ -183,6 +356,11 @@ static inline int pseries_remove_mem_node(struct device_node *np)
> >>  {
> >>  	return 0;
> >>  }
> >> +static inline int dlpar_memory_remove(struct pseries_hp_errorlog *hp_elog)
> >> +{
> >> +	return -EOPNOTSUPP;
> >> +}
> >> +
> >>  #endif /* CONFIG_MEMORY_HOTREMOVE */
> >>  
> >>  static int dlpar_add_lmb(struct of_drconf_cell *lmb)
> >> @@ -298,14 +476,24 @@ static int dlpar_memory_add_by_count(struct pseries_hp_errorlog *hp_elog,
> >>  	}
> >>  
> >>  	if (lmbs_added != lmbs_to_add) {
> >> -		/* TODO: remove added lmbs */
> >> +		pr_err("Memory hot-add failed, removing any added LMBs\n");
> >> +
> >> +		for (i = 0; i < num_lmbs; i++) {
> >> +			if (!lmbs[i].reserved)
> >> +				continue;
> >> +
> >> +			rc = dlpar_remove_lmb(&lmbs[i]);
> >> +			if (rc)
> > There is a very much related comment in dlpar_memory_remove_by_count
> > about this condition being true.
> >> +				pr_err("Failed to remove LMB, drc index %x\n",
> >> +				       be32_to_cpu(lmbs[i].drc_index));
> > 
> > You don't clear the reserved flag here?
> In the failure case here the device tree property is not updated, so no
> cleanup needed. This is not really obvious so it would probably be best
> to do the cleanup.
>  
Of course except when you fail to roll back and you'll be forced to
update the device tree - but I suppose clearing it here or not really
depends on how you do that...
> > 
> >> +		}
> >>  		rc = -EINVAL;
> > Same observation as in dlpar_memory_remove_by_count
> 
> ok.
> 
> Thanks for the review.
> 
> -Nathan
> 
> >> +	} else {
> >> +		/* Clear the reserved fields */
> >> +		for (i = 0; i < num_lmbs; i++)
> >> +			lmbs[i].reserved = 0;
> >>  	}
> >>  
> >> -	/* Clear the reserved fields */
> >> -	for (i = 0; i < num_lmbs; i++)
> >> -		lmbs[i].reserved = 0;
> >> -
> >>  	return rc;
> >>  }
> >>  
> >> @@ -373,6 +561,14 @@ int dlpar_memory(struct pseries_hp_errorlog *hp_elog)
> >>  		else
> >>  			rc = -EINVAL;
> >>  		break;
> >> +	case PSERIES_HP_ELOG_ACTION_REMOVE:
> >> +		if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_COUNT)
> >> +			rc = dlpar_memory_remove_by_count(hp_elog, prop);
> >> +		else if (hp_elog->id_type == PSERIES_HP_ELOG_ID_DRC_INDEX)
> >> +			rc = dlpar_memory_remove_by_index(hp_elog, prop);
> >> +		else
> >> +			rc = -EINVAL;
> >> +		break;
> >>  	default:
> >>  		pr_err("Invalid action (%d) specified\n", hp_elog->action);
> >>  		rc = -EINVAL;
> >>
> >> _______________________________________________
> >> Linuxppc-dev mailing list
> >> Linuxppc-dev@lists.ozlabs.org
> >> https://lists.ozlabs.org/listinfo/linuxppc-dev
> > 
> > 
> > 
> 
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev

^ permalink raw reply

* [PATCH 1/3] powerpc/eeh: Fix PE state format
From: Gavin Shan @ 2014-11-24 22:26 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Gavin Shan

Obviously I had wrong format given to the PE state output from
/sys/bus/pci/devices/xxxx/eeh_pe_state with some typoes, which
was introduced by commit 2013add4 ("powerpc/eeh: Show hex prefix
for PE state sysfs"). The patch fixes it up.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 arch/powerpc/kernel/eeh_sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/eeh_sysfs.c b/arch/powerpc/kernel/eeh_sysfs.c
index f19b1e5..1ceecdd 100644
--- a/arch/powerpc/kernel/eeh_sysfs.c
+++ b/arch/powerpc/kernel/eeh_sysfs.c
@@ -65,7 +65,7 @@ static ssize_t eeh_pe_state_show(struct device *dev,
 		return -ENODEV;
 
 	state = eeh_ops->get_state(edev->pe, NULL);
-	return sprintf(buf, "%0x08x %0x08x\n",
+	return sprintf(buf, "0x%08x 0x%08x\n",
 		       state, edev->pe->state);
 }
 
-- 
1.8.3.2

^ permalink raw reply related

* [PATCH 2/3] powerpc/powernv: Replace OPAL_DEASSERT_RESET with EEH_RESET_DEACTIVATE
From: Gavin Shan @ 2014-11-24 22:26 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Gavin Shan
In-Reply-To: <1416868020-4129-1-git-send-email-gwshan@linux.vnet.ibm.com>

The flag passed to ioda_eeh_phb_reset() should be EEH_RESET_DEACTIVATE,
which is translated to OPAL_DEASSERT_RESET or something else by the
EEH backend accordingly.

The patch replaces OPAL_DEASSERT_RESET with EEH_RESET_DEACTIVATE for
ioda_eeh_phb_reset().

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 arch/powerpc/platforms/powernv/pci-ioda.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index d035035..ba1b4cb 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -2102,7 +2102,7 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
 	if (is_kdump_kernel()) {
 		pr_info("  Issue PHB reset ...\n");
 		ioda_eeh_phb_reset(hose, EEH_RESET_FUNDAMENTAL);
-		ioda_eeh_phb_reset(hose, OPAL_DEASSERT_RESET);
+		ioda_eeh_phb_reset(hose, EEH_RESET_DEACTIVATE);
 	}
 
 	/* Remove M64 resource if we can't configure it successfully */
-- 
1.8.3.2

^ permalink raw reply related

* [PATCH 3/3] powerpc/eeh: Fix missed PE#0 on P7IOC
From: Gavin Shan @ 2014-11-24 22:27 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Gavin Shan
In-Reply-To: <1416868020-4129-1-git-send-email-gwshan@linux.vnet.ibm.com>

PE#0 should be regarded as valid for P7IOC, while it's invalid for
PHB3. The patch adds flag EEH_VALID_PE_ZERO to differentiate those
two cases. Without the patch, we possibly see frozen PE#0 state is
cleared without EEH recovery taken on P7IOC as following kernel logs
indicate:

[root@ltcfbl8eb ~]# dmesg
       :
pci 0000:00     : [PE# 000] Secondary bus 0 associated with PE#0
pci 0000:01     : [PE# 001] Secondary bus 1 associated with PE#1
pci 0001:00     : [PE# 000] Secondary bus 0 associated with PE#0
pci 0001:01     : [PE# 001] Secondary bus 1 associated with PE#1
pci 0002:00     : [PE# 000] Secondary bus 0 associated with PE#0
pci 0002:01     : [PE# 001] Secondary bus 1 associated with PE#1
pci 0003:00     : [PE# 000] Secondary bus 0 associated with PE#0
pci 0003:01     : [PE# 001] Secondary bus 1 associated with PE#1
pci 0003:20     : [PE# 002] Secondary bus 32..63 associated with PE#2
       :
EEH: Clear non-existing PHB#3-PE#0
EEH: PHB location: U78AE.001.WZS00M9-P1-002

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 arch/powerpc/include/asm/eeh.h               |  5 +++--
 arch/powerpc/kernel/eeh_pe.c                 | 14 +++++++++++---
 arch/powerpc/platforms/powernv/eeh-powernv.c | 11 +++++++++++
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/include/asm/eeh.h b/arch/powerpc/include/asm/eeh.h
index 0652ebe..9c11d1e 100644
--- a/arch/powerpc/include/asm/eeh.h
+++ b/arch/powerpc/include/asm/eeh.h
@@ -38,8 +38,9 @@ struct device_node;
 #define EEH_FORCE_DISABLED	0x02	/* EEH disabled		*/
 #define EEH_PROBE_MODE_DEV	0x04	/* From PCI device	*/
 #define EEH_PROBE_MODE_DEVTREE	0x08	/* From device tree	*/
-#define EEH_ENABLE_IO_FOR_LOG	0x10	/* Enable IO for log	*/
-#define EEH_EARLY_DUMP_LOG	0x20	/* Dump log immediately	*/
+#define EEH_VALID_PE_ZERO	0x10	/* PE#0 is valid	*/
+#define EEH_ENABLE_IO_FOR_LOG	0x20	/* Enable IO for log	*/
+#define EEH_EARLY_DUMP_LOG	0x40	/* Dump log immediately	*/
 
 /*
  * Delay for PE reset, all in ms
diff --git a/arch/powerpc/kernel/eeh_pe.c b/arch/powerpc/kernel/eeh_pe.c
index 5a63e2b..fa950fb 100644
--- a/arch/powerpc/kernel/eeh_pe.c
+++ b/arch/powerpc/kernel/eeh_pe.c
@@ -239,10 +239,18 @@ static void *__eeh_pe_get(void *data, void *flag)
 	if (pe->type & EEH_PE_PHB)
 		return NULL;
 
-	/* We prefer PE address */
-	if (edev->pe_config_addr &&
-	   (edev->pe_config_addr == pe->addr))
+	/*
+	 * We prefer PE address. For most cases, we should
+	 * have non-zero PE address
+	 */
+	if (eeh_has_flag(EEH_VALID_PE_ZERO)) {
+		if (edev->pe_config_addr == pe->addr)
+			return pe;
+	} else {
+		if (edev->pe_config_addr &&
+		    (edev->pe_config_addr == pe->addr))
 		return pe;
+	}
 
 	/* Try BDF address */
 	if (edev->config_addr &&
diff --git a/arch/powerpc/platforms/powernv/eeh-powernv.c b/arch/powerpc/platforms/powernv/eeh-powernv.c
index 1d19e79..e261869 100644
--- a/arch/powerpc/platforms/powernv/eeh-powernv.c
+++ b/arch/powerpc/platforms/powernv/eeh-powernv.c
@@ -68,6 +68,17 @@ static int powernv_eeh_init(void)
 
 		if (phb->model == PNV_PHB_MODEL_P7IOC)
 			eeh_add_flag(EEH_ENABLE_IO_FOR_LOG);
+
+		/*
+		 * PE#0 should be regarded as valid by EEH core
+		 * if it's not the reserved one. Currently, we
+		 * have the reserved PE#0 and PE#127 for PHB3
+		 * and P7IOC separately. So we should regard
+		 * PE#0 as valid for P7IOC.
+		 */
+		if (phb->ioda.reserved_pe != 0)
+			eeh_add_flag(EEH_VALID_PE_ZERO);
+
 		break;
 	}
 
-- 
1.8.3.2

^ permalink raw reply related

* [PATCH v2 07/14] of/reconfig: Always use the same structure for notifiers
From: Grant Likely @ 2014-11-24 22:33 UTC (permalink / raw)
  To: devicetree, linux-kernel, Pantelis Antoniou
  Cc: Wolfram Sang, Rob Herring, Mark Brown, Grant Likely, linuxppc-dev
In-Reply-To: <1416868422-22103-1-git-send-email-grant.likely@linaro.org>

The OF_RECONFIG notifier callback uses a different structure depending
on whether it is a node change or a property change. This is silly, and
not very safe. Rework the code to use the same data structure regardless
of the type of notifier.

Signed-off-by: Grant Likely <grant.likely@linaro.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: <linuxppc-dev@lists.ozlabs.org>
---
 arch/powerpc/mm/numa.c                          |  3 +-
 arch/powerpc/platforms/pseries/hotplug-cpu.c    |  7 +++--
 arch/powerpc/platforms/pseries/hotplug-memory.c | 15 +++++----
 arch/powerpc/platforms/pseries/iommu.c          |  5 +--
 arch/powerpc/platforms/pseries/setup.c          |  5 +--
 drivers/crypto/nx/nx-842.c                      |  4 +--
 drivers/of/dynamic.c                            | 41 +++++++++++++------------
 include/linux/of.h                              | 23 ++++++++------
 8 files changed, 54 insertions(+), 49 deletions(-)

diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index b9d1dfdbe5bb..9fe6002c1d5a 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -1711,12 +1711,11 @@ static void stage_topology_update(int core_id)
 static int dt_update_callback(struct notifier_block *nb,
 				unsigned long action, void *data)
 {
-	struct of_prop_reconfig *update;
+	struct of_reconfig_data *update = data;
 	int rc = NOTIFY_DONE;
 
 	switch (action) {
 	case OF_RECONFIG_UPDATE_PROPERTY:
-		update = (struct of_prop_reconfig *)data;
 		if (!of_prop_cmp(update->dn->type, "cpu") &&
 		    !of_prop_cmp(update->prop->name, "ibm,associativity")) {
 			u32 core_id;
diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c
index 5c375f93c669..f30cf4d136a4 100644
--- a/arch/powerpc/platforms/pseries/hotplug-cpu.c
+++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c
@@ -340,16 +340,17 @@ static void pseries_remove_processor(struct device_node *np)
 }
 
 static int pseries_smp_notifier(struct notifier_block *nb,
-				unsigned long action, void *node)
+				unsigned long action, void *data)
 {
+	struct of_reconfig_data *rd = data;
 	int err = 0;
 
 	switch (action) {
 	case OF_RECONFIG_ATTACH_NODE:
-		err = pseries_add_processor(node);
+		err = pseries_add_processor(rd->dn);
 		break;
 	case OF_RECONFIG_DETACH_NODE:
-		pseries_remove_processor(node);
+		pseries_remove_processor(rd->dn);
 		break;
 	}
 	return notifier_from_errno(err);
diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
index 3c4c0dcd90d3..1bbb78fab530 100644
--- a/arch/powerpc/platforms/pseries/hotplug-memory.c
+++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
@@ -183,7 +183,7 @@ static int pseries_add_mem_node(struct device_node *np)
 	return (ret < 0) ? -EINVAL : 0;
 }
 
-static int pseries_update_drconf_memory(struct of_prop_reconfig *pr)
+static int pseries_update_drconf_memory(struct of_reconfig_data *pr)
 {
 	struct of_drconf_cell *new_drmem, *old_drmem;
 	unsigned long memblock_size;
@@ -232,22 +232,21 @@ static int pseries_update_drconf_memory(struct of_prop_reconfig *pr)
 }
 
 static int pseries_memory_notifier(struct notifier_block *nb,
-				   unsigned long action, void *node)
+				   unsigned long action, void *data)
 {
-	struct of_prop_reconfig *pr;
+	struct of_reconfig_data *rd = data;
 	int err = 0;
 
 	switch (action) {
 	case OF_RECONFIG_ATTACH_NODE:
-		err = pseries_add_mem_node(node);
+		err = pseries_add_mem_node(rd->dn);
 		break;
 	case OF_RECONFIG_DETACH_NODE:
-		err = pseries_remove_mem_node(node);
+		err = pseries_remove_mem_node(rd->dn);
 		break;
 	case OF_RECONFIG_UPDATE_PROPERTY:
-		pr = (struct of_prop_reconfig *)node;
-		if (!strcmp(pr->prop->name, "ibm,dynamic-memory"))
-			err = pseries_update_drconf_memory(pr);
+		if (!strcmp(rd->prop->name, "ibm,dynamic-memory"))
+			err = pseries_update_drconf_memory(rd);
 		break;
 	}
 	return notifier_from_errno(err);
diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c
index e32e00976a94..3e5bfdafee63 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -1251,10 +1251,11 @@ static struct notifier_block iommu_mem_nb = {
 	.notifier_call = iommu_mem_notifier,
 };
 
-static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *node)
+static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *data)
 {
 	int err = NOTIFY_OK;
-	struct device_node *np = node;
+	struct of_reconfig_data *rd = data;
+	struct device_node *np = rd->dn;
 	struct pci_dn *pci = PCI_DN(np);
 	struct direct_window *window;
 
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 125c589eeef5..ed8a90022a3d 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -251,9 +251,10 @@ static void __init pseries_discover_pic(void)
 	       " interrupt-controller\n");
 }
 
-static int pci_dn_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *node)
+static int pci_dn_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *data)
 {
-	struct device_node *np = node;
+	struct of_reconfig_data *rd = data;
+	struct device_node *np = rd->dn;
 	struct pci_dn *pci = NULL;
 	int err = NOTIFY_OK;
 
diff --git a/drivers/crypto/nx/nx-842.c b/drivers/crypto/nx/nx-842.c
index 061407d59520..887196e9b50c 100644
--- a/drivers/crypto/nx/nx-842.c
+++ b/drivers/crypto/nx/nx-842.c
@@ -1009,9 +1009,9 @@ error_out:
  *		notifier_to_errno() to decode this value
  */
 static int nx842_OF_notifier(struct notifier_block *np, unsigned long action,
-			     void *update)
+			     void *data)
 {
-	struct of_prop_reconfig *upd = update;
+	struct of_reconfig_data *upd = data;
 	struct nx842_devdata *local_devdata;
 	struct device_node *node = NULL;
 
diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index cc106529dca8..3351ef408125 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -87,18 +87,17 @@ const char *action_names[] = {
 };
 #endif
 
-int of_reconfig_notify(unsigned long action, void *p)
+int of_reconfig_notify(unsigned long action, struct of_reconfig_data *p)
 {
 	int rc;
 #ifdef DEBUG
-	struct device_node *dn = p;
-	struct of_prop_reconfig *pr = p;
+	struct of_reconfig_data *pr = p;
 
 	switch (action) {
 	case OF_RECONFIG_ATTACH_NODE:
 	case OF_RECONFIG_DETACH_NODE:
 		pr_debug("of/notify %-15s %s\n", action_names[action],
-			dn->full_name);
+			pr->dn->full_name);
 		break;
 	case OF_RECONFIG_ADD_PROPERTY:
 	case OF_RECONFIG_REMOVE_PROPERTY:
@@ -122,31 +121,22 @@ int of_reconfig_notify(unsigned long action, void *p)
  * Returns 0 on device going from enabled to disabled, 1 on device
  * going from disabled to enabled and -1 on no change.
  */
-int of_reconfig_get_state_change(unsigned long action, void *arg)
+int of_reconfig_get_state_change(unsigned long action, struct of_reconfig_data *pr)
 {
-	struct device_node *dn;
-	struct property *prop, *old_prop;
-	struct of_prop_reconfig *pr;
+	struct property *prop, *old_prop = NULL;
 	int is_status, status_state, old_status_state, prev_state, new_state;
 
 	/* figure out if a device should be created or destroyed */
-	dn = NULL;
-	prop = old_prop = NULL;
 	switch (action) {
 	case OF_RECONFIG_ATTACH_NODE:
 	case OF_RECONFIG_DETACH_NODE:
-		dn = arg;
-		prop = of_find_property(dn, "status", NULL);
+		prop = of_find_property(pr->dn, "status", NULL);
 		break;
 	case OF_RECONFIG_ADD_PROPERTY:
 	case OF_RECONFIG_REMOVE_PROPERTY:
-		pr = arg;
-		dn = pr->dn;
 		prop = pr->prop;
 		break;
 	case OF_RECONFIG_UPDATE_PROPERTY:
-		pr = arg;
-		dn = pr->dn;
 		prop = pr->prop;
 		old_prop = pr->old_prop;
 		break;
@@ -212,7 +202,7 @@ EXPORT_SYMBOL_GPL(of_reconfig_get_state_change);
 int of_property_notify(int action, struct device_node *np,
 		       struct property *prop, struct property *oldprop)
 {
-	struct of_prop_reconfig pr;
+	struct of_reconfig_data pr;
 
 	/* only call notifiers if the node is attached */
 	if (!of_node_is_attached(np))
@@ -250,8 +240,12 @@ void __of_attach_node(struct device_node *np)
  */
 int of_attach_node(struct device_node *np)
 {
+	struct of_reconfig_data rd;
 	unsigned long flags;
 
+	memset(&rd, 0, sizeof(rd));
+	rd.dn = np;
+
 	mutex_lock(&of_mutex);
 	raw_spin_lock_irqsave(&devtree_lock, flags);
 	__of_attach_node(np);
@@ -260,7 +254,7 @@ int of_attach_node(struct device_node *np)
 	__of_attach_node_sysfs(np);
 	mutex_unlock(&of_mutex);
 
-	of_reconfig_notify(OF_RECONFIG_ATTACH_NODE, np);
+	of_reconfig_notify(OF_RECONFIG_ATTACH_NODE, &rd);
 
 	return 0;
 }
@@ -298,9 +292,13 @@ void __of_detach_node(struct device_node *np)
  */
 int of_detach_node(struct device_node *np)
 {
+	struct of_reconfig_data rd;
 	unsigned long flags;
 	int rc = 0;
 
+	memset(&rd, 0, sizeof(rd));
+	rd.dn = np;
+
 	mutex_lock(&of_mutex);
 	raw_spin_lock_irqsave(&devtree_lock, flags);
 	__of_detach_node(np);
@@ -309,7 +307,7 @@ int of_detach_node(struct device_node *np)
 	__of_detach_node_sysfs(np);
 	mutex_unlock(&of_mutex);
 
-	of_reconfig_notify(OF_RECONFIG_DETACH_NODE, np);
+	of_reconfig_notify(OF_RECONFIG_DETACH_NODE, &rd);
 
 	return rc;
 }
@@ -505,6 +503,7 @@ static void __of_changeset_entry_invert(struct of_changeset_entry *ce,
 
 static void __of_changeset_entry_notify(struct of_changeset_entry *ce, bool revert)
 {
+	struct of_reconfig_data rd;
 	struct of_changeset_entry ce_inverted;
 	int ret;
 
@@ -516,7 +515,9 @@ static void __of_changeset_entry_notify(struct of_changeset_entry *ce, bool reve
 	switch (ce->action) {
 	case OF_RECONFIG_ATTACH_NODE:
 	case OF_RECONFIG_DETACH_NODE:
-		ret = of_reconfig_notify(ce->action, ce->np);
+		memset(&rd, 0, sizeof(rd));
+		rd.dn = ce->np;
+		ret = of_reconfig_notify(ce->action, &rd);
 		break;
 	case OF_RECONFIG_ADD_PROPERTY:
 	case OF_RECONFIG_REMOVE_PROPERTY:
diff --git a/include/linux/of.h b/include/linux/of.h
index b59ee21933a4..fe1dec87fd68 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -73,6 +73,12 @@ struct of_phandle_args {
 	uint32_t args[MAX_PHANDLE_ARGS];
 };
 
+struct of_reconfig_data {
+	struct device_node	*dn;
+	struct property		*prop;
+	struct property		*old_prop;
+};
+
 /* initialize a node */
 extern struct kobj_type of_node_ktype;
 static inline void of_node_init(struct device_node *node)
@@ -318,12 +324,6 @@ extern int of_update_property(struct device_node *np, struct property *newprop);
 #define OF_RECONFIG_REMOVE_PROPERTY	0x0004
 #define OF_RECONFIG_UPDATE_PROPERTY	0x0005
 
-struct of_prop_reconfig {
-	struct device_node	*dn;
-	struct property		*prop;
-	struct property		*old_prop;
-};
-
 extern int of_attach_node(struct device_node *);
 extern int of_detach_node(struct device_node *);
 
@@ -892,8 +892,9 @@ enum of_reconfig_change {
 #ifdef CONFIG_OF_DYNAMIC
 extern int of_reconfig_notifier_register(struct notifier_block *);
 extern int of_reconfig_notifier_unregister(struct notifier_block *);
-extern int of_reconfig_notify(unsigned long, void *);
-extern int of_reconfig_get_state_change(unsigned long action, void *arg);
+extern int of_reconfig_notify(unsigned long, struct of_reconfig_data *rd);
+extern int of_reconfig_get_state_change(unsigned long action,
+					struct of_reconfig_data *arg);
 
 extern void of_changeset_init(struct of_changeset *ocs);
 extern void of_changeset_destroy(struct of_changeset *ocs);
@@ -941,11 +942,13 @@ static inline int of_reconfig_notifier_unregister(struct notifier_block *nb)
 {
 	return -EINVAL;
 }
-static inline int of_reconfig_notify(unsigned long action, void *arg)
+static inline int of_reconfig_notify(unsigned long action,
+				     struct of_reconfig_data *arg)
 {
 	return -EINVAL;
 }
-static inline int of_reconfig_get_state_change(unsigned long action, void *arg)
+static inline int of_reconfig_get_state_change(unsigned long action,
+						struct of_reconfig_data *arg)
 {
 	return -EINVAL;
 }
-- 
1.9.1

^ permalink raw reply related

* [PATCH 2/5] powerpc/powernv: Refactor ioda_eeh_reset()
From: Gavin Shan @ 2014-11-24 22:38 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Gavin Shan
In-Reply-To: <1416868727-5814-1-git-send-email-gwshan@linux.vnet.ibm.com>

The patch refactors ioda_eeh_reset() to avoid unnecessary nested
if statements, so that the code looks simplified to earn a bit
more readibility, no logic changed.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 arch/powerpc/platforms/powernv/eeh-ioda.c | 58 ++++++++++++++-----------------
 1 file changed, 26 insertions(+), 32 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/eeh-ioda.c b/arch/powerpc/platforms/powernv/eeh-ioda.c
index e5fa4ff..3b82384 100644
--- a/arch/powerpc/platforms/powernv/eeh-ioda.c
+++ b/arch/powerpc/platforms/powernv/eeh-ioda.c
@@ -679,8 +679,9 @@ void pnv_pci_reset_secondary_bus(struct pci_dev *dev)
 static int ioda_eeh_reset(struct eeh_pe *pe, int option)
 {
 	struct pci_controller *hose = pe->phb;
+	struct pnv_phb *phb;
 	struct pci_bus *bus;
-	int ret;
+	s64 rc;
 
 	/*
 	 * For PHB reset, we always have complete reset. For those PEs whose
@@ -696,41 +697,34 @@ static int ioda_eeh_reset(struct eeh_pe *pe, int option)
 	 * reset. The side effect is that EEH core has to clear the frozen
 	 * state explicitly after BAR restore.
 	 */
-	if (pe->type & EEH_PE_PHB) {
-		ret = ioda_eeh_phb_reset(hose, EEH_RESET_COMPLETE);
-	} else {
-		struct pnv_phb *phb;
-		s64 rc;
+	if (pe->type & EEH_PE_PHB)
+		return ioda_eeh_phb_reset(hose, EEH_RESET_COMPLETE);
 
-		/*
-		 * The frozen PE might be caused by PAPR error injection
-		 * registers, which are expected to be cleared after hitting
-		 * frozen PE as stated in the hardware spec. Unfortunately,
-		 * that's not true on P7IOC. So we have to clear it manually
-		 * to avoid recursive EEH errors during recovery.
-		 */
-		phb = hose->private_data;
-		if (phb->model == PNV_PHB_MODEL_P7IOC &&
-		    (option == EEH_RESET_HOT ||
-		    option == EEH_RESET_FUNDAMENTAL)) {
-			rc = opal_pci_reset(phb->opal_id,
-					    OPAL_RESET_PHB_ERROR);
-			if (rc != OPAL_SUCCESS) {
-				pr_warn("%s: Failure %lld clearing "
-					"error injection registers\n",
-					__func__, rc);
-				return -EIO;
-			}
+	/*
+	 * The frozen PE might be caused by PAPR error injection
+	 * registers, which are expected to be cleared after hitting
+	 * frozen PE as stated in the hardware spec. Unfortunately,
+	 * that's not true on P7IOC. So we have to clear it manually
+	 * to avoid recursive EEH errors during recovery.
+	 */
+	phb = hose->private_data;
+	if (phb->model == PNV_PHB_MODEL_P7IOC &&
+	    (option == EEH_RESET_HOT ||
+	     option == EEH_RESET_FUNDAMENTAL)) {
+		rc = opal_pci_reset(phb->opal_id,
+				    OPAL_RESET_PHB_ERROR);
+		if (rc != OPAL_SUCCESS) {
+			pr_warn("%s: Error %lld clearing error injection\n",
+				__func__, rc);
+			return -EIO;
 		}
-
-		bus = eeh_pe_bus_get(pe);
-		if (pci_is_root_bus(bus))
-			ret = ioda_eeh_phb_reset(hose, option);
-		else
-			ret = ioda_eeh_bridge_reset(bus->self, option);
 	}
 
-	return ret;
+	bus = eeh_pe_bus_get(pe);
+	if (pci_is_root_bus(bus))
+		return ioda_eeh_phb_reset(hose, option);
+
+	return ioda_eeh_bridge_reset(bus->self, option);
 }
 
 /**
-- 
1.8.3.2

^ permalink raw reply related

* [PATCH 3/5] powerpc/powernv: Avoid do complete reset for twice
From: Gavin Shan @ 2014-11-24 22:38 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Gavin Shan
In-Reply-To: <1416868727-5814-1-git-send-email-gwshan@linux.vnet.ibm.com>

For PHB complete reset case, EEH_RESET_DEACTIVATE followed by
EEH_RESET_{HOT,FUNDAMENTAL} requests are issued by EEH core.
All of them are translated to raising complete reset wrongly
and we did complete reset for twice unnecessarily for each
transaction.

The patch fixes above issue by translating the request properly.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 arch/powerpc/platforms/powernv/eeh-ioda.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/eeh-ioda.c b/arch/powerpc/platforms/powernv/eeh-ioda.c
index 3b82384..d02a696 100644
--- a/arch/powerpc/platforms/powernv/eeh-ioda.c
+++ b/arch/powerpc/platforms/powernv/eeh-ioda.c
@@ -697,8 +697,13 @@ static int ioda_eeh_reset(struct eeh_pe *pe, int option)
 	 * reset. The side effect is that EEH core has to clear the frozen
 	 * state explicitly after BAR restore.
 	 */
-	if (pe->type & EEH_PE_PHB)
-		return ioda_eeh_phb_reset(hose, EEH_RESET_COMPLETE);
+	if (pe->type & EEH_PE_PHB) {
+		if (option == EEH_RESET_HOT ||
+		    option == EEH_RESET_FUNDAMENTAL)
+			return ioda_eeh_phb_reset(hose, EEH_RESET_COMPLETE);
+
+		return ioda_eeh_phb_reset(hose, option);
+	}
 
 	/*
 	 * The frozen PE might be caused by PAPR error injection
-- 
1.8.3.2

^ permalink raw reply related

* [PATCH 5/5] powerpc/powernv: Drop opal_pci_reinit()
From: Gavin Shan @ 2014-11-24 22:38 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Gavin Shan
In-Reply-To: <1416868727-5814-1-git-send-email-gwshan@linux.vnet.ibm.com>

With unified PCI slot reset infrastructure supported by the firmware,
we needn't reinitialize the affected devices after PE reset. OPAL API
opal_pci_reinit() and related logic, including EEH restore_config()
callback can be killed safely. All the work covered by opal_pci_reinit()
should be done in firmware insteadly.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 arch/powerpc/include/asm/eeh.h                 |  1 -
 arch/powerpc/include/asm/opal.h                |  6 ------
 arch/powerpc/kernel/eeh_pe.c                   |  3 ---
 arch/powerpc/platforms/powernv/eeh-powernv.c   | 24 +-----------------------
 arch/powerpc/platforms/powernv/opal-wrappers.S |  1 -
 arch/powerpc/platforms/pseries/eeh_pseries.c   |  3 +--
 6 files changed, 2 insertions(+), 36 deletions(-)

diff --git a/arch/powerpc/include/asm/eeh.h b/arch/powerpc/include/asm/eeh.h
index 5847721..687fc5c 100644
--- a/arch/powerpc/include/asm/eeh.h
+++ b/arch/powerpc/include/asm/eeh.h
@@ -214,7 +214,6 @@ struct eeh_ops {
 	int (*read_config)(struct device_node *dn, int where, int size, u32 *val);
 	int (*write_config)(struct device_node *dn, int where, int size, u32 val);
 	int (*next_error)(struct eeh_pe **pe);
-	int (*restore_config)(struct device_node *dn);
 };
 
 extern int eeh_subsystem_flags;
diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 0b8b4b1..b59811f 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -108,7 +108,6 @@ struct opal_sg_list {
 #define OPAL_PCI_GET_HUB_DIAG_DATA		50
 #define OPAL_PCI_GET_PHB_DIAG_DATA		51
 #define OPAL_PCI_FENCE_PHB			52
-#define OPAL_PCI_REINIT				53
 #define OPAL_PCI_MASK_PE_ERROR			54
 #define OPAL_SET_SLOT_LED_STATUS		55
 #define OPAL_GET_EPOW_STATUS			56
@@ -395,10 +394,6 @@ enum OpalPciResetScope {
 	OPAL_RESET_PHB_ERROR		= 4
 };
 
-enum OpalPciReinitScope {
-	OPAL_REINIT_PCI_DEV = 1000
-};
-
 enum OpalSlotLedType {
 	OPAL_SLOT_LED_ID_TYPE = 0,
 	OPAL_SLOT_LED_FAULT_TYPE = 1
@@ -904,7 +899,6 @@ int64_t opal_pci_get_phb_diag_data(uint64_t phb_id, void *diag_buffer,
 int64_t opal_pci_get_phb_diag_data2(uint64_t phb_id, void *diag_buffer,
 				    uint64_t diag_buffer_len);
 int64_t opal_pci_fence_phb(uint64_t phb_id);
-int64_t opal_pci_reinit(uint64_t phb_id, uint64_t reinit_scope, uint64_t data);
 int64_t opal_pci_mask_pe_error(uint64_t phb_id, uint16_t pe_number, uint8_t error_type, uint8_t mask_action);
 int64_t opal_set_slot_led_status(uint64_t phb_id, uint64_t slot_id, uint8_t led_type, uint8_t led_action);
 int64_t opal_get_epow_status(__be64 *status);
diff --git a/arch/powerpc/kernel/eeh_pe.c b/arch/powerpc/kernel/eeh_pe.c
index fa950fb..98a1f12 100644
--- a/arch/powerpc/kernel/eeh_pe.c
+++ b/arch/powerpc/kernel/eeh_pe.c
@@ -814,9 +814,6 @@ static void *eeh_restore_one_device_bars(void *data, void *flag)
 	else
 		eeh_restore_device_bars(edev, dn);
 
-	if (eeh_ops->restore_config)
-		eeh_ops->restore_config(dn);
-
 	return NULL;
 }
 
diff --git a/arch/powerpc/platforms/powernv/eeh-powernv.c b/arch/powerpc/platforms/powernv/eeh-powernv.c
index e261869..d57ff59c 100644
--- a/arch/powerpc/platforms/powernv/eeh-powernv.c
+++ b/arch/powerpc/platforms/powernv/eeh-powernv.c
@@ -469,27 +469,6 @@ static int powernv_eeh_next_error(struct eeh_pe **pe)
 	return -EEXIST;
 }
 
-static int powernv_eeh_restore_config(struct device_node *dn)
-{
-	struct eeh_dev *edev = of_node_to_eeh_dev(dn);
-	struct pnv_phb *phb;
-	s64 ret;
-
-	if (!edev)
-		return -EEXIST;
-
-	phb = edev->phb->private_data;
-	ret = opal_pci_reinit(phb->opal_id,
-			      OPAL_REINIT_PCI_DEV, edev->config_addr);
-	if (ret) {
-		pr_warn("%s: Can't reinit PCI dev 0x%x (%lld)\n",
-			__func__, edev->config_addr, ret);
-		return -EIO;
-	}
-
-	return 0;
-}
-
 static struct eeh_ops powernv_eeh_ops = {
 	.name                   = "powernv",
 	.init                   = powernv_eeh_init,
@@ -506,8 +485,7 @@ static struct eeh_ops powernv_eeh_ops = {
 	.err_inject		= powernv_eeh_err_inject,
 	.read_config            = powernv_eeh_read_config,
 	.write_config           = powernv_eeh_write_config,
-	.next_error		= powernv_eeh_next_error,
-	.restore_config		= powernv_eeh_restore_config
+	.next_error		= powernv_eeh_next_error
 };
 
 /**
diff --git a/arch/powerpc/platforms/powernv/opal-wrappers.S b/arch/powerpc/platforms/powernv/opal-wrappers.S
index feb549a..b6474a1 100644
--- a/arch/powerpc/platforms/powernv/opal-wrappers.S
+++ b/arch/powerpc/platforms/powernv/opal-wrappers.S
@@ -209,7 +209,6 @@ OPAL_CALL(opal_pci_reset,			OPAL_PCI_RESET);
 OPAL_CALL(opal_pci_get_hub_diag_data,		OPAL_PCI_GET_HUB_DIAG_DATA);
 OPAL_CALL(opal_pci_get_phb_diag_data,		OPAL_PCI_GET_PHB_DIAG_DATA);
 OPAL_CALL(opal_pci_fence_phb,			OPAL_PCI_FENCE_PHB);
-OPAL_CALL(opal_pci_reinit,			OPAL_PCI_REINIT);
 OPAL_CALL(opal_pci_mask_pe_error,		OPAL_PCI_MASK_PE_ERROR);
 OPAL_CALL(opal_set_slot_led_status,		OPAL_SET_SLOT_LED_STATUS);
 OPAL_CALL(opal_get_epow_status,			OPAL_GET_EPOW_STATUS);
diff --git a/arch/powerpc/platforms/pseries/eeh_pseries.c b/arch/powerpc/platforms/pseries/eeh_pseries.c
index a6c7e19..e69aff6 100644
--- a/arch/powerpc/platforms/pseries/eeh_pseries.c
+++ b/arch/powerpc/platforms/pseries/eeh_pseries.c
@@ -719,8 +719,7 @@ static struct eeh_ops pseries_eeh_ops = {
 	.err_inject		= NULL,
 	.read_config		= pseries_eeh_read_config,
 	.write_config		= pseries_eeh_write_config,
-	.next_error		= NULL,
-	.restore_config		= NULL
+	.next_error		= NULL
 };
 
 /**
-- 
1.8.3.2

^ permalink raw reply related

* [PATCH v1 0/5] powerpc/pci: PCI slot unified reset
From: Gavin Shan @ 2014-11-24 22:38 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Gavin Shan

The patchset corresponds to skiboot changes, which manages PCI slots
in a unified way: OPAL APIs used to do slot reset, power management,
presence status retrival. The patchset shouldn't be merged before
the OPAL firmware counterpart is merged.

The kernel changes have been split into 2 parts: (A) Use the unified
PCI slot reset OPAL API - this patchset; (B) Changes to rpaphp.ko to
support PCI slot hotplug via sysfs entries for PowerPC PowerNV platform.

This patchset affects EEH, PCI reset logics, which is used mainly by
VFIO. A couple of cases have been tested out on P7/P8 boxes and looks
good: EEH on PowerNV, EEH support for guest, PCI passthrou.

Gavin Shan (5):
  powerpc/powernv: Use PCI slot reset infrastructure
  powerpc/powernv: Refactor ioda_eeh_reset()
  powerpc/powernv: Avoid do complete reset for twice
  powerpc/powernv: Issue fundamental reset if required
  powerpc/powernv: Drop opal_pci_reinit()

 arch/powerpc/include/asm/eeh.h                 |   2 +-
 arch/powerpc/include/asm/opal.h                |  31 +---
 arch/powerpc/kernel/eeh_pe.c                   |   3 -
 arch/powerpc/platforms/powernv/eeh-ioda.c      | 230 ++++++++++++++-----------
 arch/powerpc/platforms/powernv/eeh-powernv.c   |  24 +--
 arch/powerpc/platforms/powernv/opal-wrappers.S |   1 -
 arch/powerpc/platforms/powernv/pci-ioda.c      |   5 +-
 arch/powerpc/platforms/pseries/eeh_pseries.c   |   3 +-
 8 files changed, 139 insertions(+), 160 deletions(-)

Thanks,
Gavin

^ permalink raw reply

* [PATCH 1/5] powerpc/powernv: Use PCI slot reset infrastructure
From: Gavin Shan @ 2014-11-24 22:38 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Gavin Shan
In-Reply-To: <1416868727-5814-1-git-send-email-gwshan@linux.vnet.ibm.com>

The patch reworks the reset logic to reuse PCI slot reset
infrastructure implemented in OPAL firmware. For one particular
PCI slot, we have switch to hot reset in case the firmware can't
support reset for it.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 arch/powerpc/include/asm/eeh.h            |   1 +
 arch/powerpc/include/asm/opal.h           |  25 ++---
 arch/powerpc/platforms/powernv/eeh-ioda.c | 149 ++++++++++++++++--------------
 arch/powerpc/platforms/powernv/pci-ioda.c |   5 +-
 4 files changed, 89 insertions(+), 91 deletions(-)

diff --git a/arch/powerpc/include/asm/eeh.h b/arch/powerpc/include/asm/eeh.h
index 9c11d1e..5847721 100644
--- a/arch/powerpc/include/asm/eeh.h
+++ b/arch/powerpc/include/asm/eeh.h
@@ -192,6 +192,7 @@ enum {
 #define EEH_RESET_DEACTIVATE	0	/* Deactivate the PE reset	*/
 #define EEH_RESET_HOT		1	/* Hot reset			*/
 #define EEH_RESET_FUNDAMENTAL	3	/* Fundamental reset		*/
+#define EEH_RESET_COMPLETE	4	/* PHB complete reset		*/
 #define EEH_LOG_TEMP		1	/* EEH temporary error log	*/
 #define EEH_LOG_PERM		2	/* EEH permanent error log	*/
 
diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 9124b0e..0b8b4b1 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -388,28 +388,17 @@ enum OpalM64EnableAction {
 };
 
 enum OpalPciResetScope {
-	OPAL_RESET_PHB_COMPLETE		= 1,
-	OPAL_RESET_PCI_LINK		= 2,
-	OPAL_RESET_PHB_ERROR		= 3,
-	OPAL_RESET_PCI_HOT		= 4,
-	OPAL_RESET_PCI_FUNDAMENTAL	= 5,
-	OPAL_RESET_PCI_IODA_TABLE	= 6
+	OPAL_RESET_PCI_HOT		= 0,
+	OPAL_RESET_PCI_FUNDAMENTAL	= 1,
+	OPAL_RESET_PHB_COMPLETE		= 2,
+	OPAL_RESET_PCI_IODA_TABLE	= 3,
+	OPAL_RESET_PHB_ERROR		= 4
 };
 
 enum OpalPciReinitScope {
 	OPAL_REINIT_PCI_DEV = 1000
 };
 
-enum OpalPciResetState {
-	OPAL_DEASSERT_RESET = 0,
-	OPAL_ASSERT_RESET = 1
-};
-
-enum OpalPciMaskAction {
-	OPAL_UNMASK_ERROR_TYPE = 0,
-	OPAL_MASK_ERROR_TYPE = 1
-};
-
 enum OpalSlotLedType {
 	OPAL_SLOT_LED_ID_TYPE = 0,
 	OPAL_SLOT_LED_FAULT_TYPE = 1
@@ -906,7 +895,7 @@ int64_t opal_pci_map_pe_dma_window(uint64_t phb_id, uint16_t pe_number, uint16_t
 int64_t opal_pci_map_pe_dma_window_real(uint64_t phb_id, uint16_t pe_number,
 					uint16_t dma_window_number, uint64_t pci_start_addr,
 					uint64_t pci_mem_size);
-int64_t opal_pci_reset(uint64_t phb_id, uint8_t reset_scope, uint8_t assert_state);
+int64_t opal_pci_reset(uint64_t id, uint8_t reset_scope);
 
 int64_t opal_pci_get_hub_diag_data(uint64_t hub_id, void *diag_buffer,
 				   uint64_t diag_buffer_len);
@@ -922,7 +911,7 @@ int64_t opal_get_epow_status(__be64 *status);
 int64_t opal_set_system_attention_led(uint8_t led_action);
 int64_t opal_pci_next_error(uint64_t phb_id, __be64 *first_frozen_pe,
 			    __be16 *pci_error_type, __be16 *severity);
-int64_t opal_pci_poll(uint64_t phb_id);
+int64_t opal_pci_poll(uint64_t id);
 int64_t opal_return_cpu(void);
 int64_t opal_check_token(uint64_t token);
 int64_t opal_reinit_cpus(uint64_t flags);
diff --git a/arch/powerpc/platforms/powernv/eeh-ioda.c b/arch/powerpc/platforms/powernv/eeh-ioda.c
index 43aba2d..e5fa4ff 100644
--- a/arch/powerpc/platforms/powernv/eeh-ioda.c
+++ b/arch/powerpc/platforms/powernv/eeh-ioda.c
@@ -490,12 +490,12 @@ static int ioda_eeh_get_state(struct eeh_pe *pe)
 	return ioda_eeh_get_pe_state(pe);
 }
 
-static s64 ioda_eeh_phb_poll(struct pnv_phb *phb)
+static s64 ioda_eeh_phb_poll(uint64_t id)
 {
 	s64 rc = OPAL_HARDWARE;
 
 	while (1) {
-		rc = opal_pci_poll(phb->opal_id);
+		rc = opal_pci_poll(id);
 		if (rc <= 0)
 			break;
 
@@ -511,23 +511,29 @@ static s64 ioda_eeh_phb_poll(struct pnv_phb *phb)
 int ioda_eeh_phb_reset(struct pci_controller *hose, int option)
 {
 	struct pnv_phb *phb = hose->private_data;
+	uint8_t reset_scope;
 	s64 rc = OPAL_HARDWARE;
 
 	pr_debug("%s: Reset PHB#%x, option=%d\n",
 		 __func__, hose->global_number, option);
 
-	/* Issue PHB complete reset request */
-	if (option == EEH_RESET_FUNDAMENTAL ||
-	    option == EEH_RESET_HOT)
-		rc = opal_pci_reset(phb->opal_id,
-				OPAL_RESET_PHB_COMPLETE,
-				OPAL_ASSERT_RESET);
-	else if (option == EEH_RESET_DEACTIVATE)
-		rc = opal_pci_reset(phb->opal_id,
-				OPAL_RESET_PHB_COMPLETE,
-				OPAL_DEASSERT_RESET);
-	if (rc < 0)
-		goto out;
+	switch (option) {
+	case EEH_RESET_HOT:
+		reset_scope = OPAL_RESET_PCI_HOT;
+		break;
+	case EEH_RESET_FUNDAMENTAL:
+		reset_scope = OPAL_RESET_PCI_FUNDAMENTAL;
+		break;
+	case EEH_RESET_COMPLETE:
+		reset_scope = OPAL_RESET_PHB_COMPLETE;
+		break;
+	case EEH_RESET_DEACTIVATE:
+		return 0;
+	default:
+		pr_warn("%s: Unsupported option %d\n",
+			__func__, option);
+		return -EINVAL;
+	}
 
 	/*
 	 * Poll state of the PHB until the request is done
@@ -535,61 +541,17 @@ int ioda_eeh_phb_reset(struct pci_controller *hose, int option)
 	 * reset followed by hot reset on root bus. So we also
 	 * need the PCI bus settlement delay.
 	 */
-	rc = ioda_eeh_phb_poll(phb);
-	if (option == EEH_RESET_DEACTIVATE) {
-		if (system_state < SYSTEM_RUNNING)
-			udelay(1000 * EEH_PE_RST_SETTLE_TIME);
-		else
-			msleep(EEH_PE_RST_SETTLE_TIME);
-	}
-out:
-	if (rc != OPAL_SUCCESS)
-		return -EIO;
-
-	return 0;
-}
-
-static int ioda_eeh_root_reset(struct pci_controller *hose, int option)
-{
-	struct pnv_phb *phb = hose->private_data;
-	s64 rc = OPAL_SUCCESS;
+	rc = opal_pci_reset(phb->opal_id, reset_scope);
+	if (rc > 0)
+		rc = ioda_eeh_phb_poll(phb->opal_id);
 
-	pr_debug("%s: Reset PHB#%x, option=%d\n",
-		 __func__, hose->global_number, option);
-
-	/*
-	 * During the reset deassert time, we needn't care
-	 * the reset scope because the firmware does nothing
-	 * for fundamental or hot reset during deassert phase.
-	 */
-	if (option == EEH_RESET_FUNDAMENTAL)
-		rc = opal_pci_reset(phb->opal_id,
-				OPAL_RESET_PCI_FUNDAMENTAL,
-				OPAL_ASSERT_RESET);
-	else if (option == EEH_RESET_HOT)
-		rc = opal_pci_reset(phb->opal_id,
-				OPAL_RESET_PCI_HOT,
-				OPAL_ASSERT_RESET);
-	else if (option == EEH_RESET_DEACTIVATE)
-		rc = opal_pci_reset(phb->opal_id,
-				OPAL_RESET_PCI_HOT,
-				OPAL_DEASSERT_RESET);
-	if (rc < 0)
-		goto out;
-
-	/* Poll state of the PHB until the request is done */
-	rc = ioda_eeh_phb_poll(phb);
-	if (option == EEH_RESET_DEACTIVATE)
-		msleep(EEH_PE_RST_SETTLE_TIME);
-out:
 	if (rc != OPAL_SUCCESS)
 		return -EIO;
 
 	return 0;
 }
 
-static int ioda_eeh_bridge_reset(struct pci_dev *dev, int option)
-
+static int __ioda_eeh_bridge_reset(struct pci_dev *dev, int option)
 {
 	struct device_node *dn = pci_device_to_OF_node(dev);
 	struct eeh_dev *edev = of_node_to_eeh_dev(dn);
@@ -639,14 +601,63 @@ static int ioda_eeh_bridge_reset(struct pci_dev *dev, int option)
 	return 0;
 }
 
+static int ioda_eeh_bridge_reset(struct pci_dev *dev, int option)
+{
+	struct pci_controller *hose;
+	struct pnv_phb *phb;
+	struct device_node *dn = dev ? pci_device_to_OF_node(dev) : NULL;
+	const char *label = NULL;
+	uint64_t id = 0x1000000000000000;
+	uint8_t reset_scope;
+	s64 rc;
+
+	/*
+	 * If the firmware can't handle it, we still need simulate a hot
+	 * reset on the secondary bus. It should be the rare case.
+	 */
+	if (dn)
+		label = of_get_property(dn, "ibm,slot-label", NULL);
+	if (!label)
+		return __ioda_eeh_bridge_reset(dev, option);
+
+	/* The firmware can handle the request */
+	switch (option) {
+	case EEH_RESET_HOT:
+		reset_scope = OPAL_RESET_PCI_HOT;
+		break;
+	case EEH_RESET_FUNDAMENTAL:
+		reset_scope = OPAL_RESET_PCI_FUNDAMENTAL;
+		break;
+	case EEH_RESET_DEACTIVATE:
+		return 0;
+	case EEH_RESET_COMPLETE:
+	default:
+		pr_warn("%s: Unsupported option %d\n",
+			__func__, option);
+		return -EINVAL;
+	}
+
+	hose = pci_bus_to_host(dev->bus);
+	phb = hose->private_data;
+	id |= ((phb->opal_id << 16) | (dev->bus->number << 8) | (dev->devfn));
+	rc = opal_pci_reset(id, reset_scope);
+	if (rc > 0)
+		rc = ioda_eeh_phb_poll(id);
+
+	if (rc != OPAL_SUCCESS)
+		return -EIO;
+
+	return 0;
+}
+
 void pnv_pci_reset_secondary_bus(struct pci_dev *dev)
 {
 	struct pci_controller *hose;
 
 	if (pci_is_root_bus(dev->bus)) {
 		hose = pci_bus_to_host(dev->bus);
-		ioda_eeh_root_reset(hose, EEH_RESET_HOT);
-		ioda_eeh_root_reset(hose, EEH_RESET_DEACTIVATE);
+		ioda_eeh_phb_reset(hose, EEH_RESET_HOT);
+		ioda_eeh_phb_reset(hose, EEH_RESET_DEACTIVATE);
 	} else {
 		ioda_eeh_bridge_reset(dev, EEH_RESET_HOT);
 		ioda_eeh_bridge_reset(dev, EEH_RESET_DEACTIVATE);
@@ -686,7 +697,7 @@ static int ioda_eeh_reset(struct eeh_pe *pe, int option)
 	 * state explicitly after BAR restore.
 	 */
 	if (pe->type & EEH_PE_PHB) {
-		ret = ioda_eeh_phb_reset(hose, option);
+		ret = ioda_eeh_phb_reset(hose, EEH_RESET_COMPLETE);
 	} else {
 		struct pnv_phb *phb;
 		s64 rc;
@@ -703,8 +714,7 @@ static int ioda_eeh_reset(struct eeh_pe *pe, int option)
 		    (option == EEH_RESET_HOT ||
 		    option == EEH_RESET_FUNDAMENTAL)) {
 			rc = opal_pci_reset(phb->opal_id,
-					    OPAL_RESET_PHB_ERROR,
-					    OPAL_ASSERT_RESET);
+					    OPAL_RESET_PHB_ERROR);
 			if (rc != OPAL_SUCCESS) {
 				pr_warn("%s: Failure %lld clearing "
 					"error injection registers\n",
@@ -714,9 +724,8 @@ static int ioda_eeh_reset(struct eeh_pe *pe, int option)
 		}
 
 		bus = eeh_pe_bus_get(pe);
-		if (pci_is_root_bus(bus) ||
-		    pci_is_root_bus(bus->parent))
-			ret = ioda_eeh_root_reset(hose, option);
+		if (pci_is_root_bus(bus))
+			ret = ioda_eeh_phb_reset(hose, option);
 		else
 			ret = ioda_eeh_bridge_reset(bus->self, option);
 	}
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index ba1b4cb..5b0fcea 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -1913,8 +1913,7 @@ static u32 pnv_ioda_bdfn_to_pe(struct pnv_phb *phb, struct pci_bus *bus,
 
 static void pnv_pci_ioda_shutdown(struct pnv_phb *phb)
 {
-	opal_pci_reset(phb->opal_id, OPAL_RESET_PCI_IODA_TABLE,
-		       OPAL_ASSERT_RESET);
+	opal_pci_reset(phb->opal_id, OPAL_RESET_PCI_IODA_TABLE);
 }
 
 static void __init pnv_pci_init_ioda_phb(struct device_node *np,
@@ -2090,7 +2089,7 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
 	pci_add_flags(PCI_REASSIGN_ALL_RSRC);
 
 	/* Reset IODA tables to a clean state */
-	rc = opal_pci_reset(phb_id, OPAL_RESET_PCI_IODA_TABLE, OPAL_ASSERT_RESET);
+	rc = opal_pci_reset(phb_id, OPAL_RESET_PCI_IODA_TABLE);
 	if (rc)
 		pr_warning("  OPAL Error %ld performing IODA table reset !\n", rc);
 
-- 
1.8.3.2

^ permalink raw reply related

* [PATCH 4/5] powerpc/powernv: Issue fundamental reset if required
From: Gavin Shan @ 2014-11-24 22:38 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Gavin Shan
In-Reply-To: <1416868727-5814-1-git-send-email-gwshan@linux.vnet.ibm.com>

pnv_pci_reset_secondary_bus() is the backend for resetting the
secondary bus for the specified PCI bridge. We always issue hot
reset, which isn't enough for some devices who requires fundamental
reset explicitly. The patch switches to fundamental reset if the
devices ask for that.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 arch/powerpc/platforms/powernv/eeh-ioda.c | 34 +++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/eeh-ioda.c b/arch/powerpc/platforms/powernv/eeh-ioda.c
index d02a696..4bf2fb5 100644
--- a/arch/powerpc/platforms/powernv/eeh-ioda.c
+++ b/arch/powerpc/platforms/powernv/eeh-ioda.c
@@ -650,18 +650,34 @@ static int ioda_eeh_bridge_reset(struct pci_dev *dev, int option)
 	return 0;
 }
 
+static int pnv_pci_dev_reset_type(struct pci_dev *pdev, void *data)
+{
+	int *freset = data;
+
+	/*
+	 * Stop the iteration immediately if any one
+	 * PCI device requires fundamental reset
+	 */
+	*freset |= pdev->needs_freset;
+	return *freset;
+}
+
+/*
+ * When the function is called, there should have
+ * valid bridge. We don't need cover root bus here
+ */
 void pnv_pci_reset_secondary_bus(struct pci_dev *dev)
 {
-	struct pci_controller *hose;
+	int option = EEH_RESET_HOT;
+	int freset = 0;
 
-	if (pci_is_root_bus(dev->bus)) {
-		hose = pci_bus_to_host(dev->bus);
-		ioda_eeh_phb_reset(hose, EEH_RESET_HOT);
-		ioda_eeh_phb_reset(hose, EEH_RESET_DEACTIVATE);
-	} else {
-		ioda_eeh_bridge_reset(dev, EEH_RESET_HOT);
-		ioda_eeh_bridge_reset(dev, EEH_RESET_DEACTIVATE);
-	}
+	/* Need fundamental reset ? */
+	pci_walk_bus(dev->subordinate, pnv_pci_dev_reset_type, &freset);
+	if (freset)
+		option = EEH_RESET_FUNDAMENTAL;
+
+	ioda_eeh_bridge_reset(dev, option);
+	ioda_eeh_bridge_reset(dev, EEH_RESET_DEACTIVATE);
 }
 
 /**
-- 
1.8.3.2

^ permalink raw reply related

* [PATCH 7/8] PCI/hotplug/rpa: Hierarchial slots
From: Gavin Shan @ 2014-11-24 22:49 UTC (permalink / raw)
  To: linux-pci; +Cc: linuxppc-dev, Gavin Shan
In-Reply-To: <1416869365-7671-1-git-send-email-gwshan@linux.vnet.ibm.com>

The direct or indirect parent of hotpluggable slot has possibility
to be hotpluggable. Unfortunately, current implementation doesn't
cover it. The patch fixes the issue:

   * When adding slots based on the given device node, the child
     device nodes are scanned to see if they're hotpluggable and
     add slots for them if applicable.
   * When unregistering slot, its children slots will be removed
     automatically.
   * Parent slot is added prior to child slots in addition path,
     while child slots should be removed before parent slot in
     removal path.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 drivers/pci/hotplug/rpadlpar_core.c |   6 +--
 drivers/pci/hotplug/rpaphp.h        |  22 ++++----
 drivers/pci/hotplug/rpaphp_core.c   | 105 ++++++++++++++++++++++++------------
 3 files changed, 85 insertions(+), 48 deletions(-)

diff --git a/drivers/pci/hotplug/rpadlpar_core.c b/drivers/pci/hotplug/rpadlpar_core.c
index a36d2c9..f375e92 100644
--- a/drivers/pci/hotplug/rpadlpar_core.c
+++ b/drivers/pci/hotplug/rpadlpar_core.c
@@ -119,11 +119,9 @@ static struct device_node *find_dlpar_node(char *drc_name, int *node_type)
  */
 static struct rpa_php_slot *find_php_slot(struct device_node *dn)
 {
-	struct list_head *tmp, *n;
-	struct rpa_php_slot *slot;
+	struct rpa_php_slot *slot, *tmp;
 
-	list_for_each_safe(tmp, n, &rpaphp_slot_head) {
-		slot = list_entry(tmp, struct rpa_php_slot, rpaphp_slot_list);
+	list_for_each_entry_safe(slot, tmp, &rpaphp_slot_head, link) {
 		if (slot->dn == dn)
 			return slot;
 	}
diff --git a/drivers/pci/hotplug/rpaphp.h b/drivers/pci/hotplug/rpaphp.h
index 09dd516..0354572 100644
--- a/drivers/pci/hotplug/rpaphp.h
+++ b/drivers/pci/hotplug/rpaphp.h
@@ -57,19 +57,21 @@ extern bool rpaphp_debug;
 #define RPA_PHP_SLOT_PRESENT	1	/* Presented     */
 
 struct rpa_php_slot {
-	struct list_head rpaphp_slot_list;
-	int state;
+	char			*name;
+	int			state;
 #define RPA_PHP_SLOT_NOT_CONFIGURED	0
 #define RPA_PHP_SLOT_CONFIGURED		1
 #define RPA_PHP_SLOT_NOT_VALID		2
-	u32 index;
-	u32 type;
-	u32 power_domain;
-	char *name;
-	struct device_node *dn;
-	struct pci_bus *bus;
-	struct list_head *pci_devs;
-	struct hotplug_slot *hotplug_slot;
+	u32			index;
+	u32			type;
+	u32			power_domain;
+	struct device_node	*dn;
+	struct pci_bus		*bus;
+	struct list_head	*pci_devs;
+	struct hotplug_slot	*hotplug_slot;
+	struct list_head	link;
+	struct list_head	list;
+	struct list_head	children;
 };
 
 extern struct list_head rpaphp_slot_head;
diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c
index 91eff8f..ba28212 100644
--- a/drivers/pci/hotplug/rpaphp_core.c
+++ b/drivers/pci/hotplug/rpaphp_core.c
@@ -25,6 +25,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
+#include <linux/list.h>
 #include <linux/pci.h>
 #include <linux/pci_hotplug.h>
 #include <linux/smp.h>
@@ -87,6 +88,9 @@ struct rpa_php_slot *alloc_slot_struct(struct device_node *dn,
 	slot->power_domain = power_domain;
 	slot->hotplug_slot->private = slot;
 	slot->hotplug_slot->release = &rpaphp_release_slot;
+	INIT_LIST_HEAD(&slot->link);
+	INIT_LIST_HEAD(&slot->list);
+	INIT_LIST_HEAD(&slot->children);
 
 	slot->hotplug_slot->info->power_status = RPA_PHP_SLOT_POWER_ON;
 	slot->hotplug_slot->info->attention_status = RPA_PHP_SLOT_ATTEN_OFF;
@@ -107,16 +111,17 @@ error_nomem:
 
 int rpaphp_register_slot(struct rpa_php_slot *slot)
 {
+	struct device_node *dn;
 	struct hotplug_slot *php_slot = slot->hotplug_slot;
-	struct rpa_php_slot *tmp;
-	int slotno, retval;
+	struct rpa_php_slot *parent, *tmp;
+	int slotno, ret;
 
 	dbg("%s registering slot:path[%s] index[%x], name[%s] pdomain[%x] type[%d]\n",
 	    __func__, slot->dn->full_name, slot->index, slot->name,
 	    slot->power_domain, slot->type);
 
 	/* Should not try to register the same slot twice */
-	list_for_each_entry(tmp, &rpaphp_slot_head, rpaphp_slot_list) {
+	list_for_each_entry(tmp, &rpaphp_slot_head, link) {
 		if (!strcmp(tmp->name, slot->name)) {
 			err("%s: Slot[%s] is already registered\n",
 			    __func__, slot->name);
@@ -127,34 +132,62 @@ int rpaphp_register_slot(struct rpa_php_slot *slot)
 		slotno = PCI_SLOT(PCI_DN(slot->dn->child)->devfn);
 	else
 		slotno = -1;
-	retval = pci_hp_register(php_slot, slot->bus, slotno, slot->name);
-	if (retval) {
-		err("pci_hp_register failed with error %d\n", retval);
-		return retval;
+	ret = pci_hp_register(php_slot, slot->bus, slotno, slot->name);
+	if (ret) {
+		err("pci_hp_register failed with error %d\n", ret);
+		return ret;
+	}
+
+	/* Search parent slot */
+	parent = NULL;
+	dn = slot->dn;
+	while (!parent && (dn = of_get_parent(dn))) {
+		if (!PCI_DN(dn)) {
+			of_node_put(dn);
+			break;
+		}
+
+		list_for_each_entry(tmp, &rpaphp_slot_head, link) {
+			if (tmp->dn != dn) {
+				parent = tmp;
+				break;
+			}
+		}
 	}
 
-	/* add slot to our internal list */
-	list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head);
+	/* Add slot to parent list */
+	if (parent)
+		list_add(&slot->list, &parent->children);
+
+	/* Add slot to global list */
+	list_add(&slot->link, &rpaphp_slot_head);
 	info("Slot [%s] registered\n", slot->name);
 	return 0;
 }
 
 int rpaphp_deregister_slot(struct rpa_php_slot *slot)
 {
+	struct rpa_php_slot *child, *tmp;
 	struct hotplug_slot *php_slot = slot->hotplug_slot;
-	int retval = 0;
+	int ret;
 
-	dbg("%s - Entry: deregistering slot=%s\n",
-	    __func__, slot->name);
+	/* Unregister children firstly */
+	list_for_each_entry_safe(child, tmp, &slot->children, list) {
+		ret = rpaphp_deregister_slot(child);
+		if (ret)
+			return ret;
+	}
 
-	list_del(&slot->rpaphp_slot_list);
+	/* Remove from the parent and global lists */
+	list_del(&slot->list);
+	list_del(&slot->link);
 
-	retval = pci_hp_deregister(php_slot);
-	if (retval)
-		err("Problem unregistering a slot %s\n", slot->name);
+	ret = pci_hp_deregister(php_slot);
+	if (ret)
+		err("%s: Error %d unregistering slot[%s]\n",
+		    __func__, ret, slot->name);
 
-	dbg("%s - Exit: rc[%d]\n", __func__, retval);
-	return retval;
+	return ret;
 }
 EXPORT_SYMBOL_GPL(rpaphp_deregister_slot);
 
@@ -176,24 +209,31 @@ EXPORT_SYMBOL_GPL(rpaphp_deregister_slot);
  */
 int rpaphp_add_slot(struct device_node *dn)
 {
+	struct device_node *child;
 	struct rpa_php_slot *slot = NULL;
 	int ret;
 
 	/* Create slot */
 	if (machine_is(pseries))
 		slot = rpaphp_rtas_add_slot(dn);
-	if (!slot)
-		return -EIO;
 
-	/* Enable slot */
-	ret = slot->hotplug_slot->ops->enable_slot(slot->hotplug_slot);
-	if (ret)
-		goto fail;
+	if (slot) {
+		/* Enable slot */
+		ret = slot->hotplug_slot->ops->enable_slot(slot->hotplug_slot);
+		if (ret)
+			goto fail;
 
-	/* Register slot */
-	ret = rpaphp_register_slot(slot);
-	if (ret)
-		goto fail;
+		/* Register slot */
+		ret = rpaphp_register_slot(slot);
+		if (ret)
+			goto fail;
+	}
+
+	for_each_child_of_node(dn, child) {
+		ret = rpaphp_add_slot(child);
+		if (ret)
+			return ret;
+	}
 
 	return 0;
 fail:
@@ -204,18 +244,15 @@ EXPORT_SYMBOL_GPL(rpaphp_add_slot);
 
 static void __exit cleanup_slots(void)
 {
-	struct list_head *tmp, *n;
-	struct rpa_php_slot *slot;
+	struct rpa_php_slot *slot, *tmp;
 
 	/*
 	 * Unregister all of our slots with the pci_hotplug subsystem,
 	 * and free up all memory that we had allocated.
 	 * memory will be freed in release_slot callback.
 	 */
-
-	list_for_each_safe(tmp, n, &rpaphp_slot_head) {
-		slot = list_entry(tmp, struct rpa_php_slot, rpaphp_slot_list);
-		list_del(&slot->rpaphp_slot_list);
+	list_for_each_entry_safe(slot, tmp, &rpaphp_slot_head, link) {
+		list_del(&slot->link);
 		pci_hp_deregister(slot->hotplug_slot);
 	}
 }
-- 
1.8.3.2

^ permalink raw reply related

* [PATCH 1/8] powerpc/pci: Move pcibios_find_pci_bus() around
From: Gavin Shan @ 2014-11-24 22:49 UTC (permalink / raw)
  To: linux-pci; +Cc: linuxppc-dev, Gavin Shan
In-Reply-To: <1416869365-7671-1-git-send-email-gwshan@linux.vnet.ibm.com>

The patch moves pcibios_find_pci_bus() to PPC kerenl directory so
that it can be reused by hotplug code for pSeries and PowerNV
platform at the same time.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 arch/powerpc/kernel/pci-hotplug.c          | 36 ++++++++++++++++++++++++++++++
 arch/powerpc/platforms/pseries/pci_dlpar.c | 32 --------------------------
 2 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/arch/powerpc/kernel/pci-hotplug.c b/arch/powerpc/kernel/pci-hotplug.c
index 5b78917..6e2b4e3 100644
--- a/arch/powerpc/kernel/pci-hotplug.c
+++ b/arch/powerpc/kernel/pci-hotplug.c
@@ -21,6 +21,42 @@
 #include <asm/firmware.h>
 #include <asm/eeh.h>
 
+static struct pci_bus *find_pci_bus(struct pci_bus *bus,
+				    struct device_node *dn)
+{
+	struct pci_bus *tmp, *child = NULL;
+	struct device_node *busdn;
+
+	busdn = pci_bus_to_OF_node(bus);
+	if (busdn == dn)
+		return bus;
+
+	list_for_each_entry(tmp, &bus->children, node) {
+		child = find_pci_bus(tmp, dn);
+		if (child)
+			break;
+	}
+
+	return child;
+}
+
+/**
+ * pcibios_find_pci_bus - find PCI bus according to the given device node
+ * @dn: Device node
+ *
+ * Find the corresponding PCI bus according to the given device node.
+ */
+struct pci_bus *pcibios_find_pci_bus(struct device_node *dn)
+{
+	struct pci_dn *pdn = PCI_DN(dn);
+
+	if (!pdn  || !pdn->phb || !pdn->phb->bus)
+		return NULL;
+
+	return find_pci_bus(pdn->phb->bus, dn);
+}
+EXPORT_SYMBOL_GPL(pcibios_find_pci_bus);
+
 /**
  * pcibios_release_device - release PCI device
  * @dev: PCI device
diff --git a/arch/powerpc/platforms/pseries/pci_dlpar.c b/arch/powerpc/platforms/pseries/pci_dlpar.c
index 89e2381..98c50bc 100644
--- a/arch/powerpc/platforms/pseries/pci_dlpar.c
+++ b/arch/powerpc/platforms/pseries/pci_dlpar.c
@@ -32,38 +32,6 @@
 #include <asm/firmware.h>
 #include <asm/eeh.h>
 
-static struct pci_bus *
-find_bus_among_children(struct pci_bus *bus,
-                        struct device_node *dn)
-{
-	struct pci_bus *child = NULL;
-	struct pci_bus *tmp;
-	struct device_node *busdn;
-
-	busdn = pci_bus_to_OF_node(bus);
-	if (busdn == dn)
-		return bus;
-
-	list_for_each_entry(tmp, &bus->children, node) {
-		child = find_bus_among_children(tmp, dn);
-		if (child)
-			break;
-	};
-	return child;
-}
-
-struct pci_bus *
-pcibios_find_pci_bus(struct device_node *dn)
-{
-	struct pci_dn *pdn = dn->data;
-
-	if (!pdn  || !pdn->phb || !pdn->phb->bus)
-		return NULL;
-
-	return find_bus_among_children(pdn->phb->bus, dn);
-}
-EXPORT_SYMBOL_GPL(pcibios_find_pci_bus);
-
 struct pci_controller *init_phb_dynamic(struct device_node *dn)
 {
 	struct pci_controller *phb;
-- 
1.8.3.2

^ permalink raw reply related

* [PATCH 8/8] PCI/hotplug/rpa: Support OPAL firmware
From: Gavin Shan @ 2014-11-24 22:49 UTC (permalink / raw)
  To: linux-pci; +Cc: linuxppc-dev, Gavin Shan
In-Reply-To: <1416869365-7671-1-git-send-email-gwshan@linux.vnet.ibm.com>

The patch adds support for OPAL firmware. All hotpluggable PCI
slots are recognized by device node property "ibm,slot-pluggable".
The slot name (label) is derived from property "ibm,slot-label".

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 drivers/pci/hotplug/Kconfig       |   4 +-
 drivers/pci/hotplug/Makefile      |   3 +-
 drivers/pci/hotplug/rpaphp.h      |   5 +
 drivers/pci/hotplug/rpaphp_core.c |  12 +-
 drivers/pci/hotplug/rpaphp_opal.c | 241 ++++++++++++++++++++++++++++++++++++++
 drivers/pci/hotplug/rpaphp_rtas.c |  10 ++
 6 files changed, 268 insertions(+), 7 deletions(-)
 create mode 100644 drivers/pci/hotplug/rpaphp_opal.c

diff --git a/drivers/pci/hotplug/Kconfig b/drivers/pci/hotplug/Kconfig
index df8caec..44859e0 100644
--- a/drivers/pci/hotplug/Kconfig
+++ b/drivers/pci/hotplug/Kconfig
@@ -115,7 +115,7 @@ config HOTPLUG_PCI_SHPC
 
 config HOTPLUG_PCI_RPA
 	tristate "RPA PCI Hotplug driver"
-	depends on PPC_PSERIES && EEH
+	depends on (PPC_PSERIES || PPC_POWERNV) && EEH
 	help
 	  Say Y here if you have a RPA system that supports PCI Hotplug.
 
@@ -126,7 +126,7 @@ config HOTPLUG_PCI_RPA
 
 config HOTPLUG_PCI_RPA_DLPAR
 	tristate "RPA Dynamic Logical Partitioning for I/O slots"
-	depends on HOTPLUG_PCI_RPA
+	depends on HOTPLUG_PCI_RPA && PPC_PSERIES
 	help
 	  Say Y here if your system supports Dynamic Logical Partitioning
 	  for I/O slots.
diff --git a/drivers/pci/hotplug/Makefile b/drivers/pci/hotplug/Makefile
index 630313da..c216e40 100644
--- a/drivers/pci/hotplug/Makefile
+++ b/drivers/pci/hotplug/Makefile
@@ -51,7 +51,8 @@ acpiphp-objs		:=	acpiphp_core.o	\
 				acpiphp_glue.o
 
 rpaphp-objs		:=	rpaphp_core.o	\
-				rpaphp_rtas.o
+				rpaphp_rtas.o	\
+				rpaphp_opal.o
 
 rpadlpar_io-objs	:=	rpadlpar_core.o \
 				rpadlpar_sysfs.o
diff --git a/drivers/pci/hotplug/rpaphp.h b/drivers/pci/hotplug/rpaphp.h
index 0354572..e52ff1b 100644
--- a/drivers/pci/hotplug/rpaphp.h
+++ b/drivers/pci/hotplug/rpaphp.h
@@ -86,8 +86,13 @@ int rpaphp_deregister_slot(struct rpa_php_slot *slot);
 int rpaphp_add_slot(struct device_node *dn);
 
 /* rpaphp_rtas.c */
+int rpaphp_rtas_init(void);
 int rpaphp_get_drc_props(struct device_node *dn, int *drc_index,
 			 char **drc_name, char **drc_type, int *drc_power);
 struct rpa_php_slot *rpaphp_rtas_add_slot(struct device_node *dn);
 
+/* rpaphp_opal.c */
+int rpaphp_opal_init(void);
+struct rpa_php_slot *rpaphp_opal_add_slot(struct device_node *dn);
+
 #endif				/* _PPC64PHP_H */
diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c
index ba28212..84daa2a 100644
--- a/drivers/pci/hotplug/rpaphp_core.c
+++ b/drivers/pci/hotplug/rpaphp_core.c
@@ -216,6 +216,8 @@ int rpaphp_add_slot(struct device_node *dn)
 	/* Create slot */
 	if (machine_is(pseries))
 		slot = rpaphp_rtas_add_slot(dn);
+	else if (machine_is(powernv))
+		slot = rpaphp_opal_add_slot(dn);
 
 	if (slot) {
 		/* Enable slot */
@@ -259,14 +261,16 @@ static void __exit cleanup_slots(void)
 
 static int __init rpaphp_init(void)
 {
-	struct device_node *dn;
+	int ret = 0;
 
 	info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
 
-	for_each_node_by_name(dn, "pci")
-		rpaphp_add_slot(dn);
+	if (machine_is(pseries))
+		ret = rpaphp_rtas_init();
+	else if (machine_is(powernv))
+		ret = rpaphp_opal_init();
 
-	return 0;
+	return ret;
 }
 
 static void __exit rpaphp_exit(void)
diff --git a/drivers/pci/hotplug/rpaphp_opal.c b/drivers/pci/hotplug/rpaphp_opal.c
new file mode 100644
index 0000000..1040767
--- /dev/null
+++ b/drivers/pci/hotplug/rpaphp_opal.c
@@ -0,0 +1,241 @@
+/*
+ * OPAL backend for RPA-compliant PP64 platform.
+ *
+ * Copyright Gavin Shan, IBM Corporation 2014
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/device.h>
+#include <linux/of.h>
+#include <linux/pci.h>
+#include <linux/pci_hotplug.h>
+#include <linux/smp.h>
+#include <linux/init.h>
+#include <linux/vmalloc.h>
+#include <asm/eeh.h>
+#include <asm/pci-bridge.h>
+#include <asm/opal.h>
+#include <asm/pnv-pci.h>
+
+#include "../pci.h"
+#include "rpaphp.h"
+
+#ifdef CONFIG_PPC_POWERNV
+static int get_power_status(struct hotplug_slot *hp_slot, u8 *val)
+{
+	struct rpa_php_slot *slot = hp_slot->private;
+	int ret;
+	uint8_t state;
+
+	/* By default, the power is on */
+	*val = RPA_PHP_SLOT_POWER_ON;
+
+	/* Retrieve power state from firmware, which might fail */
+	ret = pnv_pci_get_power_status(slot->index, &state);
+	if (!ret) {
+		if (state > 0)
+			hp_slot->info->power_status = RPA_PHP_SLOT_POWER_ON;
+		else
+			hp_slot->info->power_status = RPA_PHP_SLOT_POWER_OFF;
+		*val = hp_slot->info->power_status;
+	}
+
+	return 0;
+}
+
+static int get_adapter_status(struct hotplug_slot *hp_slot, u8 *val)
+{
+	struct rpa_php_slot *slot = hp_slot->private;
+	uint8_t state;
+	int ret;
+
+	/* By default, the slot is empty */
+	*val = RPA_PHP_SLOT_EMPTY;
+
+	/* Retrieve presence state from firmware */
+	ret = pnv_pci_get_presence_status(slot->index, &state);
+	if (ret >= 0) {
+		if (state > 0)
+			hp_slot->info->adapter_status = RPA_PHP_SLOT_PRESENT;
+		else
+			hp_slot->info->adapter_status = RPA_PHP_SLOT_EMPTY;
+		*val = hp_slot->info->adapter_status;
+	}
+
+	return 0;
+}
+#else
+static int get_power_status(struct hotplug_slot *hp_slot, u8 *val)
+{
+	*val = RPA_PHP_SLOT_POWER_ON;
+
+	return 0;
+}
+
+static int get_adapter_status(struct hotplug_slot *hp_slot, u8 *val)
+{
+	*val = RPA_PHP_SLOT_EMPTY;
+
+	return 0;
+}
+#endif /* CONFIG_PPC_POWERNV */
+
+static int set_attention_status(struct hotplug_slot *hp_slot, u8 val)
+{
+	/*
+	 * The default operation would to turn on
+	 * the attention
+	 */
+	switch (val) {
+	case RPA_PHP_SLOT_ATTEN_OFF:
+	case RPA_PHP_SLOT_ATTEN_ON:
+	case RPA_PHP_SLOT_ATTEN_IND:
+	case RPA_PHP_SLOT_ATTEN_ACT:
+		break;
+	default:
+		val = RPA_PHP_SLOT_ATTEN_ON;
+	}
+
+	/* FIXME: Set it through firmware interface */
+	hp_slot->info->attention_status = val;
+
+	return 0;
+}
+
+static int enable_slot(struct hotplug_slot *hp_slot)
+{
+	struct rpa_php_slot *slot = hp_slot->private;
+	uint8_t presence;
+	int ret;
+
+	/* Check if the slot has been configured */
+	if (slot->state == RPA_PHP_SLOT_CONFIGURED)
+		return 0;
+
+	/* Retrieve slot presence status */
+	ret = hp_slot->ops->get_adapter_status(hp_slot, &presence);
+	if (ret)
+		return ret;
+
+	switch (presence) {
+	case RPA_PHP_SLOT_PRESENT:
+		pci_lock_rescan_remove();
+		pcibios_add_pci_devices(slot->bus);
+		pci_unlock_rescan_remove();
+		slot->state = RPA_PHP_SLOT_CONFIGURED;
+		break;
+	case RPA_PHP_SLOT_EMPTY:
+		slot->state = RPA_PHP_SLOT_NOT_CONFIGURED;
+		break;
+	default:
+		slot->state = RPA_PHP_SLOT_NOT_VALID;
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int disable_slot(struct hotplug_slot *hp_slot)
+{
+	struct rpa_php_slot *slot = hp_slot->private;
+
+	if (slot->state != RPA_PHP_SLOT_CONFIGURED)
+		return 0;
+
+	pci_lock_rescan_remove();
+	pcibios_remove_pci_devices(slot->bus);
+	pci_unlock_rescan_remove();
+	vm_unmap_aliases();
+
+	slot->state = RPA_PHP_SLOT_NOT_CONFIGURED;
+	return 0;
+}
+
+static struct hotplug_slot_ops rpaphp_opal_ops = {
+	.get_power_status	= get_power_status,
+	.get_adapter_status	= get_adapter_status,
+	.set_attention_status	= set_attention_status,
+	.enable_slot		= enable_slot,
+	.disable_slot		= disable_slot,
+};
+
+struct rpa_php_slot *rpaphp_opal_add_slot(struct device_node *dn)
+{
+	struct device_node *parent;
+	struct pci_bus *bus;
+	struct rpa_php_slot *slot;
+	const char *label;
+	uint64_t opal_id;
+	int hotplug, index, ret;
+
+	/* Not PCI device node ? */
+	if (!dn || !PCI_DN(dn))
+		return NULL;
+
+	/* Hotpluggable slot ? */
+	ret = of_property_read_u32(dn, "ibm,slot-pluggable", &hotplug);
+	if (ret || !hotplug)
+		return NULL;
+
+	/* Slot name missed ? */
+	ret = of_property_read_string(dn, "ibm,slot-label", &label);
+	if (ret)
+		return NULL;
+
+	/*
+	 * Check binding bus. The root port isn't hotpluggable always.
+	 * So we needn't consider root bus
+	 */
+	bus = pcibios_find_pci_bus(dn);
+	if (!bus && pci_is_root_bus(bus))
+		return NULL;
+
+	/* Retrieve PHB OPAL ID */
+	parent = of_node_get(dn);
+	while (parent) {
+		ret = of_property_read_u64(parent, "ibm,opal-phbid", &opal_id);
+		if (!ret) {
+			of_node_put(parent);
+			break;
+		}
+
+		of_node_put(parent);
+		parent = of_get_parent(parent);
+	}
+
+	/*
+	 * Allocate slot. We always have non-compound case as the root
+	 * port isn't hotpluggable always.
+	 */
+	index = (u32)(opal_id);
+	index = (index << 16) | (bus->number << 8) | bus->self->devfn;
+	slot = alloc_slot_struct(dn, index, (char *)label, -1);
+	if (!slot)
+		return NULL;
+
+	slot->type	= 0;
+	slot->bus	= bus;
+	slot->pci_devs	= &bus->devices;
+	slot->hotplug_slot->ops = &rpaphp_opal_ops;
+
+	return slot;
+}
+
+int rpaphp_opal_init(void)
+{
+	struct device_node *dn;
+
+	for_each_compatible_node(dn, "pciex", "ibm,ioda2-phb")
+		rpaphp_add_slot(dn);
+	for_each_compatible_node(dn, "pciex", "ibm,ioda-phb")
+		rpaphp_add_slot(dn);
+
+	return 0;
+}
diff --git a/drivers/pci/hotplug/rpaphp_rtas.c b/drivers/pci/hotplug/rpaphp_rtas.c
index 74f024a..86b1d4093 100644
--- a/drivers/pci/hotplug/rpaphp_rtas.c
+++ b/drivers/pci/hotplug/rpaphp_rtas.c
@@ -318,3 +318,13 @@ fail:
 	dealloc_slot_struct(slot);
 	return NULL;
 }
+
+int rpaphp_rtas_init(void)
+{
+	struct device_node *dn;
+
+	for_each_node_by_name(dn, "pci")
+		rpaphp_add_slot(dn);
+
+	return 0;
+}
-- 
1.8.3.2

^ permalink raw reply related

* [PATCH 2/8] powerpc/pci: Don't scan empty slot
From: Gavin Shan @ 2014-11-24 22:49 UTC (permalink / raw)
  To: linux-pci; +Cc: linuxppc-dev, Gavin Shan
In-Reply-To: <1416869365-7671-1-git-send-email-gwshan@linux.vnet.ibm.com>

In hotplug case, function pcibios_add_pci_devices() is called to
rescan the specified PCI bus, which possibly doesn't have any child
devices. Access to the PCI bus's child device node will cause kernel
crash without exception. The patch adds two more conditions to avoid
the kernel crash.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 arch/powerpc/kernel/pci-hotplug.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/pci-hotplug.c b/arch/powerpc/kernel/pci-hotplug.c
index 6e2b4e3..ea5513b 100644
--- a/arch/powerpc/kernel/pci-hotplug.c
+++ b/arch/powerpc/kernel/pci-hotplug.c
@@ -105,7 +105,7 @@ EXPORT_SYMBOL_GPL(pcibios_remove_pci_devices);
  * is how this routine differs from other, similar pcibios
  * routines.)
  */
-void pcibios_add_pci_devices(struct pci_bus * bus)
+void pcibios_add_pci_devices(struct pci_bus *bus)
 {
 	int slotno, mode, pass, max;
 	struct pci_dev *dev;
@@ -120,7 +120,8 @@ void pcibios_add_pci_devices(struct pci_bus * bus)
 	if (mode == PCI_PROBE_DEVTREE) {
 		/* use ofdt-based probe */
 		of_rescan_bus(dn, bus);
-	} else if (mode == PCI_PROBE_NORMAL) {
+	} else if (mode == PCI_PROBE_NORMAL &&
+		   dn->child && PCI_DN(dn->child)) {
 		/*
 		 * Use legacy probe. In the partial hotplug case, we
 		 * probably have grandchildren devices unplugged. So
-- 
1.8.3.2

^ permalink raw reply related

* [PATCH 4/8] PCI/hotplug/rpa: Code cleanup
From: Gavin Shan @ 2014-11-24 22:49 UTC (permalink / raw)
  To: linux-pci; +Cc: linuxppc-dev, Gavin Shan
In-Reply-To: <1416869365-7671-1-git-send-email-gwshan@linux.vnet.ibm.com>

The patch applies code cleanup to RPA modules to address following
issues and it shouldn't affect the logic:

   * Coding style issue: removed unnecessary "break" for default case
     in switch statement and added default case; removed unnecessary
     braces or parenthese for if or return statements; removed
     unecessary return statements
   * Refactor rpaphp_get_sensor_state() and find_php_slot_pci_node()
     to avoid nested if statements
   * Drop is_registered(), is_php_type(), is_dlpar_capable()

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 drivers/pci/hotplug/rpadlpar_core.c | 90 +++++++++++++++++++------------------
 drivers/pci/hotplug/rpaphp_core.c   | 57 ++++++++++-------------
 drivers/pci/hotplug/rpaphp_pci.c    | 43 +++++++++---------
 drivers/pci/hotplug/rpaphp_slot.c   | 25 ++++-------
 4 files changed, 101 insertions(+), 114 deletions(-)

diff --git a/drivers/pci/hotplug/rpadlpar_core.c b/drivers/pci/hotplug/rpadlpar_core.c
index 7660232..35da3b3 100644
--- a/drivers/pci/hotplug/rpadlpar_core.c
+++ b/drivers/pci/hotplug/rpadlpar_core.c
@@ -52,30 +52,35 @@ static struct device_node *find_vio_slot_node(char *drc_name)
 
 	while ((dn = of_get_next_child(parent, dn))) {
 		rc = rpaphp_get_drc_props(dn, NULL, &name, NULL, NULL);
-		if ((rc == 0) && (!strcmp(drc_name, name)))
-			break;
+		if (rc)
+			continue;
+
+		if (!strcmp(drc_name, name))
+			return dn;
 	}
 
-	return dn;
+	return NULL;
 }
 
 /* Find dlpar-capable pci node that contains the specified name and type */
 static struct device_node *find_php_slot_pci_node(char *drc_name,
 						  char *drc_type)
 {
-	struct device_node *np = NULL;
+	struct device_node *dn = NULL;
 	char *name;
 	char *type;
 	int rc;
 
-	while ((np = of_find_node_by_name(np, "pci"))) {
-		rc = rpaphp_get_drc_props(np, NULL, &name, &type, NULL);
-		if (rc == 0)
-			if (!strcmp(drc_name, name) && !strcmp(drc_type, type))
-				break;
+	while ((dn = of_find_node_by_name(dn, "pci"))) {
+		rc = rpaphp_get_drc_props(dn, NULL, &name, &type, NULL);
+		if (rc)
+			continue;
+
+		if (!strcmp(drc_name, name) && !strcmp(drc_type, type))
+			return dn;
 	}
 
-	return np;
+	return NULL;
 }
 
 static struct device_node *find_dlpar_node(char *drc_name, int *node_type)
@@ -239,10 +244,9 @@ static int dlpar_add_phb(char *drc_name, struct device_node *dn)
 {
 	struct pci_controller *phb;
 
-	if (PCI_DN(dn) && PCI_DN(dn)->phb) {
-		/* PHB already exists */
+	/* PHB already exists */
+	if (PCI_DN(dn) && PCI_DN(dn)->phb)
 		return -EINVAL;
-	}
 
 	phb = init_phb_dynamic(dn);
 	if (!phb)
@@ -299,15 +303,18 @@ int dlpar_add_slot(char *drc_name)
 	}
 
 	switch (node_type) {
-		case NODE_TYPE_VIO:
-			rc = dlpar_add_vio_slot(drc_name, dn);
-			break;
-		case NODE_TYPE_SLOT:
-			rc = dlpar_add_pci_slot(drc_name, dn);
-			break;
-		case NODE_TYPE_PHB:
-			rc = dlpar_add_phb(drc_name, dn);
-			break;
+	case NODE_TYPE_VIO:
+		rc = dlpar_add_vio_slot(drc_name, dn);
+		break;
+	case NODE_TYPE_SLOT:
+		rc = dlpar_add_pci_slot(drc_name, dn);
+		break;
+	case NODE_TYPE_PHB:
+		rc = dlpar_add_phb(drc_name, dn);
+		break;
+	default:
+		rc = -EINVAL;
+		goto exit;
 	}
 
 	printk(KERN_INFO "%s: slot %s added\n", DLPAR_MODULE_NAME, drc_name);
@@ -429,15 +436,18 @@ int dlpar_remove_slot(char *drc_name)
 	}
 
 	switch (node_type) {
-		case NODE_TYPE_VIO:
-			rc = dlpar_remove_vio_slot(drc_name, dn);
-			break;
-		case NODE_TYPE_PHB:
-			rc = dlpar_remove_phb(drc_name, dn);
-			break;
-		case NODE_TYPE_SLOT:
-			rc = dlpar_remove_pci_slot(drc_name, dn);
-			break;
+	case NODE_TYPE_VIO:
+		rc = dlpar_remove_vio_slot(drc_name, dn);
+		break;
+	case NODE_TYPE_PHB:
+		rc = dlpar_remove_phb(drc_name, dn);
+		break;
+	case NODE_TYPE_SLOT:
+		rc = dlpar_remove_pci_slot(drc_name, dn);
+		break;
+	default:
+		rc = -EINVAL;
+		goto exit;
 	}
 	vm_unmap_aliases();
 
@@ -447,20 +457,15 @@ exit:
 	return rc;
 }
 
-static inline int is_dlpar_capable(void)
-{
-	int rc = rtas_token("ibm,configure-connector");
-
-	return (int) (rc != RTAS_UNKNOWN_SERVICE);
-}
-
-int __init rpadlpar_io_init(void)
+static int __init rpadlpar_io_init(void)
 {
 	int rc = 0;
 
-	if (!is_dlpar_capable()) {
+	/* Check if we have DLPAR capability */
+	rc = rtas_token("ibm,configure-connector");
+	if (rc == RTAS_UNKNOWN_SERVICE) {
 		printk(KERN_WARNING "%s: partition not DLPAR capable\n",
-			__func__);
+		       __func__);
 		return -EPERM;
 	}
 
@@ -468,10 +473,9 @@ int __init rpadlpar_io_init(void)
 	return rc;
 }
 
-void rpadlpar_io_exit(void)
+static void __exit rpadlpar_io_exit(void)
 {
 	dlpar_sysfs_exit();
-	return;
 }
 
 module_init(rpadlpar_io_init);
diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c
index f2945fa..ff800df 100644
--- a/drivers/pci/hotplug/rpaphp_core.c
+++ b/drivers/pci/hotplug/rpaphp_core.c
@@ -74,7 +74,6 @@ static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 value)
 		break;
 	default:
 		value = 1;
-		break;
 	}
 
 	rc = rtas_set_indicator(DR_INDICATOR, slot->index, value);
@@ -94,7 +93,7 @@ static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
 	int retval, level;
 	struct slot *slot = (struct slot *)hotplug_slot->private;
 
-	retval = rtas_get_power_level (slot->power_domain, &level);
+	retval = rtas_get_power_level(slot->power_domain, &level);
 	if (!retval)
 		*value = level;
 	return retval;
@@ -161,7 +160,6 @@ static enum pci_bus_speed get_max_bus_speed(struct slot *slot)
 		break;
 	default:
 		speed = PCI_SPEED_UNKNOWN;
-		break;
 	}
 
 	return speed;
@@ -178,17 +176,17 @@ static int get_children_props(struct device_node *dn, const int **drc_indexes,
 	types = of_get_property(dn, "ibm,drc-types", NULL);
 	domains = of_get_property(dn, "ibm,drc-power-domains", NULL);
 
-	if (!indexes || !names || !types || !domains) {
-		/* Slot does not have dynamically-removable children */
+	/* Slot does not have dynamically-removable children */
+	if (!indexes || !names || !types || !domains)
 		return -EINVAL;
-	}
+
 	if (drc_indexes)
 		*drc_indexes = indexes;
+	/* &drc_names[1] contains NULL terminated slot names */
 	if (drc_names)
-		/* &drc_names[1] contains NULL terminated slot names */
 		*drc_names = names;
+	/* &drc_types[1] contains NULL terminated slot types */
 	if (drc_types)
-		/* &drc_types[1] contains NULL terminated slot types */
 		*drc_types = types;
 	if (drc_power_domains)
 		*drc_power_domains = domains;
@@ -210,15 +208,13 @@ int rpaphp_get_drc_props(struct device_node *dn, int *drc_index,
 	int i, rc;
 
 	my_index = of_get_property(dn, "ibm,my-drc-index", NULL);
-	if (!my_index) {
-		/* Node isn't DLPAR/hotplug capable */
+	/* Node isn't DLPAR/hotplug capable */
+	if (!my_index)
 		return -EINVAL;
-	}
 
 	rc = get_children_props(dn->parent, &indexes, &names, &types, &domains);
-	if (rc < 0) {
+	if (rc < 0)
 		return -EINVAL;
-	}
 
 	name_tmp = (char *) &names[1];
 	type_tmp = (char *) &types[1];
@@ -244,21 +240,8 @@ int rpaphp_get_drc_props(struct device_node *dn, int *drc_index,
 }
 EXPORT_SYMBOL_GPL(rpaphp_get_drc_props);
 
-static int is_php_type(char *drc_type)
-{
-	unsigned long value;
-	char *endptr;
-
-	/* PCI Hotplug nodes have an integer for drc_type */
-	value = simple_strtoul(drc_type, &endptr, 10);
-	if (endptr == drc_type)
-		return 0;
-
-	return 1;
-}
-
 /**
- * is_php_dn() - return 1 if this is a hotpluggable pci slot, else 0
+ * is_php_dn() - return true if this is a hotpluggable pci slot, else false
  * @dn: target &device_node
  * @indexes: passed to get_children_props()
  * @names: passed to get_children_props()
@@ -270,21 +253,28 @@ static int is_php_type(char *drc_type)
  * for built-in pci slots (even when the built-in slots are
  * dlparable.)
  */
-static int is_php_dn(struct device_node *dn, const int **indexes,
-		const int **names, const int **types, const int **power_domains)
+static bool is_php_dn(struct device_node *dn,
+		      const int **indexes, const int **names,
+		      const int **types, const int **power_domains)
 {
 	const int *drc_types;
+	const char *drc_type_str;
+	char *endptr;
+	unsigned long val;
 	int rc;
 
 	rc = get_children_props(dn, indexes, names, &drc_types, power_domains);
 	if (rc < 0)
-		return 0;
+		return false;
 
-	if (!is_php_type((char *) &drc_types[1]))
-		return 0;
+	/* PCI Hotplug nodes have an integer for drc_type */
+	drc_type_str = (char *)&drc_types[1];
+	val = simple_strtoul(drc_type_str, &endptr, 10);
+	if (endptr == drc_type_str)
+		return false;
 
 	*types = drc_types;
-	return 1;
+	return true;
 }
 
 /**
@@ -370,7 +360,6 @@ static void __exit cleanup_slots(void)
 		list_del(&slot->rpaphp_slot_list);
 		pci_hp_deregister(slot->hotplug_slot);
 	}
-	return;
 }
 
 static int __init rpaphp_init(void)
diff --git a/drivers/pci/hotplug/rpaphp_pci.c b/drivers/pci/hotplug/rpaphp_pci.c
index 9243f3e7..a4aa65c 100644
--- a/drivers/pci/hotplug/rpaphp_pci.c
+++ b/drivers/pci/hotplug/rpaphp_pci.c
@@ -38,30 +38,31 @@ int rpaphp_get_sensor_state(struct slot *slot, int *state)
 	int setlevel;
 
 	rc = rtas_get_sensor(DR_ENTITY_SENSE, slot->index, state);
+	if (rc >= 0)
+		return rc;
+	if (rc != -EFAULT && rc != -EEXIST) {
+		err("%s: Failure %d getting sensor state on slot[%s]\n",
+		    __func__, rc, slot->name);
+		return rc;
+	}
 
+
+	/*
+	 * Some slots have to be powered up before
+	 * get-sensor will succeed
+	 */
+	dbg("%s: Slot[%s] must be power up to get sensor-state\n",
+	    __func__, slot->name);
+	rc = rtas_set_power_level(slot->power_domain, POWER_ON,
+				  &setlevel);
 	if (rc < 0) {
-		if (rc == -EFAULT || rc == -EEXIST) {
-			dbg("%s: slot must be power up to get sensor-state\n",
-			    __func__);
-
-			/* some slots have to be powered up
-			 * before get-sensor will succeed.
-			 */
-			rc = rtas_set_power_level(slot->power_domain, POWER_ON,
-						  &setlevel);
-			if (rc < 0) {
-				dbg("%s: power on slot[%s] failed rc=%d.\n",
-				    __func__, slot->name, rc);
-			} else {
-				rc = rtas_get_sensor(DR_ENTITY_SENSE,
-						     slot->index, state);
-			}
-		} else if (rc == -ENODEV)
-			info("%s: slot is unusable\n", __func__);
-		else
-			err("%s failed to get sensor state\n", __func__);
+		dbg("%s: Failure %d powerng on slot[%s]\n",
+		    __func__, rc, slot->name);
+		return rc;
 	}
-	return rc;
+
+	return rtas_get_sensor(DR_ENTITY_SENSE,
+			       slot->index, state);
 }
 
 /**
diff --git a/drivers/pci/hotplug/rpaphp_slot.c b/drivers/pci/hotplug/rpaphp_slot.c
index a6082cc..be48e69 100644
--- a/drivers/pci/hotplug/rpaphp_slot.c
+++ b/drivers/pci/hotplug/rpaphp_slot.c
@@ -72,7 +72,7 @@ struct slot *alloc_slot_struct(struct device_node *dn,
 	slot->hotplug_slot->ops = &rpaphp_hotplug_slot_ops;
 	slot->hotplug_slot->release = &rpaphp_release_slot;
 
-	return (slot);
+	return slot;
 
 error_info:
 	kfree(slot->hotplug_slot->info);
@@ -84,17 +84,6 @@ error_nomem:
 	return NULL;
 }
 
-static int is_registered(struct slot *slot)
-{
-	struct slot *tmp_slot;
-
-	list_for_each_entry(tmp_slot, &rpaphp_slot_head, rpaphp_slot_list) {
-		if (!strcmp(tmp_slot->name, slot->name))
-			return 1;
-	}
-	return 0;
-}
-
 int rpaphp_deregister_slot(struct slot *slot)
 {
 	int retval = 0;
@@ -117,6 +106,7 @@ EXPORT_SYMBOL_GPL(rpaphp_deregister_slot);
 int rpaphp_register_slot(struct slot *slot)
 {
 	struct hotplug_slot *php_slot = slot->hotplug_slot;
+	struct slot *tmp;
 	int retval;
 	int slotno;
 
@@ -124,10 +114,13 @@ int rpaphp_register_slot(struct slot *slot)
 		__func__, slot->dn->full_name, slot->index, slot->name,
 		slot->power_domain, slot->type);
 
-	/* should not try to register the same slot twice */
-	if (is_registered(slot)) {
-		err("rpaphp_register_slot: slot[%s] is already registered\n", slot->name);
-		return -EAGAIN;
+	/* Should not try to register the same slot twice */
+	list_for_each_entry(tmp, &rpaphp_slot_head, rpaphp_slot_list) {
+		if (!strcmp(tmp->name, slot->name)) {
+			err("%s: Slot[%s] is already registered\n",
+			    __func__, slot->name);
+			return -EAGAIN;
+		}
 	}
 
 	if (slot->dn->child)
-- 
1.8.3.2

^ permalink raw reply related

* [PATCH 3/8] powerpc/powernv: Export functions to retrieve slot status
From: Gavin Shan @ 2014-11-24 22:49 UTC (permalink / raw)
  To: linux-pci; +Cc: linuxppc-dev, Gavin Shan
In-Reply-To: <1416869365-7671-1-git-send-email-gwshan@linux.vnet.ibm.com>

The patch exports two functions, which base on corresponding OPAL
APIs to retrieve PCI slot status:

   pnv_pci_get_power_status()     opal_pci_get_power_status()
   pnv_pci_get_presence_status()  opal_pci_get_presence_status()

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 arch/powerpc/include/asm/opal.h                |  6 +++-
 arch/powerpc/include/asm/pnv-pci.h             |  3 ++
 arch/powerpc/platforms/powernv/eeh-ioda.c      | 34 ++---------------------
 arch/powerpc/platforms/powernv/opal-wrappers.S |  2 ++
 arch/powerpc/platforms/powernv/pci.c           | 38 ++++++++++++++++++++++++++
 arch/powerpc/platforms/powernv/pci.h           |  1 +
 6 files changed, 51 insertions(+), 33 deletions(-)

diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index b59811f..b75be1c 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -153,6 +153,8 @@ struct opal_sg_list {
 #define OPAL_HANDLE_HMI				98
 #define OPAL_REGISTER_DUMP_REGION		101
 #define OPAL_UNREGISTER_DUMP_REGION		102
+#define OPAL_PCI_GET_POWER_STATUS		110
+#define OPAL_PCI_GET_PRESENCE_STATUS		111
 
 #ifndef __ASSEMBLY__
 
@@ -905,7 +907,7 @@ int64_t opal_get_epow_status(__be64 *status);
 int64_t opal_set_system_attention_led(uint8_t led_action);
 int64_t opal_pci_next_error(uint64_t phb_id, __be64 *first_frozen_pe,
 			    __be16 *pci_error_type, __be16 *severity);
-int64_t opal_pci_poll(uint64_t id);
+int64_t opal_pci_poll(uint64_t id, uint8_t *val);
 int64_t opal_return_cpu(void);
 int64_t opal_check_token(uint64_t token);
 int64_t opal_reinit_cpus(uint64_t flags);
@@ -946,6 +948,8 @@ int64_t opal_handle_hmi(void);
 int64_t opal_register_dump_region(uint32_t id, uint64_t start, uint64_t end);
 int64_t opal_unregister_dump_region(uint32_t id);
 int64_t opal_pci_set_phb_cxl_mode(uint64_t phb_id, uint64_t mode, uint64_t pe_number);
+int64_t opal_pci_get_power_status(uint64_t id, uint8_t *status);
+int64_t opal_pci_get_presence_status(uint64_t id, uint8_t *status);
 
 /* Internal functions */
 extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
diff --git a/arch/powerpc/include/asm/pnv-pci.h b/arch/powerpc/include/asm/pnv-pci.h
index f09a22f..527d97a 100644
--- a/arch/powerpc/include/asm/pnv-pci.h
+++ b/arch/powerpc/include/asm/pnv-pci.h
@@ -13,6 +13,9 @@
 #include <linux/pci.h>
 #include <misc/cxl.h>
 
+extern int pnv_pci_get_power_status(unsigned int index, unsigned char *status);
+extern int pnv_pci_get_presence_status(unsigned int index, unsigned char *status);
+
 int pnv_phb_to_cxl(struct pci_dev *dev);
 int pnv_cxl_ioda_msi_setup(struct pci_dev *dev, unsigned int hwirq,
 			   unsigned int virq);
diff --git a/arch/powerpc/platforms/powernv/eeh-ioda.c b/arch/powerpc/platforms/powernv/eeh-ioda.c
index 4bf2fb5..fb66c74 100644
--- a/arch/powerpc/platforms/powernv/eeh-ioda.c
+++ b/arch/powerpc/platforms/powernv/eeh-ioda.c
@@ -490,24 +490,6 @@ static int ioda_eeh_get_state(struct eeh_pe *pe)
 	return ioda_eeh_get_pe_state(pe);
 }
 
-static s64 ioda_eeh_phb_poll(uint64_t id)
-{
-	s64 rc = OPAL_HARDWARE;
-
-	while (1) {
-		rc = opal_pci_poll(id);
-		if (rc <= 0)
-			break;
-
-		if (system_state < SYSTEM_RUNNING)
-			udelay(1000 * rc);
-		else
-			msleep(rc);
-	}
-
-	return rc;
-}
-
 int ioda_eeh_phb_reset(struct pci_controller *hose, int option)
 {
 	struct pnv_phb *phb = hose->private_data;
@@ -542,13 +524,7 @@ int ioda_eeh_phb_reset(struct pci_controller *hose, int option)
 	 * need the PCI bus settlement delay.
 	 */
 	rc = opal_pci_reset(phb->opal_id, reset_scope);
-	if (rc > 0)
-		rc = ioda_eeh_phb_poll(phb->opal_id);
-
-	if (rc != OPAL_SUCCESS)
-		return -EIO;
-
-	return 0;
+	return pnv_pci_poll(phb->opal_id, rc, NULL);
 }
 
 static int __ioda_eeh_bridge_reset(struct pci_dev *dev, int option)
@@ -641,13 +617,7 @@ static int ioda_eeh_bridge_reset(struct pci_dev *dev, int option)
 	phb = hose->private_data;
 	id |= ((phb->opal_id << 16) | (dev->bus->number << 8) | (dev->devfn));
 	rc = opal_pci_reset(id, reset_scope);
-	if (rc > 0)
-		rc = ioda_eeh_phb_poll(id);
-
-	if (rc != OPAL_SUCCESS)
-		return -EIO;
-
-	return 0;
+	return pnv_pci_poll(id, rc, NULL);
 }
 
 static int pnv_pci_dev_reset_type(struct pci_dev *pdev, void *data)
diff --git a/arch/powerpc/platforms/powernv/opal-wrappers.S b/arch/powerpc/platforms/powernv/opal-wrappers.S
index b6474a1..b2c15ff 100644
--- a/arch/powerpc/platforms/powernv/opal-wrappers.S
+++ b/arch/powerpc/platforms/powernv/opal-wrappers.S
@@ -249,3 +249,5 @@ OPAL_CALL(opal_handle_hmi,			OPAL_HANDLE_HMI);
 OPAL_CALL(opal_register_dump_region,		OPAL_REGISTER_DUMP_REGION);
 OPAL_CALL(opal_unregister_dump_region,		OPAL_UNREGISTER_DUMP_REGION);
 OPAL_CALL(opal_pci_set_phb_cxl_mode,		OPAL_PCI_SET_PHB_CXL_MODE);
+OPAL_CALL(opal_pci_get_power_status,		OPAL_PCI_GET_POWER_STATUS);
+OPAL_CALL(opal_pci_get_presence_status,		OPAL_PCI_GET_PRESENCE_STATUS);
diff --git a/arch/powerpc/platforms/powernv/pci.c b/arch/powerpc/platforms/powernv/pci.c
index b2187d0..f5bae4f 100644
--- a/arch/powerpc/platforms/powernv/pci.c
+++ b/arch/powerpc/platforms/powernv/pci.c
@@ -45,6 +45,44 @@
 #define cfg_dbg(fmt...)	do { } while(0)
 //#define cfg_dbg(fmt...)	printk(fmt)
 
+int pnv_pci_poll(uint64_t id, int64_t rval, uint8_t *pval)
+{
+	while (rval > 0) {
+		rval = opal_pci_poll(id, pval);
+		if (rval <= 0)
+			break;
+
+		if (system_state < SYSTEM_RUNNING)
+			udelay(1000 * rval);
+		else
+			msleep(rval);
+	}
+
+	return rval ? -EIO : 0;
+}
+
+int pnv_pci_get_power_status(unsigned int index, unsigned char *status)
+{
+	uint64_t id = (0x1ul << 63);
+	long rc;
+
+	id |= index;
+	rc = opal_pci_get_power_status(id, status);
+	return pnv_pci_poll(id, rc, status);
+}
+EXPORT_SYMBOL_GPL(pnv_pci_get_power_status);
+
+int pnv_pci_get_presence_status(unsigned int index, unsigned char *status)
+{
+	uint64_t id = (0x1ul << 63);
+	long rc;
+
+	id |= index;
+	rc = opal_pci_get_presence_status(id, status);
+	return pnv_pci_poll(id, rc, status);
+}
+EXPORT_SYMBOL_GPL(pnv_pci_get_presence_status);
+
 #ifdef CONFIG_PCI_MSI
 static int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
 {
diff --git a/arch/powerpc/platforms/powernv/pci.h b/arch/powerpc/platforms/powernv/pci.h
index 6c02ff8..396fe02 100644
--- a/arch/powerpc/platforms/powernv/pci.h
+++ b/arch/powerpc/platforms/powernv/pci.h
@@ -217,6 +217,7 @@ extern struct pci_ops pnv_pci_ops;
 extern struct pnv_eeh_ops ioda_eeh_ops;
 #endif
 
+int pnv_pci_poll(uint64_t id, int64_t rval, uint8_t *pval);
 void pnv_pci_dump_phb_diag_data(struct pci_controller *hose,
 				unsigned char *log_buff);
 int pnv_pci_cfg_read(struct device_node *dn,
-- 
1.8.3.2

^ permalink raw reply related

* [PATCH RFCv1 0/8] PCI: Slot Support PowerPC PowerNV Platform
From: Gavin Shan @ 2014-11-24 22:49 UTC (permalink / raw)
  To: linux-pci; +Cc: linuxppc-dev, Gavin Shan

The series of patches depends on the OPAL firmware changes. Please
don't consider merging it before the OPAL firmware changes get merged!

The series of patches intends to support PCI slots for OPAL firmware
based PPC PowerNV platform. The OPAL firmware exports the capabilities
to check various statuses (e.g. Power, Presence) on the specified PCI
slot via so-called runtime OPAL APIs. Apart from that, the patchset
cleans up the coding style of RPA modules and fixes PCI slots lost
on PPC pSeries platform.

PATCH[1-3]: Necessary code changes to PPC PCI subsystem in order to
            support PCI slots for PPC PowerNV platform.
PATCH[4]  : Coding style cleanup for RPA modules.
PATCH[5]  : Fix the issue that PCI slots are missed on pSeries platform
PATCH[6-8]: PCI slots support for PPC PowerNV platform

Testing
=======
With the series of patches applied, PCI slots apears from sysfs and
hotplug can be completed accordingly on PowerPC PowerNV platform.

# cat /proc/cpuinfo | grep -i powernv
platform	: PowerNV
machine		: PowerNV 8286-41A

# pwd
/sys/bus/pci/slots
# ls
C10  C11  C12  C14  C15  C6  C7  C8  C9

# lspci -s 0003::.
0003:00:00.0 PCI bridge: IBM Device 03dc
0003:01:00.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:02:01.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:02:08.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:02:09.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:02:10.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:02:11.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:03:00.0 USB controller: Texas Instruments TUSB73x0 SuperSpeed USB 3.0 xHCI Host Controller (rev 02)
0003:09:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01)
0003:09:00.1 Ethernet controller: Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01)
0003:09:00.2 Ethernet controller: Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01)
0003:09:00.3 Ethernet controller: Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01)
0003:0f:00.0 Network controller: Mellanox Technologies MT27500 Family [ConnectX-3]
# pwd
/sys/bus/pci/slots/C10
# cat address 
0003:09:00
# cat address 
0003:09:00
# cat cur_bus_speed 
5.0 GT/s PCIe
# cat max_bus_speed 
8.0 GT/s PCIe
# cat power 
1
# echo 0 > power 
# lspci -s 0003::.
0003:00:00.0 PCI bridge: IBM Device 03dc
0003:01:00.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:02:01.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:02:08.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:02:09.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:02:10.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:02:11.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:03:00.0 USB controller: Texas Instruments TUSB73x0 SuperSpeed USB 3.0 xHCI Host Controller (rev 02)
0003:0f:00.0 Network controller: Mellanox Technologies MT27500 Family [ConnectX-3]
# echo 1 > power
# lspci -s 0003::.
0003:00:00.0 PCI bridge: IBM Device 03dc
0003:01:00.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:02:01.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:02:08.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:02:09.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:02:10.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:02:11.0 PCI bridge: PLX Technology, Inc. Device 8748 (rev ca)
0003:03:00.0 USB controller: Texas Instruments TUSB73x0 SuperSpeed USB 3.0 xHCI Host Controller (rev 02)
0003:09:00.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01)
0003:09:00.1 Ethernet controller: Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01)
0003:09:00.2 Ethernet controller: Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01)
0003:09:00.3 Ethernet controller: Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet PCIe (rev 01)
0003:0f:00.0 Network controller: Mellanox Technologies MT27500 Family [ConnectX-3]

Changelog
=========
N/A

Gavin Shan (8):
  powerpc/pci: Move pcibios_find_pci_bus() around
  powerpc/pci: Don't scan empty slot
  powerpc/powernv: Export functions to retrieve slot status
  PCI/hotplug/rpa: Code cleanup
  PCI/hotplug/rpa: Create PCI slot properly
  PCI/hotplug/rpa: Abstract slot operations
  PCI/hotplug/rpa: Hierarchial slots
  PCI/hotplug/rpa: Support OPAL firmware

 arch/powerpc/include/asm/opal.h                |   6 +-
 arch/powerpc/include/asm/pnv-pci.h             |   3 +
 arch/powerpc/kernel/pci-hotplug.c              |  41 ++-
 arch/powerpc/platforms/powernv/eeh-ioda.c      |  34 +-
 arch/powerpc/platforms/powernv/opal-wrappers.S |   2 +
 arch/powerpc/platforms/powernv/pci.c           |  38 ++
 arch/powerpc/platforms/powernv/pci.h           |   1 +
 arch/powerpc/platforms/pseries/pci_dlpar.c     |  32 --
 drivers/pci/hotplug/Kconfig                    |   4 +-
 drivers/pci/hotplug/Makefile                   |   4 +-
 drivers/pci/hotplug/rpadlpar_core.c            | 102 +++---
 drivers/pci/hotplug/rpaphp.h                   |  93 +++--
 drivers/pci/hotplug/rpaphp_core.c              | 480 ++++++++-----------------
 drivers/pci/hotplug/rpaphp_opal.c              | 241 +++++++++++++
 drivers/pci/hotplug/rpaphp_pci.c               | 135 -------
 drivers/pci/hotplug/rpaphp_rtas.c              | 330 +++++++++++++++++
 drivers/pci/hotplug/rpaphp_slot.c              | 147 --------
 17 files changed, 920 insertions(+), 773 deletions(-)
 create mode 100644 drivers/pci/hotplug/rpaphp_opal.c
 delete mode 100644 drivers/pci/hotplug/rpaphp_pci.c
 create mode 100644 drivers/pci/hotplug/rpaphp_rtas.c
 delete mode 100644 drivers/pci/hotplug/rpaphp_slot.c

-- 
1.8.3.2

^ permalink raw reply

* [PATCH 6/8] PCI/hotplug/rpa: Abstract slot operations
From: Gavin Shan @ 2014-11-24 22:49 UTC (permalink / raw)
  To: linux-pci; +Cc: linuxppc-dev, Gavin Shan
In-Reply-To: <1416869365-7671-1-git-send-email-gwshan@linux.vnet.ibm.com>

The patch splits the code into 2 parts: RPA PCI hotplug slot
management and RTAS backend. It enables us to support PowerNV,
which is built on top of OPAL firmware in future.

The patch also refactors the code for a bit:

    * Rename "struct slot" to "struct rpa_php_slot"
    * All macros have prefix "RPA_PHP_SLOT"
    * rpaphp_slot.c is removed and all logics moved to rpaphp_core.c

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 drivers/pci/hotplug/Makefile        |   3 +-
 drivers/pci/hotplug/rpadlpar_core.c |  10 +-
 drivers/pci/hotplug/rpaphp.h        |  64 +++----
 drivers/pci/hotplug/rpaphp_core.c   | 347 +++++++++++-------------------------
 drivers/pci/hotplug/rpaphp_pci.c    | 136 --------------
 drivers/pci/hotplug/rpaphp_rtas.c   | 320 +++++++++++++++++++++++++++++++++
 drivers/pci/hotplug/rpaphp_slot.c   | 140 ---------------
 7 files changed, 459 insertions(+), 561 deletions(-)
 delete mode 100644 drivers/pci/hotplug/rpaphp_pci.c
 create mode 100644 drivers/pci/hotplug/rpaphp_rtas.c
 delete mode 100644 drivers/pci/hotplug/rpaphp_slot.c

diff --git a/drivers/pci/hotplug/Makefile b/drivers/pci/hotplug/Makefile
index 4a9aa08..630313da 100644
--- a/drivers/pci/hotplug/Makefile
+++ b/drivers/pci/hotplug/Makefile
@@ -51,8 +51,7 @@ acpiphp-objs		:=	acpiphp_core.o	\
 				acpiphp_glue.o
 
 rpaphp-objs		:=	rpaphp_core.o	\
-				rpaphp_pci.o	\
-				rpaphp_slot.o
+				rpaphp_rtas.o
 
 rpadlpar_io-objs	:=	rpadlpar_core.o \
 				rpadlpar_sysfs.o
diff --git a/drivers/pci/hotplug/rpadlpar_core.c b/drivers/pci/hotplug/rpadlpar_core.c
index 35da3b3..a36d2c9 100644
--- a/drivers/pci/hotplug/rpadlpar_core.c
+++ b/drivers/pci/hotplug/rpadlpar_core.c
@@ -117,13 +117,13 @@ static struct device_node *find_dlpar_node(char *drc_name, int *node_type)
  * may be dlpar-able, but not hot-pluggable, so this routine
  * will return NULL for built-in PCI slots.
  */
-static struct slot *find_php_slot(struct device_node *dn)
+static struct rpa_php_slot *find_php_slot(struct device_node *dn)
 {
 	struct list_head *tmp, *n;
-	struct slot *slot;
+	struct rpa_php_slot *slot;
 
 	list_for_each_safe(tmp, n, &rpaphp_slot_head) {
-		slot = list_entry(tmp, struct slot, rpaphp_slot_list);
+		slot = list_entry(tmp, struct rpa_php_slot, rpaphp_slot_list);
 		if (slot->dn == dn)
 			return slot;
 	}
@@ -214,7 +214,7 @@ static int dlpar_add_pci_slot(char *drc_name, struct device_node *dn)
 
 static int dlpar_remove_phb(char *drc_name, struct device_node *dn)
 {
-	struct slot *slot;
+	struct rpa_php_slot *slot;
 	struct pci_dn *pdn;
 	int rc = 0;
 
@@ -359,7 +359,7 @@ static int dlpar_remove_vio_slot(char *drc_name, struct device_node *dn)
 int dlpar_remove_pci_slot(char *drc_name, struct device_node *dn)
 {
 	struct pci_bus *bus;
-	struct slot *slot;
+	struct rpa_php_slot *slot;
 	int ret = 0;
 
 	pci_lock_rescan_remove();
diff --git a/drivers/pci/hotplug/rpaphp.h b/drivers/pci/hotplug/rpaphp.h
index 39ddbdf..09dd516 100644
--- a/drivers/pci/hotplug/rpaphp.h
+++ b/drivers/pci/hotplug/rpaphp.h
@@ -30,21 +30,6 @@
 #include <linux/pci.h>
 #include <linux/pci_hotplug.h>
 
-#define DR_INDICATOR 9002
-#define DR_ENTITY_SENSE 9003
-
-#define POWER_ON	100
-#define POWER_OFF	0
-
-#define LED_OFF		0
-#define LED_ON		1	/* continuous on */
-#define LED_ID		2	/* slow blinking */
-#define LED_ACTION	3	/* fast blinking */
-
-/* Sensor values from rtas_get-sensor */
-#define EMPTY           0	/* No card in slot */
-#define PRESENT         1	/* Card in slot */
-
 #define MY_NAME "rpaphp"
 extern bool rpaphp_debug;
 #define dbg(format, arg...)					\
@@ -57,19 +42,26 @@ extern bool rpaphp_debug;
 #define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg)
 #define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg)
 
-/* slot states */
+/* Power */
+#define RPA_PHP_SLOT_POWER_ON	1	/* On            */
+#define RPA_PHP_SLOT_POWER_OFF	0	/* Off           */
 
-#define	NOT_VALID	3
-#define	NOT_CONFIGURED	2
-#define	CONFIGURED	1
-#define	EMPTY		0
+/* Attention */
+#define RPA_PHP_SLOT_ATTEN_OFF	0	/* Off           */
+#define RPA_PHP_SLOT_ATTEN_ON	1	/* On            */
+#define RPA_PHP_SLOT_ATTEN_IND	2	/* Slow blinking */
+#define RPA_PHP_SLOT_ATTEN_ACT	3	/* Fast blinking */
 
-/*
- * struct slot - slot information for each *physical* slot
- */
-struct slot {
+/* Presence */
+#define RPA_PHP_SLOT_EMPTY	0	/* No card       */
+#define RPA_PHP_SLOT_PRESENT	1	/* Presented     */
+
+struct rpa_php_slot {
 	struct list_head rpaphp_slot_list;
 	int state;
+#define RPA_PHP_SLOT_NOT_CONFIGURED	0
+#define RPA_PHP_SLOT_CONFIGURED		1
+#define RPA_PHP_SLOT_NOT_VALID		2
 	u32 index;
 	u32 type;
 	u32 power_domain;
@@ -80,24 +72,20 @@ struct slot {
 	struct hotplug_slot *hotplug_slot;
 };
 
-extern struct hotplug_slot_ops rpaphp_hotplug_slot_ops;
 extern struct list_head rpaphp_slot_head;
 
-/* function prototypes */
-
-/* rpaphp_pci.c */
-int rpaphp_enable_slot(struct slot *slot);
-int rpaphp_get_sensor_state(struct slot *slot, int *state);
-
 /* rpaphp_core.c */
 int rpaphp_add_slot(struct device_node *dn);
-int rpaphp_get_drc_props(struct device_node *dn, int *drc_index,
-		char **drc_name, char **drc_type, int *drc_power);
+void dealloc_slot_struct(struct rpa_php_slot *slot);
+struct rpa_php_slot *alloc_slot_struct(struct device_node *dn, int drc_index,
+				       char *drc_name, int power_domain);
+int rpaphp_register_slot(struct rpa_php_slot *slot);
+int rpaphp_deregister_slot(struct rpa_php_slot *slot);
+int rpaphp_add_slot(struct device_node *dn);
 
-/* rpaphp_slot.c */
-void dealloc_slot_struct(struct slot *slot);
-struct slot *alloc_slot_struct(struct device_node *dn, int drc_index, char *drc_name, int power_domain);
-int rpaphp_register_slot(struct slot *slot);
-int rpaphp_deregister_slot(struct slot *slot);
+/* rpaphp_rtas.c */
+int rpaphp_get_drc_props(struct device_node *dn, int *drc_index,
+			 char **drc_name, char **drc_type, int *drc_power);
+struct rpa_php_slot *rpaphp_rtas_add_slot(struct device_node *dn);
 
 #endif				/* _PPC64PHP_H */
diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c
index a639c5c..91eff8f 100644
--- a/drivers/pci/hotplug/rpaphp_core.c
+++ b/drivers/pci/hotplug/rpaphp_core.c
@@ -45,194 +45,118 @@ EXPORT_SYMBOL_GPL(rpaphp_slot_head);
 #define DRIVER_AUTHOR	"Linda Xie <lxie@us.ibm.com>"
 #define DRIVER_DESC	"RPA HOT Plug PCI Controller Driver"
 
-#define MAX_LOC_CODE 128
-
-MODULE_AUTHOR(DRIVER_AUTHOR);
-MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_LICENSE("GPL");
-
 module_param_named(debug, rpaphp_debug, bool, 0644);
 
-/**
- * set_attention_status - set attention LED
- * @hotplug_slot: target &hotplug_slot
- * @value: LED control value
- *
- * echo 0 > attention -- set LED OFF
- * echo 1 > attention -- set LED ON
- * echo 2 > attention -- set LED ID(identify, light is blinking)
- */
-static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 value)
+/* free up the memory used by a slot */
+static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot)
 {
-	int rc;
-	struct slot *slot = (struct slot *)hotplug_slot->private;
-
-	switch (value) {
-	case 0:
-	case 1:
-	case 2:
-		break;
-	default:
-		value = 1;
-	}
+	struct rpa_php_slot *slot = hotplug_slot->private;
 
-	rc = rtas_set_indicator(DR_INDICATOR, slot->index, value);
-	if (!rc)
-		hotplug_slot->info->attention_status = value;
-
-	return rc;
+	dealloc_slot_struct(slot);
 }
 
-/**
- * get_power_status - get power status of a slot
- * @hotplug_slot: slot to get status
- * @value: pointer to store status
- */
-static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
+void dealloc_slot_struct(struct rpa_php_slot *slot)
 {
-	int retval, level;
-	struct slot *slot = (struct slot *)hotplug_slot->private;
-
-	retval = rtas_get_power_level(slot->power_domain, &level);
-	if (!retval)
-		*value = level;
-	return retval;
+	kfree(slot->hotplug_slot->info);
+	kfree(slot->name);
+	kfree(slot->hotplug_slot);
+	kfree(slot);
 }
 
-/**
- * get_attention_status - get attention LED status
- * @hotplug_slot: slot to get status
- * @value: pointer to store status
- */
-static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
+struct rpa_php_slot *alloc_slot_struct(struct device_node *dn,
+				       int drc_index, char *drc_name,
+				       int power_domain)
 {
-	struct slot *slot = (struct slot *)hotplug_slot->private;
-	*value = slot->hotplug_slot->info->attention_status;
-	return 0;
-}
-
-static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
-{
-	struct slot *slot = (struct slot *)hotplug_slot->private;
-	int rc, state;
-
-	rc = rpaphp_get_sensor_state(slot, &state);
-
-	*value = NOT_VALID;
-	if (rc)
-		return rc;
+	struct rpa_php_slot *slot;
 
-	if (state == EMPTY)
-		*value = EMPTY;
-	else if (state == PRESENT)
-		*value = slot->state;
-
-	return 0;
+	slot = kzalloc(sizeof(*slot), GFP_KERNEL);
+	if (!slot)
+		goto error_nomem;
+	slot->hotplug_slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
+	if (!slot->hotplug_slot)
+		goto error_slot;
+	slot->hotplug_slot->info = kzalloc(sizeof(struct hotplug_slot_info),
+					   GFP_KERNEL);
+	if (!slot->hotplug_slot->info)
+		goto error_hpslot;
+	slot->name = kstrdup(drc_name, GFP_KERNEL);
+	if (!slot->name)
+		goto error_info;
+	slot->dn = dn;
+	slot->index = drc_index;
+	slot->power_domain = power_domain;
+	slot->hotplug_slot->private = slot;
+	slot->hotplug_slot->release = &rpaphp_release_slot;
+
+	slot->hotplug_slot->info->power_status = RPA_PHP_SLOT_POWER_ON;
+	slot->hotplug_slot->info->attention_status = RPA_PHP_SLOT_ATTEN_OFF;
+	slot->hotplug_slot->info->adapter_status = RPA_PHP_SLOT_EMPTY;
+	slot->state = RPA_PHP_SLOT_NOT_VALID;
+
+	return slot;
+
+error_info:
+	kfree(slot->hotplug_slot->info);
+error_hpslot:
+	kfree(slot->hotplug_slot);
+error_slot:
+	kfree(slot);
+error_nomem:
+	return NULL;
 }
 
-static enum pci_bus_speed get_max_bus_speed(struct slot *slot)
+int rpaphp_register_slot(struct rpa_php_slot *slot)
 {
-	enum pci_bus_speed speed;
-	switch (slot->type) {
-	case 1:
-	case 2:
-	case 3:
-	case 4:
-	case 5:
-	case 6:
-		speed = PCI_SPEED_33MHz;	/* speed for case 1-6 */
-		break;
-	case 7:
-	case 8:
-		speed = PCI_SPEED_66MHz;
-		break;
-	case 11:
-	case 14:
-		speed = PCI_SPEED_66MHz_PCIX;
-		break;
-	case 12:
-	case 15:
-		speed = PCI_SPEED_100MHz_PCIX;
-		break;
-	case 13:
-	case 16:
-		speed = PCI_SPEED_133MHz_PCIX;
-		break;
-	default:
-		speed = PCI_SPEED_UNKNOWN;
+	struct hotplug_slot *php_slot = slot->hotplug_slot;
+	struct rpa_php_slot *tmp;
+	int slotno, retval;
+
+	dbg("%s registering slot:path[%s] index[%x], name[%s] pdomain[%x] type[%d]\n",
+	    __func__, slot->dn->full_name, slot->index, slot->name,
+	    slot->power_domain, slot->type);
+
+	/* Should not try to register the same slot twice */
+	list_for_each_entry(tmp, &rpaphp_slot_head, rpaphp_slot_list) {
+		if (!strcmp(tmp->name, slot->name)) {
+			err("%s: Slot[%s] is already registered\n",
+			    __func__, slot->name);
+			return -EAGAIN;
+		}
+	}
+	if (slot->dn->child)
+		slotno = PCI_SLOT(PCI_DN(slot->dn->child)->devfn);
+	else
+		slotno = -1;
+	retval = pci_hp_register(php_slot, slot->bus, slotno, slot->name);
+	if (retval) {
+		err("pci_hp_register failed with error %d\n", retval);
+		return retval;
 	}
 
-	return speed;
+	/* add slot to our internal list */
+	list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head);
+	info("Slot [%s] registered\n", slot->name);
+	return 0;
 }
 
-static int parse_drc_props(struct device_node *dn, u32 drc_index,
-			   char **drc_name, char **drc_type, u32 *drc_power)
+int rpaphp_deregister_slot(struct rpa_php_slot *slot)
 {
-	const u32 *indexes, *names, *types, *domains;
-	char *name, *type;
-	struct device_node *parent = dn;
-	u32 i;
-
-	while ((parent = of_get_parent(parent))) {
-		indexes = of_get_property(parent, "ibm,drc-indexes", NULL);
-		names   = of_get_property(parent, "ibm,drc-names", NULL);
-		types   = of_get_property(parent, "ibm,drc-types", NULL);
-		domains = of_get_property(parent, "ibm,drc-power-domains", NULL);
-
-		if (!indexes || !names || !types || !domains) {
-			of_node_put(parent);
-			continue;
-		}
+	struct hotplug_slot *php_slot = slot->hotplug_slot;
+	int retval = 0;
 
-		name = (char *)&names[1];
-		type = (char *)&types[1];
-		for (i = 0; i < be32_to_cpu(indexes[0]); i++) {
-			if (be32_to_cpu(indexes[i + 1]) != drc_index) {
-				name += (strlen(name) + 1);
-				type += (strlen(type) + 1);
-				continue;
-			}
-
-			/* Matched index */
-			if (drc_name)
-				*drc_name = name;
-			if (drc_type)
-				*drc_type = type;
-			if (drc_power)
-				*drc_power = be32_to_cpu(domains[i + 1]);
-
-			of_node_put(parent);
-			return 0;
-		}
-
-		/* Next level parent */
-		of_node_put(parent);
-	}
+	dbg("%s - Entry: deregistering slot=%s\n",
+	    __func__, slot->name);
 
-	return -ENODEV;
-}
+	list_del(&slot->rpaphp_slot_list);
 
-/*
- * To get the DRC props describing the current node, first obtain it's
- * my-drc-index property.  Next obtain the DRC list from it's parent.  Use
- * the my-drc-index for correlation, and obtain the requested properties.
- */
-int rpaphp_get_drc_props(struct device_node *dn, int *drc_index,
-			 char **drc_name, char **drc_type, int *drc_power)
-{
-	const u32 *my_index;
-
-	/* Check if node is capable of hotplug */
-	my_index = of_get_property(dn, "ibm,my-drc-index", NULL);
-	if (!my_index)
-		return -EINVAL;
-	if (drc_index)
-		*drc_index = be32_to_cpu(*my_index);
+	retval = pci_hp_deregister(php_slot);
+	if (retval)
+		err("Problem unregistering a slot %s\n", slot->name);
 
-	return parse_drc_props(dn, be32_to_cpu(*my_index),
-			       drc_name, drc_type, drc_power);
+	dbg("%s - Exit: rc[%d]\n", __func__, retval);
+	return retval;
 }
-EXPORT_SYMBOL_GPL(rpaphp_get_drc_props);
+EXPORT_SYMBOL_GPL(rpaphp_deregister_slot);
 
 /**
  * rpaphp_add_slot -- declare a hotplug slot to the hotplug subsystem.
@@ -252,29 +176,22 @@ EXPORT_SYMBOL_GPL(rpaphp_get_drc_props);
  */
 int rpaphp_add_slot(struct device_node *dn)
 {
-	char *name, *type, *endptr;
-	int index, power_domain;
-	struct slot *slot;
-	int val, ret;
-
-	/* Get and parse the hotplug properties */
-	ret = rpaphp_get_drc_props(dn, &index, &name, &type, &power_domain);
-	if (ret)
-		return ret;
-
-	/* PCI Hotplug nodes have an integer for drc_type */
-	val = simple_strtoul(type, &endptr, 10);
-	if (endptr == type)
-		return -EINVAL;
+	struct rpa_php_slot *slot = NULL;
+	int ret;
 
-	slot = alloc_slot_struct(dn, index, name, power_domain);
+	/* Create slot */
+	if (machine_is(pseries))
+		slot = rpaphp_rtas_add_slot(dn);
 	if (!slot)
-		return -ENOMEM;
+		return -EIO;
 
-	slot->type = val;
-	ret = rpaphp_enable_slot(slot);
-	if (!ret)
-		ret = rpaphp_register_slot(slot);
+	/* Enable slot */
+	ret = slot->hotplug_slot->ops->enable_slot(slot->hotplug_slot);
+	if (ret)
+		goto fail;
+
+	/* Register slot */
+	ret = rpaphp_register_slot(slot);
 	if (ret)
 		goto fail;
 
@@ -288,7 +205,7 @@ EXPORT_SYMBOL_GPL(rpaphp_add_slot);
 static void __exit cleanup_slots(void)
 {
 	struct list_head *tmp, *n;
-	struct slot *slot;
+	struct rpa_php_slot *slot;
 
 	/*
 	 * Unregister all of our slots with the pci_hotplug subsystem,
@@ -297,7 +214,7 @@ static void __exit cleanup_slots(void)
 	 */
 
 	list_for_each_safe(tmp, n, &rpaphp_slot_head) {
-		slot = list_entry(tmp, struct slot, rpaphp_slot_list);
+		slot = list_entry(tmp, struct rpa_php_slot, rpaphp_slot_list);
 		list_del(&slot->rpaphp_slot_list);
 		pci_hp_deregister(slot->hotplug_slot);
 	}
@@ -320,59 +237,9 @@ static void __exit rpaphp_exit(void)
 	cleanup_slots();
 }
 
-static int enable_slot(struct hotplug_slot *hotplug_slot)
-{
-	struct slot *slot = (struct slot *)hotplug_slot->private;
-	int state;
-	int retval;
-
-	if (slot->state == CONFIGURED)
-		return 0;
-
-	retval = rpaphp_get_sensor_state(slot, &state);
-	if (retval)
-		return retval;
-
-	if (state == PRESENT) {
-		pci_lock_rescan_remove();
-		pcibios_add_pci_devices(slot->bus);
-		pci_unlock_rescan_remove();
-		slot->state = CONFIGURED;
-	} else if (state == EMPTY) {
-		slot->state = EMPTY;
-	} else {
-		err("%s: slot[%s] is in invalid state\n", __func__, slot->name);
-		slot->state = NOT_VALID;
-		return -EINVAL;
-	}
-
-	slot->bus->max_bus_speed = get_max_bus_speed(slot);
-	return 0;
-}
-
-static int disable_slot(struct hotplug_slot *hotplug_slot)
-{
-	struct slot *slot = (struct slot *)hotplug_slot->private;
-	if (slot->state == NOT_CONFIGURED)
-		return -EINVAL;
-
-	pci_lock_rescan_remove();
-	pcibios_remove_pci_devices(slot->bus);
-	pci_unlock_rescan_remove();
-	vm_unmap_aliases();
-
-	slot->state = NOT_CONFIGURED;
-	return 0;
-}
-
-struct hotplug_slot_ops rpaphp_hotplug_slot_ops = {
-	.enable_slot = enable_slot,
-	.disable_slot = disable_slot,
-	.set_attention_status = set_attention_status,
-	.get_power_status = get_power_status,
-	.get_attention_status = get_attention_status,
-	.get_adapter_status = get_adapter_status,
-};
-
 module_init(rpaphp_init);
 module_exit(rpaphp_exit);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
diff --git a/drivers/pci/hotplug/rpaphp_pci.c b/drivers/pci/hotplug/rpaphp_pci.c
deleted file mode 100644
index a4aa65c..0000000
--- a/drivers/pci/hotplug/rpaphp_pci.c
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * PCI Hot Plug Controller Driver for RPA-compliant PPC64 platform.
- * Copyright (C) 2003 Linda Xie <lxie@us.ibm.com>
- *
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
- * NON INFRINGEMENT.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * Send feedback to <lxie@us.ibm.com>
- *
- */
-#include <linux/pci.h>
-#include <linux/string.h>
-
-#include <asm/pci-bridge.h>
-#include <asm/rtas.h>
-#include <asm/machdep.h>
-
-#include "../pci.h"		/* for pci_add_new_bus */
-#include "rpaphp.h"
-
-int rpaphp_get_sensor_state(struct slot *slot, int *state)
-{
-	int rc;
-	int setlevel;
-
-	rc = rtas_get_sensor(DR_ENTITY_SENSE, slot->index, state);
-	if (rc >= 0)
-		return rc;
-	if (rc != -EFAULT && rc != -EEXIST) {
-		err("%s: Failure %d getting sensor state on slot[%s]\n",
-		    __func__, rc, slot->name);
-		return rc;
-	}
-
-
-	/*
-	 * Some slots have to be powered up before
-	 * get-sensor will succeed
-	 */
-	dbg("%s: Slot[%s] must be power up to get sensor-state\n",
-	    __func__, slot->name);
-	rc = rtas_set_power_level(slot->power_domain, POWER_ON,
-				  &setlevel);
-	if (rc < 0) {
-		dbg("%s: Failure %d powerng on slot[%s]\n",
-		    __func__, rc, slot->name);
-		return rc;
-	}
-
-	return rtas_get_sensor(DR_ENTITY_SENSE,
-			       slot->index, state);
-}
-
-/**
- * rpaphp_enable_slot - record slot state, config pci device
- * @slot: target &slot
- *
- * Initialize values in the slot, and the hotplug_slot info
- * structures to indicate if there is a pci card plugged into
- * the slot. If the slot is not empty, run the pcibios routine
- * to get pcibios stuff correctly set up.
- */
-int rpaphp_enable_slot(struct slot *slot)
-{
-	int rc, level, state;
-	struct pci_bus *bus;
-	struct hotplug_slot_info *info = slot->hotplug_slot->info;
-
-	info->adapter_status = NOT_VALID;
-	slot->state = EMPTY;
-
-	/* Find out if the power is turned on for the slot */
-	rc = rtas_get_power_level(slot->power_domain, &level);
-	if (rc)
-		return rc;
-	info->power_status = level;
-
-	/* Figure out if there is an adapter in the slot */
-	rc = rpaphp_get_sensor_state(slot, &state);
-	if (rc)
-		return rc;
-
-	bus = pcibios_find_pci_bus(slot->dn);
-	if (!bus) {
-		err("%s: no pci_bus for dn %s\n", __func__, slot->dn->full_name);
-		return -EINVAL;
-	}
-
-	info->adapter_status = EMPTY;
-	slot->bus = bus;
-	slot->pci_devs = &bus->devices;
-
-	/* if there's an adapter in the slot, go add the pci devices */
-	if (state == PRESENT) {
-		info->adapter_status = NOT_CONFIGURED;
-		slot->state = NOT_CONFIGURED;
-
-		/* non-empty slot has to have child */
-		if (!slot->dn->child) {
-			err("%s: slot[%s]'s device_node doesn't have child for adapter\n",
-			    __func__, slot->name);
-			return -EINVAL;
-		}
-
-		if (list_empty(&bus->devices))
-			pcibios_add_pci_devices(bus);
-
-		if (!list_empty(&bus->devices)) {
-			info->adapter_status = CONFIGURED;
-			slot->state = CONFIGURED;
-		}
-
-		if (rpaphp_debug) {
-			struct pci_dev *dev;
-			dbg("%s: pci_devs of slot[%s]\n", __func__, slot->dn->full_name);
-			list_for_each_entry (dev, &bus->devices, bus_list)
-				dbg("\t%s\n", pci_name(dev));
-		}
-	}
-
-	return 0;
-}
diff --git a/drivers/pci/hotplug/rpaphp_rtas.c b/drivers/pci/hotplug/rpaphp_rtas.c
new file mode 100644
index 0000000..74f024a
--- /dev/null
+++ b/drivers/pci/hotplug/rpaphp_rtas.c
@@ -0,0 +1,320 @@
+/*
+ * RTAS backend for RPA-compliant PP64 platform
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/pci.h>
+#include <linux/pci_hotplug.h>
+#include <linux/smp.h>
+#include <linux/init.h>
+#include <linux/vmalloc.h>
+#include <asm/eeh.h>
+#include <asm/rtas.h>
+#include <asm/pci-bridge.h>
+
+#include "../pci.h"
+#include "rpaphp.h"
+
+#define	RPA_PHP_DR_INDICATOR	9002
+#define RPA_PHP_DR_ENTITY_SENSE	9003
+
+static int get_power_status(struct hotplug_slot *hp_slot, u8 *val)
+{
+	struct rpa_php_slot *slot = hp_slot->private;
+	int state, ret;
+
+	/* By default, the power is on */
+	*val = RPA_PHP_SLOT_POWER_ON;
+
+	/* Retrieve power state from firmware, which might fail */
+	ret = rtas_get_power_level(slot->power_domain, &state);
+	if (!ret) {
+		if (state > 0)
+			hp_slot->info->power_status = RPA_PHP_SLOT_POWER_ON;
+		else
+			hp_slot->info->power_status = RPA_PHP_SLOT_POWER_OFF;
+		*val = hp_slot->info->power_status;
+	}
+
+	return 0;
+}
+
+static int get_adapter_status(struct hotplug_slot *hp_slot, u8 *val)
+{
+	struct rpa_php_slot *slot = hp_slot->private;
+        int state, ret;
+
+	/* By default, the slot is empty */
+	*val = RPA_PHP_SLOT_EMPTY;
+
+	/* Retrieve presence from firmware */
+	ret = rtas_get_sensor(RPA_PHP_DR_ENTITY_SENSE, slot->index, &state);
+	if (ret >= 0) {
+		if (state > 0)
+			hp_slot->info->adapter_status = RPA_PHP_SLOT_PRESENT;
+		else
+			hp_slot->info->adapter_status = RPA_PHP_SLOT_EMPTY;
+		*val = hp_slot->info->adapter_status;
+		return 0;
+	}
+
+	/* Check if we need power slot on and retry */
+	if (ret != -EFAULT && ret != -EEXIST) {
+		err("%s: Error %d getting slot[%s] presence\n",
+		    __func__, ret, slot->name);
+		return ret;
+	}
+
+	/* Power slot on, which might fail */
+	ret = rtas_set_power_level(slot->power_domain,
+				   RPA_PHP_SLOT_POWER_ON, &state);
+	if (!ret)
+		hp_slot->info->power_status = RPA_PHP_SLOT_POWER_ON;
+
+	/* Recheck the presence */
+	ret = rtas_get_sensor(RPA_PHP_DR_ENTITY_SENSE, slot->index, &state);
+	if (ret >= 0) {
+		if (state > 0)
+			hp_slot->info->adapter_status = RPA_PHP_SLOT_PRESENT;
+		else
+			hp_slot->info->adapter_status = RPA_PHP_SLOT_EMPTY;
+		*val = hp_slot->info->adapter_status;
+	}
+
+	return 0;
+}
+
+static int set_attention_status(struct hotplug_slot *hp_slot, u8 val)
+{
+	struct rpa_php_slot *slot = hp_slot->private;
+	int ret;
+
+	/*
+	 * The default operation would to turn on
+	 * the attention
+	 */
+	switch (val) {
+	case RPA_PHP_SLOT_ATTEN_OFF:
+	case RPA_PHP_SLOT_ATTEN_ON:
+	case RPA_PHP_SLOT_ATTEN_IND:
+	case RPA_PHP_SLOT_ATTEN_ACT:
+		break;
+	default:
+		val = RPA_PHP_SLOT_ATTEN_ON;
+	}
+
+	/* Set the attention */
+	ret = rtas_set_indicator(RPA_PHP_DR_INDICATOR, slot->index, val);
+	if (!ret)
+		hp_slot->info->attention_status = val;
+
+	return ret;
+}
+
+static enum pci_bus_speed get_max_bus_speed(struct rpa_php_slot *slot)
+{
+	enum pci_bus_speed speed;
+
+	switch (slot->type) {
+	case 1 ... 6:
+		speed = PCI_SPEED_33MHz;
+		break;
+	case 7 ... 8:
+		speed = PCI_SPEED_66MHz;
+		break;
+	case 11:
+	case 14:
+		speed = PCI_SPEED_66MHz_PCIX;
+		break;
+	case 12:
+	case 15:
+		speed = PCI_SPEED_100MHz_PCIX;
+		break;
+	case 13:
+	case 16:
+		speed = PCI_SPEED_133MHz_PCIX;
+		break;
+	default:
+		speed = PCI_SPEED_UNKNOWN;
+	}
+
+	return speed;
+}
+
+static int enable_slot(struct hotplug_slot *hp_slot)
+{
+	struct rpa_php_slot *slot = hp_slot->private;
+	uint8_t presence;
+	int ret;
+
+	/* Check if the slot has been configured */
+	if (slot->state == RPA_PHP_SLOT_CONFIGURED)
+		return 0;
+
+	/* Retrieve slot presence status */
+	ret = hp_slot->ops->get_adapter_status(hp_slot, &presence);
+	if (ret)
+		return ret;
+
+	switch (presence) {
+	case RPA_PHP_SLOT_PRESENT:
+		pci_lock_rescan_remove();
+		pcibios_add_pci_devices(slot->bus);
+		pci_unlock_rescan_remove();
+		slot->state = RPA_PHP_SLOT_CONFIGURED;
+		break;
+	case RPA_PHP_SLOT_EMPTY:
+		slot->state = RPA_PHP_SLOT_NOT_CONFIGURED;
+		break;
+	default:
+		slot->state = RPA_PHP_SLOT_NOT_VALID;
+		return -EINVAL;
+	}
+
+	/* Fix the bus maximal speed */
+	slot->bus->max_bus_speed = get_max_bus_speed(slot);
+	return 0;
+}
+
+static int disable_slot(struct hotplug_slot *hp_slot)
+{
+	struct rpa_php_slot *slot = hp_slot->private;
+
+	if (slot->state != RPA_PHP_SLOT_CONFIGURED)
+		return 0;
+
+	pci_lock_rescan_remove();
+	pcibios_remove_pci_devices(slot->bus);
+	pci_unlock_rescan_remove();
+	vm_unmap_aliases();
+
+	slot->state = RPA_PHP_SLOT_NOT_CONFIGURED;
+	return 0;
+}
+
+static struct hotplug_slot_ops rpaphp_rtas_ops = {
+	.enable_slot		= enable_slot,
+	.disable_slot		= disable_slot,
+	.set_attention_status	= set_attention_status,
+	.get_power_status	= get_power_status,
+	.get_adapter_status	= get_adapter_status,
+};
+
+static int parse_drc_props(struct device_node *dn, u32 drc_index,
+                           char **drc_name, char **drc_type, u32 *drc_power)
+{
+	const u32 *indexes, *names, *types, *domains;
+	char *name, *type;
+	struct device_node *parent = dn;
+	u32 i;
+
+	while ((parent = of_get_parent(parent))) {
+		indexes = of_get_property(parent, "ibm,drc-indexes", NULL);
+		names   = of_get_property(parent, "ibm,drc-names", NULL);
+		types   = of_get_property(parent, "ibm,drc-types", NULL);
+		domains = of_get_property(parent, "ibm,drc-power-domains", NULL);
+
+		if (!indexes || !names || !types || !domains) {
+			of_node_put(parent);
+			continue;
+		}
+
+		name = (char *)&names[1];
+		type = (char *)&types[1];
+		for (i = 0; i < be32_to_cpu(indexes[0]); i++) {
+			if (be32_to_cpu(indexes[i + 1]) != drc_index) {
+				name += (strlen(name) + 1);
+				type += (strlen(type) + 1);
+				continue;
+			}
+
+			/* Matched index */
+			if (drc_name)
+				*drc_name = name;
+			if (drc_type)
+				*drc_type = type;
+			if (drc_power)
+				*drc_power = be32_to_cpu(domains[i + 1]);
+
+			of_node_put(parent);
+			return 0;
+		}
+
+		/* Next level parent */
+		of_node_put(parent);
+	}
+
+	return -ENODEV;
+}
+
+/*
+ * To get the DRC props describing the current node, first obtain it's
+ * my-drc-index property.  Next obtain the DRC list from it's parent.  Use
+ * the my-drc-index for correlation, and obtain the requested properties.
+ */
+int rpaphp_get_drc_props(struct device_node *dn, int *drc_index,
+                         char **drc_name, char **drc_type, int *drc_power)
+{
+	const u32 *my_index;
+
+	/* Check if node is capable of hotplug */
+	my_index = of_get_property(dn, "ibm,my-drc-index", NULL);
+	if (!my_index)
+		return -EINVAL;
+	if (drc_index)
+		*drc_index = be32_to_cpu(*my_index);
+
+	return parse_drc_props(dn, be32_to_cpu(*my_index),
+			       drc_name, drc_type, drc_power);
+}
+EXPORT_SYMBOL_GPL(rpaphp_get_drc_props);
+
+struct rpa_php_slot *rpaphp_rtas_add_slot(struct device_node *dn)
+{
+	char *name, *type, *endptr;
+	int index, power_domain;
+	struct rpa_php_slot *slot;
+	struct pci_bus *bus;
+	int val, ret;
+
+	/* Get and parse the hotplug properties */
+	ret = rpaphp_get_drc_props(dn, &index, &name, &type, &power_domain);
+	if (ret)
+		return NULL;
+
+	/*
+	 * PCI hotplug slots have integer DRC type. That of
+	 * PHB slot is fixed to "PHB"
+	 */
+        val = simple_strtoul(type, &endptr, 10);
+	if (strcmp(type, "PHB") && (endptr == type))
+		return NULL;
+
+	slot = alloc_slot_struct(dn, index, name, power_domain);
+	if (!slot)
+		return NULL;
+
+        /* The slot should have an associated bus */
+	bus = pcibios_find_pci_bus(dn);
+	if (!bus) {
+		err("%s: No PCI bus for device node %s\n",
+			__func__, dn->full_name);
+		goto fail;
+	}
+
+	slot->hotplug_slot->ops = &rpaphp_rtas_ops;
+	slot->type     = val;
+	slot->bus      = bus;
+	slot->pci_devs = &bus->devices;
+	return slot;
+fail:
+	dealloc_slot_struct(slot);
+	return NULL;
+}
diff --git a/drivers/pci/hotplug/rpaphp_slot.c b/drivers/pci/hotplug/rpaphp_slot.c
deleted file mode 100644
index be48e69..0000000
--- a/drivers/pci/hotplug/rpaphp_slot.c
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * RPA Virtual I/O device functions
- * Copyright (C) 2004 Linda Xie <lxie@us.ibm.com>
- *
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
- * NON INFRINGEMENT.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * Send feedback to <lxie@us.ibm.com>
- *
- */
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/sysfs.h>
-#include <linux/pci.h>
-#include <linux/string.h>
-#include <linux/slab.h>
-
-#include <asm/rtas.h>
-#include "rpaphp.h"
-
-/* free up the memory used by a slot */
-static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot)
-{
-	struct slot *slot = (struct slot *) hotplug_slot->private;
-	dealloc_slot_struct(slot);
-}
-
-void dealloc_slot_struct(struct slot *slot)
-{
-	kfree(slot->hotplug_slot->info);
-	kfree(slot->name);
-	kfree(slot->hotplug_slot);
-	kfree(slot);
-}
-
-struct slot *alloc_slot_struct(struct device_node *dn,
-                       int drc_index, char *drc_name, int power_domain)
-{
-	struct slot *slot;
-
-	slot = kzalloc(sizeof(struct slot), GFP_KERNEL);
-	if (!slot)
-		goto error_nomem;
-	slot->hotplug_slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
-	if (!slot->hotplug_slot)
-		goto error_slot;
-	slot->hotplug_slot->info = kzalloc(sizeof(struct hotplug_slot_info),
-					   GFP_KERNEL);
-	if (!slot->hotplug_slot->info)
-		goto error_hpslot;
-	slot->name = kstrdup(drc_name, GFP_KERNEL);
-	if (!slot->name)
-		goto error_info;
-	slot->dn = dn;
-	slot->index = drc_index;
-	slot->power_domain = power_domain;
-	slot->hotplug_slot->private = slot;
-	slot->hotplug_slot->ops = &rpaphp_hotplug_slot_ops;
-	slot->hotplug_slot->release = &rpaphp_release_slot;
-
-	return slot;
-
-error_info:
-	kfree(slot->hotplug_slot->info);
-error_hpslot:
-	kfree(slot->hotplug_slot);
-error_slot:
-	kfree(slot);
-error_nomem:
-	return NULL;
-}
-
-int rpaphp_deregister_slot(struct slot *slot)
-{
-	int retval = 0;
-	struct hotplug_slot *php_slot = slot->hotplug_slot;
-
-	 dbg("%s - Entry: deregistering slot=%s\n",
-		__func__, slot->name);
-
-	list_del(&slot->rpaphp_slot_list);
-
-	retval = pci_hp_deregister(php_slot);
-	if (retval)
-		err("Problem unregistering a slot %s\n", slot->name);
-
-	dbg("%s - Exit: rc[%d]\n", __func__, retval);
-	return retval;
-}
-EXPORT_SYMBOL_GPL(rpaphp_deregister_slot);
-
-int rpaphp_register_slot(struct slot *slot)
-{
-	struct hotplug_slot *php_slot = slot->hotplug_slot;
-	struct slot *tmp;
-	int retval;
-	int slotno;
-
-	dbg("%s registering slot:path[%s] index[%x], name[%s] pdomain[%x] type[%d]\n",
-		__func__, slot->dn->full_name, slot->index, slot->name,
-		slot->power_domain, slot->type);
-
-	/* Should not try to register the same slot twice */
-	list_for_each_entry(tmp, &rpaphp_slot_head, rpaphp_slot_list) {
-		if (!strcmp(tmp->name, slot->name)) {
-			err("%s: Slot[%s] is already registered\n",
-			    __func__, slot->name);
-			return -EAGAIN;
-		}
-	}
-
-	if (slot->dn->child)
-		slotno = PCI_SLOT(PCI_DN(slot->dn->child)->devfn);
-	else
-		slotno = -1;
-	retval = pci_hp_register(php_slot, slot->bus, slotno, slot->name);
-	if (retval) {
-		err("pci_hp_register failed with error %d\n", retval);
-		return retval;
-	}
-
-	/* add slot to our internal list */
-	list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head);
-	info("Slot [%s] registered\n", slot->name);
-	return 0;
-}
-- 
1.8.3.2

^ permalink raw reply related

* [PATCH 5/8] PCI/hotplug/rpa: Create PCI slot properly
From: Gavin Shan @ 2014-11-24 22:49 UTC (permalink / raw)
  To: linux-pci; +Cc: linuxppc-dev, Gavin Shan
In-Reply-To: <1416869365-7671-1-git-send-email-gwshan@linux.vnet.ibm.com>

When loading rpaphp.ko on a P7 box, I didn't see any PCI slots
created under /sys/bus/pci/slots as expected. It seems that the
RPA PCI slot stuff has been broken for long time. The driver
doesn't use the properties of PCI device-tree nodes properly to
populate PCI slots: device-tree node property "ibm,my-drc-index"
is the identifier of hotpluggable PCI slot. The (direct or indirect)
parent device-tree node should have properties associated with the
"ibm,my-drc-index", which are "ibm,drc-indexes","ibm,drc-names",
"ibm,drc-types", "ibm,drc-power-domains".

The patch parses above device-tree node properties to create PCI
slots properly. One PCI slot is created for PCI device-tree node,
which has meaningful "ibm,my-drc-index".

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 drivers/pci/hotplug/rpaphp.h      |   2 +-
 drivers/pci/hotplug/rpaphp_core.c | 205 ++++++++++++++------------------------
 2 files changed, 74 insertions(+), 133 deletions(-)

diff --git a/drivers/pci/hotplug/rpaphp.h b/drivers/pci/hotplug/rpaphp.h
index b2593e8..39ddbdf 100644
--- a/drivers/pci/hotplug/rpaphp.h
+++ b/drivers/pci/hotplug/rpaphp.h
@@ -92,7 +92,7 @@ int rpaphp_get_sensor_state(struct slot *slot, int *state);
 /* rpaphp_core.c */
 int rpaphp_add_slot(struct device_node *dn);
 int rpaphp_get_drc_props(struct device_node *dn, int *drc_index,
-		char **drc_name, char **drc_type, int *drc_power_domain);
+		char **drc_name, char **drc_type, int *drc_power);
 
 /* rpaphp_slot.c */
 void dealloc_slot_struct(struct slot *slot);
diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c
index ff800df..a639c5c 100644
--- a/drivers/pci/hotplug/rpaphp_core.c
+++ b/drivers/pci/hotplug/rpaphp_core.c
@@ -165,119 +165,76 @@ static enum pci_bus_speed get_max_bus_speed(struct slot *slot)
 	return speed;
 }
 
-static int get_children_props(struct device_node *dn, const int **drc_indexes,
-		const int **drc_names, const int **drc_types,
-		const int **drc_power_domains)
+static int parse_drc_props(struct device_node *dn, u32 drc_index,
+			   char **drc_name, char **drc_type, u32 *drc_power)
 {
-	const int *indexes, *names, *types, *domains;
+	const u32 *indexes, *names, *types, *domains;
+	char *name, *type;
+	struct device_node *parent = dn;
+	u32 i;
+
+	while ((parent = of_get_parent(parent))) {
+		indexes = of_get_property(parent, "ibm,drc-indexes", NULL);
+		names   = of_get_property(parent, "ibm,drc-names", NULL);
+		types   = of_get_property(parent, "ibm,drc-types", NULL);
+		domains = of_get_property(parent, "ibm,drc-power-domains", NULL);
+
+		if (!indexes || !names || !types || !domains) {
+			of_node_put(parent);
+			continue;
+		}
 
-	indexes = of_get_property(dn, "ibm,drc-indexes", NULL);
-	names = of_get_property(dn, "ibm,drc-names", NULL);
-	types = of_get_property(dn, "ibm,drc-types", NULL);
-	domains = of_get_property(dn, "ibm,drc-power-domains", NULL);
+		name = (char *)&names[1];
+		type = (char *)&types[1];
+		for (i = 0; i < be32_to_cpu(indexes[0]); i++) {
+			if (be32_to_cpu(indexes[i + 1]) != drc_index) {
+				name += (strlen(name) + 1);
+				type += (strlen(type) + 1);
+				continue;
+			}
 
-	/* Slot does not have dynamically-removable children */
-	if (!indexes || !names || !types || !domains)
-		return -EINVAL;
+			/* Matched index */
+			if (drc_name)
+				*drc_name = name;
+			if (drc_type)
+				*drc_type = type;
+			if (drc_power)
+				*drc_power = be32_to_cpu(domains[i + 1]);
+
+			of_node_put(parent);
+			return 0;
+		}
 
-	if (drc_indexes)
-		*drc_indexes = indexes;
-	/* &drc_names[1] contains NULL terminated slot names */
-	if (drc_names)
-		*drc_names = names;
-	/* &drc_types[1] contains NULL terminated slot types */
-	if (drc_types)
-		*drc_types = types;
-	if (drc_power_domains)
-		*drc_power_domains = domains;
+		/* Next level parent */
+		of_node_put(parent);
+	}
 
-	return 0;
+	return -ENODEV;
 }
 
-/* To get the DRC props describing the current node, first obtain it's
+/*
+ * To get the DRC props describing the current node, first obtain it's
  * my-drc-index property.  Next obtain the DRC list from it's parent.  Use
  * the my-drc-index for correlation, and obtain the requested properties.
  */
 int rpaphp_get_drc_props(struct device_node *dn, int *drc_index,
-		char **drc_name, char **drc_type, int *drc_power_domain)
+			 char **drc_name, char **drc_type, int *drc_power)
 {
-	const int *indexes, *names;
-	const int *types, *domains;
-	const unsigned int *my_index;
-	char *name_tmp, *type_tmp;
-	int i, rc;
+	const u32 *my_index;
 
+	/* Check if node is capable of hotplug */
 	my_index = of_get_property(dn, "ibm,my-drc-index", NULL);
-	/* Node isn't DLPAR/hotplug capable */
 	if (!my_index)
 		return -EINVAL;
+	if (drc_index)
+		*drc_index = be32_to_cpu(*my_index);
 
-	rc = get_children_props(dn->parent, &indexes, &names, &types, &domains);
-	if (rc < 0)
-		return -EINVAL;
-
-	name_tmp = (char *) &names[1];
-	type_tmp = (char *) &types[1];
-
-	/* Iterate through parent properties, looking for my-drc-index */
-	for (i = 0; i < be32_to_cpu(indexes[0]); i++) {
-		if ((unsigned int) indexes[i + 1] == *my_index) {
-			if (drc_name)
-				*drc_name = name_tmp;
-			if (drc_type)
-				*drc_type = type_tmp;
-			if (drc_index)
-				*drc_index = be32_to_cpu(*my_index);
-			if (drc_power_domain)
-				*drc_power_domain = be32_to_cpu(domains[i+1]);
-			return 0;
-		}
-		name_tmp += (strlen(name_tmp) + 1);
-		type_tmp += (strlen(type_tmp) + 1);
-	}
-
-	return -EINVAL;
+	return parse_drc_props(dn, be32_to_cpu(*my_index),
+			       drc_name, drc_type, drc_power);
 }
 EXPORT_SYMBOL_GPL(rpaphp_get_drc_props);
 
 /**
- * is_php_dn() - return true if this is a hotpluggable pci slot, else false
- * @dn: target &device_node
- * @indexes: passed to get_children_props()
- * @names: passed to get_children_props()
- * @types: returned from get_children_props()
- * @power_domains:
- *
- * This routine will return true only if the device node is
- * a hotpluggable slot. This routine will return false
- * for built-in pci slots (even when the built-in slots are
- * dlparable.)
- */
-static bool is_php_dn(struct device_node *dn,
-		      const int **indexes, const int **names,
-		      const int **types, const int **power_domains)
-{
-	const int *drc_types;
-	const char *drc_type_str;
-	char *endptr;
-	unsigned long val;
-	int rc;
-
-	rc = get_children_props(dn, indexes, names, &drc_types, power_domains);
-	if (rc < 0)
-		return false;
-
-	/* PCI Hotplug nodes have an integer for drc_type */
-	drc_type_str = (char *)&drc_types[1];
-	val = simple_strtoul(drc_type_str, &endptr, 10);
-	if (endptr == drc_type_str)
-		return false;
-
-	*types = drc_types;
-	return true;
-}
-
-/**
  * rpaphp_add_slot -- declare a hotplug slot to the hotplug subsystem.
  * @dn: device node of slot
  *
@@ -295,52 +252,36 @@ static bool is_php_dn(struct device_node *dn,
  */
 int rpaphp_add_slot(struct device_node *dn)
 {
+	char *name, *type, *endptr;
+	int index, power_domain;
 	struct slot *slot;
-	int retval = 0;
-	int i;
-	const int *indexes, *names, *types, *power_domains;
-	char *name, *type;
-
-	if (!dn->name || strcmp(dn->name, "pci"))
-		return 0;
+	int val, ret;
 
-	/* If this is not a hotplug slot, return without doing anything. */
-	if (!is_php_dn(dn, &indexes, &names, &types, &power_domains))
-		return 0;
-
-	dbg("Entry %s: dn->full_name=%s\n", __func__, dn->full_name);
-
-	/* register PCI devices */
-	name = (char *) &names[1];
-	type = (char *) &types[1];
-	for (i = 0; i < be32_to_cpu(indexes[0]); i++) {
-		int index;
-
-		index = be32_to_cpu(indexes[i + 1]);
-		slot = alloc_slot_struct(dn, index, name,
-					 be32_to_cpu(power_domains[i + 1]));
-		if (!slot)
-			return -ENOMEM;
-
-		slot->type = simple_strtoul(type, NULL, 10);
-
-		dbg("Found drc-index:0x%x drc-name:%s drc-type:%s\n",
-				index, name, type);
+	/* Get and parse the hotplug properties */
+	ret = rpaphp_get_drc_props(dn, &index, &name, &type, &power_domain);
+	if (ret)
+		return ret;
 
-		retval = rpaphp_enable_slot(slot);
-		if (!retval)
-			retval = rpaphp_register_slot(slot);
+	/* PCI Hotplug nodes have an integer for drc_type */
+	val = simple_strtoul(type, &endptr, 10);
+	if (endptr == type)
+		return -EINVAL;
 
-		if (retval)
-			dealloc_slot_struct(slot);
+	slot = alloc_slot_struct(dn, index, name, power_domain);
+	if (!slot)
+		return -ENOMEM;
 
-		name += strlen(name) + 1;
-		type += strlen(type) + 1;
-	}
-	dbg("%s - Exit: rc[%d]\n", __func__, retval);
+	slot->type = val;
+	ret = rpaphp_enable_slot(slot);
+	if (!ret)
+		ret = rpaphp_register_slot(slot);
+	if (ret)
+		goto fail;
 
-	/* XXX FIXME: reports a failure only if last entry in loop failed */
-	return retval;
+	return 0;
+fail:
+	dealloc_slot_struct(slot);
+	return ret;
 }
 EXPORT_SYMBOL_GPL(rpaphp_add_slot);
 
-- 
1.8.3.2

^ permalink raw reply related

* Re: [PATCH v2 3/4] powerpc/mpc85xx: Add FSL QorIQ DPAA BMan support to device tree(s)
From: Scott Wood @ 2014-11-24 23:45 UTC (permalink / raw)
  To: Emil Medve
  Cc: devicetree, Poonam Aggrwal, Geoff Thorpe, linuxppc-dev,
	Chunhe Lan
In-Reply-To: <1416827243-16396-4-git-send-email-Emilian.Medve@Freescale.com>

On Mon, 2014-11-24 at 05:07 -0600, Emil Medve wrote:
> From: Kumar Gala <galak@kernel.crashing.org>
> 
> Change-Id: If643fa5ba0a903aef8f5056a2c90ebecc995b760
> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
> Signed-off-by: Geoff Thorpe <Geoff.Thorpe@freescale.com>
> Signed-off-by: Hai-Ying Wang <Haiying.Wang@freescale.com>
> Signed-off-by: Chunhe Lan <Chunhe.Lan@freescale.com>
> Signed-off-by: Poonam Aggrwal <poonam.aggrwal@freescale.com>
> [Emil Medve: Sync with the upstream binding]
> Signed-off-by: Emil Medve <Emilian.Medve@Freescale.com>
> ---
>  arch/powerpc/boot/dts/b4qds.dtsi            |  20 ++-
>  arch/powerpc/boot/dts/fsl/b4860si-post.dtsi |  60 ++++++-
>  arch/powerpc/boot/dts/fsl/b4si-post.dtsi    |  84 ++++++++-
>  arch/powerpc/boot/dts/fsl/p1023si-post.dtsi |  30 +++-
>  arch/powerpc/boot/dts/fsl/p2041si-post.dtsi |   6 +-
>  arch/powerpc/boot/dts/fsl/p3041si-post.dtsi |   6 +-
>  arch/powerpc/boot/dts/fsl/p4080si-post.dtsi |   6 +-
>  arch/powerpc/boot/dts/fsl/p5020si-post.dtsi |   6 +-
>  arch/powerpc/boot/dts/fsl/p5040si-post.dtsi |   6 +-
>  arch/powerpc/boot/dts/fsl/t1040si-post.dtsi |  60 ++++++-
>  arch/powerpc/boot/dts/fsl/t2081si-post.dtsi | 100 ++++++++++-
>  arch/powerpc/boot/dts/fsl/t4240si-post.dtsi | 260 +++++++++++++++++++++++++++-
>  arch/powerpc/boot/dts/kmcoge4.dts           |  18 ++
>  arch/powerpc/boot/dts/oca4080.dts           |  18 ++
>  arch/powerpc/boot/dts/p1023rdb.dts          |  21 ++-
>  arch/powerpc/boot/dts/p2041rdb.dts          |  20 ++-
>  arch/powerpc/boot/dts/p3041ds.dts           |  20 ++-
>  arch/powerpc/boot/dts/p4080ds.dts           |  20 ++-
>  arch/powerpc/boot/dts/p5020ds.dts           |  20 ++-
>  arch/powerpc/boot/dts/p5040ds.dts           |  20 ++-
>  arch/powerpc/boot/dts/t104xqds.dtsi         |  20 ++-
>  arch/powerpc/boot/dts/t104xrdb.dtsi         |  18 ++
>  arch/powerpc/boot/dts/t208xqds.dtsi         |  20 ++-
>  arch/powerpc/boot/dts/t208xrdb.dtsi         |  18 ++
>  arch/powerpc/boot/dts/t4240qds.dts          |  20 ++-
>  arch/powerpc/boot/dts/t4240rdb.dts          |  18 ++
>  26 files changed, 893 insertions(+), 22 deletions(-)
> 
> diff --git a/arch/powerpc/boot/dts/b4qds.dtsi b/arch/powerpc/boot/dts/b4qds.dtsi
> index 6188583..3a73103 100644
> --- a/arch/powerpc/boot/dts/b4qds.dtsi
> +++ b/arch/powerpc/boot/dts/b4qds.dtsi
> @@ -1,7 +1,7 @@
>  /*
>   * B4420DS Device Tree Source
>   *
> - * Copyright 2012 Freescale Semiconductor, Inc.
> + * Copyright 2012 - 2014 Freescale Semiconductor, Inc.
>   *
>   * Redistribution and use in source and binary forms, with or without
>   * modification, are permitted provided that the following conditions are met:
> @@ -104,10 +104,28 @@
>  		device_type = "memory";
>  	};
>  
> +	reserved-memory {
> +		#address-cells = <2>;
> +		#size-cells = <2>;
> +		ranges;
> +
> +		bman_fbpr: bman-fbpr {
> +			compatible = "fsl,bman-fbpr";
> +			alloc-ranges = <0 0 0xffff 0xffffffff>;
> +			size = <0 0x1000000>;
> +			alignment = <0 0x1000000>;
> +			no-map;
> +		};

Again, I don't think this should have no-map.  It's not required by the
hardware, it doesn't perform as advertised on PPC and would be
burdensome to support on e500, we don't currently create a separate
coherence domain for it, and you haven't indicated that there's been any
benchmarks to show that using a separate coherence domain is beneficial.

Is there a reason why these reserved-memory nodes need to be repeated in
each board dts rather than being in a dtsi?

-Scott

^ permalink raw reply

* Re: [PATCH] powerpc/powernv: Cleanup unused MCE definitions/declarations.
From: Benjamin Herrenschmidt @ 2014-11-25  1:56 UTC (permalink / raw)
  To: Mahesh J Salgaonkar; +Cc: Michael Ellerman, linuxppc-dev
In-Reply-To: <20141124162829.16359.23411.stgit@mars>

On Mon, 2014-11-24 at 21:59 +0530, Mahesh J Salgaonkar wrote:
> From: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
> 
> Cleanup OpalMCE_* definitions/declarations and other related code which
> is not used anymore.
> 
> Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>

Acked-by: Benjamin Herrrenschmidt <benh@kernel.crashing.org>

> ---
>  arch/powerpc/include/asm/opal.h       |  104 ---------------------------------
>  arch/powerpc/include/asm/paca.h       |    7 --
>  arch/powerpc/kernel/asm-offsets.c     |    7 --
>  arch/powerpc/kernel/exceptions-64s.S  |   17 -----
>  arch/powerpc/platforms/powernv/opal.c |    1 
>  5 files changed, 136 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
> index 9124b0e..1c0814f0 100644
> --- a/arch/powerpc/include/asm/opal.h
> +++ b/arch/powerpc/include/asm/opal.h
> @@ -284,62 +284,6 @@ enum OpalMessageType {
>  	OPAL_MSG_TYPE_MAX,
>  };
>  
> -/* Machine check related definitions */
> -enum OpalMCE_Version {
> -	OpalMCE_V1 = 1,
> -};
> -
> -enum OpalMCE_Severity {
> -	OpalMCE_SEV_NO_ERROR = 0,
> -	OpalMCE_SEV_WARNING = 1,
> -	OpalMCE_SEV_ERROR_SYNC = 2,
> -	OpalMCE_SEV_FATAL = 3,
> -};
> -
> -enum OpalMCE_Disposition {
> -	OpalMCE_DISPOSITION_RECOVERED = 0,
> -	OpalMCE_DISPOSITION_NOT_RECOVERED = 1,
> -};
> -
> -enum OpalMCE_Initiator {
> -	OpalMCE_INITIATOR_UNKNOWN = 0,
> -	OpalMCE_INITIATOR_CPU = 1,
> -};
> -
> -enum OpalMCE_ErrorType {
> -	OpalMCE_ERROR_TYPE_UNKNOWN = 0,
> -	OpalMCE_ERROR_TYPE_UE = 1,
> -	OpalMCE_ERROR_TYPE_SLB = 2,
> -	OpalMCE_ERROR_TYPE_ERAT = 3,
> -	OpalMCE_ERROR_TYPE_TLB = 4,
> -};
> -
> -enum OpalMCE_UeErrorType {
> -	OpalMCE_UE_ERROR_INDETERMINATE = 0,
> -	OpalMCE_UE_ERROR_IFETCH = 1,
> -	OpalMCE_UE_ERROR_PAGE_TABLE_WALK_IFETCH = 2,
> -	OpalMCE_UE_ERROR_LOAD_STORE = 3,
> -	OpalMCE_UE_ERROR_PAGE_TABLE_WALK_LOAD_STORE = 4,
> -};
> -
> -enum OpalMCE_SlbErrorType {
> -	OpalMCE_SLB_ERROR_INDETERMINATE = 0,
> -	OpalMCE_SLB_ERROR_PARITY = 1,
> -	OpalMCE_SLB_ERROR_MULTIHIT = 2,
> -};
> -
> -enum OpalMCE_EratErrorType {
> -	OpalMCE_ERAT_ERROR_INDETERMINATE = 0,
> -	OpalMCE_ERAT_ERROR_PARITY = 1,
> -	OpalMCE_ERAT_ERROR_MULTIHIT = 2,
> -};
> -
> -enum OpalMCE_TlbErrorType {
> -	OpalMCE_TLB_ERROR_INDETERMINATE = 0,
> -	OpalMCE_TLB_ERROR_PARITY = 1,
> -	OpalMCE_TLB_ERROR_MULTIHIT = 2,
> -};
> -
>  enum OpalThreadStatus {
>  	OPAL_THREAD_INACTIVE = 0x0,
>  	OPAL_THREAD_STARTED = 0x1,
> @@ -452,54 +396,6 @@ struct opal_msg {
>  	__be64 params[8];
>  };
>  
> -struct opal_machine_check_event {
> -	enum OpalMCE_Version	version:8;	/* 0x00 */
> -	uint8_t			in_use;		/* 0x01 */
> -	enum OpalMCE_Severity	severity:8;	/* 0x02 */
> -	enum OpalMCE_Initiator	initiator:8;	/* 0x03 */
> -	enum OpalMCE_ErrorType	error_type:8;	/* 0x04 */
> -	enum OpalMCE_Disposition disposition:8; /* 0x05 */
> -	uint8_t			reserved_1[2];	/* 0x06 */
> -	uint64_t		gpr3;		/* 0x08 */
> -	uint64_t		srr0;		/* 0x10 */
> -	uint64_t		srr1;		/* 0x18 */
> -	union {					/* 0x20 */
> -		struct {
> -			enum OpalMCE_UeErrorType ue_error_type:8;
> -			uint8_t		effective_address_provided;
> -			uint8_t		physical_address_provided;
> -			uint8_t		reserved_1[5];
> -			uint64_t	effective_address;
> -			uint64_t	physical_address;
> -			uint8_t		reserved_2[8];
> -		} ue_error;
> -
> -		struct {
> -			enum OpalMCE_SlbErrorType slb_error_type:8;
> -			uint8_t		effective_address_provided;
> -			uint8_t		reserved_1[6];
> -			uint64_t	effective_address;
> -			uint8_t		reserved_2[16];
> -		} slb_error;
> -
> -		struct {
> -			enum OpalMCE_EratErrorType erat_error_type:8;
> -			uint8_t		effective_address_provided;
> -			uint8_t		reserved_1[6];
> -			uint64_t	effective_address;
> -			uint8_t		reserved_2[16];
> -		} erat_error;
> -
> -		struct {
> -			enum OpalMCE_TlbErrorType tlb_error_type:8;
> -			uint8_t		effective_address_provided;
> -			uint8_t		reserved_1[6];
> -			uint64_t	effective_address;
> -			uint8_t		reserved_2[16];
> -		} tlb_error;
> -	} u;
> -};
> -
>  /* FSP memory errors handling */
>  enum OpalMemErr_Version {
>  	OpalMemErr_V1 = 1,
> diff --git a/arch/powerpc/include/asm/paca.h b/arch/powerpc/include/asm/paca.h
> index a5139ea..24a386c 100644
> --- a/arch/powerpc/include/asm/paca.h
> +++ b/arch/powerpc/include/asm/paca.h
> @@ -42,7 +42,6 @@ extern unsigned int debug_smp_processor_id(void); /* from linux/smp.h */
>  #define get_slb_shadow()	(get_paca()->slb_shadow_ptr)
>  
>  struct task_struct;
> -struct opal_machine_check_event;
>  
>  /*
>   * Defines the layout of the paca.
> @@ -153,12 +152,6 @@ struct paca_struct {
>  	u64 tm_scratch;                 /* TM scratch area for reclaim */
>  #endif
>  
> -#ifdef CONFIG_PPC_POWERNV
> -	/* Pointer to OPAL machine check event structure set by the
> -	 * early exception handler for use by high level C handler
> -	 */
> -	struct opal_machine_check_event *opal_mc_evt;
> -#endif
>  #ifdef CONFIG_PPC_BOOK3S_64
>  	/* Exclusive emergency stack pointer for machine check exception. */
>  	void *mc_emergency_sp;
> diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
> index 9d7dede..c161ef3 100644
> --- a/arch/powerpc/kernel/asm-offsets.c
> +++ b/arch/powerpc/kernel/asm-offsets.c
> @@ -726,12 +726,5 @@ int main(void)
>  					arch.timing_last_enter.tv32.tbl));
>  #endif
>  
> -#ifdef CONFIG_PPC_POWERNV
> -	DEFINE(OPAL_MC_GPR3, offsetof(struct opal_machine_check_event, gpr3));
> -	DEFINE(OPAL_MC_SRR0, offsetof(struct opal_machine_check_event, srr0));
> -	DEFINE(OPAL_MC_SRR1, offsetof(struct opal_machine_check_event, srr1));
> -	DEFINE(PACA_OPAL_MC_EVT, offsetof(struct paca_struct, opal_mc_evt));
> -#endif
> -
>  	return 0;
>  }
> diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
> index 72e783e..b7a30bd 100644
> --- a/arch/powerpc/kernel/exceptions-64s.S
> +++ b/arch/powerpc/kernel/exceptions-64s.S
> @@ -1301,23 +1301,6 @@ hmi_exception_after_realmode:
>  	EXCEPTION_PROLOG_0(PACA_EXGEN)
>  	b	hmi_exception_hv
>  
> -#ifdef CONFIG_PPC_POWERNV
> -_GLOBAL(opal_mc_secondary_handler)
> -	HMT_MEDIUM_PPR_DISCARD
> -	SET_SCRATCH0(r13)
> -	GET_PACA(r13)
> -	clrldi	r3,r3,2
> -	tovirt(r3,r3)
> -	std	r3,PACA_OPAL_MC_EVT(r13)
> -	ld	r13,OPAL_MC_SRR0(r3)
> -	mtspr	SPRN_SRR0,r13
> -	ld	r13,OPAL_MC_SRR1(r3)
> -	mtspr	SPRN_SRR1,r13
> -	ld	r3,OPAL_MC_GPR3(r3)
> -	GET_SCRATCH0(r13)
> -	b	machine_check_pSeries
> -#endif /* CONFIG_PPC_POWERNV */
> -
>  
>  #define MACHINE_CHECK_HANDLER_WINDUP			\
>  	/* Clear MSR_RI before setting SRR0 and SRR1. */\
> diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c
> index d019b08..544b9b7 100644
> --- a/arch/powerpc/platforms/powernv/opal.c
> +++ b/arch/powerpc/platforms/powernv/opal.c
> @@ -50,7 +50,6 @@ static int mc_recoverable_range_len;
>  
>  struct device_node *opal_node;
>  static DEFINE_SPINLOCK(opal_write_lock);
> -extern u64 opal_mc_secondary_handler[];
>  static unsigned int *opal_irqs;
>  static unsigned int opal_irq_count;
>  static ATOMIC_NOTIFIER_HEAD(opal_notifier_head);

^ permalink raw reply

* Re: [PATCH v2] i2c: Driver to expose PowerNV platform i2c busses
From: Benjamin Herrenschmidt @ 2014-11-25  4:32 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: Neelesh Gupta, linuxppc-dev, linux-i2c
In-Reply-To: <20141124121803.GH3733@katana>

On Mon, 2014-11-24 at 13:18 +0100, Wolfram Sang wrote:
> 
> I think there are now 3 drivers in my queue which are not fully I2C
> compatible but more supporting the very minimum to, say, read an
> eeprom.
> I am not feeling well to allow them to use I2C_FUNC_I2C. So, I want to
> think about ways how to communicate deficiencies like "only 255 byte"
> or
> "only WRRD messages" to users of that I2C controller. This is most
> likely not happening before 3.19. But assistance is very welcome.

There are drivers doing that already, this is afaik common practice.

Please don't gate the merging process to some hypothetical rework that
will imply reworking also a number of user space tools and in-kernel i2c
device drivers. Basically that would mean "your platform won't be
supported upstream for the next year and btw, rewrite all userspace".

By all means let's create new "smbus" APIs for >1 bytes offset but let's
not make it a gate to merging drivers using the existing way of doing
things that has been so far perfectly functional.

Cheers,
Ben.

^ permalink raw reply

* Re: [PATCH V4 1/8] elf: Add new PowerPC specifc core note sections
From: Anshuman Khandual @ 2014-11-25  5:26 UTC (permalink / raw)
  To: Andrew Morton
  Cc: mikey, james.hogan, avagin, Paul.Clothier, peterz, palves,
	linux-kernel, oleg, dhowells, linuxppc-dev, davej, tglx, sukadev,
	davem, sam.bobroff
In-Reply-To: <20141121154310.489097fb4403d664f2156043@linux-foundation.org>

On 11/22/2014 05:13 AM, Andrew Morton wrote:
> On Tue, 11 Nov 2014 10:56:30 +0530 Anshuman Khandual <khandual@linux.vnet.ibm.com> wrote:
> 
>> This patch adds four new core note sections for PowerPC transactional
>> memory and one core note section for general miscellaneous debug registers.
>> These addition of new elf core note sections extends the existing elf ABI
>> without affecting it in any manner.
>>
>> Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
>> ---
>>  include/uapi/linux/elf.h | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
>> index ea9bf25..2260fc0 100644
>> --- a/include/uapi/linux/elf.h
>> +++ b/include/uapi/linux/elf.h
>> @@ -379,6 +379,11 @@ typedef struct elf64_shdr {
>>  #define NT_PPC_VMX	0x100		/* PowerPC Altivec/VMX registers */
>>  #define NT_PPC_SPE	0x101		/* PowerPC SPE/EVR registers */
>>  #define NT_PPC_VSX	0x102		/* PowerPC VSX registers */
>> +#define NT_PPC_TM_SPR	0x103		/* PowerPC TM special registers */
>> +#define NT_PPC_TM_CGPR	0x104		/* PowerpC TM checkpointed GPR */
>> +#define NT_PPC_TM_CFPR	0x105		/* PowerPC TM checkpointed FPR */
>> +#define NT_PPC_TM_CVMX	0x106		/* PowerPC TM checkpointed VMX */
>> +#define NT_PPC_MISC	0x107		/* PowerPC miscellaneous registers */
>>  #define NT_386_TLS	0x200		/* i386 TLS slots (struct user_desc) */
>>  #define NT_386_IOPERM	0x201		/* x86 io permission bitmap (1=deny) */
>>  #define NT_X86_XSTATE	0x202		/* x86 extended state using xsave */
> 
> ack from me, if that was at all expected.

Thanks Andrew.

> 
> Please cc Shuah Khan <shuah.kh@samsung.com> on the tools/testing/selftests
> changes.

Sure, will do.

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox