[Skiboot] [RFC PATCH 1/3] libflash: first pass at improved eccmemcpy interface
Cyril Bur
cyrilbur at gmail.com
Thu Mar 5 20:39:23 AEDT 2015
From: Cyril Bur <cyril.bur at au1.ibm.com>
This patch is twofold, improves the memcpy to better specify that we're
reading ecc bytes and prepares for the addition of the reverse operation.
Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>
---
libflash/ecc.c | 18 +++++++++---------
libflash/ecc.h | 8 +++++++-
libflash/libflash.c | 4 ++--
3 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/libflash/ecc.c b/libflash/ecc.c
index 61084cc..f8fcb9f 100644
--- a/libflash/ecc.c
+++ b/libflash/ecc.c
@@ -141,10 +141,10 @@ static uint8_t eccverify(uint64_t data, uint8_t ecc)
* @retval UE - Data is uncorrectable.
* @retval all others - which bit was corrected.
*/
-uint8_t eccmemcpy(uint64_t *dst, uint64_t *src, uint32_t len)
+uint8_t memcpy_from_ecc(uint64_t *dst, struct ecc64 *src, uint32_t len)
{
- beint64_t *data;
- uint8_t *ecc;
+ beint64_t data;
+ uint8_t ecc;
uint32_t i;
uint8_t badbit;
@@ -159,20 +159,20 @@ uint8_t eccmemcpy(uint64_t *dst, uint64_t *src, uint32_t len)
len >>= 3;
for (i = 0; i < len; i++) {
- data = (beint64_t *)((uint8_t *)src + i * 9);
- ecc = (uint8_t *)data + 8;
+ data = (src + i)->data;
+ ecc = (src + i)->ecc;
- badbit = eccverify(be64_to_cpu(*data), *ecc);
+ badbit = eccverify(be64_to_cpu(data), ecc);
if (badbit == UE) {
FL_ERR("ECC: uncorrectable error: %016lx %02x\n",
- (long unsigned int)be64_to_cpu(*data), *ecc);
+ (long unsigned int)be64_to_cpu(data), ecc);
return badbit;
}
- *dst = *data;
+ *dst = data;
if (badbit <= UE)
FL_INF("ECC: correctable error: %i\n", badbit);
if (badbit < 64)
- *dst = (uint64_t)cpu_to_be64(be64_to_cpu(*data) ^
+ *dst = (uint64_t)cpu_to_be64(be64_to_cpu(data) ^
(1ul << (63 - badbit)));
dst++;
}
diff --git a/libflash/ecc.h b/libflash/ecc.h
index 581886f..62eec54 100644
--- a/libflash/ecc.h
+++ b/libflash/ecc.h
@@ -20,6 +20,7 @@
#define __ECC_H
#include <stdint.h>
+#include <ccan/endian/endian.h>
/* Bit field identifiers for syndrome calculations. */
enum eccbitfields
@@ -36,7 +37,12 @@ enum eccbitfields
E7 = 64 //< Error in ECC bit 7
};
-extern uint8_t eccmemcpy(uint64_t *dst, uint64_t *src, uint32_t len);
+struct ecc64 {
+ beint64_t data;
+ uint8_t ecc;
+} __attribute__((__packed__));
+
+extern uint8_t memcpy_from_ecc(uint64_t *dst, struct ecc64 *src, uint32_t len);
/*
* Calculate the size of a buffer if ECC is added
diff --git a/libflash/libflash.c b/libflash/libflash.c
index 2886fc7..c2a1c69 100644
--- a/libflash/libflash.c
+++ b/libflash/libflash.c
@@ -139,7 +139,7 @@ int flash_read(struct flash_chip *c, uint32_t pos, void *buf, uint32_t len)
int flash_read_corrected(struct flash_chip *c, uint32_t pos, void *buf,
uint32_t len, bool ecc)
{
- uint64_t *bufecc;
+ struct ecc64 *bufecc;
uint32_t copylen;
int rc;
uint8_t ret;
@@ -162,7 +162,7 @@ int flash_read_corrected(struct flash_chip *c, uint32_t pos, void *buf,
goto err;
/* Extract data from ECCed data */
- ret = eccmemcpy(buf, bufecc, copylen);
+ ret = memcpy_from_ecc(buf, bufecc, copylen);
if (ret == UE) {
rc = FLASH_ERR_ECC_INVALID;
goto err;
--
1.9.1
More information about the Skiboot
mailing list