From nobody Thu Apr 9 23:24:23 2026 Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5887F19E7F7 for ; Thu, 5 Mar 2026 15:10:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772723402; cv=none; b=uxG0G/goXcojkp94X1C1GAqlSm7wC16HL+GslkhxO9+0WL4VbX/diST0qi4X0gFrwyGhR1psJVEaL60bACk3cTbtJJF+FXnm703ipAeSKhM/Y1wWOxO480BsC+WDtKPuVhpKM0lMAIPXKC7H+MMbVDhxcQO6uvTsPJ+fS1Ayw4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772723402; c=relaxed/simple; bh=1NS1S6/8Ze2Z0/M3844fFfkCENDcmedAZ/SnBm1J5h0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RFDlFS9gkGkgGS57HMnbhFobcymjdsWJkcKpvBL+7kiqqwS0SdtnLoq2X0yKN8tAjQNblqbLJBUX6oGyDGxFqVbKgxC4R9dRwlINjDZt3dnSFYCvNwxfE8qgFPFk9Pt6AesaNW9r3UZJn91/29vOwRC8efWRKxgZ3VGPUVZh2+U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DZJRqTVq; arc=none smtp.client-ip=209.85.219.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DZJRqTVq" Received: by mail-qv1-f41.google.com with SMTP id 6a1803df08f44-899f8c33c11so42800396d6.1 for ; Thu, 05 Mar 2026 07:10:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772723399; x=1773328199; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=75guPzLnund8QIHTGwjGBLHPWaMv1GdwyGtIfQpeONU=; b=DZJRqTVqGm8XIMBBIrM19obpO+LrdXb6lfO4yyl33KFXH+Z67HcLti+fo8FUc9SkGR Bfo+EnQthsGd8ZuYx84ghbMcy196lCzayEQ7nQjJ5NIHQIJz70E+xlg9bVzinXvihADB bZnK+xR1hC6v6pZ5bW4Y73Iz5Hfpob9cuBEH3R6LsZUcnFi0/xyqnxLYi5900AvDyqA2 YKJUbgSJZvywRN9/JLTjrElVjMsdMTz8loYTC56oynFwPc0iK7F0g8dBN15EHFffIU57 MfPfNU0stwJpxKhDP+j6o3QpyawRw9KpqV/7nojoXi+2mBA0p+U8tqIp/3KvTtRap5/I uREg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772723399; x=1773328199; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=75guPzLnund8QIHTGwjGBLHPWaMv1GdwyGtIfQpeONU=; b=h+1t/i5Ej7bvCm8NNqK9dCTd0+tMkauowG1ZQzYh1DUakRoxZPzIJvKY6+G78ZV92k 1EXM+QrtgEGJLW4+ea+DvDi6LmL39OhmizdzItPxK6hSj49ioSjRQGsVR2WCDpsxSdOP e7UL6QB7gcw6Fga2VjxGOPq1DXHGhY9mMyx7qlCPlVi9NbpvamJBQyf1/kWukb3islpl vH2PlUarAcqeLNmT9ZwdbE2t9zFfD3ygXnv2KYONKrHoQTrL74vIDG6V53za6Lxxg3w8 jU6vdoEb1ViftLJV+QZhOOHuTBo3WUlcK08dR2XGhDKUzb8vayailJn9KKigE83hxCR3 1HaA== X-Forwarded-Encrypted: i=1; AJvYcCU13ILF/uUbOF5oPeTdQoFDk2CXVnCWKXeMuE3B9JYKdfgl7v/y2ktS6OEjD0l18697zDMT7z1bP0G15M8=@vger.kernel.org X-Gm-Message-State: AOJu0Yzhco5lSDntboUa9O5kQ2vWMFRs5H505dBM41jQ688dh+rLMT75 6qyqFMQVy/slzGS2XNE1CQbz6A4J8HmAhYaVPvEzzO5nsdJpO6oUvKWY X-Gm-Gg: ATEYQzzVQiUb6IrSXGn8iQs6hGM/qiszHlkajOmGAofIK63vGYKB/33GFNLYU05wp+O xs31BPUAfdzzUpmSYpnJ9WQkDyuGTcX1AP83F2eKWv19Id2o697WzM/UwCa2dws8OMJn5iEeeN2 tI/zAruWSlBpkdG3RbCoNe5rIbY6skqglslb4CVe8/0TE8wJ7fY5KRl+fBZ6gNVyA3mUhL9zq4g PfKWXp2LVHjgnWBWfTFZfGHV+U190oE96DoekuLpLJYVV7D8AbcUo4ttPpsTX27wXtS1KPDybUw kWeiREqVN+88cN7F5fNZgSBaM8+ANjRiRlBVgyG0h33L2kW1q02NQ9FHUGCUhfviKqXQcLOeQRq ZCY82Jbvppeg8pOs0S8HDcVBhGzbzXs/Uwou0OUO9C52b8XgYjZexAC+jT8DbMQxlP/MAnEFJNN 3A2zfEJUrjK6Oyq7I4tvl+ut/FluCJlbX/AdzUkH86y8pqPXO4SwjKIMhf5vA+nAI2YHymryTje 0O+Dj5GHP+H5gLt X-Received: by 2002:a05:6214:2b06:b0:899:fad1:64e7 with SMTP id 6a1803df08f44-89a19d02056mr74295566d6.47.1772723399159; Thu, 05 Mar 2026 07:09:59 -0800 (PST) Received: from PF5YBGDS.localdomain (70.15.25.19.res-cmts.sm3.ptd.net. [70.15.25.19]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-89a0bb6e27asm64183176d6.2.2026.03.05.07.09.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2026 07:09:58 -0800 (PST) From: mike.marciniszyn@gmail.com To: Alexander Duyck , Jakub Kicinski , kernel-team@meta.com, Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Russell King , Jacob Keller , Lee Trager , Mohsin Bashir , Dan Carpenter , Pei Xiao , Stanislav Fomichev , Willem de Bruijn , Samiullah Khawaja , Hangbin Liu Cc: mike.marciniszyn@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 2/5] eth fbnic: Add register self test Date: Thu, 5 Mar 2026 10:09:44 -0500 Message-ID: <20260305150947.16893-3-mike.marciniszyn@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260305150947.16893-1-mike.marciniszyn@gmail.com> References: <20260305150947.16893-1-mike.marciniszyn@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Marciniszyn (Meta)" The register test will be used to verify hardware is behaving as expected. The test itself will have us writing to registers that should have no side effects due to us resetting after the test has been completed. While the test is being run the interface should be offline. This patch counts on the first patch of this series to export netif_open() and also ensures that the half close calls netif_close() to avoid deadlock. Signed-off-by: Mike Marciniszyn (Meta) --- v2 - add enum for test return codes - place forward of struct fbnic_dev after include with a blank line v3 - no changes drivers/net/ethernet/meta/fbnic/fbnic.h | 18 +++ drivers/net/ethernet/meta/fbnic/fbnic_csr.c | 128 ++++++++++++++++++ drivers/net/ethernet/meta/fbnic/fbnic_csr.h | 19 +++ .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 50 +++++++ 3 files changed, 197 insertions(+) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_csr.c b/drivers/net/ethe= rnet/meta/fbnic/fbnic_csr.c index d9c0dc1c2af9..dc62d623e37c 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_csr.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_csr.c @@ -147,3 +147,131 @@ int fbnic_csr_regs_len(struct fbnic_dev *fbd) =20 return len; } + +/* CSR register test data + * + * The register test will be used to verify hardware is behaving as expect= ed. + * + * The test itself will have us writing to registers that should have no + * side effects due to us resetting after the test has been completed. + * While the test is being run the interface should be offline. + */ +struct fbnic_csr_reg_test_data { + int reg; + u16 reg_offset; + u8 array_len; + u32 read; + u32 write; +}; + +#define FBNIC_QUEUE_REG_TEST(_name, _read, _write) { \ + .reg =3D FBNIC_QUEUE(0) + FBNIC_QUEUE_##_name, \ + .reg_offset =3D FBNIC_QUEUE_STRIDE, \ + .array_len =3D 64, \ + .read =3D _read, \ + .write =3D _write \ +} + +static const struct fbnic_csr_reg_test_data pattern_test[] =3D { + FBNIC_QUEUE_REG_TEST(TWQ0_CTL, FBNIC_QUEUE_TWQ_CTL_RESET, + FBNIC_QUEUE_TWQ_CTL_RESET), + FBNIC_QUEUE_REG_TEST(TWQ0_PTRS, 0, ~0), + FBNIC_QUEUE_REG_TEST(TWQ0_SIZE, FBNIC_QUEUE_TWQ_SIZE_MASK, ~0), + FBNIC_QUEUE_REG_TEST(TWQ0_BAL, FBNIC_QUEUE_BAL_MASK, ~0), + FBNIC_QUEUE_REG_TEST(TWQ0_BAH, ~0, ~0), + FBNIC_QUEUE_REG_TEST(TWQ1_CTL, FBNIC_QUEUE_TWQ_CTL_RESET, + FBNIC_QUEUE_TWQ_CTL_RESET), + FBNIC_QUEUE_REG_TEST(TWQ1_PTRS, 0, ~0), + FBNIC_QUEUE_REG_TEST(TWQ1_SIZE, FBNIC_QUEUE_TWQ_SIZE_MASK, ~0), + FBNIC_QUEUE_REG_TEST(TWQ1_BAL, FBNIC_QUEUE_BAL_MASK, ~0), + FBNIC_QUEUE_REG_TEST(T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DQ_PPQ_BAH, ~0, ~0), +}; + +static enum fbnic_reg_self_test_codes +fbnic_csr_reg_pattern_test(struct fbnic_dev *fbd, int index, + const struct fbnic_csr_reg_test_data *test_data) +{ + static const u32 pattern[] =3D { ~0, 0x5A5A5A5A, 0xA5A5A5A5, 0}; + enum fbnic_reg_self_test_codes reg; + int i; + + reg =3D test_data->reg + test_data->reg_offset * index; + for (i =3D 0; i < ARRAY_SIZE(pattern); i++) { + u32 val =3D pattern[i] & test_data->write; + u32 result; + + wr32(fbd, reg, val); + result =3D rd32(fbd, reg); + val &=3D test_data->read; + + if (result =3D=3D val) + continue; + + dev_err(fbd->dev, + "%s: reg 0x%06X failed, expected 0x%08X received 0x%08X\n", + __func__, reg, val, result); + + /* Note that FBNIC_INTR_STATUS(0) could be tested and fail + * and the result would not be reported since the register + * offset is 0. However as that register isn't included in + * the register test that isn't an issue. + */ + return reg; + } + + return FBNIC_REG_TEST_SUCCESS; +} + +/** + * fbnic_csr_regs_test() - Verify behavior of NIC registers + * @fbd: device to test + * + * This function is meant to test the bit values of various registers in + * the NIC device. Specifically this test will verify which bits are + * writable and which ones are not. It will write varying patterns of bits + * to the registers testing for sticky bits, or bits that are writable but + * should not be. + * + * Return: FBNIC_REG_TEST_SUCCESS on success, register number on failure + **/ +enum fbnic_reg_self_test_codes fbnic_csr_regs_test(struct fbnic_dev *fbd) +{ + const struct fbnic_csr_reg_test_data *test_data; + + for (test_data =3D pattern_test; + test_data < pattern_test + ARRAY_SIZE(pattern_test); test_data++) { + u32 i; + + for (i =3D 0; i < test_data->array_len; i++) { + enum fbnic_reg_self_test_codes reg =3D + fbnic_csr_reg_pattern_test(fbd, i, test_data); + + if (reg) + return reg; + } + } + + return FBNIC_REG_TEST_SUCCESS; +} diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_csr.h b/drivers/net/ethe= rnet/meta/fbnic/fbnic_csr.h index b717db879cd3..7cfb42067327 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_csr.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_csr.h @@ -6,6 +6,8 @@ =20 #include =20 +struct fbnic_dev; + #define CSR_BIT(nr) (1u << (nr)) #define CSR_GENMASK(h, l) GENMASK(h, l) =20 @@ -1210,4 +1212,21 @@ enum{ FBNIC_CSR_VERSION_V1_0_ASIC =3D 1, }; =20 +/** + * enum fbnic_reg_self_test_codes - return codes from self test routines + * + * This is the code that is returned from the register self test + * routines. + * + * The test either returns success or the register number + * that failed during the test. + * + * @FBNIC_REG_TEST_SUCCESS: no errors + */ +enum fbnic_reg_self_test_codes { + FBNIC_REG_TEST_SUCCESS =3D 0, +}; + +enum fbnic_reg_self_test_codes fbnic_csr_regs_test(struct fbnic_dev *fbd); + #endif /* _FBNIC_CSR_H_ */ diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c b/drivers/net/= ethernet/meta/fbnic/fbnic_ethtool.c index 11745a2d8a44..2e882dbd408d 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c @@ -126,6 +126,16 @@ static const struct fbnic_stat fbnic_gstrings_xdp_stat= s[] =3D { #define FBNIC_STATS_LEN \ (FBNIC_HW_STATS_LEN + FBNIC_XDP_STATS_LEN * FBNIC_MAX_XDPQS) =20 +enum fbnic_self_test_results { + TEST_REG =3D 0, +}; + +static const char fbnic_gstrings_self_test[][ETH_GSTRING_LEN] =3D { + [TEST_REG] =3D "Register test (offline)", +}; + +#define FBNIC_TEST_LEN ARRAY_SIZE(fbnic_gstrings_self_test) + static void fbnic_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvin= fo) { @@ -475,6 +485,10 @@ static void fbnic_get_strings(struct net_device *dev, = u32 sset, u8 *data) for (i =3D 0; i < FBNIC_MAX_XDPQS; i++) fbnic_get_xdp_queue_strings(&data, i); break; + case ETH_SS_TEST: + memcpy(data, fbnic_gstrings_self_test, + sizeof(fbnic_gstrings_self_test)); + break; } } =20 @@ -566,6 +580,8 @@ static int fbnic_get_sset_count(struct net_device *dev,= int sset) switch (sset) { case ETH_SS_STATS: return FBNIC_STATS_LEN; + case ETH_SS_TEST: + return FBNIC_TEST_LEN; default: return -EOPNOTSUPP; } @@ -1475,6 +1491,39 @@ fbnic_remove_rxfh_context(struct net_device *netdev, return 0; } =20 +static int fbnic_ethtool_regs_test(struct net_device *netdev, u64 *data) +{ + struct fbnic_net *fbn =3D netdev_priv(netdev); + struct fbnic_dev *fbd =3D fbn->fbd; + + *data =3D fbnic_csr_regs_test(fbd); + + return !!*data; +} + +static void fbnic_self_test(struct net_device *netdev, + struct ethtool_test *eth_test, u64 *data) +{ + bool if_running =3D netif_running(netdev); + + if (!(eth_test->flags & ETH_TEST_FL_OFFLINE)) { + data[TEST_REG] =3D 0; + return; + } + + if (if_running) + netif_close(netdev); + + if (fbnic_ethtool_regs_test(netdev, &data[TEST_REG])) + eth_test->flags |=3D ETH_TEST_FL_FAILED; + + if (if_running && netif_open(netdev, NULL)) { + netdev_err(netdev, + "Failed to re-initialize hardware following test\n"); + eth_test->flags |=3D ETH_TEST_FL_FAILED; + } +} + static void fbnic_get_channels(struct net_device *netdev, struct ethtool_channels *ch) { @@ -1893,6 +1942,7 @@ static const struct ethtool_ops fbnic_ethtool_ops =3D= { .get_pause_stats =3D fbnic_get_pause_stats, .get_pauseparam =3D fbnic_phylink_get_pauseparam, .set_pauseparam =3D fbnic_phylink_set_pauseparam, + .self_test =3D fbnic_self_test, .get_strings =3D fbnic_get_strings, .get_ethtool_stats =3D fbnic_get_ethtool_stats, .get_sset_count =3D fbnic_get_sset_count, --=20 2.43.0