From: Dariusz Sosnowski <dsosnowski@nvidia.com>
To: Matan Azrad <matan@nvidia.com>,
Viacheslav Ovsiienko <viacheslavo@nvidia.com>,
Ori Kam <orika@nvidia.com>, Suanming Mou <suanmingm@nvidia.com>
Cc: <dev@dpdk.org>, Raslan Darawsheh <rasland@nvidia.com>
Subject: [PATCH 4/8] net/mlx5: add sysfs check for Multiport E-Switch
Date: Tue, 31 Oct 2023 16:27:29 +0200 [thread overview]
Message-ID: <20231031142733.2009166-5-dsosnowski@nvidia.com> (raw)
In-Reply-To: <20231031142733.2009166-1-dsosnowski@nvidia.com>
This patch implements checking if Multiport E-Switch is enabled
on a given PCI device, using sysfs Linux kernel interface.
This facility will be used in follow up commits,
which add support for such configuration to mlx5 PMD.
MLNX_OFED mlx5_core kernel module versions which support
Multiport E-Switch do not expose this configuration through Devlink,
but through sysfs interface.
If such a version is used, then Multiport E-Switch can be enabled
(or its state can be probed) through a sysfs file under path:
# <ifname> should be substituted with Linux interface name.
/sys/class/net/<ifname>/compat/devlink/lag_port_select_mode
Writing "multiport_esw" to this file enables Multiport E-Switch.
If "multiport_esw" is read from this file, then
Multiport E-Switch is enabled.
If this file does not exist or writing "multiport_esw" to this file,
raises an error, then Multiport E-Switch is not supported.
Signed-off-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
---
drivers/net/mlx5/linux/mlx5_os.c | 69 ++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c
index 2f08f2354e..7a656a7237 100644
--- a/drivers/net/mlx5/linux/mlx5_os.c
+++ b/drivers/net/mlx5/linux/mlx5_os.c
@@ -1931,6 +1931,75 @@ mlx5_device_bond_pci_match(const char *ibdev_name,
return pf;
}
+#define SYSFS_MPESW_PARAM_MAX_LEN 16
+
+static __rte_unused int
+mlx5_sysfs_esw_multiport_get(struct ibv_device *ibv, struct rte_pci_addr *pci_addr, int *enabled)
+{
+ int nl_rdma;
+ unsigned int n_ports;
+ unsigned int i;
+ int ret;
+
+ /* Provide correct value to have defined enabled state in case of an error. */
+ *enabled = 0;
+ nl_rdma = mlx5_nl_init(NETLINK_RDMA, 0);
+ if (nl_rdma < 0)
+ return nl_rdma;
+ n_ports = mlx5_nl_portnum(nl_rdma, ibv->name);
+ if (!n_ports) {
+ ret = -rte_errno;
+ goto close_nl_rdma;
+ }
+ for (i = 1; i <= n_ports; ++i) {
+ unsigned int ifindex;
+ char ifname[IF_NAMESIZE + 1];
+ struct rte_pci_addr if_pci_addr;
+ char mpesw[SYSFS_MPESW_PARAM_MAX_LEN + 1];
+ FILE *sysfs;
+ int n;
+
+ ifindex = mlx5_nl_ifindex(nl_rdma, ibv->name, i);
+ if (!ifindex)
+ continue;
+ if (!if_indextoname(ifindex, ifname))
+ continue;
+ MKSTR(sysfs_if_path, "/sys/class/net/%s", ifname);
+ if (mlx5_get_pci_addr(sysfs_if_path, &if_pci_addr))
+ continue;
+ if (pci_addr->domain != if_pci_addr.domain ||
+ pci_addr->bus != if_pci_addr.bus ||
+ pci_addr->devid != if_pci_addr.devid ||
+ pci_addr->function != if_pci_addr.function)
+ continue;
+ MKSTR(sysfs_mpesw_path,
+ "/sys/class/net/%s/compat/devlink/lag_port_select_mode", ifname);
+ sysfs = fopen(sysfs_mpesw_path, "r");
+ if (!sysfs)
+ continue;
+ n = fscanf(sysfs, "%" RTE_STR(SYSFS_MPESW_PARAM_MAX_LEN) "s", mpesw);
+ fclose(sysfs);
+ if (n != 1)
+ continue;
+ ret = 0;
+ if (strcmp(mpesw, "multiport_esw") == 0) {
+ *enabled = 1;
+ break;
+ }
+ *enabled = 0;
+ break;
+ }
+ if (i > n_ports) {
+ DRV_LOG(DEBUG, "Unable to get Multiport E-Switch state by sysfs.");
+ rte_errno = ENOENT;
+ ret = -rte_errno;
+ }
+
+close_nl_rdma:
+ close(nl_rdma);
+ return ret;
+}
+
/**
* Register a PCI device within bonding.
*
--
2.25.1
next prev parent reply other threads:[~2023-10-31 14:28 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-31 14:27 [PATCH 0/8] net/mlx5: add Multiport E-Switch support Dariusz Sosnowski
2023-10-31 14:27 ` [PATCH 1/8] net/mlx5/hws: fix leak in FT management Dariusz Sosnowski
2023-10-31 14:27 ` [PATCH 2/8] common/mlx5: fix controller index parsing Dariusz Sosnowski
2023-10-31 14:27 ` [PATCH 3/8] common/mlx5: add Netlink check for Multiport E-Switch Dariusz Sosnowski
2023-10-31 14:27 ` Dariusz Sosnowski [this message]
2023-10-31 16:09 ` [PATCH 4/8] net/mlx5: add sysfs " Stephen Hemminger
2023-10-31 17:37 ` Dariusz Sosnowski
2023-10-31 14:27 ` [PATCH 5/8] net/mlx5: add checking Multiport E-Switch state Dariusz Sosnowski
2023-10-31 14:27 ` [PATCH 6/8] net/mlx5: support port probing of Multiport E-Switch device Dariusz Sosnowski
2023-10-31 14:27 ` [PATCH 7/8] net/mlx5: sort port spawn data with uplink ports first Dariusz Sosnowski
2023-10-31 14:27 ` [PATCH 8/8] net/mlx5: add support for vport match selection Dariusz Sosnowski
2023-10-31 21:49 ` [PATCH 0/8] net/mlx5: add Multiport E-Switch support Raslan Darawsheh
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=20231031142733.2009166-5-dsosnowski@nvidia.com \
--to=dsosnowski@nvidia.com \
--cc=dev@dpdk.org \
--cc=matan@nvidia.com \
--cc=orika@nvidia.com \
--cc=rasland@nvidia.com \
--cc=suanmingm@nvidia.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).