From patchwork Thu Nov 28 06:24:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1201915 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Nnrh49GTz9sPJ for ; Thu, 28 Nov 2019 17:33:08 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JATbAKWY"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47Nnrh35zTzDqPN for ; Thu, 28 Nov 2019 17:33:08 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::541; helo=mail-pg1-x541.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JATbAKWY"; dkim-atps=neutral Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47Nnj56RGdzDqPN for ; Thu, 28 Nov 2019 17:26:33 +1100 (AEDT) Received: by mail-pg1-x541.google.com with SMTP id z188so12381610pgb.1 for ; Wed, 27 Nov 2019 22:26:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PTxw4ybDCrcvFqq9R1qIu91EA31/ELvggdq1ktW6Fqs=; b=JATbAKWYW3aVQO9pXfeRoQKGB+38NPTAHwyPoPSsfX/x4oMIfTYxn0whnxIGMaI/0u QtJQ2lp1ZEGZvmeXeGfevNNRJE0IY9kvVm42ZJ7WpW1JHPtEPB/BuaGn3UUgLjjdOZCa ZIaWxUeSk4S58qEyghggZcVJhehWsPV5oSZ3AtGf2JrPWK5F6rRUmvyjgONcLSxjP6fN zAIo5t1CG3ayO+fJg334i7YnI1iPD4/Xn8JhHdHGzYw6PFsKn7qhMYqeXX/QEyd3p0za TzrH3ZLIizjaKoKKQIJf4+1gwdvUsnGRv/f4f5mD5tVpQ8Q4Ytct0QA628h4hDh8k6Sb vINg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PTxw4ybDCrcvFqq9R1qIu91EA31/ELvggdq1ktW6Fqs=; b=n0kqASu7PTgCf3tKSCfvTomogUsjMOqqNbk/qk3YZg2ShK2I7ry+Pfiy/fYtNDxe2v h4JkzfMk1C2Pchp2IaV4qdpBlw0JHBMDDCzwUESnY0AgdXG9k78NTRKo+etwVIb/nzF6 +U0sBdyFgStwwo09ckt59FNDxmLBGrmASV/mJK9Wh2iQ03s/UkTW9fDhABFhkOs2FhBC 725H2WufhA9K8k9vX/xskdNwDH+h5wiV67AMTKyXUcHsqrZQTT8/kwOdYpcUr5qzbdNl ASyGyRcaSh+W4n+1zZtQJ8vQh+eS2HCDGPfPnuzr9iu980AYNQGH5g6SBdYUtCpztqtW 9QAQ== X-Gm-Message-State: APjAAAVxuittywIsk2BAjtf1vnPGKRYXnsMEMnsmhbBrQX0FHxAIWm0o JqNGTbD7e0KP2SbZAyL3L/p5NBt4Zi8= X-Google-Smtp-Source: APXvYqx2NLwXkvJxh3MBd/9fZPY98Hvi3gjhpTLIruIFVeDXsmF/JeC6WN3UODMEtIeTZ0Xk+l2f9A== X-Received: by 2002:a63:154d:: with SMTP id 13mr328174pgv.248.1574922390815; Wed, 27 Nov 2019 22:26:30 -0800 (PST) Received: from bobo.local0.net ([203.194.47.34]) by smtp.gmail.com with ESMTPSA id e5sm8463196pjv.29.2019.11.27.22.26.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 22:26:30 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Thu, 28 Nov 2019 16:24:34 +1000 Message-Id: <20191128062442.20690-21-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191128062442.20690-1-npiggin@gmail.com> References: <20191128062442.20690-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v8 20/28] libflash: ecc endian conversions X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Signed-off-by: Nicholas Piggin --- libflash/ecc.c | 36 ++++++++++++++++++++---------------- libflash/ecc.h | 8 ++++---- 2 files changed, 24 insertions(+), 20 deletions(-) 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); /*