From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 6206CAFDA for ; Tue, 27 May 2014 05:23:12 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 26 May 2014 20:23:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.98,916,1392192000"; d="scan'208,217";a="545285248" Received: from fmsmsx105.amr.corp.intel.com ([10.19.9.36]) by fmsmga002.fm.intel.com with ESMTP; 26 May 2014 20:23:22 -0700 Received: from FMSMSX110.amr.corp.intel.com (10.18.116.10) by FMSMSX105.amr.corp.intel.com (10.19.9.36) with Microsoft SMTP Server (TLS) id 14.3.123.3; Mon, 26 May 2014 20:23:22 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by fmsmsx110.amr.corp.intel.com (10.18.116.10) with Microsoft SMTP Server (TLS) id 14.3.123.3; Mon, 26 May 2014 20:23:21 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.7]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.7]) with mapi id 14.03.0123.003; Tue, 27 May 2014 11:23:20 +0800 From: "Xu, HuilongX" To: "dev@dpdk.org" , "Burakov, Anatoly" Thread-Topic: RE: [dpdk-dev] [PATCH v2 09/16] Enable VFIO device binding Thread-Index: Ac95WwDE+gkgumCWQaiXNyoSN+/m5A== Date: Tue, 27 May 2014 03:23:19 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-cr-hashedpuzzle: s2Y= BPWQ C8WQ DOQT EOb/ ERaA FHKd Fd7F GRui GisQ GplI HEBh ITlY Iv3r JECc LeQ/; 1; ZABlAHYAQABkAHAAZABrAC4AbwByAGcA; Sosha1_v1; 7; {66EB6379-7E5D-4452-99B8-0F3EA8AF78A1}; aAB1AGkAbABvAG4AZwB4AC4AeAB1AEAAaQBuAHQAZQBsAC4AYwBvAG0A; Tue, 27 May 2014 03:23:17 GMT; UgBFADoAIABbAGQAcABkAGsALQBkAGUAdgBdACAAWwBQAEEAVABDAEgAIAB2ADIAIAAwADkALwAxADYAXQAgAEUAbgBhAGIAbABlACAAVgBGAEkATwAgAGQAZQB2AGkAYwBlACAAYgBpAG4AZABpAG4AZwA= x-cr-puzzleid: {66EB6379-7E5D-4452-99B8-0F3EA8AF78A1} x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: Re: [dpdk-dev] [PATCH v2 09/16] Enable VFIO device binding X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 May 2014 03:23:13 -0000 Add support for binding VFIO devices if RTE_PCI_DRV_NEED_IGB_UIO is set for this driver. Try VFIO first, if not mapped then try IGB_UIO too. Signed-off-by: Anatoly Burakov Test-by: HuilongX Xu huilongx.xu@intel.com Compile pass >>Compile OS: FC20 x86_64 >>Kernel version: 3.13.6-200 >>GCC version: 4.8.2 >>Server: Crownpass --- lib/librte_eal/linuxapp/eal/eal_pci.c | 55 ++++++++++++++++++++++++++++++= ++- 1 files changed, 54 insertions(+), 1 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxap= p/eal/eal_pci.c index 7256406..953abe6 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -401,6 +401,7 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,= struct rte_pci_device *d { struct rte_pci_id *id_table; int ret =3D 0; + int mapped =3D 0; for (id_table =3D dr->id_table ; id_table->vendor_id !=3D 0= ; id_table++) { @@ -435,8 +436,17 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr= , struct rte_pci_device *d } if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPIN= G) { + /* try mapping the NIC resour= ces using VFIO if it exists */ +#ifdef VFIO_PRESENT + if (vfio_cfg.vfio_enabled) { + if ((ret =3D = pci_vfio_map_resource(dev)) =3D=3D 0) + = mapped =3D 1; + else if (ret = < 0) + = return ret; + } +#endif /* map resources for devices= that use igb_uio */ - if ((ret =3D pci_uio_map_res= ource(dev)) !=3D 0) + if (!mapped && (ret =3D pci_u= io_map_resource(dev)) !=3D 0) return ret; } else if (dr->drv_flags & RTE_PCI_DRV_FORCE= _UNBIND && rte_eal_process_type() =3D=3D RTE= _PROC_PRIMARY) { @@ -471,5 +481,48 @@ rte_eal_pci_init(void) RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus= \n", __func__); return -1; } +#ifdef VFIO_PRESENT + memset(&vfio_cfg, 0, sizeof(vfio_cfg)); + + /* initialize group list */ + int i, ret; + + for (i =3D 0; i < VFIO_MAX_GROUPS; i++) { + vfio_cfg.vfio_groups[i].fd =3D -1; + vfio_cfg.vfio_groups[i].group_no =3D -1; + } + vfio_cfg.vfio_container_fd =3D -1; + + /* check if we have VFIO driver enabled */ + if (access(VFIO_DIR, F_OK) =3D=3D 0) { + static int socket_fd; + + vfio_cfg.vfio_enabled =3D 1; + + /* if we are primary process, create a thread= to communicate with + * secondary processes. the thread will use a = socket to wait for + * requests from secondary process to send ope= n file descriptors, + * because VFIO does not allow multiple open d= escriptors on a group or + * VFIO container. + */ + if (internal_config.process_type =3D=3D RTE_P= ROC_PRIMARY) { + /* set up local socket */ + if ((socket_fd =3D pci_vfio_s= ocket_setup()) < 0) { + RTE_LOG(ERR, = EAL, "Failed to set up local socket!\n"); + return -1; + } + ret =3D pthread_create(&socke= t_thread, NULL, + = pci_vfio_socket_thread, (void*) &socket_fd); + if (ret) { + RTE_LOG(ERR, = EAL, + = "Failed to create thread for communication with secondary " + = "processes!\n"); + return -1; + } + } + } + else + RTE_LOG(INFO, EAL, "VFIO driver not loaded or= wrong permissions\n"); +#endif return 0; } -- 1.7.0.7