From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754196AbbAUPJh (ORCPT ); Wed, 21 Jan 2015 10:09:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53506 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753609AbbAUPAt (ORCPT ); Wed, 21 Jan 2015 10:00:49 -0500 Date: Wed, 21 Jan 2015 17:00:42 +0200 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Rusty Russell , virtualization@lists.linux-foundation.org, Gerd Hoffmann Subject: [PATCH pre-squash 12/14] virtio_pci: add module param to force legacy mode Message-ID: <1421852375-22604-13-git-send-email-mst@redhat.com> References: <1421852375-22604-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1421852375-22604-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If set, try legacy interface first, modern one if that fails. Useful to work around device/driver bugs, and for compatibility testing. Signed-off-by: Michael S. Tsirkin Signed-off-by: Rusty Russell Tested-by: Gerd Hoffmann --- drivers/virtio/virtio_pci_common.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c index 8ae34a3..0f87b99 100644 --- a/drivers/virtio/virtio_pci_common.c +++ b/drivers/virtio/virtio_pci_common.c @@ -19,6 +19,14 @@ #include "virtio_pci_common.h" +static bool force_legacy = false; + +#if IS_ENABLED(CONFIG_VIRTIO_PCI_LEGACY) +module_param(force_legacy, bool, 0444); +MODULE_PARM_DESC(force_legacy, + "Force legacy mode for transitional virtio 1 devices"); +#endif + /* wait for pending irq handlers */ void vp_synchronize_vectors(struct virtio_device *vdev) { @@ -505,11 +513,24 @@ static int virtio_pci_probe(struct pci_dev *pci_dev, if (rc) goto err_request_regions; - rc = virtio_pci_modern_probe(vp_dev); - if (rc == -ENODEV) + if (force_legacy) { rc = virtio_pci_legacy_probe(vp_dev); - if (rc) - goto err_probe; + /* Also try modern mode if we can't map BAR0 (no IO space). */ + if (rc != -ENODEV && rc != -ENOMEM) + return rc; + + rc = virtio_pci_modern_probe(vp_dev); + if (rc) + goto err_probe; + } else { + rc = virtio_pci_modern_probe(vp_dev); + if (rc != -ENODEV) + return rc; + + rc = virtio_pci_legacy_probe(vp_dev); + if (rc) + goto err_probe; + } pci_set_master(pci_dev); -- MST