From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [143.182.124.21]) by dpdk.org (Postfix) with ESMTP id 64ABC68CF for ; Fri, 11 Apr 2014 13:53:11 +0200 (CEST) Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga101.ch.intel.com with ESMTP; 11 Apr 2014 04:54:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,841,1389772800"; d="scan'208";a="417758667" Received: from irsmsx103.ger.corp.intel.com ([163.33.3.157]) by azsmga001.ch.intel.com with ESMTP; 11 Apr 2014 04:54:47 -0700 Received: from irsmsx104.ger.corp.intel.com ([169.254.5.2]) by IRSMSX103.ger.corp.intel.com ([163.33.3.157]) with mapi id 14.03.0123.003; Fri, 11 Apr 2014 12:53:05 +0100 From: "Burakov, Anatoly" To: "dev@dpdk.org" Thread-Topic: [PATCH] Remove RTE_EAL_UNBIND_PORTS-related code Thread-Index: Ac9Ve9Oz+Z/S1t16Qrm11IIpeQBwaw== Date: Fri, 11 Apr 2014 11:53:05 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.180] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH] Remove RTE_EAL_UNBIND_PORTS-related code 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: Fri, 11 Apr 2014 11:53:12 -0000 RTE_EAL_UNBIND_PORTS was deprecated in DPDK 1.4.0 and removed in 1.6.0, but= the code was not removed. Signed-off-by: Anatoly Burakov --- lib/librte_eal/linuxapp/eal/eal_pci.c | 221 ------------------------------= ---- 1 file changed, 221 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxap= p/eal/eal_pci.c index 5fa466e..9e5a139 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -109,199 +109,6 @@ static int pci_parse_sysfs_value(const char *filename= , uint64_t *val); /* forward prototype of function called in pci_switch_module below */ static int pci_uio_map_resource(struct rte_pci_device *dev); =20 -#ifdef RTE_EAL_UNBIND_PORTS -#define PROC_MODULES "/proc/modules" - -#define IGB_UIO_NAME "igb_uio" - -#define UIO_DRV_PATH "/sys/bus/pci/drivers/%s" - -/* maximum time to wait that /dev/uioX appears */ -#define UIO_DEV_WAIT_TIMEOUT 3 /* seconds */ - -/* - * Check that a kernel module is loaded. Returns 0 on success, or if the - * parameter is NULL, or -1 if the module is not loaded. - */ -static int -pci_uio_check_module(const char *module_name) -{ - FILE *f; - unsigned i; - char buf[BUFSIZ]; - - if (module_name =3D=3D NULL) - return 0; - - f =3D fopen(PROC_MODULES, "r"); - if (f =3D=3D NULL) { - RTE_LOG(ERR, EAL, "Cannot open "PROC_MODULES": %s\n",=20 - strerror(errno)); - return -1; - } - - while(fgets(buf, sizeof(buf), f) !=3D NULL) { - - for (i =3D 0; i < sizeof(buf) && buf[i] !=3D '\0'; i++) { - if (isspace(buf[i])) - buf[i] =3D '\0'; - } - - if (strncmp(buf, module_name, sizeof(buf)) =3D=3D 0) { - fclose(f); - return 0; - } - } - fclose(f); - return -1; -} - -/* bind a PCI to the kernel module driver */ -static int -pci_bind_device(struct rte_pci_device *dev, char dr_path[]) -{ - FILE *f; - int n; - char buf[BUFSIZ]; - char dev_bind[PATH_MAX]; - struct rte_pci_addr *loc =3D &dev->addr; - - n =3D rte_snprintf(dev_bind, sizeof(dev_bind), "%s/bind", dr_path); - if ((n < 0) || (n >=3D (int)sizeof(buf))) { - RTE_LOG(ERR, EAL, "Cannot rte_snprintf device bind path\n"); - return -1; - } - - f =3D fopen(dev_bind, "w"); - if (f =3D=3D NULL) { - RTE_LOG(ERR, EAL, "Cannot open %s\n", dev_bind); - return -1; - } - n =3D rte_snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n", - loc->domain, loc->bus, loc->devid, loc->function); - if ((n < 0) || (n >=3D (int)sizeof(buf))) { - RTE_LOG(ERR, EAL, "Cannot rte_snprintf PCI infos\n"); - fclose(f); - return -1; - } - if (fwrite(buf, n, 1, f) =3D=3D 0) { - fclose(f); - return -1; - } - - fclose(f); - return 0; -} - -static int -pci_uio_bind_device(struct rte_pci_device *dev, const char *module_name) -{ - FILE *f; - int n; - char buf[BUFSIZ]; - char uio_newid[PATH_MAX]; - char uio_bind[PATH_MAX]; - - n =3D rte_snprintf(uio_newid, sizeof(uio_newid), UIO_DRV_PATH "/new_id", = module_name); - if ((n < 0) || (n >=3D (int)sizeof(uio_newid))) { - RTE_LOG(ERR, EAL, "Cannot rte_snprintf uio_newid name\n"); - return -1; - } - - n =3D rte_snprintf(uio_bind, sizeof(uio_bind), UIO_DRV_PATH, module_name)= ; - if ((n < 0) || (n >=3D (int)sizeof(uio_bind))) { - RTE_LOG(ERR, EAL, "Cannot rte_snprintf uio_bind name\n"); - return -1; - } - - n =3D rte_snprintf(buf, sizeof(buf), "%x %x\n", - dev->id.vendor_id, dev->id.device_id); - if ((n < 0) || (n >=3D (int)sizeof(buf))) { - RTE_LOG(ERR, EAL, "Cannot rte_snprintf vendor_id/device_id\n"); - return -1; - } - - f =3D fopen(uio_newid, "w"); - if (f =3D=3D NULL) { - RTE_LOG(ERR, EAL, "Cannot open %s\n", uio_newid); - return -1; - } - if (fwrite(buf, n, 1, f) =3D=3D 0) { - fclose(f); - return -1; - } - fclose(f); - - pci_bind_device(dev, uio_bind); - return 0; -} - -/* unbind kernel driver for this device */ -static int -pci_unbind_kernel_driver(struct rte_pci_device *dev) -{ - int n; - FILE *f; - char filename[PATH_MAX]; - char buf[BUFSIZ]; - struct rte_pci_addr *loc =3D &dev->addr; - - /* open /sys/bus/pci/devices/AAAA:BB:CC.D/driver */ - rte_snprintf(filename, sizeof(filename), - SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/driver/unbind", - loc->domain, loc->bus, loc->devid, loc->function); - - f =3D fopen(filename, "w"); - if (f =3D=3D NULL) /* device was not bound */ - return 0; - - n =3D rte_snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n", - loc->domain, loc->bus, loc->devid, loc->function); - if ((n < 0) || (n >=3D (int)sizeof(buf))) { - RTE_LOG(ERR, EAL, "%s(): rte_snprintf failed\n", __func__); - goto error; - } - if (fwrite(buf, n, 1, f) =3D=3D 0) { - RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__, - filename); - goto error; - } - - fclose(f); - return 0; - -error: - fclose(f); - return -1; -} - - -static int -pci_switch_module(struct rte_pci_driver *dr, struct rte_pci_device *dev, - int uio_status, const char *module_name) -{ - if (rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY) { - /* check that our driver is loaded */ - if (uio_status !=3D 0 && - (uio_status =3D pci_uio_check_module(module_name)) !=3D 0) - rte_exit(EXIT_FAILURE, "The %s module is required by the " - "%s driver\n", module_name, dr->name); - - /* unbind current driver, bind ours */ - if (pci_unbind_kernel_driver(dev) < 0) - return -1; - if (pci_uio_bind_device(dev, module_name) < 0) - return -1; - } - /* map the NIC resources */ - if (pci_uio_map_resource(dev) < 0) - return -1; - - return 0; -} - -#endif /* ifdef EAL_UNBIND_PORTS */ - /* map a particular resource from a file */ static void * pci_map_resource(struct rte_pci_device *dev, void *requested_addr,=20 @@ -310,25 +117,10 @@ pci_map_resource(struct rte_pci_device *dev, void *re= quested_addr, int fd; void *mapaddr; =20 -#ifdef RTE_EAL_UNBIND_PORTS - /* - * open devname, and mmap it: it can take some time to - * appear, so we wait some time before returning an error - */ - unsigned n; - fd =3D dev->intr_handle.fd; - for (n =3D 0; n < UIO_DEV_WAIT_TIMEOUT*10 && fd < 0; n++) { - errno =3D 0; - if ((fd =3D open(devname, O_RDWR)) < 0 && errno !=3D ENOENT) - break; - usleep(100000); - } -#else /* * open devname, to mmap it */ fd =3D open(devname, O_RDWR); -#endif if (fd < 0) { RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",=20 devname, strerror(errno)); @@ -1036,23 +828,10 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *= dr, struct rte_pci_device *d return 0; } =20 -#ifdef RTE_EAL_UNBIND_PORTS - if (dr->drv_flags & RTE_PCI_DRV_NEED_IGB_UIO) { - /* unbind driver and load uio resources for Intel NICs */ - if (pci_switch_module(dr, dev, 1, IGB_UIO_NAME) < 0) - return -1; - } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND && - rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY) { - /* unbind current driver */ - if (pci_unbind_kernel_driver(dev) < 0) - return -1; - } -#else if (dr->drv_flags & RTE_PCI_DRV_NEED_IGB_UIO) /* just map resources for Intel NICs */ if (pci_uio_map_resource(dev) < 0) return -1; -#endif =20 /* reference driver structure */ dev->driver =3D dr; --=20 1.8.1.4