Re: [PATCH v3] cxl: Export AFU error buffer via sysfs

2015-05-20 Thread trigg

 On 21-May-2015, at 05:16, Michael Neuling mi...@neuling.org wrote:
 
 + */
 +ssize_t cxl_afu_read_err_buffer(struct cxl_afu *afu, char *buf,
 +loff_t off, size_t count)
 +{
 +loff_t aligned_off;
 +size_t aligned_count;
 +const void __iomem *ebuf = afu-afu_desc_mmio + afu-eb_offset;
 +
 +if (!afu-eb_len || count == 0 || off  0)
 
 if eb_len == 0 we don't even create the sysfs file.  So is this check
 needed?
This function is non static so it can be potentially called from kernel.
Condition check of if (count == 0 || off  0 || (size_t)off = afu-eb_len) 
should work solving the problem below too.
 
 +return 0;
 +
 +/* calculate aligned read window */
 +count = min((size_t)(afu-eb_len - off), count);
 
 What if count ends up being negative because off  afu-eb_len??
Agreed. Thanks for catching this. Size_t being unsigned would overflow
To a large positive value.

 
 +aligned_off = round_down(off, 8);
 +aligned_count = round_up(off + count, 8) - aligned_off;
 
 I kinda preferred the start end variables, and length was just end -
 start.
 
 I though it was more readable. IMHO
 
 How about:
 
   aligned_start = round_down(off, 8);
   aligned_end = round_up(off + count, 8);
   aligned_length = aligned_end - aligned_start;
Agreed on aligned_start and aligned_end but would not
need aligned_end in rest of the code.
 
 +
 +/* fast path */
 +if ((aligned_off == off)  (aligned_count == count)) {
 +/* no need to use the bounce buffer */
 +_memcpy_fromio(buf, ebuf + off, count);
 
 I would drop this, as the other code path should work fine.
 Premature optimisation.
I am inclined to differ on this. Code below uses a bounce buffer
which needs more than double the amount of loads and stores.
If the caller wants to speed up things it can simply ask for aligned
read that won't have this overhead. This will be especially useful 
In large reads.

 +
 +} else {
 +/* use bounce buffer for copy */
 +void *tbuf = (void *)__get_free_page(GFP_TEMPORARY);
 +
 +if (!tbuf)
 +return -ENOMEM;
 +
 +/* max we can copy in one read is PAGE_SIZE */
 +aligned_count = min(aligned_count, PAGE_SIZE);
 +_memcpy_fromio(tbuf, ebuf + aligned_off, aligned_count);
 +
 +count = min(count, aligned_count);
Thanks for catching this.

 
 This doesn't seem right.  count will equal PAGE_SIZE if it's too big but
 it has to be smaller by (off  7) in this case.
 
 How about this?
 
   #define MAX_COPY_SIZE PAGE_SIZE
   ...
 
   void *bbuf;
 
   /* Bounds check count with err buf length */
   count = min((size_t)(afu-eb_len - off), count);
   if ((off  0) || (count  0))
   return 0;
 
   /* Create aligned bounce buffer to copy into */
   aligned_start = round_down(off, 8);
   aligned_end = round_up(off + count, 8);
   aligned_length = aligned_end - aligned_start;
 
   if (aligned_length  MAX_COPY_SIZE) {
   aligned_length = MAX_COPY_SIZE;
   count = MAX_COPY_SIZE - (off  0x7);
   }
 
   bbuf = (void *)__get_free_page(GFP_TEMPORARY);
   if (!bbuf)
   return -ENOMEM;
 
   /* Use _memcpy_fromio() so the reads are aligned */
   _memcpy_fromio(bbuf, ebuf + aligned_start, aligned_length);
   memcpy(buf, bbuf + (off  0x7), count);
 
   free_page(bbuf);
 
 
 +memcpy(buf, tbuf + (off  0x7), count);
 +
 +free_page((unsigned long)tbuf);
 +}
 +
 +return count;
 
 ___
 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

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

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

2015-05-15 Thread trigg
Hi Vipin,

I am almost done, just a few nitpicks :-)

~Trigg

On Fri, May 15, 2015 at 4:11 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 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
 ---
  arch/powerpc/include/asm/opal-api.h|  44 +++
  arch/powerpc/include/asm/opal.h|   3 +-
  arch/powerpc/platforms/powernv/opal-power.c| 153 
 ++---
  arch/powerpc/platforms/powernv/opal-wrappers.S |   1 +
  4 files changed, 186 insertions(+), 15 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..c1dfa09 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,94 @@
   * 2 of the License

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

2015-05-14 Thread trigg


 On 14-May-2015, at 16:16, 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 support 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 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
 ---
 arch/powerpc/include/asm/opal-api.h|  44 +++
 arch/powerpc/include/asm/opal.h|   3 +-
 arch/powerpc/platforms/powernv/opal-power.c| 167 ++---
 arch/powerpc/platforms/powernv/opal-wrappers.S |   1 +
 4 files changed, 197 insertions(+), 18 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_REBOOT0x01
 +
 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..0a1e07b 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,40 +9,137 @@
  * 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 

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

2015-05-08 Thread trigg
Hi Vipin,

These comments are in addition to what Joel has said in his review.

On Thu, May 7, 2015 at 3:00 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 support 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 shutdown request.
 This patch enables host kernel on PowerNV platform to handle OPAL
 notifications for these events and initiate system poweroff. Since EPOW
 notifications are sent in advance of impending shutdown event and thus
 this patch also adds functionality to wait for EPOW condition to return to
 normal. Host allows MAX_POWEROFF_SYS_TIME (600 seconds) as system
 poweroff time (time for host + guests shutdown) and waits for remaining
 time for EPOW condition to return to normal. If EPOW condition doesn't
 return to normal in calculated time it proceeds with graceful system
 shutdown. For EPOW events with smaller timeouts values than
 MAX_POWEROFF_SYS_TIME it proceeds with system shutdown without any wait
 for EPOW condition to return to normal.
 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 stat/shutdown time.

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

 diff --git a/arch/powerpc/include/asm/opal-api.h 
 b/arch/powerpc/include/asm/opal-api.h
 index 0321a90..03b3cef 100644
 --- a/arch/powerpc/include/asm/opal-api.h
 +++ b/arch/powerpc/include/asm/opal-api.h
 @@ -730,6 +730,36 @@ 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_EPOW_MAX_CLASSES
 + * to fetch system wide EPOW status. Each element in the returned buffer
 + * will contain bitwise EPOW status for each EPOW sub class.
 + */
 +
 +/* EPOW types */
 +enum OpalEpow {
 +   OPAL_EPOW_POWER = 0,/* Power EPOW */
 +   OPAL_EPOW_TEMP  = 1,/* Temperature EPOW */
 +   OPAL_EPOW_COOLING   = 2,/* Cooling EPOW */
 +   OPAL_MAX_EPOW_CLASSES   = 3,/* Max EPOW categories */
 +};
Dont explicitly assign sequential numbers in an enum. Its taken care
of by the compiler.

 +
 +/* Power EPOW events */
 +enum OpalEpowPower {
 +   OPAL_EPOW_POWER_UPS = 0x1, /* System on UPS power */
 +   OPAL_EPOW_POWER_UPS_LOW = 0x2, /* System on UPS power with low 
 battery*/
 +};
 +
 +/* Temperature EPOW events */
 +enum OpalEpowTemp {
 +   OPAL_EPOW_TEMP_HIGH_AMB = 0x1, /* High ambient temperature */
 +   OPAL_EPOW_TEMP_CRIT_AMB = 0x2, /* Critical ambient temperature */
 +   OPAL_EPOW_TEMP_HIGH_INT = 0x4, /* High internal temperature */
 +   OPAL_EPOW_TEMP_CRIT_INT = 0x8, /* Critical internal temperature */
 +};
 +
  #endif /* __ASSEMBLY__ */

  #endif /* __OPAL_API_H */
 diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
 index 042af1a..0777864 100644
 --- a/arch/powerpc/include/asm/opal.h
 +++ b/arch/powerpc/include/asm/opal.h
 @@ -141,7 +141,6 @@ 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_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);
 @@ -200,6 +199,8 @@ int64_t opal_flash_write(uint64_t id, uint64_t offset, 
 uint64_t buf,
 uint64_t size, uint64_t token);
  int64_t opal_flash_erase(uint64_t id, uint64_t offset, uint64_t size,
 uint64_t token);
 +int32_t opal_get_epow_status(__be32 *status, __be32 *num_classes);
 +int32_t opal_get_dpo_status(__be32 *timeout);

  /* Internal functions */
  extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
 diff --git a/arch/powerpc/platforms/powernv/opal-power.c 
 b/arch/powerpc/platforms/powernv/opal-power.c