Re: [v5] powerpc/powernv: Add poweroff (EPOW, DPO) events support for PowerNV platform

2015-06-03 Thread Vipin K Parashar

Hi Michael,
  Thanks for review. Responses below

On 06/03/2015 10:43 AM, Michael Ellerman wrote:

On Mon, 2015-18-05 at 15:18:04 UTC, Vipin K Parashar wrote:

This patch adds support for FSP EPOW (Early Power Off Warning) and

Please spell out the acronyms the first time you use them, including FSP.


Will do.




DPO (Delayed Power Off) events for PowerNV platform. EPOW events are

 ^
the


the PowerNV platform.  Will edit.




generated by SPCN/FSP due to various critical system conditions that

SPCN?


Will remove SPCN. FSP should be sufficient.




need system shutdown. Few examples of these conditions are high

 ^
s/need/require/ ?   A few


Agreed.




ambient temperature or system running on UPS power with low UPS battery.
DPO event is generated in response to admin initiated system request.

Blank line between paragraphs please.


Sure




Upon receipt of EPOW and DPO events host kernel invokes

 ^
the host kernel


will edit


orderly_poweroff for performing graceful system shutdown. System admin

I like it if you spell functions with a trailing () to make it clear they are
functions, so this would be orderly_powerof().


Agreed.




can also add systemd service shutdown scripts to perform any specific
actions like graceful guest shutdown upon system poweroff. libvirt-guests
is systemd service available on recent distros for management of guests
at system start/shutdown time.

This last part about the scripts is not relevant to the kernel patch so just
leave it out please.


Agreed.




Signed-off-by: Vipin K Parashar vi...@linux.vnet.ibm.com
Reviewed-by: Joel Stanley j...@jms.id.au
Reviewed-by: Vaibhav Jain vaib...@linux.vnet.ibm.com
---
  arch/powerpc/include/asm/opal-api.h|  44 
  arch/powerpc/include/asm/opal.h|   3 +-
  arch/powerpc/platforms/powernv/opal-power.c| 147 ++---
  arch/powerpc/platforms/powernv/opal-wrappers.S |   1 +
  4 files changed, 179 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/include/asm/opal-api.h 
b/arch/powerpc/include/asm/opal-api.h
index 0321a90..90fa364 100644
--- a/arch/powerpc/include/asm/opal-api.h
+++ b/arch/powerpc/include/asm/opal-api.h
@@ -355,6 +355,10 @@ enum opal_msg_type {
OPAL_MSG_TYPE_MAX,
  };
  
+/* OPAL_MSG_SHUTDOWN parameter values */

+#defineSOFT_OFF0x00
+#defineSOFT_REBOOT 0x01

I don't see this in the skiboot version of opal-api.h ?

They should be kept in sync.

If it's a Linux only define it should go in opal.h


Agreed. Won't add these definitions to opal-api.h as its not present in 
skiboot version of opal-api.h.



  struct opal_msg {
__be32 msg_type;
__be32 reserved;
@@ -730,6 +734,46 @@ struct opal_i2c_request {
__be64 buffer_ra;   /* Buffer real address */
  };
  
+/*

+ * EPOW status sharing (OPAL and the host)
+ *
+ * The host will pass on OPAL, a buffer of length OPAL_SYSEPOW_MAX
+ * with individual elements being 16 bits wide to fetch the system
+ * wide EPOW status. Each element in the buffer will contain the
+ * EPOW status in it's bit representation for a particular EPOW sub
+ * class as defiend here. So multiple detailed EPOW status bits
+ * specific for any sub class can be represented in a single buffer
+ * element as it's bit representation.
+ */
+
+/* System EPOW type */
+enum OpalSysEpow {
+   OPAL_SYSEPOW_POWER  = 0,/* Power EPOW */
+   OPAL_SYSEPOW_TEMP   = 1,/* Temperature EPOW */
+   OPAL_SYSEPOW_COOLING= 2,/* Cooling EPOW */
+   OPAL_SYSEPOW_MAX= 3,/* Max EPOW categories */
+};
+
+/* Power EPOW */
+enum OpalSysPower {
+   OPAL_SYSPOWER_UPS   = 0x0001, /* System on UPS power */
+   OPAL_SYSPOWER_CHNG  = 0x0002, /* System power config change */
+   OPAL_SYSPOWER_FAIL  = 0x0004, /* System impending power failure */
+   OPAL_SYSPOWER_INCL  = 0x0008, /* System incomplete power */
+};
+
+/* Temperature EPOW */
+enum OpalSysTemp {
+   OPAL_SYSTEMP_AMB= 0x0001, /* System over ambient temperature */
+   OPAL_SYSTEMP_INT= 0x0002, /* System over internal temperature */
+   OPAL_SYSTEMP_HMD= 0x0004, /* System over ambient humidity */
+};
+
+/* Cooling EPOW */
+enum OpalSysCooling {
+   OPAL_SYSCOOL_INSF   = 0x0001, /* System insufficient cooling */
+};

I don't see the last three of these enums used at all, so please drop them.


OPAL_SYSPOWER_CHNG / FAIL / INCL, OPAL_SYSTEMP_HMD and OPAL_SYSCOOL_INSF
enums aren't used here but they are part of skiboot version of 
opal-api.h and

thus need to be retained.
 PKVM2.1 uses these enums and thus can't be removed from 
skiboot opal-api.h





  #endif /* __ASSEMBLY__ */
  
  #endif /* __OPAL_API_H */

diff 

Re: [PATCH v5] powerpc/powernv: Add poweroff (EPOW, DPO) events support for PowerNV platform

2015-06-02 Thread Michael Ellerman
On Tue, 2015-05-19 at 18:45 +0530, trigg wrote:
 
  On 18-May-2015, at 20:48, Vipin K Parashar vi...@linux.vnet.ibm.com wrote:
  
  This patch adds support for FSP EPOW (Early Power Off Warning) and
  DPO (Delayed Power Off) events for PowerNV platform. EPOW events are
  generated by SPCN/FSP due to various critical system conditions that
  need system shutdown. Few examples of these conditions are high
  ambient temperature or system running on UPS power with low UPS battery.
  DPO event is generated in response to admin initiated system request.
Upon receipt of EPOW and DPO events host kernel invokes
  orderly_poweroff for performing graceful system shutdown. System admin
  can also add systemd service shutdown scripts to perform any specific
  actions like graceful guest shutdown upon system poweroff. libvirt-guests
  is systemd service available on recent distros for management of guests
  at system start/shutdown time.
  
  Signed-off-by: Vipin K Parashar vi...@linux.vnet.ibm.com
 
 Acked-by: trigg mr.triggtr...@gmail.com

Please use your real name.

See: 
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/SubmittingPatches#n446

cheers


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH v5] powerpc/powernv: Add poweroff (EPOW, DPO) events support for PowerNV platform

2015-06-02 Thread Vaibhav Jain
Acked-by: Vaibhav Jain mr.triggtr...@gmail.com
Cc: Vaibhav Jain vaib...@linux.vnet.ibm.com

On Mon, May 18, 2015 at 8:48 PM, Vipin K Parashar
vi...@linux.vnet.ibm.com wrote:
 This patch adds support for FSP EPOW (Early Power Off Warning) and
 DPO (Delayed Power Off) events for PowerNV platform. EPOW events are
 generated by SPCN/FSP due to various critical system conditions that
 need system shutdown. Few examples of these conditions are high
 ambient temperature or system running on UPS power with low UPS battery.
 DPO event is generated in response to admin initiated system request.
 Upon receipt of EPOW and DPO events host kernel invokes
 orderly_poweroff for performing graceful system shutdown. System admin
 can also add systemd service shutdown scripts to perform any specific
 actions like graceful guest shutdown upon system poweroff. libvirt-guests
 is systemd service available on recent distros for management of guests
 at system start/shutdown time.

 Signed-off-by: Vipin K Parashar vi...@linux.vnet.ibm.com
 ---
  arch/powerpc/include/asm/opal-api.h|  44 
  arch/powerpc/include/asm/opal.h|   3 +-
  arch/powerpc/platforms/powernv/opal-power.c| 147 
 ++---
  arch/powerpc/platforms/powernv/opal-wrappers.S |   1 +
  4 files changed, 179 insertions(+), 16 deletions(-)

 diff --git a/arch/powerpc/include/asm/opal-api.h 
 b/arch/powerpc/include/asm/opal-api.h
 index 0321a90..90fa364 100644
 --- a/arch/powerpc/include/asm/opal-api.h
 +++ b/arch/powerpc/include/asm/opal-api.h
 @@ -355,6 +355,10 @@ enum opal_msg_type {
 OPAL_MSG_TYPE_MAX,
  };

 +/* OPAL_MSG_SHUTDOWN parameter values */
 +#defineSOFT_OFF0x00
 +#defineSOFT_REBOOT 0x01
 +
  struct opal_msg {
 __be32 msg_type;
 __be32 reserved;
 @@ -730,6 +734,46 @@ struct opal_i2c_request {
 __be64 buffer_ra;   /* Buffer real address */
  };

 +/*
 + * EPOW status sharing (OPAL and the host)
 + *
 + * The host will pass on OPAL, a buffer of length OPAL_SYSEPOW_MAX
 + * with individual elements being 16 bits wide to fetch the system
 + * wide EPOW status. Each element in the buffer will contain the
 + * EPOW status in it's bit representation for a particular EPOW sub
 + * class as defiend here. So multiple detailed EPOW status bits
 + * specific for any sub class can be represented in a single buffer
 + * element as it's bit representation.
 + */
 +
 +/* System EPOW type */
 +enum OpalSysEpow {
 +   OPAL_SYSEPOW_POWER  = 0,/* Power EPOW */
 +   OPAL_SYSEPOW_TEMP   = 1,/* Temperature EPOW */
 +   OPAL_SYSEPOW_COOLING= 2,/* Cooling EPOW */
 +   OPAL_SYSEPOW_MAX= 3,/* Max EPOW categories */
 +};
 +
 +/* Power EPOW */
 +enum OpalSysPower {
 +   OPAL_SYSPOWER_UPS   = 0x0001, /* System on UPS power */
 +   OPAL_SYSPOWER_CHNG  = 0x0002, /* System power config change */
 +   OPAL_SYSPOWER_FAIL  = 0x0004, /* System impending power failure */
 +   OPAL_SYSPOWER_INCL  = 0x0008, /* System incomplete power */
 +};
 +
 +/* Temperature EPOW */
 +enum OpalSysTemp {
 +   OPAL_SYSTEMP_AMB= 0x0001, /* System over ambient temperature 
 */
 +   OPAL_SYSTEMP_INT= 0x0002, /* System over internal temperature 
 */
 +   OPAL_SYSTEMP_HMD= 0x0004, /* System over ambient humidity */
 +};
 +
 +/* Cooling EPOW */
 +enum OpalSysCooling {
 +   OPAL_SYSCOOL_INSF   = 0x0001, /* System insufficient cooling */
 +};
 +
  #endif /* __ASSEMBLY__ */

  #endif /* __OPAL_API_H */
 diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
 index 042af1a..d30766f 100644
 --- a/arch/powerpc/include/asm/opal.h
 +++ b/arch/powerpc/include/asm/opal.h
 @@ -141,7 +141,8 @@ 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);
 +int64_t opal_get_epow_status(uint16_t *status, uint16_t *length);
 +int64_t opal_get_dpo_status(int64_t *dpo_timeout);
  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);
 diff --git a/arch/powerpc/platforms/powernv/opal-power.c 
 b/arch/powerpc/platforms/powernv/opal-power.c
 index ac46c2c..581bbd8 100644
 --- a/arch/powerpc/platforms/powernv/opal-power.c
 +++ b/arch/powerpc/platforms/powernv/opal-power.c
 @@ -1,5 +1,5 @@
  /*
 - * PowerNV OPAL power control for graceful shutdown handling
 + * PowerNV support for OPAL power-control, poweroff events
   *
   * Copyright 2015 IBM Corp.
   *
 @@ -9,18 +9,87 @@
   * 

Re: [v5] powerpc/powernv: Add poweroff (EPOW, DPO) events support for PowerNV platform

2015-06-02 Thread Michael Ellerman
On Mon, 2015-18-05 at 15:18:04 UTC, Vipin K Parashar wrote:
 This patch adds support for FSP EPOW (Early Power Off Warning) and

Please spell out the acronyms the first time you use them, including FSP.

 DPO (Delayed Power Off) events for PowerNV platform. EPOW events are
^
the

 generated by SPCN/FSP due to various critical system conditions that

SPCN?

 need system shutdown. Few examples of these conditions are high
^
s/need/require/ ?   A few

 ambient temperature or system running on UPS power with low UPS battery.
 DPO event is generated in response to admin initiated system request.

Blank line between paragraphs please.

   Upon receipt of EPOW and DPO events host kernel invokes
^
the host kernel

 orderly_poweroff for performing graceful system shutdown. System admin

I like it if you spell functions with a trailing () to make it clear they are
functions, so this would be orderly_powerof().

 can also add systemd service shutdown scripts to perform any specific
 actions like graceful guest shutdown upon system poweroff. libvirt-guests
 is systemd service available on recent distros for management of guests
 at system start/shutdown time.

This last part about the scripts is not relevant to the kernel patch so just
leave it out please.

 
 Signed-off-by: Vipin K Parashar vi...@linux.vnet.ibm.com
 Reviewed-by: Joel Stanley j...@jms.id.au
 Reviewed-by: Vaibhav Jain vaib...@linux.vnet.ibm.com
 ---
  arch/powerpc/include/asm/opal-api.h|  44 
  arch/powerpc/include/asm/opal.h|   3 +-
  arch/powerpc/platforms/powernv/opal-power.c| 147 
 ++---
  arch/powerpc/platforms/powernv/opal-wrappers.S |   1 +
  4 files changed, 179 insertions(+), 16 deletions(-)
 
 diff --git a/arch/powerpc/include/asm/opal-api.h 
 b/arch/powerpc/include/asm/opal-api.h
 index 0321a90..90fa364 100644
 --- a/arch/powerpc/include/asm/opal-api.h
 +++ b/arch/powerpc/include/asm/opal-api.h
 @@ -355,6 +355,10 @@ enum opal_msg_type {
   OPAL_MSG_TYPE_MAX,
  };
  
 +/* OPAL_MSG_SHUTDOWN parameter values */
 +#define  SOFT_OFF0x00
 +#define  SOFT_REBOOT 0x01

I don't see this in the skiboot version of opal-api.h ?

They should be kept in sync.

If it's a Linux only define it should go in opal.h

  struct opal_msg {
   __be32 msg_type;
   __be32 reserved;
 @@ -730,6 +734,46 @@ struct opal_i2c_request {
   __be64 buffer_ra;   /* Buffer real address */
  };
  
 +/*
 + * EPOW status sharing (OPAL and the host)
 + *
 + * The host will pass on OPAL, a buffer of length OPAL_SYSEPOW_MAX
 + * with individual elements being 16 bits wide to fetch the system
 + * wide EPOW status. Each element in the buffer will contain the
 + * EPOW status in it's bit representation for a particular EPOW sub
 + * class as defiend here. So multiple detailed EPOW status bits
 + * specific for any sub class can be represented in a single buffer
 + * element as it's bit representation.
 + */
 +
 +/* System EPOW type */
 +enum OpalSysEpow {
 + OPAL_SYSEPOW_POWER  = 0,/* Power EPOW */
 + OPAL_SYSEPOW_TEMP   = 1,/* Temperature EPOW */
 + OPAL_SYSEPOW_COOLING= 2,/* Cooling EPOW */
 + OPAL_SYSEPOW_MAX= 3,/* Max EPOW categories */
 +};
 +
 +/* Power EPOW */
 +enum OpalSysPower {
 + OPAL_SYSPOWER_UPS   = 0x0001, /* System on UPS power */
 + OPAL_SYSPOWER_CHNG  = 0x0002, /* System power config change */
 + OPAL_SYSPOWER_FAIL  = 0x0004, /* System impending power failure */
 + OPAL_SYSPOWER_INCL  = 0x0008, /* System incomplete power */
 +};
 +
 +/* Temperature EPOW */
 +enum OpalSysTemp {
 + OPAL_SYSTEMP_AMB= 0x0001, /* System over ambient temperature */
 + OPAL_SYSTEMP_INT= 0x0002, /* System over internal temperature */
 + OPAL_SYSTEMP_HMD= 0x0004, /* System over ambient humidity */
 +};
 +
 +/* Cooling EPOW */
 +enum OpalSysCooling {
 + OPAL_SYSCOOL_INSF   = 0x0001, /* System insufficient cooling */
 +};

I don't see the last three of these enums used at all, so please drop them.

  #endif /* __ASSEMBLY__ */
  
  #endif /* __OPAL_API_H */
 diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
 index 042af1a..d30766f 100644
 --- a/arch/powerpc/include/asm/opal.h
 +++ b/arch/powerpc/include/asm/opal.h
 @@ -141,7 +141,8 @@ 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);
 +int64_t 

Re: [PATCH v5] powerpc/powernv: Add poweroff (EPOW, DPO) events support for PowerNV platform

2015-06-01 Thread Vipin K Parashar

Hi Michael,
 Please add below minor additions in commit log once u
accept this patch. Thanks for your help with this. Let me know,
if anything else is needed from me on this.

Regards,
Vipin

On 05/18/2015 08:48 PM, Vipin K Parashar wrote:

This patch adds support for FSP EPOW (Early Power Off Warning) and
DPO (Delayed Power Off) events for PowerNV platform. EPOW events are
generated by SPCN/FSP due to various critical system conditions that
need system shutdown. Few examples of these conditions are high
ambient temperature or system running on UPS power with low UPS battery.
DPO event is generated in response to admin initiated system request.


s/system request/shutdown request/


Upon receipt of EPOW and DPO events host kernel invokes
orderly_poweroff for performing graceful system shutdown. System admin
can also add systemd service shutdown scripts to perform any specific
actions like graceful guest shutdown upon system poweroff. libvirt-guests
is systemd service available on recent distros for management of guests
at system start/shutdown time.

Signed-off-by: Vipin K Parashar vi...@linux.vnet.ibm.com


Reviewed-by: Joel Stanley j...@jms.id.au
Reviewed-by: Vaibhav Jain vaib...@linux.vnet.ibm.com


---
  arch/powerpc/include/asm/opal-api.h|  44 
  arch/powerpc/include/asm/opal.h|   3 +-
  arch/powerpc/platforms/powernv/opal-power.c| 147 ++---
  arch/powerpc/platforms/powernv/opal-wrappers.S |   1 +
  4 files changed, 179 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/include/asm/opal-api.h 
b/arch/powerpc/include/asm/opal-api.h
index 0321a90..90fa364 100644
--- a/arch/powerpc/include/asm/opal-api.h
+++ b/arch/powerpc/include/asm/opal-api.h
@@ -355,6 +355,10 @@ enum opal_msg_type {
OPAL_MSG_TYPE_MAX,
  };

+/* OPAL_MSG_SHUTDOWN parameter values */
+#defineSOFT_OFF0x00
+#defineSOFT_REBOOT 0x01
+
  struct opal_msg {
__be32 msg_type;
__be32 reserved;
@@ -730,6 +734,46 @@ struct opal_i2c_request {
__be64 buffer_ra;   /* Buffer real address */
  };

+/*
+ * EPOW status sharing (OPAL and the host)
+ *
+ * The host will pass on OPAL, a buffer of length OPAL_SYSEPOW_MAX
+ * with individual elements being 16 bits wide to fetch the system
+ * wide EPOW status. Each element in the buffer will contain the
+ * EPOW status in it's bit representation for a particular EPOW sub
+ * class as defiend here. So multiple detailed EPOW status bits
+ * specific for any sub class can be represented in a single buffer
+ * element as it's bit representation.
+ */
+
+/* System EPOW type */
+enum OpalSysEpow {
+   OPAL_SYSEPOW_POWER  = 0,/* Power EPOW */
+   OPAL_SYSEPOW_TEMP   = 1,/* Temperature EPOW */
+   OPAL_SYSEPOW_COOLING= 2,/* Cooling EPOW */
+   OPAL_SYSEPOW_MAX= 3,/* Max EPOW categories */
+};
+
+/* Power EPOW */
+enum OpalSysPower {
+   OPAL_SYSPOWER_UPS   = 0x0001, /* System on UPS power */
+   OPAL_SYSPOWER_CHNG  = 0x0002, /* System power config change */
+   OPAL_SYSPOWER_FAIL  = 0x0004, /* System impending power failure */
+   OPAL_SYSPOWER_INCL  = 0x0008, /* System incomplete power */
+};
+
+/* Temperature EPOW */
+enum OpalSysTemp {
+   OPAL_SYSTEMP_AMB= 0x0001, /* System over ambient temperature */
+   OPAL_SYSTEMP_INT= 0x0002, /* System over internal temperature */
+   OPAL_SYSTEMP_HMD= 0x0004, /* System over ambient humidity */
+};
+
+/* Cooling EPOW */
+enum OpalSysCooling {
+   OPAL_SYSCOOL_INSF   = 0x0001, /* System insufficient cooling */
+};
+
  #endif /* __ASSEMBLY__ */

  #endif /* __OPAL_API_H */
diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 042af1a..d30766f 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -141,7 +141,8 @@ 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);
+int64_t opal_get_epow_status(uint16_t *status, uint16_t *length);
+int64_t opal_get_dpo_status(int64_t *dpo_timeout);
  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);
diff --git a/arch/powerpc/platforms/powernv/opal-power.c 
b/arch/powerpc/platforms/powernv/opal-power.c
index ac46c2c..581bbd8 100644
--- a/arch/powerpc/platforms/powernv/opal-power.c
+++ b/arch/powerpc/platforms/powernv/opal-power.c
@@ -1,5 +1,5 @@
  /*
- * PowerNV OPAL power control for graceful shutdown handling
+ 

Re: [PATCH v5] powerpc/powernv: Add poweroff (EPOW, DPO) events support for PowerNV platform

2015-05-19 Thread trigg


 On 18-May-2015, at 20:48, Vipin K Parashar vi...@linux.vnet.ibm.com wrote:
 
 This patch adds support for FSP EPOW (Early Power Off Warning) and
 DPO (Delayed Power Off) events for PowerNV platform. EPOW events are
 generated by SPCN/FSP due to various critical system conditions that
 need system shutdown. Few examples of these conditions are high
 ambient temperature or system running on UPS power with low UPS battery.
 DPO event is generated in response to admin initiated system request.
   Upon receipt of EPOW and DPO events host kernel invokes
 orderly_poweroff for performing graceful system shutdown. System admin
 can also add systemd service shutdown scripts to perform any specific
 actions like graceful guest shutdown upon system poweroff. libvirt-guests
 is systemd service available on recent distros for management of guests
 at system start/shutdown time.
 
 Signed-off-by: Vipin K Parashar vi...@linux.vnet.ibm.com

Acked-by: trigg mr.triggtr...@gmail.com
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH v5] powerpc/powernv: Add poweroff (EPOW, DPO) events support for PowerNV platform

2015-05-18 Thread Vipin K Parashar
This patch adds support for FSP EPOW (Early Power Off Warning) and
DPO (Delayed Power Off) events for PowerNV platform. EPOW events are
generated by SPCN/FSP due to various critical system conditions that
need system shutdown. Few examples of these conditions are high
ambient temperature or system running on UPS power with low UPS battery.
DPO event is generated in response to admin initiated system request.
Upon receipt of EPOW and DPO events host kernel invokes
orderly_poweroff for performing graceful system shutdown. System admin
can also add systemd service shutdown scripts to perform any specific
actions like graceful guest shutdown upon system poweroff. libvirt-guests
is systemd service available on recent distros for management of guests
at system start/shutdown time.

Signed-off-by: Vipin K Parashar vi...@linux.vnet.ibm.com
---
 arch/powerpc/include/asm/opal-api.h|  44 
 arch/powerpc/include/asm/opal.h|   3 +-
 arch/powerpc/platforms/powernv/opal-power.c| 147 ++---
 arch/powerpc/platforms/powernv/opal-wrappers.S |   1 +
 4 files changed, 179 insertions(+), 16 deletions(-)

diff --git a/arch/powerpc/include/asm/opal-api.h 
b/arch/powerpc/include/asm/opal-api.h
index 0321a90..90fa364 100644
--- a/arch/powerpc/include/asm/opal-api.h
+++ b/arch/powerpc/include/asm/opal-api.h
@@ -355,6 +355,10 @@ enum opal_msg_type {
OPAL_MSG_TYPE_MAX,
 };
 
+/* OPAL_MSG_SHUTDOWN parameter values */
+#defineSOFT_OFF0x00
+#defineSOFT_REBOOT 0x01
+
 struct opal_msg {
__be32 msg_type;
__be32 reserved;
@@ -730,6 +734,46 @@ struct opal_i2c_request {
__be64 buffer_ra;   /* Buffer real address */
 };
 
+/*
+ * EPOW status sharing (OPAL and the host)
+ *
+ * The host will pass on OPAL, a buffer of length OPAL_SYSEPOW_MAX
+ * with individual elements being 16 bits wide to fetch the system
+ * wide EPOW status. Each element in the buffer will contain the
+ * EPOW status in it's bit representation for a particular EPOW sub
+ * class as defiend here. So multiple detailed EPOW status bits
+ * specific for any sub class can be represented in a single buffer
+ * element as it's bit representation.
+ */
+
+/* System EPOW type */
+enum OpalSysEpow {
+   OPAL_SYSEPOW_POWER  = 0,/* Power EPOW */
+   OPAL_SYSEPOW_TEMP   = 1,/* Temperature EPOW */
+   OPAL_SYSEPOW_COOLING= 2,/* Cooling EPOW */
+   OPAL_SYSEPOW_MAX= 3,/* Max EPOW categories */
+};
+
+/* Power EPOW */
+enum OpalSysPower {
+   OPAL_SYSPOWER_UPS   = 0x0001, /* System on UPS power */
+   OPAL_SYSPOWER_CHNG  = 0x0002, /* System power config change */
+   OPAL_SYSPOWER_FAIL  = 0x0004, /* System impending power failure */
+   OPAL_SYSPOWER_INCL  = 0x0008, /* System incomplete power */
+};
+
+/* Temperature EPOW */
+enum OpalSysTemp {
+   OPAL_SYSTEMP_AMB= 0x0001, /* System over ambient temperature */
+   OPAL_SYSTEMP_INT= 0x0002, /* System over internal temperature */
+   OPAL_SYSTEMP_HMD= 0x0004, /* System over ambient humidity */
+};
+
+/* Cooling EPOW */
+enum OpalSysCooling {
+   OPAL_SYSCOOL_INSF   = 0x0001, /* System insufficient cooling */
+};
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* __OPAL_API_H */
diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index 042af1a..d30766f 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -141,7 +141,8 @@ 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);
+int64_t opal_get_epow_status(uint16_t *status, uint16_t *length);
+int64_t opal_get_dpo_status(int64_t *dpo_timeout);
 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);
diff --git a/arch/powerpc/platforms/powernv/opal-power.c 
b/arch/powerpc/platforms/powernv/opal-power.c
index ac46c2c..581bbd8 100644
--- a/arch/powerpc/platforms/powernv/opal-power.c
+++ b/arch/powerpc/platforms/powernv/opal-power.c
@@ -1,5 +1,5 @@
 /*
- * PowerNV OPAL power control for graceful shutdown handling
+ * PowerNV support for OPAL power-control, poweroff events
  *
  * Copyright 2015 IBM Corp.
  *
@@ -9,18 +9,87 @@
  * 2 of the License, or (at your option) any later version.
  */
 
+#define pr_fmt(fmt)OPAL-POWER:   fmt
+
 #include linux/kernel.h
+#include linux/spinlock.h
+#include linux/timer.h
 #include linux/reboot.h
-#include linux/notifier.h
-
+#include linux/of.h
 #include asm/opal.h