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