From patchwork Mon Feb 10 15:49:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 863780 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e42:0:b0:385:e875:8a9e with SMTP id r2csp1661633wrt; Mon, 10 Feb 2025 07:51:50 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXmAeIOzNDmgVTbPcGh1sBLbcxESdkzNwQud+Jga5EZVSR7Vr8t6x/tIY1432QTwk74YhkCNQ==@linaro.org X-Google-Smtp-Source: AGHT+IHGnGLN5Fw9xycWG+OJcCIesgcqM5b1gbqA7CqgPX0Y2iZCSkBv+DQ836qHKdSpDA9gnCDk X-Received: by 2002:ac8:5a56:0:b0:471:9774:5f39 with SMTP id d75a77b69052e-47197746971mr41087661cf.3.1739202709877; Mon, 10 Feb 2025 07:51:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739202709; cv=none; d=google.com; s=arc-20240605; b=lcsCqIy6cuju/M3QQ4PiTjES8b1x9wMhSW142f7HLqXD47ImEyVK/pGWd0dKhfLArq wtAIyvvS4S+VkDjVp0MJocha3rMvw1HliUrO8OcYCgklc+W6QUyGSEZC3ZcsQemEOjty DLkNhiBmZS/fVfoeOh9Ze05jncVFk3SbOI33bLXEV4JsTLtxeNQpMpdYN914iSx3nfc7 lo/HjlXgt/MnFjztXsy3c6awO2LEX2LUBcXgjnvrquUB1pyiFasj7davpm0CR0qjqj8R zUyWicTCRwELHv1rf+V8Gm42Hk5cr4G68alMNixqLg5E6mN5wLE0hC+sehXk7rlyUbW7 t8Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=3JpDb2mBXISvW4UeQqZGI1/QPv2WFhNstUlA8Z8vw/w=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=j6wOw5ooWjGxDCfilWA3w8LX92zlCtBu8c+qGHb58cG2ptbIbrJZP/0VO8srltcD1x 63gliXZ1W9o8Quey4aVTMjRIPuGgI/TpxjewwU6TNlHvgkAGUqTuGDj0a3EAp5YYp1rE TYYOhcYkVqJHSvQ68KHvslWzA7gHwULSuNRwqGZN3w9EFV5feaIjL379ZrEikLjjj5M8 p78SfOZYPbzNhY7C1sDqiRDmaGSb/DYHJBqSm5fIn9otlY7K7NK0MHcWl1QGWXxb8nQU UBzW+O/owCf2sMn6Ozl1i62GuUN5+i0DPRgFC4rctGlruCIw/iNfQDYzv71lYJLGuLIY UYBw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FusLA1jT; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-4714927b5a5si91189541cf.38.2025.02.10.07.51.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Feb 2025 07:51:49 -0800 (PST) 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=FusLA1jT; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1thW3i-00080Y-7B; Mon, 10 Feb 2025 10:50:55 -0500 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 1thW2o-0007Et-FM for qemu-devel@nongnu.org; Mon, 10 Feb 2025 10:50:01 -0500 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1thW2m-0004iJ-Td for qemu-devel@nongnu.org; Mon, 10 Feb 2025 10:49:58 -0500 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-43934d41730so19145585e9.2 for ; Mon, 10 Feb 2025 07:49:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739202595; x=1739807395; darn=nongnu.org; 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=3JpDb2mBXISvW4UeQqZGI1/QPv2WFhNstUlA8Z8vw/w=; b=FusLA1jTO/S5B7uejDcvEGfT2aW+OMBGV/GkOs/Id9BldmwCwunA/UTQz2YN0RwXpA 76ZcSMonV34dzCKjZ/4t/uE9vF1a2rMeDrENvAirfP02inCMAKI8EjmGI9GgfikV6gpH Qrybx6Ht6fn68btAVB5TVIUNQWchucY1OwnlRIBVXBjWrORuY0BlJSPU9DJOy72zFikM aRzQAsEsFQs6ANuyj8z9jG8Yc926ksGUkYb0uw46Ka89YCNLTlq8GaNrEx+3Jj/GDzag LpAHtP0EJEZg+s3ujK+6/beLHdCgw0XCG9aCMAclQEVjgJ/oh7ExIKHTrx/E8jVBFK8j 9+ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739202595; x=1739807395; 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=3JpDb2mBXISvW4UeQqZGI1/QPv2WFhNstUlA8Z8vw/w=; b=INY/oJbDEgfn96JXVUdEfInjQ5kIuuDvu7i8wAP02vPe903x7c3nMNSwcbgF8KdsBA clzL1ww+CcpHIxZgRMhn7LAeYKhzobDwCrq8w93pHV3MWRXgDTz6Po5ygfrA8qrpuUtc nbcn1BKZnbNPPhDBvaoP6rejf0vKStWeGmeiCabssYaZ0Y5317rNIye777FUk1So9Geg 8lgd23hnOeV+zCXUWuVHskSJQ4rKgMH3ahRoQMSt79rYJmTEVgTv2inPpaty4y6Gc+As r/BsEL23Ld1xaTUw/PuYi15N+XEgtpQYDqpmgSmtk47/djXQXtliO0M9VBUjMdK92wRk LWig== X-Gm-Message-State: AOJu0YyX6rPKfmf98BR/3ErqWoUFABFSNQStSS0l9NSB9L1DkgFUD/+r hpQyaAyKuhKXT6pdtPU9yxOqVJp620EfWsXj3+a7LQPJ+6LrqqwhcLhi6K1Arz0wGG6kRqoGppN 8 X-Gm-Gg: ASbGnctQvhVaYpTwlPWVoDvBvV1Ed6pK1eDF9BQoRFDvRd6UWpnM/E4HVpRHGXslIlg 4ExQ7THihgDKusm0kx6PYcsxma+GnbZH1ia8gjr9Rvm5ybz5yNB4X4qV3ApOxLdGUoT5Xw6liKR 3O0bu6Po9Oc/n5deX5CWLWXqSFFFRISgzzxU+4A2d0u6rUNg4279pb9i44r69GvB1/sVxyBJYWN oMcMRUy8S3xYMsudTRGjw4AkO4OmRFzhJsEai88FxH+ammPHKAGG7SS3kGlKrozaD08za0iuhW0 zOtn1C30hGp2h6bHlu6k X-Received: by 2002:a05:600c:1f8c:b0:439:35d2:ed6 with SMTP id 5b1f17b1804b1-43935d2109emr70352135e9.3.1739202595470; Mon, 10 Feb 2025 07:49:55 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4391dfd8448sm150612845e9.38.2025.02.10.07.49.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 07:49:54 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 10/12] hw/net/cadence_gem: Fix the mask/compare/disable-mask logic Date: Mon, 10 Feb 2025 15:49:40 +0000 Message-Id: <20250210154942.3634878-11-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250210154942.3634878-1-peter.maydell@linaro.org> References: <20250210154942.3634878-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32b.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 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 From: Andrew Yuan Our current handling of the mask/compare logic in the Cadence GEM ethernet device is wrong: (1) we load the same byte twice from rx_buf when creating the compare value (2) we ignore the DISABLE_MASK flag The "Cadence IP for Gigabit Ethernet MAC Part Number: IP7014 IP Rev: R1p12 - Doc Rev: 1.3 User Guide" states that if the DISABLE_MASK bit in type2_compare_x_word_1 is set, the mask_value field in type2_compare_x_word_0 is used as an additional 2 byte Compare Value. Correct these bugs: * in the !disable_mask codepath, use lduw_le_p() so we correctly load a 16-bit value for comparison * in the disable_mask codepath, we load a full 4-byte value from rx_buf for the comparison, set the compare value to the whole of the cr0 register (i.e. the concatenation of the mask and compare fields), and set mask to 0xffffffff to force a 32-bit comparison Signed-off-by: Andrew Yuan Message-id: 20241219061658.805-1-andrew.yuan@jaguarmicro.com Suggested-by: Philippe Mathieu-Daudé [PMM: Expand commit message and comment] Reviewed-by: Peter Maydell Reviewed-by: Edgar E. Iglesias Signed-off-by: Peter Maydell --- hw/net/cadence_gem.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c index f744054a6d8..80fbbacc1e7 100644 --- a/hw/net/cadence_gem.c +++ b/hw/net/cadence_gem.c @@ -909,8 +909,8 @@ static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr, /* Compare A, B, C */ for (j = 0; j < 3; j++) { - uint32_t cr0, cr1, mask, compare; - uint16_t rx_cmp; + uint32_t cr0, cr1, mask, compare, disable_mask; + uint32_t rx_cmp; int offset; int cr_idx = extract32(reg, R_SCREENING_TYPE2_REG0_COMPARE_A_SHIFT + j * 6, R_SCREENING_TYPE2_REG0_COMPARE_A_LENGTH); @@ -946,9 +946,25 @@ static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr, break; } - rx_cmp = rxbuf_ptr[offset] << 8 | rxbuf_ptr[offset]; - mask = FIELD_EX32(cr0, TYPE2_COMPARE_0_WORD_0, MASK_VALUE); - compare = FIELD_EX32(cr0, TYPE2_COMPARE_0_WORD_0, COMPARE_VALUE); + disable_mask = + FIELD_EX32(cr1, TYPE2_COMPARE_0_WORD_1, DISABLE_MASK); + if (disable_mask) { + /* + * If disable_mask is set, mask_value is used as an + * additional 2 byte Compare Value; that is equivalent + * to using the whole cr0 register as the comparison value. + * Load 32 bits of data from rx_buf, and set mask to + * all-ones so we compare all 32 bits. + */ + rx_cmp = ldl_le_p(rxbuf_ptr + offset); + mask = 0xFFFFFFFF; + compare = cr0; + } else { + rx_cmp = lduw_le_p(rxbuf_ptr + offset); + mask = FIELD_EX32(cr0, TYPE2_COMPARE_0_WORD_0, MASK_VALUE); + compare = + FIELD_EX32(cr0, TYPE2_COMPARE_0_WORD_0, COMPARE_VALUE); + } if ((rx_cmp & mask) == (compare & mask)) { matched = true;