From: "Iremonger, Bernard" <bernard.iremonger@intel.com>
To: Tetsuya Mukawa <mukawa@igel.co.jp>, "dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH v3 2/8] eal: Add pci_uio_map_uio_resource_by_index()
Date: Mon, 29 Jun 2015 13:36:06 +0000 [thread overview]
Message-ID: <8CEF83825BEC744B83065625E567D7C204A42D6C@IRSMSX108.ger.corp.intel.com> (raw)
In-Reply-To: <1435546610-4533-3-git-send-email-mukawa@igel.co.jp>
> -----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()
>
> From: "Tetsuya.Mukawa" <mukawa@igel.co.jp>
>
> 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.
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
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(-)
>
> 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;
> }
>
> +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_index() might be better.
> + int fd;
> + char *devname;
> + void *mapaddr;
> + uint64_t offset;
> + uint64_t pagesz;
> + struct pci_map *maps;
> +
> + if ((dev == NULL) || (uio_res == NULL) || (uio_res->path == NULL))
> + return -1;
> +
> + maps = uio_res->maps;
> + devname = uio_res->path;
> + pagesz = sysconf(_SC_PAGESIZE);
> +
> + /* allocate memory to keep path */
> + maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
> + if (maps[map_idx].path == NULL) {
> + RTE_LOG(ERR, EAL, "Cannot allocate memory for "
> + "path: %s\n", strerror(errno));
> + return -1;
> + }
> +
> + /*
> + * open resource file, to mmap it
> + */
> + fd = 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 = res_idx * pagesz;
> + mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
> + (size_t)dev->mem_resource[res_idx].len, 0);
> + close(fd);
> + if (mapaddr == MAP_FAILED)
> + goto fail;
> +
> + maps[map_idx].phaddr = dev->mem_resource[res_idx].phys_addr;
> + maps[map_idx].size = dev->mem_resource[res_idx].len;
> + maps[map_idx].addr = mapaddr;
> + maps[map_idx].offset = offset;
> + strcpy(maps[map_idx].path, devname);
> + dev->mem_resource[res_idx].addr = 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 = NULL;
> struct mapped_pci_res_list *uio_res_list =
> RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> - struct pci_map *maps;
>
> dev->intr_handle.fd = -1;
> dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN; @@ -
> 268,53 +321,17 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> return ret;
>
> /* Map all BARs */
> - pagesz = sysconf(_SC_PAGESIZE);
> - devname = uio_res->path;
> -
> - maps = uio_res->maps;
> for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
> - int fd;
> -
> /* skip empty BAR */
> if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
> continue;
>
> - /* allocate memory to keep path */
> - maps[map_idx].path = rte_malloc(NULL, strlen(devname) +
> 1, 0);
> - if (maps[map_idx].path == NULL) {
> - RTE_LOG(ERR, EAL, "Cannot allocate memory for "
> - "path: %s\n", strerror(errno));
> + ret = pci_uio_map_uio_resource_by_index(dev, i,
> + uio_res, map_idx);
> + if (ret != 0)
> goto free_uio_res;
> - }
>
> - /*
> - * open resource file, to mmap it
> - */
> - fd = 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 = i * pagesz;
> - mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
> - (size_t)dev->mem_resource[i].len,
> 0);
> - close(fd);
> - if (mapaddr == MAP_FAILED) {
> - rte_free(maps[map_idx].path);
> - goto free_uio_res;
> - }
> -
> - maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
> - maps[map_idx].size = dev->mem_resource[i].len;
> - maps[map_idx].addr = mapaddr;
> - maps[map_idx].offset = offset;
> - strcpy(maps[map_idx].path, devname);
> map_idx++;
> - dev->mem_resource[i].addr = mapaddr;
> }
>
> uio_res->nb_maps = map_idx;
> @@ -325,7 +342,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>
> free_uio_res:
> for (i = 0; i < map_idx; i++)
> - rte_free(maps[i].path);
> + rte_free(uio_res->maps[i].path);
> rte_free(uio_res);
>
> /* 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;
> }
>
> +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_index() 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 == NULL) || (uio_res == NULL))
> + return -1;
> +
> + loc = &dev->addr;
> + maps = 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 = rte_malloc(NULL, strlen(devname) + 1, 0);
> + if (maps[map_idx].path == NULL) {
> + RTE_LOG(ERR, EAL, "Cannot allocate memory for "
> + "path: %s\n", strerror(errno));
> + return -1;
> + }
> +
> + /*
> + * open resource file, to mmap it
> + */
> + fd = 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 == NULL)
> + pci_map_addr = pci_find_max_end_va();
> +
> + mapaddr = pci_map_resource(pci_map_addr, fd, 0,
> + (size_t)dev->mem_resource[res_idx].len, 0);
> + close(fd);
> + if (mapaddr == MAP_FAILED)
> + goto fail;
> +
> + pci_map_addr = RTE_PTR_ADD(mapaddr,
> + (size_t)dev->mem_resource[res_idx].len);
> +
> + maps[map_idx].phaddr = dev->mem_resource[res_idx].phys_addr;
> + maps[map_idx].size = dev->mem_resource[res_idx].len;
> + maps[map_idx].addr = mapaddr;
> + maps[map_idx].offset = 0;
> + strcpy(maps[map_idx].path, devname);
> + dev->mem_resource[res_idx].addr = 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 = &dev->addr;
> struct mapped_pci_resource *uio_res = NULL;
> struct mapped_pci_res_list *uio_res_list =
> RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
> - struct pci_map *maps;
>
> dev->intr_handle.fd = -1;
> dev->intr_handle.uio_cfg_fd = -1;
> @@ -361,63 +424,18 @@ pci_uio_map_resource(struct rte_pci_device *dev)
> return ret;
>
> /* Map all BARs */
> - maps = uio_res->maps;
> for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
> - int fd;
> -
> /* skip empty BAR */
> phaddr = dev->mem_resource[i].phys_addr;
> if (phaddr == 0)
> continue;
>
> -
> - /* 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 = rte_malloc(NULL, strlen(devname) +
> 1, 0);
> - if (maps[map_idx].path == 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 = 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 = pci_uio_map_uio_resource_by_index(dev, i,
> + uio_res, map_idx);
> + if (ret != 0)
> goto free_uio_res;
> - }
> -
> - /* try mapping somewhere close to the end of hugepages */
> - if (pci_map_addr == NULL)
> - pci_map_addr = pci_find_max_end_va();
> -
> - mapaddr = pci_map_resource(pci_map_addr, fd, 0,
> - (size_t)dev->mem_resource[i].len, 0);
> - close(fd);
> - if (mapaddr == MAP_FAILED) {
> - rte_free(maps[map_idx].path);
> - goto free_uio_res;
> - }
> -
> - pci_map_addr = RTE_PTR_ADD(mapaddr,
> - (size_t)dev->mem_resource[i].len);
>
> - maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
> - maps[map_idx].size = dev->mem_resource[i].len;
> - maps[map_idx].addr = mapaddr;
> - maps[map_idx].offset = 0;
> - strcpy(maps[map_idx].path, devname);
> map_idx++;
> - dev->mem_resource[i].addr = mapaddr;
> }
>
> uio_res->nb_maps = map_idx;
> @@ -430,7 +448,7 @@ free_uio_res:
> for (i = 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);
>
> --
> 2.1.4
next prev parent reply other threads:[~2015-06-29 13:36 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-19 6:21 [dpdk-dev] [PATCH 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
2015-05-19 6:21 ` [dpdk-dev] [PATCH 1/8] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
2015-05-19 6:21 ` [dpdk-dev] [PATCH 2/8] eal: Add pci_uio_map_uio_resource_by_index() Tetsuya Mukawa
2015-05-19 6:21 ` [dpdk-dev] [PATCH 3/8] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
2015-05-19 6:21 ` [dpdk-dev] [PATCH 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
2015-06-26 8:21 ` [dpdk-dev] [PATCH v2 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
2015-06-26 8:21 ` [dpdk-dev] [PATCH v2 1/8] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
2015-06-26 8:21 ` [dpdk-dev] [PATCH v2 2/8] eal: Add pci_uio_map_uio_resource_by_index() Tetsuya Mukawa
2015-06-26 8:21 ` [dpdk-dev] [PATCH v2 3/8] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
2015-06-26 8:21 ` [dpdk-dev] [PATCH v2 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
2015-06-26 8:21 ` [dpdk-dev] [PATCH v2 5/8] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
2015-06-26 8:21 ` [dpdk-dev] [PATCH v2 6/8] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
2015-06-26 8:21 ` [dpdk-dev] [PATCH v2 7/8] eal: Consolidate pci uio functions " Tetsuya Mukawa
2015-06-26 8:21 ` [dpdk-dev] [PATCH v2 8/8] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
2015-06-29 2:56 ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Tetsuya Mukawa
2015-06-29 2:56 ` [dpdk-dev] [PATCH v3 1/8] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
2015-06-29 13:24 ` Iremonger, Bernard
2015-06-30 2:31 ` Tetsuya Mukawa
2015-06-29 2:56 ` [dpdk-dev] [PATCH v3 2/8] eal: Add pci_uio_map_uio_resource_by_index() Tetsuya Mukawa
2015-06-29 13:36 ` Iremonger, Bernard [this message]
2015-06-30 2:34 ` Tetsuya Mukawa
2015-06-29 2:56 ` [dpdk-dev] [PATCH v3 3/8] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
2015-06-29 2:56 ` [dpdk-dev] [PATCH v3 4/8] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
2015-06-29 15:28 ` Bruce Richardson
2015-06-30 8:08 ` Tetsuya Mukawa
2015-06-30 12:50 ` Bruce Richardson
2015-06-29 2:56 ` [dpdk-dev] [PATCH v3 5/8] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
2015-06-29 2:56 ` [dpdk-dev] [PATCH v3 6/8] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
2015-06-29 2:56 ` [dpdk-dev] [PATCH v3 7/8] eal: Consolidate pci uio functions " Tetsuya Mukawa
2015-06-29 14:03 ` Iremonger, Bernard
2015-06-30 2:43 ` Tetsuya Mukawa
2015-06-30 8:28 ` Tetsuya Mukawa
2015-06-29 2:56 ` [dpdk-dev] [PATCH v3 8/8] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
2015-06-30 8:26 ` [dpdk-dev] [PATCH v4] Add Port Hotplug support to BSD Tetsuya Mukawa
2015-06-30 8:26 ` [dpdk-dev] [PATCH v4] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
2015-06-30 15:08 ` Iremonger, Bernard
2015-06-30 15:40 ` Bruce Richardson
2015-07-01 6:37 ` Tetsuya Mukawa
2015-07-08 22:15 ` Thomas Monjalon
2015-06-29 15:30 ` [dpdk-dev] [PATCH v3 0/8] Add Port Hotplug support to BSD Bruce Richardson
2015-06-30 8:08 ` Tetsuya Mukawa
2015-05-19 6:21 ` [dpdk-dev] [PATCH 5/8] eal: Consolidate pci_map/unmap_device() of linuxapp and bsdapp Tetsuya Mukawa
2015-05-19 6:21 ` [dpdk-dev] [PATCH 6/8] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
2015-05-19 6:21 ` [dpdk-dev] [PATCH 7/8] eal: Consolidate pci uio functions " Tetsuya Mukawa
2015-05-19 6:21 ` [dpdk-dev] [PATCH 8/8] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
2015-05-19 16:03 ` [dpdk-dev] [PATCH 0/8] Add Port Hotplug support to BSD Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8CEF83825BEC744B83065625E567D7C204A42D6C@IRSMSX108.ger.corp.intel.com \
--to=bernard.iremonger@intel.com \
--cc=dev@dpdk.org \
--cc=mukawa@igel.co.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).