From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw0-f172.google.com (mail-yw0-f172.google.com [209.85.161.172]) by dpdk.org (Postfix) with ESMTP id BE6F99E3 for ; Thu, 10 Nov 2016 03:24:30 +0100 (CET) Received: by mail-yw0-f172.google.com with SMTP id r204so228098812ywb.0 for ; Wed, 09 Nov 2016 18:24:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=KZEbuSgDFT2W4ec2J6WG5f0XJu6sj+CRj8RSUl4U+Mc=; b=gLi72KTvv92YIzkYXxfO1abrEPkruzcYVQswMAeFR1PcoxfQXfBTGeKSBvVAqC+76o +cNMmQRLtcYlalBO28O8VneLaHCQuZTsclQfZ2DN9ZGoe8vR26+GvIZ+7qQXxJjQDU5L VxrJGTg0OlYwFfVkS53cde1qJRSOge/olafSs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=KZEbuSgDFT2W4ec2J6WG5f0XJu6sj+CRj8RSUl4U+Mc=; b=YZ67ZxyNJLBBKze8KwOKrxmY4jXjpMbIErOD7kCLP97fbsf0TU5HiXoHkJtdBVCRf4 8yHwqdObetwc4/AG7Q2QxUiqW6T0HYZBeFW66lQc7qqOlq2S12ysCBpkA15SxIxyyKAA gENMxovIb13cF8uDWoz9kuR7OTkLJUU6nrbqTctw0BQc9N1ZXaE8aMWG931PedJWCEqm nqjMeBTP4IIxkIxTx10f1M8e/Zfn+ADDMDCuhELAbTUE8hBZbajHIqfb2EIdR1GU2cbX BYe2yDr+jdVdrNKP7uCYzXXedAItZiiA8NR2GGuZFL7dGyTRtFt6ngQyZdi9I4CY4++k v/Vg== X-Gm-Message-State: ABUngve706f+2fKbFU4eTtn7omQBkeDEJ6xcNY/x/HjWOZgC9zeSW47C1eBdze6mfllLsvp2IblhEu+7OkSIOwXt X-Received: by 10.129.138.133 with SMTP id a127mr2801606ywg.290.1478744670038; Wed, 09 Nov 2016 18:24:30 -0800 (PST) MIME-Version: 1.0 Received: by 10.37.171.48 with HTTP; Wed, 9 Nov 2016 18:24:29 -0800 (PST) In-Reply-To: <1477657598-826-4-git-send-email-shreyansh.jain@nxp.com> References: <1477581467-12588-1-git-send-email-shreyansh.jain@nxp.com> <1477657598-826-1-git-send-email-shreyansh.jain@nxp.com> <1477657598-826-4-git-send-email-shreyansh.jain@nxp.com> From: Jianbo Liu Date: Thu, 10 Nov 2016 10:24:29 +0800 Message-ID: To: Shreyansh Jain Cc: dev@dpdk.org, Thomas Monjalon , Jan Viktorin Content-Type: text/plain; charset=UTF-8 Subject: Re: [dpdk-dev] [PATCH v7 03/21] eal/linux: generalize PCI kernel unbinding driver to EAL 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: Thu, 10 Nov 2016 02:24:31 -0000 On 28 October 2016 at 20:26, Shreyansh Jain wrote: > From: Jan Viktorin > > Generalize the PCI-specific pci_unbind_kernel_driver. It is now divided > into two parts. First, determination of the path and string identification > of the device to be unbound. Second, the actual unbind operation which is > generic. > > BSD implementation updated as ENOTSUP > > Signed-off-by: Jan Viktorin > Signed-off-by: Shreyansh Jain > -- > Changes since v2: > - update BSD support for unbind kernel driver > --- > lib/librte_eal/bsdapp/eal/eal.c | 7 +++++++ > lib/librte_eal/bsdapp/eal/eal_pci.c | 4 ++-- > lib/librte_eal/common/eal_private.h | 13 +++++++++++++ > lib/librte_eal/linuxapp/eal/eal.c | 26 ++++++++++++++++++++++++++ > lib/librte_eal/linuxapp/eal/eal_pci.c | 33 +++++++++------------------------ > 5 files changed, 57 insertions(+), 26 deletions(-) > > diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c > index 35e3117..5271fc2 100644 > --- a/lib/librte_eal/bsdapp/eal/eal.c > +++ b/lib/librte_eal/bsdapp/eal/eal.c > @@ -633,3 +633,10 @@ rte_eal_process_type(void) > { > return rte_config.process_type; > } > + > +int > +rte_eal_unbind_kernel_driver(const char *devpath __rte_unused, > + const char *devid __rte_unused) > +{ > + return -ENOTSUP; > +} > diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c > index 7ed0115..703f034 100644 > --- a/lib/librte_eal/bsdapp/eal/eal_pci.c > +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c > @@ -89,11 +89,11 @@ > > /* unbind kernel driver for this device */ > int > -pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused) > +pci_unbind_kernel_driver(struct rte_pci_device *dev) > { > RTE_LOG(ERR, EAL, "RTE_PCI_DRV_FORCE_UNBIND flag is not implemented " > "for BSD\n"); > - return -ENOTSUP; > + return rte_eal_unbind_kernel_driver(dev); Missing the second parameter for devid. > } > > /* Map pci device */ > diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h > index 9e7d8f6..b0c208a 100644 > --- a/lib/librte_eal/common/eal_private.h > +++ b/lib/librte_eal/common/eal_private.h > @@ -256,6 +256,19 @@ int rte_eal_alarm_init(void); > int rte_eal_check_module(const char *module_name); > > /** > + * Unbind kernel driver bound to the device specified by the given devpath, > + * and its string identification. > + * > + * @param devpath path to the device directory ("/sys/.../devices/") > + * @param devid identification of the device () > + * > + * @return > + * -1 unbind has failed > + * 0 module has been unbound > + */ > +int rte_eal_unbind_kernel_driver(const char *devpath, const char *devid); > + > +/** > * Get cpu core_id. > * > * This function is private to the EAL. > diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c > index 2075282..5f6676d 100644 > --- a/lib/librte_eal/linuxapp/eal/eal.c > +++ b/lib/librte_eal/linuxapp/eal/eal.c > @@ -943,3 +943,29 @@ rte_eal_check_module(const char *module_name) > /* Module has been found */ > return 1; > } > + > +int > +rte_eal_unbind_kernel_driver(const char *devpath, const char *devid) > +{ > + char filename[PATH_MAX]; > + FILE *f; > + > + snprintf(filename, sizeof(filename), > + "%s/driver/unbind", devpath); > + > + f = fopen(filename, "w"); > + if (f == NULL) /* device was not bound */ > + return 0; > + > + if (fwrite(devid, strlen(devid), 1, f) == 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; > +} > diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c > index 876ba38..a03553f 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_pci.c > +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c > @@ -59,38 +59,23 @@ int > pci_unbind_kernel_driver(struct rte_pci_device *dev) > { > int n; > - FILE *f; > - char filename[PATH_MAX]; > - char buf[BUFSIZ]; > + char devpath[PATH_MAX]; > + char devid[BUFSIZ]; > struct rte_pci_addr *loc = &dev->addr; > > - /* open /sys/bus/pci/devices/AAAA:BB:CC.D/driver */ > - snprintf(filename, sizeof(filename), > - "%s/" PCI_PRI_FMT "/driver/unbind", pci_get_sysfs_path(), > + /* devpath /sys/bus/pci/devices/AAAA:BB:CC.D */ > + snprintf(devpath, sizeof(devpath), > + "%s/" PCI_PRI_FMT, pci_get_sysfs_path(), > loc->domain, loc->bus, loc->devid, loc->function); > > - f = fopen(filename, "w"); > - if (f == NULL) /* device was not bound */ > - return 0; > - > - n = snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n", > + n = snprintf(devid, sizeof(devid), PCI_PRI_FMT "\n", > loc->domain, loc->bus, loc->devid, loc->function); > - if ((n < 0) || (n >= (int)sizeof(buf))) { > + if ((n < 0) || (n >= (int)sizeof(devid))) { > RTE_LOG(ERR, EAL, "%s(): snprintf failed\n", __func__); > - goto error; > - } > - if (fwrite(buf, n, 1, f) == 0) { > - RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__, > - filename); > - goto error; > + return -1; > } > > - fclose(f); > - return 0; > - > -error: > - fclose(f); > - return -1; > + return rte_eal_unbind_kernel_driver(devpath, devid); > } > > static int > -- > 2.7.4 >