Skip to contentSkip to conversation

powerpc/pstore: Add pstore support for nvram partitions

PATCH Superseded Hari Bathini 2 participants 9 messages Dec 24, 2014 – Jan 16, 2015

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 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.

Changes from v2:
Added an empty version of clobbering_unread_rtas_event() routine for !PSERIES, to avoid ifdef at the call sites

---

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             |    4 
 arch/powerpc/kernel/nvram_64.c              |  677 +++++++++++++++++++++++++++
 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, 749 insertions(+), 661 deletions(-)

--
- Hari

#1 lore raw

PATCH v3 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        |    4 
 arch/powerpc/kernel/nvram_64.c         |  656 ++++++++++++++++++++++++++++++++
 arch/powerpc/platforms/pseries/nvram.c |  665 --------------------------------
 4 files changed, 714 insertions(+), 661 deletions(-)
arch/powerpc/include/asm/nvram.h +49 -1
index b0fe0fe..09a518b 100644
@@ -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 +4 -0
index b390f55..bcf6693 100644
@@ -343,8 +343,12 @@ 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);
+#else
+int clobbering_unread_rtas_event(void) { return 0; }
 #endif
 
 #ifdef CONFIG_PPC_RTAS_DAEMON
arch/powerpc/kernel/nvram_64.c +656 -0

668 lines not on this page · raw message

arch/powerpc/platforms/pseries/nvram.c +5 -660

723 lines not on this page · raw message

#2 lore raw

Re: [PATCH v3 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.c file.

As I said in my reply to the previous version:

... 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.

Please explain in your commit message how you have dealt with that.

Also, you broke the build for every config that doesn't have CONFIG_PPC_PSERIES, all 95 of them. This is pasemi_defconfig for example:

      LD      arch/powerpc/mm/built-in.o
    arch/powerpc/mm/init_64.o: In function `clobbering_unread_rtas_event':
    init_64.c:(.opd+0x48): multiple definition of `clobbering_unread_rtas_event'
    arch/powerpc/mm/mem.o:mem.c:(.opd+0x90): first defined here
    arch/powerpc/mm/init_64.o: In function `.clobbering_unread_rtas_event':
    init_64.c:(.text+0x80): multiple definition of `.clobbering_unread_rtas_event'
    arch/powerpc/mm/mem.o:mem.c:(.text+0x2c0): first defined here
      CC      arch/powerpc/kernel/udbg.o
    /home/kisskb/slave/src/scripts/Makefile.build:336: recipe for target 'arch/powerpc/mm/built-in.o' failed
    make[2]: *** [arch/powerpc/mm/built-in.o] Error 1
    /home/kisskb/slave/src/Makefile:938: recipe for target 'arch/powerpc/mm' failed
    make[1]: *** [arch/powerpc/mm] Error 2
    make[1]: *** Waiting for unfinished jobs....

cheers

#3 lore raw

Re: [PATCH v3 1/3] powerpc/nvram: move generic code for nvram and pstore

Quoted 5 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.c file.

Quoted 8 lines

As I said in my reply to the previous version:

... 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.

we could as well do away with the PPC_PSERIES flag in a couple of places in arch/powerpc/kernel/nvram_64.c, but doing that will unnecessarily add few extra variables for !PPC_PSERIES case.

Quoted 2 lines

Please explain in your commit message how you have dealt with that.

Sure. Will update the changelog

Quoted 2 lines

Also, you broke the build for every config that doesn't have CONFIG_PPC_PSERIES, all 95 of them. This is pasemi_defconfig for example:

My bad!clobbering_unread_rtas_event should have been static inline while defining under !PPC_PSERIES

Thanks
Hari

Quoted 18 lines
       LD      arch/powerpc/mm/built-in.o
     arch/powerpc/mm/init_64.o: In function `clobbering_unread_rtas_event':
     init_64.c:(.opd+0x48): multiple definition of `clobbering_unread_rtas_event'
     arch/powerpc/mm/mem.o:mem.c:(.opd+0x90): first defined here
     arch/powerpc/mm/init_64.o: In function `.clobbering_unread_rtas_event':
     init_64.c:(.text+0x80): multiple definition of `.clobbering_unread_rtas_event'
     arch/powerpc/mm/mem.o:mem.c:(.text+0x2c0): first defined here
       CC      arch/powerpc/kernel/udbg.o
     /home/kisskb/slave/src/scripts/Makefile.build:336: recipe for target 'arch/powerpc/mm/built-in.o' failed
     make[2]: *** [arch/powerpc/mm/built-in.o] Error 1
     /home/kisskb/slave/src/Makefile:938: recipe for target 'arch/powerpc/mm' failed
     make[1]: *** [arch/powerpc/mm] Error 2
     make[1]: *** Waiting for unfinished jobs....

cheers

#4 lore raw

Re: [PATCH v3 1/3] powerpc/nvram: move generic code for nvram and pstore

Quoted 12 lines · Hari Bathini
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.c file.

As I said in my reply to the previous version:

... you need to keep in mind that it is very common for us to build kernels with both POWERNV=y and PSERIES=y.

Quoted 8 lines
Quoted 3 lines

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.

we could as well do away with the PPC_PSERIES flag in a couple of places in
arch/powerpc/kernel/nvram_64.c, but doing that will unnecessarily add few extra variables for !PPC_PSERIES case.

Yep. I'm happy for them to be there, I just want you to explain in the changelog that you've thought about the PSERIES=y POWERNV=y case and why the code makes sense for that configuration.

Quoted 3 lines
Quoted 1 line

Please explain in your commit message how you have dealt with that.

Sure. Will update the changelog

Thanks.

Quoted 5 lines
Quoted 2 lines

Also, you broke the build for every config that doesn't have CONFIG_PPC_PSERIES, all 95 of them. This is pasemi_defconfig for example:

My bad! clobbering_unread_rtas_event should have been static inline while defining under !PPC_PSERIES

Correct.

Please make sure you test build at least some of the other configurations in future. I realise it's too time consuming to build all of them, but ideally for every config symbol you use in your patch you need to build a kernel config where that symbol =y and =n (and =m if it's tristate).

cheers

#5 lore raw

Re: [PATCH v3 1/3] powerpc/nvram: move generic code for nvram and pstore

Quoted 30 lines · Michael Ellerman
Quoted 12 lines · Hari Bathini
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.c file.

As I said in my reply to the previous version:

... you need to keep in mind that it is very common for us to build kernels with both POWERNV=y and PSERIES=y.

Quoted 7 lines
Quoted 3 lines

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.

we could as well do away with the PPC_PSERIES flag in a couple of places in
arch/powerpc/kernel/nvram_64.c, but doing that will unnecessarily add few extra variables for !PPC_PSERIES case.

Yep. I'm happy for them to be there, I just want you to explain in the changelog that you've thought about the PSERIES=y POWERNV=y case and why the code makes sense for that configuration.

Quoted 2 lines
Quoted 1 line

Please explain in your commit message how you have dealt with that.

Sure. Will update the changelog

Thanks.

Quoted 2 lines
Quoted 2 lines

Also, you broke the build for every config that doesn't have CONFIG_PPC_PSERIES, all 95 of them. This is pasemi_defconfig for example:

Quoted 8 lines
Quoted 2 lines

My bad! clobbering_unread_rtas_event should have been static inline while defining under !PPC_PSERIES

Correct.

Please make sure you test build at least some of the other configurations in future. I realise it's too time consuming to build all of them, but ideally for every config symbol you use in your patch you need to build a kernel config where that symbol =y and =n (and =m if it's tristate).

Sure, Michael. I will keep this in mind :)

Thanks
Hari

Quoted 7 lines

cheers

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev

#6 lore raw

PATCH v3 2/3 pstore: Add pstore type id for firmware partition

In reply to Hari Bathini

This 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
index 5041660..8e0c009 100644
@@ -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
index ece0c6b..af44980 100644
@@ -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
 };
 
#7 lore raw

Re: [PATCH v3 2/3] pstore: Add pstore type id for firmware partition

Quoted 2 lines · Hari Bathini

This patch adds a pstore type id to be used for opal specific nvram partitions.

This needs to be CC'ed to the pstore maintainers, and at the very least get an ACK from them.

They also might ask why we need another powerpc specific pstore type, we already have 3 of the 7 that exist.

cheers

#8 lore raw

PATCH v3 3/3 pstore: add pstore support on powernv

In reply to Hari Bathini

This 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
index 42e5c6a..293da88 100644
@@ -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",
@@ -477,6 +485,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;
 	}
@@ -552,8 +570,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
index f9896fd..9db4398 100644
@@ -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;