From: Dekel Peled <dekelp@mellanox.com>
To: yskoh@mellanox.com, shahafs@mellanox.com
Cc: dev@dpdk.org, orika@mellanox.com, dekelp@mellanox.com
Subject: [dpdk-dev] [PATCH v5] net/mlx5: support new representor naming format
Date: Sun, 17 Mar 2019 08:23:03 +0200 [thread overview]
Message-ID: <1552803783-55056-1-git-send-email-dekelp@mellanox.com> (raw)
Message-ID: <20190317062303.X33dTvQYFZYfuvTTyw74Oyj79YuloWGQMuMElks1RGY@z> (raw)
In-Reply-To: <1552234001-49438-1-git-send-email-dekelp@mellanox.com>
Kernel update [1] introduce new format of representors names.
This patch implements RFC [2], updating MLX5 PMD to support the new
format, while maintaining support of the existing format.
[1] https://github.com/torvalds/linux/commit/c12ecc2
[2] http://mails.dpdk.org/archives/dev/2019-March/125676.html
Signed-off-by: Dekel Peled <dekelp@mellanox.com>
---
v5: Add flag to indicate if rep. port name is in new format.
v4: Remove redundant clear of errno.
v3: Add utility function with common logic, call it from sysfs and nl.
v2: Use public link to kernel patch, add link to RFC.
---
---
drivers/net/mlx5/mlx5.h | 3 +++
drivers/net/mlx5/mlx5_ethdev.c | 54 ++++++++++++++++++++++++++++++++++++++----
drivers/net/mlx5/mlx5_nl.c | 11 ++++-----
3 files changed, 57 insertions(+), 11 deletions(-)
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 5384453..88ffb19 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -60,6 +60,7 @@ enum {
struct mlx5_switch_info {
uint32_t master:1; /**< Master device. */
uint32_t representor:1; /**< Representor device. */
+ uint32_t port_name_new:1; /**< Rep. port name is in new format. */
int32_t port_name; /**< Representor port name. */
uint64_t switch_id; /**< Switch identifier. */
};
@@ -300,6 +301,8 @@ unsigned int mlx5_dev_to_port_id(const struct rte_device *dev,
unsigned int port_list_n);
int mlx5_sysfs_switch_info(unsigned int ifindex,
struct mlx5_switch_info *info);
+bool mlx5_translate_port_name(const char *port_name_in,
+ struct mlx5_switch_info *port_info_out);
/* mlx5_mac.c */
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index 795c9c7..428a465 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -1353,9 +1353,16 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size)
mlx5_sysfs_switch_info(unsigned int ifindex, struct mlx5_switch_info *info)
{
char ifname[IF_NAMESIZE];
+ char port_name[IF_NAMESIZE];
FILE *file;
DIR *dir;
- struct mlx5_switch_info data = { .master = 0, };
+ struct mlx5_switch_info data = {
+ .master = 0,
+ .representor = 0,
+ .port_name_new = 0,
+ .port_name = 0,
+ .switch_id = 0,
+ };
bool port_name_set = false;
bool port_switch_id_set = false;
bool device_dir = false;
@@ -1375,10 +1382,9 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size)
file = fopen(phys_port_name, "rb");
if (file != NULL) {
- port_name_set =
- fscanf(file, "%d%c", &data.port_name, &c) == 2 &&
- c == '\n';
+ fscanf(file, "%s", port_name);
fclose(file);
+ port_name_set = mlx5_translate_port_name(port_name, &data);
}
file = fopen(phys_switch_id, "rb");
if (file == NULL) {
@@ -1399,3 +1405,43 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size)
*info = data;
return 0;
}
+
+/**
+ * Extract port name, as a number, from sysfs or netlink information.
+ *
+ * @param[in] port_name_in
+ * String representing the port name.
+ * @param[out] port_info_out
+ * Port information, including port name as a number.
+ *
+ * @return
+ * true on success, false otherwise.
+ */
+bool
+mlx5_translate_port_name(const char *port_name_in,
+ struct mlx5_switch_info *port_info_out)
+{
+ char pf_c1, pf_c2, vf_c1, vf_c2;
+ char *end;
+ int32_t pf_num;
+ bool port_name_set = false;
+
+ /*
+ * Check for port-name as a string of the form pf0vf0
+ * (support kernel ver >= 5.0)
+ */
+ port_name_set = (sscanf(port_name_in, "%c%c%d%c%c%d", &pf_c1, &pf_c2,
+ &pf_num, &vf_c1, &vf_c2,
+ &port_info_out->port_name) == 6);
+ if (port_name_set) {
+ port_info_out->port_name_new = 1;
+ } else {
+ /* Check for port-name as a number (support kernel ver < 5.0 */
+ errno = 0;
+ port_info_out->port_name = strtol(port_name_in, &end, 0);
+ if (!errno &&
+ (size_t)(end - port_name_in) == strlen(port_name_in))
+ port_name_set = true;
+ }
+ return port_name_set;
+}
diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c
index 0bf6845..cb34de3 100644
--- a/drivers/net/mlx5/mlx5_nl.c
+++ b/drivers/net/mlx5/mlx5_nl.c
@@ -836,6 +836,7 @@ struct mlx5_nl_ifindex_data {
struct mlx5_switch_info info = {
.master = 0,
.representor = 0,
+ .port_name_new = 0,
.port_name = 0,
.switch_id = 0,
};
@@ -849,7 +850,6 @@ struct mlx5_nl_ifindex_data {
while (off < nh->nlmsg_len) {
struct rtattr *ra = (void *)((uintptr_t)nh + off);
void *payload = RTA_DATA(ra);
- char *end;
unsigned int i;
if (ra->rta_len > nh->nlmsg_len - off)
@@ -859,12 +859,9 @@ struct mlx5_nl_ifindex_data {
num_vf_set = true;
break;
case IFLA_PHYS_PORT_NAME:
- errno = 0;
- info.port_name = strtol(payload, &end, 0);
- if (errno ||
- (size_t)(end - (char *)payload) != strlen(payload))
- goto error;
- port_name_set = true;
+ port_name_set =
+ mlx5_translate_port_name((char *)payload,
+ &info);
break;
case IFLA_PHYS_SWITCH_ID:
info.switch_id = 0;
--
1.8.3.1
next prev parent reply other threads:[~2019-03-17 6:24 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-28 15:25 [dpdk-dev] [PATCH] net/mlx5: support new representors' " Dekel Peled
2019-03-03 7:43 ` [dpdk-dev] [PATCH v2] " Dekel Peled
2019-03-07 8:57 ` Shahaf Shuler
2019-03-10 14:55 ` Dekel Peled
2019-03-10 15:21 ` [dpdk-dev] [PATCH v3] net/mlx5: support new representor " Dekel Peled
2019-03-10 16:06 ` [dpdk-dev] [PATCH v4] " Dekel Peled
2019-03-17 6:23 ` Dekel Peled [this message]
2019-03-17 6:23 ` [dpdk-dev] [PATCH v5] " Dekel Peled
2019-03-18 6:29 ` Slava Ovsiienko
2019-03-18 6:29 ` Slava Ovsiienko
2019-03-18 6:59 ` Shahaf Shuler
2019-03-18 6:59 ` Shahaf Shuler
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=1552803783-55056-1-git-send-email-dekelp@mellanox.com \
--to=dekelp@mellanox.com \
--cc=dev@dpdk.org \
--cc=orika@mellanox.com \
--cc=shahafs@mellanox.com \
--cc=yskoh@mellanox.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).