From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (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 A436D312837 for ; Wed, 22 Jul 2026 00:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784679354; cv=none; b=s4Fq9V3EoOtUhj+gxWfDH3TneI05i4iUCMvgg4ItD3cTExAevbVfHkWhaxTvgfug64Izd4WeAj7lBebPFXFdZtZUVmR2n7BbKIgAwLLjc1y8pG2p1T55blvzfNFpx6lMFQ2+jR/j1UaO9Vzl4xT1HokhPa0YDMt8bND3/1ayUz0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784679354; c=relaxed/simple; bh=+u92+edGzJUogIivEKHvjJM5J721kuk7QGsl9GsyiVA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fWvbNejil3iuRj7DZd1B9nfw5BjZ+TM/LBgcaR5OiBtLoRzKL4l9tGkeIm5r7+bZJAjGlp2tGIBzp7bndkLZ90WCuzxEamXO1y6wlzKY9+qstgGMhRHw1pybRYDPSXaDC2DpBJg6ZIh6hl/kykFH+jAh6BCZMuhuSTl+P0Z2aMk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jrhilke.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Hb+af4dw; arc=none smtp.client-ip=209.85.214.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jrhilke.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Hb+af4dw" Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2cc6dd43737so224664595ad.2 for ; Tue, 21 Jul 2026 17:15:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784679346; x=1785284146; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=RPmtr/TNEphr6iJROeMyjAAqcZVr5NPU0l3kEo6G8jw=; b=Hb+af4dwxJ2MONl287btlm2st8bDJahde+XGVcdNKEcPwq/Agm8Jw/B5huCKMO0E08 ioCwwEnNjk4Fa0F70TiGHbuHKfpVV1nRrzWYU1uOW+sr4BgGxJQkZVuX65q6UwqqJ37t HVsMaQY4rWRzvDvRY2Sos+8fnFvYYSmsl6b1bb4cN0H389Tisw4WUrw9WeGruNCM2/xM Sm+kMyDTLZ/+fe+0jwsQiH6/xBpjUrRC/DdPbcHCOrBOe9BA8/VbritSkM+lAotwMT/G Fuc84+97ZiNmA7boq0XalNv/WeJpiVYZWDqWZTwMDmZW71r3JzA4OJtksEcdOgXL935V zJDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784679346; x=1785284146; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=RPmtr/TNEphr6iJROeMyjAAqcZVr5NPU0l3kEo6G8jw=; b=qHy5Q1+PskMGjfGzEyiPE6sQG6hSp4MR6bFTkbPLtJHZRGYxkocEdQik9lcANb2XoY bYAha7Y0dlP3sNqfzxAanEZDf4wPiTsvRxEGBxoroJsGsMxHTkBAbsfHtfEZ8HWMgje7 hCHV5wgOgdFDTS0R34Y1TsP+qi//+IIpXmXjdeAu3PSKb4ncUxSS+J5MmebTAkcvyWeY CXZWwY3KQRE7DTVe/KLna2CE38Hwg30Jt4dd9TJNRF6+Z54aX9FxwTpM0ZV8kbP6qSqH CHvpsl9P8XfV7YsB6jQ/tpX4gQIXltcAlTC/YF/tTvgX42DkAc/XUfHm4mWnO6TizwpT E1/Q== X-Forwarded-Encrypted: i=1; AHgh+RpFgNav3MjNilMu31ohUbgGBgNFRhkoEuEVCDKtXoo1FNnArbk80FAMoZeLGIlz17RcammlxrOnTRRy1Mw=@vger.kernel.org X-Gm-Message-State: AOJu0YzR12M0KhyrIGOvewxpyTiA857+pPHkqnJEb/ahnhc9M59OcVpf yhaRR3WM2mmZZc6IuoW4NZB9iv2MvHKnJs/Xqo+73ZmLb6j49XkFuzB4iDuh4hO1xXLu5ttjPGq U563XbtUM X-Received: from pgcp18.prod.google.com ([2002:a63:7412:0:b0:c9a:4ffc:3456]) (user=jrhilke job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:a103:b0:3c0:9c1a:8941 with SMTP id adf61e73a8af0-3c3ada59cd5mr21741694637.73.1784679345554; Tue, 21 Jul 2026 17:15:45 -0700 (PDT) Date: Wed, 22 Jul 2026 00:15:39 +0000 In-Reply-To: <20260722-igb_v3_b4-v6-0-0be1d29918d4@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260722-igb_v3_b4-v6-0-0be1d29918d4@google.com> X-Developer-Key: i=jrhilke@google.com; a=ed25519; pk=cK+Urrh214DoCHywJiTwhMP+zcs1ofpGrewToO/i/3A= X-Developer-Signature: v=1; a=ed25519-sha256; t=1784679337; l=4049; i=jrhilke@google.com; s=20260710; h=from:subject:message-id; bh=3HaO+LlIH5EQwYBLepHXt1276V0e3otp2TZx5sNJQxA=; b=4EgBrBNIcrg+NHGZ5nkD3MnsDofc8PMsdapr/842JIP2bDaGYrH15xDznsSmgyiLoO8X7z9El aD1bo0i0JvQDXiyvjPK8mzZfohuPAiyLS8MVb3xgODFbOwmrpYZPAP1 X-Mailer: b4 0.14.3 Message-ID: <20260722-igb_v3_b4-v6-4-0be1d29918d4@google.com> Subject: [PATCH v6 4/6] vfio: selftests: igb: Factor hardware programming into igb_hw_init() From: Josh Hilke To: David Matlack , Alex Williamson Cc: Shuah Khan , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Vipin Sharma , Josh Hilke , Alex Williamson Content-Type: text/plain; charset="utf-8" From: Alex Williamson Split the device register programming out of igb_init() into a new igb_hw_init() helper so that the same sequence can be re-run after a VFIO_DEVICE_RESET to restore the registers that CTRL.RST clears. No functional change for the initial path. igb_init() now performs the one-shot setup: region size assertion, BAR mapping, CTRL.RST + IMC mask-all to put the device into a known state, and vfio_pci_msix_enable() to set up the kernel-side IRQ trigger. igb_hw_init() does the rest: ring pointer setup and IOVA calc, CTRL_EXT, PCI bus master, GCR, PHY loopback, descriptor rings, RCTL, TCTL, GPIE/EIAC/EIAM/EIMS/IVAR, and driver-state initialization. vfio_pci_msix_enable() moves from after RCTL/TCTL to before all device-side programming. Its only side effects are the VFIO kernel IRQ trigger setup and the PCI MSI-X capability bits in config space; neither has any ordering dependency on the 82576 device register writes performed in igb_hw_init(). Performing it once in igb_init() keeps igb_hw_init() reusable from the reset recovery path (which uses vfio_pci_irq_reenable() to re-arm the existing trigger). Assisted-by: Claude:claude-opus-4-7 Signed-off-by: Alex Williamson Reviewed-by: David Matlack --- tools/testing/selftests/vfio/lib/drivers/igb/igb.c | 41 ++++++++++++++++------ 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/vfio/lib/drivers/igb/igb.c b/tools/testing/selftests/vfio/lib/drivers/igb/igb.c index 2b444be4bdfe..8eaf120330dc 100644 --- a/tools/testing/selftests/vfio/lib/drivers/igb/igb.c +++ b/tools/testing/selftests/vfio/lib/drivers/igb/igb.c @@ -202,7 +202,13 @@ static void igb_reset(struct igb *igb) igb_write32(igb, E1000_IMC, 0xFFFFFFFF); } -static void igb_init(struct vfio_pci_device *device) +/* + * Program the device into a usable state. Split out of igb_init() so it + * can be reused after a device reset to re-program the registers that + * CTRL.RST clears. Expects bar0 to be mapped and MSI-X already enabled + * via VFIO. + */ +static void igb_hw_init(struct vfio_pci_device *device) { struct igb *igb = to_igb_state(device); u64 iova_tx, iova_rx; @@ -210,15 +216,10 @@ static void igb_init(struct vfio_pci_device *device) u16 cmd_reg; int retries; - VFIO_ASSERT_GE(device->driver.region.size, sizeof(struct igb)); - - /* Set up rings and calculate IOVAs */ - igb->bar0 = device->bars[0].vaddr; - iova_tx = to_iova(device, igb->tx_ring); iova_rx = to_iova(device, igb->rx_ring); - igb_reset(igb); + /* Signal that the driver is loaded */ ctrl = igb_read32(igb, E1000_CTRL_EXT); @@ -312,9 +313,6 @@ static void igb_init(struct vfio_pci_device *device) igb_write32(igb, E1000_RCTL, rctl); igb_write32(igb, E1000_TCTL, E1000_TCTL_EN); - /* Enable MSI-X with 1 vector for the test */ - vfio_pci_msix_enable(device, MSIX_VECTOR, 1); - /* * Program MSI-X interrupt routing per 82576 datasheet: * @@ -354,6 +352,29 @@ static void igb_init(struct vfio_pci_device *device) device->driver.msi = MSIX_VECTOR; } +static void igb_init(struct vfio_pci_device *device) +{ + struct igb *igb = to_igb_state(device); + + VFIO_ASSERT_GE(device->driver.region.size, sizeof(struct igb)); + + igb->bar0 = device->bars[0].vaddr; + + igb_reset(igb); + + /* + * Enable MSI-X via VFIO before device-side register programming. + * vfio_pci_msix_enable() only touches the VFIO IRQ machinery and the + * PCI MSI-X capability via config space; it has no ordering + * dependency on the device-side writes performed by igb_hw_init(). + * Placing it here keeps igb_hw_init() reusable from the reset + * recovery path (which calls vfio_pci_irq_reenable() instead). + */ + vfio_pci_msix_enable(device, MSIX_VECTOR, 1); + + igb_hw_init(device); +} + static void igb_remove(struct vfio_pci_device *device) { struct igb *igb = to_igb_state(device); -- 2.55.0.229.g6434b31f56-goog