From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1DF84A034F; Fri, 8 Oct 2021 12:57:23 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7866B41184; Fri, 8 Oct 2021 12:56:14 +0200 (CEST) Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by mails.dpdk.org (Postfix) with ESMTP id C2D0541217 for ; Thu, 7 Oct 2021 20:44:54 +0200 (CEST) Received: by mail-pl1-f180.google.com with SMTP id y1so4464876plk.10 for ; Thu, 07 Oct 2021 11:44:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oneconvergence.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Z/GCr1Gmrqb47FTOGlulB/mWkM38APJNgJ3L24MfYFE=; b=gsqCoTNuo0oA9Liu3YrFX98hRfapxF3aQspzpnh0ofmGLFDpGP5grQSRSK3SKNkMJD o7qIB3YHPpRvf5Qeyvzwk4O1OW9NmWSKG7Z0vYlxsjndPrZSv3BwqgsdXj/xMk89dfnc ArSqkMHx5Jfgs/uHy0Gb7/Yp+/6UxqNrRxIOc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z/GCr1Gmrqb47FTOGlulB/mWkM38APJNgJ3L24MfYFE=; b=K8BP8K9yJshts5CeE/8rDWGhxzpD5vNBAvz2iy7az+IT9aHInF9R68K6i5+/KRqBqK rlJhGTrUULeInlLJO4HK3TW01eFl6CJ8tbc/Pu/4el6muYFx3ERjCAJhO8+8qmA7T/wL vwRSs3D99zoWuy567N4Zr2sS+8obWupJR0JZtVkNa6G0sge4KV0HN0N93bYdBEeLH36p CKziuVXt5QmjsgEQdzlTd0caQgHy9p1qjpS2uHLgAicZ4W+mcb8ofZ6Hg47pbyRg1nDB AGmo0tAtK+WrqeTUM4dIQ8b43vKXSArPX1NaEDLKSOaSDWJPoFtTcSKtFdF5LOCpqI3p hFjQ== X-Gm-Message-State: AOAM533Z3TliHo//xuWff25xTNSGPfRMt1b03C0HVblr6oYDe3R8FYSq ejxZzFgV8T7Vb8q1jlPZL40OvQ== X-Google-Smtp-Source: ABdhPJwwsC3GTJVqjq14CTR1wB795HTMAXyjZ4qz/GXqqtKfdSotHxXaviYrI/bIJBxaRyhzYLP/Tg== X-Received: by 2002:a17:90b:17d0:: with SMTP id me16mr7352936pjb.152.1633632293917; Thu, 07 Oct 2021 11:44:53 -0700 (PDT) Received: from srikanth-ThinkPad-T450.domain.name ([136.185.113.102]) by smtp.gmail.com with ESMTPSA id c11sm3311586pji.38.2021.10.07.11.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 11:44:53 -0700 (PDT) From: Srikanth Kaka To: Matan Azrad , Viacheslav Ovsiienko Cc: dev@dpdk.org, Vag Singh , Anand Thulasiram , Srikanth Kaka Date: Fri, 8 Oct 2021 00:13:24 +0530 Message-Id: <20211007184350.73858-16-srikanth.k@oneconvergence.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211007184350.73858-1-srikanth.k@oneconvergence.com> References: <20211007184350.73858-1-srikanth.k@oneconvergence.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Fri, 08 Oct 2021 12:55:54 +0200 Subject: [dpdk-dev] [PATCH v2 15/41] common/mlx5: add PF_INET socket interface X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" Similar to NETLINK ROUTE socket in Linux, PF_INET sockets are used to communicate with FreeBSD network stack Signed-off-by: Srikanth Kaka Signed-off-by: Vag Singh Signed-off-by: Anand Thulasiram --- drivers/common/mlx5/freebsd/meson.build | 1 + drivers/common/mlx5/freebsd/mlx5_inet.c | 308 ++++++++++++++++++++++++ drivers/common/mlx5/freebsd/mlx5_inet.h | 49 ++++ 3 files changed, 358 insertions(+) create mode 100644 drivers/common/mlx5/freebsd/mlx5_inet.c create mode 100644 drivers/common/mlx5/freebsd/mlx5_inet.h diff --git a/drivers/common/mlx5/freebsd/meson.build b/drivers/common/mlx5/freebsd/meson.build index 4112fdb155..bee2ce7861 100644 --- a/drivers/common/mlx5/freebsd/meson.build +++ b/drivers/common/mlx5/freebsd/meson.build @@ -31,6 +31,7 @@ if not cc.has_header('infiniband/mlx5dv.h') subdir_done() endif +sources += files('mlx5_inet.c') sources += files('mlx5_common_os.c') sources += files('mlx5_glue.c') sources += files('mlx5_common_verbs.c') diff --git a/drivers/common/mlx5/freebsd/mlx5_inet.c b/drivers/common/mlx5/freebsd/mlx5_inet.c new file mode 100644 index 0000000000..f721877256 --- /dev/null +++ b/drivers/common/mlx5/freebsd/mlx5_inet.c @@ -0,0 +1,308 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2018 Mellanox Technologies, Ltd + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "mlx5_inet.h" +#include "mlx5_common_log.h" +#include "mlx5_common_utils.h" +#include "mlx5_malloc.h" + +/** + * Check all multicast mode is enabled in driver through Socket. + * + * @param inetsk_fd + * Inet socket file descriptor. + * @param ifname + * ifname buffer of mlx5_get_ifname(dev, ifname) function. + * @param port_id + * port_id of the port . + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +int +mlx5_inet_check_allmulti_flag(int inetsk_fd, char *ifname, uint16_t port_id) +{ + struct ifreq ifr; + int value; + + if (inetsk_fd < 0) + return 0; + + memset(&ifr, 0, sizeof(ifr)); + (void)strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + + if (ioctl(inetsk_fd, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) + return -errno; + + value = (ifr.ifr_flags & 0xffff) | (ifr.ifr_flagshigh << 16); + if (!(value & IFF_ALLMULTI)) { + DRV_LOG(WARNING, + "port %u allmulti mode not enabled from kernel, " + "please disable it from DPDK", port_id); + return -1; + } + return 0; +} + +/** + * Enable promiscuous / all multicast mode through Socket. + * We make a copy of ifreq to avoid SIOCIGIFFLAGS overwriting on the union + * portion of the ifreq structure. + * + * @param inetsk_fd + * Inet socket file descriptor. + * @param ifname_output + * ifname buffer of mlx5_get_ifname(dev, ifname) function. + * @param flags + * IFF_PPROMISC for promiscuous, IFF_ALLMULTI for allmulti. + * @param enable + * Nonzero to enable, disable otherwise. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +int +mlx5_inet_device_flags(int inetsk_fd, char *ifname, int flags, int enable) +{ + struct ifreq ifr; + int value; + + assert(!(flags & ~(IFF_PPROMISC))); + if (inetsk_fd < 0) + return 0; + + memset(&ifr, 0, sizeof(ifr)); + (void)strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + + if (ioctl(inetsk_fd, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) + return -errno; + + value = (ifr.ifr_flags & 0xffff) | (ifr.ifr_flagshigh << 16); + if (enable) + value |= flags; + else + value &= ~flags; + + ifr.ifr_flags = value & 0xffff; + ifr.ifr_flagshigh = value >> 16; + + if (ioctl(inetsk_fd, SIOCSIFFLAGS, (caddr_t)&ifr) < 0) + return -errno; + + return 0; +} + +/** + * Enable promiscuous mode through INET Socket. + * + * @param inetsk_fd + * Inet socket file descriptor. + * @param ifname_output + * ifname buffer of mlx5_get_ifname(dev, ifname) function. + * @param enable + * Nonzero to enable, disable otherwise. + * @param port_id + * port_id of the interface + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +int +mlx5_inet_promisc(int inetsk_fd, char *ifname, int enable, uint16_t port_id) +{ + int ret; + + ret = mlx5_inet_device_flags(inetsk_fd, ifname, IFF_PPROMISC, enable); + if (ret) + DRV_LOG(DEBUG, + "port %u cannot %s promisc mode: Socket error %s", + port_id, enable ? "enable" : "disable", + strerror(rte_errno)); + return ret; +} + +/** + * Modify the MAC address neighbour table with INET Socket. + * + * @param inetsk_fd + * Inet socket file descriptor. + * @param ifname_output + * ifname buffer of mlx5_get_ifname(dev, ifname) function. + * @param mac + * MAC address to consider. + * @param port_id + * port_id of the interface + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +int +mlx5_inet_mac_addr_modify(int inetsk_fd, char *ifname, + struct rte_ether_addr *mac, uint16_t port_id) +{ + struct ifreq ifr; + + if (inetsk_fd < 0) + return 0; + + memset(&ifr, 0, sizeof(ifr)); + (void)strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + ifr.ifr_addr.sa_family = AF_LINK; + memcpy(ifr.ifr_addr.sa_data, mac, RTE_ETHER_ADDR_LEN); + ifr.ifr_addr.sa_len = RTE_ETHER_ADDR_LEN; + + if (ioctl(inetsk_fd, SIOCSIFLLADDR, &ifr) < 0) { + rte_errno = errno; + goto error; + } + + return 0; +error: + DRV_LOG(DEBUG, + "port %u cannot add MAC address %02X:%02X:%02X:%02X:%02X:%02X %s", + port_id, + mac->addr_bytes[0], mac->addr_bytes[1], + mac->addr_bytes[2], mac->addr_bytes[3], + mac->addr_bytes[4], mac->addr_bytes[5], + strerror(rte_errno)); + return -rte_errno; +} + +/** + * Set a MAC address. + * + * @param inetsk_fd + * Inet socket file descriptor. + * @param ifname_output + * ifname buffer of mlx5_get_ifname(dev, ifname) function. + * @param mac + * MAC address to register. + * @param index + * MAC address index. + * @param port_id + * port_id of the interface + * @param mac_own + * Current MAC address. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +int +mlx5_inet_mac_addr_set(int inetsk_fd, char *ifname, + struct rte_ether_addr *mac, uint32_t index, + uint16_t port_id, uint64_t *mac_own) +{ + int ret; + + ret = mlx5_inet_mac_addr_modify(inetsk_fd, ifname, mac, port_id); + if (!ret) + BITFIELD_SET(mac_own, index); + if (ret == -EEXIST) + return 0; + return ret; +} + +/** + * DPDK callback to add a MAC address. + * + * @param dev + * Pointer to Ethernet device structure. + * @param mac_addr + * MAC address to register. + * @param index + * MAC address index. + * @param vmdq + * VMDq pool index to associate address with (ignored). + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +int +mlx5_inet_mac_addr_add(struct rte_ether_addr *mac __rte_unused, + uint32_t index __rte_unused, + uint32_t vmdq __rte_unused, + uint16_t port_id) +{ + DRV_LOG(INFO, "port %u add MAC not supported in FreeBSD", + port_id); + return -EOPNOTSUPP; +} + +/** + * Before exiting, make interface LLADDR same as HWADDR + * + * @param inetsk_fd + * Inet socket file descriptor. + * @param ifname_output + * ifname buffer of mlx5_get_ifname(dev, ifname) function. + * @param lladdr + * @param port_id + * port_id of the interface + */ +void +mlx5_inet_mac_addr_flush(int inetsk_fd, char *ifname, + struct rte_ether_addr *lladdr, + uint16_t port_id) +{ + struct ifreq ifr; + + if (inetsk_fd < 0) + return; + + memset(&ifr, 0, sizeof(ifr)); + (void)strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + ifr.ifr_addr.sa_family = AF_LINK; + + if (ioctl(inetsk_fd, SIOCGHWADDR, &ifr) < 0) + return; + + if (memcmp(ifr.ifr_addr.sa_data, lladdr, RTE_ETHER_ADDR_LEN) == 0) + return; + + mlx5_inet_mac_addr_modify(inetsk_fd, ifname, + (struct rte_ether_addr *)&ifr.ifr_addr.sa_data, + port_id); +} + +/** + * Remove a MAC address. + * + * @param mac + * MAC address to remove. + * @param index + * MAC address index. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +void +mlx5_inet_mac_addr_remove(uint16_t port_id, uint32_t index __rte_unused) +{ + DRV_LOG(INFO, + "port %u cannot remove MAC. Operation not supported in FreeBSD", + port_id); +} + +/* No bind required on this socket as there are no incoming messages */ +int +mlx5_inet_init(void) +{ + int s; + + s = socket(PF_INET, SOCK_DGRAM, 0); + if (s < 0) { + rte_errno = errno; + return -rte_errno; + } + + return s; +} diff --git a/drivers/common/mlx5/freebsd/mlx5_inet.h b/drivers/common/mlx5/freebsd/mlx5_inet.h new file mode 100644 index 0000000000..cc6a05928e --- /dev/null +++ b/drivers/common/mlx5/freebsd/mlx5_inet.h @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2019 Mellanox Technologies, Ltd + */ + +#ifndef RTE_PMD_MLX5_INET_H_ +#define RTE_PMD_MLX5_INET_H_ + +#include +#include + +#include + +#include "mlx5_common.h" + +int +mlx5_inet_check_allmulti_flag(int inetsk_fd, char *ifname, uint16_t port_id); + +int +mlx5_inet_device_flags(int inetsk_fd, char *ifname, int flags, int enable); + +int +mlx5_inet_promisc(int inetsk_fd, char *ifname, int enable, uint16_t port_id); + +int +mlx5_inet_mac_addr_modify(int inetsk_fd, char *ifname, + struct rte_ether_addr *mac, uint16_t port_id); + +int +mlx5_inet_mac_addr_set(int inetsk_fd, char *ifname, + struct rte_ether_addr *mac, uint32_t index, + uint16_t port_id, uint64_t *mac_own); + +int +mlx5_inet_mac_addr_add(struct rte_ether_addr *mac __rte_unused, + uint32_t index __rte_unused, + uint32_t vmdq __rte_unused, + uint16_t port_id); + +void +mlx5_inet_mac_addr_flush(int inetsk_fd, char *ifname, + struct rte_ether_addr *lladdr, + uint16_t port_id); + +void +mlx5_inet_mac_addr_remove(uint16_t port_id, uint32_t index __rte_unused); + +int +mlx5_inet_init(void); +#endif /* RTE_PMD_MLX5_INET_H_ */ -- 2.30.2