From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 7A17BC454 for ; Mon, 29 Jun 2015 15:36:18 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP; 29 Jun 2015 06:36:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,698,1427785200"; d="scan'208";a="719606174" Received: from irsmsx153.ger.corp.intel.com ([163.33.192.75]) by orsmga001.jf.intel.com with ESMTP; 29 Jun 2015 06:36:16 -0700 Received: from irsmsx108.ger.corp.intel.com ([169.254.11.201]) by IRSMSX153.ger.corp.intel.com ([169.254.9.140]) with mapi id 14.03.0224.002; Mon, 29 Jun 2015 14:36:06 +0100 From: "Iremonger, Bernard" To: Tetsuya Mukawa , "dev@dpdk.org" Thread-Topic: [PATCH v3 2/8] eal: Add pci_uio_map_uio_resource_by_index() Thread-Index: AQHQshdn1w40NEf+KU6AODNNsxdG753DfGoA Date: Mon, 29 Jun 2015 13:36:06 +0000 Message-ID: <8CEF83825BEC744B83065625E567D7C204A42D6C@IRSMSX108.ger.corp.intel.com> References: <1432016513-8456-5-git-send-email-mukawa@igel.co.jp> <1435546610-4533-1-git-send-email-mukawa@igel.co.jp> <1435546610-4533-3-git-send-email-mukawa@igel.co.jp> In-Reply-To: <1435546610-4533-3-git-send-email-mukawa@igel.co.jp> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v3 2/8] eal: Add pci_uio_map_uio_resource_by_index() 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, 29 Jun 2015 13:36:19 -0000 > -----Original Message----- > From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp] > Sent: Monday, June 29, 2015 3:57 AM > To: dev@dpdk.org > Cc: Iremonger, Bernard; david.marchand@6wind.com; Tetsuya.Mukawa > Subject: [PATCH v3 2/8] eal: Add pci_uio_map_uio_resource_by_index() >=20 > From: "Tetsuya.Mukawa" >=20 > This patch adds a new function called pci_uio_map_resource_by_index(). > The function hides how to map uio resource in linuxapp and bsdapp. > With the function, pci_uio_map_resource() will be more abstracted. >=20 > Signed-off-by: Tetsuya Mukawa Hi Tetsuya, There are two comments inline below. > --- > lib/librte_eal/bsdapp/eal/eal_pci.c | 107 +++++++++++++++---------= -- > lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 124 +++++++++++++++++-------= -- > ---- > 2 files changed, 133 insertions(+), 98 deletions(-) >=20 > diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c > b/lib/librte_eal/bsdapp/eal/eal_pci.c > index 2d9f3a5..61d1fe5 100644 > --- a/lib/librte_eal/bsdapp/eal/eal_pci.c > +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c > @@ -240,20 +240,73 @@ close_fd: > return -1; > } >=20 > +static int > +pci_uio_map_uio_resource_by_index(struct rte_pci_device *dev, int > res_idx, > + struct mapped_pci_resource *uio_res, int map_idx) { The name of this function is a bit long winded, pci_uio_map_resource_by_ind= ex() might be better. > + int fd; > + char *devname; > + void *mapaddr; > + uint64_t offset; > + uint64_t pagesz; > + struct pci_map *maps; > + > + if ((dev =3D=3D NULL) || (uio_res =3D=3D NULL) || (uio_res->path =3D=3D= NULL)) > + return -1; > + > + maps =3D uio_res->maps; > + devname =3D uio_res->path; > + pagesz =3D sysconf(_SC_PAGESIZE); > + > + /* allocate memory to keep path */ > + maps[map_idx].path =3D rte_malloc(NULL, strlen(devname) + 1, 0); > + if (maps[map_idx].path =3D=3D NULL) { > + RTE_LOG(ERR, EAL, "Cannot allocate memory for " > + "path: %s\n", strerror(errno)); > + return -1; > + } > + > + /* > + * open resource file, to mmap it > + */ > + fd =3D open(devname, O_RDWR); > + if (fd < 0) { > + RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", > + devname, strerror(errno)); > + goto fail; > + } > + > + /* if matching map is found, then use it */ > + offset =3D res_idx * pagesz; > + mapaddr =3D pci_map_resource(NULL, fd, (off_t)offset, > + (size_t)dev->mem_resource[res_idx].len, 0); > + close(fd); > + if (mapaddr =3D=3D MAP_FAILED) > + goto fail; > + > + maps[map_idx].phaddr =3D dev->mem_resource[res_idx].phys_addr; > + maps[map_idx].size =3D dev->mem_resource[res_idx].len; > + maps[map_idx].addr =3D mapaddr; > + maps[map_idx].offset =3D offset; > + strcpy(maps[map_idx].path, devname); > + dev->mem_resource[res_idx].addr =3D mapaddr; > + > + return 0; > + > +fail: > + rte_free(maps[map_idx].path); > + return -1; > +} > + > /* map the PCI resource of a PCI device in virtual memory */ static int > pci_uio_map_resource(struct rte_pci_device *dev) { > int i, map_idx, ret; > - char *devname; > - void *mapaddr; > uint64_t phaddr; > - uint64_t offset; > - uint64_t pagesz; > struct mapped_pci_resource *uio_res =3D NULL; > struct mapped_pci_res_list *uio_res_list =3D > RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list); > - struct pci_map *maps; >=20 > dev->intr_handle.fd =3D -1; > dev->intr_handle.type =3D RTE_INTR_HANDLE_UNKNOWN; @@ - > 268,53 +321,17 @@ pci_uio_map_resource(struct rte_pci_device *dev) > return ret; >=20 > /* Map all BARs */ > - pagesz =3D sysconf(_SC_PAGESIZE); > - devname =3D uio_res->path; > - > - maps =3D uio_res->maps; > for (i =3D 0, map_idx =3D 0; i !=3D PCI_MAX_RESOURCE; i++) { > - int fd; > - > /* skip empty BAR */ > if ((phaddr =3D dev->mem_resource[i].phys_addr) =3D=3D 0) > continue; >=20 > - /* allocate memory to keep path */ > - maps[map_idx].path =3D rte_malloc(NULL, strlen(devname) + > 1, 0); > - if (maps[map_idx].path =3D=3D NULL) { > - RTE_LOG(ERR, EAL, "Cannot allocate memory for " > - "path: %s\n", strerror(errno)); > + ret =3D pci_uio_map_uio_resource_by_index(dev, i, > + uio_res, map_idx); > + if (ret !=3D 0) > goto free_uio_res; > - } >=20 > - /* > - * open resource file, to mmap it > - */ > - fd =3D open(devname, O_RDWR); > - if (fd < 0) { > - RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", > - devname, strerror(errno)); > - rte_free(maps[map_idx].path); > - goto free_uio_res; > - } > - > - /* if matching map is found, then use it */ > - offset =3D i * pagesz; > - mapaddr =3D pci_map_resource(NULL, fd, (off_t)offset, > - (size_t)dev->mem_resource[i].len, > 0); > - close(fd); > - if (mapaddr =3D=3D MAP_FAILED) { > - rte_free(maps[map_idx].path); > - goto free_uio_res; > - } > - > - maps[map_idx].phaddr =3D dev->mem_resource[i].phys_addr; > - maps[map_idx].size =3D dev->mem_resource[i].len; > - maps[map_idx].addr =3D mapaddr; > - maps[map_idx].offset =3D offset; > - strcpy(maps[map_idx].path, devname); > map_idx++; > - dev->mem_resource[i].addr =3D mapaddr; > } >=20 > uio_res->nb_maps =3D map_idx; > @@ -325,7 +342,7 @@ pci_uio_map_resource(struct rte_pci_device *dev) >=20 > free_uio_res: > for (i =3D 0; i < map_idx; i++) > - rte_free(maps[i].path); > + rte_free(uio_res->maps[i].path); > rte_free(uio_res); >=20 > /* close fd opened by pci_uio_alloc_uio_resource() */ diff --git > a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > index 9e0b617..7da4543 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > @@ -333,19 +333,82 @@ close_fd: > return -1; > } >=20 > +static int > +pci_uio_map_uio_resource_by_index(struct rte_pci_device *dev, int > res_idx, > + struct mapped_pci_resource *uio_res, int map_idx) { The name of this function is a bit long winded, pci_uio_map_resource_by_ind= ex() might be better. Regards, Bernard. > + int fd; > + char devname[PATH_MAX]; /* contains the /dev/uioX */ > + void *mapaddr; > + struct rte_pci_addr *loc; > + struct pci_map *maps; > + > + if ((dev =3D=3D NULL) || (uio_res =3D=3D NULL)) > + return -1; > + > + loc =3D &dev->addr; > + maps =3D uio_res->maps; > + > + /* update devname for mmap */ > + snprintf(devname, sizeof(devname), > + SYSFS_PCI_DEVICES "/" PCI_PRI_FMT > "/resource%d", > + loc->domain, loc->bus, loc->devid, > + loc->function, res_idx); > + > + /* allocate memory to keep path */ > + maps[map_idx].path =3D rte_malloc(NULL, strlen(devname) + 1, 0); > + if (maps[map_idx].path =3D=3D NULL) { > + RTE_LOG(ERR, EAL, "Cannot allocate memory for " > + "path: %s\n", strerror(errno)); > + return -1; > + } > + > + /* > + * open resource file, to mmap it > + */ > + fd =3D open(devname, O_RDWR); > + if (fd < 0) { > + RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", > + devname, strerror(errno)); > + goto fail; > + } > + > + /* try mapping somewhere close to the end of hugepages */ > + if (pci_map_addr =3D=3D NULL) > + pci_map_addr =3D pci_find_max_end_va(); > + > + mapaddr =3D pci_map_resource(pci_map_addr, fd, 0, > + (size_t)dev->mem_resource[res_idx].len, 0); > + close(fd); > + if (mapaddr =3D=3D MAP_FAILED) > + goto fail; > + > + pci_map_addr =3D RTE_PTR_ADD(mapaddr, > + (size_t)dev->mem_resource[res_idx].len); > + > + maps[map_idx].phaddr =3D dev->mem_resource[res_idx].phys_addr; > + maps[map_idx].size =3D dev->mem_resource[res_idx].len; > + maps[map_idx].addr =3D mapaddr; > + maps[map_idx].offset =3D 0; > + strcpy(maps[map_idx].path, devname); > + dev->mem_resource[res_idx].addr =3D mapaddr; > + > + return 0; > + > +fail: > + rte_free(maps[map_idx].path); > + return -1; > +} > + > /* map the PCI resource of a PCI device in virtual memory */ int > pci_uio_map_resource(struct rte_pci_device *dev) { > int i, map_idx, ret; > - char devname[PATH_MAX]; /* contains the /dev/uioX */ > - void *mapaddr; > uint64_t phaddr; > - struct rte_pci_addr *loc =3D &dev->addr; > struct mapped_pci_resource *uio_res =3D NULL; > struct mapped_pci_res_list *uio_res_list =3D > RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list); > - struct pci_map *maps; >=20 > dev->intr_handle.fd =3D -1; > dev->intr_handle.uio_cfg_fd =3D -1; > @@ -361,63 +424,18 @@ pci_uio_map_resource(struct rte_pci_device *dev) > return ret; >=20 > /* Map all BARs */ > - maps =3D uio_res->maps; > for (i =3D 0, map_idx =3D 0; i !=3D PCI_MAX_RESOURCE; i++) { > - int fd; > - > /* skip empty BAR */ > phaddr =3D dev->mem_resource[i].phys_addr; > if (phaddr =3D=3D 0) > continue; >=20 > - > - /* update devname for mmap */ > - snprintf(devname, sizeof(devname), > - SYSFS_PCI_DEVICES "/" PCI_PRI_FMT > "/resource%d", > - loc->domain, loc->bus, loc->devid, loc- > >function, > - i); > - > - /* allocate memory to keep path */ > - maps[map_idx].path =3D rte_malloc(NULL, strlen(devname) + > 1, 0); > - if (maps[map_idx].path =3D=3D NULL) { > - RTE_LOG(ERR, EAL, "Cannot allocate memory for " > - "path: %s\n", strerror(errno)); > - goto free_uio_res; > - } > - > - /* > - * open resource file, to mmap it > - */ > - fd =3D open(devname, O_RDWR); > - if (fd < 0) { > - RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", > - devname, strerror(errno)); > - rte_free(maps[map_idx].path); > + ret =3D pci_uio_map_uio_resource_by_index(dev, i, > + uio_res, map_idx); > + if (ret !=3D 0) > goto free_uio_res; > - } > - > - /* try mapping somewhere close to the end of hugepages */ > - if (pci_map_addr =3D=3D NULL) > - pci_map_addr =3D pci_find_max_end_va(); > - > - mapaddr =3D pci_map_resource(pci_map_addr, fd, 0, > - (size_t)dev->mem_resource[i].len, 0); > - close(fd); > - if (mapaddr =3D=3D MAP_FAILED) { > - rte_free(maps[map_idx].path); > - goto free_uio_res; > - } > - > - pci_map_addr =3D RTE_PTR_ADD(mapaddr, > - (size_t)dev->mem_resource[i].len); >=20 > - maps[map_idx].phaddr =3D dev->mem_resource[i].phys_addr; > - maps[map_idx].size =3D dev->mem_resource[i].len; > - maps[map_idx].addr =3D mapaddr; > - maps[map_idx].offset =3D 0; > - strcpy(maps[map_idx].path, devname); > map_idx++; > - dev->mem_resource[i].addr =3D mapaddr; > } >=20 > uio_res->nb_maps =3D map_idx; > @@ -430,7 +448,7 @@ free_uio_res: > for (i =3D 0; i < map_idx; i++) { > pci_unmap_resource(uio_res->maps[i].addr, > (size_t)uio_res->maps[i].size); > - rte_free(maps[i].path); > + rte_free(uio_res->maps[i].path); > } > rte_free(uio_res); >=20 > -- > 2.1.4