From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (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 7C8B347A881 for ; Tue, 28 Jul 2026 23:24:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785281092; cv=none; b=KLi5cD1oAVHAM2o7OgPOeIjPZ1Bco7fEOSL/c7RsTzQnKleW4yBmFt+9x+XF0GAQEwclt7LsgYLe21FyhPXgTtDLSSJYz3N3oyJTmYu5BqxkZ8ZdsN0wSHbvwmqv4aDpxuEv/JowpSgUu52MO7yPj+YH/GTLagdOq1QyRsnXzU4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785281092; c=relaxed/simple; bh=CNEjZGm6XOJKjg1XDa3JuFya9nU2rTolgcz77GUddG0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qd513TFofM4QTUQl1povT1/1yNj0sDPn2Jzg6E3wom/mYgD7AhlHIzO55H02v9y0NAR+HNrHQgl9PKFEkWMBDMbV7E/G4+LudPb8xbk5NpKbhxcV2GkPJraDJL8N+88Mlj8YN9roMzZ7W7CYfQk4Uef0ue6bdDoieCuAfppAH8g= 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=ZJRKF3XO; arc=none smtp.client-ip=209.85.216.72 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="ZJRKF3XO" Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-38f5ac7416eso415785a91.3 for ; Tue, 28 Jul 2026 16:24:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785281090; x=1785885890; 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=PL+yCbMYeb2vDt21oqq8Wk84XUCQR+QR8uSeLGmJoFQ=; b=ZJRKF3XOQgbqpVe2h8y49FuDeBCvbIlaOYaE6h0wLmqKQNqVkYHs3InWQUpHU+wmSs rg8uagkjyzAezeTuQxorJO4CkBqZtDGuxzu9lxO7IycdtfpOuVQx3wxDEfOe/HPNSWh5 b+nRWeDaVjg6XmTSBgllxBpqeQpA9gKsnjXOi6STNJMYh/vP/jHosQeFR5+fOWeDJvaf 7PVhHPAFSRLMPUuWqqtwscE1qzY0AmS0+1D5S51ucb7HZXpHQ/algMtBwXwR5CcQpEKK 5Yjn0IrRYY8NEP72wMQX/aV7kFeq2IgWC3MowItsjU0bsdx+71efCMpDmD7MXe4vo2o/ uK/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785281090; x=1785885890; 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=PL+yCbMYeb2vDt21oqq8Wk84XUCQR+QR8uSeLGmJoFQ=; b=bNwLsy9DPC2aXLKIGexXPTlNUPKBsNuxK/T5b9/70+yV+oHdG8yeSaeFd4EzQaKrYS rlGVlcJguwjVqODdjVn9saBQLusY7Gr87nev8E+fNGMVuuJ8bu4L8cj7AmLQXrh0ekYP tjGyZtTc4dtktkS6ic2oeWjYvFjhaPngf5kafzWw5MOvgqLZq4wPuQt3kDUGF5G0vtUP 2/DDll5CYj5v2YlYh/bVu5qKTdB7Sscy1i6g8Ha9FNe4N5vaJNrhpX+0DdGxD3L8HGl2 u1IRoi0VlaIGyUbwi+1jiqhEozm6E94oG7lH9XVYlrjk7JnIsSOY2LOrBoIwnZnkElNU L1yQ== X-Forwarded-Encrypted: i=1; AHgh+RpDQOqX2QrkJX41oHKeHOHru5itw6vMcP0520FFGE1R+6/jeVPGDh0FaLVMl3HSDxwwrSlPbro49Xrq05w=@vger.kernel.org X-Gm-Message-State: AOJu0Yxjp6NBChHsM7RwzPLb/Lilp84N5PuE4L3UgnXsFEDEZQdUltlY uA2gSzGebxSGG9ZbGgupSCcccOWsmQLF9f9NJ7WJlPmBHbBsBca8+WI+NSCHanoYKexSVCdKTzG PEtfK4+BS X-Received: from pjd13.prod.google.com ([2002:a17:90b:54cd:b0:380:f969:825e]) (user=jrhilke job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:47:b0:37f:9cdf:f03e with SMTP id 98e67ed59e1d1-38f6a427cc5mr4616277a91.33.1785281089613; Tue, 28 Jul 2026 16:24:49 -0700 (PDT) Date: Tue, 28 Jul 2026 23:24:29 +0000 In-Reply-To: <20260728-igb_v3_b4-v7-0-4616c3745796@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260728-igb_v3_b4-v7-0-4616c3745796@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=1785281084; l=4049; i=jrhilke@google.com; s=20260710; h=from:subject:message-id; bh=DDeLZleCjdmHXzE6kbgiq69I8h1p3F5RXXWU8wYy6YU=; b=84AW0Ywvpd/bE8OLbiFcZ37MVoDzjJ6yXIQJaP9QdS/kAg9SgDwH5rIGEV9lhMjxSz69cRNQX L7T4sWUbCaDDPIOt/mcMyi3ac4Urc1P4yqvOSD7G93YvYslF5WbylUm X-Mailer: b4 0.14.3 Message-ID: <20260728-igb_v3_b4-v7-4-4616c3745796@google.com> Subject: [PATCH v7 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 1b30a188a864..12fce3d69025 100644 --- a/tools/testing/selftests/vfio/lib/drivers/igb/igb.c +++ b/tools/testing/selftests/vfio/lib/drivers/igb/igb.c @@ -224,7 +224,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; @@ -232,15 +238,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); @@ -334,9 +335,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: * @@ -376,6 +374,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.487.gaf234c4eb3-goog