aboutsummaryrefslogtreecommitdiff
path: root/libflash/ecc.c
diff options
context:
space:
mode:
authorNicholas Piggin <npiggin@gmail.com>2019-12-08 22:23:04 +1000
committerOliver O'Halloran <oohall@gmail.com>2019-12-16 14:50:56 +1100
commit8d9d63b960be603c20340ad5faf1a0a76973bd71 (patch)
tree29013cf8f83209167b612756232188e540e54def /libflash/ecc.c
parentf27d32f1d1ef20c639e6e9692fb0802887078d96 (diff)
downloadskiboot-8d9d63b960be603c20340ad5faf1a0a76973bd71.zip
skiboot-8d9d63b960be603c20340ad5faf1a0a76973bd71.tar.gz
skiboot-8d9d63b960be603c20340ad5faf1a0a76973bd71.tar.bz2
libflash: ecc endian conversions
Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Diffstat (limited to 'libflash/ecc.c')
-rw-r--r--libflash/ecc.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/libflash/ecc.c b/libflash/ecc.c
index 0b85fb3..8e76e7c 100644
--- a/libflash/ecc.c
+++ b/libflash/ecc.c
@@ -142,30 +142,34 @@ static inline uint64_t eccflipbit(uint64_t data, uint8_t bit)
return data ^ (1ul << (63 - bit));
}
-static int eccbyte(uint64_t *dst, struct ecc64 *src)
+static int eccbyte(beint64_t *dst, struct ecc64 *src)
{
uint8_t ecc, badbit;
uint64_t data;
- data = src->data;
+ data = be64_to_cpu(src->data);
ecc = src->ecc;
- badbit = eccverify(be64_to_cpu(data), ecc);
+ badbit = eccverify(data, ecc);
if (badbit == UE) {
- FL_ERR("ECC: uncorrectable error: %016lx %02x\n",
- (long unsigned int)be64_to_cpu(data), ecc);
+ FL_ERR("ECC: uncorrectable error: %016llx %02x\n", (unsigned long long int)data, ecc);
return badbit;
}
- *dst = data;
if (badbit <= UE)
FL_INF("ECC: correctable error: %i\n", badbit);
if (badbit < 64)
- *dst = (uint64_t)be64_to_cpu(eccflipbit(be64_to_cpu(data),
- badbit));
+ *dst = cpu_to_be64(eccflipbit(data, badbit));
+ else
+ *dst = cpu_to_be64(data);
return 0;
}
+static beint64_t *inc_beint64_by(const void *p, uint64_t i)
+{
+ return (beint64_t *)(((char *)p) + i);
+}
+
static uint64_t *inc_uint64_by(const void *p, uint64_t i)
{
return (uint64_t *)(((char *)p) + i);
@@ -200,7 +204,7 @@ static uint64_t whole_ecc_structs(uint64_t i)
* @retval: 0 - success
* @retfal: other - fail
*/
-int memcpy_from_ecc(uint64_t *dst, struct ecc64 *src, uint64_t len)
+int memcpy_from_ecc(beint64_t *dst, struct ecc64 *src, uint64_t len)
{
uint32_t i;
@@ -256,7 +260,7 @@ int memcpy_from_ecc(uint64_t *dst, struct ecc64 *src, uint64_t len)
* @retval: 0 - success
* @retfal: other - fail
*/
-int memcpy_from_ecc_unaligned(uint64_t *dst, struct ecc64 *src,
+int memcpy_from_ecc_unaligned(beint64_t *dst, struct ecc64 *src,
uint64_t len, uint8_t alignment)
{
char data[BYTES_PER_ECC];
@@ -273,14 +277,14 @@ int memcpy_from_ecc_unaligned(uint64_t *dst, struct ecc64 *src,
* required - otherwise jump straight to memcpy_from_ecc()
*/
if (alignment) {
- rc = eccbyte((uint64_t *)data, src);
+ rc = eccbyte((beint64_t *)data, src);
if (rc)
return rc;
memcpy(dst, &data[alignment], bytes_wanted);
src = inc_ecc64_by(src, sizeof(struct ecc64));
- dst = inc_uint64_by(dst, bytes_wanted);
+ dst = inc_beint64_by(dst, bytes_wanted);
len -= bytes_wanted;
}
@@ -299,7 +303,7 @@ int memcpy_from_ecc_unaligned(uint64_t *dst, struct ecc64 *src,
}
if (len) {
- rc = eccbyte((uint64_t *)data, src);
+ rc = eccbyte((beint64_t *)data, src);
if (rc)
return rc;
@@ -323,7 +327,7 @@ int memcpy_from_ecc_unaligned(uint64_t *dst, struct ecc64 *src,
* @retval: 0 - success
* @retfal: other - fail
*/
-int memcpy_to_ecc(struct ecc64 *dst, const uint64_t *src, uint64_t len)
+int memcpy_to_ecc(struct ecc64 *dst, const beint64_t *src, uint64_t len)
{
struct ecc64 ecc_word;
uint64_t i;
@@ -390,7 +394,7 @@ int memcpy_to_ecc(struct ecc64 *dst, const uint64_t *src, uint64_t len)
* @retfal: other - fail
*/
-int memcpy_to_ecc_unaligned(struct ecc64 *dst, const uint64_t *src,
+int memcpy_to_ecc_unaligned(struct ecc64 *dst, const beint64_t *src,
uint64_t len, uint8_t alignment)
{
struct ecc64 ecc_word;
@@ -412,7 +416,7 @@ int memcpy_to_ecc_unaligned(struct ecc64 *dst, const uint64_t *src,
sizeof(struct ecc64) - alignment);
dst = inc_ecc64_by(dst, sizeof(struct ecc64) - alignment);
- src = inc_uint64_by(src, bytes_wanted);
+ src = inc_beint64_by(src, bytes_wanted);
len -= bytes_wanted;
}