diff mbox

[dpdk-dev,RFC,1/6] eal: common direct ring access API

Message ID 1416924682-24170-2-git-send-email-cunming.liang@intel.com (mailing list archive)
State RFC, archived
Headers show

Commit Message

Cunming Liang Nov. 25, 2014, 2:11 p.m. UTC
Signed-off-by: Cunming Liang <cunming.liang@intel.com>
---
 lib/librte_eal/common/Makefile                 |   5 +
 lib/librte_eal/common/include/rte_pci_bifurc.h | 186 +++++++++++++++++++++++++
 2 files changed, 191 insertions(+)
 create mode 100644 lib/librte_eal/common/include/rte_pci_bifurc.h
diff mbox

Patch

diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile
index 499ba4d..6b2e231 100644
--- a/lib/librte_eal/common/Makefile
+++ b/lib/librte_eal/common/Makefile
@@ -52,6 +52,11 @@  GENERIC_INC += rte_spinlock.h rte_memcpy.h rte_cpuflags.h
 ARCH_DIR ?= $(RTE_ARCH)
 ARCH_INC := $(notdir $(wildcard $(RTE_SDK)/lib/librte_eal/common/include/arch/$(ARCH_DIR)/*.h))
 
+ifeq ($(CONFIG_RTE_LIBRTE_EAL_LINUXAPP),y)
+INC += rte_pci_bifurc.h
+endif
+
+
 SYMLINK-$(CONFIG_RTE_LIBRTE_EAL)-include := $(addprefix include/,$(INC))
 SYMLINK-$(CONFIG_RTE_LIBRTE_EAL)-include += \
 	$(addprefix include/arch/$(ARCH_DIR)/,$(ARCH_INC))
diff --git a/lib/librte_eal/common/include/rte_pci_bifurc.h b/lib/librte_eal/common/include/rte_pci_bifurc.h
new file mode 100644
index 0000000..ad93124
--- /dev/null
+++ b/lib/librte_eal/common/include/rte_pci_bifurc.h
@@ -0,0 +1,186 @@ 
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. 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 _RTE_PCI_BIFURC_H_
+#define _RTE_PCI_BIFURC_H_
+
+/**
+ * @file
+ *
+ * RTE PCI BIFURC Interface
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <rte_pci.h>
+#include <rte_devargs.h>
+
+
+/**
+ * Open a socket for direct ring access.
+ * For those socket API support direct ring access,
+ * it opens a socket for such address family.
+ *
+ * @param sockfd
+ *     A pinter to socket file descriptor to get the open sockfd.
+ * @return
+ *     0 on success, negative on error.
+ *
+ */
+int rte_eal_bifurc_open(int *sockfd);
+
+/**
+ * Bind a net interface to specific socket for direct ring access.
+ *
+ * @param sockfd
+ *	The Socket file descriptor to bind the net interface with.
+ * @param if_index
+ *	The net interface used for direct ring access.
+ * @return
+ *      0 on success, negative on error.
+ */
+int rte_eal_bifurc_bind(int sockfd, int if_index);
+
+/**
+ * Map ring specific register space for direct access.
+ *
+ * @param sockfd
+ *	The socket file descriptor to get the ring address mapping from.
+ * @param addr
+ *	The pointer to the virtual address got from mapping.
+ * @param size
+ *      The pointer to the memory size.
+ * @return
+ *      0 on success, negative on error.
+ */
+int rte_eal_bifurc_map(int sockfd, void **addr, uint32_t *size);
+
+/**
+ * Unmap ring specific register space for direct access.
+ *
+ * @param sockfd
+ *	The socket file descriptor to release the ring address mapping.
+ * @param addr
+ *	The unmap virtual address.
+ */
+void rte_eal_bifurc_unmap(int sockfd, void *addr);
+
+/**
+ * Split the ring pairs from the net device.
+ * For those net device support direct ring access,
+ * will split the ring and exclusively reserve the resource.
+ *
+ * @param sockfd
+ *	The socket fd owns the split ring resource.
+ * @param nb_qp
+ *	Request number of queue pair.
+ * @param qp_start
+ *      The first queue pair id.
+ * @return
+ *      0 on success, negative on error.
+ */
+int rte_eal_bifurc_split(int sockfd, uint32_t *nb_qp, uint32_t *qp_start);
+
+/**
+ * Retire the ring pairs to the net device.
+ *
+ * @param sockfd
+ *	The socket fd owns the ring resource.
+ * @param nb_qp
+ *	Request number of queue pair.
+ * @param qp_start
+ *      The first queue pair id.
+ */
+void rte_eal_bifurc_retire(int sockfd, uint32_t nb_qp, uint32_t qp_start);
+
+/**
+ * Utility function to initial pci info in rte_pci_device by net device.
+ *
+ * @param sockfd
+ *	The socket fd stands for the binding net device.
+ * @param pci_dev
+ *	The pointer of pci device to hook with the net device.
+ * @return
+ *      0 on success, negative on error.
+ */
+int rte_eal_bifurc_set_pci(int sockfd, struct rte_pci_device *pci_dev);
+
+/**
+ * Utility function to get net interface info by iface name.
+ *
+ * @param sockfd
+ *	The socket fd which already bind with the net device.
+ * @param iface_name
+ *	The string for iface name.
+ * @param if_index
+ *      The pointer to the index of such net interface/device.
+ * @param hwaddr
+ *      The pointer to the MAC address of such net device.
+ * @param mtu
+ *      The pointer to the MTU os such net device.
+ * @return
+ *      0 on success, negative on error.
+ */
+int rte_eal_bifurc_get_ifinfo(int sockfd, char *iface_name,
+			      int *if_index, uint8_t *hwaddr, int *mtu);
+
+/**
+ * Utility function to get/alloc a devargs instance.
+ *
+ * @param drv_name
+ *	The string of driver name in devargs.
+ * @param args
+ *	The args in devargs.
+ * @return
+ *      0 on success, negative on error.
+ */
+struct rte_devargs *
+rte_eal_bifurc_get_devargs(const char *drv_name, const char *args);
+
+/**
+ * Utility function to free the devargs instance.
+ *
+ * @param devargs
+ *	The devargs instance to free.
+ *
+ */
+void rte_eal_bifurc_put_devargs(struct rte_devargs *devargs);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_PCI_BIFURC_H_ */