DPDK patches and discussions
 help / color / mirror / Atom feed
From: Srikanth Kaka <srikanth.k@oneconvergence.com>
To: Matan Azrad <matan@nvidia.com>,
	Viacheslav Ovsiienko <viacheslavo@nvidia.com>
Cc: dev@dpdk.org, Vag Singh <vag.singh@oneconvergence.com>,
	Anand Thulasiram <avelu@juniper.net>,
	Srikanth Kaka <srikanth.k@oneconvergence.com>
Subject: [dpdk-dev] [PATCH 06/19] common/mlx5: define PF_INET socket
Date: Mon, 27 Sep 2021 19:04:37 +0530	[thread overview]
Message-ID: <20210927133450.10653-7-srikanth.k@oneconvergence.com> (raw)
In-Reply-To: <20210927133450.10653-1-srikanth.k@oneconvergence.com>

Similar to NETLINK ROUTE socket in Linux implementation, PF_INET sockets
are used to communicate with FreeBSD network stack

Signed-off-by: Srikanth Kaka <srikanth.k@oneconvergence.com>
Signed-off-by: Vag Singh <vag.singh@oneconvergence.com>
Signed-off-by: Anand Thulasiram <avelu@juniper.net>
---
 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 <sys/ioctl.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <net/if_types.h>
+#include <err.h>
+#include <errno.h>
+
+#include <rte_errno.h>
+
+#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 <net/if.h>
+#include <netinet/in.h>
+
+#include <rte_ether.h>
+
+#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


  parent reply	other threads:[~2021-09-27 14:58 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-27 13:34 [dpdk-dev] [PATCH 00/19] MLX5 FreeBSD support Srikanth Kaka
2021-09-27 13:34 ` [dpdk-dev] [PATCH 01/19] common/mlx5: stub for FreeBSD Srikanth Kaka
2021-09-27 13:34 ` [dpdk-dev] [PATCH 02/19] net/mlx5: " Srikanth Kaka
2021-09-27 13:34 ` [dpdk-dev] [PATCH 03/19] common/mlx5: disabling auxiliary bus support Srikanth Kaka
2021-09-27 13:34 ` [dpdk-dev] [PATCH 04/19] net/mlx5: " Srikanth Kaka
2021-09-27 13:34 ` [dpdk-dev] [PATCH 05/19] net/mlx5: modified PCI probe to work on FreeBSD Srikanth Kaka
2021-09-27 13:34 ` Srikanth Kaka [this message]
2021-09-27 13:34 ` [dpdk-dev] [PATCH 07/19] net/mlx5: use the newly defined INET socket Srikanth Kaka
2021-09-27 13:34 ` [dpdk-dev] [PATCH 08/19] common/mlx5: derive PCI addr in FreeBSD Srikanth Kaka
2021-09-27 13:34 ` [dpdk-dev] [PATCH 09/19] common/mlx5: get interface name Srikanth Kaka
2021-09-27 13:34 ` [dpdk-dev] [PATCH 10/19] net/mlx5: fix socket MAC request Srikanth Kaka
2021-09-27 13:34 ` [dpdk-dev] [PATCH 11/19] net/mlx5: removing port representator support Srikanth Kaka
2021-09-27 13:34 ` [dpdk-dev] [PATCH 12/19] net/mlx5: Added procedure to detect link state Srikanth Kaka
2021-09-27 13:34 ` [dpdk-dev] [PATCH 13/19] net/mlx5: added placeholder for VLAN vmwa Srikanth Kaka
2021-09-27 13:34 ` [dpdk-dev] [PATCH 14/19] net/mlx5: added stats support Srikanth Kaka
2021-09-27 13:34 ` [dpdk-dev] [PATCH 15/19] net/mlx5: making flow control DPDK callback invalid Srikanth Kaka
2021-09-27 13:34 ` [dpdk-dev] [PATCH 16/19] net/mlx5: making module DPDK callbacks invalid Srikanth Kaka
2021-09-27 13:34 ` [dpdk-dev] [PATCH 17/19] common/mlx5: fixed missing dependency in mlx5_glue.h Srikanth Kaka
2021-09-27 13:34 ` [dpdk-dev] [PATCH 18/19] net/mlx5: fixed compilation warnings Srikanth Kaka
2021-09-27 13:34 ` [dpdk-dev] [PATCH 19/19] mlx5: Added meson support for FreeBSD Srikanth Kaka
2021-09-29 12:20 ` [dpdk-dev] [PATCH 00/19] MLX5 FreeBSD support Thomas Monjalon
2021-09-29 15:56   ` Srikanth K
2021-09-29 16:20     ` Thomas Monjalon
2021-09-30 16:27       ` Srikanth K
2021-09-30 16:55         ` Thomas Monjalon
2021-10-01 11:35           ` Srikanth K

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210927133450.10653-7-srikanth.k@oneconvergence.com \
    --to=srikanth.k@oneconvergence.com \
    --cc=avelu@juniper.net \
    --cc=dev@dpdk.org \
    --cc=matan@nvidia.com \
    --cc=vag.singh@oneconvergence.com \
    --cc=viacheslavo@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).