* Copyright 2019 Mellanox Technologies, Ltd
*/
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#define MLX5_SOCKET_PATH "/var/tmp/dpdk_net_mlx5_%d"
-int server_socket; /* Unix socket for primary process. */
-struct rte_intr_handle server_intr_handle; /* Interrupt handler. */
+int server_socket = -1; /* Unix socket for primary process. */
+struct rte_intr_handle *server_intr_handle; /* Interrupt handler. */
/**
* Handle server pmd socket interrupts.
int conn_sock;
int ret;
struct cmsghdr *cmsg = NULL;
- int data;
- char buf[CMSG_SPACE(sizeof(int))] = { 0 };
+ uint32_t data[MLX5_SENDMSG_MAX / sizeof(uint32_t)];
+ uint64_t flow_ptr = 0;
+ uint8_t buf[CMSG_SPACE(sizeof(int))] = { 0 };
struct iovec io = {
- .iov_base = &data,
+ .iov_base = data,
.iov_len = sizeof(data),
};
struct msghdr msg = {
.msg_control = buf,
.msg_controllen = sizeof(buf),
};
- uint16_t port_id;
+
+ uint32_t port_id;
int fd;
FILE *file = NULL;
struct rte_eth_dev *dev;
+ struct rte_flow_error err;
+ struct mlx5_flow_dump_req *dump_req;
+ struct mlx5_flow_dump_ack *dump_ack;
+ memset(data, 0, sizeof(data));
/* Accept the connection from the client. */
conn_sock = accept(server_socket, NULL, NULL);
if (conn_sock < 0) {
return;
}
ret = recvmsg(conn_sock, &msg, MSG_WAITALL);
- if (ret < 0) {
+ if (ret != sizeof(struct mlx5_flow_dump_req)) {
DRV_LOG(WARNING, "wrong message received: %s",
strerror(errno));
goto error;
}
+
/* Receive file descriptor. */
cmsg = CMSG_FIRSTHDR(&msg);
if (cmsg == NULL || cmsg->cmsg_type != SCM_RIGHTS ||
DRV_LOG(WARNING, "wrong port number message");
goto error;
}
- memcpy(&port_id, msg.msg_iov->iov_base, sizeof(port_id));
+
+ dump_req = (struct mlx5_flow_dump_req *)msg.msg_iov->iov_base;
+ if (dump_req) {
+ port_id = dump_req->port_id;
+ flow_ptr = dump_req->flow_id;
+ } else {
+ DRV_LOG(WARNING, "Invalid message");
+ goto error;
+ }
+
if (!rte_eth_dev_is_valid_port(port_id)) {
DRV_LOG(WARNING, "Invalid port %u", port_id);
goto error;
}
+
/* Dump flow. */
dev = &rte_eth_devices[port_id];
- ret = mlx5_flow_dev_dump(dev, file, NULL);
+ if (flow_ptr == 0)
+ ret = mlx5_flow_dev_dump(dev, NULL, file, NULL);
+ else
+ ret = mlx5_flow_dev_dump(dev,
+ (struct rte_flow *)((uintptr_t)flow_ptr), file, &err);
+
/* Set-up the ancillary data and reply. */
msg.msg_controllen = 0;
msg.msg_control = NULL;
msg.msg_iovlen = 1;
msg.msg_iov = &io;
- data = -ret;
- io.iov_len = sizeof(data);
- io.iov_base = &data;
+ dump_ack = (struct mlx5_flow_dump_ack *)data;
+ dump_ack->rc = -ret;
+ io.iov_len = sizeof(struct mlx5_flow_dump_ack);
+ io.iov_base = dump_ack;
do {
ret = sendmsg(conn_sock, &msg, 0);
} while (ret < 0 && errno == EINTR);
static int
mlx5_pmd_interrupt_handler_install(void)
{
- MLX5_ASSERT(server_socket);
- server_intr_handle.fd = server_socket;
- server_intr_handle.type = RTE_INTR_HANDLE_EXT;
- return rte_intr_callback_register(&server_intr_handle,
+ MLX5_ASSERT(server_socket != -1);
+
+ server_intr_handle =
+ rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
+ if (server_intr_handle == NULL) {
+ DRV_LOG(ERR, "Fail to allocate intr_handle");
+ return -ENOMEM;
+ }
+ if (rte_intr_fd_set(server_intr_handle, server_socket))
+ return -rte_errno;
+
+ if (rte_intr_type_set(server_intr_handle, RTE_INTR_HANDLE_EXT))
+ return -rte_errno;
+
+ return rte_intr_callback_register(server_intr_handle,
mlx5_pmd_socket_handle, NULL);
}
static void
mlx5_pmd_interrupt_handler_uninstall(void)
{
- if (server_socket) {
- mlx5_intr_callback_unregister(&server_intr_handle,
+ if (server_socket != -1) {
+ mlx5_intr_callback_unregister(server_intr_handle,
mlx5_pmd_socket_handle,
NULL);
}
- server_intr_handle.fd = 0;
- server_intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+ rte_intr_fd_set(server_intr_handle, 0);
+ rte_intr_type_set(server_intr_handle, RTE_INTR_HANDLE_UNKNOWN);
+ rte_intr_instance_free(server_intr_handle);
}
/**
- * Initialise the socket to communicate with the secondary process
- *
- * @param[in] dev
- * Pointer to Ethernet device.
+ * Initialise the socket to communicate with external tools.
*
* @return
* 0 on success, a negative value otherwise.
int flags;
MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
- if (server_socket)
+ if (server_socket != -1)
return 0;
- /*
- * Initialize the socket to communicate with the secondary
- * process.
- */
ret = socket(AF_UNIX, SOCK_STREAM, 0);
if (ret < 0) {
DRV_LOG(WARNING, "Failed to open mlx5 socket: %s",
server_socket = ret;
flags = fcntl(server_socket, F_GETFL, 0);
if (flags == -1)
- goto error;
+ goto close;
ret = fcntl(server_socket, F_SETFL, flags | O_NONBLOCK);
if (ret < 0)
- goto error;
+ goto close;
snprintf(sun.sun_path, sizeof(sun.sun_path), MLX5_SOCKET_PATH,
getpid());
remove(sun.sun_path);
if (ret < 0) {
DRV_LOG(WARNING,
"cannot bind mlx5 socket: %s", strerror(errno));
- goto close;
+ goto remove;
}
ret = listen(server_socket, 0);
if (ret < 0) {
DRV_LOG(WARNING, "cannot listen on mlx5 socket: %s",
strerror(errno));
- goto close;
+ goto remove;
}
if (mlx5_pmd_interrupt_handler_install()) {
DRV_LOG(WARNING, "cannot register interrupt handler for mlx5 socket: %s",
strerror(errno));
- goto close;
+ goto remove;
}
return 0;
-close:
+remove:
remove(sun.sun_path);
-error:
+close:
claim_zero(close(server_socket));
- server_socket = 0;
+ server_socket = -1;
+error:
DRV_LOG(ERR, "Cannot initialize socket: %s", strerror(errno));
return -errno;
}
/**
* Un-Initialize the pmd socket
*/
-RTE_FINI(mlx5_pmd_socket_uninit)
+void
+mlx5_pmd_socket_uninit(void)
{
- if (!server_socket)
+ if (server_socket == -1)
return;
mlx5_pmd_interrupt_handler_uninstall();
claim_zero(close(server_socket));
- server_socket = 0;
+ server_socket = -1;
MKSTR(path, MLX5_SOCKET_PATH, getpid());
claim_zero(remove(path));
}