From patchwork Tue May 2 12:14:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 678364 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a41:0:0:0:0:0 with SMTP id v1csp471607wrs; Tue, 2 May 2023 05:18:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ45En+E8etb01TCA0H9losG8bDgmt7V9J9LN2/H30gmtddRZGG1i4FCwZI+7MiBm86ZhrUz X-Received: by 2002:ac8:7d03:0:b0:3e4:e4c7:586a with SMTP id g3-20020ac87d03000000b003e4e4c7586amr28458935qtb.4.1683029903793; Tue, 02 May 2023 05:18:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683029903; cv=none; d=google.com; s=arc-20160816; b=OUbZj3HOsRH6xCS0oKmvjRwrW1D9Ah2WgF9q6KJqT4RjKBgYklJp06FHSFCgRoVx0/ Ub6GzcxPXKIeL1llhPJyhDpupvnWZZylDx4wNqJ09dV3v7R841O8JzEg56Jt+8wKHpra BTE/bJOVMCenHwZH82iPSIG7DAed11mTyFSzrWL+QarYQUmLyl1R7dFjQioeOAuH+7W1 5BtcGJdpPF3eRNH7qf8sBLk2DUF+RO55wrqzAOEmvf7QPAh57PidGVZiomJ3E1TiN72X L9QTVhiTN6dW0IWI/4YgCSHXOTfwBa9l81BpwTrbb3Y7y6x0LghZKzn+YehYacHDJVBk F3hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=t26Zipv849X9PCMx5u9NQYkbvFdgca4hd67t8neW/ro=; b=aBWYL1bl2YJb3P0MnQ3vUlfZ1RrDQnZCxqsX2tah6kwcG6Aun9UXOqT5WEYatiCjcl t8TKlrdwUbzE5vFhJiDb1w1T8ylLkbEzHd8zafJ+CtPwReEol4mVsIlJHoB/ZHS9sur1 3aRUSGshSiqcKF4AUmYdk79OTb2uXA3EX7+Sr3I9KdzKWbnooi79R1h8EWtOVYC2RUJf 8mp2mbf9kThONBlAsa+6uQAcDrjviWkr4TsSb6fEFuKC/JxflC/lHE2+vq/eW71G+CUu ScAwVD6mTrraFl2xMsHl1YUQm1SRVJfcegwi40Cp/1oxIUqYby9wNlpl1/7VB8YdKEKX tM1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ZQfLD/Tr"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e16-20020ac85dd0000000b003f09fc34d3bsi11942627qtx.348.2023.05.02.05.18.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 May 2023 05:18:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ZQfLD/Tr"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ptovS-0004hS-Gy; Tue, 02 May 2023 08:16:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ptoun-0003qL-Al for qemu-devel@nongnu.org; Tue, 02 May 2023 08:15:36 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ptouh-0002zl-J2 for qemu-devel@nongnu.org; Tue, 02 May 2023 08:15:26 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3f1e2555b5aso23995815e9.0 for ; Tue, 02 May 2023 05:15:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683029716; x=1685621716; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=t26Zipv849X9PCMx5u9NQYkbvFdgca4hd67t8neW/ro=; b=ZQfLD/Trv+tY2REWw7UfNu6QFhQPYt2K4HqHIJQ/oWheM2jArWgFdgcjiqHpfrXMDq MKVARKxBEnwIPDUyJOSG6m6NLaBO/WgWgPlUgaB2Y5TjnbWvwp5obxQwbQsXMlNrkA+F i3hVFxIjfuYh4eEy6sxTbY6Ib2dvwBRshaEX4pu8Yta1COUEg06OF+HyME7DgqEvFsgu 3p48GhslB9mUbQItjeKbqIYaPvD5NP1Jhl2gKiISUWgQYx3wOz3MstK5JHFXyWGsNCXK v5OstmUVV4bWfzIsQD9yfmXd6g30f25lrfBKhf4le5K3cZaQjAG5ZegRS5hTSvCjo6oI xD+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683029716; x=1685621716; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t26Zipv849X9PCMx5u9NQYkbvFdgca4hd67t8neW/ro=; b=i+CPJDJB+1FJb6EPpepc9BsSlux19jJ43aQ+/s9jwZcSblsnP67i+djBbyLZ25FvQo p59HtDHjlwwoOfqseZDm0YeBCLiPg61+pEAE7wxDUGqbLdWskz1AgEBJ+ztEmVTQQ5GJ 4hsFKEAyEbcrb7flY4sFTuqAZLeHxzwq8WJQL+XG7Ka00ZItddF4ZJXuryUQKfcL6Jwo WnF7dmqtkhUSSmMwnG7BUmgKhHVo9a3bAhuZsNOBWQ6Ct1ZaTWQcuuuOjOdmqGnJU9wN JJOxMl+0e8s39tfehyrQy3RWNg4uEQ0NvfpJztn9QcMyVZEz8+mispCTssYzOxm2NTmt yDdQ== X-Gm-Message-State: AC+VfDxaSNdl9AdcHq5IcPJ5psQ9yCsKIdTVcR3osHQWFbH9qGVB0SRQ EvQJCN6ZgQqsvC9ORBlXB4M2SSUftWwBMNtcyCk= X-Received: by 2002:a7b:c408:0:b0:3f1:75b6:8c7 with SMTP id k8-20020a7bc408000000b003f175b608c7mr11527959wmi.37.1683029716725; Tue, 02 May 2023 05:15:16 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id g10-20020a7bc4ca000000b003f171234a08sm35040330wmk.20.2023.05.02.05.15.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 05:15:16 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 35/35] hw/net/allwinner-sun8i-emac: Correctly byteswap descriptor fields Date: Tue, 2 May 2023 13:14:59 +0100 Message-Id: <20230502121459.2422303-36-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230502121459.2422303-1-peter.maydell@linaro.org> References: <20230502121459.2422303-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x329.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org In allwinner-sun8i-emac we just read directly from guest memory into a host FrameDescriptor struct and back. This only works on little-endian hosts. Reading and writing of descriptors is already abstracted into functions; make those functions also handle the byte-swapping so that TransferDescriptor structs as seen by the rest of the code are always in host-order, and fix two places that were doing ad-hoc descriptor reading without using the functions. Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell Reviewed-by: Thomas Huth Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Message-id: 20230424165053.1428857-3-peter.maydell@linaro.org --- hw/net/allwinner-sun8i-emac.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/hw/net/allwinner-sun8i-emac.c b/hw/net/allwinner-sun8i-emac.c index b861d8ff352..fac4405f452 100644 --- a/hw/net/allwinner-sun8i-emac.c +++ b/hw/net/allwinner-sun8i-emac.c @@ -350,8 +350,13 @@ static void allwinner_sun8i_emac_get_desc(AwSun8iEmacState *s, FrameDescriptor *desc, uint32_t phys_addr) { - dma_memory_read(&s->dma_as, phys_addr, desc, sizeof(*desc), + uint32_t desc_words[4]; + dma_memory_read(&s->dma_as, phys_addr, &desc_words, sizeof(desc_words), MEMTXATTRS_UNSPECIFIED); + desc->status = le32_to_cpu(desc_words[0]); + desc->status2 = le32_to_cpu(desc_words[1]); + desc->addr = le32_to_cpu(desc_words[2]); + desc->next = le32_to_cpu(desc_words[3]); } static uint32_t allwinner_sun8i_emac_next_desc(AwSun8iEmacState *s, @@ -400,10 +405,15 @@ static uint32_t allwinner_sun8i_emac_tx_desc(AwSun8iEmacState *s, } static void allwinner_sun8i_emac_flush_desc(AwSun8iEmacState *s, - FrameDescriptor *desc, + const FrameDescriptor *desc, uint32_t phys_addr) { - dma_memory_write(&s->dma_as, phys_addr, desc, sizeof(*desc), + uint32_t desc_words[4]; + desc_words[0] = cpu_to_le32(desc->status); + desc_words[1] = cpu_to_le32(desc->status2); + desc_words[2] = cpu_to_le32(desc->addr); + desc_words[3] = cpu_to_le32(desc->next); + dma_memory_write(&s->dma_as, phys_addr, &desc_words, sizeof(desc_words), MEMTXATTRS_UNSPECIFIED); } @@ -638,8 +648,7 @@ static uint64_t allwinner_sun8i_emac_read(void *opaque, hwaddr offset, break; case REG_TX_CUR_BUF: /* Transmit Current Buffer */ if (s->tx_desc_curr != 0) { - dma_memory_read(&s->dma_as, s->tx_desc_curr, &desc, sizeof(desc), - MEMTXATTRS_UNSPECIFIED); + allwinner_sun8i_emac_get_desc(s, &desc, s->tx_desc_curr); value = desc.addr; } else { value = 0; @@ -652,8 +661,7 @@ static uint64_t allwinner_sun8i_emac_read(void *opaque, hwaddr offset, break; case REG_RX_CUR_BUF: /* Receive Current Buffer */ if (s->rx_desc_curr != 0) { - dma_memory_read(&s->dma_as, s->rx_desc_curr, &desc, sizeof(desc), - MEMTXATTRS_UNSPECIFIED); + allwinner_sun8i_emac_get_desc(s, &desc, s->rx_desc_curr); value = desc.addr; } else { value = 0;