net/memif: introduce memory interface PMD
[dpdk.git] / drivers / net / memif / memif_socket.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2018-2019 Cisco Systems, Inc.  All rights reserved.
3  */
4
5 #ifndef _MEMIF_SOCKET_H_
6 #define _MEMIF_SOCKET_H_
7
8 #include <sys/queue.h>
9
10 /**
11  * Remove device from socket device list. If no device is left on the socket,
12  * remove the socket as well.
13  *
14  * @param dev
15  *   memif device
16  */
17 void memif_socket_remove_device(struct rte_eth_dev *dev);
18
19 /**
20  * Enqueue disconnect message to control channel message queue.
21  *
22  * @param cc
23  *   control channel
24  * @param reason
25  *   const string stating disconnect reason (96 characters)
26  * @param err_code
27  *   error code
28  */
29 void memif_msg_enq_disconnect(struct memif_control_channel *cc, const char *reason,
30                               int err_code);
31
32 /**
33  * Initialize memif socket for specified device. If socket doesn't exist, create socket.
34  *
35  * @param dev
36  *   memif device
37  * @param socket_filename
38  *   socket filename
39  * @return
40  *   - On success, zero.
41  *   - On failure, a negative value.
42  */
43 int memif_socket_init(struct rte_eth_dev *dev, const char *socket_filename);
44
45 /**
46  * Disconnect memif device. Close control channel and shared memory.
47  *
48  * @param dev
49  *   memif device
50  */
51 void memif_disconnect(struct rte_eth_dev *dev);
52
53 /**
54  * If device is properly configured, enable connection establishment.
55  *
56  * @param dev
57  *   memif device
58  * @return
59  *   - On success, zero.
60  *   - On failure, a negative value.
61  */
62 int memif_connect_master(struct rte_eth_dev *dev);
63
64 /**
65  * If device is properly configured, send connection request.
66  *
67  * @param dev
68  *   memif device
69  * @return
70  *   - On success, zero.
71  *   - On failure, a negative value.
72  */
73 int memif_connect_slave(struct rte_eth_dev *dev);
74
75 struct memif_socket_dev_list_elt {
76         TAILQ_ENTRY(memif_socket_dev_list_elt) next;
77         struct rte_eth_dev *dev;                /**< pointer to device internals */
78         char dev_name[RTE_ETH_NAME_MAX_LEN];
79 };
80
81 #define MEMIF_SOCKET_HASH_NAME                  "memif-sh"
82 struct memif_socket {
83         struct rte_intr_handle intr_handle;     /**< interrupt handle */
84         char filename[256];                     /**< socket filename */
85
86         TAILQ_HEAD(, memif_socket_dev_list_elt) dev_queue;
87         /**< Queue of devices using this socket */
88         uint8_t listener;                       /**< if not zero socket is listener */
89 };
90
91 /* Control message queue. */
92 struct memif_msg_queue_elt {
93         memif_msg_t msg;                        /**< control message */
94         TAILQ_ENTRY(memif_msg_queue_elt) next;
95         int fd;                                 /**< fd to be sent to peer */
96 };
97
98 struct memif_control_channel {
99         struct rte_intr_handle intr_handle;     /**< interrupt handle */
100         TAILQ_HEAD(, memif_msg_queue_elt) msg_queue; /**< control message queue */
101         struct memif_socket *socket;            /**< pointer to socket */
102         struct rte_eth_dev *dev;                /**< pointer to device */
103 };
104
105 #endif                          /* MEMIF_SOCKET_H */