virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Shannon Nelson via Virtualization <virtualization@lists.linux-foundation.org>
To: <jasowang@redhat.com>, <mst@redhat.com>,
	<virtualization@lists.linux-foundation.org>,
	<shannon.nelson@amd.com>, <brett.creeley@amd.com>,
	<netdev@vger.kernel.org>
Cc: simon.horman@corigine.com, drivers@pensando.io
Subject: [PATCH v6 virtio 01/11] virtio: allow caller to override device id in vp_modern
Date: Mon, 15 May 2023 19:55:11 -0700	[thread overview]
Message-ID: <20230516025521.43352-2-shannon.nelson@amd.com> (raw)
In-Reply-To: <20230516025521.43352-1-shannon.nelson@amd.com>

To add a bit of vendor flexibility with various virtio based devices,
allow the caller to check for a different device id.  This adds a function
pointer field to struct virtio_pci_modern_device to specify an override
device id check.  If defined by the driver, this function will be called
to check that the PCI device is the vendor's expected device, and will
return the found device id to be stored in mdev->id.device.  This allows
vendors with alternative vendor device ids to use this library on their
own device BAR.

Note: A lot of the diff in this is simply indenting the existing code
into an else block.

Signed-off-by: Shannon Nelson <shannon.nelson@amd.com>
Acked-by: Jason Wang <jasowang@redhat.com>
---
 drivers/virtio/virtio_pci_modern_dev.c | 30 ++++++++++++++++----------
 include/linux/virtio_pci_modern.h      |  3 +++
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/drivers/virtio/virtio_pci_modern_dev.c b/drivers/virtio/virtio_pci_modern_dev.c
index 869cb46bef96..9b2d6614de67 100644
--- a/drivers/virtio/virtio_pci_modern_dev.c
+++ b/drivers/virtio/virtio_pci_modern_dev.c
@@ -218,21 +218,29 @@ int vp_modern_probe(struct virtio_pci_modern_device *mdev)
 	int err, common, isr, notify, device;
 	u32 notify_length;
 	u32 notify_offset;
+	int devid;
 
 	check_offsets();
 
-	/* We only own devices >= 0x1000 and <= 0x107f: leave the rest. */
-	if (pci_dev->device < 0x1000 || pci_dev->device > 0x107f)
-		return -ENODEV;
-
-	if (pci_dev->device < 0x1040) {
-		/* Transitional devices: use the PCI subsystem device id as
-		 * virtio device id, same as legacy driver always did.
-		 */
-		mdev->id.device = pci_dev->subsystem_device;
+	if (mdev->device_id_check) {
+		devid = mdev->device_id_check(pci_dev);
+		if (devid < 0)
+			return devid;
+		mdev->id.device = devid;
 	} else {
-		/* Modern devices: simply use PCI device id, but start from 0x1040. */
-		mdev->id.device = pci_dev->device - 0x1040;
+		/* We only own devices >= 0x1000 and <= 0x107f: leave the rest. */
+		if (pci_dev->device < 0x1000 || pci_dev->device > 0x107f)
+			return -ENODEV;
+
+		if (pci_dev->device < 0x1040) {
+			/* Transitional devices: use the PCI subsystem device id as
+			 * virtio device id, same as legacy driver always did.
+			 */
+			mdev->id.device = pci_dev->subsystem_device;
+		} else {
+			/* Modern devices: simply use PCI device id, but start from 0x1040. */
+			mdev->id.device = pci_dev->device - 0x1040;
+		}
 	}
 	mdev->id.vendor = pci_dev->subsystem_vendor;
 
diff --git a/include/linux/virtio_pci_modern.h b/include/linux/virtio_pci_modern.h
index c4eeb79b0139..e7b1db1dd0bb 100644
--- a/include/linux/virtio_pci_modern.h
+++ b/include/linux/virtio_pci_modern.h
@@ -38,6 +38,9 @@ struct virtio_pci_modern_device {
 	int modern_bars;
 
 	struct virtio_device_id id;
+
+	/* optional check for vendor virtio device, returns dev_id or -ERRNO */
+	int (*device_id_check)(struct pci_dev *pdev);
 };
 
 /*
-- 
2.17.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

  reply	other threads:[~2023-05-16  2:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16  2:55 [PATCH v6 virtio 00/11] pds_vdpa driver Shannon Nelson via Virtualization
2023-05-16  2:55 ` Shannon Nelson via Virtualization [this message]
2023-05-16  2:55 ` [PATCH v6 virtio 02/11] virtio: allow caller to override device DMA mask in vp_modern Shannon Nelson via Virtualization
2023-05-16  2:55 ` [PATCH v6 virtio 03/11] pds_vdpa: Add new vDPA driver for AMD/Pensando DSC Shannon Nelson via Virtualization
2023-05-16  2:55 ` [PATCH v6 virtio 04/11] pds_vdpa: move enum from common to adminq header Shannon Nelson via Virtualization
2023-05-16  6:12   ` Michael S. Tsirkin
2023-05-16 16:38     ` Shannon Nelson via Virtualization
2023-05-16  2:55 ` [PATCH v6 virtio 05/11] pds_vdpa: new adminq entries Shannon Nelson via Virtualization
2023-05-16  2:55 ` [PATCH v6 virtio 06/11] pds_vdpa: get vdpa management info Shannon Nelson via Virtualization
2023-05-16  2:55 ` [PATCH v6 virtio 07/11] pds_vdpa: virtio bar setup for vdpa Shannon Nelson via Virtualization
2023-05-16  2:55 ` [PATCH v6 virtio 08/11] pds_vdpa: add vdpa config client commands Shannon Nelson via Virtualization
2023-05-16  2:55 ` [PATCH v6 virtio 09/11] pds_vdpa: add support for vdpa and vdpamgmt interfaces Shannon Nelson via Virtualization
     [not found]   ` <ZGNcZHUAC21S+uSK@corigine.com>
2023-05-16 16:39     ` Shannon Nelson via Virtualization
2023-05-16  2:55 ` [PATCH v6 virtio 10/11] pds_vdpa: subscribe to the pds_core events Shannon Nelson via Virtualization
2023-05-16  3:30   ` Jason Wang
2023-05-16  2:55 ` [PATCH v6 virtio 11/11] pds_vdpa: pds_vdps.rst and Kconfig Shannon Nelson via Virtualization
2023-05-16  3:29   ` Jason Wang
2023-05-17  2:24   ` kernel test robot
2023-05-17  3:56     ` Shannon Nelson via Virtualization

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230516025521.43352-2-shannon.nelson@amd.com \
    --to=virtualization@lists.linux-foundation.org \
    --cc=brett.creeley@amd.com \
    --cc=drivers@pensando.io \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=shannon.nelson@amd.com \
    --cc=simon.horman@corigine.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).