aboutsummaryrefslogtreecommitdiff
path: root/libflash/ecc.h
diff options
context:
space:
mode:
authorCyril Bur <cyril.bur@au1.ibm.com>2015-06-23 13:22:08 +1000
committerStewart Smith <stewart@linux.vnet.ibm.com>2015-06-23 13:38:42 +1000
commit69b152cab30aae6188b590b2df9a6f55932c4408 (patch)
tree3f8f375a5d80131dd4c0a1955b25a3e6b669d8d0 /libflash/ecc.h
parent6c458a0369494a7f0ae2e6352850502c5e393f8f (diff)
downloadskiboot-69b152cab30aae6188b590b2df9a6f55932c4408.zip
skiboot-69b152cab30aae6188b590b2df9a6f55932c4408.tar.gz
skiboot-69b152cab30aae6188b590b2df9a6f55932c4408.tar.bz2
libflash/ecc: Simplify and cleanup ecc code.
The ecc 'memcpy' style functions return success or fail in terms of the ECC enum. This doesn't really make sense, use true or false. As the result the ecc enum doesn't need to be exposed anymore, which makes more sense, not clear why it was exposed in the first place. Convert some of the ecc #defines to static inlines, shouldn't make any difference but feels safer. Fix minor stylistic and typo issues. Reviewed-By: Alistair Popple <alistair@popple.id.au> Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'libflash/ecc.h')
-rw-r--r--libflash/ecc.h44
1 files changed, 23 insertions, 21 deletions
diff --git a/libflash/ecc.h b/libflash/ecc.h
index d58ec3e..1e14724 100644
--- a/libflash/ecc.h
+++ b/libflash/ecc.h
@@ -22,29 +22,14 @@
#include <stdint.h>
#include <ccan/endian/endian.h>
-/* Bit field identifiers for syndrome calculations. */
-enum eccbitfields
-{
- GD = 0xff, //< Good, ECC matches.
- UE = 0xfe, //< Uncorrectable.
- E0 = 71, //< Error in ECC bit 0
- E1 = 70, //< Error in ECC bit 1
- E2 = 69, //< Error in ECC bit 2
- E3 = 68, //< Error in ECC bit 3
- E4 = 67, //< Error in ECC bit 4
- E5 = 66, //< Error in ECC bit 5
- E6 = 65, //< Error in ECC bit 6
- E7 = 64 //< Error in ECC bit 7
-};
-
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);
+extern int memcpy_from_ecc(uint64_t *dst, struct ecc64 *src, uint32_t len);
-extern uint8_t memcpy_to_ecc(struct ecc64 *dst, const uint64_t *src, uint32_t len);
+extern int memcpy_to_ecc(struct ecc64 *dst, const uint64_t *src, uint32_t len);
/*
* Calculate the size of a buffer if ECC is added
@@ -56,9 +41,26 @@ extern uint8_t memcpy_to_ecc(struct ecc64 *dst, const uint64_t *src, uint32_t le
#define ALIGN_UP(_v, _a) (((_v) + (_a) - 1) & ~((_a) - 1))
#endif
-#define ECC_SIZE(len) (ALIGN_UP((len), 8) >> 3)
-#define ECC_BUFFER_SIZE(len) (ALIGN_UP((len), 8) + ECC_SIZE(len))
-#define ECC_BUFFER_SIZE_CHECK(len) ((len) % 9)
-#define BUFFER_SIZE_MINUS_ECC(len) ((len) * 8 / 9)
+#define BYTES_PER_ECC 8
+
+static inline uint32_t ecc_size(uint32_t len)
+{
+ return ALIGN_UP(len, BYTES_PER_ECC) >> 3;
+}
+
+static inline uint32_t ecc_buffer_size(uint32_t len)
+{
+ return ALIGN_UP(len, BYTES_PER_ECC) + ecc_size(len);
+}
+
+static inline int ecc_buffer_size_check(uint32_t len)
+{
+ return len % (BYTES_PER_ECC + 1);
+}
+
+static inline uint32_t ecc_buffer_size_minus_ecc(uint32_t len)
+{
+ return len * BYTES_PER_ECC / (BYTES_PER_ECC + 1);
+}
#endif