net/memif: introduce memory interface PMD

Shared memory packet interface (memif) PMD allows for DPDK and any other
client using memif (DPDK, VPP, libmemif) to communicate using shared
memory. The created device transmits packets in a raw format. It can be
used with Ethernet mode, IP mode, or Punt/Inject. At this moment, only
Ethernet mode is supported in DPDK memif implementation. Memif is Linux
only.

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
This commit is contained in:
Jakub Grajciar 2019-06-06 13:38:50 +02:00 committed by Ferruh Yigit
parent fce0663996
commit 09c7e63a71
18 changed files with 3143 additions and 0 deletions

View File

@ -839,6 +839,12 @@ F: drivers/net/softnic/
F: doc/guides/nics/features/softnic.ini F: doc/guides/nics/features/softnic.ini
F: doc/guides/nics/softnic.rst F: doc/guides/nics/softnic.rst
Memif PMD
M: Jakub Grajciar <jgrajcia@cisco.com>
F: drivers/net/memif/
F: doc/guides/nics/memif.rst
F: doc/guides/nics/features/memif.ini
Crypto Drivers Crypto Drivers
-------------- --------------

View File

@ -444,6 +444,11 @@ CONFIG_RTE_LIBRTE_PMD_AF_PACKET=n
# #
CONFIG_RTE_LIBRTE_PMD_AF_XDP=n CONFIG_RTE_LIBRTE_PMD_AF_XDP=n
#
# Compile Memory Interface PMD driver (Linux only)
#
CONFIG_RTE_LIBRTE_PMD_MEMIF=n
# #
# Compile link bonding PMD library # Compile link bonding PMD library
# #

View File

@ -19,6 +19,7 @@ CONFIG_RTE_LIBRTE_VHOST_POSTCOPY=n
CONFIG_RTE_LIBRTE_PMD_VHOST=y CONFIG_RTE_LIBRTE_PMD_VHOST=y
CONFIG_RTE_LIBRTE_IFC_PMD=y CONFIG_RTE_LIBRTE_IFC_PMD=y
CONFIG_RTE_LIBRTE_PMD_AF_PACKET=y CONFIG_RTE_LIBRTE_PMD_AF_PACKET=y
CONFIG_RTE_LIBRTE_PMD_MEMIF=y
CONFIG_RTE_LIBRTE_PMD_SOFTNIC=y CONFIG_RTE_LIBRTE_PMD_SOFTNIC=y
CONFIG_RTE_LIBRTE_PMD_TAP=y CONFIG_RTE_LIBRTE_PMD_TAP=y
CONFIG_RTE_LIBRTE_AVP_PMD=y CONFIG_RTE_LIBRTE_AVP_PMD=y

View File

@ -0,0 +1,14 @@
;
; Supported features of the 'memif' network poll mode driver.
;
; Refer to default.ini for the full list of available PMD features.
;
[Features]
Link status = Y
Basic stats = Y
Jumbo frame = Y
ARMv8 = Y
Power8 = Y
x86-32 = Y
x86-64 = Y
Usage doc = Y

View File

@ -36,6 +36,7 @@ Network Interface Controller Drivers
intel_vf intel_vf
kni kni
liquidio liquidio
memif
mlx4 mlx4
mlx5 mlx5
mvneta mvneta

234
doc/guides/nics/memif.rst Normal file
View File

@ -0,0 +1,234 @@
.. SPDX-License-Identifier: BSD-3-Clause
Copyright(c) 2018-2019 Cisco Systems, Inc.
======================
Memif Poll Mode Driver
======================
Shared memory packet interface (memif) PMD allows for DPDK and any other client
using memif (DPDK, VPP, libmemif) to communicate using shared memory. Memif is
Linux only.
The created device transmits packets in a raw format. It can be used with
Ethernet mode, IP mode, or Punt/Inject. At this moment, only Ethernet mode is
supported in DPDK memif implementation.
Memif works in two roles: master and slave. Slave connects to master over an
existing socket. It is also a producer of shared memory file and initializes
the shared memory. Each interface can be connected to one peer interface
at same time. The peer interface is identified by id parameter. Master
creates the socket and listens for any slave connection requests. The socket
may already exist on the system. Be sure to remove any such sockets, if you
are creating a master interface, or you will see an "Address already in use"
error. Function ``rte_pmd_memif_remove()``, which removes memif interface,
will also remove a listener socket, if it is not being used by any other
interface.
The method to enable one or more interfaces is to use the
``--vdev=net_memif0`` option on the DPDK application command line. Each
``--vdev=net_memif1`` option given will create an interface named net_memif0,
net_memif1, and so on. Memif uses unix domain socket to transmit control
messages. Each memif has a unique id per socket. This id is used to identify
peer interface. If you are connecting multiple
interfaces using same socket, be sure to specify unique ids ``id=0``, ``id=1``,
etc. Note that if you assign a socket to a master interface it becomes a
listener socket. Listener socket can not be used by a slave interface on same
client.
.. csv-table:: **Memif configuration options**
:header: "Option", "Description", "Default", "Valid value"
"id=0", "Used to identify peer interface", "0", "uint32_t"
"role=master", "Set memif role", "slave", "master|slave"
"bsize=1024", "Size of single packet buffer", "2048", "uint16_t"
"rsize=11", "Log2 of ring size. If rsize is 10, actual ring size is 1024", "10", "1-14"
"socket=/tmp/memif.sock", "Socket filename", "/tmp/memif.sock", "string len 256"
"mac=01:23:45:ab:cd:ef", "Mac address", "01:ab:23:cd:45:ef", ""
"secret=abc123", "Secret is an optional security option, which if specified, must be matched by peer", "", "string len 24"
"zero-copy=yes", "Enable/disable zero-copy slave mode", "no", "yes|no"
**Connection establishment**
In order to create memif connection, two memif interfaces, each in separate
process, are needed. One interface in ``master`` role and other in
``slave`` role. It is not possible to connect two interfaces in a single
process. Each interface can be connected to one interface at same time,
identified by matching id parameter.
Memif driver uses unix domain socket to exchange required information between
memif interfaces. Socket file path is specified at interface creation see
*Memif configuration options* table above. If socket is used by ``master``
interface, it's marked as listener socket (in scope of current process) and
listens to connection requests from other processes. One socket can be used by
multiple interfaces. One process can have ``slave`` and ``master`` interfaces
at the same time, provided each role is assigned unique socket.
For detailed information on memif control messages, see: net/memif/memif.h.
Slave interface attempts to make a connection on assigned socket. Process
listening on this socket will extract the connection request and create a new
connected socket (control channel). Then it sends the 'hello' message
(``MEMIF_MSG_TYPE_HELLO``), containing configuration boundaries. Slave interface
adjusts its configuration accordingly, and sends 'init' message
(``MEMIF_MSG_TYPE_INIT``). This message among others contains interface id. Driver
uses this id to find master interface, and assigns the control channel to this
interface. If such interface is found, 'ack' message (``MEMIF_MSG_TYPE_ACK``) is
sent. Slave interface sends 'add region' message (``MEMIF_MSG_TYPE_ADD_REGION``) for
every region allocated. Master responds to each of these messages with 'ack'
message. Same behavior applies to rings. Slave sends 'add ring' message
(``MEMIF_MSG_TYPE_ADD_RING``) for every initialized ring. Master again responds to
each message with 'ack' message. To finalize the connection, slave interface
sends 'connect' message (``MEMIF_MSG_TYPE_CONNECT``). Upon receiving this message
master maps regions to its address space, initializes rings and responds with
'connected' message (``MEMIF_MSG_TYPE_CONNECTED``). Disconnect
(``MEMIF_MSG_TYPE_DISCONNECT``) can be sent by both master and slave interfaces at
any time, due to driver error or if the interface is being deleted.
Files
- net/memif/memif.h *- control messages definitions*
- net/memif/memif_socket.h
- net/memif/memif_socket.c
Shared memory
~~~~~~~~~~~~~
**Shared memory format**
Slave is producer and master is consumer. Memory regions, are mapped shared memory files,
created by memif slave and provided to master at connection establishment.
Regions contain rings and buffers. Rings and buffers can also be separated into multiple
regions. For no-zero-copy, rings and buffers are stored inside single memory
region to reduce the number of opened files.
region n (no-zero-copy):
+-----------------------+-------------------------------------------------------------------------+
| Rings | Buffers |
+-----------+-----------+-----------------+---+---------------------------------------------------+
| S2M rings | M2S rings | packet buffer 0 | . | pb ((1 << pmd->run.log2_ring_size)*(s2m + m2s))-1 |
+-----------+-----------+-----------------+---+---------------------------------------------------+
S2M OR M2S Rings:
+--------+--------+-----------------------+
| ring 0 | ring 1 | ring num_s2m_rings - 1|
+--------+--------+-----------------------+
ring 0:
+-------------+---------------------------------------+
| ring header | (1 << pmd->run.log2_ring_size) * desc |
+-------------+---------------------------------------+
Descriptors are assigned packet buffers in order of rings creation. If we have one ring
in each direction and ring size is 1024, then first 1024 buffers will belong to S2M ring and
last 1024 will belong to M2S ring. In case of zero-copy, buffers are dequeued and
enqueued as needed.
**Descriptor format**
+----+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Quad|6| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |3|3| | | | | | | | | | | | | | |1|1| | | | | | | | | | | | | | | |
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Word|3| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |2|1| | | | | | | | | | | | | | |6|5| | | | | | | | | | | | | | |0|
+----+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|0 |length |region |flags |
+----+---------------------------------------------------------------+-------------------------------+-------------------------------+
|1 |metadata |offset |
+----+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |6| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |3|3| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |3| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |2|1| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |0|
+----+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
**Flags field - flags (Quad Word 0, bits 0:15)**
+-----+--------------------+------------------------------------------------------------------------------------------------+
|Bits |Name |Functionality |
+=====+====================+================================================================================================+
|0 |MEMIF_DESC_FLAG_NEXT|Is chained buffer. When set, the packet is divided into multiple buffers. May not be contiguous.|
+-----+--------------------+------------------------------------------------------------------------------------------------+
**Region index - region (Quad Word 0, 16:31)**
Index of memory region, the buffer is located in.
**Data length - length (Quad Word 0, 32:63)**
Length of transmitted/received data.
**Data Offset - offset (Quad Word 1, 0:31)**
Data start offset from memory region address. *.regions[desc->region].addr + desc->offset*
**Metadata - metadata (Quad Word 1, 32:63)**
Buffer metadata.
Files
- net/memif/memif.h *- descriptor and ring definitions*
- net/memif/rte_eth_memif.c *- eth_memif_rx() eth_memif_tx()*
Example: testpmd
----------------------------
In this example we run two instances of testpmd application and transmit packets over memif.
First create ``master`` interface::
#./build/app/testpmd -l 0-1 --proc-type=primary --file-prefix=pmd1 --vdev=net_memif,role=master -- -i
Now create ``slave`` interface (master must be already running so the slave will connect)::
#./build/app/testpmd -l 2-3 --proc-type=primary --file-prefix=pmd2 --vdev=net_memif -- -i
Start forwarding packets::
Slave:
testpmd> start
Master:
testpmd> start tx_first
Show status::
testpmd> show port stats 0
For more details on testpmd please refer to :doc:`../testpmd_app_ug/index`.
Example: testpmd and VPP
------------------------
For information on how to get and run VPP please see `<https://wiki.fd.io/view/VPP>`_.
Start VPP in interactive mode (should be by default). Create memif master interface in VPP::
vpp# create interface memif id 0 master no-zero-copy
vpp# set interface state memif0/0 up
vpp# set interface ip address memif0/0 192.168.1.1/24
To see socket filename use show memif command::
vpp# show memif
sockets
id listener filename
0 yes (1) /run/vpp/memif.sock
...
Now create memif interface by running testpmd with these command line options::
#./testpmd --vdev=net_memif,socket=/run/vpp/memif.sock -- -i
Testpmd should now create memif slave interface and try to connect to master.
In testpmd set forward option to icmpecho and start forwarding::
testpmd> set fwd icmpecho
testpmd> start
Send ping from VPP::
vpp# ping 192.168.1.2
64 bytes from 192.168.1.2: icmp_seq=2 ttl=254 time=36.2918 ms
64 bytes from 192.168.1.2: icmp_seq=3 ttl=254 time=23.3927 ms
64 bytes from 192.168.1.2: icmp_seq=4 ttl=254 time=24.2975 ms
64 bytes from 192.168.1.2: icmp_seq=5 ttl=254 time=17.7049 ms

View File

@ -62,6 +62,11 @@ New Features
* Added support for SSE vector mode * Added support for SSE vector mode
* Updated HWRM API to version 1.10.0.74 * Updated HWRM API to version 1.10.0.74
* **Added memif PMD.**
Added the new Shared Memory Packet Interface (``memif``) PMD.
See the :doc:`../nics/memif` guide for more details on this new driver.
Removed Items Removed Items
------------- -------------

View File

@ -35,6 +35,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_ICE_PMD) += ice
DIRS-$(CONFIG_RTE_LIBRTE_IPN3KE_PMD) += ipn3ke DIRS-$(CONFIG_RTE_LIBRTE_IPN3KE_PMD) += ipn3ke
DIRS-$(CONFIG_RTE_LIBRTE_IXGBE_PMD) += ixgbe DIRS-$(CONFIG_RTE_LIBRTE_IXGBE_PMD) += ixgbe
DIRS-$(CONFIG_RTE_LIBRTE_LIO_PMD) += liquidio DIRS-$(CONFIG_RTE_LIBRTE_LIO_PMD) += liquidio
DIRS-$(CONFIG_RTE_LIBRTE_PMD_MEMIF) += memif
DIRS-$(CONFIG_RTE_LIBRTE_MLX4_PMD) += mlx4 DIRS-$(CONFIG_RTE_LIBRTE_MLX4_PMD) += mlx4
DIRS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5 DIRS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5
DIRS-$(CONFIG_RTE_LIBRTE_MVNETA_PMD) += mvneta DIRS-$(CONFIG_RTE_LIBRTE_MVNETA_PMD) += mvneta

View File

@ -0,0 +1,31 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2018-2019 Cisco Systems, Inc. All rights reserved.
include $(RTE_SDK)/mk/rte.vars.mk
#
# library name
#
LIB = librte_pmd_memif.a
EXPORT_MAP := rte_pmd_memif_version.map
LIBABIVER := 1
CFLAGS += -O3
CFLAGS += $(WERROR_FLAGS)
CFLAGS += -DALLOW_EXPERIMENTAL_API
# Experimantal APIs:
# - rte_intr_callback_unregister_pending
LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool
LDLIBS += -lrte_ethdev -lrte_kvargs
LDLIBS += -lrte_hash
LDLIBS += -lrte_bus_vdev
#
# all source are stored in SRCS-y
#
SRCS-$(CONFIG_RTE_LIBRTE_PMD_MEMIF) += rte_eth_memif.c
SRCS-$(CONFIG_RTE_LIBRTE_PMD_MEMIF) += memif_socket.c
include $(RTE_SDK)/mk/rte.lib.mk

179
drivers/net/memif/memif.h Normal file
View File

@ -0,0 +1,179 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright 2018-2019 Cisco Systems, Inc. All rights reserved.
*/
#ifndef _MEMIF_H_
#define _MEMIF_H_
#define MEMIF_COOKIE 0x3E31F20
#define MEMIF_VERSION_MAJOR 2
#define MEMIF_VERSION_MINOR 0
#define MEMIF_VERSION ((MEMIF_VERSION_MAJOR << 8) | MEMIF_VERSION_MINOR)
#define MEMIF_NAME_SZ 32
/*
* S2M: direction slave -> master
* M2S: direction master -> slave
*/
/*
* Type definitions
*/
typedef enum memif_msg_type {
MEMIF_MSG_TYPE_NONE,
MEMIF_MSG_TYPE_ACK,
MEMIF_MSG_TYPE_HELLO,
MEMIF_MSG_TYPE_INIT,
MEMIF_MSG_TYPE_ADD_REGION,
MEMIF_MSG_TYPE_ADD_RING,
MEMIF_MSG_TYPE_CONNECT,
MEMIF_MSG_TYPE_CONNECTED,
MEMIF_MSG_TYPE_DISCONNECT,
} memif_msg_type_t;
typedef enum {
MEMIF_RING_S2M, /**< buffer ring in direction slave -> master */
MEMIF_RING_M2S, /**< buffer ring in direction master -> slave */
} memif_ring_type_t;
typedef enum {
MEMIF_INTERFACE_MODE_ETHERNET,
MEMIF_INTERFACE_MODE_IP,
MEMIF_INTERFACE_MODE_PUNT_INJECT,
} memif_interface_mode_t;
typedef uint16_t memif_region_index_t;
typedef uint32_t memif_region_offset_t;
typedef uint64_t memif_region_size_t;
typedef uint16_t memif_ring_index_t;
typedef uint32_t memif_interface_id_t;
typedef uint16_t memif_version_t;
typedef uint8_t memif_log2_ring_size_t;
/*
* Socket messages
*/
/**
* M2S
* Contains master interfaces configuration.
*/
typedef struct __rte_packed {
uint8_t name[MEMIF_NAME_SZ]; /**< Client app name. In this case DPDK version */
memif_version_t min_version; /**< lowest supported memif version */
memif_version_t max_version; /**< highest supported memif version */
memif_region_index_t max_region; /**< maximum num of regions */
memif_ring_index_t max_m2s_ring; /**< maximum num of M2S ring */
memif_ring_index_t max_s2m_ring; /**< maximum num of S2M rings */
memif_log2_ring_size_t max_log2_ring_size; /**< maximum ring size (as log2) */
} memif_msg_hello_t;
/**
* S2M
* Contains information required to identify interface
* to which the slave wants to connect.
*/
typedef struct __rte_packed {
memif_version_t version; /**< memif version */
memif_interface_id_t id; /**< interface id */
memif_interface_mode_t mode:8; /**< interface mode */
uint8_t secret[24]; /**< optional security parameter */
uint8_t name[MEMIF_NAME_SZ]; /**< Client app name. In this case DPDK version */
} memif_msg_init_t;
/**
* S2M
* Request master to add new shared memory region to master interface.
* Shared files file descriptor is passed in cmsghdr.
*/
typedef struct __rte_packed {
memif_region_index_t index; /**< shm regions index */
memif_region_size_t size; /**< shm region size */
} memif_msg_add_region_t;
/**
* S2M
* Request master to add new ring to master interface.
*/
typedef struct __rte_packed {
uint16_t flags; /**< flags */
#define MEMIF_MSG_ADD_RING_FLAG_S2M 1 /**< ring is in S2M direction */
memif_ring_index_t index; /**< ring index */
memif_region_index_t region; /**< region index on which this ring is located */
memif_region_offset_t offset; /**< buffer start offset */
memif_log2_ring_size_t log2_ring_size; /**< ring size (log2) */
uint16_t private_hdr_size; /**< used for private metadata */
} memif_msg_add_ring_t;
/**
* S2M
* Finalize connection establishment.
*/
typedef struct __rte_packed {
uint8_t if_name[MEMIF_NAME_SZ]; /**< slave interface name */
} memif_msg_connect_t;
/**
* M2S
* Finalize connection establishment.
*/
typedef struct __rte_packed {
uint8_t if_name[MEMIF_NAME_SZ]; /**< master interface name */
} memif_msg_connected_t;
/**
* S2M & M2S
* Disconnect interfaces.
*/
typedef struct __rte_packed {
uint32_t code; /**< error code */
uint8_t string[96]; /**< disconnect reason */
} memif_msg_disconnect_t;
typedef struct __rte_packed __rte_aligned(128)
{
memif_msg_type_t type:16;
union {
memif_msg_hello_t hello;
memif_msg_init_t init;
memif_msg_add_region_t add_region;
memif_msg_add_ring_t add_ring;
memif_msg_connect_t connect;
memif_msg_connected_t connected;
memif_msg_disconnect_t disconnect;
};
} memif_msg_t;
/*
* Ring and Descriptor Layout
*/
/**
* Buffer descriptor.
*/
typedef struct __rte_packed {
uint16_t flags; /**< flags */
#define MEMIF_DESC_FLAG_NEXT 1 /**< is chained buffer */
memif_region_index_t region; /**< region index on which the buffer is located */
uint32_t length; /**< buffer length */
memif_region_offset_t offset; /**< buffer offset */
uint32_t metadata;
} memif_desc_t;
#define MEMIF_CACHELINE_ALIGN_MARK(mark) \
uint8_t mark[0] __rte_aligned(RTE_CACHE_LINE_SIZE)
typedef struct {
MEMIF_CACHELINE_ALIGN_MARK(cacheline0);
uint32_t cookie; /**< MEMIF_COOKIE */
uint16_t flags; /**< flags */
#define MEMIF_RING_FLAG_MASK_INT 1 /**< disable interrupt mode */
volatile uint16_t head; /**< pointer to ring buffer head */
MEMIF_CACHELINE_ALIGN_MARK(cacheline1);
volatile uint16_t tail; /**< pointer to ring buffer tail */
MEMIF_CACHELINE_ALIGN_MARK(cacheline2);
memif_desc_t desc[0]; /**< buffer descriptors */
} memif_ring_t;
#endif /* _MEMIF_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,105 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright 2018-2019 Cisco Systems, Inc. All rights reserved.
*/
#ifndef _MEMIF_SOCKET_H_
#define _MEMIF_SOCKET_H_
#include <sys/queue.h>
/**
* Remove device from socket device list. If no device is left on the socket,
* remove the socket as well.
*
* @param dev
* memif device
*/
void memif_socket_remove_device(struct rte_eth_dev *dev);
/**
* Enqueue disconnect message to control channel message queue.
*
* @param cc
* control channel
* @param reason
* const string stating disconnect reason (96 characters)
* @param err_code
* error code
*/
void memif_msg_enq_disconnect(struct memif_control_channel *cc, const char *reason,
int err_code);
/**
* Initialize memif socket for specified device. If socket doesn't exist, create socket.
*
* @param dev
* memif device
* @param socket_filename
* socket filename
* @return
* - On success, zero.
* - On failure, a negative value.
*/
int memif_socket_init(struct rte_eth_dev *dev, const char *socket_filename);
/**
* Disconnect memif device. Close control channel and shared memory.
*
* @param dev
* memif device
*/
void memif_disconnect(struct rte_eth_dev *dev);
/**
* If device is properly configured, enable connection establishment.
*
* @param dev
* memif device
* @return
* - On success, zero.
* - On failure, a negative value.
*/
int memif_connect_master(struct rte_eth_dev *dev);
/**
* If device is properly configured, send connection request.
*
* @param dev
* memif device
* @return
* - On success, zero.
* - On failure, a negative value.
*/
int memif_connect_slave(struct rte_eth_dev *dev);
struct memif_socket_dev_list_elt {
TAILQ_ENTRY(memif_socket_dev_list_elt) next;
struct rte_eth_dev *dev; /**< pointer to device internals */
char dev_name[RTE_ETH_NAME_MAX_LEN];
};
#define MEMIF_SOCKET_HASH_NAME "memif-sh"
struct memif_socket {
struct rte_intr_handle intr_handle; /**< interrupt handle */
char filename[256]; /**< socket filename */
TAILQ_HEAD(, memif_socket_dev_list_elt) dev_queue;
/**< Queue of devices using this socket */
uint8_t listener; /**< if not zero socket is listener */
};
/* Control message queue. */
struct memif_msg_queue_elt {
memif_msg_t msg; /**< control message */
TAILQ_ENTRY(memif_msg_queue_elt) next;
int fd; /**< fd to be sent to peer */
};
struct memif_control_channel {
struct rte_intr_handle intr_handle; /**< interrupt handle */
TAILQ_HEAD(, memif_msg_queue_elt) msg_queue; /**< control message queue */
struct memif_socket *socket; /**< pointer to socket */
struct rte_eth_dev *dev; /**< pointer to device */
};
#endif /* MEMIF_SOCKET_H */

View File

@ -0,0 +1,15 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2018-2019 Cisco Systems, Inc. All rights reserved.
if host_machine.system() != 'linux'
build = false
endif
sources = files('rte_eth_memif.c',
'memif_socket.c')
allow_experimental_apis = true
# Experimantal APIs:
# - rte_intr_callback_unregister_pending
deps += ['hash']

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,212 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright 2018-2019 Cisco Systems, Inc. All rights reserved.
*/
#ifndef _RTE_ETH_MEMIF_H_
#define _RTE_ETH_MEMIF_H_
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif /* GNU_SOURCE */
#include <sys/queue.h>
#include <rte_ethdev_driver.h>
#include <rte_ether.h>
#include <rte_interrupts.h>
#include "memif.h"
#define ETH_MEMIF_DEFAULT_SOCKET_FILENAME "/run/memif.sock"
#define ETH_MEMIF_DEFAULT_RING_SIZE 10
#define ETH_MEMIF_DEFAULT_PKT_BUFFER_SIZE 2048
#define ETH_MEMIF_MAX_NUM_Q_PAIRS 255
#define ETH_MEMIF_MAX_LOG2_RING_SIZE 14
#define ETH_MEMIF_MAX_REGION_NUM 256
#define ETH_MEMIF_SHM_NAME_SIZE 32
#define ETH_MEMIF_DISC_STRING_SIZE 96
#define ETH_MEMIF_SECRET_SIZE 24
extern int memif_logtype;
#define MIF_LOG(level, fmt, args...) \
rte_log(RTE_LOG_ ## level, memif_logtype, \
"%s(): " fmt "\n", __func__, ##args)
enum memif_role_t {
MEMIF_ROLE_MASTER,
MEMIF_ROLE_SLAVE,
};
struct memif_region {
void *addr; /**< shared memory address */
memif_region_size_t region_size; /**< shared memory size */
int fd; /**< shared memory file descriptor */
uint32_t pkt_buffer_offset;
/**< offset from 'addr' to first packet buffer */
};
struct memif_queue {
struct rte_mempool *mempool; /**< mempool for RX packets */
struct pmd_internals *pmd; /**< device internals */
memif_ring_type_t type; /**< ring type */
memif_region_index_t region; /**< shared memory region index */
uint16_t in_port; /**< port id */
memif_region_offset_t ring_offset;
/**< ring offset from start of shm region (ring - memif_region.addr) */
uint16_t last_head; /**< last ring head */
uint16_t last_tail; /**< last ring tail */
/* rx/tx info */
uint64_t n_pkts; /**< number of rx/tx packets */
uint64_t n_bytes; /**< number of rx/tx bytes */
uint64_t n_err; /**< number of tx errors */
memif_ring_t *ring; /**< pointer to ring */
struct rte_intr_handle intr_handle; /**< interrupt handle */
memif_log2_ring_size_t log2_ring_size; /**< log2 of ring size */
};
struct pmd_internals {
memif_interface_id_t id; /**< unique id */
enum memif_role_t role; /**< device role */
uint32_t flags; /**< device status flags */
#define ETH_MEMIF_FLAG_CONNECTING (1 << 0)
/**< device is connecting */
#define ETH_MEMIF_FLAG_CONNECTED (1 << 1)
/**< device is connected */
#define ETH_MEMIF_FLAG_ZERO_COPY (1 << 2)
/**< device is zero-copy enabled */
#define ETH_MEMIF_FLAG_DISABLED (1 << 3)
/**< device has not been configured and can not accept connection requests */
char *socket_filename; /**< pointer to socket filename */
char secret[ETH_MEMIF_SECRET_SIZE]; /**< secret (optional security parameter) */
struct memif_control_channel *cc; /**< control channel */
struct memif_region *regions[ETH_MEMIF_MAX_REGION_NUM];
/**< shared memory regions */
memif_region_index_t regions_num; /**< number of regions */
/* remote info */
char remote_name[RTE_DEV_NAME_MAX_LEN]; /**< remote app name */
char remote_if_name[RTE_DEV_NAME_MAX_LEN]; /**< remote peer name */
struct {
memif_log2_ring_size_t log2_ring_size; /**< log2 of ring size */
uint8_t num_s2m_rings; /**< number of slave to master rings */
uint8_t num_m2s_rings; /**< number of master to slave rings */
uint16_t pkt_buffer_size; /**< buffer size */
} cfg; /**< Configured parameters (max values) */
struct {
memif_log2_ring_size_t log2_ring_size; /**< log2 of ring size */
uint8_t num_s2m_rings; /**< number of slave to master rings */
uint8_t num_m2s_rings; /**< number of master to slave rings */
uint16_t pkt_buffer_size; /**< buffer size */
} run;
/**< Parameters used in active connection */
char local_disc_string[ETH_MEMIF_DISC_STRING_SIZE];
/**< local disconnect reason */
char remote_disc_string[ETH_MEMIF_DISC_STRING_SIZE];
/**< remote disconnect reason */
struct rte_vdev_device *vdev; /**< vdev handle */
};
/**
* Unmap shared memory and free regions from memory.
*
* @param pmd
* device internals
*/
void memif_free_regions(struct pmd_internals *pmd);
/**
* Finalize connection establishment process. Map shared memory file
* (master role), initialize ring queue, set link status up.
*
* @param dev
* memif device
* @return
* - On success, zero.
* - On failure, a negative value.
*/
int memif_connect(struct rte_eth_dev *dev);
/**
* Create shared memory file and initialize ring queue.
* Only called by slave when establishing connection
*
* @param dev
* memif device
* @return
* - On success, zero.
* - On failure, a negative value.
*/
int memif_init_regions_and_queues(struct rte_eth_dev *dev);
/**
* Get memif version string.
*
* @return
* - memif version string
*/
const char *memif_version(void);
#ifndef MFD_HUGETLB
#ifndef __NR_memfd_create
#if defined __x86_64__
#define __NR_memfd_create 319
#elif defined __x86_32__
#define __NR_memfd_create 1073742143
#elif defined __arm__
#define __NR_memfd_create 385
#elif defined __aarch64__
#define __NR_memfd_create 279
#elif defined __powerpc__
#define __NR_memfd_create 360
#elif defined __i386__
#define __NR_memfd_create 356
#else
#error "__NR_memfd_create unknown for this architecture"
#endif
#endif /* __NR_memfd_create */
static inline int memfd_create(const char *name, unsigned int flags)
{
return syscall(__NR_memfd_create, name, flags);
}
#endif /* MFD_HUGETLB */
#ifndef F_LINUX_SPECIFIC_BASE
#define F_LINUX_SPECIFIC_BASE 1024
#endif
#ifndef MFD_ALLOW_SEALING
#define MFD_ALLOW_SEALING 0x0002U
#endif
#ifndef F_ADD_SEALS
#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
#define F_SEAL_GROW 0x0004 /* prevent file from growing */
#define F_SEAL_WRITE 0x0008 /* prevent writes */
#endif
#endif /* RTE_ETH_MEMIF_H */

View File

@ -0,0 +1,4 @@
DPDK_19.08 {
local: *;
};

View File

@ -24,6 +24,7 @@ drivers = ['af_packet',
'ixgbe', 'ixgbe',
'kni', 'kni',
'liquidio', 'liquidio',
'memif',
'mlx4', 'mlx4',
'mlx5', 'mlx5',
'mvneta', 'mvneta',

View File

@ -171,6 +171,7 @@ ifeq ($(CONFIG_RTE_LIBRTE_KNI),y)
_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_KNI) += -lrte_pmd_kni _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_KNI) += -lrte_pmd_kni
endif endif
_LDLIBS-$(CONFIG_RTE_LIBRTE_LIO_PMD) += -lrte_pmd_lio _LDLIBS-$(CONFIG_RTE_LIBRTE_LIO_PMD) += -lrte_pmd_lio
_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_MEMIF) += -lrte_pmd_memif
_LDLIBS-$(CONFIG_RTE_LIBRTE_MLX4_PMD) += -lrte_pmd_mlx4 _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX4_PMD) += -lrte_pmd_mlx4
_LDLIBS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += -lrte_pmd_mlx5 -lmnl _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += -lrte_pmd_mlx5 -lmnl
ifeq ($(CONFIG_RTE_IBVERBS_LINK_DLOPEN),y) ifeq ($(CONFIG_RTE_IBVERBS_LINK_DLOPEN),y)