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 DA838A0C46; Mon, 27 Sep 2021 16:58:52 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 42376410DA; Mon, 27 Sep 2021 16:58:15 +0200 (CEST) Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by mails.dpdk.org (Postfix) with ESMTP id D52F340E3C for ; Mon, 27 Sep 2021 15:36:20 +0200 (CEST) Received: by mail-pj1-f51.google.com with SMTP id h12so2113367pjj.1 for ; Mon, 27 Sep 2021 06:36:20 -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=q9PGoBLdjhciMRPyM+w/EEsmxr57HymS94kyY9DxHjY=; b=DUkch7/9tpI1O+g9iC6fVoMNn0B1YPSVSIO5lA2Gl7lAHPx3xGdJzJCxUqsyMJBP09 pfb4ZzW/iLrpQokJA0PScB3x1oZl8j5ff+Gd+XQPakl365RsN0hRN/VeDYzoLFypicVj 4Rb2JFmTxgHVSONeHsR8JZi7uqSKPUvU9249E= 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=q9PGoBLdjhciMRPyM+w/EEsmxr57HymS94kyY9DxHjY=; b=KikuHqR9fTL/K1wrHyvofPbLBHZCXSyp5RIWbbjUgge6vy/KZbS9CXbjy43sjsXTXy NZwje53disxXf/xMqSeVcKIULQJMtBTGPCqHYTtfQp5DsZPeAJp6T4pb9OC/zgdHHI88 L/YO5MIiza6c3LY52QRkc2DVdiYdcaKBsuZksRqTVRpU8FPWkW9BlSI5Ac3bqrAfSRgR LALNZjXwimjQR3ALchuUaA1Cq9OVcVA5eBABhKFuItCZjPOT0DnuleLN/2yPb/G7kL11 aDZqrqG2l6lvFOkgU6wtuTT20ZpCsdnh/f2wB0dr3nwe4fgADExBlWrljagyANqnlu6z uOmg== X-Gm-Message-State: AOAM533QQ1HGuw1hiZJehuhhVwwLGbYE8I+guHQUYB2/uJevPiBX5grN AXU9LuNDQT3Ew/kzn4/4bUhRxw== X-Google-Smtp-Source: ABdhPJyzl3wzZD9MljO4yNA+KhoQ84dazSHXmvcRQR0tBby99iz9Yx+h8ZOME3NRHBA+By4XBEv9pw== X-Received: by 2002:a17:90b:38c5:: with SMTP id nn5mr20035589pjb.139.1632749779960; Mon, 27 Sep 2021 06:36:19 -0700 (PDT) Received: from srikanth-ThinkPad-T450.domain.name ([223.178.22.200]) by smtp.gmail.com with ESMTPSA id t6sm17342274pfh.63.2021.09.27.06.36.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 06:36:19 -0700 (PDT) From: Srikanth Kaka To: Matan Azrad , Viacheslav Ovsiienko Cc: dev@dpdk.org, Vag Singh , Anand Thulasiram , Srikanth Kaka Date: Mon, 27 Sep 2021 19:04:37 +0530 Message-Id: <20210927133450.10653-7-srikanth.k@oneconvergence.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210927133450.10653-1-srikanth.k@oneconvergence.com> References: <20210927133450.10653-1-srikanth.k@oneconvergence.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Mon, 27 Sep 2021 16:58:07 +0200 Subject: [dpdk-dev] [PATCH 06/19] common/mlx5: define PF_INET socket 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 implementation, 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/mlx5_inet.c | 306 ++++++++++++++++++++++++ drivers/common/mlx5/freebsd/mlx5_inet.h | 75 ++++++ 2 files changed, 381 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/mlx5_inet.c b/drivers/common/mlx5/freebsd/mlx5_inet.c new file mode 100644 index 0000000000..5b21e7414e --- /dev/null +++ b/drivers/common/mlx5/freebsd/mlx5_inet.c @@ -0,0 +1,306 @@ +/* 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 = 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..1bbf4ffb47 --- /dev/null +++ b/drivers/common/mlx5/freebsd/mlx5_inet.h @@ -0,0 +1,75 @@ +/* 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" + + +/* VLAN netdev for VLAN workaround. */ +struct mlx5_nl_vlan_dev { + uint32_t refcnt; + uint32_t ifindex; /**< Own interface index. */ +}; + +/* + * Array of VLAN devices created on the base of VF + * used for workaround in virtual environments. + */ + +struct mlx5_nl_vlan_vmwa_context { + int nl_socket; + uint32_t vf_ifindex; + rte_spinlock_t sl; + struct mlx5_nl_vlan_dev vlan_dev[4096]; +}; + +__rte_internal +void mlx5_nl_vlan_vmwa_delete(struct mlx5_nl_vlan_vmwa_context *vmwa, + uint32_t ifindex); + +__rte_internal +uint32_t mlx5_nl_vlan_vmwa_create(struct mlx5_nl_vlan_vmwa_context *vmwa, + uint32_t ifindex, uint16_t tag); +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