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 */ 18void 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 */ 30void 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 */ 44int 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 */ 52void 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 */ 63int memif_connect_server(struct rte_eth_dev *dev); 64 65 66/** 67 * If device is properly configured, send connection request. 68 * 69 * @param dev 70 * memif device 71 * @return 72 * - On success, zero. 73 * - On failure, a negative value. 74 */ 75int memif_connect_client(struct rte_eth_dev *dev); 76 77struct memif_socket_dev_list_elt { 78 TAILQ_ENTRY(memif_socket_dev_list_elt) next; 79 struct rte_eth_dev *dev; /**< pointer to device internals */ 80 char dev_name[RTE_ETH_NAME_MAX_LEN]; 81}; 82 83#define MEMIF_SOCKET_HASH_NAME "memif-sh" 84#define MEMIF_SOCKET_UN_SIZE \ 85 (sizeof(struct sockaddr_un) - offsetof(struct sockaddr_un, sun_path)) 86 87struct memif_socket { 88 struct rte_intr_handle *intr_handle; /**< interrupt handle */ 89 char filename[MEMIF_SOCKET_UN_SIZE]; /**< socket filename */ 90 91 TAILQ_HEAD(, memif_socket_dev_list_elt) dev_queue; 92 /**< Queue of devices using this socket */ 93 uint8_t listener; /**< if not zero socket is listener */ 94}; 95 96/* Control message queue. */ 97struct memif_msg_queue_elt { 98 memif_msg_t msg; /**< control message */ 99 TAILQ_ENTRY(memif_msg_queue_elt) next; 100 int fd; /**< fd to be sent to peer */ 101}; 102 103struct memif_control_channel { 104 struct rte_intr_handle *intr_handle; /**< interrupt handle */ 105 TAILQ_HEAD(, memif_msg_queue_elt) msg_queue; /**< control message queue */ 106 struct memif_socket *socket; /**< pointer to socket */ 107 struct rte_eth_dev *dev; /**< pointer to device */ 108}; 109 110#endif /* MEMIF_SOCKET_H */ 111