From patchwork Tue May 9 14:57:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Radu Nicolau X-Patchwork-Id: 24169 X-Patchwork-Delegate: pablo.de.lara.guarch@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 388356DB2; Tue, 9 May 2017 17:01:09 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 1863F68A9 for ; Tue, 9 May 2017 17:01:02 +0200 (CEST) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 May 2017 08:00:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,315,1491289200"; d="scan'208";a="97610261" Received: from silpixa00383879.ir.intel.com (HELO silpixa00383879.ger.corp.intel.com) ([10.237.223.127]) by orsmga005.jf.intel.com with ESMTP; 09 May 2017 08:00:58 -0700 From: Radu Nicolau To: dev@dpdk.org Cc: Radu Nicolau Date: Tue, 9 May 2017 15:57:56 +0100 Message-Id: <1494341879-18718-3-git-send-email-radu.nicolau@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1494341879-18718-1-git-send-email-radu.nicolau@intel.com> References: <1494341879-18718-1-git-send-email-radu.nicolau@intel.com> Subject: [dpdk-dev] [RFC][PATCH 2/5] pci: allow shared device instances. X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Updated PCI initialization code to allow devices to be shared across multiple PMDs. Signed-off-by: Radu Nicolau --- lib/librte_eal/common/eal_common_pci.c | 15 ++++++++++++--- lib/librte_eal/common/include/rte_pci.h | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index b749991..8fdc38f 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -203,7 +203,7 @@ static int rte_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev) { - int ret; + int ret = 1; struct rte_pci_addr *loc; if ((dr == NULL) || (dev == NULL)) @@ -254,6 +254,11 @@ rte_pci_probe_one_driver(struct rte_pci_driver *dr, rte_pci_unmap_device(dev); } + if (!dr->id_table->shared || ret) { + return ret; + } + /* else continue to parse the table for another match */ + return ret; } @@ -303,6 +308,7 @@ pci_probe_all_drivers(struct rte_pci_device *dev) { struct rte_pci_driver *dr = NULL; int rc = 0; + int res = 1; if (dev == NULL) return -1; @@ -319,9 +325,12 @@ pci_probe_all_drivers(struct rte_pci_device *dev) if (rc > 0) /* positive value means driver doesn't support it */ continue; - return 0; + if (dr->id_table->shared) + res = 0; + else + return 0; } - return 1; + return res; } /* diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index ab64c63..3a66ef4 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -135,6 +135,7 @@ struct rte_pci_id { uint16_t device_id; /**< Device ID or PCI_ANY_ID. */ uint16_t subsystem_vendor_id; /**< Subsystem vendor ID or PCI_ANY_ID. */ uint16_t subsystem_device_id; /**< Subsystem device ID or PCI_ANY_ID. */ + uint8_t shared; /**< Device can be shared by multiple drivers. */ }; /** @@ -187,22 +188,31 @@ struct rte_pci_device { #ifdef __cplusplus /** C++ macro used to help building up tables of device IDs */ -#define RTE_PCI_DEVICE(vend, dev) \ +#define _RTE_PCI_DEVICE_SH(vend, dev, sh) \ RTE_CLASS_ANY_ID, \ (vend), \ (dev), \ PCI_ANY_ID, \ - PCI_ANY_ID + PCI_ANY_ID, \ + (sh) #else /** Macro used to help building up tables of device IDs */ -#define RTE_PCI_DEVICE(vend, dev) \ +#define _RTE_PCI_DEVICE_SH(vend, dev, sh) \ .class_id = RTE_CLASS_ANY_ID, \ .vendor_id = (vend), \ .device_id = (dev), \ .subsystem_vendor_id = PCI_ANY_ID, \ - .subsystem_device_id = PCI_ANY_ID + .subsystem_device_id = PCI_ANY_ID, \ + .shared = (sh) #endif +#define RTE_PCI_DEVICE(vend, dev) \ + _RTE_PCI_DEVICE_SH((vend), (dev), 0) +#define RTE_PCI_DEVICE_SH(vend, dev) \ + _RTE_PCI_DEVICE_SH((vend), (dev), 1) + +struct rte_pci_driver; + /** * Initialisation function for the driver called during PCI probing. */