From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f181.google.com (mail-pf0-f181.google.com [209.85.192.181]) by dpdk.org (Postfix) with ESMTP id 6200B567C for ; Mon, 14 Dec 2015 14:01:18 +0100 (CET) Received: by pff63 with SMTP id 63so11007839pff.2 for ; Mon, 14 Dec 2015 05:01:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mvista-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dk8s1rpjzR03o/0kquzv5cYlJ3BD64szWXSLQQVdhkA=; b=Pd/KDN7/sDH1aWGOmaMNVj5hgFMurLalGNONQp2ThLUPRGu5b8t6zBWHkP7Zk4IRVl 6joJ2MVq5yrWpI0bgaDhXrRaVF1VmtTq/N9bI7EIZL0BxWsIiWi5YKdJ1rwa6ILV1t7t A+ohxCMUITIEtiDep06FvyJ5XD3dq0zzKd60cDr+9M1ymmwQNxVM57FMS3usC/qvzsHV Ze/8jfUufr6jpJUfqp0dMHedghmTOxjwUSY9H6nxL7JYXfJBCF+yGL26ClMsSO6QISh7 B7pP3OjS7SmmlaKnhA+Wlo8DRdGAbq6FdwG2uPjM3ZNH3nKL2NDqw1w2n0qMiYLwtHSj MkVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dk8s1rpjzR03o/0kquzv5cYlJ3BD64szWXSLQQVdhkA=; b=lPRahi3wpLf3RNVAZ3AckgcyUt5fbOz6Lj8ynZRTfvskm8w71+5v6QAdjCiETvEHpO OUahd6LLj4tJ9OPCWCivg2xoWZF0kHXfVtrVZ3sWJ4P8DA+zB8DMHmds7Il1M5D4DCXR v9dleoa0nhl+b+y+jbStwiDP3mdHK47Ia3mXKZPP8SVFEwnrsb7D25eKMRxB5lX1oiCW 9ICHp1uZ+BcT51CvPUN8jpubSerIW+H7FWkdYdFObvFt6/odteFmT65UvIB27c2oC0Wj E8FzUzWBKTzY0b9IT6f2EJeYOE5J+50kT3t87C8imgDJBMp8sA448v6v5QWOWJmAl4Ma 4F0w== X-Gm-Message-State: ALoCoQk2gf5J9QUoCZE252Tfh6SabWvGwAc6+QafTdgzF7Atpt7y5Pw+X69TCJJkW06f4KUI9AskT/vmaiYA2sLMpTTVCqWJCA== X-Received: by 10.98.68.198 with SMTP id m67mr13526669pfi.148.1450098077785; Mon, 14 Dec 2015 05:01:17 -0800 (PST) Received: from santosh-Latitude-E5530-non-vPro.mvista.com ([110.172.16.5]) by smtp.gmail.com with ESMTPSA id 9sm42506405pfn.51.2015.12.14.05.01.14 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Dec 2015 05:01:16 -0800 (PST) From: Santosh Shukla To: dev@dpdk.org Date: Mon, 14 Dec 2015 18:30:30 +0530 Message-Id: <1450098032-21198-12-git-send-email-sshukla@mvista.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1450098032-21198-1-git-send-email-sshukla@mvista.com> References: <1450098032-21198-1-git-send-email-sshukla@mvista.com> Cc: Rakesh Krishnamurthy , Rizwan Ansari Subject: [dpdk-dev] [ [PATCH v2] 11/13] virtio_ioport: armv7/v8: mmap virtio iopci bar region 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, 14 Dec 2015 13:01:18 -0000 Introducing module to mmap iopci bar region. Applicable for linuxapp for non-x86 archs, Tested for arm64/ThunderX platform for linux. For that adding two global api. - virtio_ioport_init - virtio_ioport_unmap Signed-off-by: Santosh Shukla Signed-off-by: Rizwan Ansari Signed-off-by: Rakesh Krishnamurthy --- drivers/net/virtio/Makefile | 1 + drivers/net/virtio/virtio_ioport.c | 163 ++++++++++++++++++++++++++++++++++++ drivers/net/virtio/virtio_ioport.h | 42 ++++++++++ 3 files changed, 206 insertions(+) create mode 100644 drivers/net/virtio/virtio_ioport.c create mode 100644 drivers/net/virtio/virtio_ioport.h diff --git a/drivers/net/virtio/Makefile b/drivers/net/virtio/Makefile index 25a842d..5cba6d3 100644 --- a/drivers/net/virtio/Makefile +++ b/drivers/net/virtio/Makefile @@ -50,6 +50,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtqueue.c SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_pci.c SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_rxtx.c SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_ethdev.c +SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_ioport.c SRCS-$(CONFIG_RTE_VIRTIO_INC_VECTOR) += virtio_rxtx_simple.c # this lib depends upon: diff --git a/drivers/net/virtio/virtio_ioport.c b/drivers/net/virtio/virtio_ioport.c new file mode 100644 index 0000000..ffeb8e9 --- /dev/null +++ b/drivers/net/virtio/virtio_ioport.c @@ -0,0 +1,163 @@ +/* + * BSD LICENSE + * + * Copyright(c) 2015 Cavium Networks. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "virtio_ioport.h" + +#if defined(RTE_EXEC_ENV_LINUXAPP) && (defined(RTE_ARCH_ARM) || \ + defined(RTE_ARCH_ARM64)) + +#include +#include +#include +#include +#include +#include +#include + +#include "virtio_logs.h" + +/* start address of first pci_iobar slot (user-space virtual-addres) */ +void *ioport_map; +/** + * ioport map count, + * Use-case: virtio-net-pci. + * Keeps track of number of virtio-net-pci device mapped/unmapped. Max device + * support by linux kernel is 31, so ioport_map_cnt can not be greater than 31. + */ +static int ioport_map_cnt; + +static int +virtio_map_ioport(void **resource_addr) +{ + int fd; + int ret = 0; + + /* avoid -Werror=unused-parameter, keep compiler happy */ + (void)resource_addr; + fd = open(VIRT_IOPORT_DEV, O_RDWR); + if (fd < 0) { + PMD_INIT_LOG(ERR, "device file %s open error: %d\n", + DEV_NAME, fd); + ret = -1; + goto out; + } + + ioport_map = mmap(NULL, PCI_VIRT_IOPORT_SIZE, + PROT_EXEC | PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0); + + if (ioport_map == MAP_FAILED) { + PMD_INIT_LOG(ERR, "mmap: failed to map bar Address=%p\n", + *resource_addr); + ret = -ENOMEM; + goto out1; + } + + PMD_INIT_LOG(INFO, "First pci_iobar mapped at %p\n", ioport_map); + +out1: + close(fd); +out: + return ret; +} + +static int +virtio_set_ioport_addr(void **resource_addr, unsigned long offset) +{ + int ret = 0; + + if (ioport_map_cnt >= PCI_VIRT_IOPORT_MAX) { + ret = -1; + PMD_INIT_LOG(ERR, + "ioport_map_cnt(%d) greater than" + "PCI_VIRT_IOPORT_MAX(%d)\n", + ioport_map_cnt, PCI_VIRT_IOPORT_MAX); + return ret; + } + *resource_addr = (void *)((char *)ioport_map + (ioport_map_cnt)*offset); + ioport_map_cnt++; + + PMD_INIT_LOG(DEBUG, "pci.resource_addr %p ioport_map_cnt %d\n", + *resource_addr, ioport_map_cnt); + return ret; +} + +int virtio_ioport_init(struct rte_pci_resource *mem_resource) +{ + int ret = 0; + + /** + * Map the all IOBAR entry from /proc/ioport to 4k page_size only once. + * Later virtio_set_ioport_addr() func will update correct bar_addr for + * each ioport (i.e..pci_dev->mem_resource[0].addr) + */ + if (!ioport_map) { + ret = virtio_map_ioport(&mem_resource->addr); + if (ret < 0) + return ret; + PMD_INIT_LOG(INFO, "ioport_map %p\n", ioport_map); + } + + ret = virtio_set_ioport_addr(&mem_resource->addr, mem_resource->len); + if (ret < 0) + return ret; + + PMD_INIT_LOG(INFO, "resource_addr %p resource_len :%ld\n", + mem_resource->addr, (unsigned long)mem_resource->len); + return ret; +} + +void virtio_ioport_unmap(void) +{ + /* unmap ioport memory */ + ioport_map_cnt--; + if (!ioport_map_cnt) + munmap(ioport_map, PCI_VIRT_IOPORT_SIZE); + + PMD_INIT_LOG(DEBUG, "unmapping ioport_mem %d\n", ioport_map_cnt); +} + +#else /* !LINUXAPP && !ARM/64 */ + +int virtio_ioport_init(struct rte_pci_resource *mem_resource) +{ + (void)mem_resource; + return 0; +} + +void virtio_ioport_unmap(void) +{ + return; +} + +#endif /* LINUXAPP, ARM/64 */ diff --git a/drivers/net/virtio/virtio_ioport.h b/drivers/net/virtio/virtio_ioport.h new file mode 100644 index 0000000..bf79551 --- /dev/null +++ b/drivers/net/virtio/virtio_ioport.h @@ -0,0 +1,42 @@ +/* + * BSD LICENSE + * + * Copyright(c) 2015 Cavium Networks. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _VIRTIO_IOPORT_H_ +#define _VIRTIO_IOPORT_H_ + +#include + +int virtio_ioport_init(struct rte_pci_resource *mem_resource); +void virtio_ioport_unmap(void); + +#endif /* _VIRTIO_IOPORT_H_ */ -- 1.7.9.5