diff mbox series

[v8,20/28] libflash: ecc endian conversions

Message ID 20191128062442.20690-21-npiggin@gmail.com
State Superseded
Headers show
Series little endian skiboot | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch warning Failed to apply on branch master (d75e82dbfbb9443efeb3f9a5921ac23605aab469)
snowpatch_ozlabs/apply_patch fail Failed to apply to any branch

Commit Message

Nicholas Piggin Nov. 28, 2019, 6:24 a.m. UTC
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 libflash/ecc.c | 36 ++++++++++++++++++++----------------
 libflash/ecc.h |  8 ++++----
 2 files changed, 24 insertions(+), 20 deletions(-)
diff mbox series

Patch

diff --git a/libflash/ecc.c b/libflash/ecc.c
index 0b85fb3ea..8e76e7cf3 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;
 	}
 
diff --git a/libflash/ecc.h b/libflash/ecc.h
index 608d50008..75c3adf22 100644
--- a/libflash/ecc.h
+++ b/libflash/ecc.h
@@ -16,12 +16,12 @@  struct ecc64 {
 	uint8_t ecc;
 } __attribute__((__packed__));
 
-extern int memcpy_from_ecc(uint64_t *dst, struct ecc64 *src, uint64_t len);
-extern int memcpy_from_ecc_unaligned(uint64_t *dst, struct ecc64 *src, uint64_t len,
+extern int memcpy_from_ecc(beint64_t *dst, struct ecc64 *src, uint64_t len);
+extern int memcpy_from_ecc_unaligned(beint64_t *dst, struct ecc64 *src, uint64_t len,
 		uint8_t alignment);
 
-extern int memcpy_to_ecc(struct ecc64 *dst, const uint64_t *src, uint64_t len);
-extern int memcpy_to_ecc_unaligned(struct ecc64 *dst, const uint64_t *src, uint64_t len,
+extern int memcpy_to_ecc(struct ecc64 *dst, const beint64_t *src, uint64_t len);
+extern int memcpy_to_ecc_unaligned(struct ecc64 *dst, const beint64_t *src, uint64_t len,
 		uint8_t alignment);
 
 /*