From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 54ACBA0517; Wed, 10 Jun 2020 11:33:31 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A70692C60; Wed, 10 Jun 2020 11:33:07 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2078.outbound.protection.outlook.com [40.107.22.78]) by dpdk.org (Postfix) with ESMTP id 191302C02 for ; Wed, 10 Jun 2020 11:33:04 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OBN/W5h2WrF5AB0FSst46lUEdmn7lu6RCvXw2XxmfR4etJ7l5A2Tyj53Ux5GngT4i35aNdfEZ3NqoDwaND5ecuz3oPlVJHFMUVUJRihRUgYOjPy3eUvY1SGgyyvFEOyP3DskCMOdMBSEOYyrBHnXf0Sl/4V6wgKAnggOqHStDb4xUqIu/GpIPg7xmFgzoaZMViO3OtVeiO6UpR4Z91DDB0swph4Xjj8oNU3dU5qw8lCVSDz/rR3zgMlWIyqam+ZHM4/+lijNbHANZXGQIw9Uj5Zo8bX4BJzY8VgTEejgnof9MZclDnvWlCSFG4sVB7+cncwxEBauVZ/W/aDNxOgqyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Qg9JwF03aCIaaC4GDlxB3az0giTeOV75+s5Kh1VeG44=; b=NdrLkOa9xkwcIGPGmKGlq6RHQmTOH29a1AuiWLeAFbh7/9eEa/V4fjfAbWEmHa/e+Xh6cpq25NEwwbO6hHAyD4nIt1lOV3SVm2KE0uLEQ7ejgcgtZRLjRWS4/6Y9dELGjT3tFT6va0DARjSzBO4aGzxCnFZTwWOHm8iFIcCw+OZ5afMKQ/j030iSXCzGcka8qyR6+Gy4aEiEirQSvGDxRHWz7ZVxTFNcu44lLHnepnYHgMCwR8chrchsMwDpGBlFxsgYR0c+vgUGmzGERHJBSaA7RpQNcE3Lor6AJPZ9oOJ1WnwmKiT9CgUVpmJlN+jp2Tb+JFRFOeYs/3gtVM9X8g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=mellanox.com; dmarc=pass action=none header.from=mellanox.com; dkim=pass header.d=mellanox.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Qg9JwF03aCIaaC4GDlxB3az0giTeOV75+s5Kh1VeG44=; b=CDLIiclAvfZifbKZloBOh4dsU8Zb5x3ns23mblUjhMw6lewp72KO4GAAdBeXrcKFDrPsKxBPXSSFeQBlGaB8prqaV/XFwEkLuyZQnhvzPjvIxfO3u6AmA1hs5poDx71I/cSIw5Swzo8akFPwshdUiEjaDBTa4IYpnkng00MqcJo= Authentication-Results: dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=none action=none header.from=mellanox.com; Received: from AM0PR05MB4209.eurprd05.prod.outlook.com (2603:10a6:208:61::22) by AM0PR05MB4545.eurprd05.prod.outlook.com (2603:10a6:208:b9::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.20; Wed, 10 Jun 2020 09:33:03 +0000 Received: from AM0PR05MB4209.eurprd05.prod.outlook.com ([fe80::1068:89a9:41d3:b14a]) by AM0PR05MB4209.eurprd05.prod.outlook.com ([fe80::1068:89a9:41d3:b14a%3]) with mapi id 15.20.3066.023; Wed, 10 Jun 2020 09:33:03 +0000 From: Ophir Munk To: dev@dpdk.org, Matan Azrad , Raslan Darawsheh Cc: Ophir Munk Date: Wed, 10 Jun 2020 09:32:28 +0000 Message-Id: <20200610093233.23902-4-ophirmu@mellanox.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20200610093233.23902-1-ophirmu@mellanox.com> References: <20200610093233.23902-1-ophirmu@mellanox.com> Content-Type: text/plain X-ClientProxiedBy: MRXP264CA0003.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:15::15) To AM0PR05MB4209.eurprd05.prod.outlook.com (2603:10a6:208:61::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mellanox.com (37.142.13.130) by MRXP264CA0003.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:15::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.18 via Frontend Transport; Wed, 10 Jun 2020 09:33:02 +0000 X-Mailer: git-send-email 2.8.4 X-Originating-IP: [37.142.13.130] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9b1e5564-5fa1-4e70-dc0c-08d80d2145ac X-MS-TrafficTypeDiagnostic: AM0PR05MB4545: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtFwd X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:79; X-Forefront-PRVS: 0430FA5CB7 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GiPPnutqqAC5mVVElEKVRyAPSwruKFjDtPdkooqSF5xw8Dew/psw6Ctp1sAN5NEwzf96W6/A25xMsoF9xK2R9COgSIcU+8WL+elcAFKD0Tmwb90MyXPGaRlnkwEJn7CZELvaT07fxyPYJKcyrYi/ltD8s+C+IIunq1LN62JQv1FUzll/OvXY8J/IhC2JDoM184yetBBv/x3npM8MjnimO07y8z4poGewbVGxJNzfzuvwWtzqQX/EwjYNBl13cTBQAuQuYNHDUUP+ZEsxldB4a7pat+hQOTHHHT6DNNMkgmeMqva+UNBeDekj8S9iDqSOxI/rMqhJ1URJsM32xnGvig== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR05MB4209.eurprd05.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(346002)(376002)(39860400002)(396003)(366004)(136003)(6666004)(478600001)(26005)(186003)(8676002)(5660300002)(8886007)(66476007)(66556008)(36756003)(66946007)(2906002)(956004)(2616005)(55016002)(52116002)(7696005)(8936002)(6636002)(110136005)(1076003)(16526019)(83380400001)(316002)(30864003)(86362001)(107886003)(4326008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: lQSUx11Fz8m1N1rmLvwazkesnLPx8mo/7jZduXC4plkzPZDnpsx98MY3abhewCD/WEfT7yU3TCOiXLzeRNzPQHiLqCbWAta8U55zyU0zditWqWPETMJcys0u7s3+1AGsTgzi2CelDbIKsPi9CwkV9HtGYgNxcXrbVoS6/ba2w9QQw4ijE/dq6K0os6K7UEk/951zWVWjjieAdh6K8EI/aSAdq3UE7mW0CV51Q15aM5hRGlqFS6sO2JP4U9VCSIHik75ppO2999XQmIlC2EmNaU13nUjfBfTSwwwAORCjUaTx1oCD9pILY1dljxAb32myC9d9g7VfoLNIEwbmSZ1r9OyfoUn4XZ/AOPmJMsN2ZTE5zHQkMEtzK1Y6QyvS1obtSNN2KRr+oDiwunICP9yaz1bNcYtdZ9JsT7PtGFtfGNa8jw8ScCebbDDC3d11qbakKpI05c8xPNDQiCRD+JszoevaIvqRZLlEKCwStvBJGF1YWgjRtxMLpID1cmnlwzEZ X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9b1e5564-5fa1-4e70-dc0c-08d80d2145ac X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2020 09:33:03.1490 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ABHg448rfWkgQ7mDMNnQN0BUyHVdxtOMed5TAi8VHAm2FFUj2gTilbMJ4K8vrNIE7P07kdtIZGhQZnh/RUmEyg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB4545 Subject: [dpdk-dev] [PATCH v1 3/8] net/mlx5: move socket files under Linux directory X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" mlx5_socket.c file is using APIs which are Linux specifics. Therefore move it (including mlx5_socket.h) from net/mlx5 directory to net/mlx5/linux directory. This commit also updates the Makefile and the meson files. Signed-off-by: Ophir Munk --- drivers/net/mlx5/Makefile | 2 +- drivers/net/mlx5/linux/meson.build | 1 + drivers/net/mlx5/linux/mlx5_socket.c | 230 +++++++++++++++++++++++++++++++++++ drivers/net/mlx5/meson.build | 1 - drivers/net/mlx5/mlx5_socket.c | 230 ----------------------------------- 5 files changed, 232 insertions(+), 232 deletions(-) create mode 100644 drivers/net/mlx5/linux/mlx5_socket.c delete mode 100644 drivers/net/mlx5/mlx5_socket.c diff --git a/drivers/net/mlx5/Makefile b/drivers/net/mlx5/Makefile index 41ab73e..84fc9cc 100644 --- a/drivers/net/mlx5/Makefile +++ b/drivers/net/mlx5/Makefile @@ -31,7 +31,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_flow_dv.c SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_flow_verbs.c SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_mp.c SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_utils.c -SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_socket.c +SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += linux/mlx5_socket.c SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += linux/mlx5_os.c # Basic CFLAGS. diff --git a/drivers/net/mlx5/linux/meson.build b/drivers/net/mlx5/linux/meson.build index 2ea0792..f8369cc 100644 --- a/drivers/net/mlx5/linux/meson.build +++ b/drivers/net/mlx5/linux/meson.build @@ -3,6 +3,7 @@ includes += include_directories('.') sources += files( + 'mlx5_socket.c', 'mlx5_os.c', ) diff --git a/drivers/net/mlx5/linux/mlx5_socket.c b/drivers/net/mlx5/linux/mlx5_socket.c new file mode 100644 index 0000000..08af905 --- /dev/null +++ b/drivers/net/mlx5/linux/mlx5_socket.c @@ -0,0 +1,230 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2019 Mellanox Technologies, Ltd + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include "rte_eal.h" +#include "mlx5_utils.h" +#include "mlx5.h" + +/* PMD socket service for tools. */ + +int server_socket; /* Unix socket for primary process. */ +struct rte_intr_handle server_intr_handle; /* Interrupt handler. */ + +static void +mlx5_pmd_make_path(struct sockaddr_un *addr, int pid) +{ + snprintf(addr->sun_path, sizeof(addr->sun_path), "/var/tmp/dpdk_%s_%d", + MLX5_DRIVER_NAME, pid); +} + +/** + * Handle server pmd socket interrupts. + */ +static void +mlx5_pmd_socket_handle(void *cb __rte_unused) +{ + int conn_sock; + int ret; + struct cmsghdr *cmsg = NULL; + int data; + char buf[CMSG_SPACE(sizeof(int))] = { 0 }; + struct iovec io = { + .iov_base = &data, + .iov_len = sizeof(data), + }; + struct msghdr msg = { + .msg_iov = &io, + .msg_iovlen = 1, + .msg_control = buf, + .msg_controllen = sizeof(buf), + }; + uint16_t port_id; + int fd; + FILE *file = NULL; + struct rte_eth_dev *dev; + + /* Accept the connection from the client. */ + conn_sock = accept(server_socket, NULL, NULL); + if (conn_sock < 0) { + DRV_LOG(WARNING, "connection failed: %s", strerror(errno)); + return; + } + ret = recvmsg(conn_sock, &msg, MSG_WAITALL); + if (ret < 0) { + 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 || + cmsg->cmsg_len < sizeof(int)) { + DRV_LOG(WARNING, "invalid file descriptor message"); + goto error; + } + memcpy(&fd, CMSG_DATA(cmsg), sizeof(fd)); + file = fdopen(fd, "w"); + if (!file) { + DRV_LOG(WARNING, "Failed to open file"); + goto error; + } + /* Receive port number. */ + if (msg.msg_iovlen != 1 || msg.msg_iov->iov_len < sizeof(uint16_t)) { + DRV_LOG(WARNING, "wrong port number message"); + goto error; + } + memcpy(&port_id, msg.msg_iov->iov_base, sizeof(port_id)); + 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); + /* 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; + do { + ret = sendmsg(conn_sock, &msg, 0); + } while (ret < 0 && errno == EINTR); + if (ret < 0) + DRV_LOG(WARNING, "failed to send response %s", + strerror(errno)); +error: + if (conn_sock >= 0) + close(conn_sock); + if (file) + fclose(file); +} + +/** + * Install interrupt handler. + * + * @param dev + * Pointer to Ethernet device. + * @return + * 0 on success, a negative errno value otherwise. + */ +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_pmd_socket_handle, NULL); +} + +/** + * Uninstall interrupt handler. + */ +static void +mlx5_pmd_interrupt_handler_uninstall(void) +{ + if (server_socket) { + 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; +} + +/** + * Initialise the socket to communicate with the secondary process + * + * @param[in] dev + * Pointer to Ethernet device. + * + * @return + * 0 on success, a negative value otherwise. + */ +int +mlx5_pmd_socket_init(void) +{ + struct sockaddr_un sun = { + .sun_family = AF_UNIX, + }; + int ret; + int flags; + + MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); + if (server_socket) + 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", + strerror(errno)); + goto error; + } + server_socket = ret; + flags = fcntl(server_socket, F_GETFL, 0); + if (flags == -1) + goto error; + ret = fcntl(server_socket, F_SETFL, flags | O_NONBLOCK); + if (ret < 0) + goto error; + mlx5_pmd_make_path(&sun, getpid()); + remove(sun.sun_path); + ret = bind(server_socket, (const struct sockaddr *)&sun, sizeof(sun)); + if (ret < 0) { + DRV_LOG(WARNING, + "cannot bind mlx5 socket: %s", strerror(errno)); + goto close; + } + ret = listen(server_socket, 0); + if (ret < 0) { + DRV_LOG(WARNING, "cannot listen on mlx5 socket: %s", + strerror(errno)); + goto close; + } + if (mlx5_pmd_interrupt_handler_install()) { + DRV_LOG(WARNING, "cannot register interrupt handler for mlx5 socket: %s", + strerror(errno)); + goto close; + } + return 0; +close: + remove(sun.sun_path); +error: + claim_zero(close(server_socket)); + server_socket = 0; + DRV_LOG(ERR, "Cannot initialize socket: %s", strerror(errno)); + return -errno; +} + +/** + * Un-Initialize the pmd socket + */ +RTE_FINI(mlx5_pmd_socket_uninit) +{ + if (!server_socket) + return; + mlx5_pmd_interrupt_handler_uninstall(); + claim_zero(close(server_socket)); + server_socket = 0; + MKSTR(path, "/var/tmp/dpdk_%s_%d", MLX5_DRIVER_NAME, getpid()); + claim_zero(remove(path)); +} diff --git a/drivers/net/mlx5/meson.build b/drivers/net/mlx5/meson.build index e71b2c5..e95ce02 100644 --- a/drivers/net/mlx5/meson.build +++ b/drivers/net/mlx5/meson.build @@ -28,7 +28,6 @@ sources = files( 'mlx5_txq.c', 'mlx5_vlan.c', 'mlx5_utils.c', - 'mlx5_socket.c', ) if (dpdk_conf.has('RTE_ARCH_X86_64') or dpdk_conf.has('RTE_ARCH_ARM64') diff --git a/drivers/net/mlx5/mlx5_socket.c b/drivers/net/mlx5/mlx5_socket.c deleted file mode 100644 index 08af905..0000000 --- a/drivers/net/mlx5/mlx5_socket.c +++ /dev/null @@ -1,230 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright 2019 Mellanox Technologies, Ltd - */ - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include -#include -#include -#include -#include -#include -#include - -#include "rte_eal.h" -#include "mlx5_utils.h" -#include "mlx5.h" - -/* PMD socket service for tools. */ - -int server_socket; /* Unix socket for primary process. */ -struct rte_intr_handle server_intr_handle; /* Interrupt handler. */ - -static void -mlx5_pmd_make_path(struct sockaddr_un *addr, int pid) -{ - snprintf(addr->sun_path, sizeof(addr->sun_path), "/var/tmp/dpdk_%s_%d", - MLX5_DRIVER_NAME, pid); -} - -/** - * Handle server pmd socket interrupts. - */ -static void -mlx5_pmd_socket_handle(void *cb __rte_unused) -{ - int conn_sock; - int ret; - struct cmsghdr *cmsg = NULL; - int data; - char buf[CMSG_SPACE(sizeof(int))] = { 0 }; - struct iovec io = { - .iov_base = &data, - .iov_len = sizeof(data), - }; - struct msghdr msg = { - .msg_iov = &io, - .msg_iovlen = 1, - .msg_control = buf, - .msg_controllen = sizeof(buf), - }; - uint16_t port_id; - int fd; - FILE *file = NULL; - struct rte_eth_dev *dev; - - /* Accept the connection from the client. */ - conn_sock = accept(server_socket, NULL, NULL); - if (conn_sock < 0) { - DRV_LOG(WARNING, "connection failed: %s", strerror(errno)); - return; - } - ret = recvmsg(conn_sock, &msg, MSG_WAITALL); - if (ret < 0) { - 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 || - cmsg->cmsg_len < sizeof(int)) { - DRV_LOG(WARNING, "invalid file descriptor message"); - goto error; - } - memcpy(&fd, CMSG_DATA(cmsg), sizeof(fd)); - file = fdopen(fd, "w"); - if (!file) { - DRV_LOG(WARNING, "Failed to open file"); - goto error; - } - /* Receive port number. */ - if (msg.msg_iovlen != 1 || msg.msg_iov->iov_len < sizeof(uint16_t)) { - DRV_LOG(WARNING, "wrong port number message"); - goto error; - } - memcpy(&port_id, msg.msg_iov->iov_base, sizeof(port_id)); - 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); - /* 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; - do { - ret = sendmsg(conn_sock, &msg, 0); - } while (ret < 0 && errno == EINTR); - if (ret < 0) - DRV_LOG(WARNING, "failed to send response %s", - strerror(errno)); -error: - if (conn_sock >= 0) - close(conn_sock); - if (file) - fclose(file); -} - -/** - * Install interrupt handler. - * - * @param dev - * Pointer to Ethernet device. - * @return - * 0 on success, a negative errno value otherwise. - */ -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_pmd_socket_handle, NULL); -} - -/** - * Uninstall interrupt handler. - */ -static void -mlx5_pmd_interrupt_handler_uninstall(void) -{ - if (server_socket) { - 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; -} - -/** - * Initialise the socket to communicate with the secondary process - * - * @param[in] dev - * Pointer to Ethernet device. - * - * @return - * 0 on success, a negative value otherwise. - */ -int -mlx5_pmd_socket_init(void) -{ - struct sockaddr_un sun = { - .sun_family = AF_UNIX, - }; - int ret; - int flags; - - MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); - if (server_socket) - 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", - strerror(errno)); - goto error; - } - server_socket = ret; - flags = fcntl(server_socket, F_GETFL, 0); - if (flags == -1) - goto error; - ret = fcntl(server_socket, F_SETFL, flags | O_NONBLOCK); - if (ret < 0) - goto error; - mlx5_pmd_make_path(&sun, getpid()); - remove(sun.sun_path); - ret = bind(server_socket, (const struct sockaddr *)&sun, sizeof(sun)); - if (ret < 0) { - DRV_LOG(WARNING, - "cannot bind mlx5 socket: %s", strerror(errno)); - goto close; - } - ret = listen(server_socket, 0); - if (ret < 0) { - DRV_LOG(WARNING, "cannot listen on mlx5 socket: %s", - strerror(errno)); - goto close; - } - if (mlx5_pmd_interrupt_handler_install()) { - DRV_LOG(WARNING, "cannot register interrupt handler for mlx5 socket: %s", - strerror(errno)); - goto close; - } - return 0; -close: - remove(sun.sun_path); -error: - claim_zero(close(server_socket)); - server_socket = 0; - DRV_LOG(ERR, "Cannot initialize socket: %s", strerror(errno)); - return -errno; -} - -/** - * Un-Initialize the pmd socket - */ -RTE_FINI(mlx5_pmd_socket_uninit) -{ - if (!server_socket) - return; - mlx5_pmd_interrupt_handler_uninstall(); - claim_zero(close(server_socket)); - server_socket = 0; - MKSTR(path, "/var/tmp/dpdk_%s_%d", MLX5_DRIVER_NAME, getpid()); - claim_zero(remove(path)); -} -- 2.8.4