powerpc/powernv: Poweroff (EPOW, DPO) events support for PowerNV platform
PATCH v5 1/1 powerpc/powernv: Poweroff (EPOW, DPO) events support for PowerNV platform
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 shutdown request.
Upon receipt of EPOW and DPO events host kernel invokesorderly_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.
Changes in v5:
- Made changes to address review comments on previous patch.
Changes in v4:
- Made changes to address review comments on previous patch.
Changes in v3:
- Made changes to immediately call orderly_poweroff upon receipt of OPAL EPOW, DPO notifications.
- Made code changes to address review comments on previous patch.
- Made code changes to use existing OPAL EPOW API.
- Removed patch to extract EPOW event timeout from OPAL device-tree.
Changes in v2:
- Made code changes to improve code as per previous review comments.
- Added patch to obtain EPOW event timeout values from OPAL device-tree.
Vipin K Parashar (1):
powerpc/powernv: Add poweroff (EPOW, DPO) events support for PowerNV
platform
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(-)
Signature · 1 line
1.9.3
PATCH v5 1/1 powerpc/powernv: Add poweroff (EPOW, DPO) events support for PowerNV platform
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 invokesorderly_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.
--- 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(-)
arch/powerpc/include/asm/opal-api.h +44 -0
@@ -355,6 +355,10 @@ enum opal_msg_type { OPAL_MSG_TYPE_MAX, }; +/* OPAL_MSG_SHUTDOWN parameter values */ +#define SOFT_OFF 0x00 +#define SOFT_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 */
arch/powerpc/include/asm/opal.h +2 -1
@@ -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);
arch/powerpc/platforms/powernv/opal-power.c +132 -15
191 lines not on this page · raw message
arch/powerpc/platforms/powernv/opal-wrappers.S +1 -0
@@ -249,6 +249,7 @@ 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); +OPAL_CALL(opal_get_dpo_status, OPAL_GET_DPO_STATUS); OPAL_CALL(opal_set_system_attention_led, OPAL_SET_SYSTEM_ATTENTION_LED); OPAL_CALL(opal_pci_next_error, OPAL_PCI_NEXT_ERROR); OPAL_CALL(opal_pci_poll, OPAL_PCI_POLL);
Signature · 1 line
1.9.3
Re: [PATCH v5] powerpc/powernv: Add poweroff (EPOW, DPO) events support for PowerNV platform
Quoted 3 lines
On 18-May-2015, at 20:48, Vipin K Parashar <[email protected]> wrot=
e:
Quoted 14 lines
=20
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 invokesorderly_powerofffor 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.
=20
Quoted 1 line
Signed-off-by Vipin K Parashar <[email protected]>
Michael Ellerman
reviewerRe: [PATCH v5] powerpc/powernv: Add poweroff (EPOW, DPO) events support for PowerNV platform
Quoted 16 lines · trigg
Quoted 16 lines · 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 invokesorderly_powerofffor 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.
Quoted 3 lines
Quoted 1 line
Signed-off-by Vipin K Parashar <[email protected]>Acked-by trigg <[email protected]>
Please use your real name.
cheers
Re: [PATCH v5] powerpc/powernv: Add poweroff (EPOW, DPO) events support for PowerNV platform
In reply to Vipin K ParasharHi 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
Quoted 6 lines · 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.
s/system request/shutdown request/
Quoted 8 lines
Upon receipt of EPOW and DPO events host kernel invokes
orderly_powerofffor 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 <[email protected]>
Quoted 294 lines
--- 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(-)arch/powerpc/include/asm/opal-api.h +44
-0@@ -355,6 +355,10 @@ enum opal_msg_type { OPAL_MSG_TYPE_MAX, }; +/* OPAL_MSG_SHUTDOWN parameter values */ +#define SOFT_OFF 0x00 +#define SOFT_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 */ arch/powerpc/include/asm/opal.h +2
-1@@ -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);arch/powerpc/platforms/powernv/opal-power.c +132
-15@@ -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> #include <asm/machdep.h> -#define SOFT_OFF 0x00 -#define SOFT_REBOOT 0x01 +/* Get EPOW status */ +static bool get_epow_status (void ) +{ +int i; +u16 num_classes; +__be16 epow_classes; +__be16 opal_epow_status[OPAL_SYSEPOW_MAX ] = {0 }; + +/* Send kernel EPOW classes supported info to OPAL */ + epow_classes =cpu_to_be16 (OPAL_SYSEPOW_MAX ); + +/* Get EPOW events information from OPAL */ +opal_get_epow_status (opal_epow_status, &epow_classes); + +/* Look for EPOW events present */ + num_classes =be16_to_cpu (epow_classes); +for (i =0 ; i < num_classes; i++) { +if (be16_to_cpu (opal_epow_status[i])) +return true; + } + +return false; +} + +/* Process existing EPOW, DPO events */ +static void process_existing_poweroff_events (void ) +{ +int rc; +__be64 opal_dpo_timeout; +/* Check for DPO event */ + rc =opal_get_dpo_status (&opal_dpo_timeout); +if (rc !=OPAL_WRONG_STATE ) { +pr_info ("Existing DPO event detected. Powering off system\n" ); + goto poweroff; + } + +/* Check for EPOW event */ +if (get_epow_status ()) { +pr_info ("Existing EPOW event detected. Powering off system" ); + goto poweroff; + } +return ; + +poweroff: +orderly_poweroff (true); +} + +/* OPAL EPOW, DPO event notifier */ +static int opal_epow_dpo_event (struct notifier_block *nb, +unsigned long msg_type,void *msg) +{ +switch (msg_type) { +case OPAL_MSG_EPOW : +pr_info ("EPOW msg received. Powering off system\n" ); +break ; +case OPAL_MSG_DPO : +pr_info ("DPO msg received. Powering off system\n" ); +break ; +default : +pr_err ("Unknown message type %lu\n" , msg_type); +return 0 ; + } + +orderly_poweroff (true); +return 0 ; +} + +/* OPAL power-control events notifier */ static int opal_power_control_event (struct notifier_block *nb, -unsigned long msg_type,void *msg) +unsigned long msg_type,void *msg) {struct opal_msg *power_msg = msg;uint64_t type;@@ -29,20 +98,35 @@ static int opal_power_control_event(struct notifier_block *nb,switch (type) {case SOFT_REBOOT : -pr_info ("OPAL: reboot requested\n" ); +pr_info ("Reboot requested\n" );orderly_reboot ();break ;case SOFT_OFF : -pr_info ("OPAL: poweroff requested\n" ); +pr_info ("Poweroff requested\n" );orderly_poweroff (true);break ;default : -pr_err ("OPAL: power control type unexpected %016llx\n" , type); +pr_err ("Unknown power-control type %llu\n" , type); }return 0 ; } +/* OPAL EPOW event notifier block */ +static struct notifier_block opal_epow_nb = { + .notifier_call = opal_epow_dpo_event, + .next =NULL , + .priority =0 , +}; + +/* OPAL DPO event notifier block */ +static struct notifier_block opal_dpo_nb = { + .notifier_call = opal_epow_dpo_event, + .next =NULL , + .priority =0 , +}; + +/* OPAL power-control event notifier block */ static struct notifier_block opal_power_control_nb = { .notifier_call = opal_power_control_event, .next =NULL ,@@ -51,16 +135,49 @@ static struct notifier_block opal_power_control_nb = {static int __init opal_power_control_init (void ) { -int ret; +int ret, epow_dpo_supported =0 ; +struct device_node *node_epow; +/* Register OPAL power-control events notifier */ ret =opal_message_notifier_register (OPAL_MSG_SHUTDOWN , - &opal_power_control_nb); -if (ret) { -pr_err ("%s: Can't register OPAL event notifier (%d)\n" , - __func__, ret); -return ret; + &opal_power_control_nb); +if (ret) +pr_err ("Power-control events notifier registration " +"failed, ret = %d\n" , ret); + +/* Determine EPOW, DPO support in hardware. */ + node_epow =of_find_node_by_path ("/ibm,opal/epow" ); +if (node_epow) { + epow_dpo_supported =of_device_is_compatible (node_epow, +"ibm,opal-v3-epow" ); +of_node_put (node_epow); } +if (epow_dpo_supported) +pr_info ("OPAL EPOW, DPO support detected.\n" ); +else +return 0 ; + +/* Register EPOW event notifier */ + ret =opal_message_notifier_register (OPAL_MSG_EPOW , + &opal_epow_nb); +if (ret) +pr_err ("EPOW event notifier registration failed, " +"ret = %d\n" , ret); + +/* Register DPO event notifier */ + ret =opal_message_notifier_register (OPAL_MSG_DPO , + &opal_dpo_nb); +if (ret) +pr_err ("DPO event notifier registration failed, " +"ret = %d\n" , ret); + +/* Check for any existing EPOW or DPO events. */ +process_existing_poweroff_events (); + +pr_info ("Poweroff events support initialized\n" ); +return 0 ; } +machine_subsys_initcall (powernv, opal_power_control_init);arch/powerpc/platforms/powernv/opal-wrappers.S +1
-0@@ -249,6 +249,7 @@ 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); +OPAL_CALL(opal_get_dpo_status, OPAL_GET_DPO_STATUS); OPAL_CALL(opal_set_system_attention_led, OPAL_SET_SYSTEM_ATTENTION_LED); OPAL_CALL(opal_pci_next_error, OPAL_PCI_NEXT_ERROR); OPAL_CALL(opal_pci_poll, OPAL_PCI_POLL);
Re: [PATCH v5] powerpc/powernv: Add poweroff (EPOW, DPO) events support for PowerNV platform
In reply to Vipin K ParasharQuoted 315 lines · 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 invokesorderly_powerofffor 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 <[email protected]>--- 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(-)arch/powerpc/include/asm/opal-api.h +44
-0@@ -355,6 +355,10 @@ enum opal_msg_type { OPAL_MSG_TYPE_MAX, }; +/* OPAL_MSG_SHUTDOWN parameter values */ +#define SOFT_OFF 0x00 +#define SOFT_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 */ arch/powerpc/include/asm/opal.h +2
-1@@ -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);arch/powerpc/platforms/powernv/opal-power.c +132
-15@@ -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> #include <asm/machdep.h> -#define SOFT_OFF 0x00 -#define SOFT_REBOOT 0x01 +/* Get EPOW status */ +static bool get_epow_status (void ) +{ +int i; +u16 num_classes; +__be16 epow_classes; +__be16 opal_epow_status[OPAL_SYSEPOW_MAX ] = {0 }; + +/* Send kernel EPOW classes supported info to OPAL */ + epow_classes =cpu_to_be16 (OPAL_SYSEPOW_MAX ); + +/* Get EPOW events information from OPAL */ +opal_get_epow_status (opal_epow_status, &epow_classes); + +/* Look for EPOW events present */ + num_classes =be16_to_cpu (epow_classes); +for (i =0 ; i < num_classes; i++) { +if (be16_to_cpu (opal_epow_status[i])) +return true; + } + +return false; +} + +/* Process existing EPOW, DPO events */ +static void process_existing_poweroff_events (void ) +{ +int rc; +__be64 opal_dpo_timeout; +/* Check for DPO event */ + rc =opal_get_dpo_status (&opal_dpo_timeout); +if (rc !=OPAL_WRONG_STATE ) { +pr_info ("Existing DPO event detected. Powering off system\n" ); + goto poweroff; + } + +/* Check for EPOW event */ +if (get_epow_status ()) { +pr_info ("Existing EPOW event detected. Powering off system" ); + goto poweroff; + } +return ; + +poweroff: +orderly_poweroff (true); +} + +/* OPAL EPOW, DPO event notifier */ +static int opal_epow_dpo_event (struct notifier_block *nb, +unsigned long msg_type,void *msg) +{ +switch (msg_type) { +case OPAL_MSG_EPOW : +pr_info ("EPOW msg received. Powering off system\n" ); +break ; +case OPAL_MSG_DPO : +pr_info ("DPO msg received. Powering off system\n" ); +break ; +default : +pr_err ("Unknown message type %lu\n" , msg_type); +return 0 ; + } + +orderly_poweroff (true); +return 0 ; +} + +/* OPAL power-control events notifier */ static int opal_power_control_event (struct notifier_block *nb, -unsigned long msg_type,void *msg) +unsigned long msg_type,void *msg) {struct opal_msg *power_msg = msg;uint64_t type;@@ -29,20 +98,35 @@ static int opal_power_control_event(struct notifier_block *nb,switch (type) {case SOFT_REBOOT : -pr_info ("OPAL: reboot requested\n" ); +pr_info ("Reboot requested\n" );orderly_reboot ();break ;case SOFT_OFF : -pr_info ("OPAL: poweroff requested\n" ); +pr_info ("Poweroff requested\n" );orderly_poweroff (true);break ;default : -pr_err ("OPAL: power control type unexpected %016llx\n" , type); +pr_err ("Unknown power-control type %llu\n" , type); }return 0 ; } +/* OPAL EPOW event notifier block */ +static struct notifier_block opal_epow_nb = { + .notifier_call = opal_epow_dpo_event, + .next =NULL , + .priority =0 , +}; + +/* OPAL DPO event notifier block */ +static struct notifier_block opal_dpo_nb = { + .notifier_call = opal_epow_dpo_event, + .next =NULL , + .priority =0 , +}; + +/* OPAL power-control event notifier block */ static struct notifier_block opal_power_control_nb = { .notifier_call = opal_power_control_event, .next =NULL ,@@ -51,16 +135,49 @@ static struct notifier_block opal_power_control_nb = {static int __init opal_power_control_init (void ) { -int ret; +int ret, epow_dpo_supported =0 ; +struct device_node *node_epow; +/* Register OPAL power-control events notifier */ ret =opal_message_notifier_register (OPAL_MSG_SHUTDOWN , - &opal_power_control_nb); -if (ret) { -pr_err ("%s: Can't register OPAL event notifier (%d)\n" , - __func__, ret); -return ret; + &opal_power_control_nb); +if (ret) +pr_err ("Power-control events notifier registration " +"failed, ret = %d\n" , ret); + +/* Determine EPOW, DPO support in hardware. */ + node_epow =of_find_node_by_path ("/ibm,opal/epow" ); +if (node_epow) { + epow_dpo_supported =of_device_is_compatible (node_epow, +"ibm,opal-v3-epow" ); +of_node_put (node_epow); } +if (epow_dpo_supported) +pr_info ("OPAL EPOW, DPO support detected.\n" ); +else +return 0 ; + +/* Register EPOW event notifier */ + ret =opal_message_notifier_register (OPAL_MSG_EPOW , + &opal_epow_nb); +if (ret) +pr_err ("EPOW event notifier registration failed, " +"ret = %d\n" , ret); + +/* Register DPO event notifier */ + ret =opal_message_notifier_register (OPAL_MSG_DPO , + &opal_dpo_nb); +if (ret) +pr_err ("DPO event notifier registration failed, " +"ret = %d\n" , ret); + +/* Check for any existing EPOW or DPO events. */ +process_existing_poweroff_events (); + +pr_info ("Poweroff events support initialized\n" ); +return 0 ; } +machine_subsys_initcall (powernv, opal_power_control_init);arch/powerpc/platforms/powernv/opal-wrappers.S +1
-1@@ -249,6 +249,7 @@ 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); +OPAL_CALL(opal_get_dpo_status, OPAL_GET_DPO_STATUS); OPAL_CALL(opal_set_system_attention_led, OPAL_SET_SYSTEM_ATTENTION_LED); OPAL_CALL(opal_pci_next_error, OPAL_PCI_NEXT_ERROR); OPAL_CALL(opal_pci_poll, OPAL_PCI_POLL); --1.9.3
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
Michael Ellerman
reviewerRe: [v5] powerpc/powernv: Add poweroff (EPOW, DPO) events support for PowerNV platform
In reply to Vipin K ParasharQuoted 1 line · Vipin K Parashar
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.
Quoted 1 line
DPO (Delayed Power Off) events for PowerNV platform. EPOW events are
^ the
Quoted 1 line
generated by SPCN/FSP due to various critical system conditions that
SPCN?
Quoted 1 line
need system shutdown. Few examples of these conditions are high
^
s/need/require/ ? A few
Quoted 2 lines
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.
Quoted 1 line
Upon receipt of EPOW and DPO events host kernel invokes
^
the host kernel
Quoted 1 line
orderly_powerofffor 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()".
Quoted 4 lines
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.
Quoted 16 lines
Signed-off-by Vipin K Parashar <[email protected]>Reviewed-by Joel Stanley <[email protected]>Reviewed-by Vaibhav Jain <[email protected]>--- 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(-)arch/powerpc/include/asm/opal-api.h +0
-0
arch/powerpc/include/asm/opal-api.h enum opal_msg_type { · line 360
Quoted 6 lines
arch/powerpc/include/asm/opal-api.h +3
-0@@ -355,6 +355,10 @@ enum opal_msg_type { OPAL_MSG_TYPE_MAX, }; +/* OPAL_MSG_SHUTDOWN parameter values */ +#define SOFT_OFF 0x00 +#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
Quoted 36 lines
arch/powerpc/include/asm/opal-api.h +29
-0struct 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 */
arch/powerpc/include/asm/opal-api.h struct opal_i2c_request { · line 775
Quoted 10 lines
arch/powerpc/include/asm/opal-api.h +10
-0+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.
arch/powerpc/include/asm/opal.h int64_t opal_pci_fence_phb(uint64_t phb_id); · line 144
Quoted 13 lines
arch/powerpc/include/asm/opal-api.h +0
-0#endif /* __ASSEMBLY__ */ #endif /* __OPAL_API_H */ arch/powerpc/include/asm/opal.h +1
-1@@ -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);
Has the signature of this function really changed or was it just wrong before?
If it's changed how do we know we're running on a version of OPAL that supports the two argument version?
The parameter names don't seem very clear either. status is actually a pointer to an array of "statuses", and length is the number of entries in that array.
Also you removed the endian annotations but then you pass it __be16 values, so that looks incorrect, you should be using __be16 here.
arch/powerpc/include/asm/opal.h int64_t opal_pci_fence_phb(uint64_t phb_id); · line 145
Quoted 1 line
arch/powerpc/include/asm/opal.h +1
-0+int64_t opal_get_dpo_status (int64_t *dpo_timeout);
Similarly this should be __be64 AFAICS.
Quoted 12 lines
arch/powerpc/platforms/powernv/opal-power.c +1
-1@@ -1,5 +1,5 @@/* -* PowerNV OPAL power control for graceful shutdown handling +* PowerNV support for OPAL power-control, poweroff events * * Copyright 2015 IBM Corp. *
arch/powerpc/platforms/powernv/opal-power.c line 12
Quoted 4 lines
arch/powerpc/platforms/powernv/opal-power.c +1
-0@@ -9,18 +9,87 @@* 2 of the License, or (at your option) any later version. */ +#define pr_fmt (fmt) "OPAL-POWER: " fmt
Please don't shout, "opal-power" is fine.
arch/powerpc/platforms/powernv/opal-power.c line 16
Quoted 3 lines
arch/powerpc/platforms/powernv/opal-power.c +2
-0#include <linux/kernel.h> +#include <linux/spinlock.h> +#include <linux/timer.h>
Don't think you need those?
arch/powerpc/platforms/powernv/opal-power.c line 15
Quoted 3 lines
arch/powerpc/platforms/powernv/opal-power.c +0
-2#include <linux/reboot.h> -#include <linux/notifier.h> -
I think you DO need notifier.h.
arch/powerpc/platforms/powernv/opal-power.c line 23
Quoted 8 lines
arch/powerpc/platforms/powernv/opal-power.c +3
-2+#include <linux/of.h> #include <asm/opal.h> #include <asm/machdep.h> -#define SOFT_OFF 0x00 -#define SOFT_REBOOT 0x01 +/* Get EPOW status */ +static bool get_epow_status (void )
This is not a great name, "get" implies it gives you something back, but it doesn't it just tells you true or false.
So maybe epow_event_pending() ?
arch/powerpc/platforms/powernv/opal-power.c line 27
Quoted 4 lines
arch/powerpc/platforms/powernv/opal-power.c +4
-0+{ +int i; +u16 num_classes; +__be16 epow_classes;
I think this would be cleaner if you just had a single num_classes and you endian swap in the one place you use it.
arch/powerpc/platforms/powernv/opal-power.c line 34
Quoted 7 lines
arch/powerpc/platforms/powernv/opal-power.c +7
-0+__be16 opal_epow_status[OPAL_SYSEPOW_MAX ] = {0 }; + +/* Send kernel EPOW classes supported info to OPAL */ + epow_classes =cpu_to_be16 (OPAL_SYSEPOW_MAX ); + +/* Get EPOW events information from OPAL */ +opal_get_epow_status (opal_epow_status, &epow_classes);
This could fail.
Quoted 23 lines
arch/powerpc/platforms/powernv/opal-power.c +22
-0+ +/* Look for EPOW events present */ + num_classes =be16_to_cpu (epow_classes); +for (i =0 ; i < num_classes; i++) { +if (be16_to_cpu (opal_epow_status[i])) +return true; + } + +return false; +} + +/* Process existing EPOW, DPO events */ +static void process_existing_poweroff_events (void ) +{ +int rc; +__be64 opal_dpo_timeout; +/* Check for DPO event */ + rc =opal_get_dpo_status (&opal_dpo_timeout); +if (rc !=OPAL_WRONG_STATE ) { +pr_info ("Existing DPO event detected. Powering off system\n" ); + goto poweroff; + }
arch/powerpc/platforms/powernv/opal-power.c line 67
Quoted 10 lines
arch/powerpc/platforms/powernv/opal-power.c +10
-0+ +/* Check for EPOW event */ +if (get_epow_status ()) { +pr_info ("Existing EPOW event detected. Powering off system" ); + goto poweroff; + } +return ; + +poweroff: +orderly_poweroff (true);
I don't like that much, you shouldn't need to use goto for such simple logic.
Can you create a single function, maybe called event_pending(), and have it check both EPOW and DPO and return a bool if there's any kind of event pending.
Then this can just become:
if (event_pending()) orderly_poweroff(true);
Quoted 11 lines
arch/powerpc/platforms/powernv/opal-power.c +11
-0+} + +/* OPAL EPOW, DPO event notifier */ +static int opal_epow_dpo_event (struct notifier_block *nb, +unsigned long msg_type,void *msg) +{ +switch (msg_type) { +case OPAL_MSG_EPOW : +pr_info ("EPOW msg received. Powering off system\n" ); +break ; +case OPAL_MSG_DPO :
arch/powerpc/platforms/powernv/opal-power.c line 88
Quoted 10 lines
arch/powerpc/platforms/powernv/opal-power.c +10
-0+pr_info ("DPO msg received. Powering off system\n" ); +break ; +default : +pr_err ("Unknown message type %lu\n" , msg_type); +return 0 ; + } + +orderly_poweroff (true); +return 0 ; +}
Why do we need a separate notifier function? Can't this just be folded into opal_power_control_event() ?
Quoted 48 lines
arch/powerpc/platforms/powernv/opal-power.c +21
-4+ +/* OPAL power-control events notifier */ static int opal_power_control_event (struct notifier_block *nb, -unsigned long msg_type,void *msg) +unsigned long msg_type,void *msg) {struct opal_msg *power_msg = msg;uint64_t type;@@ -29,20 +98,35 @@ static int opal_power_control_event(struct notifier_block *nb,switch (type) {case SOFT_REBOOT : -pr_info ("OPAL: reboot requested\n" ); +pr_info ("Reboot requested\n" );orderly_reboot ();break ;case SOFT_OFF : -pr_info ("OPAL: poweroff requested\n" ); +pr_info ("Poweroff requested\n" );orderly_poweroff (true);break ;default : -pr_err ("OPAL: power control type unexpected %016llx\n" , type); +pr_err ("Unknown power-control type %llu\n" , type); }return 0 ; } +/* OPAL EPOW event notifier block */ +static struct notifier_block opal_epow_nb = { + .notifier_call = opal_epow_dpo_event, + .next =NULL , + .priority =0 , +}; + +/* OPAL DPO event notifier block */ +static struct notifier_block opal_dpo_nb = { + .notifier_call = opal_epow_dpo_event, + .next =NULL , + .priority =0 , +}; + +/* OPAL power-control event notifier block */ static struct notifier_block opal_power_control_nb = { .notifier_call = opal_power_control_event, .next =NULL ,
arch/powerpc/platforms/powernv/opal-power.c static struct notifier_block opal_power_control_nb = { · line 138
Quoted 5 lines
arch/powerpc/platforms/powernv/opal-power.c +1
-1@@ -51,16 +135,49 @@ static struct notifier_block opal_power_control_nb = {static int __init opal_power_control_init (void ) { -int ret; +int ret, epow_dpo_supported =0 ;
Can you make that a bool and call it "supported".
arch/powerpc/platforms/powernv/opal-power.c static struct notifier_block opal_power_control_nb = { · line 139
Quoted 1 line
arch/powerpc/platforms/powernv/opal-power.c +1
-0+struct device_node *node_epow;
It's typical to just call it "np".
arch/powerpc/platforms/powernv/opal-power.c static struct notifier_block opal_power_control_nb = { · line 146
Quoted 12 lines
arch/powerpc/platforms/powernv/opal-power.c +5
-5+/* Register OPAL power-control events notifier */ ret =opal_message_notifier_register (OPAL_MSG_SHUTDOWN , - &opal_power_control_nb); -if (ret) { -pr_err ("%s: Can't register OPAL event notifier (%d)\n" , - __func__, ret); -return ret; + &opal_power_control_nb); +if (ret) +pr_err ("Power-control events notifier registration " +"failed, ret = %d\n" , ret);
Please don't split the string, and similarly below.
arch/powerpc/platforms/powernv/opal-power.c static struct notifier_block opal_power_control_nb = { · line 159
Quoted 13 lines
arch/powerpc/platforms/powernv/opal-power.c +11
-0+ +/* Determine EPOW, DPO support in hardware. */ + node_epow =of_find_node_by_path ("/ibm,opal/epow" ); +if (node_epow) { + epow_dpo_supported =of_device_is_compatible (node_epow, +"ibm,opal-v3-epow" ); +of_node_put (node_epow); } +if (epow_dpo_supported) +pr_info ("OPAL EPOW, DPO support detected.\n" ); +else +return 0 ;
Clearer as:
if (!supported)
return 0;
pr_info("OPAL EPOW, DPO support detected.\n");Quoted 13 lines
arch/powerpc/platforms/powernv/opal-power.c +13
-0+ +/* Register EPOW event notifier */ + ret =opal_message_notifier_register (OPAL_MSG_EPOW , + &opal_epow_nb); +if (ret) +pr_err ("EPOW event notifier registration failed, " +"ret = %d\n" , ret); + +/* Register DPO event notifier */ + ret =opal_message_notifier_register (OPAL_MSG_DPO , + &opal_dpo_nb); +if (ret) + pr_err("DPO event notifier registration failed, "
arch/powerpc/platforms/powernv/opal-power.c static struct notifier_block opal_power_control_nb = { · line 182
Quoted 10 lines
arch/powerpc/platforms/powernv/opal-power.c +8
-0+ "ret = %d\n", ret); + +/* Check for any existing EPOW or DPO events. */ +process_existing_poweroff_events (); + +pr_info ("Poweroff events support initialized\n" ); +return 0 ; } +
No extra blank line thanks.
arch/powerpc/platforms/powernv/opal-power.c static struct notifier_block opal_power_control_nb = { · line 183
Quoted 1 line
arch/powerpc/platforms/powernv/opal-power.c +0
-0machine_subsys_initcall (powernv, opal_power_control_init);
cheers
Re: [v5] powerpc/powernv: Add poweroff (EPOW, DPO) events support for PowerNV platform
Hi Michael,
Thanks for review. Responses below
Quoted 3 lines · Michael Ellerman
Quoted 1 line · Vipin K Parashar
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.
Quoted 4 lines
Quoted 2 lines
DPO (Delayed Power Off) events for PowerNV platform. EPOW events are
^ the
the PowerNV platform. Will edit.
Quoted 3 lines
Quoted 2 lines
generated by SPCN/FSP due to various critical system conditions that
SPCN?
Will remove SPCN. FSP should be sufficient.
Quoted 4 lines
Quoted 2 lines
need system shutdown. Few examples of these conditions are high
^s/need/require/ ? A few
Agreed.
Quoted 4 lines
Quoted 3 lines
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
Quoted 4 lines
Quoted 2 lines
Upon receipt of EPOW and DPO events host kernel invokes
^
the host kernel
will edit
Quoted 3 lines
Quoted 1 line
orderly_powerofffor performing graceful system shutdown. System adminI like it if you spell functions with a trailing () to make it clear they are functions, so this would be "
orderly_powerof()".
Agreed.
Quoted 7 lines
Quoted 5 lines
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.
Quoted 19 lines
Quoted 19 lines
Signed-off-by Vipin K Parashar <[email protected]>Reviewed-by Joel Stanley <[email protected]>Reviewed-by Vaibhav Jain <[email protected]>--- 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(-)arch/powerpc/include/asm/opal-api.h +0
-0@@ -355,6 +355,10 @@ enum opal_msg_type { OPAL_MSG_TYPE_MAX, };
Quoted 8 lines
arch/powerpc/include/asm/opal-api.h enum opal_msg_type { · line 360
Quoted 3 lines
arch/powerpc/include/asm/opal-api.h +3
-0+/* OPAL_MSG_SHUTDOWN parameter values */ +#define SOFT_OFF 0x00 +#define SOFT_REBOOT 0x01I 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.
Quoted 39 lines
Quoted 39 lines
arch/powerpc/include/asm/opal-api.h +32
-0struct 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 */
Quoted 8 lines
arch/powerpc/include/asm/opal-api.h struct opal_i2c_request { · line 775
Quoted 7 lines
arch/powerpc/include/asm/opal-api.h +7
-0+ 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
Quoted 16 lines
Quoted 9 lines
arch/powerpc/include/asm/opal-api.h +0
-0#endif /* __ASSEMBLY__ */ #endif /* __OPAL_API_H */ arch/powerpc/include/asm/opal.h +0
-0arch/powerpc/include/asm/opal.h int64_t opal_pci_fence_phb(uint64_t phb_id); · line 144
Quoted 5 lines
arch/powerpc/include/asm/opal.h +1
-1@@ -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);Has the signature of this function really changed or was it just wrong before?
Quoted 2 lines
If it's changed how do we know we're running on a version of OPAL that supports the two argument version?
__be64 * status is wrong here. OPAL expects two arguments of type __be16 * and has been unchanged.
Quoted 6 lines
The parameter names don't seem very clear either. status is actually a pointer to an array of "statuses", and length is the number of entries in that array.
Also you removed the endian annotations but then you pass it
__be16values, so that looks incorrect, you should be using__be16here.
Will correct endian notation and use below names for epow, dpo api int64_t opal_get_epow_status(__be16 *epow_status, __be16 *num_epow_classes); int64_t opal_get_dpo_status(__be64 *dpo_timeout);
Quoted 3 lines
arch/powerpc/include/asm/opal.h int64_t opal_pci_fence_phb(uint64_t phb_id); · line 145
Quoted 2 lines
arch/powerpc/include/asm/opal.h +1
-0+int64_t opal_get_dpo_status (int64_t *dpo_timeout);Similarly this should be
__be64AFAICS.
Agreed. Changed api above.
Quoted 16 lines
Quoted 16 lines
arch/powerpc/platforms/powernv/opal-power.c +1
-1@@ -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. */
Quoted 2 lines
arch/powerpc/platforms/powernv/opal-power.c line 12
Quoted 1 line
arch/powerpc/platforms/powernv/opal-power.c +1
-0+#define pr_fmt (fmt) "OPAL-POWER: " fmtPlease don't shout, "opal-power" is fine.
Will keep in small letters.
Quoted 5 lines
arch/powerpc/platforms/powernv/opal-power.c line 16
Quoted 4 lines
arch/powerpc/platforms/powernv/opal-power.c +2
-0#include <linux/kernel.h> +#include <linux/spinlock.h> +#include <linux/timer.h> Don't think you need those?
yes, not needed now.
Quoted 5 lines
arch/powerpc/platforms/powernv/opal-power.c line 15
Quoted 4 lines
arch/powerpc/platforms/powernv/opal-power.c +0
-2#include <linux/reboot.h> -#include <linux/notifier.h> -I think you DO need
notifier.h.
Agreed. Won't remove.
Quoted 5 lines
Quoted 5 lines
arch/powerpc/platforms/powernv/opal-power.c +1
-0+#include <linux/of.h> #include <asm/opal.h> #include <asm/machdep.h>
Quoted 8 lines
arch/powerpc/platforms/powernv/opal-power.c line 23
Quoted 4 lines
arch/powerpc/platforms/powernv/opal-power.c +2
-2-#define SOFT_OFF 0x00 -#define SOFT_REBOOT 0x01 +/* Get EPOW status */ +static bool get_epow_status (void )This is not a great name, "get" implies it gives you something back, but it doesn't it just tells you true or false.
So maybe
epow_event_pending()?
Agreed. Will use better naming.
Quoted 7 lines
arch/powerpc/platforms/powernv/opal-power.c line 27
Quoted 5 lines
arch/powerpc/platforms/powernv/opal-power.c +4
-0+{ +int i; +u16 num_classes; +__be16 epow_classes;I think this would be cleaner if you just had a single
num_classesand you endian swap in the one place you use it.
Agreed.
Quoted 9 lines
arch/powerpc/platforms/powernv/opal-power.c line 34
Quoted 8 lines
arch/powerpc/platforms/powernv/opal-power.c +7
-0+__be16 opal_epow_status[OPAL_SYSEPOW_MAX ] = {0 }; + +/* Send kernel EPOW classes supported info to OPAL */ + epow_classes =cpu_to_be16 (OPAL_SYSEPOW_MAX ); + +/* Get EPOW events information from OPAL */ +opal_get_epow_status (opal_epow_status, &epow_classes);This could fail.
Will add a check for API failure.
Though skiboot implementation doesn't have a fail case for this.
Quoted 36 lines
Quoted 24 lines
arch/powerpc/platforms/powernv/opal-power.c +22
-0+ +/* Look for EPOW events present */ + num_classes =be16_to_cpu (epow_classes); +for (i =0 ; i < num_classes; i++) { +if (be16_to_cpu (opal_epow_status[i])) +return true; + } + +return false; +} + +/* Process existing EPOW, DPO events */ +static void process_existing_poweroff_events (void ) +{ +int rc; +__be64 opal_dpo_timeout; +/* Check for DPO event */ + rc =opal_get_dpo_status (&opal_dpo_timeout); +if (rc !=OPAL_WRONG_STATE ) { +pr_info ("Existing DPO event detected. Powering off system\n" ); + goto poweroff; + }arch/powerpc/platforms/powernv/opal-power.c line 67
Quoted 10 lines
arch/powerpc/platforms/powernv/opal-power.c +10
-0+ +/* Check for EPOW event */ +if (get_epow_status ()) { +pr_info ("Existing EPOW event detected. Powering off system" ); + goto poweroff; + } +return ; + +poweroff: +orderly_poweroff (true);I don't like that much, you shouldn't need to use goto for such simple logic.
Quoted 7 lines
Can you create a single function, maybe called
event_pending(), and have it check both EPOW and DPO and return a bool if there's any kind of event pending.Then this can just become:
if (event_pending()) orderly_poweroff(true);
Agreed. Will reorganize this code.
Quoted 16 lines
Quoted 16 lines
arch/powerpc/platforms/powernv/opal-power.c +15
-0+} + +/* OPAL EPOW, DPO event notifier */ +static int opal_epow_dpo_event (struct notifier_block *nb, +unsigned long msg_type,void *msg) +{ +switch (msg_type) { +case OPAL_MSG_EPOW : +pr_info ("EPOW msg received. Powering off system\n" ); +break ; +case OPAL_MSG_DPO : +pr_info ("DPO msg received. Powering off system\n" ); +break ; +default : +pr_err ("Unknown message type %lu\n" , msg_type);
Quoted 8 lines
arch/powerpc/platforms/powernv/opal-power.c line 88
Quoted 6 lines
arch/powerpc/platforms/powernv/opal-power.c +6
-0+return 0 ; + } + +orderly_poweroff (true); +return 0 ; +}Why do we need a separate notifier function? Can't this just be folded into
opal_power_control_event()?
Will merge all of them into opal_power_control_event.
Quoted 50 lines
Quoted 50 lines
arch/powerpc/platforms/powernv/opal-power.c +21
-4+ +/* OPAL power-control events notifier */ static int opal_power_control_event (struct notifier_block *nb, -unsigned long msg_type,void *msg) +unsigned long msg_type,void *msg) {struct opal_msg *power_msg = msg;uint64_t type;@@ -29,20 +98,35 @@ static int opal_power_control_event(struct notifier_block *nb,switch (type) {case SOFT_REBOOT : -pr_info ("OPAL: reboot requested\n" ); +pr_info ("Reboot requested\n" );orderly_reboot ();break ;case SOFT_OFF : -pr_info ("OPAL: poweroff requested\n" ); +pr_info ("Poweroff requested\n" );orderly_poweroff (true);break ;default : -pr_err ("OPAL: power control type unexpected %016llx\n" , type); +pr_err ("Unknown power-control type %llu\n" , type); }return 0 ; } +/* OPAL EPOW event notifier block */ +static struct notifier_block opal_epow_nb = { + .notifier_call = opal_epow_dpo_event, + .next =NULL , + .priority =0 , +}; + +/* OPAL DPO event notifier block */ +static struct notifier_block opal_dpo_nb = { + .notifier_call = opal_epow_dpo_event, + .next =NULL , + .priority =0 , +}; + +/* OPAL power-control event notifier block */ static struct notifier_block opal_power_control_nb = { .notifier_call = opal_power_control_event, .next =NULL ,@@ -51,16 +135,49 @@ static struct notifier_block opal_power_control_nb = {
Quoted 5 lines
arch/powerpc/platforms/powernv/opal-power.c static struct notifier_block opal_power_control_nb = { · line 138
Quoted 4 lines
arch/powerpc/platforms/powernv/opal-power.c +1
-1static int __init opal_power_control_init (void ) { -int ret; +int ret, epow_dpo_supported =0 ;Can you make that a bool and call it "supported".
Will change name to supported. Pasted reorganized code below.
Quoted 3 lines
arch/powerpc/platforms/powernv/opal-power.c static struct notifier_block opal_power_control_nb = { · line 139
Quoted 2 lines
arch/powerpc/platforms/powernv/opal-power.c +1
-0+struct device_node *node_epow;It's typical to just call it "np".
Agreed. will use "np"
Quoted 14 lines
arch/powerpc/platforms/powernv/opal-power.c static struct notifier_block opal_power_control_nb = { · line 146
Quoted 13 lines
arch/powerpc/platforms/powernv/opal-power.c +5
-5+/* Register OPAL power-control events notifier */ ret =opal_message_notifier_register (OPAL_MSG_SHUTDOWN , - &opal_power_control_nb); -if (ret) { -pr_err ("%s: Can't register OPAL event notifier (%d)\n" , - __func__, ret); -return ret; + &opal_power_control_nb); +if (ret) +pr_err ("Power-control events notifier registration " +"failed, ret = %d\n" , ret);Please don't split the string, and similarly below.
sure
Quoted 16 lines
Quoted 4 lines
arch/powerpc/platforms/powernv/opal-power.c +3
-0+ +/* Determine EPOW, DPO support in hardware. */ + node_epow =of_find_node_by_path ("/ibm,opal/epow" );arch/powerpc/platforms/powernv/opal-power.c static struct notifier_block opal_power_control_nb = { · line 159
Quoted 10 lines
arch/powerpc/platforms/powernv/opal-power.c +8
-0+if (node_epow) { + epow_dpo_supported =of_device_is_compatible (node_epow, +"ibm,opal-v3-epow" ); +of_node_put (node_epow); } +if (epow_dpo_supported) +pr_info ("OPAL EPOW, DPO support detected.\n" ); +else +return 0 ;Clearer as:
Quoted 4 lines
if (!supported)
return 0;
pr_info("OPAL EPOW, DPO support detected.\n");Reorganized code as below
/* Determine OPAL EPOW, DPO support */
np = of_find_node_by_path("/ibm,opal/epow");
if (np) {
int supported;
supported = of_device_is_compatible(np,
"ibm,opal-v3-epow");
of_node_put(np);
if (!supported)
return 0;
pr_info("OPAL EPOW, DPO support detected.\n");
}Quoted 17 lines
Quoted 17 lines
arch/powerpc/platforms/powernv/opal-power.c +16
-0+ +/* Register EPOW event notifier */ + ret =opal_message_notifier_register (OPAL_MSG_EPOW , + &opal_epow_nb); +if (ret) +pr_err ("EPOW event notifier registration failed, " +"ret = %d\n" , ret); + +/* Register DPO event notifier */ + ret =opal_message_notifier_register (OPAL_MSG_DPO , + &opal_dpo_nb); +if (ret) +pr_err ("DPO event notifier registration failed, " +"ret = %d\n" , ret); + +/* Check for any existing EPOW or DPO events. */
Quoted 8 lines
arch/powerpc/platforms/powernv/opal-power.c static struct notifier_block opal_power_control_nb = { · line 182
Quoted 7 lines
arch/powerpc/platforms/powernv/opal-power.c +5
-0+process_existing_poweroff_events (); + +pr_info ("Poweroff events support initialized\n" ); +return 0 ; } +No extra blank line thanks.
sure
Quoted 5 lines
arch/powerpc/platforms/powernv/opal-power.c static struct notifier_block opal_power_control_nb = { · line 183
Quoted 2 lines
arch/powerpc/platforms/powernv/opal-power.c +0
-0machine_subsys_initcall (powernv, opal_power_control_init);cheers