powerpc/pstore: Add pstore support for nvram partitions
Subsystems (2)
v2 cover powerpc/pstore: Add pstore support for nvram partitions
This patch series adds pstore support on powernv platform to read different nvram partitions and write compressed data to oops-log nvram partition. As pseries platform already has pstore support, this series moves most of the common code for pseries and powernv platforms to a common file. Tested the patches successfully on both pseries and powernv platforms.
---
Hari Bathini (3):
powerpc/nvram: move generic code for nvram and pstore
pstore: Add pstore type id for firmware partition
pstore: add pstore support on powernv
arch/powerpc/include/asm/nvram.h | 50 ++ arch/powerpc/include/asm/rtas.h | 2 arch/powerpc/kernel/nvram_64.c | 681 +++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/opal-nvram.c | 10 arch/powerpc/platforms/pseries/nvram.c | 665 -------------------------- fs/pstore/inode.c | 3 include/linux/pstore.h | 1 7 files changed, 751 insertions(+), 661 deletions(-)
--
- Hari
PATCH v2 1/3 powerpc/nvram: move generic code for nvram and pstore
With minor checks, we can move most of the code for nvram under pseries to a common place to be re-used by other powerpc platforms like powernv. This patch moves such common code to arch/powerpc/kernel/nvram_64.c file.
--- arch/powerpc/include/asm/nvram.h | 50 ++ arch/powerpc/include/asm/rtas.h | 2 arch/powerpc/kernel/nvram_64.c | 660 ++++++++++++++++++++++++++++++++ arch/powerpc/platforms/pseries/nvram.c | 665 -------------------------------- 4 files changed, 716 insertions(+), 661 deletions(-)
arch/powerpc/include/asm/nvram.h +49 -1
@@ -9,12 +9,43 @@#ifndef _ASM_POWERPC_NVRAM_H#define _ASM_POWERPC_NVRAM_H - +#include <linux/types.h> #include <linux/errno.h> #include <linux/list.h> #include <uapi/asm/nvram.h> +/* +* Set oops header version to distinguish between old and new format header. +* lnx,oops-log partition max size is 4000, header version > 4000 will +* help in identifying new header. +*/ +#define OOPS_HDR_VERSION 5000 + +struct err_log_info { +__be32 error_type; +__be32 seq_num; +}; + +struct nvram_os_partition { +const char *name; +int req_size;/* desired size, in bytes */ +int min_size;/* minimum acceptable size (0 means req_size) */ +long size;/* size of data portion (excluding err_log_info) */ +long index;/* offset of data portion of partition */ +bool os_partition;/* partition initialized by OS, not FW */ +}; + +struct oops_log_info { +__be16 version; +__be16 report_length; +__be64 timestamp; +} __attribute__((packed)); + +extern struct nvram_os_partition oops_log_partition; +#ifdef CONFIG_PPC_PSERIES +extern struct nvram_os_partition rtas_log_partition; +extern int nvram_write_error_log (char * buff,int length,unsigned int err_type,unsigned int err_seq); extern int nvram_read_error_log(char * buff, int length,
@@ -50,6 +81,23 @@ extern void pmac_xpram_write(int xpaddr, u8 data);/* Synchronize NVRAM */ extern void nvram_sync (void ); +/* Initialize NVRAM OS partition */ +extern int __init nvram_init_os_partition (struct nvram_os_partition *part); + +/* Initialize NVRAM oops partition */ +extern void __init nvram_init_oops_partition (int rtas_partition_exists); + +/* Read a NVRAM partition */ +extern int nvram_read_partition (struct nvram_os_partition *part,char *buff, +int length,unsigned int *err_type, +unsigned int *error_log_cnt); + +/* Write to NVRAM OS partition */ +extern int nvram_write_os_partition (struct nvram_os_partition *part, +char *buff,int length, +unsigned int err_type, +unsigned int error_log_cnt); +/* Determine NVRAM size */ extern ssize_t nvram_get_size (void );
arch/powerpc/include/asm/rtas.h +2 -0
@@ -343,6 +343,8 @@ extern int early_init_dt_scan_rtas(unsigned long node,extern void pSeries_log_error (char *buf,unsigned int err_type,int fatal);#ifdef CONFIG_PPC_PSERIES +extern unsigned long last_rtas_event; +extern int clobbering_unread_rtas_event (void );extern int pseries_devicetree_update (s32 scope);extern void post_mobility_fixup (void );#endif
arch/powerpc/kernel/nvram_64.c +660 -0
672 lines not on this page · raw message
arch/powerpc/platforms/pseries/nvram.c +5 -660
723 lines not on this page · raw message
Michael Ellerman
reviewerRe: [PATCH v2 1/3] powerpc/nvram: move generic code for nvram and pstore
Quoted 4 lines · Hari Bathini
With minor checks, we can move most of the code for nvram under pseries to a common place to be re-used by other powerpc platforms like powernv. This patch moves such common code to
arch/powerpc/kernel/nvram_64.cfile.
Sharing the code is great.
But, you need to keep in mind that it is very common for us to build kernels with both POWERNV=y and PSERIES=y.
So you need to make sure you're only using CONFIG_PPC_PSERIES to protect things that are optional on pseries. Not things that we *shouldn't* be doing on powernv.
For example the logic in nvram_init_oops_partition() looks like it might do the wrong thing for PSERIES=y POWERNV=y.
arch/powerpc/include/asm/rtas.h extern int early_init_dt_scan_rtas(unsigned long node, · line 347
Quoted 10 lines
arch/powerpc/include/asm/rtas.h +2
-0@@ -343,6 +343,8 @@ extern int early_init_dt_scan_rtas(unsigned long node,extern void pSeries_log_error (char *buf,unsigned int err_type,int fatal);#ifdef CONFIG_PPC_PSERIES +extern unsigned long last_rtas_event; +extern int clobbering_unread_rtas_event (void );
You should add an empty version of this for !PSERIES, so you don't have to ifdef all the call sites.
cheers
Re: [PATCH v2 1/3] powerpc/nvram: move generic code for nvram and pstore
Quoted 10 lines · Michael Ellerman
Quoted 4 lines · Hari Bathini
With minor checks, we can move most of the code for nvram under pseries to a common place to be re-used by other powerpc platforms like powernv. This patch moves such common code to
arch/powerpc/kernel/nvram_64.cfile.Sharing the code is great.
But, you need to keep in mind that it is very common for us to build kernels with both POWERNV=y and PSERIES=y.
Quoted 6 lines
So you need to make sure you're only using
CONFIG_PPC_PSERIESto protect things that are optional on pseries. Not things that we *shouldn't* be doing on powernv.For example the logic in
nvram_init_oops_partition()looks like it might do the wrong thing for PSERIES=y POWERNV=y.
True. It might do wrong thing when an incorrect value is passed by the caller. But since the caller is platform specific code [pseries_nvram_init_log_partitions() or opal_nvram_init_log_partitions() routine], with appropriate parameter passed, I haven't seen any issues while testing.
Quoted 7 lines
Quoted 7 lines
arch/powerpc/include/asm/rtas.h +0
-0@@ -343,6 +343,8 @@ extern int early_init_dt_scan_rtas(unsigned long node,extern void pSeries_log_error (char *buf,unsigned int err_type,int fatal);
Quoted 5 lines
arch/powerpc/include/asm/rtas.h extern int early_init_dt_scan_rtas(unsigned long node, · line 347
Quoted 3 lines
arch/powerpc/include/asm/rtas.h +2
-0#ifdef CONFIG_PPC_PSERIES +extern unsigned long last_rtas_event; +extern int clobbering_unread_rtas_event (void );You should add an empty version of this for !PSERIES, so you don't have to ifdef all the call sites.
Sure. Will update accordingly..
Thanks
Hari
Quoted 3 lines
cheers
PATCH v2 2/3 pstore: Add pstore type id for firmware partition
In reply to Hari BathiniThis patch adds a pstore type id to be used for opal specific nvram partitions.
--- fs/pstore/inode.c | 3 +++ include/linux/pstore.h | 1 + 2 files changed, 4 insertions(+)
fs/pstore/inode.c +3 -0
@@ -359,6 +359,9 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, int count,case PSTORE_TYPE_PPC_COMMON :sprintf (name,"powerpc-common-%s-%lld" , psname, id);break ; +case PSTORE_TYPE_PPC_OPAL : +sprintf (name,"powerpc-opal-%s-%lld" , psname, id); +break ;case PSTORE_TYPE_UNKNOWN :sprintf (name,"unknown-%s-%lld" , psname, id);break ;
include/linux/pstore.h +1 -0
@@ -39,6 +39,7 @@ enum pstore_type_id {PSTORE_TYPE_PPC_RTAS =4 ,PSTORE_TYPE_PPC_OF =5 ,PSTORE_TYPE_PPC_COMMON =6 , +PSTORE_TYPE_PPC_OPAL =7 , PSTORE_TYPE_UNKNOWN = 255 };
PATCH v2 3/3 pstore: add pstore support on powernv
In reply to Hari BathiniThis patch extends pstore, a generic interface to platform dependent persistent storage, support for powernv platform to capture certain useful information, during dying moments. Such support is already in place for pseries platform. This patch re-uses most of that code.
--- arch/powerpc/kernel/nvram_64.c | 25 +++++++++++++++++++++++-- arch/powerpc/platforms/powernv/opal-nvram.c | 10 ++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-)
arch/powerpc/kernel/nvram_64.c +23 -2
@@ -127,6 +127,14 @@ static size_t oops_data_sz;static struct z_stream_s stream;#ifdef CONFIG_PSTORE +#ifdef CONFIG_PPC_POWERNV +static struct nvram_os_partition skiboot_partition = { + .name ="ibm,skiboot" , + .index =-1 , + .os_partition = false +}; +#endif +#ifdef CONFIG_PPC_PSERIES static struct nvram_os_partition of_config_partition = { .name = "of-config",
@@ -479,6 +487,16 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type, time->tv_nsec =0 ;break ;#endif +#ifdef CONFIG_PPC_POWERNV +case PSTORE_TYPE_PPC_OPAL : + sig =NVRAM_SIG_FW ; + part = &skiboot_partition; + *type =PSTORE_TYPE_PPC_OPAL ; + *id =PSTORE_TYPE_PPC_OPAL ; + time->tv_sec =0 ; + time->tv_nsec =0 ; +break ; +#endif default :return 0 ; }
@@ -554,8 +572,11 @@ static int nvram_pstore_init(void) {int rc =0 ; - nvram_type_ids[2 ] =PSTORE_TYPE_PPC_RTAS ; - nvram_type_ids[3 ] =PSTORE_TYPE_PPC_OF ; +if (machine_is (pseries)) { + nvram_type_ids[2 ] =PSTORE_TYPE_PPC_RTAS ; + nvram_type_ids[3 ] =PSTORE_TYPE_PPC_OF ; + }else + nvram_type_ids[2 ] =PSTORE_TYPE_PPC_OPAL ; nvram_pstore_info.buf = oops_data; nvram_pstore_info.bufsize = oops_data_sz;
arch/powerpc/platforms/powernv/opal-nvram.c +10 -0
@@ -16,6 +16,7 @@#include <linux/of.h> #include <asm/opal.h> +#include <asm/nvram.h> #include <asm/machdep.h> static unsigned int nvram_size;
@@ -62,6 +63,15 @@ static ssize_t opal_nvram_write(char *buf, size_t count, loff_t *index)return count; } +static int __init opal_nvram_init_log_partitions (void ) +{ +/* Scan nvram for partitions */ +nvram_scan_partitions (); +nvram_init_oops_partition (0 ); +return 0 ; +} +machine_arch_initcall (powernv, opal_nvram_init_log_partitions); +void __init opal_nvram_init (void ) {struct device_node *np;