From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 1DC3F2C7A for ; Mon, 9 Feb 2015 14:10:16 +0100 (CET) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP; 09 Feb 2015 05:10:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,543,1418112000"; d="scan'208";a="649469866" Received: from pgsmsx102.gar.corp.intel.com ([10.221.44.80]) by orsmga001.jf.intel.com with ESMTP; 09 Feb 2015 05:10:02 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by PGSMSX102.gar.corp.intel.com (10.221.44.80) with Microsoft SMTP Server (TLS) id 14.3.195.1; Mon, 9 Feb 2015 21:10:00 +0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.192]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.46]) with mapi id 14.03.0195.001; Mon, 9 Feb 2015 21:10:00 +0800 From: "Qiu, Michael" To: Tetsuya Mukawa , "dev@dpdk.org" Thread-Topic: [PATCH v7 04/14] eal/pci: Consolidate pci address comparison APIs Thread-Index: AQHQRELTSxWi0iDBGE+tIPrk61ioFA== Date: Mon, 9 Feb 2015 13:10:00 +0000 Message-ID: <533710CFB86FA344BFBF2D6802E60286CE71EA@SHSMSX101.ccr.corp.intel.com> References: <1422763322-13742-4-git-send-email-mukawa@igel.co.jp> <1423470639-15744-1-git-send-email-mukawa@igel.co.jp> <1423470639-15744-5-git-send-email-mukawa@igel.co.jp> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v7 04/14] eal/pci: Consolidate pci address comparison APIs 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: Mon, 09 Feb 2015 13:10:17 -0000 On 2/9/2015 4:31 PM, Tetsuya Mukawa wrote:=0A= > This patch replaces pci_addr_comparison() and memcmp() of pci addresses b= y=0A= > eal_compare_pci_addr().=0A= >=0A= > v5:=0A= > - Fix pci_scan_one to handle pt_driver correctly.=0A= > v4:=0A= > - Fix calculation method of eal_compare_pci_addr().=0A= > - Add parameter checking.=0A= >=0A= > Signed-off-by: Tetsuya Mukawa =0A= > ---=0A= > lib/librte_eal/bsdapp/eal/eal_pci.c | 25 ++++++++---------------= =0A= > lib/librte_eal/common/eal_common_pci.c | 2 +-=0A= > lib/librte_eal/common/include/rte_pci.h | 34 +++++++++++++++++++++++++= ++++++=0A= > lib/librte_eal/linuxapp/eal/eal_pci.c | 25 ++++++++---------------= =0A= > lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 2 +-=0A= > 5 files changed, 54 insertions(+), 34 deletions(-)=0A= >=0A= > diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/= eal/eal_pci.c=0A= > index 74ecce7..c844d58 100644=0A= > --- a/lib/librte_eal/bsdapp/eal/eal_pci.c=0A= > +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c=0A= > @@ -270,20 +270,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)=0A= > return (0);=0A= > }=0A= > =0A= > -/* Compare two PCI device addresses. */=0A= > -static int=0A= > -pci_addr_comparison(struct rte_pci_addr *addr, struct rte_pci_addr *addr= 2)=0A= > -{=0A= > - uint64_t dev_addr =3D (addr->domain << 24) + (addr->bus << 16) + (addr-= >devid << 8) + addr->function;=0A= > - uint64_t dev_addr2 =3D (addr2->domain << 24) + (addr2->bus << 16) + (ad= dr2->devid << 8) + addr2->function;=0A= > -=0A= > - if (dev_addr > dev_addr2)=0A= > - return 1;=0A= > - else=0A= > - return 0;=0A= > -}=0A= > -=0A= > -=0A= > /* Scan one pci sysfs entry, and fill the devices list from it. */=0A= > static int=0A= > pci_scan_one(int dev_pci_fd, struct pci_conf *conf)=0A= > @@ -356,13 +342,20 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)= =0A= > }=0A= > else {=0A= > struct rte_pci_device *dev2 =3D NULL;=0A= > + int ret;=0A= > =0A= > TAILQ_FOREACH(dev2, &pci_device_list, next) {=0A= > - if (pci_addr_comparison(&dev->addr, &dev2->addr))=0A= > + ret =3D eal_compare_pci_addr(&dev->addr, &dev2->addr);=0A= > + if (ret > 0)=0A= > continue;=0A= > - else {=0A= > + else if (ret < 0) {=0A= > TAILQ_INSERT_BEFORE(dev2, dev, next);=0A= > return 0;=0A= > + } else { /* already registered */=0A= > + /* update pt_driver */=0A= > + dev2->pt_driver =3D dev->pt_driver;=0A= > + free(dev);=0A= > + return 0;=0A= > }=0A= > }=0A= > TAILQ_INSERT_TAIL(&pci_device_list, dev, next);=0A= > diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/comm= on/eal_common_pci.c=0A= > index f3c7f71..a89f5c3 100644=0A= > --- a/lib/librte_eal/common/eal_common_pci.c=0A= > +++ b/lib/librte_eal/common/eal_common_pci.c=0A= > @@ -93,7 +93,7 @@ static struct rte_devargs *pci_devargs_lookup(struct rt= e_pci_device *dev)=0A= > if (devargs->type !=3D RTE_DEVTYPE_BLACKLISTED_PCI &&=0A= > devargs->type !=3D RTE_DEVTYPE_WHITELISTED_PCI)=0A= > continue;=0A= > - if (!memcmp(&dev->addr, &devargs->pci.addr, sizeof(dev->addr)))=0A= > + if (!eal_compare_pci_addr(&dev->addr, &devargs->pci.addr))=0A= > return devargs;=0A= > }=0A= > return NULL;=0A= > diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/com= mon/include/rte_pci.h=0A= > index 7f2d699..4814cd7 100644=0A= > --- a/lib/librte_eal/common/include/rte_pci.h=0A= > +++ b/lib/librte_eal/common/include/rte_pci.h=0A= > @@ -269,6 +269,40 @@ eal_parse_pci_DomBDF(const char *input, struct rte_p= ci_addr *dev_addr)=0A= > }=0A= > #undef GET_PCIADDR_FIELD=0A= > =0A= > +/* Compare two PCI device addresses. */=0A= > +/**=0A= > + * Utility function to compare two PCI device addresses.=0A= > + *=0A= > + * @param addr=0A= > + * The PCI Bus-Device-Function address to compare=0A= > + * @param addr2=0A= > + * The PCI Bus-Device-Function address to compare=0A= > + * @return=0A= > + * 0 on equal PCI address.=0A= > + * Positive on addr is greater than addr2.=0A= > + * Negative on addr is less than addr2, or error.=0A= > + */=0A= > +static inline int=0A= > +eal_compare_pci_addr(struct rte_pci_addr *addr, struct rte_pci_addr *add= r2)=0A= > +{=0A= > + uint64_t dev_addr, dev_addr2;=0A= > +=0A= > + if ((addr =3D=3D NULL) || (addr2 =3D=3D NULL))=0A= > + return -1;=0A= > +=0A= > + dev_addr =3D (addr->domain << 24) | (addr->bus << 16) |=0A= > + (addr->devid << 8) | addr->function;=0A= > + dev_addr2 =3D (addr2->domain << 24) | (addr2->bus << 16) |=0A= > + (addr2->devid << 8) | addr2->function;=0A= > +=0A= > + if (dev_addr > dev_addr2)=0A= > + return 1;=0A= > + else if (dev_addr < dev_addr2)=0A= > + return -1;=0A= > + else=0A= > + return 0;=0A= > +}=0A= > +=0A= > /**=0A= > * Probe the PCI bus for registered drivers.=0A= > *=0A= > diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linux= app/eal/eal_pci.c=0A= > index c0ca5a5..d847102 100644=0A= > --- a/lib/librte_eal/linuxapp/eal/eal_pci.c=0A= > +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c=0A= > @@ -229,20 +229,6 @@ error:=0A= > return -1;=0A= > }=0A= > =0A= > -/* Compare two PCI device addresses. */=0A= > -static int=0A= > -pci_addr_comparison(struct rte_pci_addr *addr, struct rte_pci_addr *addr= 2)=0A= > -{=0A= > - uint64_t dev_addr =3D (addr->domain << 24) + (addr->bus << 16) + (addr-= >devid << 8) + addr->function;=0A= > - uint64_t dev_addr2 =3D (addr2->domain << 24) + (addr2->bus << 16) + (ad= dr2->devid << 8) + addr2->function;=0A= > -=0A= > - if (dev_addr > dev_addr2)=0A= > - return 1;=0A= > - else=0A= > - return 0;=0A= > -}=0A= > -=0A= > -=0A= > /* Scan one pci sysfs entry, and fill the devices list from it. */=0A= > static int=0A= > pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,=0A= > @@ -353,13 +339,20 @@ pci_scan_one(const char *dirname, uint16_t domain, = uint8_t bus,=0A= > }=0A= > else {=0A= > struct rte_pci_device *dev2 =3D NULL;=0A= > + int ret;=0A= > =0A= > TAILQ_FOREACH(dev2, &pci_device_list, next) {=0A= > - if (pci_addr_comparison(&dev->addr, &dev2->addr))=0A= > + ret =3D eal_compare_pci_addr(&dev->addr, &dev2->addr);=0A= > + if (ret > 0)=0A= > continue;=0A= > - else {=0A= > + else if (ret < 0) {=0A= > TAILQ_INSERT_BEFORE(dev2, dev, next);=0A= > return 0;=0A= > + } else { /* already registered */=0A= > + /* update pt_driver */=0A= > + dev2->pt_driver =3D dev->pt_driver;=0A= > + free(dev);=0A= > + return 0;=0A= > }=0A= > }=0A= > TAILQ_INSERT_TAIL(&pci_device_list, dev, next);=0A= > diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/l= inuxapp/eal/eal_pci_uio.c=0A= > index e53f06b..1da3507 100644=0A= > --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c=0A= > +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c=0A= > @@ -123,7 +123,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev)=0A= > TAILQ_FOREACH(uio_res, pci_res_list, next) {=0A= > =0A= > /* skip this element if it doesn't match our PCI address */=0A= > - if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev->addr)))=0A= > + if (eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))=0A= > continue;=0A= > =0A= > for (i =3D 0; i !=3D uio_res->nb_maps; i++) {=0A= Acked-by: Michael Qiu =0A=