Skip to contentSkip to conversation

support SubFunction representor

RFC Superseded Xueming Li 11 participants 209 messages Dec 18, 2020 – Apr 12, 2021 Network drivers Page 1 of 2

lore
Share & tools
lore

Xueming Li

author
#0 lore raw

cover support SubFunction representor

SubFunction [1] is a portion of the PCI device, a SF netdev has its own dedicated queues(txq, rxq). A SF netdev supports eswitch representation offload similar to existing PF and VF representors. A SF shares PCI level resources with other SFs and/or with its parent PCI function.

From SmartNIC perspective, when PCI device is shared for multi-host, representors for host controller and host PF is required.

This patch set introduces new representor types in addtion to existing VF representor. Syntax:

[[c#]pf#]vf#: VF port representor/s from controller/pf [[c#]pf#]sf#: SF port representor/s from controller/pf #: VF representor - for backwards compatibility

"#" is number instance, list or range, valid examples:
1, [1,3,5], [0-3], [0,2-4,6]

For flexibility, this patch also introduces new netdev capability to indicate the capability to support new representor types.

[1]:
https://lore.kernel.org/netdev/[email protected]/

Xueming Li (7):
ethdev: support sub function representor
ethdev: support multi-host representor
devarg: change reprsentor ID to bitmap
ethdev: capability for new representor syntax
kvargs: update parser for new representor syntax common/mlx5: update representor name parsing net/mlx5: support representor of sub function

 0000-cover-letter.patch                    |  44 ++++++
 config/rte_config.h                        |   1 +
 drivers/common/mlx5/linux/mlx5_common_os.c |  32 ++--
 drivers/common/mlx5/linux/mlx5_nl.c        |   2 +
 drivers/common/mlx5/mlx5_common.h          |   2 +
 drivers/net/mlx5/linux/mlx5_ethdev_os.c    |   5 +
 drivers/net/mlx5/linux/mlx5_os.c           |  69 ++++++++-
 drivers/net/mlx5/mlx5_ethdev.c             |   2 +
 lib/librte_ethdev/ethdev_private.c         | 164 ++++++++++++++-------
 lib/librte_ethdev/ethdev_private.h         |   3 -
 lib/librte_ethdev/rte_class_eth.c          |   7 +-
 lib/librte_ethdev/rte_ethdev.c             |   5 +-
 lib/librte_ethdev/rte_ethdev.h             |   2 +
 lib/librte_ethdev/rte_ethdev_driver.h      |  35 +++++
 lib/librte_kvargs/rte_kvargs.c             |  82 +++++++----
 15 files changed, 351 insertions(+), 104 deletions(-)
 create mode 100644 0000-cover-letter.patch
Signature · 1 line
2.25.1
author
#200 lore raw

RFC 4/7 ethdev: capability for new representor syntax

This patch introduces new eth device capability to support SubFunction representor device.

---
 lib/librte_ethdev/rte_ethdev.h | 2 ++
 1 file changed, 2 insertions(+)
lib/librte_ethdev/rte_ethdev.h +2 -0
index f5f8919186..3c087bec67 100644
@@ -1432,6 +1432,8 @@ struct rte_eth_conf {
 #define RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP 0x00000001
 /** Device supports Tx queue setup after device started. */
 #define RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP 0x00000002
+/**< Device supports SubFunction representor. */
+#define RTE_ETH_DEV_CAPA_REPRESENTOR_SF         0x00000004
 /**@}*/
 
 /*
Signature · 1 line
2.25.1
author
#197 lore raw

RFC 3/7 devarg: change reprsentor ID to bitmap

In reply to Xueming Li

In eth representor comparer callback, ethdev was compared with devarg. Since ethdev representor port didn't contain controller(host) and owner port information, callback only compared representor port and returned representor port on other PF port.

This patch changes representor port to bitmap encoding, expands and updates representor port ID after parsing, when device representor ID uses the same bitmap encoding, the eth representor comparer callback returns correct ethdev.

Representor port ID bitmap definition:
Representor ID bitmap:
xxxx xxxx xxxx xxxx

 |||| |LLL LLLL LLLL vf/sf id
 |||| L 1:sf, 0:vf
 ||LL pf id

LL controller(host) id

---
 0000-cover-letter.patch               | 44 +++++++++++++++++++++++++++
 lib/librte_ethdev/ethdev_private.c    | 42 ++++++++++++++++++++++++-
 lib/librte_ethdev/rte_ethdev_driver.h | 22 ++++++++++++++
 3 files changed, 107 insertions(+), 1 deletion(-)
 create mode 100644 0000-cover-letter.patch
0000-cover-letter.patch new file +44 -0
new file mode 100644
index 0000000000..3f8ce2be72
@@ -0,0 +1,44 @@
+From 4e1f8fc062fa6813e0b57f78ad72760601ca1d98 Mon Sep 17 00:00:00 2001
+From: Xueming Li <[email protected]>
+Date: Fri, 18 Dec 2020 22:31:53 +0800
+Subject: [RFC 0/7] *** SUBJECT HERE ***
+To: Viacheslav Ovsiienko <[email protected]>,
+    Thomas Monjalon <[email protected]>,
+    Ferruh Yigit <[email protected]>,
+    Andrew Rybchenko <[email protected]>,
+    Olivier Matz <[email protected]>,
+    Matan Azrad <[email protected]>
+Cc: [email protected],
+    [email protected],
+    Asaf Penso <[email protected]>
+
+*** BLURB HERE ***
+
+Xueming Li (7):
+  ethdev: support sub function representor
+  ethdev: support multi-host representor
+  devarg: change reprsentor ID to bitmap
+  ethdev: capability for new representor syntax
+  kvargs: update parser for new representor syntax
+  common/mlx5: update representor name parsing
+  net/mlx5: support representor of sub function
+
+ config/rte_config.h                        |   1 +
+ drivers/common/mlx5/linux/mlx5_common_os.c |  32 ++--
+ drivers/common/mlx5/linux/mlx5_nl.c        |   2 +
+ drivers/common/mlx5/mlx5_common.h          |   2 +
+ drivers/net/mlx5/linux/mlx5_ethdev_os.c    |   5 +
+ drivers/net/mlx5/linux/mlx5_os.c           |  69 ++++++++-
+ drivers/net/mlx5/mlx5_ethdev.c             |   2 +
+ lib/librte_ethdev/ethdev_private.c         | 163 ++++++++++++++-------
+ lib/librte_ethdev/ethdev_private.h         |   3 -
+ lib/librte_ethdev/rte_class_eth.c          |   7 +-
+ lib/librte_ethdev/rte_ethdev.c             |   5 +-
+ lib/librte_ethdev/rte_ethdev.h             |   2 +
+ lib/librte_ethdev/rte_ethdev_driver.h      |  35 +++++
+ lib/librte_kvargs/rte_kvargs.c             |  82 +++++++----
+ 14 files changed, 306 insertions(+), 104 deletions(-)
+
+-- 
+2.25.1
+
lib/librte_ethdev/ethdev_private.c +41 -1

63 lines not on this page · raw message

lib/librte_ethdev/rte_ethdev_driver.h +22 -0
index a7969c9408..dbad55c704 100644
@@ -1218,6 +1218,28 @@ struct rte_eth_devargs {
 	enum rte_eth_representor_type type; /* type of representor */
 };
 
+/**
+ * Encoding representor port ID.
+ *
+ * The compact format is used for device iterator that comparing
+ * ethdev representor ID with target devargs.
+ *
+ * xxxx xxxx xxxx xxxx
+ * |||| |LLL LLLL LLLL vf/sf id
+ * |||| L 1:sf, 0:vf
+ * ||LL pf id
+ * LL controller(host) id
+ */
+#define RTE_ETH_REPR(c, pf, sf, port) \
+	((((c) & 3) << 14) |     \
+	(((pf) & 3) << 12) |     \
+	(!!(sf) << 11) |         \
+	((port) & 0x7ff))
+/** Get 'pf' port id from representor ID */
+#define RTE_ETH_REPR_PF(repr) (((repr) >> 12) & 3)
+/** Get 'vf' or 'sf' port from representor ID */
+#define RTE_ETH_REPR_PORT(repr) ((repr) & 0x7ff)
+
 /**
  * PMD helper function to parse ethdev arguments
  *
Signature · 1 line
2.25.1
author
#195 lore raw

RFC 2/7 ethdev: support multi-host representor

In reply to Xueming Li

This patch introduce multi-host controller for ethdev representor syntax, examples:

[[c#]pf#]vf#: VF port representor/s, example: pf0vf1 [[c#]pf#]sf#: SF port representor/s, example: c1pf1sf[0-3]

c# is controller ID/range in case of multi-host, optional. It is mostly for SmartNIC attached to multiple hosts in the same rack to allow routing the packets between PF/SF/VF running on these hosts.

---
 config/rte_config.h                   |  1 +
 lib/librte_ethdev/ethdev_private.c    | 13 +++++++++++--
 lib/librte_ethdev/rte_ethdev_driver.h |  4 ++++
 3 files changed, 16 insertions(+), 2 deletions(-)
config/rte_config.h +1 -0
index a0b5160ff2..23d02d51ef 100644
@@ -58,6 +58,7 @@
 #define RTE_MAX_QUEUES_PER_PORT 1024
 #define RTE_ETHDEV_QUEUE_STAT_CNTRS 16 /* max 256 */
 #define RTE_ETHDEV_RXTX_CALLBACKS 1
+#define RTE_MAX_MULTI_HOST_CTRLS 4
 
 /* cryptodev defines */
 #define RTE_CRYPTO_MAX_DEVS 64
lib/librte_ethdev/ethdev_private.c +11 -2
index 2a057c5f36..3e455acea9 100644
@@ -95,8 +95,8 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
 /*
  * representor format:
  *   #: range or single number of VF representor - legacy
- *   [pf#]vf#: VF port representor/s
- *   [pf#]sf#: SF port representor/s
+ *   [[c#]pf#]vf#: VF port representor/s
+ *   [[c#]pf#]sf#: SF port representor/s
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
@@ -105,6 +105,15 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	int ret;
 
 	eth_da->type = RTE_ETH_REPRESENTOR_NONE;
+	if (str[0] == 'c') {
+		str += 1;
+		ret = rte_eth_devargs_process_list(str, eth_da->mh_controllers,
+				&eth_da->nb_mh_controllers,
+				RTE_DIM(eth_da->mh_controllers));
+		if (ret < 0)
+			goto err;
+		str += ret;
+	}
 	/* parse pf# */
 	if (str[0] == 'p' && str[1] == 'f') {
 		str += 2;
lib/librte_ethdev/rte_ethdev_driver.h +4 -0
index edb000cbd4..a7969c9408 100644
@@ -1203,6 +1203,10 @@ enum rte_eth_representor_type {
 
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
+	uint16_t mh_controllers[RTE_MAX_MULTI_HOST_CTRLS];
+	/** controller/s number in case of multi-host */
+	uint16_t nb_mh_controllers;
+	/** number of controllers in multi-host contollerss field */
 	uint16_t ports[RTE_MAX_ETHPORTS];
 	/** port/s number to enable on a multi-port single function */
 	uint16_t nb_ports;
Signature · 1 line
2.25.1
author
#1 lore raw

RFC 1/7 ethdev: support sub function representor

In reply to Xueming Li

To support SF representor, this patch enhances devargs syntax:

[pf#]vf#: new VF port representor/s, example: vf[0-3], pf0vf3 [pf#]sf#: new SF port representor/s, example: sf[0-3], pf1sf2

pf# is optional for SF and VF representor. If not present, representor is detected from PCI BDF of device argument. In case of bonding, pf# indicates owner PF device of SF or VF.

For backwards compatible, # default to vf#.

Enhances rte_eth_devargs_parse_representor_port() function to parse new representor syntax, replace rte_eth_devargs_parse_list() function which only parse simple list.

---
 lib/librte_ethdev/ethdev_private.c    | 115 ++++++++++++++------------
 lib/librte_ethdev/ethdev_private.h    |   3 -
 lib/librte_ethdev/rte_class_eth.c     |   7 +-
 lib/librte_ethdev/rte_ethdev.c        |   5 +-
 lib/librte_ethdev/rte_ethdev_driver.h |   9 ++
 5 files changed, 77 insertions(+), 62 deletions(-)
lib/librte_ethdev/ethdev_private.c +64 -51
index 162a502fe7..2a057c5f36 100644
@@ -38,60 +38,13 @@ eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp,
 	return NULL;
 }
 
-int
-rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
-	void *data)
-{
-	char *str_start;
-	int state;
-	int result;
-
-	if (*str != '[')
-		/* Single element, not a list */
-		return callback(str, data);
-
-	/* Sanity check, then strip the brackets */
-	str_start = &str[strlen(str) - 1];
-	if (*str_start != ']') {
-		RTE_LOG(ERR, EAL, "(%s): List does not end with ']'\n", str);
-		return -EINVAL;
-	}
-	str++;
-	*str_start = '\0';
-
-	/* Process list elements */
-	state = 0;
-	while (1) {
-		if (state == 0) {
-			if (*str == '\0')
-				break;
-			if (*str != ',') {
-				str_start = str;
-				state = 1;
-			}
-		} else if (state == 1) {
-			if (*str == ',' || *str == '\0') {
-				if (str > str_start) {
-					/* Non-empty string fragment */
-					*str = '\0';
-					result = callback(str_start, data);
-					if (result < 0)
-						return result;
-				}
-				state = 0;
-			}
-		}
-		str++;
-	}
-	return 0;
-}
-
 static int
 rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
 	const uint16_t max_list)
 {
 	uint16_t lo, hi, val;
 	int result;
+	char *pos = str;
 
 	result = sscanf(str, "%hu-%hu", &lo, &hi);
 	if (result == 1) {
@@ -99,7 +52,7 @@ rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
 			return -ENOMEM;
 		list[(*len_list)++] = lo;
 	} else if (result == 2) {
-		if (lo >= hi || lo > RTE_MAX_ETHPORTS || hi > RTE_MAX_ETHPORTS)
+		if (lo >= hi)
 			return -EINVAL;
 		for (val = lo; val <= hi; val++) {
 			if (*len_list >= max_list)
@@ -108,14 +61,74 @@ rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
 		}
 	} else
 		return -EINVAL;
-	return 0;
+	while (*pos != 0 && ((*pos >= '0' && *pos <= '9') || *pos == '-'))
+		pos++;
+	return pos - str;
 }
 
+static int
+rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
+	const uint16_t max_list)
+{
+	char *pos = str;
+	int ret;
+
+	if (*pos == '[')
+		pos++;
+	while (1) {
+		ret = rte_eth_devargs_process_range(pos, list, len_list,
+						    max_list);
+		if (ret < 0)
+			return ret;
+		pos += ret;
+		if (*pos != ',') /* end of list */
+			break;
+		pos++;
+	}
+	if (*str == '[' && *pos != ']')
+		return -EINVAL;
+	if (*pos == ']')
+		pos++;
+	return pos - str;
+}
+
+/*
+ * representor format:
+ *   #: range or single number of VF representor - legacy
+ *   [pf#]vf#: VF port representor/s
+ *   [pf#]sf#: SF port representor/s
+ */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
 {
 	struct rte_eth_devargs *eth_da = data;
+	int ret;
 
-	return rte_eth_devargs_process_range(str, eth_da->representor_ports,
+	eth_da->type = RTE_ETH_REPRESENTOR_NONE;
+	/* parse pf# */
+	if (str[0] == 'p' && str[1] == 'f') {
+		str += 2;
+		eth_da->type = RTE_ETH_REPRESENTOR_PF;
+		ret = rte_eth_devargs_process_list(str, eth_da->ports,
+				&eth_da->nb_ports, RTE_MAX_ETHPORTS);
+		if (ret < 0)
+			goto err;
+		str += ret;
+	}
+	/* parse vf# and sf#, number # alone implies VF */
+	if (str[0] == 'v'  && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_VF;
+		str += 2;
+	} else if (str[0] == 's'  && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_SF;
+		str += 2;
+	} else {
+		eth_da->type = RTE_ETH_REPRESENTOR_VF;
+	}
+	ret = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
+err:
+	if (ret < 0)
+		RTE_LOG(ERR, EAL, "wrong representor format: %s", str);
+	return ret < 0 ? ret : 0;
 }
lib/librte_ethdev/ethdev_private.h +0 -3
index 905a45c337..220ddd4408 100644
@@ -26,9 +26,6 @@ eth_find_device(const struct rte_eth_dev *_start, rte_eth_cmp_t cmp,
 		const void *data);
 
 /* Parse devargs value for representor parameter. */
-typedef int (*rte_eth_devargs_callback_t)(char *str, void *data);
-int rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
-	void *data);
 int rte_eth_devargs_parse_representor_ports(char *str, void *data);
 
 #ifdef __cplusplus
lib/librte_ethdev/rte_class_eth.c +2 -5
index 6338355e25..7da06808ea 100644
@@ -66,7 +66,7 @@ eth_representor_cmp(const char *key __rte_unused,
 	int ret;
 	char *values;
 	const struct rte_eth_dev_data *data = opaque;
-	struct rte_eth_devargs representors;
+	struct rte_eth_devargs representors = { 0 };
 	uint16_t index;
 
 	if ((data->dev_flags & RTE_ETH_DEV_REPRESENTOR) == 0)
@@ -76,10 +76,7 @@ eth_representor_cmp(const char *key __rte_unused,
 	values = strdup(value);
 	if (values == NULL)
 		return -1;
-	memset(&representors, 0, sizeof(representors));
-	ret = rte_eth_devargs_parse_list(values,
-			rte_eth_devargs_parse_representor_ports,
-			&representors);
+	ret = rte_eth_devargs_parse_representor_ports(values, &representors);
 	free(values);
 	if (ret != 0)
 		return -1; /* invalid devargs value */
lib/librte_ethdev/rte_ethdev.c +2 -3
index 17ddacc78d..2ac51ac149 100644
@@ -5542,9 +5542,8 @@ rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
 	for (i = 0; i < args.count; i++) {
 		pair = &args.pairs[i];
 		if (strcmp("representor", pair->key) == 0) {
-			result = rte_eth_devargs_parse_list(pair->value,
-				rte_eth_devargs_parse_representor_ports,
-				eth_da);
+			result = rte_eth_devargs_parse_representor_ports(
+					pair->value, eth_da);
 			if (result < 0)
 				goto parse_cleanup;
 		}
lib/librte_ethdev/rte_ethdev_driver.h +9 -0
index 0eacfd8425..edb000cbd4 100644
@@ -1193,6 +1193,14 @@ __rte_internal
 int
 rte_eth_switch_domain_free(uint16_t domain_id);
 
+/** Ethernet device representor type */
+enum rte_eth_representor_type {
+	RTE_ETH_REPRESENTOR_NONE, /* not a representor */
+	RTE_ETH_REPRESENTOR_VF,   /* representor of VF */
+	RTE_ETH_REPRESENTOR_SF,   /* representor of SF */
+	RTE_ETH_REPRESENTOR_PF,   /* representor of host PF */
+};
+
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
 	uint16_t ports[RTE_MAX_ETHPORTS];
@@ -1203,6 +1211,7 @@ struct rte_eth_devargs {
 	/** representor port/s identifier to enable on device */
 	uint16_t nb_representor_ports;
 	/** number of ports in representor port field */
+	enum rte_eth_representor_type type; /* type of representor */
 };
 
 /**
Signature · 1 line
2.25.1
author
#205 lore raw

RFC 7/7 net/mlx5: support representor of sub function

In reply to Xueming Li

This patch supports of SF representor. Similar to VF representor, switch port name of SF representor in sysfs phys_port_name is "pf<x>sf<y>".

Device representor argumnt is "representors=sf[list]", list member could be mix of instance and range. Example:
representors=sf[0,2,4,8-12,-1]

To probe VF representor and SF representor, need to separate into 2 devices:
-a <BDF>,representor=vf[list] -a <BDF>,representor=sf[list]

---
 drivers/net/mlx5/linux/mlx5_ethdev_os.c |  2 +
 drivers/net/mlx5/linux/mlx5_os.c        | 69 ++++++++++++++++++++++---
 drivers/net/mlx5/mlx5_ethdev.c          |  2 +
 3 files changed, 67 insertions(+), 6 deletions(-)
drivers/net/mlx5/linux/mlx5_ethdev_os.c +2 -0
index d4eed11fbc..11c30d587c 100644
@@ -1010,6 +1010,8 @@ mlx5_sysfs_check_switch_info(bool device_dir,
 	case MLX5_PHYS_PORT_NAME_TYPE_PFHPF:
 		/* Fallthrough */
 	case MLX5_PHYS_PORT_NAME_TYPE_PFVF:
+		/* Fallthrough */
+	case MLX5_PHYS_PORT_NAME_TYPE_PFSF:
 		/* New representors naming schema. */
 		switch_info->representor = 1;
 		break;
drivers/net/mlx5/linux/mlx5_os.c +63 -6

106 lines not on this page · raw message

drivers/net/mlx5/mlx5_ethdev.c +2 -0
index 45ee7e4488..ad6aacc329 100644
@@ -374,6 +374,8 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
 			break;
 		}
 	}
+	if (priv->master)
+		info->dev_capa = RTE_ETH_DEV_CAPA_REPRESENTOR_SF;
 	return 0;
 }
 
Signature · 1 line
2.25.1
author
#204 lore raw

RFC 6/7 common/mlx5: update representor name parsing

In reply to Xueming Li

This patch updates representor name parsing for SF.
In sysfs, representor name stored in from 'phys_port_name file', similar to VF representor, switch port name of SF representor is "pf<x>sf<y>".

For netlink message, net SF type is supported.

Examples:

pf0sf1
pf0sf[0-3]

---
 drivers/common/mlx5/linux/mlx5_common_os.c | 32 +++++++++++++++-------
 drivers/common/mlx5/linux/mlx5_nl.c        |  2 ++
 drivers/common/mlx5/mlx5_common.h          |  2 ++
 drivers/net/mlx5/linux/mlx5_ethdev_os.c    |  3 ++
 4 files changed, 29 insertions(+), 10 deletions(-)
drivers/common/mlx5/linux/mlx5_common_os.c +22 -10
index 0edd78ea6d..5cf9576921 100644
@@ -97,22 +97,34 @@ void
 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, eol;
+	char ctrl = 0, pf_c1, pf_c2, vf_c1, vf_c2, eol;
 	char *end;
 	int sc_items;
 
-	/*
-	 * Check for port-name as a string of the form pf0vf0
-	 * (support kernel ver >= 5.0 or OFED ver >= 4.6).
-	 */
+	sc_items = sscanf(port_name_in, "%c%d",
+			  &ctrl, &port_info_out->ctrl_num);
+	if (sc_items == 2 && ctrl == 'c') {
+		port_name_in++; /* 'c' */
+		port_name_in += snprintf(NULL, 0, "%d",
+					  port_info_out->ctrl_num);
+	}
+	/* Check for port-name as a string of the form pf0vf0 or pf0sf0 */
 	sc_items = sscanf(port_name_in, "%c%c%d%c%c%d%c",
 			  &pf_c1, &pf_c2, &port_info_out->pf_num,
 			  &vf_c1, &vf_c2, &port_info_out->port_name, &eol);
-	if (sc_items == 6 &&
-	    pf_c1 == 'p' && pf_c2 == 'f' &&
-	    vf_c1 == 'v' && vf_c2 == 'f') {
-		port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_PFVF;
-		return;
+	if (sc_items == 6 && pf_c1 == 'p' && pf_c2 == 'f') {
+		if (vf_c1 == 'v' && vf_c2 == 'f') {
+			/* Kernel ver >= 5.0 or OFED ver >= 4.6 */
+			port_info_out->name_type =
+					MLX5_PHYS_PORT_NAME_TYPE_PFVF;
+			return;
+		}
+		if (vf_c1 == 's' && vf_c2 == 'f') {
+			/* Kernel ver >= 5.11 or OFED ver >= 5.1 */
+			port_info_out->name_type =
+					MLX5_PHYS_PORT_NAME_TYPE_PFSF;
+			return;
+		}
 	}
 	/*
 	 * Check for port-name as a string of the form p0
drivers/common/mlx5/linux/mlx5_nl.c +2 -0
index 40d8620300..3d55cc98b4 100644
@@ -1148,6 +1148,8 @@ mlx5_nl_check_switch_info(bool num_vf_set,
 	case MLX5_PHYS_PORT_NAME_TYPE_PFHPF:
 		/* Fallthrough */
 	case MLX5_PHYS_PORT_NAME_TYPE_PFVF:
+		/* Fallthrough */
+	case MLX5_PHYS_PORT_NAME_TYPE_PFSF:
 		/* New representors naming schema. */
 		switch_info->representor = 1;
 		break;
drivers/common/mlx5/mlx5_common.h +2 -0
index a484b74b9c..4c75addd08 100644
@@ -153,6 +153,7 @@ enum mlx5_nl_phys_port_name_type {
 	MLX5_PHYS_PORT_NAME_TYPE_UPLINK, /* p0, kernel ver >= 5.0 */
 	MLX5_PHYS_PORT_NAME_TYPE_PFVF, /* pf0vf0, kernel ver >= 5.0 */
 	MLX5_PHYS_PORT_NAME_TYPE_PFHPF, /* pf0, kernel ver >= 5.7, HPF rep */
+	MLX5_PHYS_PORT_NAME_TYPE_PFSF, /* pf0sf0, kernel ver >= 5.0 */
 	MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN, /* Unrecognized. */
 };
 
@@ -161,6 +162,7 @@ struct mlx5_switch_info {
 	uint32_t master:1; /**< Master device. */
 	uint32_t representor:1; /**< Representor device. */
 	enum mlx5_nl_phys_port_name_type name_type; /** < Port name type. */
+	int32_t ctrl_num; /**< Controller number (valid for c#pf#vf# format). */
 	int32_t pf_num; /**< PF number (valid for pfxvfx format only). */
 	int32_t port_name; /**< Representor port name. */
 	uint64_t switch_id; /**< Switch identifier. */
drivers/net/mlx5/linux/mlx5_ethdev_os.c +3 -0
index 128845cb52..d4eed11fbc 100644
@@ -1013,6 +1013,9 @@ mlx5_sysfs_check_switch_info(bool device_dir,
 		/* New representors naming schema. */
 		switch_info->representor = 1;
 		break;
+	default:
+		switch_info->master = device_dir;
+		break;
 	}
 }
 
Signature · 1 line
2.25.1
author
#202 lore raw

RFC 5/7 kvargs: update parser for new representor syntax

In reply to Xueming Li

This patch updates kvargs parser to allow comma in list value:
k1=a[1,2]b[3-5]

---
 lib/librte_kvargs/rte_kvargs.c | 82 +++++++++++++++++++++++-----------
 1 file changed, 56 insertions(+), 26 deletions(-)
lib/librte_kvargs/rte_kvargs.c +56 -26
index 285081c86c..6193109a17 100644
@@ -13,15 +13,19 @@
 /*
  * Receive a string with a list of arguments following the pattern
  * key=value,key=value,... and insert them into the list.
- * strtok() is used so the params string will be copied to be modified.
+ * Params string will be copied to be modified.
+ * list "[]" and list element splitter ",", "-" is treated as value.
+ * Supported examples:
+ *   k1=v1,k2=v2
+ *   v1
+ *   k1=x[0-1]y[1,3-5,9]z
  */
 static int
 rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
 {
 	unsigned i;
-	char *str;
-	char *ctx1 = NULL;
-	char *ctx2 = NULL;
+	char *str, *start;
+	int in_list = 0, end_k = 0, end_v = 0;
 
 	/* Copy the const char *params to a modifiable string
 	 * to pass to rte_strsplit
@@ -32,36 +36,62 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
 
 	/* browse each key/value pair and add it in kvlist */
 	str = kvlist->str;
-	while ((str = strtok_r(str, RTE_KVARGS_PAIRS_DELIM, &ctx1)) != NULL) {
+	start = str; /* start of current key or value */
+	while (1) {
+		switch (*str) {
+		case '=': /* End of key. */
+			end_k = 1;
+			break;
+		case ',':
+			/* End of value, skip comma in middle of range */
+			if (!in_list)
+				end_v = 1;
+			break;
+		case '[': /* Start of list. */
+			in_list++;
+			break;
+		case ']': /* End of list.  */
+			if (in_list)
+				in_list--;
+			break;
+		case 0: /* End of string */
+			end_v = 1;
+			break;
+		default:
+			break;
+		}
+
+		if (!end_k && !end_v) {
+			/* Continue if not end of key or value. */
+			str++;
+			continue;
+		}
 
 		i = kvlist->count;
 		if (i >= RTE_KVARGS_MAX)
 			return -1;
 
-		kvlist->pairs[i].key = strtok_r(str, RTE_KVARGS_KV_DELIM, &ctx2);
-		kvlist->pairs[i].value = strtok_r(NULL, RTE_KVARGS_KV_DELIM, &ctx2);
-		if (kvlist->pairs[i].key == NULL ||
-		    kvlist->pairs[i].value == NULL)
-			return -1;
-
-		/* Detect list [a,b] to skip comma delimiter in list. */
-		str = kvlist->pairs[i].value;
-		if (str[0] == '[') {
-			/* Find the end of the list. */
-			while (str[strlen(str) - 1] != ']') {
-				/* Restore the comma erased by strtok_r(). */
-				if (ctx1 == NULL || ctx1[0] == '\0')
-					return -1; /* no closing bracket */
-				str[strlen(str)] = ',';
-				/* Parse until next comma. */
-				str = strtok_r(NULL, RTE_KVARGS_PAIRS_DELIM, &ctx1);
-				if (str == NULL)
-					return -1; /* no closing bracket */
+		if (start == str) /* Empty key  or value. */
+			start = NULL;
+
+		if (end_k) {
+			/* Key parsed. */
+			kvlist->pairs[i].key = start;
+			end_k = 0;
+		} else if (end_v) {
+			/* Allow single key or single value. */
+			if (kvlist->pairs[i].key || start) {
+				kvlist->pairs[i].value = start;
+				kvlist->count++;
 			}
+			end_v = 0;
 		}
 
-		kvlist->count++;
-		str = NULL;
+		if (!*str) /* End of string. */
+			break;
+		*str = 0;
+		str++;
+		start = str;
 	}
 
 	return 0;
Signature · 1 line
2.25.1
#2 lore raw

Re: [dpdk-dev] [RFC 1/7] ethdev: support sub function representor

In reply to Xueming Li
Quoted 9 lines · Xueming Li

To support SF representor, this patch enhances devargs syntax:

[pf#]vf#: new VF port representor/s, example: vf[0-3], pf0vf3 [pf#]sf#: new SF port representor/s, example: sf[0-3], pf1sf2

pf# is optional for SF and VF representor. If not present, representor is detected from PCI BDF of device argument. In case of bonding, pf# indicates owner PF device of SF or VF.

Quoted 5 lines

For backwards compatible, # default to vf#.

Enhances rte_eth_devargs_parse_representor_port() function to parse new representor syntax, replace rte_eth_devargs_parse_list() function which only parse simple list.

Consider to split it into few patches:
1. rework infrastructure/functions, introduce enum, support old syntax only
2. add new syntax for VFs
3. add SubFunctions support, add enum member (don't forget to update existing drivers to reject if SF is requested)
4. add PFs support, add enum member (also don't forget to update existing drivers as well)

Quoted 129 lines
---
 lib/librte_ethdev/ethdev_private.c    | 115 ++++++++++++++------------
 lib/librte_ethdev/ethdev_private.h    |   3 -
 lib/librte_ethdev/rte_class_eth.c     |   7 +-
 lib/librte_ethdev/rte_ethdev.c        |   5 +-
 lib/librte_ethdev/rte_ethdev_driver.h |   9 ++
 5 files changed, 77 insertions(+), 62 deletions(-)
lib/librte_ethdev/ethdev_private.c +37 -50
index 162a502fe7..2a057c5f36 100644
@@ -38,60 +38,13 @@ eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp,
 	return NULL;
 }
 
-int
-rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
-	void *data)
-{
-	char *str_start;
-	int state;
-	int result;
-
-	if (*str != '[')
-		/* Single element, not a list */
-		return callback(str, data);
-
-	/* Sanity check, then strip the brackets */
-	str_start = &str[strlen(str) - 1];
-	if (*str_start != ']') {
-		RTE_LOG(ERR, EAL, "(%s): List does not end with ']'\n", str);
-		return -EINVAL;
-	}
-	str++;
-	*str_start = '\0';
-
-	/* Process list elements */
-	state = 0;
-	while (1) {
-		if (state == 0) {
-			if (*str == '\0')
-				break;
-			if (*str != ',') {
-				str_start = str;
-				state = 1;
-			}
-		} else if (state == 1) {
-			if (*str == ',' || *str == '\0') {
-				if (str > str_start) {
-					/* Non-empty string fragment */
-					*str = '\0';
-					result = callback(str_start, data);
-					if (result < 0)
-						return result;
-				}
-				state = 0;
-			}
-		}
-		str++;
-	}
-	return 0;
-}
-
 static int
 rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
 	const uint16_t max_list)
 {
 	uint16_t lo, hi, val;
 	int result;
+	char *pos = str;
 
 	result = sscanf(str, "%hu-%hu", &lo, &hi);
 	if (result == 1) {
@@ -99,7 +52,7 @@ rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
 			return -ENOMEM;
 		list[(*len_list)++] = lo;
 	} else if (result == 2) {
-		if (lo >= hi || lo > RTE_MAX_ETHPORTS || hi > RTE_MAX_ETHPORTS)
+		if (lo >= hi)
 			return -EINVAL;
 		for (val = lo; val <= hi; val++) {
 			if (*len_list >= max_list)
@@ -108,14 +61,74 @@ rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
 		}
 	} else
 		return -EINVAL;
-	return 0;
+	while (*pos != 0 && ((*pos >= '0' && *pos <= '9') || *pos == '-'))
+		pos++;
+	return pos - str;
 }
 
+static int
+rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
+	const uint16_t max_list)
+{
+	char *pos = str;
+	int ret;
+
+	if (*pos == '[')
+		pos++;
+	while (1) {
+		ret = rte_eth_devargs_process_range(pos, list, len_list,
+						    max_list);
+		if (ret < 0)
+			return ret;
+		pos += ret;
+		if (*pos != ',') /* end of list */
+			break;
+		pos++;
+	}
+	if (*str == '[' && *pos != ']')
+		return -EINVAL;
+	if (*pos == ']')
+		pos++;
+	return pos - str;
+}
+
+/*
+ * representor format:
+ *   #: range or single number of VF representor - legacy
+ *   [pf#]vf#: VF port representor/s
+ *   [pf#]sf#: SF port representor/s
+ */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list, · line 111

Quoted 10 lines
lib/librte_ethdev/ethdev_private.c +6 -1
 {
 	struct rte_eth_devargs *eth_da = data;
+	int ret;
 
-	return rte_eth_devargs_process_range(str, eth_da->representor_ports,
+	eth_da->type = RTE_ETH_REPRESENTOR_NONE;
+	/* parse pf# */
+	if (str[0] == 'p' && str[1] == 'f') {
+		str += 2;
+		eth_da->type = RTE_ETH_REPRESENTOR_PF;

Just to be consistent with similar lines below, please, swap these two lines.

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list, · line 113

Quoted 2 lines
lib/librte_ethdev/ethdev_private.c +2 -0
+		ret = rte_eth_devargs_process_list(str, eth_da->ports,
+				&eth_da->nb_ports, RTE_MAX_ETHPORTS);

I'm not sure that it matches ports and nb_ports fields purpose.

In any case it should update existing drivers which support representors to reject devargs with PFs specified.

Quoted 9 lines
lib/librte_ethdev/ethdev_private.c +9 -0
+		if (ret < 0)
+			goto err;
+		str += ret;
+	}
+	/* parse vf# and sf#, number # alone implies VF */
+	if (str[0] == 'v'  && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_VF;
+		str += 2;
+	} else if (str[0] == 's'  && str[1] == 'f') {

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list, · line 132

Quoted 10 lines
lib/librte_ethdev/ethdev_private.c +9 -0
+		eth_da->type = RTE_ETH_REPRESENTOR_SF;
+		str += 2;
+	} else {
+		eth_da->type = RTE_ETH_REPRESENTOR_VF;
+	}
+	ret = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
+err:
+	if (ret < 0)
+		RTE_LOG(ERR, EAL, "wrong representor format: %s", str);

Missing \n

Quoted 85 lines
lib/librte_ethdev/ethdev_private.c +1 -0
+	return ret < 0 ? ret : 0;
 }
lib/librte_ethdev/ethdev_private.h +0 -3
index 905a45c337..220ddd4408 100644
@@ -26,9 +26,6 @@ eth_find_device(const struct rte_eth_dev *_start, rte_eth_cmp_t cmp,
 		const void *data);
 
 /* Parse devargs value for representor parameter. */
-typedef int (*rte_eth_devargs_callback_t)(char *str, void *data);
-int rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
-	void *data);
 int rte_eth_devargs_parse_representor_ports(char *str, void *data);
 
 #ifdef __cplusplus
lib/librte_ethdev/rte_class_eth.c +2 -5
index 6338355e25..7da06808ea 100644
@@ -66,7 +66,7 @@ eth_representor_cmp(const char *key __rte_unused,
 	int ret;
 	char *values;
 	const struct rte_eth_dev_data *data = opaque;
-	struct rte_eth_devargs representors;
+	struct rte_eth_devargs representors = { 0 };
 	uint16_t index;
 
 	if ((data->dev_flags & RTE_ETH_DEV_REPRESENTOR) == 0)
@@ -76,10 +76,7 @@ eth_representor_cmp(const char *key __rte_unused,
 	values = strdup(value);
 	if (values == NULL)
 		return -1;
-	memset(&representors, 0, sizeof(representors));
-	ret = rte_eth_devargs_parse_list(values,
-			rte_eth_devargs_parse_representor_ports,
-			&representors);
+	ret = rte_eth_devargs_parse_representor_ports(values, &representors);
 	free(values);
 	if (ret != 0)
 		return -1; /* invalid devargs value */
lib/librte_ethdev/rte_ethdev.c +2 -3
index 17ddacc78d..2ac51ac149 100644
@@ -5542,9 +5542,8 @@ rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
 	for (i = 0; i < args.count; i++) {
 		pair = &args.pairs[i];
 		if (strcmp("representor", pair->key) == 0) {
-			result = rte_eth_devargs_parse_list(pair->value,
-				rte_eth_devargs_parse_representor_ports,
-				eth_da);
+			result = rte_eth_devargs_parse_representor_ports(
+					pair->value, eth_da);
 			if (result < 0)
 				goto parse_cleanup;
 		}
lib/librte_ethdev/rte_ethdev_driver.h +9 -0
index 0eacfd8425..edb000cbd4 100644
@@ -1193,6 +1193,14 @@ __rte_internal
 int
 rte_eth_switch_domain_free(uint16_t domain_id);
 
+/** Ethernet device representor type */
+enum rte_eth_representor_type {
+	RTE_ETH_REPRESENTOR_NONE, /* not a representor */
+	RTE_ETH_REPRESENTOR_VF,   /* representor of VF */
+	RTE_ETH_REPRESENTOR_SF,   /* representor of SF */
+	RTE_ETH_REPRESENTOR_PF,   /* representor of host PF */
+};
+
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
 	uint16_t ports[RTE_MAX_ETHPORTS];
@@ -1203,6 +1211,7 @@ struct rte_eth_devargs {
 	/** representor port/s identifier to enable on device */
 	uint16_t nb_representor_ports;
 	/** number of ports in representor port field */
+	enum rte_eth_representor_type type; /* type of representor */
 };
 
 /**
#203 lore raw

Re: [dpdk-dev] [RFC 5/7] kvargs: update parser for new representor syntax

In reply to Xueming Li
Quoted 57 lines · Xueming Li

This patch updates kvargs parser to allow comma in list value:
k1=a[1,2]b[3-5]

---
 lib/librte_kvargs/rte_kvargs.c | 82 +++++++++++++++++++++++-----------
 1 file changed, 56 insertions(+), 26 deletions(-)
lib/librte_kvargs/rte_kvargs.c +24 -5
index 285081c86c..6193109a17 100644
@@ -13,15 +13,19 @@
 /*
  * Receive a string with a list of arguments following the pattern
  * key=value,key=value,... and insert them into the list.
- * strtok() is used so the params string will be copied to be modified.
+ * Params string will be copied to be modified.
+ * list "[]" and list element splitter ",", "-" is treated as value.
+ * Supported examples:
+ *   k1=v1,k2=v2
+ *   v1
+ *   k1=x[0-1]y[1,3-5,9]z
  */
 static int
 rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
 {
 	unsigned i;
-	char *str;
-	char *ctx1 = NULL;
-	char *ctx2 = NULL;
+	char *str, *start;
+	int in_list = 0, end_k = 0, end_v = 0;
 
 	/* Copy the const char *params to a modifiable string
 	 * to pass to rte_strsplit
@@ -32,36 +36,62 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
 
 	/* browse each key/value pair and add it in kvlist */
 	str = kvlist->str;
-	while ((str = strtok_r(str, RTE_KVARGS_PAIRS_DELIM, &ctx1)) != NULL) {
+	start = str; /* start of current key or value */
+	while (1) {
+		switch (*str) {
+		case '=': /* End of key. */
+			end_k = 1;
+			break;
+		case ',':
+			/* End of value, skip comma in middle of range */
+			if (!in_list)
+				end_v = 1;
+			break;
+		case '[': /* Start of list. */
+			in_list++;
+			break;
+		case ']': /* End of list.  */
+			if (in_list)

lib/librte_kvargs/rte_kvargs.c rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params) · line 64

Quoted 10 lines
lib/librte_kvargs/rte_kvargs.c +10 -0
+				in_list--;
+			break;
+		case 0: /* End of string */
+			end_v = 1;
+			break;
+		default:
+			break;
+		}
+
+		if (!end_k && !end_v) {

DPDK coding style requires to compare integers vs 0 explicitly. Otherwise you can define it as bool and use as bool this way.

Quoted 22 lines
lib/librte_kvargs/rte_kvargs.c +4 -13
+			/* Continue if not end of key or value. */
+			str++;
+			continue;
+		}
 
 		i = kvlist->count;
 		if (i >= RTE_KVARGS_MAX)
 			return -1;
 
-		kvlist->pairs[i].key = strtok_r(str, RTE_KVARGS_KV_DELIM, &ctx2);
-		kvlist->pairs[i].value = strtok_r(NULL, RTE_KVARGS_KV_DELIM, &ctx2);
-		if (kvlist->pairs[i].key == NULL ||
-		    kvlist->pairs[i].value == NULL)
-			return -1;
-
-		/* Detect list [a,b] to skip comma delimiter in list. */
-		str = kvlist->pairs[i].value;
-		if (str[0] == '[') {
-			/* Find the end of the list. */
-			while (str[strlen(str) - 1] != ']') {
-				/* Restore the comma erased by strtok_r(). */
-				if (ctx1 == NULL || ctx1[0] == '\0')

lib/librte_kvargs/rte_kvargs.c rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params) · line 77

Quoted 10 lines
lib/librte_kvargs/rte_kvargs.c +4 -6
-					return -1; /* no closing bracket */
-				str[strlen(str)] = ',';
-				/* Parse until next comma. */
-				str = strtok_r(NULL, RTE_KVARGS_PAIRS_DELIM, &ctx1);
-				if (str == NULL)
-					return -1; /* no closing bracket */
+		if (start == str) /* Empty key  or value. */
+			start = NULL;
+
+		if (end_k) {

same

lib/librte_kvargs/rte_kvargs.c rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params) · line 81

Quoted 4 lines
lib/librte_kvargs/rte_kvargs.c +4 -0
+			/* Key parsed. */
+			kvlist->pairs[i].key = start;
+			end_k = 0;
+		} else if (end_v) {

same

lib/librte_kvargs/rte_kvargs.c rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params) · line 90

Quoted 11 lines
lib/librte_kvargs/rte_kvargs.c +6 -2
+			/* Allow single key or single value. */
+			if (kvlist->pairs[i].key || start) {
+				kvlist->pairs[i].value = start;
+				kvlist->count++;
 			}
+			end_v = 0;
 		}
 
-		kvlist->count++;
-		str = NULL;
+		if (!*str) /* End of string. */

Compare with '\0'.

Quoted 7 lines
lib/librte_kvargs/rte_kvargs.c +4 -0
+			break;
+		*str = 0;
+		str++;
+		start = str;
 	}
 
 	return 0;
#198 lore raw

Re: [dpdk-dev] [RFC 3/7] devarg: change reprsentor ID to bitmap

In reply to Xueming Li
Quoted 1 line · Xueming Li

In eth representor comparer callback, ethdev was compared with devarg.

comparer -> comparator?

Quoted 9 lines

Since ethdev representor port didn't contain controller(host) and owner port information, callback only compared representor port and returned representor port on other PF port.

This patch changes representor port to bitmap encoding, expands and updates representor port ID after parsing, when device representor ID uses the same bitmap encoding, the eth representor comparer callback returns correct ethdev.

Quoted 6 lines

Representor port ID bitmap definition:
Representor ID bitmap:
xxxx xxxx xxxx xxxx

 |||| |LLL LLLL LLLL vf/sf id
 |||| L 1:sf, 0:vf
 ||LL pf id

Just 2 bits for PF ID is definitely not future proof.

Quoted 1 line

LL controller(host) id

Same here.

In general, I'm not sure that such approch with bitmap makes sense. I think we need a new API which returns information about available functions which could be represented and IDs there could be used as representor IDs.

Quoted 4 lines
---
 0000-cover-letter.patch               | 44 +++++++++++++++++++++++++++

I guess it should not be added to the changeset.

Quoted 82 lines
 lib/librte_ethdev/ethdev_private.c    | 42 ++++++++++++++++++++++++-
 lib/librte_ethdev/rte_ethdev_driver.h | 22 ++++++++++++++
 3 files changed, 107 insertions(+), 1 deletion(-)
 create mode 100644 0000-cover-letter.patch
0000-cover-letter.patch new file +44 -0
new file mode 100644
index 0000000000..3f8ce2be72
@@ -0,0 +1,44 @@
+From 4e1f8fc062fa6813e0b57f78ad72760601ca1d98 Mon Sep 17 00:00:00 2001
+From: Xueming Li <[email protected]>
+Date: Fri, 18 Dec 2020 22:31:53 +0800
+Subject: [RFC 0/7] *** SUBJECT HERE ***
+To: Viacheslav Ovsiienko <[email protected]>,
+    Thomas Monjalon <[email protected]>,
+    Ferruh Yigit <[email protected]>,
+    Andrew Rybchenko <[email protected]>,
+    Olivier Matz <[email protected]>,
+    Matan Azrad <[email protected]>
+Cc: [email protected],
+    [email protected],
+    Asaf Penso <[email protected]>
+
+*** BLURB HERE ***
+
+Xueming Li (7):
+  ethdev: support sub function representor
+  ethdev: support multi-host representor
+  devarg: change reprsentor ID to bitmap
+  ethdev: capability for new representor syntax
+  kvargs: update parser for new representor syntax
+  common/mlx5: update representor name parsing
+  net/mlx5: support representor of sub function
+
+ config/rte_config.h                        |   1 +
+ drivers/common/mlx5/linux/mlx5_common_os.c |  32 ++--
+ drivers/common/mlx5/linux/mlx5_nl.c        |   2 +
+ drivers/common/mlx5/mlx5_common.h          |   2 +
+ drivers/net/mlx5/linux/mlx5_ethdev_os.c    |   5 +
+ drivers/net/mlx5/linux/mlx5_os.c           |  69 ++++++++-
+ drivers/net/mlx5/mlx5_ethdev.c             |   2 +
+ lib/librte_ethdev/ethdev_private.c         | 163 ++++++++++++++-------
+ lib/librte_ethdev/ethdev_private.h         |   3 -
+ lib/librte_ethdev/rte_class_eth.c          |   7 +-
+ lib/librte_ethdev/rte_ethdev.c             |   5 +-
+ lib/librte_ethdev/rte_ethdev.h             |   2 +
+ lib/librte_ethdev/rte_ethdev_driver.h      |  35 +++++
+ lib/librte_kvargs/rte_kvargs.c             |  82 +++++++----
+ 14 files changed, 306 insertions(+), 104 deletions(-)
+
+-- 
+2.25.1
+
lib/librte_ethdev/ethdev_private.c +5 -1
index 3e455acea9..a0fc187378 100644
@@ -93,16 +93,20 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
 }
 
 /*
- * representor format:
+ * Parse representor ports, expand and update representor port ID.
+ * Representor format:
  *   #: range or single number of VF representor - legacy
  *   [[c#]pf#]vf#: VF port representor/s
  *   [[c#]pf#]sf#: SF port representor/s
+ *
+ * See RTE_ETH_REPR() for representor ID format.
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
 {
 	struct rte_eth_devargs *eth_da = data;
 	int ret;
+	uint32_t c, p, f, i = 0;
 
 	eth_da->type = RTE_ETH_REPRESENTOR_NONE;
 	if (str[0] == 'c') {

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 147

Quoted 8 lines
lib/librte_ethdev/ethdev_private.c +5 -0
@@ -136,6 +140,42 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	}
 	ret = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
+	if (ret < 0)
+		goto err;
+
+	/* Set default values, expand and update representor ID. */
+	if (!eth_da->nb_mh_controllers) {

DPDK coding style requires to compare vs 0 expliticly.

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 151

Quoted 4 lines
lib/librte_ethdev/ethdev_private.c +4 -0
+		eth_da->nb_mh_controllers = 1;
+		eth_da->mh_controllers[0] = 0;
+	}
+	if (!eth_da->nb_ports) {

DPDK coding style requires to compare vs 0 expliticly.

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 155

Quoted 4 lines
lib/librte_ethdev/ethdev_private.c +4 -0
+		eth_da->nb_ports = 1;
+		eth_da->ports[0] = 0;
+	}
+	if (!eth_da->nb_representor_ports) {

DPDK coding style requires to compare vs 0 expliticly.

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 166

Quoted 11 lines
lib/librte_ethdev/ethdev_private.c +11 -0
+		eth_da->nb_representor_ports = 1;
+		eth_da->representor_ports[0] = 0;
+	}
+	for (c = 0; c < eth_da->nb_mh_controllers; ++c) {
+		for (p = 0; p < eth_da->nb_ports; ++p) {
+			for (f = 0; f < eth_da->nb_representor_ports; ++f) {
+				i = c * eth_da->nb_ports *
+					eth_da->nb_representor_ports +
+				    p * eth_da->nb_representor_ports + f;
+				if (i >= RTE_DIM(eth_da->representor_ports)) {
+					RTE_LOG(ERR, EAL, "too many representor specified: %s",

Missing \n

Quoted 49 lines
lib/librte_ethdev/ethdev_private.c +12 -0
+						str);
+					return -EINVAL;
+				}
+				eth_da->representor_ports[i] = RTE_ETH_REPR(
+					eth_da->mh_controllers[c],
+					eth_da->ports[p],
+					eth_da->type == RTE_ETH_REPRESENTOR_SF,
+					eth_da->representor_ports[f]);
+			}
+		}
+	}
+	eth_da->nb_representor_ports = i + 1;
 err:
 	if (ret < 0)
 		RTE_LOG(ERR, EAL, "wrong representor format: %s", str);
lib/librte_ethdev/rte_ethdev_driver.h +22 -0
index a7969c9408..dbad55c704 100644
@@ -1218,6 +1218,28 @@ struct rte_eth_devargs {
 	enum rte_eth_representor_type type; /* type of representor */
 };
 
+/**
+ * Encoding representor port ID.
+ *
+ * The compact format is used for device iterator that comparing
+ * ethdev representor ID with target devargs.
+ *
+ * xxxx xxxx xxxx xxxx
+ * |||| |LLL LLLL LLLL vf/sf id
+ * |||| L 1:sf, 0:vf
+ * ||LL pf id
+ * LL controller(host) id
+ */
+#define RTE_ETH_REPR(c, pf, sf, port) \
+	((((c) & 3) << 14) |     \
+	(((pf) & 3) << 12) |     \
+	(!!(sf) << 11) |         \
+	((port) & 0x7ff))
+/** Get 'pf' port id from representor ID */
+#define RTE_ETH_REPR_PF(repr) (((repr) >> 12) & 3)
+/** Get 'vf' or 'sf' port from representor ID */
+#define RTE_ETH_REPR_PORT(repr) ((repr) & 0x7ff)
+
 /**
  * PMD helper function to parse ethdev arguments
  *
#196 lore raw

Re: [dpdk-dev] [RFC 2/7] ethdev: support multi-host representor

In reply to Xueming Li
Quoted 9 lines · Xueming Li

This patch introduce multi-host controller for ethdev representor syntax, examples:

[[c#]pf#]vf#: VF port representor/s, example: pf0vf1 [[c#]pf#]sf#: SF port representor/s, example: c1pf1sf[0-3]

c# is controller ID/range in case of multi-host, optional. It is mostly for SmartNIC attached to multiple hosts in the same rack to allow routing the packets between PF/SF/VF running on these hosts.

There is a big question here what is the controller ID and how to explain it to end-user (e.g. OvS admin) which one is 0 and which one is 1, etc.

Quoted 56 lines
---
 config/rte_config.h                   |  1 +
 lib/librte_ethdev/ethdev_private.c    | 13 +++++++++++--
 lib/librte_ethdev/rte_ethdev_driver.h |  4 ++++
 3 files changed, 16 insertions(+), 2 deletions(-)
config/rte_config.h +1 -0
index a0b5160ff2..23d02d51ef 100644
@@ -58,6 +58,7 @@
 #define RTE_MAX_QUEUES_PER_PORT 1024
 #define RTE_ETHDEV_QUEUE_STAT_CNTRS 16 /* max 256 */
 #define RTE_ETHDEV_RXTX_CALLBACKS 1
+#define RTE_MAX_MULTI_HOST_CTRLS 4
 
 /* cryptodev defines */
 #define RTE_CRYPTO_MAX_DEVS 64
lib/librte_ethdev/ethdev_private.c +11 -2
index 2a057c5f36..3e455acea9 100644
@@ -95,8 +95,8 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
 /*
  * representor format:
  *   #: range or single number of VF representor - legacy
- *   [pf#]vf#: VF port representor/s
- *   [pf#]sf#: SF port representor/s
+ *   [[c#]pf#]vf#: VF port representor/s
+ *   [[c#]pf#]sf#: SF port representor/s
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
@@ -105,6 +105,15 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	int ret;
 
 	eth_da->type = RTE_ETH_REPRESENTOR_NONE;
+	if (str[0] == 'c') {
+		str += 1;
+		ret = rte_eth_devargs_process_list(str, eth_da->mh_controllers,
+				&eth_da->nb_mh_controllers,
+				RTE_DIM(eth_da->mh_controllers));
+		if (ret < 0)
+			goto err;
+		str += ret;
+	}
 	/* parse pf# */
 	if (str[0] == 'p' && str[1] == 'f') {
 		str += 2;
lib/librte_ethdev/rte_ethdev_driver.h +0 -0
index edb000cbd4..a7969c9408 100644

lib/librte_ethdev/rte_ethdev_driver.h enum rte_eth_representor_type { · line 1209

Quoted 7 lines
lib/librte_ethdev/rte_ethdev_driver.h +4 -0
@@ -1203,6 +1203,10 @@ enum rte_eth_representor_type {
 
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
+	uint16_t mh_controllers[RTE_MAX_MULTI_HOST_CTRLS];
+	/** controller/s number in case of multi-host */
+	uint16_t nb_mh_controllers;
+	/** number of controllers in multi-host contollerss field */

Typo: contollerss

Quoted 4 lines
lib/librte_ethdev/rte_ethdev_driver.h +0 -0
 	uint16_t ports[RTE_MAX_ETHPORTS];
 	/** port/s number to enable on a multi-port single function */
 	uint16_t nb_ports;
#206 lore raw
In reply to Xueming Li
Quoted 15 lines · Xueming Li

SubFunction [1] is a portion of the PCI device, a SF netdev has its own dedicated queues(txq, rxq). A SF netdev supports eswitch representation offload similar to existing PF and VF representors. A SF shares PCI level resources with other SFs and/or with its parent PCI function.

Quoted 1 line

From SmartNIC perspective, when PCI device is shared for multi-host,

representors for host controller and host PF is required.

This patch set introduces new representor types in addtion to existing VF representor. Syntax:

[[c#]pf#]vf#: VF port representor/s from controller/pf [[c#]pf#]sf#: SF port representor/s from controller/pf #: VF representor - for backwards compatibility

Quoted 5 lines

"#" is number instance, list or range, valid examples:
1, [1,3,5], [0-3], [0,2-4,6]

For flexibility, this patch also introduces new netdev capability to indicate the capability to support new representor types.

Many thanks for sharing the patchset. Looks very interesting. I've already sent my comments and questions for individual patches.

Quoted 2 lines

[1]:
https://lore.kernel.org/netdev/[email protected]/

[snip]

#207 lore raw

Hi Andrew,

Quoted 27 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Monday, December 28, 2020 9:45 PM
To: Xueming(Steven) Li <[email protected]>; Slava Ovsiienko <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Olivier Matz <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Asaf Penso <[email protected]>
Subject: Re: [RFC 0/7] support SubFunction representor

Quoted 4 lines · Xueming Li

SubFunction [1] is a portion of the PCI device, a SF netdev has its own dedicated queues(txq, rxq). A SF netdev supports eswitch representation offload similar to existing PF and VF representors. A SF shares PCI level resources with other SFs and/or with its parent PCI

function.

Quoted 11 lines
Quoted 2 lines

From SmartNIC perspective, when PCI device is shared for multi-host,

representors for host controller and host PF is required.

This patch set introduces new representor types in addtion to existing VF representor. Syntax:

[[c#]pf#]vf#: VF port representor/s from controller/pf [[c#]pf#]sf#: SF port representor/s from controller/pf #: VF representor - for backwards compatibility

Quoted 8 lines
Quoted 5 lines

"#" is number instance, list or range, valid examples:
1, [1,3,5], [0-3], [0,2-4,6]

For flexibility, this patch also introduces new netdev capability to indicate the capability to support new representor types.

Many thanks for sharing the patchset. Looks very interesting. I've already sent my comments and questions for individual patches.

Appreciate for the wonderful review, will address them next week.

Quoted 5 lines
Quoted 3 lines

[1]:
https://lore.kernel.org/netdev/[email protected]/

[snip]

#208 lore raw

30/12/2020 09:54, Xueming(Steven) Li:

Quoted 23 lines

Hi Andrew,

From: Andrew Rybchenko <[email protected]>

Quoted 20 lines · Xueming Li
Quoted 4 lines

SubFunction [1] is a portion of the PCI device, a SF netdev has its own dedicated queues(txq, rxq). A SF netdev supports eswitch representation offload similar to existing PF and VF representors. A SF shares PCI level resources with other SFs and/or with its parent PCI

function.

Quoted 14 lines
Quoted 2 lines

From SmartNIC perspective, when PCI device is shared for multi-host,

representors for host controller and host PF is required.

This patch set introduces new representor types in addtion to existing VF representor. Syntax:

[[c#]pf#]vf#: VF port representor/s from controller/pf [[c#]pf#]sf#: SF port representor/s from controller/pf #: VF representor - for backwards compatibility

"#" is number instance, list or range, valid examples:
1, [1,3,5], [0-3], [0,2-4,6]

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

For flexibility, this patch also introduces new netdev capability to indicate the capability to support new representor types.

Many thanks for sharing the patchset. Looks very interesting. I've already sent my comments and questions for individual patches.

Appreciate for the wonderful review, will address them next week.

I agree, good review, thanks.
I am waiting for a v2.

#199 lore raw

Re: [dpdk-dev] [RFC 3/7] devarg: change reprsentor ID to bitmap

In reply to Andrew Rybchenko

Hi Andrew,

Quoted 24 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Monday, December 28, 2020 9:37 PM
To: Xueming(Steven) Li <[email protected]>; Slava Ovsiienko <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Olivier Matz <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Asaf Penso <[email protected]>
Subject: Re: [RFC 3/7] devarg: change reprsentor ID to bitmap

Quoted 1 line · Xueming Li

In eth representor comparer callback, ethdev was compared with devarg.

comparer -> comparator?

Quoted 9 lines

Since ethdev representor port didn't contain controller(host) and owner port information, callback only compared representor port and returned representor port on other PF port.

This patch changes representor port to bitmap encoding, expands and updates representor port ID after parsing, when device representor ID uses the same bitmap encoding, the eth representor comparer callback returns correct ethdev.

Quoted 8 lines
Quoted 6 lines

Representor port ID bitmap definition:
Representor ID bitmap:
xxxx xxxx xxxx xxxx

 |||| |LLL LLLL LLLL vf/sf id
 |||| L 1:sf, 0:vf
 ||LL pf id

Just 2 bits for PF ID is definitely not future proof.

Yes, this is a valid concern, to keep ABI compatibility, need to wait next LTS to change it to u32 or u64.

Quoted 8 lines
Quoted 2 lines

LL controller(host) id

Same here.

In general, I'm not sure that such approch with bitmap makes sense. I think we need a new API which returns information about available functions which could be represented and IDs there could be used as representor IDs.

Agree, will introduce rte_eth_representor_id_encode() and rte_eth_representor_id_parse() in next vesion.

Quoted 184 lines
Quoted 5 lines
---
 0000-cover-letter.patch               | 44 +++++++++++++++++++++++++++

I guess it should not be added to the changeset.

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char

Quoted 82 lines
 lib/librte_ethdev/ethdev_private.c    | 42 ++++++++++++++++++++++++-
 lib/librte_ethdev/rte_ethdev_driver.h | 22 ++++++++++++++
 3 files changed, 107 insertions(+), 1 deletion(-)  create mode 100644

0000-cover-letter.patch

0000-cover-letter.patch new renamed from 0000-cover-letter.patch +0 -0

file mode 100644 index 0000000000..3f8ce2be72

0000-cover-letter.patch new file +45 -0
@@ -0,0 +1,44 @@
+From 4e1f8fc062fa6813e0b57f78ad72760601ca1d98 Mon Sep 17 00:00:00
+2001
+From: Xueming Li <[email protected]>
+Date: Fri, 18 Dec 2020 22:31:53 +0800
+Subject: [RFC 0/7] *** SUBJECT HERE ***
+To: Viacheslav Ovsiienko <[email protected]>,
+    Thomas Monjalon <[email protected]>,
+    Ferruh Yigit <[email protected]>,
+    Andrew Rybchenko <[email protected]>,
+    Olivier Matz <[email protected]>,
+    Matan Azrad <[email protected]>
+Cc: [email protected],
+    [email protected],
+    Asaf Penso <[email protected]>
+
+*** BLURB HERE ***
+
+Xueming Li (7):
+  ethdev: support sub function representor
+  ethdev: support multi-host representor
+  devarg: change reprsentor ID to bitmap
+  ethdev: capability for new representor syntax
+  kvargs: update parser for new representor syntax
+  common/mlx5: update representor name parsing
+  net/mlx5: support representor of sub function
+
+ config/rte_config.h                        |   1 +
+ drivers/common/mlx5/linux/mlx5_common_os.c |  32 ++--
+ drivers/common/mlx5/linux/mlx5_nl.c        |   2 +
+ drivers/common/mlx5/mlx5_common.h          |   2 +
+ drivers/net/mlx5/linux/mlx5_ethdev_os.c    |   5 +
+ drivers/net/mlx5/linux/mlx5_os.c           |  69 ++++++++-
+ drivers/net/mlx5/mlx5_ethdev.c             |   2 +
+ lib/librte_ethdev/ethdev_private.c         | 163 ++++++++++++++-------
+ lib/librte_ethdev/ethdev_private.h         |   3 -
+ lib/librte_ethdev/rte_class_eth.c          |   7 +-
+ lib/librte_ethdev/rte_ethdev.c             |   5 +-
+ lib/librte_ethdev/rte_ethdev.h             |   2 +
+ lib/librte_ethdev/rte_ethdev_driver.h      |  35 +++++
+ lib/librte_kvargs/rte_kvargs.c             |  82 +++++++----
+ 14 files changed, 306 insertions(+), 104 deletions(-)
+
+--
+2.25.1
+
lib/librte_ethdev/ethdev_private.c +5 -1
index 3e455acea9..a0fc187378 100644
@@ -93,16 +93,20 @@ rte_eth_devargs_process_list(char *str, uint16_t
 *list, uint16_t *len_list,  }
 
 /*
- * representor format:
+ * Parse representor ports, expand and update representor port ID.
+ * Representor format:
  *   #: range or single number of VF representor - legacy
  *   [[c#]pf#]vf#: VF port representor/s
  *   [[c#]pf#]sf#: SF port representor/s
+ *
+ * See RTE_ETH_REPR() for representor ID format.
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)  {
 	struct rte_eth_devargs *eth_da = data;
 	int ret;
+	uint32_t c, p, f, i = 0;
 
 	eth_da->type = RTE_ETH_REPRESENTOR_NONE;
 	if (str[0] == 'c') {
@@ -136,6 +140,42 @@ rte_eth_devargs_parse_representor_ports(char

*str, void *data)

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 147

Quoted 8 lines
lib/librte_ethdev/ethdev_private.c +5 -0
 	}
 	ret = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
+	if (ret < 0)
+		goto err;
+
+	/* Set default values, expand and update representor ID. */
+	if (!eth_da->nb_mh_controllers) {

DPDK coding style requires to compare vs 0 expliticly.

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 151

Quoted 4 lines
lib/librte_ethdev/ethdev_private.c +4 -0
+		eth_da->nb_mh_controllers = 1;
+		eth_da->mh_controllers[0] = 0;
+	}
+	if (!eth_da->nb_ports) {

DPDK coding style requires to compare vs 0 expliticly.

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 155

Quoted 4 lines
lib/librte_ethdev/ethdev_private.c +4 -0
+		eth_da->nb_ports = 1;
+		eth_da->ports[0] = 0;
+	}
+	if (!eth_da->nb_representor_ports) {

DPDK coding style requires to compare vs 0 expliticly.

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data)

Quoted 10 lines
lib/librte_ethdev/ethdev_private.c +10 -0
+		eth_da->nb_representor_ports = 1;
+		eth_da->representor_ports[0] = 0;
+	}
+	for (c = 0; c < eth_da->nb_mh_controllers; ++c) {
+		for (p = 0; p < eth_da->nb_ports; ++p) {
+			for (f = 0; f < eth_da->nb_representor_ports; ++f) {
+				i = c * eth_da->nb_ports *
+					eth_da->nb_representor_ports +
+				    p * eth_da->nb_representor_ports + f;
+				if (i >= RTE_DIM(eth_da->representor_ports))

{

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char · line 166

Quoted 1 line
lib/librte_ethdev/ethdev_private.c +1 -0
+					RTE_LOG(ERR, EAL, "too many

representor specified: %s",

Missing \n

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data)

Quoted 4 lines
lib/librte_ethdev/ethdev_private.c +4 -0
+						str);
+					return -EINVAL;
+				}
+				eth_da->representor_ports[i] =

RTE_ETH_REPR(

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data)

Quoted 3 lines
lib/librte_ethdev/ethdev_private.c +3 -0
+					eth_da->mh_controllers[c],
+					eth_da->ports[p],
+					eth_da->type ==

RTE_ETH_REPRESENTOR_SF,

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data)

Quoted 8 lines
lib/librte_ethdev/ethdev_private.c +5 -0
+					eth_da->representor_ports[f]);
+			}
+		}
+	}
+	eth_da->nb_representor_ports = i + 1;
 err:
 	if (ret < 0)
 		RTE_LOG(ERR, EAL, "wrong representor format: %s", str); diff -

-git

Quoted 34 lines

a/lib/librte_ethdev/rte_ethdev_driver.h
b/lib/librte_ethdev/rte_ethdev_driver.h
index a7969c9408..dbad55c704 100644

lib/librte_ethdev/rte_ethdev_driver.h +22 -0
@@ -1218,6 +1218,28 @@ struct rte_eth_devargs {
 	enum rte_eth_representor_type type; /* type of representor */  };
 
+/**
+ * Encoding representor port ID.
+ *
+ * The compact format is used for device iterator that comparing
+ * ethdev representor ID with target devargs.
+ *
+ * xxxx xxxx xxxx xxxx
+ * |||| |LLL LLLL LLLL vf/sf id
+ * |||| L 1:sf, 0:vf
+ * ||LL pf id
+ * LL controller(host) id
+ */
+#define RTE_ETH_REPR(c, pf, sf, port) \
+	((((c) & 3) << 14) |     \
+	(((pf) & 3) << 12) |     \
+	(!!(sf) << 11) |         \
+	((port) & 0x7ff))
+/** Get 'pf' port id from representor ID */ #define
+RTE_ETH_REPR_PF(repr) (((repr) >> 12) & 3)
+/** Get 'vf' or 'sf' port from representor ID */ #define
+RTE_ETH_REPR_PORT(repr) ((repr) & 0x7ff)
+
 /**
  * PMD helper function to parse ethdev arguments
  *
 
author
#8 lore raw

PATCH v2 2/9 ethdev: support new VF representor syntax

In reply to Xueming Li

To prepare for more representor types, this patch adds compatible VF representor devargs syntax:

vf#: new VF port representor/s, example: vf[0-3], vf2

For backwards compatibility, representor "#" is deemed as "vf#".

---
 doc/guides/prog_guide/poll_mode_drv.rst | 6 +++---
 lib/librte_ethdev/ethdev_private.c      | 5 ++++-
 2 files changed, 7 insertions(+), 4 deletions(-)
doc/guides/prog_guide/poll_mode_drv.rst +3 -3
index 239ec820ea..979a2bab9d 100644
@@ -374,9 +374,9 @@ parameters to those ports.
   this argument allows user to specify which switch ports to enable port
   representors for.::
 
-   -a DBDF,representor=0
-   -a DBDF,representor=[0,4,6,9]
-   -a DBDF,representor=[0-31]
+   -a DBDF,representor=vf0
+   -a DBDF,representor=vf[0,4,6,9]
+   -a DBDF,representor=vf[0-31]
 
 Note: PMDs are not required to support the standard device arguments and users
 should consult the relevant PMD documentation to see support devargs.
lib/librte_ethdev/ethdev_private.c +4 -1
index c219164a4a..54f565ca37 100644
@@ -95,6 +95,7 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
 /*
  * representor format:
  *   #: range or single number of VF representor - legacy
+ *   vf#: VF port representor/s
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
@@ -102,8 +103,10 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	struct rte_eth_devargs *eth_da = data;
 	int ret;
 
-	/* Number # alone implies VF */
+	/* Parse vf# or number # alone implies VF */
 	eth_da->type = RTE_ETH_REPRESENTOR_VF;
+	if (str[0] == 'v'  && str[1] == 'f')
+		str += 2;
 	ret = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
 	if (ret < 0)
Signature · 1 line
2.25.1
author
#14 lore raw

PATCH v2 8/9 kvargs: update parser for new representor syntax

In reply to Xueming Li

This patch updates kvargs parser to allow comma in list value:
k1=a[1,2]b[3-5]

---
 lib/librte_kvargs/rte_kvargs.c | 83 +++++++++++++++++++++++-----------
 1 file changed, 57 insertions(+), 26 deletions(-)
lib/librte_kvargs/rte_kvargs.c +57 -26
index 285081c86c..4053989157 100644
@@ -5,6 +5,7 @@
 
 #include <string.h>
 #include <stdlib.h>
+#include <stdbool.h>
 
 #include <rte_string_fns.h>
 
@@ -13,15 +14,19 @@
 /*
  * Receive a string with a list of arguments following the pattern
  * key=value,key=value,... and insert them into the list.
- * strtok() is used so the params string will be copied to be modified.
+ * Params string will be copied to be modified.
+ * list "[]" and list element splitter ",", "-" is treated as value.
+ * Supported examples:
+ *   k1=v1,k2=v2
+ *   v1
+ *   k1=x[0-1]y[1,3-5,9]z
  */
 static int
 rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
 {
 	unsigned i;
-	char *str;
-	char *ctx1 = NULL;
-	char *ctx2 = NULL;
+	char *str, *start;
+	bool in_list = false, end_k = false, end_v = false;
 
 	/* Copy the const char *params to a modifiable string
 	 * to pass to rte_strsplit
@@ -32,36 +37,62 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
 
 	/* browse each key/value pair and add it in kvlist */
 	str = kvlist->str;
-	while ((str = strtok_r(str, RTE_KVARGS_PAIRS_DELIM, &ctx1)) != NULL) {
+	start = str; /* start of current key or value */
+	while (1) {
+		switch (*str) {
+		case '=': /* End of key. */
+			end_k = true;
+			break;
+		case ',':
+			/* End of value, skip comma in middle of range */
+			if (!in_list)
+				end_v = true;
+			break;
+		case '[': /* Start of list. */
+			in_list = true;
+			break;
+		case ']': /* End of list.  */
+			if (in_list)
+				in_list = false;
+			break;
+		case 0: /* End of string */
+			end_v = true;
+			break;
+		default:
+			break;
+		}
+
+		if (!end_k && !end_v) {
+			/* Continue if not end of key or value. */
+			str++;
+			continue;
+		}
 
 		i = kvlist->count;
 		if (i >= RTE_KVARGS_MAX)
 			return -1;
 
-		kvlist->pairs[i].key = strtok_r(str, RTE_KVARGS_KV_DELIM, &ctx2);
-		kvlist->pairs[i].value = strtok_r(NULL, RTE_KVARGS_KV_DELIM, &ctx2);
-		if (kvlist->pairs[i].key == NULL ||
-		    kvlist->pairs[i].value == NULL)
-			return -1;
-
-		/* Detect list [a,b] to skip comma delimiter in list. */
-		str = kvlist->pairs[i].value;
-		if (str[0] == '[') {
-			/* Find the end of the list. */
-			while (str[strlen(str) - 1] != ']') {
-				/* Restore the comma erased by strtok_r(). */
-				if (ctx1 == NULL || ctx1[0] == '\0')
-					return -1; /* no closing bracket */
-				str[strlen(str)] = ',';
-				/* Parse until next comma. */
-				str = strtok_r(NULL, RTE_KVARGS_PAIRS_DELIM, &ctx1);
-				if (str == NULL)
-					return -1; /* no closing bracket */
+		if (start == str) /* Empty key  or value. */
+			start = NULL;
+
+		if (end_k) {
+			/* Key parsed. */
+			kvlist->pairs[i].key = start;
+			end_k = false;
+		} else if (end_v) {
+			/* Allow single key or single value. */
+			if (kvlist->pairs[i].key || start) {
+				kvlist->pairs[i].value = start;
+				kvlist->count++;
 			}
+			end_v = false;
 		}
 
-		kvlist->count++;
-		str = NULL;
+		if (*str == '\0') /* End of string. */
+			break;
+		*str = '\0';
+		str++;
+		start = str;
 	}
 
 	return 0;
Signature · 1 line
2.25.1
author
#4 lore raw

PATCH v2 1/9 ethdev: refactor representor infrastructure

In reply to Xueming Li

To support extended representor syntax, this patch refactor represntor infrastructure:
1. introduces representor type enum
2. devargs representor port range extraction from partial value

---
 drivers/net/bnxt/bnxt_ethdev.c        | 12 ++++
 drivers/net/enic/enic_ethdev.c        |  7 ++
 drivers/net/i40e/i40e_ethdev.c        |  8 +++
 drivers/net/ixgbe/ixgbe_ethdev.c      |  8 +++
 drivers/net/mlx5/linux/mlx5_os.c      | 11 ++++
 lib/librte_ethdev/ethdev_private.c    | 93 ++++++++++++---------------
 lib/librte_ethdev/ethdev_private.h    |  3 -
 lib/librte_ethdev/rte_class_eth.c     |  4 +-
 lib/librte_ethdev/rte_ethdev.c        |  5 +-
 lib/librte_ethdev/rte_ethdev_driver.h |  7 ++
 10 files changed, 98 insertions(+), 60 deletions(-)
drivers/net/bnxt/bnxt_ethdev.c +12 -0
index 81c8f8d79d..844a6c3c66 100644
@@ -5520,6 +5520,18 @@ static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev,
 	int i, ret = 0;
 	struct rte_kvargs *kvlist = NULL;
 
+	if (eth_da->type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da->type != RTE_ETH_REPRESENTOR_VF) {
+		PMD_DRV_LOG(ERR, "unsupported representor type %d\n",
+			    eth_da->type);
+		return -ENOTSUP;
+	}
+	if (eth_da->type != RTE_ETH_REPRESENTOR_VF) {
+		PMD_DRV_LOG(ERR, "unsupported representor type %d\n",
+			    eth_da->type);
+		return -EINVAL;
+	}
 	num_rep = eth_da->nb_representor_ports;
 	if (num_rep > BNXT_MAX_VF_REPS) {
 		PMD_DRV_LOG(ERR, "nb_representor_ports = %d > %d MAX VF REPS\n",
drivers/net/enic/enic_ethdev.c +7 -0
index d041a6bee9..dd085caa93 100644
@@ -1303,6 +1303,13 @@ static int eth_enic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 		if (retval)
 			return retval;
 	}
+	if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+		ENICPMD_LOG(ERR, "unsupported representor type: %s\n",
+			    pci_dev->device.devargs->args);
+		return -ENOTSUP;
+	}
 	retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
 		sizeof(struct enic),
 		eth_dev_pci_specific_init, pci_dev,
drivers/net/i40e/i40e_ethdev.c +8 -0
index f54769c29d..05ed2e1079 100644
@@ -640,6 +640,14 @@ eth_i40e_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 			return retval;
 	}
 
+	if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+		PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
+			    pci_dev->device.devargs->args);
+		return -ENOTSUP;
+	}
+
 	retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
 		sizeof(struct i40e_adapter),
 		eth_dev_pci_specific_init, pci_dev,
drivers/net/ixgbe/ixgbe_ethdev.c +8 -0
index 9a47a8b262..9ea0139197 100644
@@ -1717,6 +1717,14 @@ eth_ixgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 	} else
 		memset(&eth_da, 0, sizeof(eth_da));
 
+	if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+		PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
+			    pci_dev->device.devargs->args);
+		return -ENOTSUP;
+	}
+
 	retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
 		sizeof(struct ixgbe_adapter),
 		eth_dev_pci_specific_init, pci_dev,
drivers/net/mlx5/linux/mlx5_os.c +11 -0
index 6812a1f215..6981ba1f41 100644
@@ -706,6 +706,17 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 				strerror(rte_errno));
 			return NULL;
 		}
+		if (eth_da.type != RTE_ETH_REPRESENTOR_NONE) {
+			/* Representor not specified. */
+			rte_errno = EBUSY;
+			return NULL;
+		}
+		if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+			rte_errno = ENOTSUP;
+			DRV_LOG(ERR, "unsupported representor type: %s",
+				dpdk_dev->devargs->args);
+			return NULL;
+		}
 		for (i = 0; i < eth_da.nb_representor_ports; ++i)
 			if (eth_da.representor_ports[i] ==
 			    (uint16_t)switch_info->port_name)
lib/librte_ethdev/ethdev_private.c +42 -51

123 lines not on this page · raw message

lib/librte_ethdev/ethdev_private.h +0 -3
index 905a45c337..220ddd4408 100644
@@ -26,9 +26,6 @@ eth_find_device(const struct rte_eth_dev *_start, rte_eth_cmp_t cmp,
 		const void *data);
 
 /* Parse devargs value for representor parameter. */
-typedef int (*rte_eth_devargs_callback_t)(char *str, void *data);
-int rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
-	void *data);
 int rte_eth_devargs_parse_representor_ports(char *str, void *data);
 
 #ifdef __cplusplus
lib/librte_ethdev/rte_class_eth.c +1 -3
index 6338355e25..efe6149df5 100644
@@ -77,9 +77,7 @@ eth_representor_cmp(const char *key __rte_unused,
 	if (values == NULL)
 		return -1;
 	memset(&representors, 0, sizeof(representors));
-	ret = rte_eth_devargs_parse_list(values,
-			rte_eth_devargs_parse_representor_ports,
-			&representors);
+	ret = rte_eth_devargs_parse_representor_ports(values, &representors);
 	free(values);
 	if (ret != 0)
 		return -1; /* invalid devargs value */
lib/librte_ethdev/rte_ethdev.c +2 -3
index 17ddacc78d..2ac51ac149 100644
@@ -5542,9 +5542,8 @@ rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
 	for (i = 0; i < args.count; i++) {
 		pair = &args.pairs[i];
 		if (strcmp("representor", pair->key) == 0) {
-			result = rte_eth_devargs_parse_list(pair->value,
-				rte_eth_devargs_parse_representor_ports,
-				eth_da);
+			result = rte_eth_devargs_parse_representor_ports(
+					pair->value, eth_da);
 			if (result < 0)
 				goto parse_cleanup;
 		}
lib/librte_ethdev/rte_ethdev_driver.h +7 -0
index 0eacfd8425..b66a955b18 100644
@@ -1193,6 +1193,12 @@ __rte_internal
 int
 rte_eth_switch_domain_free(uint16_t domain_id);
 
+/** Ethernet device representor type */
+enum rte_eth_representor_type {
+	RTE_ETH_REPRESENTOR_NONE, /* not a representor */
+	RTE_ETH_REPRESENTOR_VF,   /* representor of VF */
+};
+
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
 	uint16_t ports[RTE_MAX_ETHPORTS];
@@ -1203,6 +1209,7 @@ struct rte_eth_devargs {
 	/** representor port/s identifier to enable on device */
 	uint16_t nb_representor_ports;
 	/** number of ports in representor port field */
+	enum rte_eth_representor_type type; /* type of representor */
 };
 
 /**
Signature · 1 line
2.25.1
author
#15 lore raw

PATCH v2 9/9 eal: allow PCI device with different representors

In reply to Xueming Li

When probing same PCI device with different representor arguments, PCI bus on probed first devargs, ignored other allowed devices with different representor arguments.

This patch iterates all devargs and try them all after PCI bus scan.

---
 lib/librte_eal/common/eal_common_bus.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
lib/librte_eal/common/eal_common_bus.c +25 -0
index baa5b532af..47c0243647 100644
@@ -10,6 +10,7 @@
 #include <rte_debug.h>
 #include <rte_string_fns.h>
 #include <rte_errno.h>
+#include <rte_devargs.h>
 
 #include "eal_private.h"
 
@@ -56,12 +57,22 @@ rte_bus_scan(void)
 	return 0;
 }
 
+static int
+cmp_dev_name(const struct rte_device *dev, const void *_name)
+{
+	const char *name = _name;
+
+	return strcmp(dev->name, name);
+}
+
 /* Probe all devices of all buses */
 int
 rte_bus_probe(void)
 {
 	int ret;
 	struct rte_bus *bus, *vbus = NULL;
+	struct rte_devargs *da;
+	struct rte_device *dev;
 
 	TAILQ_FOREACH(bus, &rte_bus_list, next) {
 		if (!strcmp(bus->name, "vdev")) {
@@ -82,6 +93,20 @@ rte_bus_probe(void)
 				vbus->name);
 	}
 
+	/* For devargs with same name but different arguments, try them all. */
+	RTE_EAL_DEVARGS_FOREACH("pci", da) {
+		dev = da->bus->find_device(NULL, cmp_dev_name, da->name);
+		if (!dev || !rte_dev_is_probed(dev) || dev->devargs == da)
+			continue;
+		dev->devargs = da;
+		ret = dev->bus->plug(dev);
+		if (ret > 0)
+			ret = -ENOTSUP;
+		if (!ret && rte_dev_is_probed(dev))
+			RTE_LOG(ERR, EAL, "device probed %s %s", da->name,
+				da->args);
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.25.1
author
#3 lore raw

v2 cover support SubFunction representor

In reply to Xueming Li

SubFunction [1] is a portion of the PCI device, a SF netdev has its own dedicated queues(txq, rxq). A SF netdev supports eswitch representation offload similar to existing PF and VF representors. A SF shares PCI level resources with other SFs and/or with its parent PCI function.

From SmartNIC perspective, when PCI device is shared for multi-host, representors for host controller and host PF is required.

This patch set introduces new representor types in addtion to existing VF representor. Syntax:

[[c#]pf#]vf#: VF port representor/s from controller/pf [[c#]pf#]sf#: SF port representor/s from controller/pf #: VF representor - for backwards compatibility

"#" is number instance, list or range, valid examples:
1, [1,3,5], [0-3], [0,2-4,6]

For backward compatibility, this patch also introduces new netdev capability
to indicate the capability to support SF representor.

Version history:
RFC:
initial version [2]
V2:
- separate patch for represnetor infrastructure, controller, pf and sf.
- replace representor ID macro with functions:
rte_eth_representor_id_encode() rte_eth_representor_id_parse()
- new patch to allow devargs with same PCI BDF but different representors.
- other minor code updates according to comments, thanks Andrew!
- update document

[1] SubFunction in kernel:
https://lore.kernel.org/netdev/[email protected]/

[2] RFC:
http://patchwork.dpdk.org/project/dpdk/list/?series=14376

Xueming Li (9):
ethdev: refactor representor infrastructure
ethdev: support new VF representor syntax
ethdev: support sub function representor
ethdev: support PF index in representor
ethdev: support multi-host representor
devarg: change reprsentor ID to bitmap
ethdev: capability of new representor syntax
kvargs: update parser for new representor syntax
eal: allow PCI device with different representors

 config/rte_config.h                      |   1 +
 doc/guides/prog_guide/poll_mode_drv.rst  |   8 +-
 drivers/net/bnxt/bnxt_ethdev.c           |  12 +++
 drivers/net/bnxt/bnxt_reps.c             |   3 +-
 drivers/net/enic/enic_ethdev.c           |   7 ++
 drivers/net/enic/enic_vf_representor.c   |   3 +-
 drivers/net/i40e/i40e_ethdev.c           |   8 ++
 drivers/net/i40e/i40e_vf_representor.c   |   3 +-
 drivers/net/ixgbe/ixgbe_ethdev.c         |   8 ++
 drivers/net/ixgbe/ixgbe_vf_representor.c |   3 +-
 drivers/net/mlx5/linux/mlx5_os.c         |  15 ++-
 lib/librte_eal/common/eal_common_bus.c   |  25 +++++
 lib/librte_ethdev/ethdev_private.c       | 128 ++++++++++++++---------
 lib/librte_ethdev/ethdev_private.h       |   3 -
 lib/librte_ethdev/rte_class_eth.c        |  40 +++++--
 lib/librte_ethdev/rte_ethdev.c           |  31 +++++-
 lib/librte_ethdev/rte_ethdev.h           |   2 +
 lib/librte_ethdev/rte_ethdev_driver.h    |  64 ++++++++++++
 lib/librte_ethdev/version.map            |   2 +
 lib/librte_kvargs/rte_kvargs.c           |  83 ++++++++++-----
 20 files changed, 348 insertions(+), 101 deletions(-)
Signature · 1 line
2.25.1
author
#13 lore raw

PATCH v2 7/9 ethdev: capability of new representor syntax

New representor devargs syntax can't be recognized correctly by previous DPDK version. For application to adapt different DPDK version automatically, this patch introduces new eth device capability of supportting SubFunction representor device.

---
 lib/librte_ethdev/rte_ethdev.h | 2 ++
 1 file changed, 2 insertions(+)
lib/librte_ethdev/rte_ethdev.h +2 -0
index f5f8919186..3c087bec67 100644
@@ -1432,6 +1432,8 @@ struct rte_eth_conf {
 #define RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP 0x00000001
 /** Device supports Tx queue setup after device started. */
 #define RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP 0x00000002
+/**< Device supports SubFunction representor. */
+#define RTE_ETH_DEV_CAPA_REPRESENTOR_SF         0x00000004
 /**@}*/
 
 /*
Signature · 1 line
2.25.1
author
#9 lore raw

PATCH v2 3/9 ethdev: support sub function representor

In reply to Xueming Li

SubFunction is a portion of the PCI device, created on demand, a SF netdev has its own dedicated queues(txq, rxq). A SF netdev supports eswitch representation offload similar to existing PF and VF representors.

To support SF representor, this patch introduces new devargs syntax:

sf#: new SF port representor/s, example: sf[0-3], sf2

---
 doc/guides/prog_guide/poll_mode_drv.rst |  1 +
 lib/librte_ethdev/ethdev_private.c      | 14 +++++++++++---
 lib/librte_ethdev/rte_ethdev_driver.h   |  1 +
 3 files changed, 13 insertions(+), 3 deletions(-)
doc/guides/prog_guide/poll_mode_drv.rst +1 -0
index 979a2bab9d..831d620c8d 100644
@@ -377,6 +377,7 @@ parameters to those ports.
    -a DBDF,representor=vf0
    -a DBDF,representor=vf[0,4,6,9]
    -a DBDF,representor=vf[0-31]
+   -a DBDF,representor=sf[0-1023]
 
 Note: PMDs are not required to support the standard device arguments and users
 should consult the relevant PMD documentation to see support devargs.
lib/librte_ethdev/ethdev_private.c +11 -3
index 54f565ca37..551a43738a 100644
@@ -96,6 +96,7 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
  * representor format:
  *   #: range or single number of VF representor - legacy
  *   vf#: VF port representor/s
+ *   sf#: SF port representor/s
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
@@ -103,10 +104,17 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	struct rte_eth_devargs *eth_da = data;
 	int ret;
 
-	/* Parse vf# or number # alone implies VF */
-	eth_da->type = RTE_ETH_REPRESENTOR_VF;
-	if (str[0] == 'v'  && str[1] == 'f')
+	eth_da->type = RTE_ETH_REPRESENTOR_NONE;
+	/* Parse vf# and sf#, number # alone implies VF */
+	if (str[0] == 'v'  && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_VF;
 		str += 2;
+	} else if (str[0] == 's'  && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_SF;
+		str += 2;
+	} else {
+		eth_da->type = RTE_ETH_REPRESENTOR_VF;
+	}
 	ret = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
 	if (ret < 0)
lib/librte_ethdev/rte_ethdev_driver.h +1 -0
index b66a955b18..086d64223a 100644
@@ -1197,6 +1197,7 @@ rte_eth_switch_domain_free(uint16_t domain_id);
 enum rte_eth_representor_type {
 	RTE_ETH_REPRESENTOR_NONE, /* not a representor */
 	RTE_ETH_REPRESENTOR_VF,   /* representor of VF */
+	RTE_ETH_REPRESENTOR_SF,   /* representor of SF */
 };
 
 /** Generic Ethernet device arguments  */
Signature · 1 line
2.25.1
author
#10 lore raw

PATCH v2 4/9 ethdev: support PF index in representor

In reply to Xueming Li

To support representor in bonding, this patch introduces 'pf' section to representor devargs syntax:

[pf#]vf#: VF port representor/s, example: vf3, pf0vf3 [pf#]sf#: SF port representor/s, example: sf2, pf1sf2

pf# is optional for SF and VF representor, indicates owner PF device of SF or VF.

---
 doc/guides/prog_guide/poll_mode_drv.rst |  1 +
 lib/librte_ethdev/ethdev_private.c      | 15 +++++++++++++--
 lib/librte_ethdev/rte_ethdev_driver.h   |  1 +
 3 files changed, 15 insertions(+), 2 deletions(-)
doc/guides/prog_guide/poll_mode_drv.rst +1 -0
index 831d620c8d..87f23c4f49 100644
@@ -378,6 +378,7 @@ parameters to those ports.
    -a DBDF,representor=vf[0,4,6,9]
    -a DBDF,representor=vf[0-31]
    -a DBDF,representor=sf[0-1023]
+   -a DBDF,representor=pf[0-1]sf[0-1023]
 
 Note: PMDs are not required to support the standard device arguments and users
 should consult the relevant PMD documentation to see support devargs.
lib/librte_ethdev/ethdev_private.c +13 -2
index 551a43738a..ccc638ec49 100644
@@ -95,8 +95,8 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
 /*
  * representor format:
  *   #: range or single number of VF representor - legacy
- *   vf#: VF port representor/s
- *   sf#: SF port representor/s
+ *   [pf#]vf#: VF port representor/s
+ *   [pf#]sf#: SF port representor/s
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
@@ -105,6 +105,16 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	int ret;
 
 	eth_da->type = RTE_ETH_REPRESENTOR_NONE;
+	/* Parse pf# */
+	if (str[0] == 'p' && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_PF;
+		str += 2;
+		ret = rte_eth_devargs_process_list(str, eth_da->ports,
+				&eth_da->nb_ports, RTE_MAX_ETHPORTS);
+		if (ret < 0)
+			goto err;
+		str += ret;
+	}
 	/* Parse vf# and sf#, number # alone implies VF */
 	if (str[0] == 'v'  && str[1] == 'f') {
 		eth_da->type = RTE_ETH_REPRESENTOR_VF;
@@ -117,6 +127,7 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	}
 	ret = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
+err:
 	if (ret < 0)
 		RTE_LOG(ERR, EAL, "wrong representor format: %s\n", str);
 	return ret < 0 ? ret : 0;
lib/librte_ethdev/rte_ethdev_driver.h +1 -0
index 086d64223a..edb000cbd4 100644
@@ -1198,6 +1198,7 @@ enum rte_eth_representor_type {
 	RTE_ETH_REPRESENTOR_NONE, /* not a representor */
 	RTE_ETH_REPRESENTOR_VF,   /* representor of VF */
 	RTE_ETH_REPRESENTOR_SF,   /* representor of SF */
+	RTE_ETH_REPRESENTOR_PF,   /* representor of host PF */
 };
 
 /** Generic Ethernet device arguments  */
Signature · 1 line
2.25.1
author
#12 lore raw

PATCH v2 6/9 devarg: change reprsentor ID to bitmap

In reply to Xueming Li

In eth representor comparator callback, ethdev was compared with devarg. Since ethdev representor port didn't contain controller(host) and owner port information, callback only compared representor port and returned representor port on other PF port.

This patch changes representor port to bitmap encoding, expands and updates representor port ID after parsing, when device representor ID uses the same bitmap encoding, the eth representor comparer callback returns correct ethdev.

Representor port ID bitmap definition:
Representor ID bitmap:
xxxx xxxx xxxx xxxx

 |||| |LLL LLLL LLLL vf/sf id
 |||| L 1:sf, 0:vf
 ||LL pf id

LL controller(host) id

---
 drivers/net/bnxt/bnxt_reps.c             |  3 +-
 drivers/net/enic/enic_vf_representor.c   |  3 +-
 drivers/net/i40e/i40e_vf_representor.c   |  3 +-
 drivers/net/ixgbe/ixgbe_vf_representor.c |  3 +-
 drivers/net/mlx5/linux/mlx5_os.c         |  4 +-
 lib/librte_ethdev/ethdev_private.c       |  5 ++-
 lib/librte_ethdev/rte_class_eth.c        | 38 ++++++++++++++----
 lib/librte_ethdev/rte_ethdev.c           | 26 ++++++++++++
 lib/librte_ethdev/rte_ethdev_driver.h    | 51 ++++++++++++++++++++++++
 lib/librte_ethdev/version.map            |  2 +
 10 files changed, 124 insertions(+), 14 deletions(-)
drivers/net/bnxt/bnxt_reps.c +2 -1
index e5ba0909b9..bc3b564d06 100644
@@ -186,7 +186,8 @@ int bnxt_representor_init(struct rte_eth_dev *eth_dev, void *params)
 
 	eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
 					RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-	eth_dev->data->representor_id = rep_params->vf_id;
+	eth_dev->data->representor_id = rte_eth_representor_id_encode(
+		0, 0, RTE_ETH_REPRESENTOR_VF, rep_params->vf_id);
 
 	rte_eth_random_addr(vf_rep_bp->dflt_mac_addr);
 	memcpy(vf_rep_bp->mac_addr, vf_rep_bp->dflt_mac_addr,
drivers/net/enic/enic_vf_representor.c +2 -1
index c2c03c0281..632317af15 100644
@@ -674,7 +674,8 @@ int enic_vf_representor_init(struct rte_eth_dev *eth_dev, void *init_params)
 	eth_dev->dev_ops = &enic_vf_representor_dev_ops;
 	eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
 					RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-	eth_dev->data->representor_id = vf->vf_id;
+	eth_dev->data->representor_id = rte_eth_representor_id_encode(
+		0, 0, RTE_ETH_REPRESENTOR_VF, vf->vf_id);
 	eth_dev->data->mac_addrs = rte_zmalloc("enic_mac_addr_vf",
 		sizeof(struct rte_ether_addr) *
 		ENIC_UNICAST_PERFECT_FILTERS, 0);
drivers/net/i40e/i40e_vf_representor.c +2 -1
index 9e40406a3d..d90d0fdb9d 100644
@@ -510,7 +510,8 @@ i40e_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params)
 
 	ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
 					RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-	ethdev->data->representor_id = representor->vf_id;
+	ethdev->data->representor_id = rte_eth_representor_id_encode(
+			0, 0, RTE_ETH_REPRESENTOR_VF, representor->vf_id);
 
 	/* Setting the number queues allocated to the VF */
 	ethdev->data->nb_rx_queues = vf->vsi->nb_qps;
drivers/net/ixgbe/ixgbe_vf_representor.c +2 -1
index 8185f0d3bb..e15b794761 100644
@@ -196,7 +196,8 @@ ixgbe_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params)
 		return -ENODEV;
 
 	ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
-	ethdev->data->representor_id = representor->vf_id;
+	ethdev->data->representor_id = rte_eth_representor_id_encode(
+			0, 0, RTE_ETH_REPRESENTOR_VF, representor->vf_id);
 
 	/* Set representor device ops */
 	ethdev->dev_ops = &ixgbe_vf_representor_dev_ops;
drivers/net/mlx5/linux/mlx5_os.c +3 -1
index 6981ba1f41..7739a1b0a5 100644
@@ -1031,7 +1031,9 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 #endif
 	/* representor_id field keeps the unmodified VF index. */
 	priv->representor_id = switch_info->representor ?
-			       switch_info->port_name : -1;
+		rte_eth_representor_id_encode(0, 0, RTE_ETH_REPRESENTOR_VF,
+					      switch_info->port_name) :
+		-1;
 	/*
 	 * Look for sibling devices in order to reuse their switch domain
 	 * if any, otherwise allocate one.
lib/librte_ethdev/ethdev_private.c +4 -1
index 95f1ab847a..57e84a34af 100644
@@ -93,10 +93,13 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
 }
 
 /*
- * representor format:
+ * Parse representor ports, expand and update representor port ID.
+ * Representor format:
  *   #: range or single number of VF representor - legacy
  *   [[c#]pf#]vf#: VF port representor/s
  *   [[c#]pf#]sf#: SF port representor/s
+ *
+ * See RTE_ETH_REPR() for representor ID format.
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
lib/librte_ethdev/rte_class_eth.c +30 -8
index efe6149df5..994db96960 100644
@@ -66,8 +66,8 @@ eth_representor_cmp(const char *key __rte_unused,
 	int ret;
 	char *values;
 	const struct rte_eth_dev_data *data = opaque;
-	struct rte_eth_devargs representors;
-	uint16_t index;
+	struct rte_eth_devargs eth_da;
+	uint16_t index, c, p, f;
 
 	if ((data->dev_flags & RTE_ETH_DEV_REPRESENTOR) == 0)
 		return -1; /* not a representor port */
@@ -76,17 +76,39 @@ eth_representor_cmp(const char *key __rte_unused,
 	values = strdup(value);
 	if (values == NULL)
 		return -1;
-	memset(&representors, 0, sizeof(representors));
-	ret = rte_eth_devargs_parse_representor_ports(values, &representors);
+	memset(&eth_da, 0, sizeof(eth_da));
+	ret = rte_eth_devargs_parse_representor_ports(values, &eth_da);
 	free(values);
 	if (ret != 0)
 		return -1; /* invalid devargs value */
 
+	/* Set default values. */
+	if (eth_da.nb_mh_controllers == 0) {
+		eth_da.nb_mh_controllers = 1;
+		eth_da.mh_controllers[0] = 0;
+	}
+	if (eth_da.nb_ports == 0) {
+		eth_da.nb_ports = 1;
+		eth_da.ports[0] = 0;
+	}
+	if (eth_da.nb_representor_ports == 0) {
+		eth_da.nb_representor_ports = 1;
+		eth_da.representor_ports[0] = 0;
+	}
 	/* Return 0 if representor id is matching one of the values. */
-	for (index = 0; index < representors.nb_representor_ports; index++)
-		if (data->representor_id ==
-				representors.representor_ports[index])
-			return 0;
+	for (c = 0; c < eth_da.nb_mh_controllers; ++c) {
+		for (p = 0; p < eth_da.nb_ports; ++p) {
+			for (f = 0; f < eth_da.nb_representor_ports; ++f) {
+				index = rte_eth_representor_id_encode(
+					eth_da.mh_controllers[c],
+					eth_da.ports[p],
+					eth_da.type,
+					eth_da.representor_ports[f]);
+				if (data->representor_id == index)
+					return 0;
+			}
+		}
+	}
 	return -1; /* no match */
 }
 
lib/librte_ethdev/rte_ethdev.c +26 -0
index 2ac51ac149..276f42e54b 100644
@@ -5556,6 +5556,32 @@ rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
 	return result;
 }
 
+uint16_t
+rte_eth_representor_id_encode(uint16_t controller, uint16_t pf,
+			      enum rte_eth_representor_type type,
+			      uint16_t representor_port)
+{
+	return (((controller & 3) << 14) |
+		((pf & 3) << 12) |
+		(!!(type == RTE_ETH_REPRESENTOR_SF) << 11) |
+		(representor_port & 0x7ff));
+}
+
+uint16_t
+rte_eth_representor_id_parse(const uint16_t representor_id,
+			     uint16_t *controller, uint16_t *pf,
+			     enum rte_eth_representor_type *type)
+{
+	if (controller)
+		*controller = (representor_id >> 14) & 3;
+	if (pf)
+		*pf = (representor_id >> 12) & 3;
+	if (type)
+		*type = ((representor_id >> 11) & 1) ?
+			RTE_ETH_REPRESENTOR_SF : RTE_ETH_REPRESENTOR_VF;
+	return representor_id & 0x7ff;
+}
+
 static int
 eth_dev_handle_port_list(const char *cmd __rte_unused,
 		const char *params __rte_unused,
lib/librte_ethdev/rte_ethdev_driver.h +51 -0

57 lines not on this page · raw message

lib/librte_ethdev/version.map +2 -0
index d3f5410806..44edaed507 100644
@@ -257,6 +257,8 @@ INTERNAL {
 	rte_eth_dev_release_port;
 	rte_eth_dev_internal_reset;
 	rte_eth_devargs_parse;
+	rte_eth_representor_id_encode;
+	rte_eth_representor_id_parse;
 	rte_eth_dma_zone_free;
 	rte_eth_dma_zone_reserve;
 	rte_eth_hairpin_queue_peer_bind;
Signature · 1 line
2.25.1
author
#11 lore raw

PATCH v2 5/9 ethdev: support multi-host representor

In reply to Xueming Li

This patch introduces multi-host controller for ethdev representor syntax, examples:

[[c#]pf#]vf#: VF port representor/s, example: pf0vf1 [[c#]pf#]sf#: SF port representor/s, example: c1pf1sf[0-3]

c# is controller(host) ID/range in case of multi-host, optional. It is mostly for SmartNIC attached to multiple hosts in the same rack to allow routing the packets between PF/SF/VF running on these hosts.

Controller ID is physical host ID in multi-host, for end-user (e.g. OVS) it is transparent as part of representor syntax, sam as representor ID, interpreted by PMD.

---
 config/rte_config.h                   |  1 +
 lib/librte_ethdev/ethdev_private.c    | 14 ++++++++++++--
 lib/librte_ethdev/rte_ethdev_driver.h |  4 ++++
 3 files changed, 17 insertions(+), 2 deletions(-)
config/rte_config.h +1 -0
index a0b5160ff2..23d02d51ef 100644
@@ -58,6 +58,7 @@
 #define RTE_MAX_QUEUES_PER_PORT 1024
 #define RTE_ETHDEV_QUEUE_STAT_CNTRS 16 /* max 256 */
 #define RTE_ETHDEV_RXTX_CALLBACKS 1
+#define RTE_MAX_MULTI_HOST_CTRLS 4
 
 /* cryptodev defines */
 #define RTE_CRYPTO_MAX_DEVS 64
lib/librte_ethdev/ethdev_private.c +12 -2
index ccc638ec49..95f1ab847a 100644
@@ -95,8 +95,8 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
 /*
  * representor format:
  *   #: range or single number of VF representor - legacy
- *   [pf#]vf#: VF port representor/s
- *   [pf#]sf#: SF port representor/s
+ *   [[c#]pf#]vf#: VF port representor/s
+ *   [[c#]pf#]sf#: SF port representor/s
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
@@ -105,6 +105,16 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	int ret;
 
 	eth_da->type = RTE_ETH_REPRESENTOR_NONE;
+	/* Parse c# */
+	if (str[0] == 'c') {
+		str += 1;
+		ret = rte_eth_devargs_process_list(str, eth_da->mh_controllers,
+				&eth_da->nb_mh_controllers,
+				RTE_DIM(eth_da->mh_controllers));
+		if (ret < 0)
+			goto err;
+		str += ret;
+	}
 	/* Parse pf# */
 	if (str[0] == 'p' && str[1] == 'f') {
 		eth_da->type = RTE_ETH_REPRESENTOR_PF;
lib/librte_ethdev/rte_ethdev_driver.h +4 -0
index edb000cbd4..b9e4a0b9ba 100644
@@ -1203,6 +1203,10 @@ enum rte_eth_representor_type {
 
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
+	uint16_t mh_controllers[RTE_MAX_MULTI_HOST_CTRLS];
+	/** controller/s number in case of multi-host */
+	uint16_t nb_mh_controllers;
+	/** number of controllers in multi-host controllers field */
 	uint16_t ports[RTE_MAX_ETHPORTS];
 	/** port/s number to enable on a multi-port single function */
 	uint16_t nb_ports;
Signature · 1 line
2.25.1
author
#19 lore raw

PATCH v2 3/4 net/mlx5: revert setting representor to first PF

In reply to Xueming Li

Representors on second PF are being probed by devargs:
<primary_bdf>,representor=pf1vf<N>
No need to save primary PF port ID and lookup when probing sibling ports, revert patch [1]

[1]:
commit e6818853c022 ("net/mlx5: set representor to first PF in bonding mode")

---
 drivers/net/mlx5/linux/mlx5_os.c | 20 ++------------------
 drivers/net/mlx5/mlx5.c          |  1 -
 drivers/net/mlx5/mlx5.h          |  1 -
 3 files changed, 2 insertions(+), 20 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +2 -18
index 6f667dd747..1209bfed5b 100644
@@ -817,13 +817,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			rte_errno = ENOMEM;
 			return NULL;
 		}
-		priv = eth_dev->data->dev_private;
-		if (priv->sh->bond_dev != UINT16_MAX)
-			/* For bonding port, use primary PCI device. */
-			eth_dev->device =
-				rte_eth_devices[priv->sh->bond_dev].device;
-		else
-			eth_dev->device = dpdk_dev;
+		eth_dev->device = dpdk_dev;
 		eth_dev->dev_ops = &mlx5_dev_sec_ops;
 		eth_dev->rx_descriptor_status = mlx5_rx_descriptor_status;
 		eth_dev->tx_descriptor_status = mlx5_tx_descriptor_status;
@@ -1451,17 +1445,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 	eth_dev->data->dev_private = priv;
 	priv->dev_data = eth_dev->data;
 	eth_dev->data->mac_addrs = priv->mac;
-	if (spawn->pf_bond < 0) {
-		eth_dev->device = dpdk_dev;
-	} else {
-		/* Use primary bond PCI as device. */
-		if (sh->bond_dev == UINT16_MAX) {
-			sh->bond_dev = eth_dev->data->port_id;
-			eth_dev->device = dpdk_dev;
-		} else {
-			eth_dev->device = rte_eth_devices[sh->bond_dev].device;
-		}
-	}
+	eth_dev->device = dpdk_dev;
 	eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
 	/* Configure the first MAC address by default. */
 	if (mlx5_get_mac(eth_dev, &mac.addr_bytes)) {
drivers/net/mlx5/mlx5.c +0 -1
index 023ef50a77..628587faac 100644
@@ -917,7 +917,6 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,
 		goto error;
 	}
 	sh->refcnt = 1;
-	sh->bond_dev = UINT16_MAX;
 	sh->max_port = spawn->max_port;
 	strncpy(sh->ibdev_name, mlx5_os_get_ctx_device_name(sh->ctx),
 		sizeof(sh->ibdev_name) - 1);
drivers/net/mlx5/mlx5.h +0 -1
index 41034f5d19..a77a1600d5 100644
@@ -692,7 +692,6 @@ struct mlx5_flex_parser_profiles {
 struct mlx5_dev_ctx_shared {
 	LIST_ENTRY(mlx5_dev_ctx_shared) next;
 	uint32_t refcnt;
-	uint16_t bond_dev; /* Bond primary device id. */
 	uint32_t devx:1; /* Opened with DV. */
 	uint32_t flow_hit_aso_en:1; /* Flow Hit ASO is supported. */
 	uint32_t eqn; /* Event Queue number. */
Signature · 1 line
2.25.1
author
#17 lore raw

PATCH v2 1/4 common/mlx5: update representor name parsing

In reply to Xueming Li

This patch updates representor name parsing for SF.
In sysfs, representor name stored in from 'phys_port_name file', similar to VF representor, switch port name of SF representor is "pf<x>sf<y>".

For netlink message, net SF type is supported.

Examples:

pf0sf1
pf0sf[0-3]

---
 drivers/common/mlx5/linux/mlx5_common_os.c | 32 +++++++++++++++-------
 drivers/common/mlx5/linux/mlx5_nl.c        |  2 ++
 drivers/common/mlx5/mlx5_common.h          |  2 ++
 drivers/net/mlx5/linux/mlx5_ethdev_os.c    |  3 ++
 4 files changed, 29 insertions(+), 10 deletions(-)
drivers/common/mlx5/linux/mlx5_common_os.c +22 -10
index 0edd78ea6d..5cf9576921 100644
@@ -97,22 +97,34 @@ void
 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, eol;
+	char ctrl = 0, pf_c1, pf_c2, vf_c1, vf_c2, eol;
 	char *end;
 	int sc_items;
 
-	/*
-	 * Check for port-name as a string of the form pf0vf0
-	 * (support kernel ver >= 5.0 or OFED ver >= 4.6).
-	 */
+	sc_items = sscanf(port_name_in, "%c%d",
+			  &ctrl, &port_info_out->ctrl_num);
+	if (sc_items == 2 && ctrl == 'c') {
+		port_name_in++; /* 'c' */
+		port_name_in += snprintf(NULL, 0, "%d",
+					  port_info_out->ctrl_num);
+	}
+	/* Check for port-name as a string of the form pf0vf0 or pf0sf0 */
 	sc_items = sscanf(port_name_in, "%c%c%d%c%c%d%c",
 			  &pf_c1, &pf_c2, &port_info_out->pf_num,
 			  &vf_c1, &vf_c2, &port_info_out->port_name, &eol);
-	if (sc_items == 6 &&
-	    pf_c1 == 'p' && pf_c2 == 'f' &&
-	    vf_c1 == 'v' && vf_c2 == 'f') {
-		port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_PFVF;
-		return;
+	if (sc_items == 6 && pf_c1 == 'p' && pf_c2 == 'f') {
+		if (vf_c1 == 'v' && vf_c2 == 'f') {
+			/* Kernel ver >= 5.0 or OFED ver >= 4.6 */
+			port_info_out->name_type =
+					MLX5_PHYS_PORT_NAME_TYPE_PFVF;
+			return;
+		}
+		if (vf_c1 == 's' && vf_c2 == 'f') {
+			/* Kernel ver >= 5.11 or OFED ver >= 5.1 */
+			port_info_out->name_type =
+					MLX5_PHYS_PORT_NAME_TYPE_PFSF;
+			return;
+		}
 	}
 	/*
 	 * Check for port-name as a string of the form p0
drivers/common/mlx5/linux/mlx5_nl.c +2 -0
index 40d8620300..3d55cc98b4 100644
@@ -1148,6 +1148,8 @@ mlx5_nl_check_switch_info(bool num_vf_set,
 	case MLX5_PHYS_PORT_NAME_TYPE_PFHPF:
 		/* Fallthrough */
 	case MLX5_PHYS_PORT_NAME_TYPE_PFVF:
+		/* Fallthrough */
+	case MLX5_PHYS_PORT_NAME_TYPE_PFSF:
 		/* New representors naming schema. */
 		switch_info->representor = 1;
 		break;
drivers/common/mlx5/mlx5_common.h +2 -0
index a484b74b9c..4c75addd08 100644
@@ -153,6 +153,7 @@ enum mlx5_nl_phys_port_name_type {
 	MLX5_PHYS_PORT_NAME_TYPE_UPLINK, /* p0, kernel ver >= 5.0 */
 	MLX5_PHYS_PORT_NAME_TYPE_PFVF, /* pf0vf0, kernel ver >= 5.0 */
 	MLX5_PHYS_PORT_NAME_TYPE_PFHPF, /* pf0, kernel ver >= 5.7, HPF rep */
+	MLX5_PHYS_PORT_NAME_TYPE_PFSF, /* pf0sf0, kernel ver >= 5.0 */
 	MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN, /* Unrecognized. */
 };
 
@@ -161,6 +162,7 @@ struct mlx5_switch_info {
 	uint32_t master:1; /**< Master device. */
 	uint32_t representor:1; /**< Representor device. */
 	enum mlx5_nl_phys_port_name_type name_type; /** < Port name type. */
+	int32_t ctrl_num; /**< Controller number (valid for c#pf#vf# format). */
 	int32_t pf_num; /**< PF number (valid for pfxvfx format only). */
 	int32_t port_name; /**< Representor port name. */
 	uint64_t switch_id; /**< Switch identifier. */
drivers/net/mlx5/linux/mlx5_ethdev_os.c +3 -0
index e36a78091c..1b37970c21 100644
@@ -1013,6 +1013,9 @@ mlx5_sysfs_check_switch_info(bool device_dir,
 		/* New representors naming schema. */
 		switch_info->representor = 1;
 		break;
+	default:
+		switch_info->master = device_dir;
+		break;
 	}
 }
 
Signature · 1 line
2.25.1
author
#16 lore raw

v2 cover net/mlx5: support SubFunction representor

In reply to Xueming Li

SubFunction [1] is a portion of the PCI device, a SF netdev has its own dedicated queues(txq, rxq). A SF netdev supports eswitch representation offload similar to existing PF and VF representors. A SF shares PCI level resources with other SFs and/or with its parent PCI function.

This patch set introduces SubFunction representor support for mlx5 PMD driver.

Depends-on: series-14559 ("support SubFunction representor")

Version history:
RFC:
initial version [2]
V2:
- support bonding representor probe with new pf#vf# devargs
- adapt EAL api V2 [3] changes
- update document

[1] SubFunction in kernel:
https://lore.kernel.org/netdev/[email protected]/

[2] RFC:
http://patchwork.dpdk.org/project/dpdk/list/?series=14376

[3] EAL part to support SF representor:
http://patchwork.dpdk.org/project/dpdk/list/?series=14559

Xueming Li (4):
common/mlx5: update representor name parsing net/mlx5: support representor of sub function net/mlx5: revert setting representor to first PF net/mlx5: improve bonding representor probe

 doc/guides/nics/mlx5.rst                   |  62 +++++-
 drivers/common/mlx5/linux/mlx5_common_os.c |  32 ++-
 drivers/common/mlx5/linux/mlx5_nl.c        |   2 +
 drivers/common/mlx5/mlx5_common.h          |   2 +
 drivers/net/mlx5/linux/mlx5_ethdev_os.c    |   5 +
 drivers/net/mlx5/linux/mlx5_os.c           | 215 ++++++++++++++-------
 drivers/net/mlx5/mlx5.c                    |  23 ++-
 drivers/net/mlx5/mlx5.h                    |   4 +-
 drivers/net/mlx5/mlx5_defs.h               |   4 -
 drivers/net/mlx5/mlx5_ethdev.c             |  29 +--
 drivers/net/mlx5/mlx5_mac.c                |   8 +-
 11 files changed, 261 insertions(+), 125 deletions(-)
Signature · 1 line
2.25.1
author
#18 lore raw

PATCH v2 2/4 net/mlx5: support representor of sub function

This patch supports of SF representor. Similar to VF representor, switch port name of SF representor in sysfs phys_port_name is "pf<x>sf<y>".

Device representor argumnt is "representors=sf[list]", list member could be mix of instance and range. Example:
representors=sf[0,2,4,8-12,-1]

To probe VF representor and SF representor, need to separate into 2 devices:
-a <BDF>,representor=vf[list] -a <BDF>,representor=sf[list]

---
 doc/guides/nics/mlx5.rst                |  58 +++++++++--
 drivers/net/mlx5/linux/mlx5_ethdev_os.c |   2 +
 drivers/net/mlx5/linux/mlx5_os.c        | 123 ++++++++++++++++++++----
 drivers/net/mlx5/mlx5_ethdev.c          |   2 +
 4 files changed, 154 insertions(+), 31 deletions(-)
doc/guides/nics/mlx5.rst +48 -10
index 3bda0f8417..fc7e93842f 100644
@@ -874,14 +874,18 @@ Driver options
 - ``representor`` parameter [list]
 
   This parameter can be used to instantiate DPDK Ethernet devices from
-  existing port (or VF) representors configured on the device.
+  existing port (PF, VF or SF) representors configured on the device.
 
   It is a standard parameter whose format is described in
   :ref:`ethernet_device_standard_device_arguments`.
 
-  For instance, to probe port representors 0 through 2::
+  For instance, to probe VF port representors 0 through 2::
 
-    representor=[0-2]
+    representor=vf[0-2]
+
+  To probe SF port representors 0 through 2::
+
+    representor=sf[0-2]
 
 - ``max_dump_files_num`` parameter [int]
 
@@ -1253,15 +1257,15 @@ Quick Start Guide on OFED/EN
 Enable switchdev mode
 ---------------------
 
-Switchdev mode is a mode in E-Switch, that binds between representor and VF.
-Representor is a port in DPDK that is connected to a VF in such a way
-that assuming there are no offload flows, each packet that is sent from the VF
-will be received by the corresponding representor. While each packet that is
-sent to a representor will be received by the VF.
+Switchdev mode is a mode in E-Switch, that binds between representor and VF or SF.
+Representor is a port in DPDK that is connected to a VF or SF in such a way
+that assuming there are no offload flows, each packet that is sent from the VF or SF
+will be received by the corresponding representor. While each packet that is or SF
+sent to a representor will be received by the VF or SF.
 This is very useful in case of SRIOV mode, where the first packet that is sent
-by the VF will be received by the DPDK application which will decide if this
+by the VF or SF will be received by the DPDK application which will decide if this
 flow should be offloaded to the E-Switch. After offloading the flow packet
-that the VF that are matching the flow will not be received any more by
+that the VF or SF that are matching the flow will not be received any more by
 the DPDK application.
 
 1. Enable SRIOV mode::
@@ -1288,6 +1292,40 @@ the DPDK application.
 
         echo switchdev > /sys/class/net/<net device>/compat/devlink/mode
 
+SubFunction representor support
+-------------------------------
+SubFunction is a portion of the PCI device, a SF netdev has its own
+dedicated queues(txq, rxq). A SF netdev supports eswitch representation
+offload similar to existing PF and VF representors. A SF shares PCI
+level resources with other SFs and/or with its parent PCI function.
+
+1. Configure SF feature::
+
+        mlxconfig -d <mst device> set PF_BAR2_SIZE=<0/1/2/3> PF_BAR2_ENABLE=1
+
+        Value of PF_BAR2_SIZE:
+
+            0: 8 SFs
+            1: 16 SFs
+            2: 32 SFs
+            3: 64 SFs
+
+2. Reset the FW::
+
+        mlxfwreset -d <mst device> reset
+
+3. Enable switchdev mode::
+
+        echo switchdev > /sys/class/net/<net device>/compat/devlink/mode
+
+4. Create SF::
+
+        mlnx-sf -d <PCI_BDF> -a create
+
+5. Probe SF representor::
+
+        testpmd> port attach <PCI_BDF>,representor=sf0,dv_flow_en=1
+
 Performance tuning
 ------------------
 
drivers/net/mlx5/linux/mlx5_ethdev_os.c +2 -0
index 1b37970c21..ac311de46d 100644
@@ -1010,6 +1010,8 @@ mlx5_sysfs_check_switch_info(bool device_dir,
 	case MLX5_PHYS_PORT_NAME_TYPE_PFHPF:
 		/* Fallthrough */
 	case MLX5_PHYS_PORT_NAME_TYPE_PFVF:
+		/* Fallthrough */
+	case MLX5_PHYS_PORT_NAME_TYPE_PFSF:
 		/* New representors naming schema. */
 		switch_info->representor = 1;
 		break;
drivers/net/mlx5/linux/mlx5_os.c +102 -21

191 lines not on this page · raw message

drivers/net/mlx5/mlx5_ethdev.c +2 -0
index 45ee7e4488..ad6aacc329 100644
@@ -374,6 +374,8 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
 			break;
 		}
 	}
+	if (priv->master)
+		info->dev_capa = RTE_ETH_DEV_CAPA_REPRESENTOR_SF;
 	return 0;
 }
 
Signature · 1 line
2.25.1
author
#20 lore raw

PATCH v2 4/4 net/mlx5: improve bonding representor probe

In reply to Xueming Li

To probe representor on 2nd PF of bonding device, had to specify PF1 BDF in devarg:
<PF1_BDF>,representor=0
When closing bonding device, all representors had to be closed together and this implies all representors have to use master PF of bonding device. So after probing representor port on 2nd PF, when locating new probed device using device argument, the filter used 2nd PF as PCI address and failed to locate new device.

Conflict happened by using current representor devargs:
- Use PCI BDF to specify representor owner PF
- Use PCI BDF to locate probed representor device.
- PMD use master PCI BDF as PCI device.

To resolve such conflicts, new representor syntax is introduced here:
<master BDF>,representor=pfXvfY
All representors must use master PF as owner PCI device, PMD internally locate owner PCI address by checking representor "pfX" part. To EAL, all representor are registered to master PCI device, 2nd PF is hidden to EAL, thus all search should be consistent.

This patch also add pf index into bonding mode representor port name:

	<BDF>_<ib_name>_representor_pf<X>vf<Y>
---
 doc/guides/nics/mlx5.rst         |   8 +-
 drivers/net/mlx5/linux/mlx5_os.c | 160 +++++++++++++++++--------------
 drivers/net/mlx5/mlx5.c          |  22 +++++
 drivers/net/mlx5/mlx5.h          |   3 +-
 drivers/net/mlx5/mlx5_defs.h     |   4 -
 drivers/net/mlx5/mlx5_ethdev.c   |  27 ------
 drivers/net/mlx5/mlx5_mac.c      |   8 +-
 7 files changed, 122 insertions(+), 110 deletions(-)
doc/guides/nics/mlx5.rst +6 -2
index fc7e93842f..8a142e1d59 100644
@@ -881,11 +881,15 @@ Driver options
 
   For instance, to probe VF port representors 0 through 2::
 
-    representor=vf[0-2]
+    <PCI_BDF>,representor=vf[0-2]
 
   To probe SF port representors 0 through 2::
 
-    representor=sf[0-2]
+    <PCI_BDF>,representor=sf[0-2]
+
+  To probe VF port representors 0 through 2 on both PFs of bonding device::
+
+    <Primary_PCI_BDF>,representor=pf[0,1]vf[0-2]
 
 - ``max_dump_files_num`` parameter [int]
 
drivers/net/mlx5/linux/mlx5_os.c +86 -74

261 lines not on this page · raw message

drivers/net/mlx5/mlx5.c +22 -0
index 628587faac..a8de42ff14 100644
@@ -358,6 +358,28 @@ static const struct mlx5_indexed_pool_config mlx5_ipool_cfg[] = {
 
 #define MLX5_FLOW_TABLE_HLIST_ARRAY_SIZE 4096
 
+/**
+ * Decide whether representor ID is a HPF(host PF) port on BF2.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ *
+ * @return
+ *   Non-zero if HPF, otherwise 0.
+ */
+int
+mlx5_is_hpf(struct rte_eth_dev *dev)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	enum rte_eth_representor_type type;
+	uint16_t port;
+
+	port = rte_eth_representor_id_parse(priv->representor_id,
+					    NULL, NULL, &type);
+	return priv->representor && type == RTE_ETH_REPRESENTOR_VF &&
+	       port == rte_eth_representor_id_parse(-1, NULL, NULL, NULL);
+}
+
 /**
  * Initialize the ASO aging management structure.
  *
drivers/net/mlx5/mlx5.h +2 -1
index a77a1600d5..767dcfdc6d 100644
@@ -945,7 +945,7 @@ struct mlx5_priv {
 	uint16_t vport_id; /* Associated VF vport index (if any). */
 	uint32_t vport_meta_tag; /* Used for vport index match ove VF LAG. */
 	uint32_t vport_meta_mask; /* Used for vport index field match mask. */
-	int32_t representor_id; /* Port representor identifier. */
+	int32_t representor_id; /* RTE_ETH_REPR(), -1 if not a representor. */
 	int32_t pf_bond; /* >=0 means PF index in bonding configuration. */
 	unsigned int if_index; /* Associated kernel network device index. */
 	uint32_t bond_ifindex; /**< Bond interface index. */
@@ -1019,6 +1019,7 @@ int mlx5_udp_tunnel_port_add(struct rte_eth_dev *dev,
 			      struct rte_eth_udp_tunnel *udp_tunnel);
 uint16_t mlx5_eth_find_next(uint16_t port_id, struct rte_pci_device *pci_dev);
 int mlx5_dev_close(struct rte_eth_dev *dev);
+int mlx5_is_hpf(struct rte_eth_dev *dev);
 void mlx5_age_event_prepare(struct mlx5_dev_ctx_shared *sh);
 
 /* Macro to iterate over all valid ports for mlx5 driver. */
drivers/net/mlx5/mlx5_defs.h +0 -4
index 85a0979653..4648196550 100644
@@ -48,10 +48,6 @@
 #define MLX5_PMD_SOFT_COUNTERS 1
 #endif
 
-/* Switch port ID parameters for bonding configurations. */
-#define MLX5_PORT_ID_BONDING_PF_MASK 0xf
-#define MLX5_PORT_ID_BONDING_PF_SHIFT 12
-
 /* Alarm timeout. */
 #define MLX5_ALARM_TIMEOUT_US 100000
 
drivers/net/mlx5/mlx5_ethdev.c +0 -27
index ad6aacc329..5341eb16c9 100644
@@ -330,33 +330,6 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
 	if (priv->representor) {
 		uint16_t port_id;
 
-		if (priv->pf_bond >= 0) {
-			/*
-			 * Switch port ID is opaque value with driver defined
-			 * format. Push the PF index in bonding configurations
-			 * in upper four bits of port ID. If we get too many
-			 * representors (more than 4K) or PFs (more than 15)
-			 * this approach must be reconsidered.
-			 */
-			/* Switch port ID for VF representors: 0 - 0xFFE */
-			if ((info->switch_info.port_id != 0xffff &&
-				info->switch_info.port_id >=
-				((1 << MLX5_PORT_ID_BONDING_PF_SHIFT) - 1)) ||
-			    priv->pf_bond > MLX5_PORT_ID_BONDING_PF_MASK) {
-				DRV_LOG(ERR, "can't update switch port ID"
-					     " for bonding device");
-				MLX5_ASSERT(false);
-				return -ENODEV;
-			}
-			/*
-			 * Switch port ID for Host PF representor
-			 * (representor_id is -1) , set to 0xFFF
-			 */
-			if (info->switch_info.port_id == 0xffff)
-				info->switch_info.port_id = 0xfff;
-			info->switch_info.port_id |=
-				priv->pf_bond << MLX5_PORT_ID_BONDING_PF_SHIFT;
-		}
 		MLX5_ETH_FOREACH_DEV(port_id, priv->pci_dev) {
 			struct mlx5_priv *opriv =
 				rte_eth_devices[port_id].data->dev_private;
drivers/net/mlx5/mlx5_mac.c +6 -2
index bd786fd638..b5b810b508 100644
@@ -159,7 +159,7 @@ mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 	 * Configuring the VF instead of its representor,
 	 * need to skip the special case of HPF on Bluefield.
 	 */
-	if (priv->representor && priv->representor_id >= 0) {
+	if (priv->representor && !mlx5_is_hpf(dev)) {
 		DRV_LOG(DEBUG, "VF represented by port %u setting primary MAC address",
 			dev->data->port_id);
 		RTE_ETH_FOREACH_DEV_SIBLING(port_id, dev->data->port_id) {
@@ -169,7 +169,11 @@ mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
 				return mlx5_os_vf_mac_addr_modify
 				       (priv,
 					mlx5_ifindex(&rte_eth_devices[port_id]),
-					mac_addr, priv->representor_id);
+					mac_addr,
+					rte_eth_representor_id_parse(
+							priv->representor_id,
+							NULL, NULL, NULL)
+					);
 			}
 		}
 		rte_errno = -ENOTSUP;
Signature · 1 line
2.25.1
#5 lore raw

Re: [dpdk-dev] [PATCH v2 1/9] ethdev: refactor representor infrastructure

In reply to Xueming Li
Quoted 2 lines · Xueming Li

To support extended representor syntax, this patch refactor represntor

Typo in 'representor'

Quoted 24 lines

infrastructure:
1. introduces representor type enum
2. devargs representor port range extraction from partial value

---
 drivers/net/bnxt/bnxt_ethdev.c        | 12 ++++
 drivers/net/enic/enic_ethdev.c        |  7 ++
 drivers/net/i40e/i40e_ethdev.c        |  8 +++
 drivers/net/ixgbe/ixgbe_ethdev.c      |  8 +++
 drivers/net/mlx5/linux/mlx5_os.c      | 11 ++++
 lib/librte_ethdev/ethdev_private.c    | 93 ++++++++++++---------------
 lib/librte_ethdev/ethdev_private.h    |  3 -
 lib/librte_ethdev/rte_class_eth.c     |  4 +-
 lib/librte_ethdev/rte_ethdev.c        |  5 +-
 lib/librte_ethdev/rte_ethdev_driver.h |  7 ++
 10 files changed, 98 insertions(+), 60 deletions(-)
drivers/net/bnxt/bnxt_ethdev.c +0 -0
index 81c8f8d79d..844a6c3c66 100644
@@ -5520,6 +5520,18 @@ static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev,
        int i, ret = 0;

drivers/net/bnxt/bnxt_ethdev.c static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev, · line 5530

Quoted 10 lines
drivers/net/bnxt/bnxt_ethdev.c +8 -0
        struct rte_kvargs *kvlist = NULL;
 
+       if (eth_da->type == RTE_ETH_REPRESENTOR_NONE)
+               return 0;
+       if (eth_da->type != RTE_ETH_REPRESENTOR_VF) {
+               PMD_DRV_LOG(ERR, "unsupported representor type %d\n",
+                           eth_da->type);
+               return -ENOTSUP;
+       }
+       if (eth_da->type != RTE_ETH_REPRESENTOR_VF) {

Seems like an extra 'if ' condition by mistake? Otherwise there is no diff b/n this 'if' condition and the one few lines above?

Quoted 288 lines
drivers/net/bnxt/bnxt_ethdev.c +4 -0
+               PMD_DRV_LOG(ERR, "unsupported representor type %d\n",
+                           eth_da->type);
+               return -EINVAL;
+       }
        num_rep = eth_da->nb_representor_ports;
        if (num_rep > BNXT_MAX_VF_REPS) {
                PMD_DRV_LOG(ERR, "nb_representor_ports = %d > %d MAX VF REPS\n",
drivers/net/enic/enic_ethdev.c +7 -0
index d041a6bee9..dd085caa93 100644
@@ -1303,6 +1303,13 @@ static int eth_enic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
                if (retval)
                        return retval;
        }
+       if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+               return 0;
+       if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+               ENICPMD_LOG(ERR, "unsupported representor type: %s\n",
+                           pci_dev->device.devargs->args);
+               return -ENOTSUP;
+       }
        retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
                sizeof(struct enic),
                eth_dev_pci_specific_init, pci_dev,
drivers/net/i40e/i40e_ethdev.c +8 -0
index f54769c29d..05ed2e1079 100644
@@ -640,6 +640,14 @@ eth_i40e_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
                        return retval;
        }
 
+       if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+               return 0;
+       if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+               PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
+                           pci_dev->device.devargs->args);
+               return -ENOTSUP;
+       }
+
        retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
                sizeof(struct i40e_adapter),
                eth_dev_pci_specific_init, pci_dev,
drivers/net/ixgbe/ixgbe_ethdev.c +8 -0
index 9a47a8b262..9ea0139197 100644
@@ -1717,6 +1717,14 @@ eth_ixgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
        } else
                memset(&eth_da, 0, sizeof(eth_da));
 
+       if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+               return 0;
+       if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+               PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
+                           pci_dev->device.devargs->args);
+               return -ENOTSUP;
+       }
+
        retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
                sizeof(struct ixgbe_adapter),
                eth_dev_pci_specific_init, pci_dev,
drivers/net/mlx5/linux/mlx5_os.c +11 -0
index 6812a1f215..6981ba1f41 100644
@@ -706,6 +706,17 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
                                strerror(rte_errno));
                        return NULL;
                }
+               if (eth_da.type != RTE_ETH_REPRESENTOR_NONE) {
+                       /* Representor not specified. */
+                       rte_errno = EBUSY;
+                       return NULL;
+               }
+               if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+                       rte_errno = ENOTSUP;
+                       DRV_LOG(ERR, "unsupported representor type: %s",
+                               dpdk_dev->devargs->args);
+                       return NULL;
+               }
                for (i = 0; i < eth_da.nb_representor_ports; ++i)
                        if (eth_da.representor_ports[i] ==
                            (uint16_t)switch_info->port_name)
lib/librte_ethdev/ethdev_private.c +42 -51
index 162a502fe7..c219164a4a 100644
@@ -38,60 +38,13 @@ eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp,
        return NULL;
 }
 
-int
-rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
-       void *data)
-{
-       char *str_start;
-       int state;
-       int result;
-
-       if (*str != '[')
-               /* Single element, not a list */
-               return callback(str, data);
-
-       /* Sanity check, then strip the brackets */
-       str_start = &str[strlen(str) - 1];
-       if (*str_start != ']') {
-               RTE_LOG(ERR, EAL, "(%s): List does not end with ']'\n", str);
-               return -EINVAL;
-       }
-       str++;
-       *str_start = '\0';
-
-       /* Process list elements */
-       state = 0;
-       while (1) {
-               if (state == 0) {
-                       if (*str == '\0')
-                               break;
-                       if (*str != ',') {
-                               str_start = str;
-                               state = 1;
-                       }
-               } else if (state == 1) {
-                       if (*str == ',' || *str == '\0') {
-                               if (str > str_start) {
-                                       /* Non-empty string fragment */
-                                       *str = '\0';
-                                       result = callback(str_start, data);
-                                       if (result < 0)
-                                               return result;
-                               }
-                               state = 0;
-                       }
-               }
-               str++;
-       }
-       return 0;
-}
-
 static int
 rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
        const uint16_t max_list)
 {
        uint16_t lo, hi, val;
        int result;
+       char *pos = str;
 
        result = sscanf(str, "%hu-%hu", &lo, &hi);
        if (result == 1) {
@@ -99,7 +52,7 @@ rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
                        return -ENOMEM;
                list[(*len_list)++] = lo;
        } else if (result == 2) {
-               if (lo >= hi || lo > RTE_MAX_ETHPORTS || hi > RTE_MAX_ETHPORTS)
+               if (lo >= hi)
                        return -EINVAL;
                for (val = lo; val <= hi; val++) {
                        if (*len_list >= max_list)
@@ -108,14 +61,52 @@ rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
                }
        } else
                return -EINVAL;
-       return 0;
+       while (*pos != 0 && ((*pos >= '0' && *pos <= '9') || *pos == '-'))
+               pos++;
+       return pos - str;
 }
 
+static int
+rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
+       const uint16_t max_list)
+{
+       char *pos = str;
+       int ret;
+
+       if (*pos == '[')
+               pos++;
+       while (1) {
+               ret = rte_eth_devargs_process_range(pos, list, len_list,
+                                                   max_list);
+               if (ret < 0)
+                       return ret;
+               pos += ret;
+               if (*pos != ',') /* end of list */
+                       break;
+               pos++;
+       }
+       if (*str == '[' && *pos != ']')
+               return -EINVAL;
+       if (*pos == ']')
+               pos++;
+       return pos - str;
+}
+
+/*
+ * representor format:
+ *   #: range or single number of VF representor - legacy
+ */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
 {
        struct rte_eth_devargs *eth_da = data;
+       int ret;
 
-       return rte_eth_devargs_process_range(str, eth_da->representor_ports,
+       /* Number # alone implies VF */
+       eth_da->type = RTE_ETH_REPRESENTOR_VF;
+       ret = rte_eth_devargs_process_list(str, eth_da->representor_ports,
                &eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
+       if (ret < 0)
+               RTE_LOG(ERR, EAL, "wrong representor format: %s\n", str);
+       return ret < 0 ? ret : 0;
 }
lib/librte_ethdev/ethdev_private.h +0 -3
index 905a45c337..220ddd4408 100644
@@ -26,9 +26,6 @@ eth_find_device(const struct rte_eth_dev *_start, rte_eth_cmp_t cmp,
                const void *data);
 
 /* Parse devargs value for representor parameter. */
-typedef int (*rte_eth_devargs_callback_t)(char *str, void *data);
-int rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
-       void *data);
 int rte_eth_devargs_parse_representor_ports(char *str, void *data);
 
 #ifdef __cplusplus
lib/librte_ethdev/rte_class_eth.c +1 -3
index 6338355e25..efe6149df5 100644
@@ -77,9 +77,7 @@ eth_representor_cmp(const char *key __rte_unused,
        if (values == NULL)
                return -1;
        memset(&representors, 0, sizeof(representors));
-       ret = rte_eth_devargs_parse_list(values,
-                       rte_eth_devargs_parse_representor_ports,
-                       &representors);
+       ret = rte_eth_devargs_parse_representor_ports(values, &representors);
        free(values);
        if (ret != 0)
                return -1; /* invalid devargs value */
lib/librte_ethdev/rte_ethdev.c +2 -3
index 17ddacc78d..2ac51ac149 100644
@@ -5542,9 +5542,8 @@ rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
        for (i = 0; i < args.count; i++) {
                pair = &args.pairs[i];
                if (strcmp("representor", pair->key) == 0) {
-                       result = rte_eth_devargs_parse_list(pair->value,
-                               rte_eth_devargs_parse_representor_ports,
-                               eth_da);
+                       result = rte_eth_devargs_parse_representor_ports(
+                                       pair->value, eth_da);
                        if (result < 0)
                                goto parse_cleanup;
                }
lib/librte_ethdev/rte_ethdev_driver.h +7 -1
index 0eacfd8425..b66a955b18 100644
@@ -1193,6 +1193,12 @@ __rte_internal
 int
 rte_eth_switch_domain_free(uint16_t domain_id);
 
+/** Ethernet device representor type */
+enum rte_eth_representor_type {
+       RTE_ETH_REPRESENTOR_NONE, /* not a representor */
+       RTE_ETH_REPRESENTOR_VF,   /* representor of VF */
+};
+
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
        uint16_t ports[RTE_MAX_ETHPORTS];
@@ -1203,6 +1209,7 @@ struct rte_eth_devargs {
        /** representor port/s identifier to enable on device */
        uint16_t nb_representor_ports;
        /** number of ports in representor port field */
+       enum rte_eth_representor_type type; /* type of representor */
 };
 
 /**
--

2.25.1

Signature · 11 lines
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.
#6 lore raw

Re: [dpdk-dev] [PATCH v2 1/9] ethdev: refactor representor infrastructure

Quoted 54 lines

-----Original Message-----
From: Somnath Kotur <[email protected]>
Sent: Thursday, January 7, 2021 2:32 PM
To: Xueming(Steven) Li <[email protected]>
Cc: NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>; Olivier Matz <[email protected]>; Slava Ovsiienko <[email protected]>; dev <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v2 1/9] ethdev: refactor representor infrastructure

Quoted 2 lines · Xueming Li

To support extended representor syntax, this patch refactor represntor

Typo in 'representor'

Quoted 18 lines

infrastructure:
1. introduces representor type enum
2. devargs representor port range extraction from partial value

---
 drivers/net/bnxt/bnxt_ethdev.c        | 12 ++++
 drivers/net/enic/enic_ethdev.c        |  7 ++
 drivers/net/i40e/i40e_ethdev.c        |  8 +++
 drivers/net/ixgbe/ixgbe_ethdev.c      |  8 +++
 drivers/net/mlx5/linux/mlx5_os.c      | 11 ++++
 lib/librte_ethdev/ethdev_private.c    | 93 ++++++++++++---------------
 lib/librte_ethdev/ethdev_private.h    |  3 -
 lib/librte_ethdev/rte_class_eth.c     |  4 +-
 lib/librte_ethdev/rte_ethdev.c        |  5 +-
 lib/librte_ethdev/rte_ethdev_driver.h |  7 ++
 10 files changed, 98 insertions(+), 60 deletions(-)

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/bnxt/bnxt_ethdev.c

drivers/net/bnxt/bnxt_ethdev.c static int bnxt_rep_port_probe(struct

Quoted 4 lines

index 81c8f8d79d..844a6c3c66 100644

drivers/net/bnxt/bnxt_ethdev.c +0 -0
@@ -5520,6 +5520,18 @@ static int bnxt_rep_port_probe(struct

rte_pci_device *pci_dev,

drivers/net/bnxt/bnxt_ethdev.c static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev, · line 5530

Quoted 11 lines
drivers/net/bnxt/bnxt_ethdev.c +8 -0
        int i, ret = 0;
        struct rte_kvargs *kvlist = NULL;
 
+       if (eth_da->type == RTE_ETH_REPRESENTOR_NONE)
+               return 0;
+       if (eth_da->type != RTE_ETH_REPRESENTOR_VF) {
+               PMD_DRV_LOG(ERR, "unsupported representor type %d\n",
+                           eth_da->type);
+               return -ENOTSUP;
+       }
+       if (eth_da->type != RTE_ETH_REPRESENTOR_VF) {
Quoted 2 lines

Seems like an extra 'if ' condition by mistake? Otherwise there is no diff b/n this 'if' condition and the one few lines above?

Thanks, good catch!

Quoted 317 lines

drivers/net/bnxt/bnxt_ethdev.c static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev,

Quoted 7 lines
drivers/net/bnxt/bnxt_ethdev.c +4 -0
+               PMD_DRV_LOG(ERR, "unsupported representor type %d\n",
+                           eth_da->type);
+               return -EINVAL;
+       }
        num_rep = eth_da->nb_representor_ports;
        if (num_rep > BNXT_MAX_VF_REPS) {
                PMD_DRV_LOG(ERR, "nb_representor_ports = %d > %d MAX VF

REPS\n",

drivers/net/enic/enic_ethdev.c static int eth_enic_pci_probe(struct

Quoted 5 lines
drivers/net/enic/enic_ethdev.c +0 -0
index d041a6bee9..dd085caa93 100644
@@ -1303,6 +1303,13 @@ static int eth_enic_pci_probe(struct

rte_pci_driver *pci_drv __rte_unused,

drivers/net/i40e/i40e_ethdev.c eth_i40e_pci_probe(struct rte_pci_driver *pci_drv

Quoted 18 lines
drivers/net/enic/enic_ethdev.c +7 -0
                if (retval)
                        return retval;
        }
+       if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+               return 0;
+       if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+               ENICPMD_LOG(ERR, "unsupported representor type: %s\n",
+                           pci_dev->device.devargs->args);
+               return -ENOTSUP;
+       }
        retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
                sizeof(struct enic),
                eth_dev_pci_specific_init, pci_dev,
drivers/net/i40e/i40e_ethdev.c +0 -0
index f54769c29d..05ed2e1079 100644
@@ -640,6 +640,14 @@ eth_i40e_pci_probe(struct rte_pci_driver *pci_drv

__rte_unused,

Review

Quoted 15 lines
drivers/net/i40e/i40e_ethdev.c +8 -0
                        return retval;
        }
 
+       if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+               return 0;
+       if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+               PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
+                           pci_dev->device.devargs->args);
+               return -ENOTSUP;
+       }
+
        retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
                sizeof(struct i40e_adapter),
                eth_dev_pci_specific_init, pci_dev,
(quoted diff) +0 -0

b/drivers/net/ixgbe/ixgbe_ethdev.c

drivers/net/ixgbe/ixgbe_ethdev.c eth_ixgbe_pci_probe(struct rte_pci_driver

Quoted 4 lines

index 9a47a8b262..9ea0139197 100644

drivers/net/ixgbe/ixgbe_ethdev.c +0 -0
@@ -1717,6 +1717,14 @@ eth_ixgbe_pci_probe(struct rte_pci_driver

*pci_drv __rte_unused,

Review

Quoted 15 lines
drivers/net/ixgbe/ixgbe_ethdev.c +8 -0
        } else
                memset(&eth_da, 0, sizeof(eth_da));
 
+       if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+               return 0;
+       if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+               PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
+                           pci_dev->device.devargs->args);
+               return -ENOTSUP;
+       }
+
        retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
                sizeof(struct ixgbe_adapter),
                eth_dev_pci_specific_init, pci_dev,
(quoted diff) +0 -0

b/drivers/net/mlx5/linux/mlx5_os.c

Review

Quoted 22 lines

index 6812a1f215..6981ba1f41 100644

drivers/net/mlx5/linux/mlx5_os.c +11 -0
@@ -706,6 +706,17 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
                                strerror(rte_errno));
                        return NULL;
                }
+               if (eth_da.type != RTE_ETH_REPRESENTOR_NONE) {
+                       /* Representor not specified. */
+                       rte_errno = EBUSY;
+                       return NULL;
+               }
+               if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+                       rte_errno = ENOTSUP;
+                       DRV_LOG(ERR, "unsupported representor type: %s",
+                               dpdk_dev->devargs->args);
+                       return NULL;
+               }
                for (i = 0; i < eth_da.nb_representor_ports; ++i)
                        if (eth_da.representor_ports[i] ==
                            (uint16_t)switch_info->port_name)
(quoted diff) +0 -0

b/lib/librte_ethdev/ethdev_private.c

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start,

Quoted 4 lines

index 162a502fe7..c219164a4a 100644

lib/librte_ethdev/ethdev_private.c +0 -0
@@ -38,60 +38,13 @@ eth_find_device(const struct rte_eth_dev *start,

rte_eth_cmp_t cmp,

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_process_range(char *str, uint16_t

Quoted 62 lines
lib/librte_ethdev/ethdev_private.c +1 -48
        return NULL;
 }
 
-int
-rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
-       void *data)
-{
-       char *str_start;
-       int state;
-       int result;
-
-       if (*str != '[')
-               /* Single element, not a list */
-               return callback(str, data);
-
-       /* Sanity check, then strip the brackets */
-       str_start = &str[strlen(str) - 1];
-       if (*str_start != ']') {
-               RTE_LOG(ERR, EAL, "(%s): List does not end with ']'\n", str);
-               return -EINVAL;
-       }
-       str++;
-       *str_start = '\0';
-
-       /* Process list elements */
-       state = 0;
-       while (1) {
-               if (state == 0) {
-                       if (*str == '\0')
-                               break;
-                       if (*str != ',') {
-                               str_start = str;
-                               state = 1;
-                       }
-               } else if (state == 1) {
-                       if (*str == ',' || *str == '\0') {
-                               if (str > str_start) {
-                                       /* Non-empty string fragment */
-                                       *str = '\0';
-                                       result = callback(str_start, data);
-                                       if (result < 0)
-                                               return result;
-                               }
-                               state = 0;
-                       }
-               }
-               str++;
-       }
-       return 0;
-}
-
 static int
 rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
        const uint16_t max_list)
 {
        uint16_t lo, hi, val;
        int result;
+       char *pos = str;
 
        result = sscanf(str, "%hu-%hu", &lo, &hi);
        if (result == 1) {
@@ -99,7 +52,7 @@ rte_eth_devargs_process_range(char *str, uint16_t

*list, uint16_t *len_list,

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_process_range(char *str, uint16_t

Quoted 9 lines
lib/librte_ethdev/ethdev_private.c +1 -1
                        return -ENOMEM;
                list[(*len_list)++] = lo;
        } else if (result == 2) {
-               if (lo >= hi || lo > RTE_MAX_ETHPORTS || hi > RTE_MAX_ETHPORTS)
+               if (lo >= hi)
                        return -EINVAL;
                for (val = lo; val <= hi; val++) {
                        if (*len_list >= max_list)
@@ -108,14 +61,52 @@ rte_eth_devargs_process_range(char *str, uint16_t

*list, uint16_t *len_list,

Review

Quoted 55 lines
lib/librte_ethdev/ethdev_private.c +40 -2
                }
        } else
                return -EINVAL;
-       return 0;
+       while (*pos != 0 && ((*pos >= '0' && *pos <= '9') || *pos == '-'))
+               pos++;
+       return pos - str;
 }
 
+static int
+rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
+       const uint16_t max_list)
+{
+       char *pos = str;
+       int ret;
+
+       if (*pos == '[')
+               pos++;
+       while (1) {
+               ret = rte_eth_devargs_process_range(pos, list, len_list,
+                                                   max_list);
+               if (ret < 0)
+                       return ret;
+               pos += ret;
+               if (*pos != ',') /* end of list */
+                       break;
+               pos++;
+       }
+       if (*str == '[' && *pos != ']')
+               return -EINVAL;
+       if (*pos == ']')
+               pos++;
+       return pos - str;
+}
+
+/*
+ * representor format:
+ *   #: range or single number of VF representor - legacy
+ */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
 {
        struct rte_eth_devargs *eth_da = data;
+       int ret;
 
-       return rte_eth_devargs_process_range(str, eth_da->representor_ports,
+       /* Number # alone implies VF */
+       eth_da->type = RTE_ETH_REPRESENTOR_VF;
+       ret = rte_eth_devargs_process_list(str, eth_da->representor_ports,
                &eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
+       if (ret < 0)
+               RTE_LOG(ERR, EAL, "wrong representor format: %s\n", str);
+       return ret < 0 ? ret : 0;
 }
(quoted diff) +0 -0

b/lib/librte_ethdev/ethdev_private.h

lib/librte_ethdev/ethdev_private.h eth_find_device(const struct rte_eth_dev *_start,

Quoted 4 lines

index 905a45c337..220ddd4408 100644

lib/librte_ethdev/ethdev_private.h +0 -0
@@ -26,9 +26,6 @@ eth_find_device(const struct rte_eth_dev *_start,

rte_eth_cmp_t cmp,

lib/librte_ethdev/ethdev_private.h eth_find_device(const struct rte_eth_dev *_start, rte_eth_cmp_t cmp,

Quoted 5 lines
lib/librte_ethdev/ethdev_private.h +0 -2
                const void *data);
 
 /* Parse devargs value for representor parameter. */
-typedef int (*rte_eth_devargs_callback_t)(char *str, void *data);
-int rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t

callback,

Review

Quoted 5 lines
lib/librte_ethdev/ethdev_private.h +0 -1
-       void *data);
 int rte_eth_devargs_parse_representor_ports(char *str, void *data);
 
 #ifdef __cplusplus
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_class_eth.c

lib/librte_ethdev/rte_ethdev.c rte_eth_devargs_parse(const char *dargs, struct

Quoted 19 lines

index 6338355e25..efe6149df5 100644

lib/librte_ethdev/rte_class_eth.c +1 -3
@@ -77,9 +77,7 @@ eth_representor_cmp(const char *key __rte_unused,
        if (values == NULL)
                return -1;
        memset(&representors, 0, sizeof(representors));
-       ret = rte_eth_devargs_parse_list(values,
-                       rte_eth_devargs_parse_representor_ports,
-                       &representors);
+       ret = rte_eth_devargs_parse_representor_ports(values, &representors);
        free(values);
        if (ret != 0)
                return -1; /* invalid devargs value */
lib/librte_ethdev/rte_ethdev.c +0 -0
index 17ddacc78d..2ac51ac149 100644
@@ -5542,9 +5542,8 @@ rte_eth_devargs_parse(const char *dargs, struct

rte_eth_devargs *eth_da)

Review

Quoted 12 lines
lib/librte_ethdev/rte_ethdev.c +2 -3
        for (i = 0; i < args.count; i++) {
                pair = &args.pairs[i];
                if (strcmp("representor", pair->key) == 0) {
-                       result = rte_eth_devargs_parse_list(pair->value,
-                               rte_eth_devargs_parse_representor_ports,
-                               eth_da);
+                       result = rte_eth_devargs_parse_representor_ports(
+                                       pair->value, eth_da);
                        if (result < 0)
                                goto parse_cleanup;
                }
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_ethdev_driver.h

Quoted 25 lines

index 0eacfd8425..b66a955b18 100644

lib/librte_ethdev/rte_ethdev_driver.h +7 -1
@@ -1193,6 +1193,12 @@ __rte_internal
 int
 rte_eth_switch_domain_free(uint16_t domain_id);
 
+/** Ethernet device representor type */
+enum rte_eth_representor_type {
+       RTE_ETH_REPRESENTOR_NONE, /* not a representor */
+       RTE_ETH_REPRESENTOR_VF,   /* representor of VF */
+};
+
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
        uint16_t ports[RTE_MAX_ETHPORTS];
@@ -1203,6 +1209,7 @@ struct rte_eth_devargs {
        /** representor port/s identifier to enable on device */
        uint16_t nb_representor_ports;
        /** number of ports in representor port field */
+       enum rte_eth_representor_type type; /* type of representor */
 };
 
 /**
--
Quoted 2 lines

2.25.1

--
This electronic communication and the information and any files transmitted with it, or attached to it, are confidential and are intended solely for the use of the individual or entity to whom it is addressed and may contain information that is confidential, legally privileged, protected by privacy laws, or otherwise restricted from disclosure to anyone else. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, you are hereby notified that any use, copying, distributing, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please return the e-mail to the sender, delete it from your computer, and destroy any printed copy of it.

#7 lore raw

Re: [dpdk-dev] [PATCH v2 1/9] ethdev: refactor representor infrastructure

Quoted 15 lines · Xueming(Steven) Li
Quoted 15 lines

-----Original Message-----
From: Somnath Kotur <[email protected]>
Sent: Thursday, January 7, 2021 2:32 PM
To: Xueming(Steven) Li <[email protected]>
Cc: NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>; Olivier Matz <[email protected]>; Slava Ovsiienko <[email protected]>; dev <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v2 1/9] ethdev: refactor representor infrastructure

Quoted 3 lines
Quoted 3 lines · Xueming Li
Quoted 2 lines

To support extended representor syntax, this patch refactor represntor

Please fix this Typo in 'representor' as well ...Thanks

Quoted 358 lines
Quoted 36 lines
Quoted 18 lines

infrastructure:
1. introduces representor type enum
2. devargs representor port range extraction from partial value

---
 drivers/net/bnxt/bnxt_ethdev.c        | 12 ++++
 drivers/net/enic/enic_ethdev.c        |  7 ++
 drivers/net/i40e/i40e_ethdev.c        |  8 +++
 drivers/net/ixgbe/ixgbe_ethdev.c      |  8 +++
 drivers/net/mlx5/linux/mlx5_os.c      | 11 ++++
 lib/librte_ethdev/ethdev_private.c    | 93 ++++++++++++---------------
 lib/librte_ethdev/ethdev_private.h    |  3 -
 lib/librte_ethdev/rte_class_eth.c     |  4 +-
 lib/librte_ethdev/rte_ethdev.c        |  5 +-
 lib/librte_ethdev/rte_ethdev_driver.h |  7 ++
 10 files changed, 98 insertions(+), 60 deletions(-)

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/bnxt/bnxt_ethdev.c

drivers/net/bnxt/bnxt_ethdev.c static int bnxt_rep_port_probe(struct

Quoted 4 lines

index 81c8f8d79d..844a6c3c66 100644

drivers/net/bnxt/bnxt_ethdev.c +0 -0
@@ -5520,6 +5520,18 @@ static int bnxt_rep_port_probe(struct

rte_pci_device *pci_dev,

drivers/net/bnxt/bnxt_ethdev.c static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev, · line 5530

Quoted 11 lines
drivers/net/bnxt/bnxt_ethdev.c +8 -0
        int i, ret = 0;
        struct rte_kvargs *kvlist = NULL;
 
+       if (eth_da->type == RTE_ETH_REPRESENTOR_NONE)
+               return 0;
+       if (eth_da->type != RTE_ETH_REPRESENTOR_VF) {
+               PMD_DRV_LOG(ERR, "unsupported representor type %d\n",
+                           eth_da->type);
+               return -ENOTSUP;
+       }
+       if (eth_da->type != RTE_ETH_REPRESENTOR_VF) {
Quoted 2 lines

Seems like an extra 'if ' condition by mistake? Otherwise there is no diff b/n this 'if' condition and the one few lines above?

Thanks, good catch!

Quoted 317 lines

drivers/net/bnxt/bnxt_ethdev.c static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev,

Quoted 7 lines
drivers/net/bnxt/bnxt_ethdev.c +4 -0
+               PMD_DRV_LOG(ERR, "unsupported representor type %d\n",
+                           eth_da->type);
+               return -EINVAL;
+       }
        num_rep = eth_da->nb_representor_ports;
        if (num_rep > BNXT_MAX_VF_REPS) {
                PMD_DRV_LOG(ERR, "nb_representor_ports = %d > %d MAX VF

REPS\n",

drivers/net/enic/enic_ethdev.c static int eth_enic_pci_probe(struct

Quoted 5 lines
drivers/net/enic/enic_ethdev.c +0 -0
index d041a6bee9..dd085caa93 100644
@@ -1303,6 +1303,13 @@ static int eth_enic_pci_probe(struct

rte_pci_driver *pci_drv __rte_unused,

drivers/net/i40e/i40e_ethdev.c eth_i40e_pci_probe(struct rte_pci_driver *pci_drv

Quoted 18 lines
drivers/net/enic/enic_ethdev.c +7 -0
                if (retval)
                        return retval;
        }
+       if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+               return 0;
+       if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+               ENICPMD_LOG(ERR, "unsupported representor type: %s\n",
+                           pci_dev->device.devargs->args);
+               return -ENOTSUP;
+       }
        retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
                sizeof(struct enic),
                eth_dev_pci_specific_init, pci_dev,
drivers/net/i40e/i40e_ethdev.c +0 -0
index f54769c29d..05ed2e1079 100644
@@ -640,6 +640,14 @@ eth_i40e_pci_probe(struct rte_pci_driver *pci_drv

__rte_unused,

Review

Quoted 15 lines
drivers/net/i40e/i40e_ethdev.c +8 -0
                        return retval;
        }
 
+       if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+               return 0;
+       if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+               PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
+                           pci_dev->device.devargs->args);
+               return -ENOTSUP;
+       }
+
        retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
                sizeof(struct i40e_adapter),
                eth_dev_pci_specific_init, pci_dev,
(quoted diff) +0 -0

b/drivers/net/ixgbe/ixgbe_ethdev.c

drivers/net/ixgbe/ixgbe_ethdev.c eth_ixgbe_pci_probe(struct rte_pci_driver

Quoted 4 lines

index 9a47a8b262..9ea0139197 100644

drivers/net/ixgbe/ixgbe_ethdev.c +0 -0
@@ -1717,6 +1717,14 @@ eth_ixgbe_pci_probe(struct rte_pci_driver

*pci_drv __rte_unused,

Review

Quoted 15 lines
drivers/net/ixgbe/ixgbe_ethdev.c +8 -0
        } else
                memset(&eth_da, 0, sizeof(eth_da));
 
+       if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+               return 0;
+       if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+               PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
+                           pci_dev->device.devargs->args);
+               return -ENOTSUP;
+       }
+
        retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
                sizeof(struct ixgbe_adapter),
                eth_dev_pci_specific_init, pci_dev,
(quoted diff) +0 -0

b/drivers/net/mlx5/linux/mlx5_os.c

Review

Quoted 22 lines

index 6812a1f215..6981ba1f41 100644

drivers/net/mlx5/linux/mlx5_os.c +11 -0
@@ -706,6 +706,17 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
                                strerror(rte_errno));
                        return NULL;
                }
+               if (eth_da.type != RTE_ETH_REPRESENTOR_NONE) {
+                       /* Representor not specified. */
+                       rte_errno = EBUSY;
+                       return NULL;
+               }
+               if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+                       rte_errno = ENOTSUP;
+                       DRV_LOG(ERR, "unsupported representor type: %s",
+                               dpdk_dev->devargs->args);
+                       return NULL;
+               }
                for (i = 0; i < eth_da.nb_representor_ports; ++i)
                        if (eth_da.representor_ports[i] ==
                            (uint16_t)switch_info->port_name)
(quoted diff) +0 -0

b/lib/librte_ethdev/ethdev_private.c

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start,

Quoted 4 lines

index 162a502fe7..c219164a4a 100644

lib/librte_ethdev/ethdev_private.c +0 -0
@@ -38,60 +38,13 @@ eth_find_device(const struct rte_eth_dev *start,

rte_eth_cmp_t cmp,

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_process_range(char *str, uint16_t

Quoted 62 lines
lib/librte_ethdev/ethdev_private.c +1 -48
        return NULL;
 }
 
-int
-rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
-       void *data)
-{
-       char *str_start;
-       int state;
-       int result;
-
-       if (*str != '[')
-               /* Single element, not a list */
-               return callback(str, data);
-
-       /* Sanity check, then strip the brackets */
-       str_start = &str[strlen(str) - 1];
-       if (*str_start != ']') {
-               RTE_LOG(ERR, EAL, "(%s): List does not end with ']'\n", str);
-               return -EINVAL;
-       }
-       str++;
-       *str_start = '\0';
-
-       /* Process list elements */
-       state = 0;
-       while (1) {
-               if (state == 0) {
-                       if (*str == '\0')
-                               break;
-                       if (*str != ',') {
-                               str_start = str;
-                               state = 1;
-                       }
-               } else if (state == 1) {
-                       if (*str == ',' || *str == '\0') {
-                               if (str > str_start) {
-                                       /* Non-empty string fragment */
-                                       *str = '\0';
-                                       result = callback(str_start, data);
-                                       if (result < 0)
-                                               return result;
-                               }
-                               state = 0;
-                       }
-               }
-               str++;
-       }
-       return 0;
-}
-
 static int
 rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
        const uint16_t max_list)
 {
        uint16_t lo, hi, val;
        int result;
+       char *pos = str;
 
        result = sscanf(str, "%hu-%hu", &lo, &hi);
        if (result == 1) {
@@ -99,7 +52,7 @@ rte_eth_devargs_process_range(char *str, uint16_t

*list, uint16_t *len_list,

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_process_range(char *str, uint16_t

Quoted 9 lines
lib/librte_ethdev/ethdev_private.c +1 -1
                        return -ENOMEM;
                list[(*len_list)++] = lo;
        } else if (result == 2) {
-               if (lo >= hi || lo > RTE_MAX_ETHPORTS || hi > RTE_MAX_ETHPORTS)
+               if (lo >= hi)
                        return -EINVAL;
                for (val = lo; val <= hi; val++) {
                        if (*len_list >= max_list)
@@ -108,14 +61,52 @@ rte_eth_devargs_process_range(char *str, uint16_t

*list, uint16_t *len_list,

Review

Quoted 55 lines
lib/librte_ethdev/ethdev_private.c +40 -2
                }
        } else
                return -EINVAL;
-       return 0;
+       while (*pos != 0 && ((*pos >= '0' && *pos <= '9') || *pos == '-'))
+               pos++;
+       return pos - str;
 }
 
+static int
+rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
+       const uint16_t max_list)
+{
+       char *pos = str;
+       int ret;
+
+       if (*pos == '[')
+               pos++;
+       while (1) {
+               ret = rte_eth_devargs_process_range(pos, list, len_list,
+                                                   max_list);
+               if (ret < 0)
+                       return ret;
+               pos += ret;
+               if (*pos != ',') /* end of list */
+                       break;
+               pos++;
+       }
+       if (*str == '[' && *pos != ']')
+               return -EINVAL;
+       if (*pos == ']')
+               pos++;
+       return pos - str;
+}
+
+/*
+ * representor format:
+ *   #: range or single number of VF representor - legacy
+ */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
 {
        struct rte_eth_devargs *eth_da = data;
+       int ret;
 
-       return rte_eth_devargs_process_range(str, eth_da->representor_ports,
+       /* Number # alone implies VF */
+       eth_da->type = RTE_ETH_REPRESENTOR_VF;
+       ret = rte_eth_devargs_process_list(str, eth_da->representor_ports,
                &eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
+       if (ret < 0)
+               RTE_LOG(ERR, EAL, "wrong representor format: %s\n", str);
+       return ret < 0 ? ret : 0;
 }
(quoted diff) +0 -0

b/lib/librte_ethdev/ethdev_private.h

lib/librte_ethdev/ethdev_private.h eth_find_device(const struct rte_eth_dev *_start,

Quoted 4 lines

index 905a45c337..220ddd4408 100644

lib/librte_ethdev/ethdev_private.h +0 -0
@@ -26,9 +26,6 @@ eth_find_device(const struct rte_eth_dev *_start,

rte_eth_cmp_t cmp,

lib/librte_ethdev/ethdev_private.h eth_find_device(const struct rte_eth_dev *_start, rte_eth_cmp_t cmp,

Quoted 5 lines
lib/librte_ethdev/ethdev_private.h +0 -2
                const void *data);
 
 /* Parse devargs value for representor parameter. */
-typedef int (*rte_eth_devargs_callback_t)(char *str, void *data);
-int rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t

callback,

Review

Quoted 5 lines
lib/librte_ethdev/ethdev_private.h +0 -1
-       void *data);
 int rte_eth_devargs_parse_representor_ports(char *str, void *data);
 
 #ifdef __cplusplus
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_class_eth.c

lib/librte_ethdev/rte_ethdev.c rte_eth_devargs_parse(const char *dargs, struct

Quoted 19 lines

index 6338355e25..efe6149df5 100644

lib/librte_ethdev/rte_class_eth.c +1 -3
@@ -77,9 +77,7 @@ eth_representor_cmp(const char *key __rte_unused,
        if (values == NULL)
                return -1;
        memset(&representors, 0, sizeof(representors));
-       ret = rte_eth_devargs_parse_list(values,
-                       rte_eth_devargs_parse_representor_ports,
-                       &representors);
+       ret = rte_eth_devargs_parse_representor_ports(values, &representors);
        free(values);
        if (ret != 0)
                return -1; /* invalid devargs value */
lib/librte_ethdev/rte_ethdev.c +0 -0
index 17ddacc78d..2ac51ac149 100644
@@ -5542,9 +5542,8 @@ rte_eth_devargs_parse(const char *dargs, struct

rte_eth_devargs *eth_da)

Review

Quoted 12 lines
lib/librte_ethdev/rte_ethdev.c +2 -3
        for (i = 0; i < args.count; i++) {
                pair = &args.pairs[i];
                if (strcmp("representor", pair->key) == 0) {
-                       result = rte_eth_devargs_parse_list(pair->value,
-                               rte_eth_devargs_parse_representor_ports,
-                               eth_da);
+                       result = rte_eth_devargs_parse_representor_ports(
+                                       pair->value, eth_da);
                        if (result < 0)
                                goto parse_cleanup;
                }
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_ethdev_driver.h

Quoted 25 lines

index 0eacfd8425..b66a955b18 100644

lib/librte_ethdev/rte_ethdev_driver.h +7 -1
@@ -1193,6 +1193,12 @@ __rte_internal
 int
 rte_eth_switch_domain_free(uint16_t domain_id);
 
+/** Ethernet device representor type */
+enum rte_eth_representor_type {
+       RTE_ETH_REPRESENTOR_NONE, /* not a representor */
+       RTE_ETH_REPRESENTOR_VF,   /* representor of VF */
+};
+
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
        uint16_t ports[RTE_MAX_ETHPORTS];
@@ -1203,6 +1209,7 @@ struct rte_eth_devargs {
        /** representor port/s identifier to enable on device */
        uint16_t nb_representor_ports;
        /** number of ports in representor port field */
+       enum rte_eth_representor_type type; /* type of representor */
 };
 
 /**
--
Quoted 2 lines

2.25.1

--
This electronic communication and the information and any files transmitted with it, or attached to it, are confidential and are intended solely for the use of the individual or entity to whom it is addressed and may contain information that is confidential, legally privileged, protected by privacy laws, or otherwise restricted from disclosure to anyone else. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, you are hereby notified that any use, copying, distributing, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please return the e-mail to the sender, delete it from your computer, and destroy any printed copy of it.

Signature · 11 lines
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.
author
#21 lore raw

v3 cover ethdev: support SubFunction representor

In reply to Xueming Li

SubFunction [1] is a portion of the PCI device, a SF netdev has its own dedicated queues(txq, rxq). A SF netdev supports eswitch representation offload similar to existing PF and VF representors. A SF shares PCI level resources with other SFs and/or with its parent PCI function.

From SmartNIC perspective, when PCI device is shared for multi-host, representors for host controller and host PF is required.

This patch set introduces new representor types in addtion to existing VF representor. Syntax:

[[c#]pf#]vf#: VF port representor/s from controller/pf [[c#]pf#]sf#: SF port representor/s from controller/pf #: VF representor - for backwards compatibility

"#" is number instance, list or range, valid examples:
1, [1,3,5], [0-3], [0,2-4,6]

For backward compatibility, this patch also introduces new netdev capability to indicate the capability of supportting SF representor.

Version history:
RFC:
initial version [2]
V2:
- separate patch for represnetor infrastructure, controller, pf and sf.
- replace representor ID macro with functions:
rte_eth_representor_id_encode() rte_eth_representor_id_parse()
- new patch to allow devargs with same PCI BDF but different representors.
- other minor code updates according to comments, thanks Andrew!
- update document
V3:
- improve probing of allowed devargs with same name.
- parse single word of kvargs as key.
- update kvargs test cases.

[1] SubFunction in kernel:
https://lore.kernel.org/netdev/[email protected]/

[2] RFC:
http://patchwork.dpdk.org/project/dpdk/list/?series=14376

[3] V2:
http://patchwork.dpdk.org/project/dpdk/list/?series=14559

Xueming Li (9):
ethdev: refactor representor infrastructure
ethdev: support new VF representor syntax
ethdev: support sub function representor
ethdev: support PF index in representor
ethdev: support multi-host representor
devarg: change reprsentor ID to bitmap
ethdev: capability of new representor syntax
kvargs: update parser for new representor syntax
eal: probe devices of same PCI but different devargs

 app/test/test_kvargs.c                   |  51 +++++++--
 config/rte_config.h                      |   1 +
 doc/guides/prog_guide/poll_mode_drv.rst  |   8 +-
 drivers/net/bnxt/bnxt_ethdev.c           |   7 ++
 drivers/net/bnxt/bnxt_reps.c             |   3 +-
 drivers/net/enic/enic_ethdev.c           |   7 ++
 drivers/net/enic/enic_vf_representor.c   |   3 +-
 drivers/net/i40e/i40e_ethdev.c           |   8 ++
 drivers/net/i40e/i40e_vf_representor.c   |   3 +-
 drivers/net/ixgbe/ixgbe_ethdev.c         |   8 ++
 drivers/net/ixgbe/ixgbe_vf_representor.c |   3 +-
 drivers/net/mlx5/linux/mlx5_os.c         |  15 ++-
 lib/librte_eal/common/eal_common_bus.c   |  23 ++++
 lib/librte_ethdev/ethdev_private.c       | 128 ++++++++++++++---------
 lib/librte_ethdev/ethdev_private.h       |   3 -
 lib/librte_ethdev/rte_class_eth.c        |  40 +++++--
 lib/librte_ethdev/rte_ethdev.c           |  31 +++++-
 lib/librte_ethdev/rte_ethdev.h           |   2 +
 lib/librte_ethdev/rte_ethdev_driver.h    |  64 ++++++++++++
 lib/librte_ethdev/version.map            |   2 +
 lib/librte_kvargs/rte_kvargs.c           | 101 +++++++++++++-----
 21 files changed, 401 insertions(+), 110 deletions(-)
Signature · 1 line
2.25.1
author
#22 lore raw

PATCH v3 1/9 ethdev: refactor representor infrastructure

In reply to Xueming Li

To support extended representor syntax, this patch refactor representor infrastructure:
1. introduces representor type enum
2. devargs representor port range extraction from partial value

---
 drivers/net/bnxt/bnxt_ethdev.c        |  7 ++
 drivers/net/enic/enic_ethdev.c        |  7 ++
 drivers/net/i40e/i40e_ethdev.c        |  8 +++
 drivers/net/ixgbe/ixgbe_ethdev.c      |  8 +++
 drivers/net/mlx5/linux/mlx5_os.c      | 11 ++++
 lib/librte_ethdev/ethdev_private.c    | 93 ++++++++++++---------------
 lib/librte_ethdev/ethdev_private.h    |  3 -
 lib/librte_ethdev/rte_class_eth.c     |  4 +-
 lib/librte_ethdev/rte_ethdev.c        |  5 +-
 lib/librte_ethdev/rte_ethdev_driver.h |  7 ++
 10 files changed, 93 insertions(+), 60 deletions(-)
drivers/net/bnxt/bnxt_ethdev.c +7 -0
index 0788d263d8..fe4d4d4728 100644
@@ -5513,6 +5513,13 @@ static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev,
 	int i, ret = 0;
 	struct rte_kvargs *kvlist = NULL;
 
+	if (eth_da->type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da->type != RTE_ETH_REPRESENTOR_VF) {
+		PMD_DRV_LOG(ERR, "unsupported representor type %d\n",
+			    eth_da->type);
+		return -ENOTSUP;
+	}
 	num_rep = eth_da->nb_representor_ports;
 	if (num_rep > BNXT_MAX_VF_REPS) {
 		PMD_DRV_LOG(ERR, "nb_representor_ports = %d > %d MAX VF REPS\n",
drivers/net/enic/enic_ethdev.c +7 -0
index d041a6bee9..dd085caa93 100644
@@ -1303,6 +1303,13 @@ static int eth_enic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 		if (retval)
 			return retval;
 	}
+	if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+		ENICPMD_LOG(ERR, "unsupported representor type: %s\n",
+			    pci_dev->device.devargs->args);
+		return -ENOTSUP;
+	}
 	retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
 		sizeof(struct enic),
 		eth_dev_pci_specific_init, pci_dev,
drivers/net/i40e/i40e_ethdev.c +8 -0
index 14622484a0..6b74b514fc 100644
@@ -640,6 +640,14 @@ eth_i40e_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 			return retval;
 	}
 
+	if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+		PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
+			    pci_dev->device.devargs->args);
+		return -ENOTSUP;
+	}
+
 	retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
 		sizeof(struct i40e_adapter),
 		eth_dev_pci_specific_init, pci_dev,
drivers/net/ixgbe/ixgbe_ethdev.c +8 -0
index d7a1806ab8..eb2c4929e2 100644
@@ -1717,6 +1717,14 @@ eth_ixgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 	} else
 		memset(&eth_da, 0, sizeof(eth_da));
 
+	if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+		PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
+			    pci_dev->device.devargs->args);
+		return -ENOTSUP;
+	}
+
 	retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
 		sizeof(struct ixgbe_adapter),
 		eth_dev_pci_specific_init, pci_dev,
drivers/net/mlx5/linux/mlx5_os.c +11 -0
index 6812a1f215..6981ba1f41 100644
@@ -706,6 +706,17 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 				strerror(rte_errno));
 			return NULL;
 		}
+		if (eth_da.type != RTE_ETH_REPRESENTOR_NONE) {
+			/* Representor not specified. */
+			rte_errno = EBUSY;
+			return NULL;
+		}
+		if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+			rte_errno = ENOTSUP;
+			DRV_LOG(ERR, "unsupported representor type: %s",
+				dpdk_dev->devargs->args);
+			return NULL;
+		}
 		for (i = 0; i < eth_da.nb_representor_ports; ++i)
 			if (eth_da.representor_ports[i] ==
 			    (uint16_t)switch_info->port_name)
lib/librte_ethdev/ethdev_private.c +42 -51

123 lines not on this page · raw message

lib/librte_ethdev/ethdev_private.h +0 -3
index 905a45c337..220ddd4408 100644
@@ -26,9 +26,6 @@ eth_find_device(const struct rte_eth_dev *_start, rte_eth_cmp_t cmp,
 		const void *data);
 
 /* Parse devargs value for representor parameter. */
-typedef int (*rte_eth_devargs_callback_t)(char *str, void *data);
-int rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
-	void *data);
 int rte_eth_devargs_parse_representor_ports(char *str, void *data);
 
 #ifdef __cplusplus
lib/librte_ethdev/rte_class_eth.c +1 -3
index 6338355e25..efe6149df5 100644
@@ -77,9 +77,7 @@ eth_representor_cmp(const char *key __rte_unused,
 	if (values == NULL)
 		return -1;
 	memset(&representors, 0, sizeof(representors));
-	ret = rte_eth_devargs_parse_list(values,
-			rte_eth_devargs_parse_representor_ports,
-			&representors);
+	ret = rte_eth_devargs_parse_representor_ports(values, &representors);
 	free(values);
 	if (ret != 0)
 		return -1; /* invalid devargs value */
lib/librte_ethdev/rte_ethdev.c +2 -3
index 17ddacc78d..2ac51ac149 100644
@@ -5542,9 +5542,8 @@ rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
 	for (i = 0; i < args.count; i++) {
 		pair = &args.pairs[i];
 		if (strcmp("representor", pair->key) == 0) {
-			result = rte_eth_devargs_parse_list(pair->value,
-				rte_eth_devargs_parse_representor_ports,
-				eth_da);
+			result = rte_eth_devargs_parse_representor_ports(
+					pair->value, eth_da);
 			if (result < 0)
 				goto parse_cleanup;
 		}
lib/librte_ethdev/rte_ethdev_driver.h +7 -0
index 0eacfd8425..b66a955b18 100644
@@ -1193,6 +1193,12 @@ __rte_internal
 int
 rte_eth_switch_domain_free(uint16_t domain_id);
 
+/** Ethernet device representor type */
+enum rte_eth_representor_type {
+	RTE_ETH_REPRESENTOR_NONE, /* not a representor */
+	RTE_ETH_REPRESENTOR_VF,   /* representor of VF */
+};
+
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
 	uint16_t ports[RTE_MAX_ETHPORTS];
@@ -1203,6 +1209,7 @@ struct rte_eth_devargs {
 	/** representor port/s identifier to enable on device */
 	uint16_t nb_representor_ports;
 	/** number of ports in representor port field */
+	enum rte_eth_representor_type type; /* type of representor */
 };
 
 /**
Signature · 1 line
2.25.1
author
#23 lore raw

PATCH v3 2/9 ethdev: support new VF representor syntax

In reply to Xueming Li

To prepare for more representor types, this patch adds compatible VF representor devargs syntax:

vf#: new VF port representor/s, example: vf[0-3], vf2

For backwards compatibility, representor "#" is deemed as "vf#".

---
 doc/guides/prog_guide/poll_mode_drv.rst | 6 +++---
 lib/librte_ethdev/ethdev_private.c      | 5 ++++-
 2 files changed, 7 insertions(+), 4 deletions(-)
doc/guides/prog_guide/poll_mode_drv.rst +3 -3
index 239ec820ea..979a2bab9d 100644
@@ -374,9 +374,9 @@ parameters to those ports.
   this argument allows user to specify which switch ports to enable port
   representors for.::
 
-   -a DBDF,representor=0
-   -a DBDF,representor=[0,4,6,9]
-   -a DBDF,representor=[0-31]
+   -a DBDF,representor=vf0
+   -a DBDF,representor=vf[0,4,6,9]
+   -a DBDF,representor=vf[0-31]
 
 Note: PMDs are not required to support the standard device arguments and users
 should consult the relevant PMD documentation to see support devargs.
lib/librte_ethdev/ethdev_private.c +4 -1
index c219164a4a..54f565ca37 100644
@@ -95,6 +95,7 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
 /*
  * representor format:
  *   #: range or single number of VF representor - legacy
+ *   vf#: VF port representor/s
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
@@ -102,8 +103,10 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	struct rte_eth_devargs *eth_da = data;
 	int ret;
 
-	/* Number # alone implies VF */
+	/* Parse vf# or number # alone implies VF */
 	eth_da->type = RTE_ETH_REPRESENTOR_VF;
+	if (str[0] == 'v'  && str[1] == 'f')
+		str += 2;
 	ret = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
 	if (ret < 0)
Signature · 1 line
2.25.1
author
#24 lore raw

PATCH v3 3/9 ethdev: support sub function representor

In reply to Xueming Li

SubFunction is a portion of the PCI device, created on demand, a SF netdev has its own dedicated queues(txq, rxq). A SF netdev supports eswitch representation offload similar to existing PF and VF representors.

To support SF representor, this patch introduces new devargs syntax:

sf#: new SF port representor/s, example: sf[0-3], sf2

---
 doc/guides/prog_guide/poll_mode_drv.rst |  1 +
 lib/librte_ethdev/ethdev_private.c      | 14 +++++++++++---
 lib/librte_ethdev/rte_ethdev_driver.h   |  1 +
 3 files changed, 13 insertions(+), 3 deletions(-)
doc/guides/prog_guide/poll_mode_drv.rst +1 -0
index 979a2bab9d..831d620c8d 100644
@@ -377,6 +377,7 @@ parameters to those ports.
    -a DBDF,representor=vf0
    -a DBDF,representor=vf[0,4,6,9]
    -a DBDF,representor=vf[0-31]
+   -a DBDF,representor=sf[0-1023]
 
 Note: PMDs are not required to support the standard device arguments and users
 should consult the relevant PMD documentation to see support devargs.
lib/librte_ethdev/ethdev_private.c +11 -3
index 54f565ca37..551a43738a 100644
@@ -96,6 +96,7 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
  * representor format:
  *   #: range or single number of VF representor - legacy
  *   vf#: VF port representor/s
+ *   sf#: SF port representor/s
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
@@ -103,10 +104,17 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	struct rte_eth_devargs *eth_da = data;
 	int ret;
 
-	/* Parse vf# or number # alone implies VF */
-	eth_da->type = RTE_ETH_REPRESENTOR_VF;
-	if (str[0] == 'v'  && str[1] == 'f')
+	eth_da->type = RTE_ETH_REPRESENTOR_NONE;
+	/* Parse vf# and sf#, number # alone implies VF */
+	if (str[0] == 'v'  && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_VF;
 		str += 2;
+	} else if (str[0] == 's'  && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_SF;
+		str += 2;
+	} else {
+		eth_da->type = RTE_ETH_REPRESENTOR_VF;
+	}
 	ret = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
 	if (ret < 0)
lib/librte_ethdev/rte_ethdev_driver.h +1 -0
index b66a955b18..086d64223a 100644
@@ -1197,6 +1197,7 @@ rte_eth_switch_domain_free(uint16_t domain_id);
 enum rte_eth_representor_type {
 	RTE_ETH_REPRESENTOR_NONE, /* not a representor */
 	RTE_ETH_REPRESENTOR_VF,   /* representor of VF */
+	RTE_ETH_REPRESENTOR_SF,   /* representor of SF */
 };
 
 /** Generic Ethernet device arguments  */
Signature · 1 line
2.25.1
author
#25 lore raw

PATCH v3 4/9 ethdev: support PF index in representor

In reply to Xueming Li

To support representor in bonding, this patch introduces 'pf' section to representor devargs syntax:

[pf#]vf#: VF port representor/s, example: vf3, pf0vf3 [pf#]sf#: SF port representor/s, example: sf2, pf1sf2

pf# is optional for SF and VF representor, indicates owner PF device of SF or VF.

---
 doc/guides/prog_guide/poll_mode_drv.rst |  1 +
 lib/librte_ethdev/ethdev_private.c      | 15 +++++++++++++--
 lib/librte_ethdev/rte_ethdev_driver.h   |  1 +
 3 files changed, 15 insertions(+), 2 deletions(-)
doc/guides/prog_guide/poll_mode_drv.rst +1 -0
index 831d620c8d..87f23c4f49 100644
@@ -378,6 +378,7 @@ parameters to those ports.
    -a DBDF,representor=vf[0,4,6,9]
    -a DBDF,representor=vf[0-31]
    -a DBDF,representor=sf[0-1023]
+   -a DBDF,representor=pf[0-1]sf[0-1023]
 
 Note: PMDs are not required to support the standard device arguments and users
 should consult the relevant PMD documentation to see support devargs.
lib/librte_ethdev/ethdev_private.c +13 -2
index 551a43738a..ccc638ec49 100644
@@ -95,8 +95,8 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
 /*
  * representor format:
  *   #: range or single number of VF representor - legacy
- *   vf#: VF port representor/s
- *   sf#: SF port representor/s
+ *   [pf#]vf#: VF port representor/s
+ *   [pf#]sf#: SF port representor/s
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
@@ -105,6 +105,16 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	int ret;
 
 	eth_da->type = RTE_ETH_REPRESENTOR_NONE;
+	/* Parse pf# */
+	if (str[0] == 'p' && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_PF;
+		str += 2;
+		ret = rte_eth_devargs_process_list(str, eth_da->ports,
+				&eth_da->nb_ports, RTE_MAX_ETHPORTS);
+		if (ret < 0)
+			goto err;
+		str += ret;
+	}
 	/* Parse vf# and sf#, number # alone implies VF */
 	if (str[0] == 'v'  && str[1] == 'f') {
 		eth_da->type = RTE_ETH_REPRESENTOR_VF;
@@ -117,6 +127,7 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	}
 	ret = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
+err:
 	if (ret < 0)
 		RTE_LOG(ERR, EAL, "wrong representor format: %s\n", str);
 	return ret < 0 ? ret : 0;
lib/librte_ethdev/rte_ethdev_driver.h +1 -0
index 086d64223a..edb000cbd4 100644
@@ -1198,6 +1198,7 @@ enum rte_eth_representor_type {
 	RTE_ETH_REPRESENTOR_NONE, /* not a representor */
 	RTE_ETH_REPRESENTOR_VF,   /* representor of VF */
 	RTE_ETH_REPRESENTOR_SF,   /* representor of SF */
+	RTE_ETH_REPRESENTOR_PF,   /* representor of host PF */
 };
 
 /** Generic Ethernet device arguments  */
Signature · 1 line
2.25.1
author
#26 lore raw

PATCH v3 5/9 ethdev: support multi-host representor

In reply to Xueming Li

This patch introduces multi-host controller for ethdev representor syntax, examples:

[[c#]pf#]vf#: VF port representor/s, example: pf0vf1 [[c#]pf#]sf#: SF port representor/s, example: c1pf1sf[0-3]

c# is controller(host) ID/range in case of multi-host, optional. It is mostly for SmartNIC attached to multiple hosts in the same rack to allow routing the packets between PF/SF/VF running on these hosts.

Controller ID is physical host ID in multi-host, for end-user (e.g. OVS) it is transparent as part of representor syntax, sam as representor ID, interpreted by PMD.

---
 config/rte_config.h                   |  1 +
 lib/librte_ethdev/ethdev_private.c    | 14 ++++++++++++--
 lib/librte_ethdev/rte_ethdev_driver.h |  4 ++++
 3 files changed, 17 insertions(+), 2 deletions(-)
config/rte_config.h +1 -0
index a0b5160ff2..23d02d51ef 100644
@@ -58,6 +58,7 @@
 #define RTE_MAX_QUEUES_PER_PORT 1024
 #define RTE_ETHDEV_QUEUE_STAT_CNTRS 16 /* max 256 */
 #define RTE_ETHDEV_RXTX_CALLBACKS 1
+#define RTE_MAX_MULTI_HOST_CTRLS 4
 
 /* cryptodev defines */
 #define RTE_CRYPTO_MAX_DEVS 64
lib/librte_ethdev/ethdev_private.c +12 -2
index ccc638ec49..95f1ab847a 100644
@@ -95,8 +95,8 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
 /*
  * representor format:
  *   #: range or single number of VF representor - legacy
- *   [pf#]vf#: VF port representor/s
- *   [pf#]sf#: SF port representor/s
+ *   [[c#]pf#]vf#: VF port representor/s
+ *   [[c#]pf#]sf#: SF port representor/s
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
@@ -105,6 +105,16 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	int ret;
 
 	eth_da->type = RTE_ETH_REPRESENTOR_NONE;
+	/* Parse c# */
+	if (str[0] == 'c') {
+		str += 1;
+		ret = rte_eth_devargs_process_list(str, eth_da->mh_controllers,
+				&eth_da->nb_mh_controllers,
+				RTE_DIM(eth_da->mh_controllers));
+		if (ret < 0)
+			goto err;
+		str += ret;
+	}
 	/* Parse pf# */
 	if (str[0] == 'p' && str[1] == 'f') {
 		eth_da->type = RTE_ETH_REPRESENTOR_PF;
lib/librte_ethdev/rte_ethdev_driver.h +4 -0
index edb000cbd4..b9e4a0b9ba 100644
@@ -1203,6 +1203,10 @@ enum rte_eth_representor_type {
 
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
+	uint16_t mh_controllers[RTE_MAX_MULTI_HOST_CTRLS];
+	/** controller/s number in case of multi-host */
+	uint16_t nb_mh_controllers;
+	/** number of controllers in multi-host controllers field */
 	uint16_t ports[RTE_MAX_ETHPORTS];
 	/** port/s number to enable on a multi-port single function */
 	uint16_t nb_ports;
Signature · 1 line
2.25.1
author
#27 lore raw

PATCH v3 6/9 devarg: change reprsentor ID to bitmap

In reply to Xueming Li

In eth representor comparator callback, ethdev was compared with devarg. Since ethdev representor port didn't contain controller(host) and owner port information, callback only compared representor port and returned representor port on other PF port.

This patch changes representor port to bitmap encoding, expands and updates representor port ID after parsing, when device representor ID uses the same bitmap encoding, the eth representor comparer callback returns correct ethdev.

Representor port ID bitmap definition:
Representor ID bitmap:
xxxx xxxx xxxx xxxx

 |||| |LLL LLLL LLLL vf/sf id
 |||| L 1:sf, 0:vf
 ||LL pf id

LL controller(host) id

---
 drivers/net/bnxt/bnxt_reps.c             |  3 +-
 drivers/net/enic/enic_vf_representor.c   |  3 +-
 drivers/net/i40e/i40e_vf_representor.c   |  3 +-
 drivers/net/ixgbe/ixgbe_vf_representor.c |  3 +-
 drivers/net/mlx5/linux/mlx5_os.c         |  4 +-
 lib/librte_ethdev/ethdev_private.c       |  5 ++-
 lib/librte_ethdev/rte_class_eth.c        | 38 ++++++++++++++----
 lib/librte_ethdev/rte_ethdev.c           | 26 ++++++++++++
 lib/librte_ethdev/rte_ethdev_driver.h    | 51 ++++++++++++++++++++++++
 lib/librte_ethdev/version.map            |  2 +
 10 files changed, 124 insertions(+), 14 deletions(-)
drivers/net/bnxt/bnxt_reps.c +2 -1
index f7bbf77d3f..34febc2d1e 100644
@@ -186,7 +186,8 @@ int bnxt_representor_init(struct rte_eth_dev *eth_dev, void *params)
 
 	eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
 					RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-	eth_dev->data->representor_id = rep_params->vf_id;
+	eth_dev->data->representor_id = rte_eth_representor_id_encode(
+		0, 0, RTE_ETH_REPRESENTOR_VF, rep_params->vf_id);
 
 	rte_eth_random_addr(vf_rep_bp->dflt_mac_addr);
 	memcpy(vf_rep_bp->mac_addr, vf_rep_bp->dflt_mac_addr,
drivers/net/enic/enic_vf_representor.c +2 -1
index c2c03c0281..632317af15 100644
@@ -674,7 +674,8 @@ int enic_vf_representor_init(struct rte_eth_dev *eth_dev, void *init_params)
 	eth_dev->dev_ops = &enic_vf_representor_dev_ops;
 	eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
 					RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-	eth_dev->data->representor_id = vf->vf_id;
+	eth_dev->data->representor_id = rte_eth_representor_id_encode(
+		0, 0, RTE_ETH_REPRESENTOR_VF, vf->vf_id);
 	eth_dev->data->mac_addrs = rte_zmalloc("enic_mac_addr_vf",
 		sizeof(struct rte_ether_addr) *
 		ENIC_UNICAST_PERFECT_FILTERS, 0);
drivers/net/i40e/i40e_vf_representor.c +2 -1
index 9e40406a3d..d90d0fdb9d 100644
@@ -510,7 +510,8 @@ i40e_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params)
 
 	ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
 					RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-	ethdev->data->representor_id = representor->vf_id;
+	ethdev->data->representor_id = rte_eth_representor_id_encode(
+			0, 0, RTE_ETH_REPRESENTOR_VF, representor->vf_id);
 
 	/* Setting the number queues allocated to the VF */
 	ethdev->data->nb_rx_queues = vf->vsi->nb_qps;
drivers/net/ixgbe/ixgbe_vf_representor.c +2 -1
index 8185f0d3bb..e15b794761 100644
@@ -196,7 +196,8 @@ ixgbe_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params)
 		return -ENODEV;
 
 	ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
-	ethdev->data->representor_id = representor->vf_id;
+	ethdev->data->representor_id = rte_eth_representor_id_encode(
+			0, 0, RTE_ETH_REPRESENTOR_VF, representor->vf_id);
 
 	/* Set representor device ops */
 	ethdev->dev_ops = &ixgbe_vf_representor_dev_ops;
drivers/net/mlx5/linux/mlx5_os.c +3 -1
index 6981ba1f41..7739a1b0a5 100644
@@ -1031,7 +1031,9 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 #endif
 	/* representor_id field keeps the unmodified VF index. */
 	priv->representor_id = switch_info->representor ?
-			       switch_info->port_name : -1;
+		rte_eth_representor_id_encode(0, 0, RTE_ETH_REPRESENTOR_VF,
+					      switch_info->port_name) :
+		-1;
 	/*
 	 * Look for sibling devices in order to reuse their switch domain
 	 * if any, otherwise allocate one.
lib/librte_ethdev/ethdev_private.c +4 -1
index 95f1ab847a..57e84a34af 100644
@@ -93,10 +93,13 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
 }
 
 /*
- * representor format:
+ * Parse representor ports, expand and update representor port ID.
+ * Representor format:
  *   #: range or single number of VF representor - legacy
  *   [[c#]pf#]vf#: VF port representor/s
  *   [[c#]pf#]sf#: SF port representor/s
+ *
+ * See RTE_ETH_REPR() for representor ID format.
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
lib/librte_ethdev/rte_class_eth.c +30 -8
index efe6149df5..994db96960 100644
@@ -66,8 +66,8 @@ eth_representor_cmp(const char *key __rte_unused,
 	int ret;
 	char *values;
 	const struct rte_eth_dev_data *data = opaque;
-	struct rte_eth_devargs representors;
-	uint16_t index;
+	struct rte_eth_devargs eth_da;
+	uint16_t index, c, p, f;
 
 	if ((data->dev_flags & RTE_ETH_DEV_REPRESENTOR) == 0)
 		return -1; /* not a representor port */
@@ -76,17 +76,39 @@ eth_representor_cmp(const char *key __rte_unused,
 	values = strdup(value);
 	if (values == NULL)
 		return -1;
-	memset(&representors, 0, sizeof(representors));
-	ret = rte_eth_devargs_parse_representor_ports(values, &representors);
+	memset(&eth_da, 0, sizeof(eth_da));
+	ret = rte_eth_devargs_parse_representor_ports(values, &eth_da);
 	free(values);
 	if (ret != 0)
 		return -1; /* invalid devargs value */
 
+	/* Set default values. */
+	if (eth_da.nb_mh_controllers == 0) {
+		eth_da.nb_mh_controllers = 1;
+		eth_da.mh_controllers[0] = 0;
+	}
+	if (eth_da.nb_ports == 0) {
+		eth_da.nb_ports = 1;
+		eth_da.ports[0] = 0;
+	}
+	if (eth_da.nb_representor_ports == 0) {
+		eth_da.nb_representor_ports = 1;
+		eth_da.representor_ports[0] = 0;
+	}
 	/* Return 0 if representor id is matching one of the values. */
-	for (index = 0; index < representors.nb_representor_ports; index++)
-		if (data->representor_id ==
-				representors.representor_ports[index])
-			return 0;
+	for (c = 0; c < eth_da.nb_mh_controllers; ++c) {
+		for (p = 0; p < eth_da.nb_ports; ++p) {
+			for (f = 0; f < eth_da.nb_representor_ports; ++f) {
+				index = rte_eth_representor_id_encode(
+					eth_da.mh_controllers[c],
+					eth_da.ports[p],
+					eth_da.type,
+					eth_da.representor_ports[f]);
+				if (data->representor_id == index)
+					return 0;
+			}
+		}
+	}
 	return -1; /* no match */
 }
 
lib/librte_ethdev/rte_ethdev.c +26 -0
index 2ac51ac149..276f42e54b 100644
@@ -5556,6 +5556,32 @@ rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
 	return result;
 }
 
+uint16_t
+rte_eth_representor_id_encode(uint16_t controller, uint16_t pf,
+			      enum rte_eth_representor_type type,
+			      uint16_t representor_port)
+{
+	return (((controller & 3) << 14) |
+		((pf & 3) << 12) |
+		(!!(type == RTE_ETH_REPRESENTOR_SF) << 11) |
+		(representor_port & 0x7ff));
+}
+
+uint16_t
+rte_eth_representor_id_parse(const uint16_t representor_id,
+			     uint16_t *controller, uint16_t *pf,
+			     enum rte_eth_representor_type *type)
+{
+	if (controller)
+		*controller = (representor_id >> 14) & 3;
+	if (pf)
+		*pf = (representor_id >> 12) & 3;
+	if (type)
+		*type = ((representor_id >> 11) & 1) ?
+			RTE_ETH_REPRESENTOR_SF : RTE_ETH_REPRESENTOR_VF;
+	return representor_id & 0x7ff;
+}
+
 static int
 eth_dev_handle_port_list(const char *cmd __rte_unused,
 		const char *params __rte_unused,
lib/librte_ethdev/rte_ethdev_driver.h +51 -0

57 lines not on this page · raw message

lib/librte_ethdev/version.map +2 -0
index d3f5410806..44edaed507 100644
@@ -257,6 +257,8 @@ INTERNAL {
 	rte_eth_dev_release_port;
 	rte_eth_dev_internal_reset;
 	rte_eth_devargs_parse;
+	rte_eth_representor_id_encode;
+	rte_eth_representor_id_parse;
 	rte_eth_dma_zone_free;
 	rte_eth_dma_zone_reserve;
 	rte_eth_hairpin_queue_peer_bind;
Signature · 1 line
2.25.1
author
#29 lore raw

PATCH v3 8/9 kvargs: update parser for new representor syntax

In reply to Xueming Li

This patch updates kvargs parser to allow comma in list value:
k1=a[1,2]b[3-5]

---
 app/test/test_kvargs.c         |  51 +++++++++++++++--
 lib/librte_kvargs/rte_kvargs.c | 101 +++++++++++++++++++++++----------
 2 files changed, 117 insertions(+), 35 deletions(-)
app/test/test_kvargs.c +45 -6
index 2a2dae43a0..b42cdcb9f5 100644
@@ -35,6 +35,25 @@ static int check_handler(const char *key, const char *value,
 	return 0;
 }
 
+/* test parsing. */
+static int test_kvargs_parsing(const char *args, unsigned int n)
+{
+	struct rte_kvargs *kvlist;
+
+	kvlist = rte_kvargs_parse(args, NULL);
+	if (kvlist == NULL) {
+		printf("rte_kvargs_parse() error: %s\n", args);
+		return -1;
+	}
+	if (kvlist->count != n) {
+		printf("invalid count value %d: %s\n", kvlist->count, args);
+		rte_kvargs_free(kvlist);
+		return -1;
+	}
+	rte_kvargs_free(kvlist);
+	return 0;
+}
+
 /* test a valid case */
 static int test_valid_kvargs(void)
 {
@@ -191,6 +210,32 @@ static int test_valid_kvargs(void)
 	}
 	rte_kvargs_free(kvlist);
 
+	valid_keys = NULL;
+
+	args = "foo=1,foo=";
+	if (test_kvargs_parsing(args, 2))
+		goto fail;
+
+	args = "foo=1,foo";
+	if (test_kvargs_parsing(args, 2))
+		goto fail;
+
+	args = "foo=1,=2";
+	if (test_kvargs_parsing(args, 2))
+		goto fail;
+
+	args = "foo=[1,2";
+	if (test_kvargs_parsing(args, 1))
+		goto fail;
+
+	args = ",=";
+	if (test_kvargs_parsing(args, 1))
+		goto fail;
+
+	args = "foo=[";
+	if (test_kvargs_parsing(args, 1))
+		goto fail;
+
 	return 0;
 
  fail:
@@ -212,12 +257,6 @@ static int test_invalid_kvargs(void)
 	/* list of argument that should fail */
 	const char *args_list[] = {
 		"wrong-key=x",     /* key not in valid_keys_list */
-		"foo=1,foo=",      /* empty value */
-		"foo=1,foo",       /* no value */
-		"foo=1,=2",        /* no key */
-		"foo=[1,2",        /* no closing bracket in value */
-		",=",              /* also test with a smiley */
-		"foo=[",           /* no value in list and no closing bracket */
 		NULL };
 	const char **args;
 	const char *valid_keys_list[] = { "foo", "check", NULL };
lib/librte_kvargs/rte_kvargs.c +72 -29

129 lines not on this page · raw message

Signature · 1 line
2.25.1
author
#28 lore raw

PATCH v3 7/9 ethdev: capability of new representor syntax

In reply to Xueming Li

New representor devargs syntax can't be recognized correctly by previous DPDK version. For application to adapt different DPDK version automatically, this patch introduces new eth device capability of supportting SubFunction representor device.

---
 lib/librte_ethdev/rte_ethdev.h | 2 ++
 1 file changed, 2 insertions(+)
lib/librte_ethdev/rte_ethdev.h +2 -0
index f5f8919186..3c087bec67 100644
@@ -1432,6 +1432,8 @@ struct rte_eth_conf {
 #define RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP 0x00000001
 /** Device supports Tx queue setup after device started. */
 #define RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP 0x00000002
+/**< Device supports SubFunction representor. */
+#define RTE_ETH_DEV_CAPA_REPRESENTOR_SF         0x00000004
 /**@}*/
 
 /*
Signature · 1 line
2.25.1
author
#30 lore raw

PATCH v3 9/9 eal: probe devices of same PCI but different devargs

In reply to Xueming Li

When probing same PCI device with different representor arguments, PCI bus only probed first devargs, ignored other allowed devices with different representor arguments.

This patch iterates all devargs and try them all after bus scan.

---
 lib/librte_eal/common/eal_common_bus.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
lib/librte_eal/common/eal_common_bus.c +23 -0
index baa5b532af..9f88a0fe6e 100644
@@ -10,6 +10,7 @@
 #include <rte_debug.h>
 #include <rte_string_fns.h>
 #include <rte_errno.h>
+#include <rte_devargs.h>
 
 #include "eal_private.h"
 
@@ -56,12 +57,22 @@ rte_bus_scan(void)
 	return 0;
 }
 
+static int
+cmp_dev_name(const struct rte_device *dev, const void *_name)
+{
+	const char *name = _name;
+
+	return strcmp(dev->name, name);
+}
+
 /* Probe all devices of all buses */
 int
 rte_bus_probe(void)
 {
 	int ret;
 	struct rte_bus *bus, *vbus = NULL;
+	struct rte_devargs *da;
+	struct rte_device *dev;
 
 	TAILQ_FOREACH(bus, &rte_bus_list, next) {
 		if (!strcmp(bus->name, "vdev")) {
@@ -82,6 +93,18 @@ rte_bus_probe(void)
 				vbus->name);
 	}
 
+	/* For devargs with same name but different arguments, try them all. */
+	RTE_EAL_DEVARGS_FOREACH(NULL, da) {
+		dev = da->bus->find_device(NULL, cmp_dev_name, da->name);
+		if (!dev || !rte_dev_is_probed(dev) || dev->devargs == da)
+			continue;
+		dev->devargs = da;
+		ret = dev->bus->plug(dev);
+		if (ret == 0)
+			RTE_LOG(DEBUG, EAL, "device probed %s %s", da->name,
+				da->args);
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.25.1
author
#32 lore raw

PATCH v4 1/9 ethdev: introduce representor type

In reply to Xueming Li

To support more representor type, this patch introduces representor type enum. The enum is subject to extend for new types upcoming.

---
 drivers/net/bnxt/bnxt_ethdev.c        |  7 +++++++
 drivers/net/enic/enic_ethdev.c        |  7 +++++++
 drivers/net/i40e/i40e_ethdev.c        |  8 ++++++++
 drivers/net/ixgbe/ixgbe_ethdev.c      |  8 ++++++++
 drivers/net/mlx5/linux/mlx5_os.c      | 11 +++++++++++
 lib/librte_ethdev/ethdev_private.c    |  5 +++++
 lib/librte_ethdev/rte_ethdev_driver.h |  9 +++++++++
 7 files changed, 55 insertions(+)
drivers/net/bnxt/bnxt_ethdev.c +7 -0
index 74b0f3d1dc..d7c8b3ec07 100644
@@ -5586,6 +5586,13 @@ static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev,
 	int i, ret = 0;
 	struct rte_kvargs *kvlist = NULL;
 
+	if (eth_da->type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da->type != RTE_ETH_REPRESENTOR_VF) {
+		PMD_DRV_LOG(ERR, "unsupported representor type %d\n",
+			    eth_da->type);
+		return -ENOTSUP;
+	}
 	num_rep = eth_da->nb_representor_ports;
 	if (num_rep > BNXT_MAX_VF_REPS) {
 		PMD_DRV_LOG(ERR, "nb_representor_ports = %d > %d MAX VF REPS\n",
drivers/net/enic/enic_ethdev.c +7 -0
index d041a6bee9..dd085caa93 100644
@@ -1303,6 +1303,13 @@ static int eth_enic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 		if (retval)
 			return retval;
 	}
+	if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+		ENICPMD_LOG(ERR, "unsupported representor type: %s\n",
+			    pci_dev->device.devargs->args);
+		return -ENOTSUP;
+	}
 	retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
 		sizeof(struct enic),
 		eth_dev_pci_specific_init, pci_dev,
drivers/net/i40e/i40e_ethdev.c +8 -0
index c1c2327b3f..3cea6de2bd 100644
@@ -638,6 +638,14 @@ eth_i40e_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 			return retval;
 	}
 
+	if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+		PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
+			    pci_dev->device.devargs->args);
+		return -ENOTSUP;
+	}
+
 	retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
 		sizeof(struct i40e_adapter),
 		eth_dev_pci_specific_init, pci_dev,
drivers/net/ixgbe/ixgbe_ethdev.c +8 -0
index d7a1806ab8..eb2c4929e2 100644
@@ -1717,6 +1717,14 @@ eth_ixgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 	} else
 		memset(&eth_da, 0, sizeof(eth_da));
 
+	if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+		PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
+			    pci_dev->device.devargs->args);
+		return -ENOTSUP;
+	}
+
 	retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
 		sizeof(struct ixgbe_adapter),
 		eth_dev_pci_specific_init, pci_dev,
drivers/net/mlx5/linux/mlx5_os.c +11 -0
index 9ac1d46b1b..caead107b0 100644
@@ -705,6 +705,17 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 				strerror(rte_errno));
 			return NULL;
 		}
+		if (eth_da.type != RTE_ETH_REPRESENTOR_NONE) {
+			/* Representor not specified. */
+			rte_errno = EBUSY;
+			return NULL;
+		}
+		if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+			rte_errno = ENOTSUP;
+			DRV_LOG(ERR, "unsupported representor type: %s",
+				dpdk_dev->devargs->args);
+			return NULL;
+		}
 		for (i = 0; i < eth_da.nb_representor_ports; ++i)
 			if (eth_da.representor_ports[i] ==
 			    (uint16_t)switch_info->port_name)
lib/librte_ethdev/ethdev_private.c +5 -0
index 162a502fe7..c1a411dba4 100644
@@ -111,11 +111,16 @@ rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
 	return 0;
 }
 
+/*
+ * representor format:
+ *   #: range or single number of VF representor
+ */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
 {
 	struct rte_eth_devargs *eth_da = data;
 
+	eth_da->type = RTE_ETH_REPRESENTOR_VF;
 	return rte_eth_devargs_process_range(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
 }
lib/librte_ethdev/rte_ethdev_driver.h +9 -0
index 0eacfd8425..3bc5c5bbbb 100644
@@ -1193,6 +1193,14 @@ __rte_internal
 int
 rte_eth_switch_domain_free(uint16_t domain_id);
 
+/** Ethernet device representor type */
+enum rte_eth_representor_type {
+	RTE_ETH_REPRESENTOR_NONE, /**< not a representor. */
+	RTE_ETH_REPRESENTOR_VF,   /**< representor of VF. */
+	RTE_ETH_REPRESENTOR_SF,   /**< representor of SF. */
+	RTE_ETH_REPRESENTOR_PF,   /**< representor of host PF. */
+};
+
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
 	uint16_t ports[RTE_MAX_ETHPORTS];
@@ -1203,6 +1211,7 @@ struct rte_eth_devargs {
 	/** representor port/s identifier to enable on device */
 	uint16_t nb_representor_ports;
 	/** number of ports in representor port field */
+	enum rte_eth_representor_type type; /* type of representor */
 };
 
 /**
Signature · 1 line
2.25.1
author
#46 lore raw

PATCH v4 2/9 ethdev: support representor port list

In reply to Xueming Li

To support extended representor syntax, this patch extends the representor list parsing to support for representor port range in devargs, examples:
representor=[1,2,3] - single list
representor=[1,3-5,7,9-11] - list with singles and ranges

---
 lib/librte_ethdev/ethdev_private.c | 105 ++++++++++++++---------------
 lib/librte_ethdev/ethdev_private.h |   3 -
 lib/librte_ethdev/rte_class_eth.c  |   4 +-
 lib/librte_ethdev/rte_ethdev.c     |   5 +-
 4 files changed, 54 insertions(+), 63 deletions(-)
lib/librte_ethdev/ethdev_private.c +51 -54
index c1a411dba4..12bcc7e98d 100644
@@ -38,77 +38,71 @@ eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp,
 	return NULL;
 }
 
-int
-rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
-	void *data)
+static int
+rte_eth_devargs_enlist(uint16_t *list, uint16_t *len_list,
+		       const uint16_t max_list, uint16_t val)
 {
-	char *str_start;
-	int state;
-	int result;
-
-	if (*str != '[')
-		/* Single element, not a list */
-		return callback(str, data);
-
-	/* Sanity check, then strip the brackets */
-	str_start = &str[strlen(str) - 1];
-	if (*str_start != ']') {
-		RTE_LOG(ERR, EAL, "(%s): List does not end with ']'\n", str);
-		return -EINVAL;
-	}
-	str++;
-	*str_start = '\0';
+	uint16_t i;
 
-	/* Process list elements */
-	state = 0;
-	while (1) {
-		if (state == 0) {
-			if (*str == '\0')
-				break;
-			if (*str != ',') {
-				str_start = str;
-				state = 1;
-			}
-		} else if (state == 1) {
-			if (*str == ',' || *str == '\0') {
-				if (str > str_start) {
-					/* Non-empty string fragment */
-					*str = '\0';
-					result = callback(str_start, data);
-					if (result < 0)
-						return result;
-				}
-				state = 0;
-			}
-		}
-		str++;
+	if (*len_list >= max_list)
+		return -1;
+	for (i = 0; i < *len_list; i++) {
+		if (list[i] == val)
+			return 0;
 	}
+	list[(*len_list)++] = val;
 	return 0;
 }
 
-static int
+static char *
 rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
 	const uint16_t max_list)
 {
 	uint16_t lo, hi, val;
 	int result;
+	char *pos = str;
 
 	result = sscanf(str, "%hu-%hu", &lo, &hi);
 	if (result == 1) {
-		if (*len_list >= max_list)
-			return -ENOMEM;
-		list[(*len_list)++] = lo;
+		if (rte_eth_devargs_enlist(list, len_list, max_list, lo) != 0)
+			return NULL;
 	} else if (result == 2) {
-		if (lo >= hi || lo > RTE_MAX_ETHPORTS || hi > RTE_MAX_ETHPORTS)
-			return -EINVAL;
+		if (lo >= hi)
+			return NULL;
 		for (val = lo; val <= hi; val++) {
-			if (*len_list >= max_list)
-				return -ENOMEM;
-			list[(*len_list)++] = val;
+			if (rte_eth_devargs_enlist(list, len_list, max_list,
+						   val) != 0)
+				return NULL;
 		}
 	} else
-		return -EINVAL;
-	return 0;
+		return NULL;
+	while (*pos != 0 && ((*pos >= '0' && *pos <= '9') || *pos == '-'))
+		pos++;
+	return pos;
+}
+
+static char *
+rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
+	const uint16_t max_list)
+{
+	char *pos = str;
+
+	if (*pos == '[')
+		pos++;
+	while (1) {
+		pos = rte_eth_devargs_process_range(pos, list, len_list,
+						    max_list);
+		if (pos == NULL)
+			return NULL;
+		if (*pos != ',') /* end of list */
+			break;
+		pos++;
+	}
+	if (*str == '[' && *pos != ']')
+		return NULL;
+	if (*pos == ']')
+		pos++;
+	return pos;
 }
 
 /*
@@ -121,6 +115,9 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	struct rte_eth_devargs *eth_da = data;
 
 	eth_da->type = RTE_ETH_REPRESENTOR_VF;
-	return rte_eth_devargs_process_range(str, eth_da->representor_ports,
+	str = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
+	if (str == NULL)
+		RTE_LOG(ERR, EAL, "wrong representor format: %s\n", str);
+	return str == NULL ? -1 : 0;
 }
lib/librte_ethdev/ethdev_private.h +0 -3
index 905a45c337..220ddd4408 100644
@@ -26,9 +26,6 @@ eth_find_device(const struct rte_eth_dev *_start, rte_eth_cmp_t cmp,
 		const void *data);
 
 /* Parse devargs value for representor parameter. */
-typedef int (*rte_eth_devargs_callback_t)(char *str, void *data);
-int rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
-	void *data);
 int rte_eth_devargs_parse_representor_ports(char *str, void *data);
 
 #ifdef __cplusplus
lib/librte_ethdev/rte_class_eth.c +1 -3
index 6338355e25..efe6149df5 100644
@@ -77,9 +77,7 @@ eth_representor_cmp(const char *key __rte_unused,
 	if (values == NULL)
 		return -1;
 	memset(&representors, 0, sizeof(representors));
-	ret = rte_eth_devargs_parse_list(values,
-			rte_eth_devargs_parse_representor_ports,
-			&representors);
+	ret = rte_eth_devargs_parse_representor_ports(values, &representors);
 	free(values);
 	if (ret != 0)
 		return -1; /* invalid devargs value */
lib/librte_ethdev/rte_ethdev.c +2 -3
index 17ddacc78d..2ac51ac149 100644
@@ -5542,9 +5542,8 @@ rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
 	for (i = 0; i < args.count; i++) {
 		pair = &args.pairs[i];
 		if (strcmp("representor", pair->key) == 0) {
-			result = rte_eth_devargs_parse_list(pair->value,
-				rte_eth_devargs_parse_representor_ports,
-				eth_da);
+			result = rte_eth_devargs_parse_representor_ports(
+					pair->value, eth_da);
 			if (result < 0)
 				goto parse_cleanup;
 		}
Signature · 1 line
2.25.1
author
#55 lore raw

PATCH v4 5/9 ethdev: support PF index in representor

In reply to Xueming Li

With Kernel bonding, multiple underlying PFs are bonded, VFs come from different PF, need to identify representor of VFs unambiguously by adding PF index.

This patch introduces optional 'pf' section to representor devargs syntax, examples:
representor=pf0vf0 - single VF representor
representor=pf[0-1]sf[0-1023] - SF representors from 2 PFs

---
 doc/guides/prog_guide/poll_mode_drv.rst |  2 ++
 lib/librte_ethdev/ethdev_private.c      | 13 +++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
doc/guides/prog_guide/poll_mode_drv.rst +2 -0
index 86e5867f1b..b2147aad30 100644
@@ -382,6 +382,8 @@ parameters to those ports.
    -a DBDF,representor=sf[1,3,5]
    -a DBDF,representor=sf[0-1023]
    -a DBDF,representor=sf[0,2-4,7,9-11]
+   -a DBDF,representor=pf1vf0
+   -a DBDF,representor=pf[0-1]sf[0-127]
 
 Note: PMDs are not required to support the standard device arguments and users
 should consult the relevant PMD documentation to see support devargs.
lib/librte_ethdev/ethdev_private.c +11 -2
index 170b3ef067..f81423ceb8 100644
@@ -108,14 +108,22 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
 /*
  * representor format:
  *   #: range or single number of VF representor - legacy
- *   vf#: VF port representor/s
- *   sf#: SF port representor/s
+ *   [pf#]vf#: VF port representor/s
+ *   [pf#]sf#: SF port representor/s
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
 {
 	struct rte_eth_devargs *eth_da = data;
 
+	if (str[0] == 'p' && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_PF;
+		str += 2;
+		str = rte_eth_devargs_process_list(str, eth_da->ports,
+				&eth_da->nb_ports, RTE_MAX_ETHPORTS);
+		if (str == NULL)
+			goto err;
+	}
 	if (str[0] == 'v' && str[1] == 'f') {
 		eth_da->type = RTE_ETH_REPRESENTOR_VF;
 		str += 2;
@@ -127,6 +135,7 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	}
 	str = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
+err:
 	if (str == NULL)
 		RTE_LOG(ERR, EAL, "wrong representor format: %s\n", str);
 	return str == NULL ? -1 : 0;
Signature · 1 line
2.25.1
author
#61 lore raw

PATCH v4 9/9 kvargs: update parser to support lists

In reply to Xueming Li

This patch updates kvargs parser to support lists on top of range, allow multiple lists or range:
k1=a[1,2]b[3-5]

---
 app/test/test_kvargs.c         |  46 +++++++++++++--
 lib/librte_kvargs/rte_kvargs.c | 101 +++++++++++++++++++++++----------
 2 files changed, 112 insertions(+), 35 deletions(-)
app/test/test_kvargs.c +40 -6
index 2a2dae43a0..a91ea8dc47 100644
@@ -35,6 +35,25 @@ static int check_handler(const char *key, const char *value,
 	return 0;
 }
 
+/* test parsing. */
+static int test_kvargs_parsing(const char *args, unsigned int n)
+{
+	struct rte_kvargs *kvlist;
+
+	kvlist = rte_kvargs_parse(args, NULL);
+	if (kvlist == NULL) {
+		printf("rte_kvargs_parse() error: %s\n", args);
+		return -1;
+	}
+	if (kvlist->count != n) {
+		printf("invalid count value %d: %s\n", kvlist->count, args);
+		rte_kvargs_free(kvlist);
+		return -1;
+	}
+	rte_kvargs_free(kvlist);
+	return 0;
+}
+
 /* test a valid case */
 static int test_valid_kvargs(void)
 {
@@ -42,6 +61,19 @@ static int test_valid_kvargs(void)
 	const char *args;
 	const char *valid_keys_list[] = { "foo", "check", NULL };
 	const char **valid_keys;
+	static const struct {
+		unsigned int expected;
+		const char *input;
+	} valid_inputs[] = {
+		{ 2, "foo=1,foo=" },
+		{ 2, "foo=1,foo=" },
+		{ 2, "foo=1,foo" },
+		{ 2, "foo=1,=2" },
+		{ 1, "foo=[1,2" },
+		{ 1, ",=" },
+		{ 1, "foo=[" },
+	};
+	unsigned int i;
 
 	/* empty args is valid */
 	args = "";
@@ -191,6 +223,14 @@ static int test_valid_kvargs(void)
 	}
 	rte_kvargs_free(kvlist);
 
+	valid_keys = NULL;
+
+	for (i = 0; i < RTE_DIM(valid_inputs); ++i) {
+		args = valid_inputs[i].input;
+		if (test_kvargs_parsing(args, valid_inputs[i].expected))
+			goto fail;
+	}
+
 	return 0;
 
  fail:
@@ -212,12 +252,6 @@ static int test_invalid_kvargs(void)
 	/* list of argument that should fail */
 	const char *args_list[] = {
 		"wrong-key=x",     /* key not in valid_keys_list */
-		"foo=1,foo=",      /* empty value */
-		"foo=1,foo",       /* no value */
-		"foo=1,=2",        /* no key */
-		"foo=[1,2",        /* no closing bracket in value */
-		",=",              /* also test with a smiley */
-		"foo=[",           /* no value in list and no closing bracket */
 		NULL };
 	const char **args;
 	const char *valid_keys_list[] = { "foo", "check", NULL };
lib/librte_kvargs/rte_kvargs.c +72 -29

129 lines not on this page · raw message

Signature · 1 line
2.25.1
author
#31 lore raw

v4 cover ethdev: support SubFunction representor

In reply to Xueming Li

SubFunction [1] is a portion of the PCI device, a SF netdev has its own dedicated queues(txq, rxq). A SF netdev supports E-Switch representation offload similar to existing PF and VF representors. A SF shares PCI level resources with other SFs and/or with its parent PCI function.

From SmartNIC perspective, when PCI device is shared for multi-host, representors for host controller and host PF is required.

This patch set introduces new representor types in addtion to existing VF representor. Syntax:

[[c#]pf#]vf#: VF port representor/s from controller/pf [[c#]pf#]sf#: SF port representor/s from controller/pf #: VF representor - for backwards compatibility

"#" is number instance, list or range, valid examples:
1, [1,3,5], [0-3], [0,2-4,6]

For backward compatibility, this patch also introduces new netdev capability to indicate the capability of supportting SF representor.

Version history:
RFC:
initial version [2]
V2:
- separate patch for represnetor infrastructure, controller, pf and sf.
- replace representor ID macro with functions:
rte_eth_representor_id_encode() rte_eth_representor_id_parse()
- new patch to allow devargs with same PCI BDF but different representors.
- other minor code updates according to comments, thanks Andrew!
- update document
V3:
- improve probing of allowed devargs with same name.
- parse single word of kvargs as key.
- update kvargs test cases.
V4:
- split first representor refactor patch into
1: add representor type
2: refector representor list parsing
- push the patch supporting multi-devargs for same device.

[1] SubFunction in kernel:
https://lore.kernel.org/netdev/[email protected]/

[2] RFC:
http://patchwork.dpdk.org/project/dpdk/list/?series=14376

[3] V2:
http://patchwork.dpdk.org/project/dpdk/list/?series=14559

[4] v3:
1 http://patchwork.dpdk.org/patch/86460/
2 http://patchwork.dpdk.org/patch/86461/
3 http://patchwork.dpdk.org/patch/86462/
4 http://patchwork.dpdk.org/patch/86463/
5 http://patchwork.dpdk.org/patch/86464/
6 http://patchwork.dpdk.org/patch/86465/
7 http://patchwork.dpdk.org/patch/86467/
8 http://patchwork.dpdk.org/patch/86466/
9 http://patchwork.dpdk.org/patch/86468/

Xueming Li (9):
ethdev: introduce representor type
ethdev: support representor port list
ethdev: support new VF representor syntax
ethdev: support sub function representor
ethdev: support PF index in representor
ethdev: support multi-host in representor
devarg: change representor ID to bitmap
ethdev: add capability of sub-function representor
kvargs: update parser to support lists

 app/test/test_kvargs.c                   |  46 +++++++-
 config/rte_config.h                      |   1 +
 doc/guides/prog_guide/poll_mode_drv.rst  |  13 ++-
 drivers/net/bnxt/bnxt_ethdev.c           |   7 ++
 drivers/net/bnxt/bnxt_reps.c             |   3 +-
 drivers/net/enic/enic_ethdev.c           |   7 ++
 drivers/net/enic/enic_vf_representor.c   |   3 +-
 drivers/net/i40e/i40e_ethdev.c           |   8 ++
 drivers/net/i40e/i40e_vf_representor.c   |   3 +-
 drivers/net/ixgbe/ixgbe_ethdev.c         |   8 ++
 drivers/net/ixgbe/ixgbe_vf_representor.c |   3 +-
 drivers/net/mlx5/linux/mlx5_os.c         |  15 ++-
 lib/librte_ethdev/ethdev_private.c       | 140 ++++++++++++++---------
 lib/librte_ethdev/ethdev_private.h       |   3 -
 lib/librte_ethdev/rte_class_eth.c        |  40 +++++--
 lib/librte_ethdev/rte_ethdev.c           |  31 ++++-
 lib/librte_ethdev/rte_ethdev.h           |   2 +
 lib/librte_ethdev/rte_ethdev_driver.h    |  66 +++++++++++
 lib/librte_ethdev/version.map            |   2 +
 lib/librte_kvargs/rte_kvargs.c           | 101 +++++++++++-----
 20 files changed, 389 insertions(+), 113 deletions(-)
Signature · 1 line
2.25.1
author
#57 lore raw

PATCH v4 7/9 devarg: change representor ID to bitmap

The NIC can have multiple PCIe links and can be attached to multiple hosts, for example the same single NIC can be shared for multiple server units in the rack. On each PCIe link NIC can provide multiple PFs and VFs/SFs based on these ones. The full representor identifier consists of three indices - controller index, PF index, and VF or SF index (if any).

SR-IOV and SubFunction are created on top of PF. PF index is introduced because there might be multiple PFs in the bonding configuration and only bonding device is probed.

In eth representor comparator callback, ethdev was compared with devarg. Since ethdev representor port didn't contain controller index and PF index information, callback returned representor from other PF or controller.

This patch changes representor ID to bitmap so that the ethdev representor comparer callback returns correct ethdev by comparing full representor information including: controller index, PF index, representor type, SF or VF index.

Representor ID bitmap definition:
xxxx xxxx xxxx xxxx

 |||| |LLL LLLL LLLL vf/sf id
 |||| L 1:sf, 0:vf
 ||LL pf id

LL controller(host) id

This approach keeps binary compatibility with all drivers, VF representor id matches with simple id for non-bonding and non-multi-host configurations.

In the future, the representor ID field and each section should extend to bigger width to support more devices.

---
 drivers/net/bnxt/bnxt_reps.c             |  3 +-
 drivers/net/enic/enic_vf_representor.c   |  3 +-
 drivers/net/i40e/i40e_vf_representor.c   |  3 +-
 drivers/net/ixgbe/ixgbe_vf_representor.c |  3 +-
 drivers/net/mlx5/linux/mlx5_os.c         |  4 +-
 lib/librte_ethdev/ethdev_private.c       |  5 ++-
 lib/librte_ethdev/rte_class_eth.c        | 38 +++++++++++++----
 lib/librte_ethdev/rte_ethdev.c           | 26 ++++++++++++
 lib/librte_ethdev/rte_ethdev_driver.h    | 53 ++++++++++++++++++++++++
 lib/librte_ethdev/version.map            |  2 +
 10 files changed, 126 insertions(+), 14 deletions(-)
drivers/net/bnxt/bnxt_reps.c +2 -1
index f7bbf77d3f..34febc2d1e 100644
@@ -186,7 +186,8 @@ int bnxt_representor_init(struct rte_eth_dev *eth_dev, void *params)
 
 	eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
 					RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-	eth_dev->data->representor_id = rep_params->vf_id;
+	eth_dev->data->representor_id = rte_eth_representor_id_encode(
+		0, 0, RTE_ETH_REPRESENTOR_VF, rep_params->vf_id);
 
 	rte_eth_random_addr(vf_rep_bp->dflt_mac_addr);
 	memcpy(vf_rep_bp->mac_addr, vf_rep_bp->dflt_mac_addr,
drivers/net/enic/enic_vf_representor.c +2 -1
index c2c03c0281..632317af15 100644
@@ -674,7 +674,8 @@ int enic_vf_representor_init(struct rte_eth_dev *eth_dev, void *init_params)
 	eth_dev->dev_ops = &enic_vf_representor_dev_ops;
 	eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
 					RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-	eth_dev->data->representor_id = vf->vf_id;
+	eth_dev->data->representor_id = rte_eth_representor_id_encode(
+		0, 0, RTE_ETH_REPRESENTOR_VF, vf->vf_id);
 	eth_dev->data->mac_addrs = rte_zmalloc("enic_mac_addr_vf",
 		sizeof(struct rte_ether_addr) *
 		ENIC_UNICAST_PERFECT_FILTERS, 0);
drivers/net/i40e/i40e_vf_representor.c +2 -1
index 9e40406a3d..d90d0fdb9d 100644
@@ -510,7 +510,8 @@ i40e_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params)
 
 	ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
 					RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-	ethdev->data->representor_id = representor->vf_id;
+	ethdev->data->representor_id = rte_eth_representor_id_encode(
+			0, 0, RTE_ETH_REPRESENTOR_VF, representor->vf_id);
 
 	/* Setting the number queues allocated to the VF */
 	ethdev->data->nb_rx_queues = vf->vsi->nb_qps;
drivers/net/ixgbe/ixgbe_vf_representor.c +2 -1
index 8185f0d3bb..e15b794761 100644
@@ -196,7 +196,8 @@ ixgbe_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params)
 		return -ENODEV;
 
 	ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
-	ethdev->data->representor_id = representor->vf_id;
+	ethdev->data->representor_id = rte_eth_representor_id_encode(
+			0, 0, RTE_ETH_REPRESENTOR_VF, representor->vf_id);
 
 	/* Set representor device ops */
 	ethdev->dev_ops = &ixgbe_vf_representor_dev_ops;
drivers/net/mlx5/linux/mlx5_os.c +3 -1
index caead107b0..4d7940bcca 100644
@@ -1025,7 +1025,9 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 #endif
 	/* representor_id field keeps the unmodified VF index. */
 	priv->representor_id = switch_info->representor ?
-			       switch_info->port_name : -1;
+		rte_eth_representor_id_encode(0, 0, RTE_ETH_REPRESENTOR_VF,
+					      switch_info->port_name) :
+		-1;
 	/*
 	 * Look for sibling devices in order to reuse their switch domain
 	 * if any, otherwise allocate one.
lib/librte_ethdev/ethdev_private.c +4 -1
index 57473b5a39..0b3b4aa871 100644
@@ -106,10 +106,13 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
 }
 
 /*
- * representor format:
+ * Parse representor ports, expand and update representor port ID.
+ * Representor format:
  *   #: range or single number of VF representor - legacy
  *   [[c#]pf#]vf#: VF port representor/s
  *   [[c#]pf#]sf#: SF port representor/s
+ *
+ * See RTE_ETH_REPR() for representor ID format.
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
lib/librte_ethdev/rte_class_eth.c +30 -8
index efe6149df5..994db96960 100644
@@ -66,8 +66,8 @@ eth_representor_cmp(const char *key __rte_unused,
 	int ret;
 	char *values;
 	const struct rte_eth_dev_data *data = opaque;
-	struct rte_eth_devargs representors;
-	uint16_t index;
+	struct rte_eth_devargs eth_da;
+	uint16_t index, c, p, f;
 
 	if ((data->dev_flags & RTE_ETH_DEV_REPRESENTOR) == 0)
 		return -1; /* not a representor port */
@@ -76,17 +76,39 @@ eth_representor_cmp(const char *key __rte_unused,
 	values = strdup(value);
 	if (values == NULL)
 		return -1;
-	memset(&representors, 0, sizeof(representors));
-	ret = rte_eth_devargs_parse_representor_ports(values, &representors);
+	memset(&eth_da, 0, sizeof(eth_da));
+	ret = rte_eth_devargs_parse_representor_ports(values, &eth_da);
 	free(values);
 	if (ret != 0)
 		return -1; /* invalid devargs value */
 
+	/* Set default values. */
+	if (eth_da.nb_mh_controllers == 0) {
+		eth_da.nb_mh_controllers = 1;
+		eth_da.mh_controllers[0] = 0;
+	}
+	if (eth_da.nb_ports == 0) {
+		eth_da.nb_ports = 1;
+		eth_da.ports[0] = 0;
+	}
+	if (eth_da.nb_representor_ports == 0) {
+		eth_da.nb_representor_ports = 1;
+		eth_da.representor_ports[0] = 0;
+	}
 	/* Return 0 if representor id is matching one of the values. */
-	for (index = 0; index < representors.nb_representor_ports; index++)
-		if (data->representor_id ==
-				representors.representor_ports[index])
-			return 0;
+	for (c = 0; c < eth_da.nb_mh_controllers; ++c) {
+		for (p = 0; p < eth_da.nb_ports; ++p) {
+			for (f = 0; f < eth_da.nb_representor_ports; ++f) {
+				index = rte_eth_representor_id_encode(
+					eth_da.mh_controllers[c],
+					eth_da.ports[p],
+					eth_da.type,
+					eth_da.representor_ports[f]);
+				if (data->representor_id == index)
+					return 0;
+			}
+		}
+	}
 	return -1; /* no match */
 }
 
lib/librte_ethdev/rte_ethdev.c +26 -0
index 2ac51ac149..276f42e54b 100644
@@ -5556,6 +5556,32 @@ rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
 	return result;
 }
 
+uint16_t
+rte_eth_representor_id_encode(uint16_t controller, uint16_t pf,
+			      enum rte_eth_representor_type type,
+			      uint16_t representor_port)
+{
+	return (((controller & 3) << 14) |
+		((pf & 3) << 12) |
+		(!!(type == RTE_ETH_REPRESENTOR_SF) << 11) |
+		(representor_port & 0x7ff));
+}
+
+uint16_t
+rte_eth_representor_id_parse(const uint16_t representor_id,
+			     uint16_t *controller, uint16_t *pf,
+			     enum rte_eth_representor_type *type)
+{
+	if (controller)
+		*controller = (representor_id >> 14) & 3;
+	if (pf)
+		*pf = (representor_id >> 12) & 3;
+	if (type)
+		*type = ((representor_id >> 11) & 1) ?
+			RTE_ETH_REPRESENTOR_SF : RTE_ETH_REPRESENTOR_VF;
+	return representor_id & 0x7ff;
+}
+
 static int
 eth_dev_handle_port_list(const char *cmd __rte_unused,
 		const char *params __rte_unused,
lib/librte_ethdev/rte_ethdev_driver.h +53 -0

59 lines not on this page · raw message

lib/librte_ethdev/version.map +2 -0
index d3f5410806..44edaed507 100644
@@ -257,6 +257,8 @@ INTERNAL {
 	rte_eth_dev_release_port;
 	rte_eth_dev_internal_reset;
 	rte_eth_devargs_parse;
+	rte_eth_representor_id_encode;
+	rte_eth_representor_id_parse;
 	rte_eth_dma_zone_free;
 	rte_eth_dma_zone_reserve;
 	rte_eth_hairpin_queue_peer_bind;
Signature · 1 line
2.25.1
author
#60 lore raw

PATCH v4 8/9 ethdev: add capability of sub-function representor

In reply to Xueming Li

Old DPDK version or some drivers that don't support SubFunction representor. For application to adapt different DPDK version automatically, or to be used for different NICs, this patch introduces new eth device capability of supporting SubFunction representor device.

---
 lib/librte_ethdev/rte_ethdev.h | 2 ++
 1 file changed, 2 insertions(+)
lib/librte_ethdev/rte_ethdev.h +2 -0
index 2cbce958cf..da65adf1ab 100644
@@ -1433,6 +1433,8 @@ struct rte_eth_conf {
 #define RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP 0x00000001
 /** Device supports Tx queue setup after device started. */
 #define RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP 0x00000002
+/** Device supports SubFunction representor. */
+#define RTE_ETH_DEV_CAPA_REPRESENTOR_SF         0x00000004
 /**@}*/
 
 /*
Signature · 1 line
2.25.1
author
#53 lore raw

PATCH v4 3/9 ethdev: support new VF representor syntax

In reply to Xueming Li

To prepare for more representor types, this patch adds compatible VF representor devargs syntax:

vf#: new VF port representor/s, examples:

 representor=vf2          - single representor
 representor=vf[1,3,5]    - single list
 representor=vf[0-3]      - single range
 representor=vf[0,1,4-7]  - list with singles and range

For backwards compatibility, representor "#" is deemed as "vf#".

---
 doc/guides/prog_guide/poll_mode_drv.rst | 7 ++++---
 lib/librte_ethdev/ethdev_private.c      | 5 ++++-
 2 files changed, 8 insertions(+), 4 deletions(-)
doc/guides/prog_guide/poll_mode_drv.rst +4 -3
index 239ec820ea..0117c2af07 100644
@@ -374,9 +374,10 @@ parameters to those ports.
   this argument allows user to specify which switch ports to enable port
   representors for.::
 
-   -a DBDF,representor=0
-   -a DBDF,representor=[0,4,6,9]
-   -a DBDF,representor=[0-31]
+   -a DBDF,representor=vf0
+   -a DBDF,representor=vf[0,4,6,9]
+   -a DBDF,representor=vf[0-31]
+   -a DBDF,representor=vf[0,2-4,7,9-11]
 
 Note: PMDs are not required to support the standard device arguments and users
 should consult the relevant PMD documentation to see support devargs.
lib/librte_ethdev/ethdev_private.c +4 -1
index 12bcc7e98d..ee60b1259a 100644
@@ -107,7 +107,8 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
 
 /*
  * representor format:
- *   #: range or single number of VF representor
+ *   #: range or single number of VF representor - legacy
+ *   vf#: VF port representor/s
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
@@ -115,6 +116,8 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	struct rte_eth_devargs *eth_da = data;
 
 	eth_da->type = RTE_ETH_REPRESENTOR_VF;
+	if (str[0] == 'v' && str[1] == 'f')
+		str += 2;
 	str = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
 	if (str == NULL)
Signature · 1 line
2.25.1
author
#56 lore raw

PATCH v4 6/9 ethdev: support multi-host in representor

In reply to Xueming Li

The NIC can have multiple PCIe links and can be attached to the multiple hosts, for example the same single NIC can be shared for multiple server units in the rack. On each PCIe link NIC can provide multiple PFs and VFs/SFs based on these ones. To provide the unambiguous identification of the PCIe function the controller index is added. The full representor identifier consists of three indices - controller index, PF index, and VF or SF index (if any).

This patch introduces controller index to ethdev representor syntax, examples:

[[c#]pf#]vf#: VF port representor/s, example: pf0vf1 [[c#]pf#]sf#: SF port representor/s, example: c1pf1sf[0-3]

c# is controller(host) ID/range in case of multi-host, optional.

For user application (e.g. OVS), PMD is responsible to interpret and locate representor device based on controller ID, PF ID and VF/SF ID in representor syntax.

---
 config/rte_config.h                   |  1 +
 lib/librte_ethdev/ethdev_private.c    | 12 ++++++++++--
 lib/librte_ethdev/rte_ethdev_driver.h |  4 ++++
 3 files changed, 15 insertions(+), 2 deletions(-)
config/rte_config.h +1 -0
index a0b5160ff2..23d02d51ef 100644
@@ -58,6 +58,7 @@
 #define RTE_MAX_QUEUES_PER_PORT 1024
 #define RTE_ETHDEV_QUEUE_STAT_CNTRS 16 /* max 256 */
 #define RTE_ETHDEV_RXTX_CALLBACKS 1
+#define RTE_MAX_MULTI_HOST_CTRLS 4
 
 /* cryptodev defines */
 #define RTE_CRYPTO_MAX_DEVS 64
lib/librte_ethdev/ethdev_private.c +10 -2
index f81423ceb8..57473b5a39 100644
@@ -108,14 +108,22 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
 /*
  * representor format:
  *   #: range or single number of VF representor - legacy
- *   [pf#]vf#: VF port representor/s
- *   [pf#]sf#: SF port representor/s
+ *   [[c#]pf#]vf#: VF port representor/s
+ *   [[c#]pf#]sf#: SF port representor/s
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
 {
 	struct rte_eth_devargs *eth_da = data;
 
+	if (str[0] == 'c') {
+		str += 1;
+		str = rte_eth_devargs_process_list(str, eth_da->mh_controllers,
+				&eth_da->nb_mh_controllers,
+				RTE_DIM(eth_da->mh_controllers));
+		if (str == NULL)
+			goto err;
+	}
 	if (str[0] == 'p' && str[1] == 'f') {
 		eth_da->type = RTE_ETH_REPRESENTOR_PF;
 		str += 2;
lib/librte_ethdev/rte_ethdev_driver.h +4 -0
index 3bc5c5bbbb..8e04634660 100644
@@ -1203,6 +1203,10 @@ enum rte_eth_representor_type {
 
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
+	uint16_t mh_controllers[RTE_MAX_MULTI_HOST_CTRLS];
+	/** controller/s number in case of multi-host */
+	uint16_t nb_mh_controllers;
+	/** number of controllers in multi-host controllers field */
 	uint16_t ports[RTE_MAX_ETHPORTS];
 	/** port/s number to enable on a multi-port single function */
 	uint16_t nb_ports;
Signature · 1 line
2.25.1
author
#54 lore raw

PATCH v4 4/9 ethdev: support sub function representor

In reply to Xueming Li

SubFunction is a portion of the PCI device, created on demand, a SF netdev has its own dedicated queues(txq, rxq). A SF netdev supports eswitch representation offload similar to existing PF and VF representors.

To support SF representor, this patch introduces new devargs syntax, examples:

 representor=sf0               - single SubFunction representor
 representor=sf[1,3,5]         - single list
 representor=sf[0-3],          - single range

representor=sf[0,2-6,8,10-12] - list with singles and ranges

---
 doc/guides/prog_guide/poll_mode_drv.rst |  4 ++++
 lib/librte_ethdev/ethdev_private.c      | 11 +++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
doc/guides/prog_guide/poll_mode_drv.rst +4 -0
index 0117c2af07..86e5867f1b 100644
@@ -378,6 +378,10 @@ parameters to those ports.
    -a DBDF,representor=vf[0,4,6,9]
    -a DBDF,representor=vf[0-31]
    -a DBDF,representor=vf[0,2-4,7,9-11]
+   -a DBDF,representor=sf0
+   -a DBDF,representor=sf[1,3,5]
+   -a DBDF,representor=sf[0-1023]
+   -a DBDF,representor=sf[0,2-4,7,9-11]
 
 Note: PMDs are not required to support the standard device arguments and users
 should consult the relevant PMD documentation to see support devargs.
lib/librte_ethdev/ethdev_private.c +9 -2
index ee60b1259a..170b3ef067 100644
@@ -109,15 +109,22 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
  * representor format:
  *   #: range or single number of VF representor - legacy
  *   vf#: VF port representor/s
+ *   sf#: SF port representor/s
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
 {
 	struct rte_eth_devargs *eth_da = data;
 
-	eth_da->type = RTE_ETH_REPRESENTOR_VF;
-	if (str[0] == 'v' && str[1] == 'f')
+	if (str[0] == 'v' && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_VF;
 		str += 2;
+	} else if (str[0] == 's' && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_SF;
+		str += 2;
+	} else {
+		eth_da->type = RTE_ETH_REPRESENTOR_VF;
+	}
 	str = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
 	if (str == NULL)
Signature · 1 line
2.25.1
#33 lore raw

Re: [dpdk-dev] [PATCH v4 1/9] ethdev: introduce representor type

In reply to Xueming Li

+Cc more maintainers

18/01/2021 12:16, Xueming Li:

Quoted 157 lines

To support more representor type, this patch introduces representor type enum. The enum is subject to extend for new types upcoming.

---
 drivers/net/bnxt/bnxt_ethdev.c        |  7 +++++++
 drivers/net/enic/enic_ethdev.c        |  7 +++++++
 drivers/net/i40e/i40e_ethdev.c        |  8 ++++++++
 drivers/net/ixgbe/ixgbe_ethdev.c      |  8 ++++++++
 drivers/net/mlx5/linux/mlx5_os.c      | 11 +++++++++++
 lib/librte_ethdev/ethdev_private.c    |  5 +++++
 lib/librte_ethdev/rte_ethdev_driver.h |  9 +++++++++
 7 files changed, 55 insertions(+)
drivers/net/bnxt/bnxt_ethdev.c +7 -0
index 74b0f3d1dc..d7c8b3ec07 100644
@@ -5586,6 +5586,13 @@ static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev,
 	int i, ret = 0;
 	struct rte_kvargs *kvlist = NULL;
 
+	if (eth_da->type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da->type != RTE_ETH_REPRESENTOR_VF) {
+		PMD_DRV_LOG(ERR, "unsupported representor type %d\n",
+			    eth_da->type);
+		return -ENOTSUP;
+	}
 	num_rep = eth_da->nb_representor_ports;
 	if (num_rep > BNXT_MAX_VF_REPS) {
 		PMD_DRV_LOG(ERR, "nb_representor_ports = %d > %d MAX VF REPS\n",
drivers/net/enic/enic_ethdev.c +7 -0
index d041a6bee9..dd085caa93 100644
@@ -1303,6 +1303,13 @@ static int eth_enic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 		if (retval)
 			return retval;
 	}
+	if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+		ENICPMD_LOG(ERR, "unsupported representor type: %s\n",
+			    pci_dev->device.devargs->args);
+		return -ENOTSUP;
+	}
 	retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
 		sizeof(struct enic),
 		eth_dev_pci_specific_init, pci_dev,
drivers/net/i40e/i40e_ethdev.c +8 -0
index c1c2327b3f..3cea6de2bd 100644
@@ -638,6 +638,14 @@ eth_i40e_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 			return retval;
 	}
 
+	if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+		PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
+			    pci_dev->device.devargs->args);
+		return -ENOTSUP;
+	}
+
 	retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
 		sizeof(struct i40e_adapter),
 		eth_dev_pci_specific_init, pci_dev,
drivers/net/ixgbe/ixgbe_ethdev.c +8 -0
index d7a1806ab8..eb2c4929e2 100644
@@ -1717,6 +1717,14 @@ eth_ixgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 	} else
 		memset(&eth_da, 0, sizeof(eth_da));
 
+	if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+		PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
+			    pci_dev->device.devargs->args);
+		return -ENOTSUP;
+	}
+
 	retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
 		sizeof(struct ixgbe_adapter),
 		eth_dev_pci_specific_init, pci_dev,
drivers/net/mlx5/linux/mlx5_os.c +11 -0
index 9ac1d46b1b..caead107b0 100644
@@ -705,6 +705,17 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 				strerror(rte_errno));
 			return NULL;
 		}
+		if (eth_da.type != RTE_ETH_REPRESENTOR_NONE) {
+			/* Representor not specified. */
+			rte_errno = EBUSY;
+			return NULL;
+		}
+		if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+			rte_errno = ENOTSUP;
+			DRV_LOG(ERR, "unsupported representor type: %s",
+				dpdk_dev->devargs->args);
+			return NULL;
+		}
 		for (i = 0; i < eth_da.nb_representor_ports; ++i)
 			if (eth_da.representor_ports[i] ==
 			    (uint16_t)switch_info->port_name)
lib/librte_ethdev/ethdev_private.c +5 -0
index 162a502fe7..c1a411dba4 100644
@@ -111,11 +111,16 @@ rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
 	return 0;
 }
 
+/*
+ * representor format:
+ *   #: range or single number of VF representor
+ */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
 {
 	struct rte_eth_devargs *eth_da = data;
 
+	eth_da->type = RTE_ETH_REPRESENTOR_VF;
 	return rte_eth_devargs_process_range(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
 }
lib/librte_ethdev/rte_ethdev_driver.h +9 -0
index 0eacfd8425..3bc5c5bbbb 100644
@@ -1193,6 +1193,14 @@ __rte_internal
 int
 rte_eth_switch_domain_free(uint16_t domain_id);
 
+/** Ethernet device representor type */
+enum rte_eth_representor_type {
+	RTE_ETH_REPRESENTOR_NONE, /**< not a representor. */
+	RTE_ETH_REPRESENTOR_VF,   /**< representor of VF. */
+	RTE_ETH_REPRESENTOR_SF,   /**< representor of SF. */
+	RTE_ETH_REPRESENTOR_PF,   /**< representor of host PF. */
+};
+
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
 	uint16_t ports[RTE_MAX_ETHPORTS];
@@ -1203,6 +1211,7 @@ struct rte_eth_devargs {
 	/** representor port/s identifier to enable on device */
 	uint16_t nb_representor_ports;
 	/** number of ports in representor port field */
+	enum rte_eth_representor_type type; /* type of representor */
 };
#47 lore raw

Re: [dpdk-dev] [PATCH v4 2/9] ethdev: support representor port list

In reply to Xueming Li

18/01/2021 12:16, Xueming Li:

Quoted 8 lines

To support extended representor syntax, this patch extends the representor list parsing to support for representor port range in devargs, examples:
representor=[1,2,3] - single list
representor=[1,3-5,7,9-11] - list with singles and ranges

Parsing functions are usually difficult to read.
If you need to do another version, I would recommend adding an oneline comment on top of parsing functions to give a hint about what it is really doing.

Here,

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, · line 43

Quoted 3 lines
lib/librte_ethdev/ethdev_private.c +3 -0
+static int
+rte_eth_devargs_enlist(uint16_t *list, uint16_t *len_list,
+		       const uint16_t max_list, uint16_t val)

here,

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, · line 59

Quoted 3 lines
lib/librte_ethdev/ethdev_private.c +1 -0
+static char *
 rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
 	const uint16_t max_list)

here,

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, · line 86

Quoted 3 lines
lib/librte_ethdev/ethdev_private.c +3 -0
+static char *
+rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
+	const uint16_t max_list)

and also for this old one:

Quoted 1 line
(quoted diff) +0 -0
@@ -121,6 +115,9 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
Acked-by on the v4 series
#62 lore raw

Re: [dpdk-dev] [PATCH v4 0/9] ethdev: support SubFunction representor

In reply to Xueming Li

18/01/2021 12:16, Xueming Li:

Quoted 9 lines

This patch set introduces new representor types in addtion to existing VF representor. Syntax:

[[c#]pf#]vf#: VF port representor/s from controller/pf [[c#]pf#]sf#: SF port representor/s from controller/pf #: VF representor - for backwards compatibility

"#" is number instance, list or range, valid examples:
1, [1,3,5], [0-3], [0,2-4,6]

[...]

Quoted 10 lines

Xueming Li (9):
ethdev: introduce representor type
ethdev: support representor port list
ethdev: support new VF representor syntax
ethdev: support sub function representor
ethdev: support PF index in representor
ethdev: support multi-host in representor
devarg: change representor ID to bitmap
ethdev: add capability of sub-function representor
kvargs: update parser to support lists

For the series,

Nice work, thank you.

Acked-by on v4 1/9
#34 lore raw

Re: [dpdk-dev] [PATCH v4 1/9] ethdev: introduce representor type

In reply to Xueming Li
Quoted 6 lines · Xueming Li

To support more representor type, this patch introduces representor type enum. The enum is subject to extend for new types upcoming.

Quoted 18 lines
---
 drivers/net/bnxt/bnxt_ethdev.c        |  7 +++++++
 drivers/net/enic/enic_ethdev.c        |  7 +++++++
 drivers/net/i40e/i40e_ethdev.c        |  8 ++++++++
 drivers/net/ixgbe/ixgbe_ethdev.c      |  8 ++++++++
 drivers/net/mlx5/linux/mlx5_os.c      | 11 +++++++++++
 lib/librte_ethdev/ethdev_private.c    |  5 +++++
 lib/librte_ethdev/rte_ethdev_driver.h |  9 +++++++++
 7 files changed, 55 insertions(+)
drivers/net/bnxt/bnxt_ethdev.c +0 -0
index 74b0f3d1dc..d7c8b3ec07 100644
@@ -5586,6 +5586,13 @@ static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev,
        int i, ret = 0;
        struct rte_kvargs *kvlist = NULL;
 

drivers/net/bnxt/bnxt_ethdev.c static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev, · line 5598

Quoted 10 lines
drivers/net/bnxt/bnxt_ethdev.c +7 -0
+       if (eth_da->type == RTE_ETH_REPRESENTOR_NONE)
+               return 0;
+       if (eth_da->type != RTE_ETH_REPRESENTOR_VF) {
+               PMD_DRV_LOG(ERR, "unsupported representor type %d\n",
+                           eth_da->type);
+               return -ENOTSUP;
+       }
        num_rep = eth_da->nb_representor_ports;
        if (num_rep > BNXT_MAX_VF_REPS) {
                PMD_DRV_LOG(ERR, "nb_representor_ports = %d > %d MAX VF REPS\n",

Ack. Thanks

:::: snip ::::

drivers/net/bnxt/bnxt_ethdev.c

Quoted 5 lines
drivers/net/bnxt/bnxt_ethdev.c +5 -0
+/** Ethernet device representor type */
+enum rte_eth_representor_type {
+       RTE_ETH_REPRESENTOR_NONE, /**< not a representor. */
+       RTE_ETH_REPRESENTOR_VF,   /**< representor of VF. */
+       RTE_ETH_REPRESENTOR_SF,   /**< representor of SF. */

Till we get used to the terminology...
Can we also have SF = "Sub Function" mentioned in the docs or comments?

Quoted 17 lines
drivers/net/bnxt/bnxt_ethdev.c +4 -1
+       RTE_ETH_REPRESENTOR_PF,   /**< representor of host PF. */
+};
+
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
        uint16_t ports[RTE_MAX_ETHPORTS];
@@ -1203,6 +1211,7 @@ struct rte_eth_devargs {
        /** representor port/s identifier to enable on device */
        uint16_t nb_representor_ports;
        /** number of ports in representor port field */
+       enum rte_eth_representor_type type; /* type of representor */
 };
 
 /**
--

2.25.1

#35 lore raw

Re: [dpdk-dev] [PATCH v4 1/9] ethdev: introduce representor type

18/01/2021 18:42, Ajit Khaparde:

Quoted 7 lines · Xueming Li

lib/librte_ethdev/rte_ethdev_driver.h __rte_internal · line 1200

Quoted 4 lines
lib/librte_ethdev/rte_ethdev_driver.h +4 -0
+enum rte_eth_representor_type {
+       RTE_ETH_REPRESENTOR_NONE, /**< not a representor. */
+       RTE_ETH_REPRESENTOR_VF,   /**< representor of VF. */
+       RTE_ETH_REPRESENTOR_SF,   /**< representor of SF. */

Till we get used to the terminology...
Can we also have SF = "Sub Function" mentioned in the docs or comments?

Are we sure about the definition?
I remember seeing SF = Scalable Function somewhere else (maybe from Intel)

#36 lore raw

Re: [dpdk-dev] [PATCH v4 1/9] ethdev: introduce representor type

Quoted 7 lines · Thomas Monjalon

18/01/2021 18:42, Ajit Khaparde:

Quoted 5 lines · Xueming Li
Quoted 4 lines
lib/librte_ethdev/rte_ethdev_driver.h +4 -0
+enum rte_eth_representor_type {
+       RTE_ETH_REPRESENTOR_NONE, /**< not a representor. */
+       RTE_ETH_REPRESENTOR_VF,   /**< representor of VF. */
+       RTE_ETH_REPRESENTOR_SF,   /**< representor of SF. */
Quoted 5 lines
Quoted 2 lines

Till we get used to the terminology...
Can we also have SF = "Sub Function" mentioned in the docs or comments?

Are we sure about the definition?
I remember seeing SF = Scalable Function somewhere else (maybe from Intel)

That complicates it. But if they mean the same thing, let's pick one.

#37 lore raw

Re: [dpdk-dev] [PATCH v4 1/9] ethdev: introduce representor type

18/01/2021 19:00, Ajit Khaparde:

Quoted 7 lines · Thomas Monjalon
Quoted 6 lines

18/01/2021 18:42, Ajit Khaparde:

Quoted 5 lines · Xueming Li
Quoted 4 lines
lib/librte_ethdev/rte_ethdev_driver.h +4 -0
+enum rte_eth_representor_type {
+       RTE_ETH_REPRESENTOR_NONE, /**< not a representor. */
+       RTE_ETH_REPRESENTOR_VF,   /**< representor of VF. */
+       RTE_ETH_REPRESENTOR_SF,   /**< representor of SF. */
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

Till we get used to the terminology...
Can we also have SF = "Sub Function" mentioned in the docs or comments?

Are we sure about the definition?
I remember seeing SF = Scalable Function somewhere else (maybe from Intel)

That complicates it. But if they mean the same thing, let's pick one.

I think "Sub Function" and "Virtual Function" are easy to understand for everybody.
I suggest picking these two for comments above.

#38 lore raw

Re: [dpdk-dev] [PATCH v4 1/9] ethdev: introduce representor type

Quoted 12 lines · Thomas Monjalon

18/01/2021 19:00, Ajit Khaparde:

Quoted 10 lines · Thomas Monjalon
Quoted 9 lines

18/01/2021 18:42, Ajit Khaparde:

Quoted 7 lines · Xueming Li

lib/librte_ethdev/rte_ethdev_driver.h __rte_internal · line 1200

Quoted 4 lines
lib/librte_ethdev/rte_ethdev_driver.h +4 -0
+enum rte_eth_representor_type {
+       RTE_ETH_REPRESENTOR_NONE, /**< not a representor. */
+       RTE_ETH_REPRESENTOR_VF,   /**< representor of VF. */
+       RTE_ETH_REPRESENTOR_SF,   /**< representor of SF. */

Till we get used to the terminology...
Can we also have SF = "Sub Function" mentioned in the docs or comments?

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Are we sure about the definition?
I remember seeing SF = Scalable Function somewhere else (maybe from Intel)

That complicates it. But if they mean the same thing, let's pick one.

I think "Sub Function" and "Virtual Function" are easy to understand for everybody.
I suggest picking these two for comments above.

+1

Quoted 1 line
#58 lore raw

Re: [dpdk-dev] [PATCH v4 7/9] devarg: change representor ID to bitmap

In reply to Xueming Li
Quoted 32 lines · Xueming Li

The NIC can have multiple PCIe links and can be attached to multiple hosts, for example the same single NIC can be shared for multiple server units in the rack. On each PCIe link NIC can provide multiple PFs and VFs/SFs based on these ones. The full representor identifier consists of three indices - controller index, PF index, and VF or SF index (if any).

SR-IOV and SubFunction are created on top of PF. PF index is introduced because there might be multiple PFs in the bonding configuration and only bonding device is probed.

In eth representor comparator callback, ethdev was compared with devarg. Since ethdev representor port didn't contain controller index and PF index information, callback returned representor from other PF or controller.

This patch changes representor ID to bitmap so that the ethdev representor comparer callback returns correct ethdev by comparing full representor information including: controller index, PF index, representor type, SF or VF index.

Representor ID bitmap definition:
xxxx xxxx xxxx xxxx

 |||| |LLL LLLL LLLL vf/sf id
 |||| L 1:sf, 0:vf
 ||LL pf id

LL controller(host) id

This approach keeps binary compatibility with all drivers, VF representor id matches with simple id for non-bonding and non-multi-host configurations.

Quoted 5 lines

In the future, the representor ID field and each section should extend to bigger width to support more devices.

Not just in this patch, there is a lot of info in the commit logs. Unless I missed it, I don't see an update to doc/guides/prog_guide/switch_representation.rst
Can you please update that.

Quoted 281 lines
---
 drivers/net/bnxt/bnxt_reps.c             |  3 +-
 drivers/net/enic/enic_vf_representor.c   |  3 +-
 drivers/net/i40e/i40e_vf_representor.c   |  3 +-
 drivers/net/ixgbe/ixgbe_vf_representor.c |  3 +-
 drivers/net/mlx5/linux/mlx5_os.c         |  4 +-
 lib/librte_ethdev/ethdev_private.c       |  5 ++-
 lib/librte_ethdev/rte_class_eth.c        | 38 +++++++++++++----
 lib/librte_ethdev/rte_ethdev.c           | 26 ++++++++++++
 lib/librte_ethdev/rte_ethdev_driver.h    | 53 ++++++++++++++++++++++++
 lib/librte_ethdev/version.map            |  2 +
 10 files changed, 126 insertions(+), 14 deletions(-)
drivers/net/bnxt/bnxt_reps.c +2 -1
index f7bbf77d3f..34febc2d1e 100644
@@ -186,7 +186,8 @@ int bnxt_representor_init(struct rte_eth_dev *eth_dev, void *params)
 
        eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
                                        RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-       eth_dev->data->representor_id = rep_params->vf_id;
+       eth_dev->data->representor_id = rte_eth_representor_id_encode(
+               0, 0, RTE_ETH_REPRESENTOR_VF, rep_params->vf_id);
 
        rte_eth_random_addr(vf_rep_bp->dflt_mac_addr);
        memcpy(vf_rep_bp->mac_addr, vf_rep_bp->dflt_mac_addr,
drivers/net/enic/enic_vf_representor.c +2 -1
index c2c03c0281..632317af15 100644
@@ -674,7 +674,8 @@ int enic_vf_representor_init(struct rte_eth_dev *eth_dev, void *init_params)
        eth_dev->dev_ops = &enic_vf_representor_dev_ops;
        eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
                                        RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-       eth_dev->data->representor_id = vf->vf_id;
+       eth_dev->data->representor_id = rte_eth_representor_id_encode(
+               0, 0, RTE_ETH_REPRESENTOR_VF, vf->vf_id);
        eth_dev->data->mac_addrs = rte_zmalloc("enic_mac_addr_vf",
                sizeof(struct rte_ether_addr) *
                ENIC_UNICAST_PERFECT_FILTERS, 0);
drivers/net/i40e/i40e_vf_representor.c +2 -1
index 9e40406a3d..d90d0fdb9d 100644
@@ -510,7 +510,8 @@ i40e_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params)
 
        ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
                                        RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-       ethdev->data->representor_id = representor->vf_id;
+       ethdev->data->representor_id = rte_eth_representor_id_encode(
+                       0, 0, RTE_ETH_REPRESENTOR_VF, representor->vf_id);
 
        /* Setting the number queues allocated to the VF */
        ethdev->data->nb_rx_queues = vf->vsi->nb_qps;
drivers/net/ixgbe/ixgbe_vf_representor.c +2 -1
index 8185f0d3bb..e15b794761 100644
@@ -196,7 +196,8 @@ ixgbe_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params)
                return -ENODEV;
 
        ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
-       ethdev->data->representor_id = representor->vf_id;
+       ethdev->data->representor_id = rte_eth_representor_id_encode(
+                       0, 0, RTE_ETH_REPRESENTOR_VF, representor->vf_id);
 
        /* Set representor device ops */
        ethdev->dev_ops = &ixgbe_vf_representor_dev_ops;
drivers/net/mlx5/linux/mlx5_os.c +3 -1
index caead107b0..4d7940bcca 100644
@@ -1025,7 +1025,9 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 #endif
        /* representor_id field keeps the unmodified VF index. */
        priv->representor_id = switch_info->representor ?
-                              switch_info->port_name : -1;
+               rte_eth_representor_id_encode(0, 0, RTE_ETH_REPRESENTOR_VF,
+                                             switch_info->port_name) :
+               -1;
        /*
         * Look for sibling devices in order to reuse their switch domain
         * if any, otherwise allocate one.
lib/librte_ethdev/ethdev_private.c +4 -1
index 57473b5a39..0b3b4aa871 100644
@@ -106,10 +106,13 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
 }
 
 /*
- * representor format:
+ * Parse representor ports, expand and update representor port ID.
+ * Representor format:
  *   #: range or single number of VF representor - legacy
  *   [[c#]pf#]vf#: VF port representor/s
  *   [[c#]pf#]sf#: SF port representor/s
+ *
+ * See RTE_ETH_REPR() for representor ID format.
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
lib/librte_ethdev/rte_class_eth.c +30 -8
index efe6149df5..994db96960 100644
@@ -66,8 +66,8 @@ eth_representor_cmp(const char *key __rte_unused,
        int ret;
        char *values;
        const struct rte_eth_dev_data *data = opaque;
-       struct rte_eth_devargs representors;
-       uint16_t index;
+       struct rte_eth_devargs eth_da;
+       uint16_t index, c, p, f;
 
        if ((data->dev_flags & RTE_ETH_DEV_REPRESENTOR) == 0)
                return -1; /* not a representor port */
@@ -76,17 +76,39 @@ eth_representor_cmp(const char *key __rte_unused,
        values = strdup(value);
        if (values == NULL)
                return -1;
-       memset(&representors, 0, sizeof(representors));
-       ret = rte_eth_devargs_parse_representor_ports(values, &representors);
+       memset(&eth_da, 0, sizeof(eth_da));
+       ret = rte_eth_devargs_parse_representor_ports(values, &eth_da);
        free(values);
        if (ret != 0)
                return -1; /* invalid devargs value */
 
+       /* Set default values. */
+       if (eth_da.nb_mh_controllers == 0) {
+               eth_da.nb_mh_controllers = 1;
+               eth_da.mh_controllers[0] = 0;
+       }
+       if (eth_da.nb_ports == 0) {
+               eth_da.nb_ports = 1;
+               eth_da.ports[0] = 0;
+       }
+       if (eth_da.nb_representor_ports == 0) {
+               eth_da.nb_representor_ports = 1;
+               eth_da.representor_ports[0] = 0;
+       }
        /* Return 0 if representor id is matching one of the values. */
-       for (index = 0; index < representors.nb_representor_ports; index++)
-               if (data->representor_id ==
-                               representors.representor_ports[index])
-                       return 0;
+       for (c = 0; c < eth_da.nb_mh_controllers; ++c) {
+               for (p = 0; p < eth_da.nb_ports; ++p) {
+                       for (f = 0; f < eth_da.nb_representor_ports; ++f) {
+                               index = rte_eth_representor_id_encode(
+                                       eth_da.mh_controllers[c],
+                                       eth_da.ports[p],
+                                       eth_da.type,
+                                       eth_da.representor_ports[f]);
+                               if (data->representor_id == index)
+                                       return 0;
+                       }
+               }
+       }
        return -1; /* no match */
 }
 
lib/librte_ethdev/rte_ethdev.c +26 -0
index 2ac51ac149..276f42e54b 100644
@@ -5556,6 +5556,32 @@ rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
        return result;
 }
 
+uint16_t
+rte_eth_representor_id_encode(uint16_t controller, uint16_t pf,
+                             enum rte_eth_representor_type type,
+                             uint16_t representor_port)
+{
+       return (((controller & 3) << 14) |
+               ((pf & 3) << 12) |
+               (!!(type == RTE_ETH_REPRESENTOR_SF) << 11) |
+               (representor_port & 0x7ff));
+}
+
+uint16_t
+rte_eth_representor_id_parse(const uint16_t representor_id,
+                            uint16_t *controller, uint16_t *pf,
+                            enum rte_eth_representor_type *type)
+{
+       if (controller)
+               *controller = (representor_id >> 14) & 3;
+       if (pf)
+               *pf = (representor_id >> 12) & 3;
+       if (type)
+               *type = ((representor_id >> 11) & 1) ?
+                       RTE_ETH_REPRESENTOR_SF : RTE_ETH_REPRESENTOR_VF;
+       return representor_id & 0x7ff;
+}
+
 static int
 eth_dev_handle_port_list(const char *cmd __rte_unused,
                const char *params __rte_unused,
lib/librte_ethdev/rte_ethdev_driver.h +53 -0
index 8e04634660..0d8893693e 100644
@@ -1218,6 +1218,59 @@ struct rte_eth_devargs {
        enum rte_eth_representor_type type; /* type of representor */
 };
 
+#define RTE_NO_REPRESENTOR_ID UINT16_MAX /**< No representor ID. */
+
+/**
+ * PMD helper function to encode representor ID
+ *
+ * The compact format is used for device iterator that comparing
+ * ethdev representor ID with target devargs.
+ *
+ * xxxx xxxx xxxx xxxx
+ * |||| |LLL LLLL LLLL vf/sf id
+ * |||| L 1:sf, 0:vf
+ * ||LL pf id
+ * LL controller(host) id
+ *
+ * @param controller
+ *  Controller ID.
+ * @param pf
+ *  PF port ID.
+ * @param type
+ *  Representor type.
+ * @param representor_port
+ *  Representor port ID.
+ *
+ * @return
+ *   Encoded representor ID.
+ */
+__rte_internal
+uint16_t
+rte_eth_representor_id_encode(uint16_t controller, uint16_t pf,
+                             enum rte_eth_representor_type type,
+                             uint16_t representor_port);
+
+/**
+ * PMD helper function to parse representor ID
+ *
+ * @param representor_id
+ *  Representor ID.
+ * @param controller
+ *  Parsed controller ID.
+ * @param pf
+ *  Parsed PF port ID.
+ * @param type
+ *  Parsed representor type.
+ *
+ * @return
+ *   Parsed representor port ID.
+ */
+__rte_internal
+uint16_t
+rte_eth_representor_id_parse(const uint16_t representor_id,
+                            uint16_t *controller, uint16_t *pf,
+                            enum rte_eth_representor_type *type);
+
 /**
  * PMD helper function to parse ethdev arguments
  *
lib/librte_ethdev/version.map +2 -1
index d3f5410806..44edaed507 100644
@@ -257,6 +257,8 @@ INTERNAL {
        rte_eth_dev_release_port;
        rte_eth_dev_internal_reset;
        rte_eth_devargs_parse;
+       rte_eth_representor_id_encode;
+       rte_eth_representor_id_parse;
        rte_eth_dma_zone_free;
        rte_eth_dma_zone_reserve;
        rte_eth_hairpin_queue_peer_bind;
--

2.25.1

#48 lore raw

Re: [dpdk-dev] [PATCH v4 2/9] ethdev: support representor port list

In reply to Thomas Monjalon

Hi Thomas,

Quoted 39 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, January 19, 2021 12:18 AM
To: Xueming(Steven) Li <[email protected]>
Cc: Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>; Olivier Matz <[email protected]>; [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v4 2/9] ethdev: support representor port list

18/01/2021 12:16, Xueming Li:

Quoted 8 lines

To support extended representor syntax, this patch extends the representor list parsing to support for representor port range in devargs, examples:
representor=[1,2,3] - single list
representor=[1,3-5,7,9-11] - list with singles and ranges

Parsing functions are usually difficult to read.
If you need to do another version, I would recommend adding an oneline comment on top of parsing functions to give a hint about what it is really doing.

Here,

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, · line 43

Quoted 3 lines
lib/librte_ethdev/ethdev_private.c +3 -0
+static int
+rte_eth_devargs_enlist(uint16_t *list, uint16_t *len_list,
+		       const uint16_t max_list, uint16_t val)

here,

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, · line 59

Quoted 3 lines
lib/librte_ethdev/ethdev_private.c +1 -0
+static char *
 rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
 	const uint16_t max_list)

here,

Quoted 10 lines

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, · line 86

Quoted 3 lines
lib/librte_ethdev/ethdev_private.c +3 -0
+static char *
+rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
+	const uint16_t max_list)

and also for this old one:

Review rte_eth_devargs_parse_representor_ports(char *str, · line 115

Quoted 2 lines
(quoted diff) +0 -0
@@ -121,6 +115,9 @@ rte_eth_devargs_parse_representor_ports(char *str,
 void *data)

Will add them in next version, thanks.

#39 lore raw

Re: [dpdk-dev] [PATCH v4 1/9] ethdev: introduce representor type

In reply to Ajit Khaparde
Quoted 30 lines

-----Original Message-----
From: Ajit Khaparde <[email protected]>
Sent: Tuesday, January 19, 2021 2:18 AM
To: NBU-Contact-Thomas Monjalon <[email protected]>
Cc: Xueming(Steven) Li <[email protected]>; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>; Olivier Matz <[email protected]>; dpdk-dev <[email protected]>; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v4 1/9] ethdev: introduce representor type

Quoted 3 lines · Thomas Monjalon

18/01/2021 19:00, Ajit Khaparde:

Quoted 1 line

On Mon, Jan 18, 2021 at 9:57 AM Thomas Monjalon

Quoted 2 lines · <[email protected]> wrote:
Quoted 2 lines
Quoted 2 lines

18/01/2021 18:42, Ajit Khaparde:

Quoted 1 line

On Mon, Jan 18, 2021 at 3:17 AM Xueming Li <[email protected]>

Quoted 6 lines · wrote:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

lib/librte_ethdev/rte_ethdev_driver.h __rte_internal · line 1200

Quoted 4 lines
lib/librte_ethdev/rte_ethdev_driver.h +4 -0
+enum rte_eth_representor_type {
+       RTE_ETH_REPRESENTOR_NONE, /**< not a representor. */
+       RTE_ETH_REPRESENTOR_VF,   /**< representor of VF. */
+       RTE_ETH_REPRESENTOR_SF,   /**< representor of SF. */

Till we get used to the terminology...
Can we also have SF = "Sub Function" mentioned in the docs or

comments?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Are we sure about the definition?
I remember seeing SF = Scalable Function somewhere else (maybe from

Quoted 7 lines

Intel)

Quoted 5 lines
Quoted 1 line

That complicates it. But if they mean the same thing, let's pick one.

I think "Sub Function" and "Virtual Function" are easy to understand for everybody.
I suggest picking these two for comments above.

+1

There was an internal discussion and the conclusion is to align with kernel driver name. Will update comment in next version, thanks!

Quoted 2 lines
Quoted 2 lines
author
#63 lore raw

v5 cover ethdev: support SubFunction representor

In reply to Xueming Li

dedicated queues(txq, rxq). A SF netdev supports E-Switch representation offload similar to existing PF and VF representors. A SF shares PCI level resources with other SFs and/or with its parent PCI function.

From SmartNIC perspective, when PCI device is shared for multi-host, representors for host controller and host PF is required.

This patch set introduces new representor types in addtion to existing VF representor. Syntax:

[[c#]pf#]vf#: VF port representor/s from controller/pf [[c#]pf#]sf#: SF port representor/s from controller/pf #: VF representor - for backwards compatibility

"#" is number instance, list or range, valid examples:
1, [1,3,5], [0-3], [0,2-4,6]

For backward compatibility, this patch also introduces new netdev capability to indicate the capability of supportting SF representor.

Version history:
RFC:
initial version [2]
V2:
- separate patch for represnetor infrastructure, controller, pf and sf.
- replace representor ID macro with functions:
rte_eth_representor_id_encode() rte_eth_representor_id_parse()
- new patch to allow devargs with same PCI BDF but different representors.
- other minor code updates according to comments, thanks Andrew!
- update document
V3:
- improve probing of allowed devargs with same name.
- parse single word of kvargs as key.
- update kvargs test cases.
V4:
- split first representor refactor patch into
1: add representor type
2: refector representor list parsing
- push the patch supporting multi-devargs for same device.
V5:
- add comments for parsing functions
- update switch_representation.rst - Thanks Ajit

[1] SubFunction in kernel:
https://lore.kernel.org/netdev/[email protected]/

[2] RFC:
http://patchwork.dpdk.org/project/dpdk/list/?series=14376

[3] V2:
http://patchwork.dpdk.org/project/dpdk/list/?series=14559

[4] V3:
1 http://patchwork.dpdk.org/patch/86460/
2 http://patchwork.dpdk.org/patch/86461/
3 http://patchwork.dpdk.org/patch/86462/
4 http://patchwork.dpdk.org/patch/86463/
5 http://patchwork.dpdk.org/patch/86464/
6 http://patchwork.dpdk.org/patch/86465/
7 http://patchwork.dpdk.org/patch/86467/
8 http://patchwork.dpdk.org/patch/86466/
9 http://patchwork.dpdk.org/patch/86468/

[5] V4:
http://patchwork.dpdk.org/project/dpdk/list/?series=14809

Xueming Li (9):
ethdev: introduce representor type
ethdev: support representor port list
ethdev: support new VF representor syntax
ethdev: support sub function representor
ethdev: support PF index in representor
ethdev: support multi-host in representor
devarg: change representor ID to bitmap
ethdev: add capability of sub-function representor
kvargs: update parser to support lists

 app/test/test_kvargs.c                        |  46 +++++-
 config/rte_config.h                           |   1 +
 doc/guides/prog_guide/poll_mode_drv.rst       |  13 +-
 .../prog_guide/switch_representation.rst      |  35 ++--
 drivers/net/bnxt/bnxt_ethdev.c                |   7 +
 drivers/net/bnxt/bnxt_reps.c                  |   3 +-
 drivers/net/enic/enic_ethdev.c                |   7 +
 drivers/net/enic/enic_vf_representor.c        |   3 +-
 drivers/net/i40e/i40e_ethdev.c                |   8 +
 drivers/net/i40e/i40e_vf_representor.c        |   3 +-
 drivers/net/ixgbe/ixgbe_ethdev.c              |   8 +
 drivers/net/ixgbe/ixgbe_vf_representor.c      |   3 +-
 drivers/net/mlx5/linux/mlx5_os.c              |  15 +-
 lib/librte_ethdev/ethdev_private.c            | 154 ++++++++++++------
 lib/librte_ethdev/ethdev_private.h            |   3 -
 lib/librte_ethdev/rte_class_eth.c             |  40 +++--
 lib/librte_ethdev/rte_ethdev.c                |  31 +++-
 lib/librte_ethdev/rte_ethdev.h                |   2 +
 lib/librte_ethdev/rte_ethdev_driver.h         |  66 ++++++++
 lib/librte_ethdev/version.map                 |   2 +
 lib/librte_kvargs/rte_kvargs.c                | 101 ++++++++----
 21 files changed, 428 insertions(+), 123 deletions(-)
Signature · 1 line
2.25.1
author
#78 lore raw

PATCH v5 1/9 ethdev: introduce representor type

In reply to Xueming Li

To support more representor type, this patch introduces representor type enum. The enum is subject to extend for new types upcoming.

---
 drivers/net/bnxt/bnxt_ethdev.c        |  7 +++++++
 drivers/net/enic/enic_ethdev.c        |  7 +++++++
 drivers/net/i40e/i40e_ethdev.c        |  8 ++++++++
 drivers/net/ixgbe/ixgbe_ethdev.c      |  8 ++++++++
 drivers/net/mlx5/linux/mlx5_os.c      | 11 +++++++++++
 lib/librte_ethdev/ethdev_private.c    |  5 +++++
 lib/librte_ethdev/rte_ethdev_driver.h |  9 +++++++++
 7 files changed, 55 insertions(+)
drivers/net/bnxt/bnxt_ethdev.c +7 -0
index 74b0f3d1dc..d7c8b3ec07 100644
@@ -5586,6 +5586,13 @@ static int bnxt_rep_port_probe(struct rte_pci_device *pci_dev,
 	int i, ret = 0;
 	struct rte_kvargs *kvlist = NULL;
 
+	if (eth_da->type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da->type != RTE_ETH_REPRESENTOR_VF) {
+		PMD_DRV_LOG(ERR, "unsupported representor type %d\n",
+			    eth_da->type);
+		return -ENOTSUP;
+	}
 	num_rep = eth_da->nb_representor_ports;
 	if (num_rep > BNXT_MAX_VF_REPS) {
 		PMD_DRV_LOG(ERR, "nb_representor_ports = %d > %d MAX VF REPS\n",
drivers/net/enic/enic_ethdev.c +7 -0
index d041a6bee9..dd085caa93 100644
@@ -1303,6 +1303,13 @@ static int eth_enic_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 		if (retval)
 			return retval;
 	}
+	if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+		ENICPMD_LOG(ERR, "unsupported representor type: %s\n",
+			    pci_dev->device.devargs->args);
+		return -ENOTSUP;
+	}
 	retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
 		sizeof(struct enic),
 		eth_dev_pci_specific_init, pci_dev,
drivers/net/i40e/i40e_ethdev.c +8 -0
index f083ac52fa..eb55d64585 100644
@@ -638,6 +638,14 @@ eth_i40e_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 			return retval;
 	}
 
+	if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+		PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
+			    pci_dev->device.devargs->args);
+		return -ENOTSUP;
+	}
+
 	retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
 		sizeof(struct i40e_adapter),
 		eth_dev_pci_specific_init, pci_dev,
drivers/net/ixgbe/ixgbe_ethdev.c +8 -0
index fa0f5afd03..6f1a710dae 100644
@@ -1717,6 +1717,14 @@ eth_ixgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 	} else
 		memset(&eth_da, 0, sizeof(eth_da));
 
+	if (eth_da.type == RTE_ETH_REPRESENTOR_NONE)
+		return 0;
+	if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+		PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
+			    pci_dev->device.devargs->args);
+		return -ENOTSUP;
+	}
+
 	retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
 		sizeof(struct ixgbe_adapter),
 		eth_dev_pci_specific_init, pci_dev,
drivers/net/mlx5/linux/mlx5_os.c +11 -0
index 9ac1d46b1b..caead107b0 100644
@@ -705,6 +705,17 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 				strerror(rte_errno));
 			return NULL;
 		}
+		if (eth_da.type != RTE_ETH_REPRESENTOR_NONE) {
+			/* Representor not specified. */
+			rte_errno = EBUSY;
+			return NULL;
+		}
+		if (eth_da.type != RTE_ETH_REPRESENTOR_VF) {
+			rte_errno = ENOTSUP;
+			DRV_LOG(ERR, "unsupported representor type: %s",
+				dpdk_dev->devargs->args);
+			return NULL;
+		}
 		for (i = 0; i < eth_da.nb_representor_ports; ++i)
 			if (eth_da.representor_ports[i] ==
 			    (uint16_t)switch_info->port_name)
lib/librte_ethdev/ethdev_private.c +5 -0
index 162a502fe7..c1a411dba4 100644
@@ -111,11 +111,16 @@ rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
 	return 0;
 }
 
+/*
+ * representor format:
+ *   #: range or single number of VF representor
+ */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
 {
 	struct rte_eth_devargs *eth_da = data;
 
+	eth_da->type = RTE_ETH_REPRESENTOR_VF;
 	return rte_eth_devargs_process_range(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
 }
lib/librte_ethdev/rte_ethdev_driver.h +9 -0
index 0eacfd8425..cd33184f17 100644
@@ -1193,6 +1193,14 @@ __rte_internal
 int
 rte_eth_switch_domain_free(uint16_t domain_id);
 
+/** Ethernet device representor port type */
+enum rte_eth_representor_type {
+	RTE_ETH_REPRESENTOR_NONE, /**< not a representor. */
+	RTE_ETH_REPRESENTOR_VF,   /**< representor of Virtual Function. */
+	RTE_ETH_REPRESENTOR_SF,   /**< representor of Sub Function. */
+	RTE_ETH_REPRESENTOR_PF,   /**< representor of host Physical Function. */
+};
+
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
 	uint16_t ports[RTE_MAX_ETHPORTS];
@@ -1203,6 +1211,7 @@ struct rte_eth_devargs {
 	/** representor port/s identifier to enable on device */
 	uint16_t nb_representor_ports;
 	/** number of ports in representor port field */
+	enum rte_eth_representor_type type; /* type of representor */
 };
 
 /**
Signature · 1 line
2.25.1
author
#79 lore raw

PATCH v5 2/9 ethdev: support representor port list

To support extended representor syntax, this patch extends the representor list parsing to support for representor port range in devargs, examples:
representor=[1,2,3] - single list
representor=[1,3-5,7,9-11] - list with singles and ranges

---
 lib/librte_ethdev/ethdev_private.c | 124 ++++++++++++++++-------------
 lib/librte_ethdev/ethdev_private.h |   3 -
 lib/librte_ethdev/rte_class_eth.c  |   4 +-
 lib/librte_ethdev/rte_ethdev.c     |   5 +-
 4 files changed, 72 insertions(+), 64 deletions(-)
lib/librte_ethdev/ethdev_private.c +69 -55
index c1a411dba4..e87636f665 100644
@@ -38,82 +38,93 @@ eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp,
 	return NULL;
 }
 
-int
-rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
-	void *data)
+/* Put new value into list. */
+static int
+rte_eth_devargs_enlist(uint16_t *list, uint16_t *len_list,
+		       const uint16_t max_list, uint16_t val)
 {
-	char *str_start;
-	int state;
-	int result;
+	uint16_t i;
 
-	if (*str != '[')
-		/* Single element, not a list */
-		return callback(str, data);
-
-	/* Sanity check, then strip the brackets */
-	str_start = &str[strlen(str) - 1];
-	if (*str_start != ']') {
-		RTE_LOG(ERR, EAL, "(%s): List does not end with ']'\n", str);
-		return -EINVAL;
-	}
-	str++;
-	*str_start = '\0';
-
-	/* Process list elements */
-	state = 0;
-	while (1) {
-		if (state == 0) {
-			if (*str == '\0')
-				break;
-			if (*str != ',') {
-				str_start = str;
-				state = 1;
-			}
-		} else if (state == 1) {
-			if (*str == ',' || *str == '\0') {
-				if (str > str_start) {
-					/* Non-empty string fragment */
-					*str = '\0';
-					result = callback(str_start, data);
-					if (result < 0)
-						return result;
-				}
-				state = 0;
-			}
-		}
-		str++;
+	if (*len_list >= max_list)
+		return -1;
+	for (i = 0; i < *len_list; i++) {
+		if (list[i] == val)
+			return 0;
 	}
+	list[(*len_list)++] = val;
 	return 0;
 }
 
-static int
+/* Parse and enlist a range expression of "min-max" or a single value. */
+static char *
 rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
 	const uint16_t max_list)
 {
 	uint16_t lo, hi, val;
 	int result;
+	char *pos = str;
 
 	result = sscanf(str, "%hu-%hu", &lo, &hi);
 	if (result == 1) {
-		if (*len_list >= max_list)
-			return -ENOMEM;
-		list[(*len_list)++] = lo;
+		if (rte_eth_devargs_enlist(list, len_list, max_list, lo) != 0)
+			return NULL;
 	} else if (result == 2) {
-		if (lo >= hi || lo > RTE_MAX_ETHPORTS || hi > RTE_MAX_ETHPORTS)
-			return -EINVAL;
+		if (lo >= hi)
+			return NULL;
 		for (val = lo; val <= hi; val++) {
-			if (*len_list >= max_list)
-				return -ENOMEM;
-			list[(*len_list)++] = val;
+			if (rte_eth_devargs_enlist(list, len_list, max_list,
+						   val) != 0)
+				return NULL;
 		}
 	} else
-		return -EINVAL;
-	return 0;
+		return NULL;
+	while (*pos != 0 && ((*pos >= '0' && *pos <= '9') || *pos == '-'))
+		pos++;
+	return pos;
+}
+
+/*
+ * Parse list of values separated by ",".
+ * Each value could be a range [min-max] or single number.
+ * Examples:
+ *  2               - single
+ *  [1,2,3]         - single list
+ *  [1,3-5,7,9-11]  - list with singles and ranges
+ */
+static char *
+rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
+	const uint16_t max_list)
+{
+	char *pos = str;
+
+	if (*pos == '[')
+		pos++;
+	while (1) {
+		pos = rte_eth_devargs_process_range(pos, list, len_list,
+						    max_list);
+		if (pos == NULL)
+			return NULL;
+		if (*pos != ',') /* end of list */
+			break;
+		pos++;
+	}
+	if (*str == '[' && *pos != ']')
+		return NULL;
+	if (*pos == ']')
+		pos++;
+	return pos;
 }
 
 /*
- * representor format:
+ * Parse representor ports from a single value or lists.
+ *
+ * Representor format:
  *   #: range or single number of VF representor
+ *
+ * Examples of #:
+ *  2               - single
+ *  [1,2,3]         - single list
+ *  [1,3-5,7,9-11]  - list with singles and ranges
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
@@ -121,6 +132,9 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	struct rte_eth_devargs *eth_da = data;
 
 	eth_da->type = RTE_ETH_REPRESENTOR_VF;
-	return rte_eth_devargs_process_range(str, eth_da->representor_ports,
+	str = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
+	if (str == NULL)
+		RTE_LOG(ERR, EAL, "wrong representor format: %s\n", str);
+	return str == NULL ? -1 : 0;
 }
lib/librte_ethdev/ethdev_private.h +0 -3
index 905a45c337..220ddd4408 100644
@@ -26,9 +26,6 @@ eth_find_device(const struct rte_eth_dev *_start, rte_eth_cmp_t cmp,
 		const void *data);
 
 /* Parse devargs value for representor parameter. */
-typedef int (*rte_eth_devargs_callback_t)(char *str, void *data);
-int rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
-	void *data);
 int rte_eth_devargs_parse_representor_ports(char *str, void *data);
 
 #ifdef __cplusplus
lib/librte_ethdev/rte_class_eth.c +1 -3
index 6338355e25..efe6149df5 100644
@@ -77,9 +77,7 @@ eth_representor_cmp(const char *key __rte_unused,
 	if (values == NULL)
 		return -1;
 	memset(&representors, 0, sizeof(representors));
-	ret = rte_eth_devargs_parse_list(values,
-			rte_eth_devargs_parse_representor_ports,
-			&representors);
+	ret = rte_eth_devargs_parse_representor_ports(values, &representors);
 	free(values);
 	if (ret != 0)
 		return -1; /* invalid devargs value */
lib/librte_ethdev/rte_ethdev.c +2 -3
index 71e1e9a6db..91b3263338 100644
@@ -5561,9 +5561,8 @@ rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
 	for (i = 0; i < args.count; i++) {
 		pair = &args.pairs[i];
 		if (strcmp("representor", pair->key) == 0) {
-			result = rte_eth_devargs_parse_list(pair->value,
-				rte_eth_devargs_parse_representor_ports,
-				eth_da);
+			result = rte_eth_devargs_parse_representor_ports(
+					pair->value, eth_da);
 			if (result < 0)
 				goto parse_cleanup;
 		}
Signature · 1 line
2.25.1
author
#82 lore raw

PATCH v5 3/9 ethdev: support new VF representor syntax

In reply to Xueming Li

Current VF representor syntax:
representor=2 - single representor
representor=[0-3] - single range

To prepare for more representor types, this patch adds compatible VF representor devargs syntax:

vf#:

 representor=vf2          - single representor
 representor=vf[1,3,5]    - single list
 representor=vf[0-3]      - single range
 representor=vf[0,1,4-7]  - list with singles and range

For backwards compatibility, representor "#" is interpreted as "vf#".

---
 doc/guides/prog_guide/poll_mode_drv.rst | 7 ++++---
 lib/librte_ethdev/ethdev_private.c      | 5 ++++-
 2 files changed, 8 insertions(+), 4 deletions(-)
doc/guides/prog_guide/poll_mode_drv.rst +4 -3
index 239ec820ea..0117c2af07 100644
@@ -374,9 +374,10 @@ parameters to those ports.
   this argument allows user to specify which switch ports to enable port
   representors for.::
 
-   -a DBDF,representor=0
-   -a DBDF,representor=[0,4,6,9]
-   -a DBDF,representor=[0-31]
+   -a DBDF,representor=vf0
+   -a DBDF,representor=vf[0,4,6,9]
+   -a DBDF,representor=vf[0-31]
+   -a DBDF,representor=vf[0,2-4,7,9-11]
 
 Note: PMDs are not required to support the standard device arguments and users
 should consult the relevant PMD documentation to see support devargs.
lib/librte_ethdev/ethdev_private.c +4 -1
index e87636f665..20e48a48be 100644
@@ -119,7 +119,8 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
  * Parse representor ports from a single value or lists.
  *
  * Representor format:
- *   #: range or single number of VF representor
+ *   #: range or single number of VF representor - legacy
+ *   vf#: VF port representor/s
  *
  * Examples of #:
  *  2               - single
@@ -132,6 +133,8 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	struct rte_eth_devargs *eth_da = data;
 
 	eth_da->type = RTE_ETH_REPRESENTOR_VF;
+	if (str[0] == 'v' && str[1] == 'f')
+		str += 2;
 	str = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
 	if (str == NULL)
Signature · 1 line
2.25.1
author
#84 lore raw

PATCH v5 4/9 ethdev: support sub function representor

In reply to Xueming Li

SubFunction is a portion of the PCI device, created on demand, a SF netdev has its own dedicated queues(txq, rxq). A SF netdev supports eswitch representation offload similar to existing PF and VF representors.

To support SF representor, this patch introduces new devargs syntax, examples:

 representor=sf0               - single SubFunction representor
 representor=sf[1,3,5]         - single list
 representor=sf[0-3],          - single range

representor=sf[0,2-6,8,10-12] - list with singles and ranges

---
 doc/guides/prog_guide/poll_mode_drv.rst       |  4 +++
 .../prog_guide/switch_representation.rst      | 35 +++++++++++++------
 lib/librte_ethdev/ethdev_private.c            | 11 ++++--
 3 files changed, 38 insertions(+), 12 deletions(-)
doc/guides/prog_guide/poll_mode_drv.rst +4 -0
index 0117c2af07..86e5867f1b 100644
@@ -378,6 +378,10 @@ parameters to those ports.
    -a DBDF,representor=vf[0,4,6,9]
    -a DBDF,representor=vf[0-31]
    -a DBDF,representor=vf[0,2-4,7,9-11]
+   -a DBDF,representor=sf0
+   -a DBDF,representor=sf[1,3,5]
+   -a DBDF,representor=sf[0-1023]
+   -a DBDF,representor=sf[0,2-4,7,9-11]
 
 Note: PMDs are not required to support the standard device arguments and users
 should consult the relevant PMD documentation to see support devargs.
doc/guides/prog_guide/switch_representation.rst +25 -10
index 07ba12bea6..ff6aa91c80 100644
@@ -13,7 +13,7 @@ Introduction
 
 Network adapters with multiple physical ports and/or SR-IOV capabilities
 usually support the offload of traffic steering rules between their virtual
-functions (VFs), physical functions (PFs) and ports.
+functions (VFs), sub functions (SFs), physical functions (PFs) and ports.
 
 Like for standard Ethernet switches, this involves a combination of
 automatic MAC learning and manual configuration. For most purposes it is
@@ -24,7 +24,7 @@ layer 2 (L2) traffic (such as OVS) need to steer traffic themselves
 according on their own criteria.
 
 Without a standard software interface to manage traffic steering rules
-between VFs, PFs and the various physical ports of a given device,
+between VFs, SFs, PFs and the various physical ports of a given device,
 applications cannot take advantage of these offloads; software processing is
 mandatory even for traffic which ends up re-injected into the device it
 originates from.
@@ -34,6 +34,17 @@ the DPDK flow API (**rte_flow**), with emphasis on the SR-IOV use case
 (PF/VF steering) using a single physical port for clarity, however the same
 logic applies to any number of ports without necessarily involving SR-IOV.
 
+Sub Function
+------------
+Besides SR-IOV, Sub function is a portion of the PCI device, a SF netdev
+has its own dedicated queues(txq, rxq). A SF netdev supports E-Switch
+representation offload similar to existing PF and VF representors.
+A SF shares PCI level resources with other SFs and/or with its parent PCI
+function.
+
+Sub function is created on-demand, coexists with VFs. Number of SFs is
+limited by hardware resources.
+
 Port Representors
 -----------------
 
@@ -42,15 +53,16 @@ applications usually have to process a bit of traffic in software before
 thinking about offloading specific flows to hardware.
 
 Applications therefore need the ability to receive and inject traffic to
-various device endpoints (other VFs, PFs or physical ports) before
+various device endpoints (other VFs, SFs, PFs or physical ports) before
 connecting them together. Device drivers must provide means to hook the
 "other end" of these endpoints and to refer them when configuring flow
 rules.
 
 This role is left to so-called "port representors" (also known as "VF
-representors" in the specific context of VFs), which are to DPDK what the
-Ethernet switch device driver model (**switchdev**) [1]_ is to Linux, and
-which can be thought as a software "patch panel" front-end for applications.
+representors" in the specific context of VFs, "SF representors" in the
+specific context of SFs), which are to DPDK what the Ethernet switch
+device driver model (**switchdev**) [1]_ is to Linux, and which can be
+thought as a software "patch panel" front-end for applications.
 
 - DPDK port representors are implemented as additional virtual Ethernet
   device (**ethdev**) instances, spawned on an as needed basis through
@@ -59,9 +71,12 @@ which can be thought as a software "patch panel" front-end for applications.
 
 ::
 
-   -a pci:dbdf,representor=0
-   -a pci:dbdf,representor=[0-3]
-   -a pci:dbdf,representor=[0,5-11]
+   -a pci:dbdf,representor=vf0
+   -a pci:dbdf,representor=vf[0-3]
+   -a pci:dbdf,representor=vf[0,5-11]
+   -a pci:dbdf,representor=sf1
+   -a pci:dbdf,representor=sf[0-1023]
+   -a pci:dbdf,representor=sf[0,2-1023]
 
 - As virtual devices, they may be more limited than their physical
   counterparts, for instance by exposing only a subset of device
@@ -360,7 +375,7 @@ Compared to creating a brand new dedicated interface, **rte_flow** was
 deemed flexible enough to manage representor traffic only with minor
 extensions:
 
-- Using physical ports, PF, VF or port representors as targets.
+- Using physical ports, PF, SF, VF or port representors as targets.
 
 - Affecting traffic that is not necessarily addressed to the DPDK port ID a
   flow rule is associated with (e.g. forcing VF traffic redirection to PF).
lib/librte_ethdev/ethdev_private.c +9 -2
index 20e48a48be..d513f035d0 100644
@@ -121,6 +121,7 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
  * Representor format:
  *   #: range or single number of VF representor - legacy
  *   vf#: VF port representor/s
+ *   sf#: SF port representor/s
  *
  * Examples of #:
  *  2               - single
@@ -132,9 +133,15 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 {
 	struct rte_eth_devargs *eth_da = data;
 
-	eth_da->type = RTE_ETH_REPRESENTOR_VF;
-	if (str[0] == 'v' && str[1] == 'f')
+	if (str[0] == 'v' && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_VF;
 		str += 2;
+	} else if (str[0] == 's' && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_SF;
+		str += 2;
+	} else {
+		eth_da->type = RTE_ETH_REPRESENTOR_VF;
+	}
 	str = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
 	if (str == NULL)
Signature · 1 line
2.25.1
author
#86 lore raw

PATCH v5 5/9 ethdev: support PF index in representor

In reply to Xueming Li

With Kernel bonding, multiple underlying PFs are bonded, VFs come from different PF, need to identify representor of VFs unambiguously by adding PF index.

This patch introduces optional 'pf' section to representor devargs syntax, examples:
representor=pf0vf0 - single VF representor
representor=pf[0-1]sf[0-1023] - SF representors from 2 PFs

---
 doc/guides/prog_guide/poll_mode_drv.rst |  2 ++
 lib/librte_ethdev/ethdev_private.c      | 13 +++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
doc/guides/prog_guide/poll_mode_drv.rst +2 -0
index 86e5867f1b..b2147aad30 100644
@@ -382,6 +382,8 @@ parameters to those ports.
    -a DBDF,representor=sf[1,3,5]
    -a DBDF,representor=sf[0-1023]
    -a DBDF,representor=sf[0,2-4,7,9-11]
+   -a DBDF,representor=pf1vf0
+   -a DBDF,representor=pf[0-1]sf[0-127]
 
 Note: PMDs are not required to support the standard device arguments and users
 should consult the relevant PMD documentation to see support devargs.
lib/librte_ethdev/ethdev_private.c +11 -2
index d513f035d0..b9fdbd0f72 100644
@@ -120,8 +120,8 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
  *
  * Representor format:
  *   #: range or single number of VF representor - legacy
- *   vf#: VF port representor/s
- *   sf#: SF port representor/s
+ *   [pf#]vf#: VF port representor/s
+ *   [pf#]sf#: SF port representor/s
  *
  * Examples of #:
  *  2               - single
@@ -133,6 +133,14 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 {
 	struct rte_eth_devargs *eth_da = data;
 
+	if (str[0] == 'p' && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_PF;
+		str += 2;
+		str = rte_eth_devargs_process_list(str, eth_da->ports,
+				&eth_da->nb_ports, RTE_MAX_ETHPORTS);
+		if (str == NULL)
+			goto err;
+	}
 	if (str[0] == 'v' && str[1] == 'f') {
 		eth_da->type = RTE_ETH_REPRESENTOR_VF;
 		str += 2;
@@ -144,6 +152,7 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	}
 	str = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
+err:
 	if (str == NULL)
 		RTE_LOG(ERR, EAL, "wrong representor format: %s\n", str);
 	return str == NULL ? -1 : 0;
Signature · 1 line
2.25.1
author
#94 lore raw

PATCH v5 7/9 devarg: change representor ID to bitmap

In reply to Xueming Li

The NIC can have multiple PCIe links and can be attached to multiple hosts, for example the same single NIC can be shared for multiple server units in the rack. On each PCIe link NIC can provide multiple PFs and VFs/SFs based on these ones. The full representor identifier consists of three indices - controller index, PF index, and VF or SF index (if any).

SR-IOV and SubFunction are created on top of PF. PF index is introduced because there might be multiple PFs in the bonding configuration and only bonding device is probed.

In eth representor comparator callback, ethdev was compared with devarg. Since ethdev representor port didn't contain controller index and PF index information, callback returned representor from other PF or controller.

This patch changes representor ID to bitmap so that the ethdev representor comparer callback returns correct ethdev by comparing full representor information including: controller index, PF index, representor type, SF or VF index.

Representor ID bitmap definition:
xxxx xxxx xxxx xxxx

 |||| |LLL LLLL LLLL vf/sf id
 |||| L 1:sf, 0:vf
 ||LL pf id

LL controller(host) id

This approach keeps binary compatibility with all drivers, VF representor id matches with simple id for non-bonding and non-multi-host configurations.

In the future, the representor ID field and each section should extend to bigger width to support more devices.

---
 drivers/net/bnxt/bnxt_reps.c             |  3 +-
 drivers/net/enic/enic_vf_representor.c   |  3 +-
 drivers/net/i40e/i40e_vf_representor.c   |  3 +-
 drivers/net/ixgbe/ixgbe_vf_representor.c |  3 +-
 drivers/net/mlx5/linux/mlx5_os.c         |  4 +-
 lib/librte_ethdev/rte_class_eth.c        | 38 +++++++++++++----
 lib/librte_ethdev/rte_ethdev.c           | 26 ++++++++++++
 lib/librte_ethdev/rte_ethdev_driver.h    | 53 ++++++++++++++++++++++++
 lib/librte_ethdev/version.map            |  2 +
 9 files changed, 122 insertions(+), 13 deletions(-)
drivers/net/bnxt/bnxt_reps.c +2 -1
index f7bbf77d3f..34febc2d1e 100644
@@ -186,7 +186,8 @@ int bnxt_representor_init(struct rte_eth_dev *eth_dev, void *params)
 
 	eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
 					RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-	eth_dev->data->representor_id = rep_params->vf_id;
+	eth_dev->data->representor_id = rte_eth_representor_id_encode(
+		0, 0, RTE_ETH_REPRESENTOR_VF, rep_params->vf_id);
 
 	rte_eth_random_addr(vf_rep_bp->dflt_mac_addr);
 	memcpy(vf_rep_bp->mac_addr, vf_rep_bp->dflt_mac_addr,
drivers/net/enic/enic_vf_representor.c +2 -1
index c2c03c0281..632317af15 100644
@@ -674,7 +674,8 @@ int enic_vf_representor_init(struct rte_eth_dev *eth_dev, void *init_params)
 	eth_dev->dev_ops = &enic_vf_representor_dev_ops;
 	eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
 					RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-	eth_dev->data->representor_id = vf->vf_id;
+	eth_dev->data->representor_id = rte_eth_representor_id_encode(
+		0, 0, RTE_ETH_REPRESENTOR_VF, vf->vf_id);
 	eth_dev->data->mac_addrs = rte_zmalloc("enic_mac_addr_vf",
 		sizeof(struct rte_ether_addr) *
 		ENIC_UNICAST_PERFECT_FILTERS, 0);
drivers/net/i40e/i40e_vf_representor.c +2 -1
index 9e40406a3d..d90d0fdb9d 100644
@@ -510,7 +510,8 @@ i40e_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params)
 
 	ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
 					RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-	ethdev->data->representor_id = representor->vf_id;
+	ethdev->data->representor_id = rte_eth_representor_id_encode(
+			0, 0, RTE_ETH_REPRESENTOR_VF, representor->vf_id);
 
 	/* Setting the number queues allocated to the VF */
 	ethdev->data->nb_rx_queues = vf->vsi->nb_qps;
drivers/net/ixgbe/ixgbe_vf_representor.c +2 -1
index 8185f0d3bb..e15b794761 100644
@@ -196,7 +196,8 @@ ixgbe_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params)
 		return -ENODEV;
 
 	ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
-	ethdev->data->representor_id = representor->vf_id;
+	ethdev->data->representor_id = rte_eth_representor_id_encode(
+			0, 0, RTE_ETH_REPRESENTOR_VF, representor->vf_id);
 
 	/* Set representor device ops */
 	ethdev->dev_ops = &ixgbe_vf_representor_dev_ops;
drivers/net/mlx5/linux/mlx5_os.c +3 -1
index caead107b0..4d7940bcca 100644
@@ -1025,7 +1025,9 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 #endif
 	/* representor_id field keeps the unmodified VF index. */
 	priv->representor_id = switch_info->representor ?
-			       switch_info->port_name : -1;
+		rte_eth_representor_id_encode(0, 0, RTE_ETH_REPRESENTOR_VF,
+					      switch_info->port_name) :
+		-1;
 	/*
 	 * Look for sibling devices in order to reuse their switch domain
 	 * if any, otherwise allocate one.
lib/librte_ethdev/rte_class_eth.c +30 -8
index efe6149df5..994db96960 100644
@@ -66,8 +66,8 @@ eth_representor_cmp(const char *key __rte_unused,
 	int ret;
 	char *values;
 	const struct rte_eth_dev_data *data = opaque;
-	struct rte_eth_devargs representors;
-	uint16_t index;
+	struct rte_eth_devargs eth_da;
+	uint16_t index, c, p, f;
 
 	if ((data->dev_flags & RTE_ETH_DEV_REPRESENTOR) == 0)
 		return -1; /* not a representor port */
@@ -76,17 +76,39 @@ eth_representor_cmp(const char *key __rte_unused,
 	values = strdup(value);
 	if (values == NULL)
 		return -1;
-	memset(&representors, 0, sizeof(representors));
-	ret = rte_eth_devargs_parse_representor_ports(values, &representors);
+	memset(&eth_da, 0, sizeof(eth_da));
+	ret = rte_eth_devargs_parse_representor_ports(values, &eth_da);
 	free(values);
 	if (ret != 0)
 		return -1; /* invalid devargs value */
 
+	/* Set default values. */
+	if (eth_da.nb_mh_controllers == 0) {
+		eth_da.nb_mh_controllers = 1;
+		eth_da.mh_controllers[0] = 0;
+	}
+	if (eth_da.nb_ports == 0) {
+		eth_da.nb_ports = 1;
+		eth_da.ports[0] = 0;
+	}
+	if (eth_da.nb_representor_ports == 0) {
+		eth_da.nb_representor_ports = 1;
+		eth_da.representor_ports[0] = 0;
+	}
 	/* Return 0 if representor id is matching one of the values. */
-	for (index = 0; index < representors.nb_representor_ports; index++)
-		if (data->representor_id ==
-				representors.representor_ports[index])
-			return 0;
+	for (c = 0; c < eth_da.nb_mh_controllers; ++c) {
+		for (p = 0; p < eth_da.nb_ports; ++p) {
+			for (f = 0; f < eth_da.nb_representor_ports; ++f) {
+				index = rte_eth_representor_id_encode(
+					eth_da.mh_controllers[c],
+					eth_da.ports[p],
+					eth_da.type,
+					eth_da.representor_ports[f]);
+				if (data->representor_id == index)
+					return 0;
+			}
+		}
+	}
 	return -1; /* no match */
 }
 
lib/librte_ethdev/rte_ethdev.c +26 -0
index 91b3263338..2cac0ccfbd 100644
@@ -5575,6 +5575,32 @@ rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
 	return result;
 }
 
+uint16_t
+rte_eth_representor_id_encode(uint16_t controller, uint16_t pf,
+			      enum rte_eth_representor_type type,
+			      uint16_t representor_port)
+{
+	return (((controller & 3) << 14) |
+		((pf & 3) << 12) |
+		(!!(type == RTE_ETH_REPRESENTOR_SF) << 11) |
+		(representor_port & 0x7ff));
+}
+
+uint16_t
+rte_eth_representor_id_parse(const uint16_t representor_id,
+			     uint16_t *controller, uint16_t *pf,
+			     enum rte_eth_representor_type *type)
+{
+	if (controller)
+		*controller = (representor_id >> 14) & 3;
+	if (pf)
+		*pf = (representor_id >> 12) & 3;
+	if (type)
+		*type = ((representor_id >> 11) & 1) ?
+			RTE_ETH_REPRESENTOR_SF : RTE_ETH_REPRESENTOR_VF;
+	return representor_id & 0x7ff;
+}
+
 static int
 eth_dev_handle_port_list(const char *cmd __rte_unused,
 		const char *params __rte_unused,
lib/librte_ethdev/rte_ethdev_driver.h +53 -0

59 lines not on this page · raw message

lib/librte_ethdev/version.map +2 -0
index d3f5410806..44edaed507 100644
@@ -257,6 +257,8 @@ INTERNAL {
 	rte_eth_dev_release_port;
 	rte_eth_dev_internal_reset;
 	rte_eth_devargs_parse;
+	rte_eth_representor_id_encode;
+	rte_eth_representor_id_parse;
 	rte_eth_dma_zone_free;
 	rte_eth_dma_zone_reserve;
 	rte_eth_hairpin_queue_peer_bind;
Signature · 1 line
2.25.1
author
#105 lore raw

PATCH v5 9/9 kvargs: update parser to support lists

In reply to Xueming Li

This patch updates kvargs parser to support lists on top of range, allow multiple lists or range:
k1=a[1,2]b[3-5]

---
 app/test/test_kvargs.c         |  46 +++++++++++++--
 lib/librte_kvargs/rte_kvargs.c | 101 +++++++++++++++++++++++----------
 2 files changed, 112 insertions(+), 35 deletions(-)
app/test/test_kvargs.c +40 -6
index 2a2dae43a0..a91ea8dc47 100644
@@ -35,6 +35,25 @@ static int check_handler(const char *key, const char *value,
 	return 0;
 }
 
+/* test parsing. */
+static int test_kvargs_parsing(const char *args, unsigned int n)
+{
+	struct rte_kvargs *kvlist;
+
+	kvlist = rte_kvargs_parse(args, NULL);
+	if (kvlist == NULL) {
+		printf("rte_kvargs_parse() error: %s\n", args);
+		return -1;
+	}
+	if (kvlist->count != n) {
+		printf("invalid count value %d: %s\n", kvlist->count, args);
+		rte_kvargs_free(kvlist);
+		return -1;
+	}
+	rte_kvargs_free(kvlist);
+	return 0;
+}
+
 /* test a valid case */
 static int test_valid_kvargs(void)
 {
@@ -42,6 +61,19 @@ static int test_valid_kvargs(void)
 	const char *args;
 	const char *valid_keys_list[] = { "foo", "check", NULL };
 	const char **valid_keys;
+	static const struct {
+		unsigned int expected;
+		const char *input;
+	} valid_inputs[] = {
+		{ 2, "foo=1,foo=" },
+		{ 2, "foo=1,foo=" },
+		{ 2, "foo=1,foo" },
+		{ 2, "foo=1,=2" },
+		{ 1, "foo=[1,2" },
+		{ 1, ",=" },
+		{ 1, "foo=[" },
+	};
+	unsigned int i;
 
 	/* empty args is valid */
 	args = "";
@@ -191,6 +223,14 @@ static int test_valid_kvargs(void)
 	}
 	rte_kvargs_free(kvlist);
 
+	valid_keys = NULL;
+
+	for (i = 0; i < RTE_DIM(valid_inputs); ++i) {
+		args = valid_inputs[i].input;
+		if (test_kvargs_parsing(args, valid_inputs[i].expected))
+			goto fail;
+	}
+
 	return 0;
 
  fail:
@@ -212,12 +252,6 @@ static int test_invalid_kvargs(void)
 	/* list of argument that should fail */
 	const char *args_list[] = {
 		"wrong-key=x",     /* key not in valid_keys_list */
-		"foo=1,foo=",      /* empty value */
-		"foo=1,foo",       /* no value */
-		"foo=1,=2",        /* no key */
-		"foo=[1,2",        /* no closing bracket in value */
-		",=",              /* also test with a smiley */
-		"foo=[",           /* no value in list and no closing bracket */
 		NULL };
 	const char **args;
 	const char *valid_keys_list[] = { "foo", "check", NULL };
lib/librte_kvargs/rte_kvargs.c +72 -29

129 lines not on this page · raw message

Signature · 1 line
2.25.1
author
#91 lore raw

PATCH v5 6/9 ethdev: support multi-host in representor

In reply to Xueming Li

The NIC can have multiple PCIe links and can be attached to the multiple hosts, for example the same single NIC can be shared for multiple server units in the rack. On each PCIe link NIC can provide multiple PFs and VFs/SFs based on these ones. To provide the unambiguous identification of the PCIe function the controller index is added. The full representor identifier consists of three indices - controller index, PF index, and VF or SF index (if any).

This patch introduces controller index to ethdev representor syntax, examples:

[[c#]pf#]vf#: VF port representor/s, example: pf0vf1 [[c#]pf#]sf#: SF port representor/s, example: c1pf1sf[0-3]

c# is controller(host) ID/range in case of multi-host, optional.

For user application (e.g. OVS), PMD is responsible to interpret and locate representor device based on controller ID, PF ID and VF/SF ID in representor syntax.

---
 config/rte_config.h                   |  1 +
 lib/librte_ethdev/ethdev_private.c    | 12 ++++++++++--
 lib/librte_ethdev/rte_ethdev_driver.h |  4 ++++
 3 files changed, 15 insertions(+), 2 deletions(-)
config/rte_config.h +1 -0
index a0b5160ff2..23d02d51ef 100644
@@ -58,6 +58,7 @@
 #define RTE_MAX_QUEUES_PER_PORT 1024
 #define RTE_ETHDEV_QUEUE_STAT_CNTRS 16 /* max 256 */
 #define RTE_ETHDEV_RXTX_CALLBACKS 1
+#define RTE_MAX_MULTI_HOST_CTRLS 4
 
 /* cryptodev defines */
 #define RTE_CRYPTO_MAX_DEVS 64
lib/librte_ethdev/ethdev_private.c +10 -2
index b9fdbd0f72..9a0945c22e 100644
@@ -120,8 +120,8 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
  *
  * Representor format:
  *   #: range or single number of VF representor - legacy
- *   [pf#]vf#: VF port representor/s
- *   [pf#]sf#: SF port representor/s
+ *   [[c#]pf#]vf#: VF port representor/s
+ *   [[c#]pf#]sf#: SF port representor/s
  *
  * Examples of #:
  *  2               - single
@@ -133,6 +133,14 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 {
 	struct rte_eth_devargs *eth_da = data;
 
+	if (str[0] == 'c') {
+		str += 1;
+		str = rte_eth_devargs_process_list(str, eth_da->mh_controllers,
+				&eth_da->nb_mh_controllers,
+				RTE_DIM(eth_da->mh_controllers));
+		if (str == NULL)
+			goto err;
+	}
 	if (str[0] == 'p' && str[1] == 'f') {
 		eth_da->type = RTE_ETH_REPRESENTOR_PF;
 		str += 2;
lib/librte_ethdev/rte_ethdev_driver.h +4 -0
index cd33184f17..b01f118965 100644
@@ -1203,6 +1203,10 @@ enum rte_eth_representor_type {
 
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
+	uint16_t mh_controllers[RTE_MAX_MULTI_HOST_CTRLS];
+	/** controller/s number in case of multi-host */
+	uint16_t nb_mh_controllers;
+	/** number of controllers in multi-host controllers field */
 	uint16_t ports[RTE_MAX_ETHPORTS];
 	/** port/s number to enable on a multi-port single function */
 	uint16_t nb_ports;
Signature · 1 line
2.25.1
author
#101 lore raw

PATCH v5 8/9 ethdev: add capability of sub-function representor

In reply to Xueming Li

Old DPDK version or some drivers didn't support SubFunction representor. For application to adapt different DPDK version automatically, or to be used for different NICs, this patch introduces new eth device capability of supporting SubFunction representor device.

---
 lib/librte_ethdev/rte_ethdev.h | 2 ++
 1 file changed, 2 insertions(+)
lib/librte_ethdev/rte_ethdev.h +2 -0
index 2cbce958cf..da65adf1ab 100644
@@ -1433,6 +1433,8 @@ struct rte_eth_conf {
 #define RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP 0x00000001
 /** Device supports Tx queue setup after device started. */
 #define RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP 0x00000002
+/** Device supports SubFunction representor. */
+#define RTE_ETH_DEV_CAPA_REPRESENTOR_SF         0x00000004
 /**@}*/
 
 /*
Signature · 1 line
2.25.1
Acked-by on v4 1/9
#41 lore raw

Re: [dpdk-dev] [PATCH v4 1/9] ethdev: introduce representor type

In reply to Xueming Li
Quoted 5 lines · Xueming Li

To support more representor type, this patch introduces representor type enum. The enum is subject to extend for new types upcoming.

One nit below and a question below.

In any case:

[snip]

Quoted 5 lines
lib/librte_ethdev/rte_ethdev_driver.h +0 -0
index 0eacfd8425..3bc5c5bbbb 100644

lib/librte_ethdev/rte_ethdev_driver.h __rte_internal · line 1201

Quoted 9 lines
lib/librte_ethdev/rte_ethdev_driver.h +6 -0
@@ -1193,6 +1193,14 @@ __rte_internal
 int
 rte_eth_switch_domain_free(uint16_t domain_id);
 
+/** Ethernet device representor type */
+enum rte_eth_representor_type {
+	RTE_ETH_REPRESENTOR_NONE, /**< not a representor. */
+	RTE_ETH_REPRESENTOR_VF,   /**< representor of VF. */
+	RTE_ETH_REPRESENTOR_SF,   /**< representor of SF. */
+	RTE_ETH_REPRESENTOR_PF,   /**< representor of host PF. */

RTE_ETH_REPRESENTOR_SF and PF looks dead in the patch. IMHO, addition of these members here make future patches which add support inconsistent.

lib/librte_ethdev/rte_ethdev_driver.h struct rte_eth_devargs { · line 1214

Quoted 10 lines
lib/librte_ethdev/rte_ethdev_driver.h +3 -0
+};
+
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
 	uint16_t ports[RTE_MAX_ETHPORTS];
@@ -1203,6 +1211,7 @@ struct rte_eth_devargs {
 	/** representor port/s identifier to enable on device */
 	uint16_t nb_representor_ports;
 	/** number of ports in representor port field */
+	enum rte_eth_representor_type type; /* type of representor */

Is it intended and documented limitation that we can't add different type representors in one request? Or am I missing something and it is possible?

Quoted 4 lines
lib/librte_ethdev/rte_ethdev_driver.h +0 -0
 };
 
 /**
#95 lore raw

Re: [dpdk-dev] [PATCH v5 7/9] devarg: change representor ID to bitmap

In reply to Xueming Li
Quoted 79 lines

-----Original Message-----
From: Xueming Li <[email protected]>
Sent: Tuesday, January 19, 2021 15:15
Cc: [email protected]; Viacheslav Ovsiienko <[email protected]>; [email protected]; Asaf Penso <[email protected]>; Ajit Khaparde <[email protected]>; Somnath Kotur <[email protected]>; Daley, John <[email protected]>; Hyong Youb Kim <[email protected]>; Xing, Beilei <[email protected]>; Guo, Jia <[email protected]>; Wang, Haiyue <[email protected]>; Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; Thomas Monjalon <[email protected]>; Yigit, Ferruh <[email protected]>; Andrew Rybchenko <[email protected]>; Ray Kinsella <[email protected]>; Neil Horman <[email protected]>
Subject: [PATCH v5 7/9] devarg: change representor ID to bitmap

The NIC can have multiple PCIe links and can be attached to multiple hosts, for example the same single NIC can be shared for multiple server units in the rack. On each PCIe link NIC can provide multiple PFs and VFs/SFs based on these ones. The full representor identifier consists of three indices - controller index, PF index, and VF or SF index (if any).

SR-IOV and SubFunction are created on top of PF. PF index is introduced because there might be multiple PFs in the bonding configuration and only bonding device is probed.

In eth representor comparator callback, ethdev was compared with devarg. Since ethdev representor port didn't contain controller index and PF index information, callback returned representor from other PF or controller.

This patch changes representor ID to bitmap so that the ethdev representor comparer callback returns correct ethdev by comparing full representor information including: controller index, PF index, representor type, SF or VF index.

Representor ID bitmap definition:
xxxx xxxx xxxx xxxx

 |||| |LLL LLLL LLLL vf/sf id
 |||| L 1:sf, 0:vf
 ||LL pf id

LL controller(host) id

This approach keeps binary compatibility with all drivers, VF representor id matches with simple id for non-bonding and non-multi-host configurations.

In the future, the representor ID field and each section should extend to bigger width to support more devices.

---
 drivers/net/bnxt/bnxt_reps.c             |  3 +-
 drivers/net/enic/enic_vf_representor.c   |  3 +-
 drivers/net/i40e/i40e_vf_representor.c   |  3 +-
 drivers/net/ixgbe/ixgbe_vf_representor.c |  3 +-
 drivers/net/mlx5/linux/mlx5_os.c         |  4 +-
 lib/librte_ethdev/rte_class_eth.c        | 38 +++++++++++++----
 lib/librte_ethdev/rte_ethdev.c           | 26 ++++++++++++
 lib/librte_ethdev/rte_ethdev_driver.h    | 53 ++++++++++++++++++++++++
 lib/librte_ethdev/version.map            |  2 +
 9 files changed, 122 insertions(+), 13 deletions(-)
lib/librte_ethdev/rte_ethdev.c +16 -0
+uint16_t
+rte_eth_representor_id_encode(uint16_t controller, uint16_t pf,
+			      enum rte_eth_representor_type type,
+			      uint16_t representor_port)
+{
+	return (((controller & 3) << 14) |
+		((pf & 3) << 12) |
+		(!!(type == RTE_ETH_REPRESENTOR_SF) << 11) |
+		(representor_port & 0x7ff));
+}
+
+uint16_t
+rte_eth_representor_id_parse(const uint16_t representor_id,
+			     uint16_t *controller, uint16_t *pf,
+			     enum rte_eth_representor_type *type)
+{

lib/librte_ethdev/rte_ethdev.c rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da) · line 5603

Quoted 10 lines
lib/librte_ethdev/rte_ethdev.c +10 -0
+	if (controller)
+		*controller = (representor_id >> 14) & 3;
+	if (pf)
+		*pf = (representor_id >> 12) & 3;
+	if (type)
+		*type = ((representor_id >> 11) & 1) ?
+			RTE_ETH_REPRESENTOR_SF : RTE_ETH_REPRESENTOR_VF;
+	return representor_id & 0x7ff;
+}
+

Rename 'parse' to 'decode' ? Since not parse from string. ;-) The these two functions are pair style.

rte_eth_representor_id_encode / rte_eth_representor_id_decode ?

Quoted 1 line

2.25.1

#42 lore raw

Re: [dpdk-dev] [PATCH v4 1/9] ethdev: introduce representor type

In reply to Andrew Rybchenko

Hi Andrew,

Quoted 34 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 3:25 PM
To: Xueming(Steven) Li <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Olivier Matz <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [PATCH v4 1/9] ethdev: introduce representor type

Quoted 5 lines · Xueming Li

To support more representor type, this patch introduces representor type enum. The enum is subject to extend for new types upcoming.

One nit below and a question below.

In any case:

[snip]

Quoted 9 lines
lib/librte_ethdev/rte_ethdev_driver.h +0 -0
index 0eacfd8425..3bc5c5bbbb 100644
@@ -1193,6 +1193,14 @@ __rte_internal
 int
 rte_eth_switch_domain_free(uint16_t domain_id);
 
Quoted 10 lines

lib/librte_ethdev/rte_ethdev_driver.h __rte_internal · line 1201

Quoted 6 lines
lib/librte_ethdev/rte_ethdev_driver.h +6 -0
+/** Ethernet device representor type */ enum rte_eth_representor_type
+{
+	RTE_ETH_REPRESENTOR_NONE, /**< not a representor. */
+	RTE_ETH_REPRESENTOR_VF,   /**< representor of VF. */
+	RTE_ETH_REPRESENTOR_SF,   /**< representor of SF. */
+	RTE_ETH_REPRESENTOR_PF,   /**< representor of host PF. */

RTE_ETH_REPRESENTOR_SF and PF looks dead in the patch. IMHO, addition of these members here make future patches which add support inconsistent.

Yes, later patch in this patchset will support it.

Quoted 13 lines

lib/librte_ethdev/rte_ethdev_driver.h struct rte_eth_devargs { · line 1214

Quoted 10 lines
lib/librte_ethdev/rte_ethdev_driver.h +3 -0
+};
+
 /** Generic Ethernet device arguments  */  struct rte_eth_devargs {
 	uint16_t ports[RTE_MAX_ETHPORTS];
@@ -1203,6 +1211,7 @@ struct rte_eth_devargs {
 	/** representor port/s identifier to enable on device */
 	uint16_t nb_representor_ports;
 	/** number of ports in representor port field */
+	enum rte_eth_representor_type type; /* type of representor */

Is it intended and documented limitation that we can't add different type representors in one request? Or am I missing something and it is possible?

Correct, current devargs structure can't support mix of different types. I'll update in next version if any.

Quoted 5 lines
Quoted 5 lines
lib/librte_ethdev/rte_ethdev_driver.h +0 -0
 };
 
 /**
Acked-by
#40 lore raw

Re: [dpdk-dev] [PATCH v4 1/9] ethdev: introduce representor type

In reply to Xueming(Steven) Li
Quoted 34 lines · Xueming(Steven) Li
Quoted 34 lines

-----Original Message-----
From: Ajit Khaparde <[email protected]>
Sent: Tuesday, January 19, 2021 2:18 AM
To: NBU-Contact-Thomas Monjalon <[email protected]>
Cc: Xueming(Steven) Li <[email protected]>; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>; Olivier Matz <[email protected]>; dpdk-dev <[email protected]>; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v4 1/9] ethdev: introduce representor type

Quoted 3 lines · Thomas Monjalon

18/01/2021 19:00, Ajit Khaparde:

Quoted 1 line

On Mon, Jan 18, 2021 at 9:57 AM Thomas Monjalon

Quoted 2 lines · <[email protected]> wrote:
Quoted 2 lines
Quoted 2 lines

18/01/2021 18:42, Ajit Khaparde:

Quoted 1 line

On Mon, Jan 18, 2021 at 3:17 AM Xueming Li <[email protected]>

Quoted 6 lines · wrote:
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+enum rte_eth_representor_type {
+       RTE_ETH_REPRESENTOR_NONE, /**< not a representor. */
+       RTE_ETH_REPRESENTOR_VF,   /**< representor of VF. */
+       RTE_ETH_REPRESENTOR_SF,   /**< representor of SF. */

Till we get used to the terminology...
Can we also have SF = "Sub Function" mentioned in the docs or

comments?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Are we sure about the definition?
I remember seeing SF = Scalable Function somewhere else (maybe from

Intel)

Quoted 2 lines
Quoted 1 line

That complicates it. But if they mean the same thing, let's pick one.

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

I think "Sub Function" and "Virtual Function" are easy to understand for everybody.
I suggest picking these two for comments above.

+1

There was an internal discussion and the conclusion is to align with kernel driver name. Will update comment in next version, thanks!

Ok. In that case for the series:

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
#49 lore raw

Re: [dpdk-dev] [PATCH v4 2/9] ethdev: support representor port list

In reply to Xueming Li
Quoted 8 lines · Xueming Li

To support extended representor syntax, this patch extends the representor list parsing to support for representor port range in devargs, examples:
representor=[1,2,3] - single list
representor=[1,3-5,7,9-11] - list with singles and ranges

See below

Quoted 55 lines
---
 lib/librte_ethdev/ethdev_private.c | 105 ++++++++++++++---------------
 lib/librte_ethdev/ethdev_private.h |   3 -
 lib/librte_ethdev/rte_class_eth.c  |   4 +-
 lib/librte_ethdev/rte_ethdev.c     |   5 +-
 4 files changed, 54 insertions(+), 63 deletions(-)
lib/librte_ethdev/ethdev_private.c +4 -34
index c1a411dba4..12bcc7e98d 100644
@@ -38,77 +38,71 @@ eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp,
 	return NULL;
 }
 
-int
-rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
-	void *data)
+static int
+rte_eth_devargs_enlist(uint16_t *list, uint16_t *len_list,
+		       const uint16_t max_list, uint16_t val)
 {
-	char *str_start;
-	int state;
-	int result;
-
-	if (*str != '[')
-		/* Single element, not a list */
-		return callback(str, data);
-
-	/* Sanity check, then strip the brackets */
-	str_start = &str[strlen(str) - 1];
-	if (*str_start != ']') {
-		RTE_LOG(ERR, EAL, "(%s): List does not end with ']'\n", str);
-		return -EINVAL;
-	}
-	str++;
-	*str_start = '\0';
+	uint16_t i;
 
-	/* Process list elements */
-	state = 0;
-	while (1) {
-		if (state == 0) {
-			if (*str == '\0')
-				break;
-			if (*str != ',') {
-				str_start = str;
-				state = 1;
-			}
-		} else if (state == 1) {
-			if (*str == ',' || *str == '\0') {
-				if (str > str_start) {
-					/* Non-empty string fragment */
-					*str = '\0';

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, · line 48

Quoted 10 lines
lib/librte_ethdev/ethdev_private.c +2 -8
-					result = callback(str_start, data);
-					if (result < 0)
-						return result;
-				}
-				state = 0;
-			}
-		}
-		str++;
+	if (*len_list >= max_list)
+		return -1;

If current length is equal to max, but added value is already is in the list, it should not be an error. So, these two lines should be moved after below for loop.

Quoted 16 lines
lib/librte_ethdev/ethdev_private.c +6 -1
+	for (i = 0; i < *len_list; i++) {
+		if (list[i] == val)
+			return 0;
 	}
+	list[(*len_list)++] = val;
 	return 0;
 }
 
-static int
+static char *
 rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
 	const uint16_t max_list)
 {
 	uint16_t lo, hi, val;
 	int result;
+	char *pos = str;

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, · line 102

Quoted 10 lines
lib/librte_ethdev/ethdev_private.c +2 -4
 
 	result = sscanf(str, "%hu-%hu", &lo, &hi);
 	if (result == 1) {
-		if (*len_list >= max_list)
-			return -ENOMEM;
-		list[(*len_list)++] = lo;
+		if (rte_eth_devargs_enlist(list, len_list, max_list, lo) != 0)
+			return NULL;
 	} else if (result == 2) {
-		if (lo >= hi || lo > RTE_MAX_ETHPORTS || hi > RTE_MAX_ETHPORTS)

Strictly speaking removal of comparision vs RTE_MAX_ETHPORTS is a separate logical change with a separate motivation.

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, · line 70

Quoted 2 lines
lib/librte_ethdev/ethdev_private.c +1 -1
-			return -EINVAL;
+		if (lo >= hi)

I'd remove '=' here. It should not be a problem and handed perfectly by below code. I see no point to deny 3-3 range which is an equivalent for just 3. It could be convenient in some cases.

Quoted 4 lines
lib/librte_ethdev/ethdev_private.c +1 -2
+			return NULL;
 		for (val = lo; val <= hi; val++) {
-			if (*len_list >= max_list)
-				return -ENOMEM;

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, · line 79

Quoted 10 lines
lib/librte_ethdev/ethdev_private.c +5 -3
-			list[(*len_list)++] = val;
+			if (rte_eth_devargs_enlist(list, len_list, max_list,
+						   val) != 0)
+				return NULL;
 		}
 	} else
-		return -EINVAL;
-	return 0;
+		return NULL;
+	while (*pos != 0 && ((*pos >= '0' && *pos <= '9') || *pos == '-'))

*post != '\0' is a bit better looking at subsequent comparisons. Yes, it is just style. Up to you.

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, · line 80

Quoted 1 line
lib/librte_ethdev/ethdev_private.c +1 -0
+		pos++;

It looks too fragile. May I suggest to use %n in above scanf to be able to skip only parsed characters.

Quoted 29 lines
lib/librte_ethdev/ethdev_private.c +25 -0
+	return pos;
+}
+
+static char *
+rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
+	const uint16_t max_list)
+{
+	char *pos = str;
+
+	if (*pos == '[')
+		pos++;
+	while (1) {
+		pos = rte_eth_devargs_process_range(pos, list, len_list,
+						    max_list);
+		if (pos == NULL)
+			return NULL;
+		if (*pos != ',') /* end of list */
+			break;
+		pos++;
+	}
+	if (*str == '[' && *pos != ']')
+		return NULL;
+	if (*pos == ']')
+		pos++;
+	return pos;
 }
 
 /*

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 119

Quoted 6 lines
lib/librte_ethdev/ethdev_private.c +1 -1
@@ -121,6 +115,9 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	struct rte_eth_devargs *eth_da = data;
 
 	eth_da->type = RTE_ETH_REPRESENTOR_VF;
-	return rte_eth_devargs_process_range(str, eth_da->representor_ports,
+	str = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);

Not directly related to the patch, but I dislike
RTE_MAX_ETHPORTS above.
RTE_DIM(eth_da->representor_ports) would be more
readable.

Quoted 4 lines
lib/librte_ethdev/ethdev_private.c +3 -0
+	if (str == NULL)
+		RTE_LOG(ERR, EAL, "wrong representor format: %s\n", str);
+	return str == NULL ? -1 : 0;
 }

[snip]

#80 lore raw

Re: [dpdk-dev] [PATCH v5 2/9] ethdev: support representor port list

In reply to Xueming Li
Quoted 9 lines · Xueming Li

To support extended representor syntax, this patch extends the representor list parsing to support for representor port range in devargs, examples:
representor=[1,2,3] - single list
representor=[1,3-5,7,9-11] - list with singles and ranges

It looks like my comments to the previous version are all applicable here. Sorry, I should review this one from the very beginning.

#43 lore raw

Re: [dpdk-dev] [PATCH v4 1/9] ethdev: introduce representor type

In reply to Xueming(Steven) Li
Quoted 47 lines · Xueming(Steven) Li

Hi Andrew,

Quoted 34 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 3:25 PM
To: Xueming(Steven) Li <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Olivier Matz <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [PATCH v4 1/9] ethdev: introduce representor type

Quoted 5 lines · Xueming Li

To support more representor type, this patch introduces representor type enum. The enum is subject to extend for new types upcoming.

One nit below and a question below.

In any case:

[snip]

Quoted 9 lines
lib/librte_ethdev/rte_ethdev_driver.h +0 -0
index 0eacfd8425..3bc5c5bbbb 100644
@@ -1193,6 +1193,14 @@ __rte_internal
 int
 rte_eth_switch_domain_free(uint16_t domain_id);
 
Quoted 10 lines

lib/librte_ethdev/rte_ethdev_driver.h __rte_internal · line 1201

Quoted 6 lines
lib/librte_ethdev/rte_ethdev_driver.h +6 -0
+/** Ethernet device representor type */ enum rte_eth_representor_type
+{
+	RTE_ETH_REPRESENTOR_NONE, /**< not a representor. */
+	RTE_ETH_REPRESENTOR_VF,   /**< representor of VF. */
+	RTE_ETH_REPRESENTOR_SF,   /**< representor of SF. */
+	RTE_ETH_REPRESENTOR_PF,   /**< representor of host PF. */

RTE_ETH_REPRESENTOR_SF and PF looks dead in the patch. IMHO, addition of these members here make future patches which add support inconsistent.

Quoted 1 line

Yes, later patch in this patchset will support it.

I know. The question is why it is not added in the later patches when these types are actually supported.

Quoted 22 lines
Quoted 13 lines

lib/librte_ethdev/rte_ethdev_driver.h struct rte_eth_devargs { · line 1214

Quoted 10 lines
lib/librte_ethdev/rte_ethdev_driver.h +3 -0
+};
+
 /** Generic Ethernet device arguments  */  struct rte_eth_devargs {
 	uint16_t ports[RTE_MAX_ETHPORTS];
@@ -1203,6 +1211,7 @@ struct rte_eth_devargs {
 	/** representor port/s identifier to enable on device */
 	uint16_t nb_representor_ports;
 	/** number of ports in representor port field */
+	enum rte_eth_representor_type type; /* type of representor */

Is it intended and documented limitation that we can't add different type representors in one request? Or am I missing something and it is possible?

Correct, current devargs structure can't support mix of different types. I'll update in next version if any.

Quoted 5 lines
Quoted 5 lines
lib/librte_ethdev/rte_ethdev_driver.h +0 -0
 };
 
 /**
Acked-by on v5 3/9
#83 lore raw

Re: [dpdk-dev] [PATCH v5 3/9] ethdev: support new VF representor syntax

In reply to Xueming Li
Quoted 13 lines · Xueming Li

Current VF representor syntax:
representor=2 - single representor
representor=[0-3] - single range

To prepare for more representor types, this patch adds compatible VF representor devargs syntax:

vf#:

 representor=vf2          - single representor
 representor=vf[1,3,5]    - single list
 representor=vf[0-3]      - single range
 representor=vf[0,1,4-7]  - list with singles and range
Quoted 5 lines

For backwards compatibility, representor "#" is interpreted as "vf#".

Acked-by on v5 4/9
#85 lore raw

Re: [dpdk-dev] [PATCH v5 4/9] ethdev: support sub function representor

In reply to Xueming Li
Quoted 7 lines · Xueming Li

SubFunction is a portion of the PCI device, created on demand, a SF netdev has its own dedicated queues(txq, rxq). A SF netdev supports eswitch representation offload similar to existing PF and VF representors.

To support SF representor, this patch introduces new devargs syntax, examples:

Quoted 8 lines
 representor=sf0               - single SubFunction representor
 representor=sf[1,3,5]         - single list
 representor=sf[0-3],          - single range

representor=sf[0,2-6,8,10-12] - list with singles and ranges

#44 lore raw

Re: [dpdk-dev] [PATCH v4 1/9] ethdev: introduce representor type

In reply to Andrew Rybchenko
Quoted 59 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 3:49 PM
To: Xueming(Steven) Li <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Olivier Matz <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [PATCH v4 1/9] ethdev: introduce representor type

Quoted 46 lines · Xueming(Steven) Li

Hi Andrew,

Quoted 43 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 3:25 PM
To: Xueming(Steven) Li <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Olivier Matz <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [PATCH v4 1/9] ethdev: introduce representor type

Quoted 5 lines · Xueming Li

To support more representor type, this patch introduces representor type enum. The enum is subject to extend for new types upcoming.

One nit below and a question below.

In any case:

[snip]

Quoted 6 lines
lib/librte_ethdev/rte_ethdev_driver.h +0 -0
index 0eacfd8425..3bc5c5bbbb 100644

lib/librte_ethdev/rte_ethdev_driver.h __rte_internal int · line 1200

Quoted 8 lines
lib/librte_ethdev/rte_ethdev_driver.h +6 -0
@@ -1193,6 +1193,14 @@ __rte_internal  int
 rte_eth_switch_domain_free(uint16_t domain_id);
 
+/** Ethernet device representor type */ enum
+rte_eth_representor_type {
+	RTE_ETH_REPRESENTOR_NONE, /**< not a representor. */
+	RTE_ETH_REPRESENTOR_VF,   /**< representor of VF. */
+	RTE_ETH_REPRESENTOR_SF,   /**< representor of SF. */
+	RTE_ETH_REPRESENTOR_PF,   /**< representor of host PF. */

RTE_ETH_REPRESENTOR_SF and PF looks dead in the patch. IMHO, addition of these members here make future patches which add support inconsistent.

Quoted 5 lines
Quoted 1 line

Yes, later patch in this patchset will support it.

I know. The question is why it is not added in the later patches when these types are actually supported.

Good suggestion, will update

Quoted 24 lines
Quoted 14 lines
Quoted 14 lines

lib/librte_ethdev/rte_ethdev_driver.h struct rte_eth_devargs { · line 1214

Quoted 11 lines
lib/librte_ethdev/rte_ethdev_driver.h +3 -0
+};
+
 /** Generic Ethernet device arguments  */  struct rte_eth_devargs {
 	uint16_t ports[RTE_MAX_ETHPORTS];
@@ -1203,6 +1211,7 @@ struct rte_eth_devargs {
 	/** representor port/s identifier to enable on device */
 	uint16_t nb_representor_ports;
 	/** number of ports in representor port field */
+	enum rte_eth_representor_type type; /* type of representor */

Is it intended and documented limitation that we can't add different type representors in one request? Or am I missing something and it is

possible?

Quoted 9 lines

Correct, current devargs structure can't support mix of different types. I'll update in next version if any.

Quoted 5 lines
Quoted 5 lines
lib/librte_ethdev/rte_ethdev_driver.h +0 -0
 };
 
 /**
#87 lore raw

Re: [dpdk-dev] [PATCH v5 5/9] ethdev: support PF index in representor

In reply to Xueming Li
Quoted 8 lines · Xueming Li

With Kernel bonding, multiple underlying PFs are bonded, VFs come from different PF, need to identify representor of VFs unambiguously by adding PF index.

This patch introduces optional 'pf' section to representor devargs syntax, examples:
representor=pf0vf0 - single VF representor
representor=pf[0-1]sf[0-1023] - SF representors from 2 PFs

Don't we need
representor=pf3
i.e. without VF or sub-function?

Quoted 39 lines
---
 doc/guides/prog_guide/poll_mode_drv.rst |  2 ++
 lib/librte_ethdev/ethdev_private.c      | 13 +++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
doc/guides/prog_guide/poll_mode_drv.rst +2 -0
index 86e5867f1b..b2147aad30 100644
@@ -382,6 +382,8 @@ parameters to those ports.
    -a DBDF,representor=sf[1,3,5]
    -a DBDF,representor=sf[0-1023]
    -a DBDF,representor=sf[0,2-4,7,9-11]
+   -a DBDF,representor=pf1vf0
+   -a DBDF,representor=pf[0-1]sf[0-127]
 
 Note: PMDs are not required to support the standard device arguments and users
 should consult the relevant PMD documentation to see support devargs.
lib/librte_ethdev/ethdev_private.c +2 -2
index d513f035d0..b9fdbd0f72 100644
@@ -120,8 +120,8 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
  *
  * Representor format:
  *   #: range or single number of VF representor - legacy
- *   vf#: VF port representor/s
- *   sf#: SF port representor/s
+ *   [pf#]vf#: VF port representor/s
+ *   [pf#]sf#: SF port representor/s
  *
  * Examples of #:
  *  2               - single

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 140

Quoted 8 lines
lib/librte_ethdev/ethdev_private.c +5 -0
@@ -133,6 +133,14 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 {
 	struct rte_eth_devargs *eth_da = data;
 
+	if (str[0] == 'p' && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_PF;
+		str += 2;
+		str = rte_eth_devargs_process_list(str, eth_da->ports,
+				&eth_da->nb_ports, RTE_MAX_ETHPORTS);

May be RTE_MAX_ETHPORTS -> RTE_DIM(eth_da->ports) ?

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 142

Quoted 2 lines
lib/librte_ethdev/ethdev_private.c +2 -0
+		if (str == NULL)
+			goto err;

Below we should not allow legacy VF syntax without "vf" prefix.

Quoted 13 lines
lib/librte_ethdev/ethdev_private.c +2 -0
+	}
 	if (str[0] == 'v' && str[1] == 'f') {
 		eth_da->type = RTE_ETH_REPRESENTOR_VF;
 		str += 2;
@@ -144,6 +152,7 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 	}
 	str = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
+err:
 	if (str == NULL)
 		RTE_LOG(ERR, EAL, "wrong representor format: %s\n", str);
 	return str == NULL ? -1 : 0;
#92 lore raw

Re: [dpdk-dev] [PATCH v5 6/9] ethdev: support multi-host in representor

In reply to Xueming Li
Quoted 57 lines · Xueming Li

The NIC can have multiple PCIe links and can be attached to the multiple hosts, for example the same single NIC can be shared for multiple server units in the rack. On each PCIe link NIC can provide multiple PFs and VFs/SFs based on these ones. To provide the unambiguous identification of the PCIe function the controller index is added. The full representor identifier consists of three indices - controller index, PF index, and VF or SF index (if any).

This patch introduces controller index to ethdev representor syntax, examples:

[[c#]pf#]vf#: VF port representor/s, example: pf0vf1 [[c#]pf#]sf#: SF port representor/s, example: c1pf1sf[0-3]

c# is controller(host) ID/range in case of multi-host, optional.

For user application (e.g. OVS), PMD is responsible to interpret and locate representor device based on controller ID, PF ID and VF/SF ID in representor syntax.

---
 config/rte_config.h                   |  1 +
 lib/librte_ethdev/ethdev_private.c    | 12 ++++++++++--
 lib/librte_ethdev/rte_ethdev_driver.h |  4 ++++
 3 files changed, 15 insertions(+), 2 deletions(-)
config/rte_config.h +1 -0
index a0b5160ff2..23d02d51ef 100644
@@ -58,6 +58,7 @@
 #define RTE_MAX_QUEUES_PER_PORT 1024
 #define RTE_ETHDEV_QUEUE_STAT_CNTRS 16 /* max 256 */
 #define RTE_ETHDEV_RXTX_CALLBACKS 1
+#define RTE_MAX_MULTI_HOST_CTRLS 4
 
 /* cryptodev defines */
 #define RTE_CRYPTO_MAX_DEVS 64
lib/librte_ethdev/ethdev_private.c +2 -2
index b9fdbd0f72..9a0945c22e 100644
@@ -120,8 +120,8 @@ rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
  *
  * Representor format:
  *   #: range or single number of VF representor - legacy
- *   [pf#]vf#: VF port representor/s
- *   [pf#]sf#: SF port representor/s
+ *   [[c#]pf#]vf#: VF port representor/s
+ *   [[c#]pf#]sf#: SF port representor/s
  *
  * Examples of #:
  *  2               - single

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 142

Quoted 10 lines
lib/librte_ethdev/ethdev_private.c +7 -0
@@ -133,6 +133,14 @@ rte_eth_devargs_parse_representor_ports(char *str, void *data)
 {
 	struct rte_eth_devargs *eth_da = data;
 
+	if (str[0] == 'c') {
+		str += 1;
+		str = rte_eth_devargs_process_list(str, eth_da->mh_controllers,
+				&eth_da->nb_mh_controllers,
+				RTE_DIM(eth_da->mh_controllers));
+		if (str == NULL)
+			goto err;

The parser must enforce pf to follow. I.e. should not allow c1vf3. At least above syntax description in comments says so.

Quoted 20 lines
lib/librte_ethdev/ethdev_private.c +1 -0
+	}
 	if (str[0] == 'p' && str[1] == 'f') {
 		eth_da->type = RTE_ETH_REPRESENTOR_PF;
 		str += 2;
lib/librte_ethdev/rte_ethdev_driver.h +4 -0
index cd33184f17..b01f118965 100644
@@ -1203,6 +1203,10 @@ enum rte_eth_representor_type {
 
 /** Generic Ethernet device arguments  */
 struct rte_eth_devargs {
+	uint16_t mh_controllers[RTE_MAX_MULTI_HOST_CTRLS];
+	/** controller/s number in case of multi-host */
+	uint16_t nb_mh_controllers;
+	/** number of controllers in multi-host controllers field */
 	uint16_t ports[RTE_MAX_ETHPORTS];
 	/** port/s number to enable on a multi-port single function */
 	uint16_t nb_ports;
#102 lore raw

Re: [dpdk-dev] [PATCH v5 8/9] ethdev: add capability of sub-function representor

In reply to Xueming Li
Quoted 4 lines · Xueming Li

Old DPDK version or some drivers didn't support SubFunction representor. For application to adapt different DPDK version automatically, or to be used for different NICs, this patch introduces new eth device capability of supporting SubFunction representor device.

Sorry, it does not sound sufficient motivation to introduce the capability. I simply need real life example why application need to know it.

Quoted 12 lines
---
 lib/librte_ethdev/rte_ethdev.h | 2 ++
 1 file changed, 2 insertions(+)
lib/librte_ethdev/rte_ethdev.h +0 -0
index 2cbce958cf..da65adf1ab 100644

lib/librte_ethdev/rte_ethdev.h struct rte_eth_conf { · line 1437

Quoted 5 lines
lib/librte_ethdev/rte_ethdev.h +2 -0
@@ -1433,6 +1433,8 @@ struct rte_eth_conf {
 #define RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP 0x00000001
 /** Device supports Tx queue setup after device started. */
 #define RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP 0x00000002
+/** Device supports SubFunction representor. */
+#define RTE_ETH_DEV_CAPA_REPRESENTOR_SF         0x00000004

Will we have a PMD which supports it in the release cycle?

Quoted 3 lines
lib/librte_ethdev/rte_ethdev.h +0 -0
 /**@}*/
 
 /*
#96 lore raw

Re: [dpdk-dev] [PATCH v5 7/9] devarg: change representor ID to bitmap

In reply to Wang, Haiyue

Hi Haiyue,

Quoted 108 lines

-----Original Message-----
From: Wang, Haiyue <[email protected]>
Sent: Tuesday, January 19, 2021 3:37 PM
To: Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>; Ajit Khaparde <[email protected]>; Somnath Kotur <[email protected]>; Daley, John <[email protected]>; Hyong Youb Kim <[email protected]>; Xing, Beilei <[email protected]>; Guo, Jia <[email protected]>; Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; NBU-Contact- Thomas Monjalon <[email protected]>; Yigit, Ferruh <[email protected]>; Andrew Rybchenko <[email protected]>; Ray Kinsella <[email protected]>; Neil Horman <[email protected]>
Subject: RE: [PATCH v5 7/9] devarg: change representor ID to bitmap

Quoted 7 lines

-----Original Message-----
From: Xueming Li <[email protected]>
Sent: Tuesday, January 19, 2021 15:15
Cc: [email protected]; Viacheslav Ovsiienko <[email protected]>; [email protected]; Asaf Penso <[email protected]>; Ajit Khaparde <[email protected]>; Somnath Kotur <[email protected]>; Daley, John <[email protected]>;

Hyong

Quoted 9 lines

Youb Kim <[email protected]>; Xing, Beilei <[email protected]>; Guo, Jia <[email protected]>; Wang, Haiyue <[email protected]>; Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; Thomas Monjalon <[email protected]>; Yigit, Ferruh <[email protected]>; Andrew Rybchenko <[email protected]>; Ray Kinsella <[email protected]>; Neil Horman <[email protected]>
Subject: [PATCH v5 7/9] devarg: change representor ID to bitmap

Quoted 5 lines

The NIC can have multiple PCIe links and can be attached to multiple hosts, for example the same single NIC can be shared for multiple server units in the rack. On each PCIe link NIC can provide multiple PFs and VFs/SFs based on these ones. The full representor identifier consists of three indices - controller index, PF index, and VF or SF index (if

any).

Quoted 58 lines

SR-IOV and SubFunction are created on top of PF. PF index is introduced because there might be multiple PFs in the bonding configuration and only bonding device is probed.

In eth representor comparator callback, ethdev was compared with devarg. Since ethdev representor port didn't contain controller index and PF index information, callback returned representor from other PF or controller.

This patch changes representor ID to bitmap so that the ethdev representor comparer callback returns correct ethdev by comparing full representor information including: controller index, PF index, representor type, SF or VF index.

Representor ID bitmap definition:
xxxx xxxx xxxx xxxx

 |||| |LLL LLLL LLLL vf/sf id
 |||| L 1:sf, 0:vf
 ||LL pf id

LL controller(host) id

This approach keeps binary compatibility with all drivers, VF representor id matches with simple id for non-bonding and non-multi-host configurations.

In the future, the representor ID field and each section should extend to bigger width to support more devices.

---
 drivers/net/bnxt/bnxt_reps.c             |  3 +-
 drivers/net/enic/enic_vf_representor.c   |  3 +-
 drivers/net/i40e/i40e_vf_representor.c   |  3 +-
 drivers/net/ixgbe/ixgbe_vf_representor.c |  3 +-
 drivers/net/mlx5/linux/mlx5_os.c         |  4 +-
 lib/librte_ethdev/rte_class_eth.c        | 38 +++++++++++++----
 lib/librte_ethdev/rte_ethdev.c           | 26 ++++++++++++
 lib/librte_ethdev/rte_ethdev_driver.h    | 53 ++++++++++++++++++++++++
 lib/librte_ethdev/version.map            |  2 +
 9 files changed, 122 insertions(+), 13 deletions(-)
lib/librte_ethdev/rte_ethdev.c +12 -0
+uint16_t
+rte_eth_representor_id_encode(uint16_t controller, uint16_t pf,
+			      enum rte_eth_representor_type type,
+			      uint16_t representor_port)
+{
+	return (((controller & 3) << 14) |
+		((pf & 3) << 12) |
+		(!!(type == RTE_ETH_REPRESENTOR_SF) << 11) |
+		(representor_port & 0x7ff));
+}
+
+uint16_t

lib/librte_ethdev/rte_ethdev.c rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)

Quoted 10 lines
lib/librte_ethdev/rte_ethdev.c +10 -0
+rte_eth_representor_id_parse(const uint16_t representor_id,
+			     uint16_t *controller, uint16_t *pf,
+			     enum rte_eth_representor_type *type) {
+	if (controller)
+		*controller = (representor_id >> 14) & 3;
+	if (pf)
+		*pf = (representor_id >> 12) & 3;
+	if (type)
+		*type = ((representor_id >> 11) & 1) ?
+			RTE_ETH_REPRESENTOR_SF :

RTE_ETH_REPRESENTOR_VF;

Quoted 8 lines

lib/librte_ethdev/rte_ethdev.c rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da) · line 5603

Quoted 3 lines
lib/librte_ethdev/rte_ethdev.c +3 -0
+	return representor_id & 0x7ff;
+}
+

Rename 'parse' to 'decode' ? Since not parse from string. ;-) The these two functions are pair style.

rte_eth_representor_id_encode / rte_eth_representor_id_decode ?

Nice catch, thanks!

Quoted 2 lines
Quoted 2 lines

2.25.1

#81 lore raw

Re: [dpdk-dev] [PATCH v5 2/9] ethdev: support representor port list

In reply to Andrew Rybchenko
Quoted 18 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 3:48 PM
To: Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>
Subject: Re: [PATCH v5 2/9] ethdev: support representor port list

Quoted 6 lines · Xueming Li

To support extended representor syntax, this patch extends the representor list parsing to support for representor port range in devargs, examples:
representor=[1,2,3] - single list
representor=[1,3-5,7,9-11] - list with singles and ranges

Quoted 6 lines
Quoted 3 lines

It looks like my comments to the previous version are all applicable here. Sorry, I should review this one from the very beginning.

NP, noted and WIP.

#97 lore raw

Re: [dpdk-dev] [PATCH v5 7/9] devarg: change representor ID to bitmap

In reply to Xueming Li
Quoted 20 lines · Xueming Li

The NIC can have multiple PCIe links and can be attached to multiple hosts, for example the same single NIC can be shared for multiple server units in the rack. On each PCIe link NIC can provide multiple PFs and VFs/SFs based on these ones. The full representor identifier consists of three indices - controller index, PF index, and VF or SF index (if any).

SR-IOV and SubFunction are created on top of PF. PF index is introduced because there might be multiple PFs in the bonding configuration and only bonding device is probed.

In eth representor comparator callback, ethdev was compared with devarg. Since ethdev representor port didn't contain controller index and PF index information, callback returned representor from other PF or controller.

This patch changes representor ID to bitmap so that the ethdev representor comparer callback returns correct ethdev by comparing full representor information including: controller index, PF index, representor type, SF or VF index.

Quoted 6 lines

Representor ID bitmap definition:
xxxx xxxx xxxx xxxx

 |||| |LLL LLLL LLLL vf/sf id
 |||| L 1:sf, 0:vf
 ||LL pf id

LL controller(host) id

What about PF representor case? I.e. representor for entire PF.

Also it implies that controller ID 0 is the caller. I.e. special meaning. So, space for just 3 specific contoller left

Similar for PF. In fact it is worse. E.g. PMD is bound to the second PF (PF number 1). If so, vf0 means the first VF of the PF itself, i.e. PF 1 VF 0. But, pf0vf0 should mean PF 1 VF 1.

Quoted 89 lines

This approach keeps binary compatibility with all drivers, VF representor id matches with simple id for non-bonding and non-multi-host configurations.

In the future, the representor ID field and each section should extend to bigger width to support more devices.

lib/librte_ethdev/rte_class_eth.c +30 -8
index efe6149df5..994db96960 100644
@@ -66,8 +66,8 @@ eth_representor_cmp(const char *key __rte_unused,
 	int ret;
 	char *values;
 	const struct rte_eth_dev_data *data = opaque;
-	struct rte_eth_devargs representors;
-	uint16_t index;
+	struct rte_eth_devargs eth_da;
+	uint16_t index, c, p, f;
 
 	if ((data->dev_flags & RTE_ETH_DEV_REPRESENTOR) == 0)
 		return -1; /* not a representor port */
@@ -76,17 +76,39 @@ eth_representor_cmp(const char *key __rte_unused,
 	values = strdup(value);
 	if (values == NULL)
 		return -1;
-	memset(&representors, 0, sizeof(representors));
-	ret = rte_eth_devargs_parse_representor_ports(values, &representors);
+	memset(&eth_da, 0, sizeof(eth_da));
+	ret = rte_eth_devargs_parse_representor_ports(values, &eth_da);
 	free(values);
 	if (ret != 0)
 		return -1; /* invalid devargs value */
 
+	/* Set default values. */
+	if (eth_da.nb_mh_controllers == 0) {
+		eth_da.nb_mh_controllers = 1;
+		eth_da.mh_controllers[0] = 0;
+	}
+	if (eth_da.nb_ports == 0) {
+		eth_da.nb_ports = 1;
+		eth_da.ports[0] = 0;
+	}
+	if (eth_da.nb_representor_ports == 0) {
+		eth_da.nb_representor_ports = 1;
+		eth_da.representor_ports[0] = 0;
+	}
 	/* Return 0 if representor id is matching one of the values. */
-	for (index = 0; index < representors.nb_representor_ports; index++)
-		if (data->representor_id ==
-				representors.representor_ports[index])
-			return 0;
+	for (c = 0; c < eth_da.nb_mh_controllers; ++c) {
+		for (p = 0; p < eth_da.nb_ports; ++p) {
+			for (f = 0; f < eth_da.nb_representor_ports; ++f) {
+				index = rte_eth_representor_id_encode(
+					eth_da.mh_controllers[c],
+					eth_da.ports[p],
+					eth_da.type,
+					eth_da.representor_ports[f]);
+				if (data->representor_id == index)
+					return 0;
+			}
+		}
+	}
 	return -1; /* no match */
 }
 
lib/librte_ethdev/rte_ethdev.c +7 -0
index 91b3263338..2cac0ccfbd 100644
@@ -5575,6 +5575,32 @@ rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
 	return result;
 }
 
+uint16_t
+rte_eth_representor_id_encode(uint16_t controller, uint16_t pf,
+			      enum rte_eth_representor_type type,
+			      uint16_t representor_port)
+{
+	return (((controller & 3) << 14) |
+		((pf & 3) << 12) |

lib/librte_ethdev/rte_ethdev.c rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da) · line 5594

Quoted 10 lines
lib/librte_ethdev/rte_ethdev.c +10 -0
+		(!!(type == RTE_ETH_REPRESENTOR_SF) << 11) |
+		(representor_port & 0x7ff));
+}
+
+uint16_t
+rte_eth_representor_id_parse(const uint16_t representor_id,
+			     uint16_t *controller, uint16_t *pf,
+			     enum rte_eth_representor_type *type)
+{
+	if (controller)

Compare vs NULL in accordance with DPDK coding style guide

lib/librte_ethdev/rte_ethdev.c rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da) · line 5596

Quoted 2 lines
lib/librte_ethdev/rte_ethdev.c +2 -0
+		*controller = (representor_id >> 14) & 3;
+	if (pf)

Compare vs NULL in accordance with DPDK coding style guide

lib/librte_ethdev/rte_ethdev.c rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da) · line 5598

Quoted 2 lines
lib/librte_ethdev/rte_ethdev.c +2 -0
+		*pf = (representor_id >> 12) & 3;
+	if (type)

Compare vs NULL in accordance with DPDK coding style guide

Quoted 77 lines
lib/librte_ethdev/rte_ethdev.c +5 -0
+		*type = ((representor_id >> 11) & 1) ?
+			RTE_ETH_REPRESENTOR_SF : RTE_ETH_REPRESENTOR_VF;
+	return representor_id & 0x7ff;
+}
+
 static int
 eth_dev_handle_port_list(const char *cmd __rte_unused,
 		const char *params __rte_unused,
lib/librte_ethdev/rte_ethdev_driver.h +53 -0
index b01f118965..57253c8f90 100644
@@ -1218,6 +1218,59 @@ struct rte_eth_devargs {
 	enum rte_eth_representor_type type; /* type of representor */
 };
 
+#define RTE_NO_REPRESENTOR_ID UINT16_MAX /**< No representor ID. */
+
+/**
+ * PMD helper function to encode representor ID
+ *
+ * The compact format is used for device iterator that comparing
+ * ethdev representor ID with target devargs.
+ *
+ * xxxx xxxx xxxx xxxx
+ * |||| |LLL LLLL LLLL vf/sf id
+ * |||| L 1:sf, 0:vf
+ * ||LL pf id
+ * LL controller(host) id
+ *
+ * @param controller
+ *  Controller ID.
+ * @param pf
+ *  PF port ID.
+ * @param type
+ *  Representor type.
+ * @param representor_port
+ *  Representor port ID.
+ *
+ * @return
+ *   Encoded representor ID.
+ */
+__rte_internal
+uint16_t
+rte_eth_representor_id_encode(uint16_t controller, uint16_t pf,
+			      enum rte_eth_representor_type type,
+			      uint16_t representor_port);
+
+/**
+ * PMD helper function to parse representor ID
+ *
+ * @param representor_id
+ *  Representor ID.
+ * @param controller
+ *  Parsed controller ID.
+ * @param pf
+ *  Parsed PF port ID.
+ * @param type
+ *  Parsed representor type.
+ *
+ * @return
+ *   Parsed representor port ID.
+ */
+__rte_internal
+uint16_t
+rte_eth_representor_id_parse(const uint16_t representor_id,
+			     uint16_t *controller, uint16_t *pf,
+			     enum rte_eth_representor_type *type);
+
 /**
  * PMD helper function to parse ethdev arguments
  *
lib/librte_ethdev/version.map +0 -0
index d3f5410806..44edaed507 100644

lib/librte_ethdev/version.map INTERNAL { · line 261

Quoted 5 lines
lib/librte_ethdev/version.map +2 -0
@@ -257,6 +257,8 @@ INTERNAL {
 	rte_eth_dev_release_port;
 	rte_eth_dev_internal_reset;
 	rte_eth_devargs_parse;
+	rte_eth_representor_id_encode;
+	rte_eth_representor_id_parse;

The place looks wrong. It must be sorted or added at bottom with the comment with version number. I'd prefer to have it simply alphanumberically sorted.

Quoted 4 lines
lib/librte_ethdev/version.map +0 -0
 	rte_eth_dma_zone_free;
 	rte_eth_dma_zone_reserve;
 	rte_eth_hairpin_queue_peer_bind;
#98 lore raw

Re: [dpdk-dev] [PATCH v5 7/9] devarg: change representor ID to bitmap

19/01/2021 09:20, Andrew Rybchenko:

Quoted 5 lines · Xueming Li
Quoted 4 lines
lib/librte_ethdev/version.map +0 -0
@@ -257,6 +257,8 @@ INTERNAL {
 	rte_eth_dev_release_port;
Quoted 8 lines

lib/librte_ethdev/version.map INTERNAL { · line 261

Quoted 4 lines
lib/librte_ethdev/version.map +2 -0
 	rte_eth_dev_internal_reset;
 	rte_eth_devargs_parse;
+	rte_eth_representor_id_encode;
+	rte_eth_representor_id_parse;

The place looks wrong. It must be sorted or added at bottom with the comment with version number. I'd prefer to have it simply alphanumberically sorted.

We add a version number for experimental symbols to help moving old ones to stable.
In this case, they are internal symbols, so we don't need version, but you're right it must be alphabetically sorted.

#45 lore raw

Re: [dpdk-dev] [PATCH v4 1/9] ethdev: introduce representor type

In reply to Xueming(Steven) Li

19/01/2021 08:56, Xueming(Steven) Li:

Quoted 15 lines

From: Andrew Rybchenko <[email protected]>

Quoted 14 lines · Xueming(Steven) Li
Quoted 13 lines

From: Andrew Rybchenko <[email protected]>

Quoted 11 lines · Xueming Li

lib/librte_ethdev/rte_ethdev_driver.h __rte_internal · line 1201

Quoted 6 lines
lib/librte_ethdev/rte_ethdev_driver.h +6 -0
+/** Ethernet device representor type */ enum
+rte_eth_representor_type {
+	RTE_ETH_REPRESENTOR_NONE, /**< not a representor. */
+	RTE_ETH_REPRESENTOR_VF,   /**< representor of VF. */
+	RTE_ETH_REPRESENTOR_SF,   /**< representor of SF. */
+	RTE_ETH_REPRESENTOR_PF,   /**< representor of host PF. */

RTE_ETH_REPRESENTOR_SF and PF looks dead in the patch. IMHO, addition of these members here make future patches which add support inconsistent.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Yes, later patch in this patchset will support it.

I know. The question is why it is not added in the later patches when these types are actually supported.

Good suggestion, will update

+1 (I was sure it was already the case)

#64 lore raw

Re: [dpdk-dev] [PATCH v5 0/9] ethdev: support SubFunction representor

In reply to Xueming Li
Quoted 14 lines · Xueming Li

dedicated queues(txq, rxq). A SF netdev supports E-Switch representation offload similar to existing PF and VF representors. A SF shares PCI level resources with other SFs and/or with its parent PCI function.

Quoted 1 line

From SmartNIC perspective, when PCI device is shared for multi-host,

representors for host controller and host PF is required.

This patch set introduces new representor types in addtion to existing VF representor. Syntax:

[[c#]pf#]vf#: VF port representor/s from controller/pf [[c#]pf#]sf#: SF port representor/s from controller/pf #: VF representor - for backwards compatibility

Quoted 5 lines

"#" is number instance, list or range, valid examples:
1, [1,3,5], [0-3], [0,2-4,6]

For backward compatibility, this patch also introduces new netdev capability to indicate the capability of supportting SF representor.

The patch series looks really nice. Thanks.

As before, my biggest concern is making representor ID a bitmap. See my comments to a specific patch. Plus absence of defined semantics of caller function. Basically it is looks like it is assumed that controller #0 and PF #0 is the caller. However, it could be wrong.

The next biggest concert is the absence of capability reporting API. How many controller are available? How many PFs on each controller are available? How many VFs on each controller/PF are available? How many SFs?

From the first sight it sounds not that important right now and an extra feature which could be added in the follow up patches, but IMHO addition of the API would allow to avoid making representor ID a bitmap. Basically capabilities API can provide an array of available functions with representor ID assigned to each entry. Also it could make the entire patch series optional since it would allow to interpret numbers in representor=[....] as representor IDs which are mapped to controller/PF/VF/SF by the capabilities reporting API.

I realize that sometimes it could be more convenient to use syntax suggested here. Mainly for human.

#50 lore raw

Re: [dpdk-dev] [PATCH v4 2/9] ethdev: support representor port list

In reply to Andrew Rybchenko

Hi Andrew,

Quoted 122 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 3:46 PM
To: Xueming(Steven) Li <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Olivier Matz <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [PATCH v4 2/9] ethdev: support representor port list

Quoted 8 lines · Xueming Li

To support extended representor syntax, this patch extends the representor list parsing to support for representor port range in devargs, examples:
representor=[1,2,3] - single list
representor=[1,3-5,7,9-11] - list with singles and ranges

See below

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start,

Quoted 13 lines
---
 lib/librte_ethdev/ethdev_private.c | 105 ++++++++++++++---------------
 lib/librte_ethdev/ethdev_private.h |   3 -
 lib/librte_ethdev/rte_class_eth.c  |   4 +-
 lib/librte_ethdev/rte_ethdev.c     |   5 +-
 4 files changed, 54 insertions(+), 63 deletions(-)
lib/librte_ethdev/ethdev_private.c +0 -0
index c1a411dba4..12bcc7e98d 100644
@@ -38,77 +38,71 @@ eth_find_device(const struct rte_eth_dev *start,

rte_eth_cmp_t cmp,

Quoted 43 lines
lib/librte_ethdev/ethdev_private.c +4 -34
 	return NULL;
 }
 
-int
-rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
-	void *data)
+static int
+rte_eth_devargs_enlist(uint16_t *list, uint16_t *len_list,
+		       const uint16_t max_list, uint16_t val)
 {
-	char *str_start;
-	int state;
-	int result;
-
-	if (*str != '[')
-		/* Single element, not a list */
-		return callback(str, data);
-
-	/* Sanity check, then strip the brackets */
-	str_start = &str[strlen(str) - 1];
-	if (*str_start != ']') {
-		RTE_LOG(ERR, EAL, "(%s): List does not end with ']'\n", str);
-		return -EINVAL;
-	}
-	str++;
-	*str_start = '\0';
+	uint16_t i;
 
-	/* Process list elements */
-	state = 0;
-	while (1) {
-		if (state == 0) {
-			if (*str == '\0')
-				break;
-			if (*str != ',') {
-				str_start = str;
-				state = 1;
-			}
-		} else if (state == 1) {
-			if (*str == ',' || *str == '\0') {
-				if (str > str_start) {
-					/* Non-empty string fragment */
-					*str = '\0';

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, · line 48

Quoted 10 lines
lib/librte_ethdev/ethdev_private.c +2 -8
-					result = callback(str_start, data);
-					if (result < 0)
-						return result;
-				}
-				state = 0;
-			}
-		}
-		str++;
+	if (*len_list >= max_list)
+		return -1;

If current length is equal to max, but added value is already is in the list, it should not be an error. So, these two lines should be moved after below for loop.

Quoted 16 lines
lib/librte_ethdev/ethdev_private.c +6 -1
+	for (i = 0; i < *len_list; i++) {
+		if (list[i] == val)
+			return 0;
 	}
+	list[(*len_list)++] = val;
 	return 0;
 }
 
-static int
+static char *
 rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
 	const uint16_t max_list)
 {
 	uint16_t lo, hi, val;
 	int result;
+	char *pos = str;

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp,

Quoted 10 lines
lib/librte_ethdev/ethdev_private.c +2 -4
 
 	result = sscanf(str, "%hu-%hu", &lo, &hi);
 	if (result == 1) {
-		if (*len_list >= max_list)
-			return -ENOMEM;
-		list[(*len_list)++] = lo;
+		if (rte_eth_devargs_enlist(list, len_list, max_list, lo) != 0)
+			return NULL;
 	} else if (result == 2) {
-		if (lo >= hi || lo > RTE_MAX_ETHPORTS || hi >

RTE_MAX_ETHPORTS)

Quoted 2 lines

Strictly speaking removal of comparision vs RTE_MAX_ETHPORTS is a separate logical change with a separate motivation.

To make this function comment for controller/pf/vf/sf parsing, the max value is passed in as parameter and checked in rte_eth_devargs_enlist(). Caller code in rte_eth_devargs_process_list() decide the max value.

Quoted 63 lines

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, · line 70

Quoted 3 lines
lib/librte_ethdev/ethdev_private.c +1 -1
-			return -EINVAL;
+		if (lo >= hi)

I'd remove '=' here. It should not be a problem and handed perfectly by below code. I see no point to deny 3-3 range which is an equivalent for just 3. It could be convenient in some cases.

Quoted 4 lines
lib/librte_ethdev/ethdev_private.c +1 -2
+			return NULL;
 		for (val = lo; val <= hi; val++) {
-			if (*len_list >= max_list)
-				return -ENOMEM;

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, · line 79

Quoted 10 lines
lib/librte_ethdev/ethdev_private.c +5 -3
-			list[(*len_list)++] = val;
+			if (rte_eth_devargs_enlist(list, len_list, max_list,
+						   val) != 0)
+				return NULL;
 		}
 	} else
-		return -EINVAL;
-	return 0;
+		return NULL;
+	while (*pos != 0 && ((*pos >= '0' && *pos <= '9') || *pos == '-'))

*post != '\0' is a bit better looking at subsequent comparisons. Yes, it is just style. Up to you.

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, · line 80

Quoted 1 line
lib/librte_ethdev/ethdev_private.c +1 -0
+		pos++;

It looks too fragile. May I suggest to use %n in above scanf to be able to skip only parsed characters.

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str,

Quoted 29 lines
lib/librte_ethdev/ethdev_private.c +25 -0
+	return pos;
+}
+
+static char *
+rte_eth_devargs_process_list(char *str, uint16_t *list, uint16_t *len_list,
+	const uint16_t max_list)
+{
+	char *pos = str;
+
+	if (*pos == '[')
+		pos++;
+	while (1) {
+		pos = rte_eth_devargs_process_range(pos, list, len_list,
+						    max_list);
+		if (pos == NULL)
+			return NULL;
+		if (*pos != ',') /* end of list */
+			break;
+		pos++;
+	}
+	if (*str == '[' && *pos != ']')
+		return NULL;
+	if (*pos == ']')
+		pos++;
+	return pos;
 }
 
 /*
@@ -121,6 +115,9 @@ rte_eth_devargs_parse_representor_ports(char *str,

void *data)

Quoted 2 lines
lib/librte_ethdev/ethdev_private.c +0 -0
 	struct rte_eth_devargs *eth_da = data;
 
Quoted 8 lines

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 119

Quoted 5 lines
lib/librte_ethdev/ethdev_private.c +1 -1
 	eth_da->type = RTE_ETH_REPRESENTOR_VF;
-	return rte_eth_devargs_process_range(str, eth_da-
 representor_ports,
+	str = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);

Not directly related to the patch, but I dislike RTE_MAX_ETHPORTS above. RTE_DIM(eth_da->representor_ports) would be more readable.

The array dim could be different than RTE_MAX_ETHPORTS, although they are same today 😊

Quoted 8 lines
Quoted 5 lines
lib/librte_ethdev/ethdev_private.c +3 -0
+	if (str == NULL)
+		RTE_LOG(ERR, EAL, "wrong representor format: %s\n", str);
+	return str == NULL ? -1 : 0;

}

[snip]

Other comments looks great, will update, thanks!

#51 lore raw

Re: [dpdk-dev] [PATCH v4 2/9] ethdev: support representor port list

Quoted 124 lines · Xueming(Steven) Li

Hi Andrew,

Quoted 122 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 3:46 PM
To: Xueming(Steven) Li <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Olivier Matz <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [PATCH v4 2/9] ethdev: support representor port list

Quoted 8 lines · Xueming Li

To support extended representor syntax, this patch extends the representor list parsing to support for representor port range in devargs, examples:
representor=[1,2,3] - single list
representor=[1,3-5,7,9-11] - list with singles and ranges

See below

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start,

Quoted 13 lines
---
 lib/librte_ethdev/ethdev_private.c | 105 ++++++++++++++---------------
 lib/librte_ethdev/ethdev_private.h |   3 -
 lib/librte_ethdev/rte_class_eth.c  |   4 +-
 lib/librte_ethdev/rte_ethdev.c     |   5 +-
 4 files changed, 54 insertions(+), 63 deletions(-)
lib/librte_ethdev/ethdev_private.c +0 -0
index c1a411dba4..12bcc7e98d 100644
@@ -38,77 +38,71 @@ eth_find_device(const struct rte_eth_dev *start,

rte_eth_cmp_t cmp,

Quoted 43 lines
lib/librte_ethdev/ethdev_private.c +4 -34
 	return NULL;
 }
 
-int
-rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback,
-	void *data)
+static int
+rte_eth_devargs_enlist(uint16_t *list, uint16_t *len_list,
+		       const uint16_t max_list, uint16_t val)
 {
-	char *str_start;
-	int state;
-	int result;
-
-	if (*str != '[')
-		/* Single element, not a list */
-		return callback(str, data);
-
-	/* Sanity check, then strip the brackets */
-	str_start = &str[strlen(str) - 1];
-	if (*str_start != ']') {
-		RTE_LOG(ERR, EAL, "(%s): List does not end with ']'\n", str);
-		return -EINVAL;
-	}
-	str++;
-	*str_start = '\0';
+	uint16_t i;
 
-	/* Process list elements */
-	state = 0;
-	while (1) {
-		if (state == 0) {
-			if (*str == '\0')
-				break;
-			if (*str != ',') {
-				str_start = str;
-				state = 1;
-			}
-		} else if (state == 1) {
-			if (*str == ',' || *str == '\0') {
-				if (str > str_start) {
-					/* Non-empty string fragment */
-					*str = '\0';

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, · line 48

Quoted 10 lines
lib/librte_ethdev/ethdev_private.c +2 -8
-					result = callback(str_start, data);
-					if (result < 0)
-						return result;
-				}
-				state = 0;
-			}
-		}
-		str++;
+	if (*len_list >= max_list)
+		return -1;

If current length is equal to max, but added value is already is in the list, it should not be an error. So, these two lines should be moved after below for loop.

Quoted 16 lines
lib/librte_ethdev/ethdev_private.c +6 -1
+	for (i = 0; i < *len_list; i++) {
+		if (list[i] == val)
+			return 0;
 	}
+	list[(*len_list)++] = val;
 	return 0;
 }
 
-static int
+static char *
 rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list,
 	const uint16_t max_list)
 {
 	uint16_t lo, hi, val;
 	int result;
+	char *pos = str;

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp,

Quoted 10 lines
lib/librte_ethdev/ethdev_private.c +2 -4
 
 	result = sscanf(str, "%hu-%hu", &lo, &hi);
 	if (result == 1) {
-		if (*len_list >= max_list)
-			return -ENOMEM;
-		list[(*len_list)++] = lo;
+		if (rte_eth_devargs_enlist(list, len_list, max_list, lo) != 0)
+			return NULL;
 	} else if (result == 2) {
-		if (lo >= hi || lo > RTE_MAX_ETHPORTS || hi >

RTE_MAX_ETHPORTS)

Quoted 6 lines
Quoted 2 lines

Strictly speaking removal of comparision vs RTE_MAX_ETHPORTS is a separate logical change with a separate motivation.

To make this function comment for controller/pf/vf/sf parsing, the max value is passed in as parameter and checked in rte_eth_devargs_enlist(). Caller code in rte_eth_devargs_process_list() decide the max value.

Which maximum? Maximum number of elements in array and maximum element value are different things.

[snip]

#88 lore raw

Re: [dpdk-dev] [PATCH v5 5/9] ethdev: support PF index in representor

In reply to Andrew Rybchenko

Hi Andrew,

Quoted 20 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 4:01 PM
To: Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>
Subject: Re: [PATCH v5 5/9] ethdev: support PF index in representor

Quoted 8 lines · Xueming Li

With Kernel bonding, multiple underlying PFs are bonded, VFs come from different PF, need to identify representor of VFs unambiguously by adding PF index.

This patch introduces optional 'pf' section to representor devargs syntax, examples:
representor=pf0vf0 - single VF representor
representor=pf[0-1]sf[0-1023] - SF representors from 2 PFs

Quoted 3 lines

Don't we need
representor=pf3
i.e. without VF or sub-function?

Standalone PF not used by Mellnaox PMD, but should be supported. Will update.

Quoted 47 lines
Quoted 24 lines
---
 doc/guides/prog_guide/poll_mode_drv.rst |  2 ++
 lib/librte_ethdev/ethdev_private.c      | 13 +++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
doc/guides/prog_guide/poll_mode_drv.rst +2 -0
index 86e5867f1b..b2147aad30 100644
@@ -382,6 +382,8 @@ parameters to those ports.
    -a DBDF,representor=sf[1,3,5]
    -a DBDF,representor=sf[0-1023]
    -a DBDF,representor=sf[0,2-4,7,9-11]
+   -a DBDF,representor=pf1vf0
+   -a DBDF,representor=pf[0-1]sf[0-127]
 
 Note: PMDs are not required to support the standard device arguments
Quoted 1 line

and users should consult the relevant PMD documentation to see support

devargs.

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_process_list(char *str, uint16_t

Quoted 6 lines
lib/librte_ethdev/ethdev_private.c +0 -0
index d513f035d0..b9fdbd0f72 100644
@@ -120,8 +120,8 @@ rte_eth_devargs_process_list(char *str, uint16_t

*list, uint16_t *len_list,

Quoted 14 lines
lib/librte_ethdev/ethdev_private.c +2 -2
  *
  * Representor format:
  *   #: range or single number of VF representor - legacy
- *   vf#: VF port representor/s
- *   sf#: SF port representor/s
+ *   [pf#]vf#: VF port representor/s
+ *   [pf#]sf#: SF port representor/s
  *
  * Examples of #:
  *  2               - single
@@ -133,6 +133,14 @@ rte_eth_devargs_parse_representor_ports(char
 *str, void *data)  {
 	struct rte_eth_devargs *eth_da = data;
 
Quoted 7 lines

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 140

Quoted 5 lines
lib/librte_ethdev/ethdev_private.c +5 -0
+	if (str[0] == 'p' && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_PF;
+		str += 2;
+		str = rte_eth_devargs_process_list(str, eth_da->ports,
+				&eth_da->nb_ports, RTE_MAX_ETHPORTS);

May be RTE_MAX_ETHPORTS -> RTE_DIM(eth_da->ports) ?

Same here, the dim could be different than MAX value.

Quoted 5 lines

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 142

Quoted 3 lines
lib/librte_ethdev/ethdev_private.c +2 -0
+		if (str == NULL)
+			goto err;

Below we should not allow legacy VF syntax without "vf" prefix.

For backward compatibility, default numbers to "vf", otherwise some existing app like OVS that working with VF will break.

Quoted 15 lines

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str,

Quoted 6 lines
lib/librte_ethdev/ethdev_private.c +1 -0
+	}
 	if (str[0] == 'v' && str[1] == 'f') {
 		eth_da->type = RTE_ETH_REPRESENTOR_VF;
 		str += 2;
@@ -144,6 +152,7 @@ rte_eth_devargs_parse_representor_ports(char *str,

void *data)

Quoted 8 lines
lib/librte_ethdev/ethdev_private.c +1 -0
 	}
 	str = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
+err:
 	if (str == NULL)
 		RTE_LOG(ERR, EAL, "wrong representor format: %s\n", str);
 	return str == NULL ? -1 : 0;
#93 lore raw

Re: [dpdk-dev] [PATCH v5 6/9] ethdev: support multi-host in representor

In reply to Andrew Rybchenko
Quoted 73 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 4:03 PM
To: Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>; Bruce Richardson <[email protected]>; NBU- Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>
Subject: Re: [PATCH v5 6/9] ethdev: support multi-host in representor

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_process_list(char *str, uint16_t

Quoted 47 lines · Xueming Li

The NIC can have multiple PCIe links and can be attached to the multiple hosts, for example the same single NIC can be shared for multiple server units in the rack. On each PCIe link NIC can provide multiple PFs and VFs/SFs based on these ones. To provide the unambiguous identification of the PCIe function the controller index is added. The full representor identifier consists of three indices - controller index, PF index, and VF or SF index (if any).

This patch introduces controller index to ethdev representor syntax, examples:

[[c#]pf#]vf#: VF port representor/s, example: pf0vf1 [[c#]pf#]sf#: SF port representor/s, example: c1pf1sf[0-3]

c# is controller(host) ID/range in case of multi-host, optional.

For user application (e.g. OVS), PMD is responsible to interpret and locate representor device based on controller ID, PF ID and VF/SF ID in representor syntax.

---
 config/rte_config.h                   |  1 +
 lib/librte_ethdev/ethdev_private.c    | 12 ++++++++++--
 lib/librte_ethdev/rte_ethdev_driver.h |  4 ++++
 3 files changed, 15 insertions(+), 2 deletions(-)
config/rte_config.h index renamed from config/rte_config.h +0 -0

a0b5160ff2..23d02d51ef 100644

config/rte_config.h +0 -0
@@ -58,6 +58,7 @@
 #define RTE_MAX_QUEUES_PER_PORT 1024
 #define RTE_ETHDEV_QUEUE_STAT_CNTRS 16 /* max 256 */  #define

RTE_ETHDEV_RXTX_CALLBACKS 1

config/rte_config.h +1 -0
+#define RTE_MAX_MULTI_HOST_CTRLS 4
 
 /* cryptodev defines */
 #define RTE_CRYPTO_MAX_DEVS 64
lib/librte_ethdev/ethdev_private.c +0 -0
index b9fdbd0f72..9a0945c22e 100644
@@ -120,8 +120,8 @@ rte_eth_devargs_process_list(char *str, uint16_t

*list, uint16_t *len_list,

Quoted 14 lines
lib/librte_ethdev/ethdev_private.c +2 -2
  *
  * Representor format:
  *   #: range or single number of VF representor - legacy
- *   [pf#]vf#: VF port representor/s
- *   [pf#]sf#: SF port representor/s
+ *   [[c#]pf#]vf#: VF port representor/s
+ *   [[c#]pf#]sf#: SF port representor/s
  *
  * Examples of #:
  *  2               - single
@@ -133,6 +133,14 @@ rte_eth_devargs_parse_representor_ports(char
 *str, void *data)  {
 	struct rte_eth_devargs *eth_da = data;
 
Quoted 11 lines

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 142

Quoted 8 lines
lib/librte_ethdev/ethdev_private.c +7 -0
+	if (str[0] == 'c') {
+		str += 1;
+		str = rte_eth_devargs_process_list(str, eth_da-
 mh_controllers,
+				&eth_da->nb_mh_controllers,
+				RTE_DIM(eth_da->mh_controllers));
+		if (str == NULL)
+			goto err;

The parser must enforce pf to follow. I.e. should not allow c1vf3. At least above syntax description in comments says so.

Good catch, will add, thanks.

Quoted 21 lines
Quoted 21 lines
lib/librte_ethdev/ethdev_private.c +1 -0
+	}
 	if (str[0] == 'p' && str[1] == 'f') {
 		eth_da->type = RTE_ETH_REPRESENTOR_PF;
lib/librte_ethdev/ethdev_private.c +0 -0
 		str += 2;
lib/librte_ethdev/rte_ethdev_driver.h +4 -0
index cd33184f17..b01f118965 100644
@@ -1203,6 +1203,10 @@ enum rte_eth_representor_type {
 
 /** Generic Ethernet device arguments  */  struct rte_eth_devargs {
+	uint16_t mh_controllers[RTE_MAX_MULTI_HOST_CTRLS];
+	/** controller/s number in case of multi-host */
+	uint16_t nb_mh_controllers;
+	/** number of controllers in multi-host controllers field */
 	uint16_t ports[RTE_MAX_ETHPORTS];
 	/** port/s number to enable on a multi-port single function */
 	uint16_t nb_ports;
 
#89 lore raw

Re: [dpdk-dev] [PATCH v5 5/9] ethdev: support PF index in representor

In reply to Xueming(Steven) Li
Quoted 83 lines · Xueming(Steven) Li

Hi Andrew,

Quoted 20 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 4:01 PM
To: Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>
Subject: Re: [PATCH v5 5/9] ethdev: support PF index in representor

Quoted 8 lines · Xueming Li

With Kernel bonding, multiple underlying PFs are bonded, VFs come from different PF, need to identify representor of VFs unambiguously by adding PF index.

This patch introduces optional 'pf' section to representor devargs syntax, examples:
representor=pf0vf0 - single VF representor
representor=pf[0-1]sf[0-1023] - SF representors from 2 PFs

Quoted 3 lines

Don't we need
representor=pf3
i.e. without VF or sub-function?

Standalone PF not used by Mellnaox PMD, but should be supported. Will update.

Quoted 47 lines
Quoted 24 lines
---
 doc/guides/prog_guide/poll_mode_drv.rst |  2 ++
 lib/librte_ethdev/ethdev_private.c      | 13 +++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
doc/guides/prog_guide/poll_mode_drv.rst +2 -0
index 86e5867f1b..b2147aad30 100644
@@ -382,6 +382,8 @@ parameters to those ports.
    -a DBDF,representor=sf[1,3,5]
    -a DBDF,representor=sf[0-1023]
    -a DBDF,representor=sf[0,2-4,7,9-11]
+   -a DBDF,representor=pf1vf0
+   -a DBDF,representor=pf[0-1]sf[0-127]
 
 Note: PMDs are not required to support the standard device arguments
Quoted 1 line

and users should consult the relevant PMD documentation to see support

devargs.

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_process_list(char *str, uint16_t

Quoted 6 lines
lib/librte_ethdev/ethdev_private.c +0 -0
index d513f035d0..b9fdbd0f72 100644
@@ -120,8 +120,8 @@ rte_eth_devargs_process_list(char *str, uint16_t

*list, uint16_t *len_list,

Quoted 14 lines
lib/librte_ethdev/ethdev_private.c +2 -2
  *
  * Representor format:
  *   #: range or single number of VF representor - legacy
- *   vf#: VF port representor/s
- *   sf#: SF port representor/s
+ *   [pf#]vf#: VF port representor/s
+ *   [pf#]sf#: SF port representor/s
  *
  * Examples of #:
  *  2               - single
@@ -133,6 +133,14 @@ rte_eth_devargs_parse_representor_ports(char
 *str, void *data)  {
 	struct rte_eth_devargs *eth_da = data;
 
Quoted 7 lines

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 140

Quoted 5 lines
lib/librte_ethdev/ethdev_private.c +5 -0
+	if (str[0] == 'p' && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_PF;
+		str += 2;
+		str = rte_eth_devargs_process_list(str, eth_da->ports,
+				&eth_da->nb_ports, RTE_MAX_ETHPORTS);

May be RTE_MAX_ETHPORTS -> RTE_DIM(eth_da->ports) ?

Quoted 1 line

Same here, the dim could be different than MAX value.

Hold on, just for my understanding. The maximum says how many entries could be added to the array. So, why?

Quoted 8 lines
Quoted 5 lines

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 142

Quoted 3 lines
lib/librte_ethdev/ethdev_private.c +2 -0
+		if (str == NULL)
+			goto err;

Below we should not allow legacy VF syntax without "vf" prefix.

For backward compatibility, default numbers to "vf", otherwise some existing app like OVS that working with VF will break.

I mean if new syntax is used (i.e. we have pfX prefix), we must deny legacy syntax for VFs below.

Quoted 16 lines
Quoted 15 lines

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str,

Quoted 6 lines
lib/librte_ethdev/ethdev_private.c +1 -0
+	}
 	if (str[0] == 'v' && str[1] == 'f') {
 		eth_da->type = RTE_ETH_REPRESENTOR_VF;
 		str += 2;
@@ -144,6 +152,7 @@ rte_eth_devargs_parse_representor_ports(char *str,

void *data)

Quoted 8 lines
lib/librte_ethdev/ethdev_private.c +1 -0
 	}
 	str = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
+err:
 	if (str == NULL)
 		RTE_LOG(ERR, EAL, "wrong representor format: %s\n", str);
 	return str == NULL ? -1 : 0;
#52 lore raw

Re: [dpdk-dev] [PATCH v4 2/9] ethdev: support representor port list

In reply to Andrew Rybchenko
Quoted 141 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 5:04 PM
To: Xueming(Steven) Li <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Olivier Matz <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [PATCH v4 2/9] ethdev: support representor port list

Quoted 38 lines · Xueming(Steven) Li

Hi Andrew,

Quoted 36 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 3:46 PM
To: Xueming(Steven) Li <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Olivier Matz <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [PATCH v4 2/9] ethdev: support representor port list

Quoted 8 lines · Xueming Li

To support extended representor syntax, this patch extends the representor list parsing to support for representor port range in devargs, examples:
representor=[1,2,3] - single list
representor=[1,3-5,7,9-11] - list with singles and ranges

See below

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start,

Quoted 13 lines
---
 lib/librte_ethdev/ethdev_private.c | 105 ++++++++++++++---------------
 lib/librte_ethdev/ethdev_private.h |   3 -
 lib/librte_ethdev/rte_class_eth.c  |   4 +-
 lib/librte_ethdev/rte_ethdev.c     |   5 +-
 4 files changed, 54 insertions(+), 63 deletions(-)
lib/librte_ethdev/ethdev_private.c +0 -0
index c1a411dba4..12bcc7e98d 100644
@@ -38,77 +38,71 @@ eth_find_device(const struct rte_eth_dev *start,

rte_eth_cmp_t cmp,

Quoted 5 lines
Quoted 5 lines

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp,

Quoted 5 lines
lib/librte_ethdev/ethdev_private.c +0 -2
 	return NULL;
 }
 
-int
-rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t

callback,

Quoted 61 lines
Quoted 61 lines
Quoted 38 lines
lib/librte_ethdev/ethdev_private.c +4 -32
-	void *data)
+static int
+rte_eth_devargs_enlist(uint16_t *list, uint16_t *len_list,
+		       const uint16_t max_list, uint16_t val)
 {
-	char *str_start;
-	int state;
-	int result;
-
-	if (*str != '[')
-		/* Single element, not a list */
-		return callback(str, data);
-
-	/* Sanity check, then strip the brackets */
-	str_start = &str[strlen(str) - 1];
-	if (*str_start != ']') {
-		RTE_LOG(ERR, EAL, "(%s): List does not end with ']'\n", str);
-		return -EINVAL;
-	}
-	str++;
-	*str_start = '\0';
+	uint16_t i;
 
-	/* Process list elements */
-	state = 0;
-	while (1) {
-		if (state == 0) {
-			if (*str == '\0')
-				break;
-			if (*str != ',') {
-				str_start = str;
-				state = 1;
-			}
-		} else if (state == 1) {
-			if (*str == ',' || *str == '\0') {
-				if (str > str_start) {
-					/* Non-empty string fragment */
-					*str = '\0';

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, · line 48

Quoted 10 lines
lib/librte_ethdev/ethdev_private.c +2 -8
-					result = callback(str_start, data);
-					if (result < 0)
-						return result;
-				}
-				state = 0;
-			}
-		}
-		str++;
+	if (*len_list >= max_list)
+		return -1;

If current length is equal to max, but added value is already is in the list, it should not be an error. So, these two lines should be moved after below for loop.

Quoted 8 lines
lib/librte_ethdev/ethdev_private.c +4 -0
+	for (i = 0; i < *len_list; i++) {
+		if (list[i] == val)
+			return 0;
 	}
+	list[(*len_list)++] = val;
 	return 0;
 }
 
Quoted 3 lines
Quoted 3 lines

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp,

Quoted 3 lines
lib/librte_ethdev/ethdev_private.c +1 -1
-static int
+static char *
 rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t

*len_list,

Quoted 20 lines
Quoted 19 lines
Quoted 5 lines
lib/librte_ethdev/ethdev_private.c +1 -0
 	const uint16_t max_list)
 {
 	uint16_t lo, hi, val;
 	int result;
+	char *pos = str;

lib/librte_ethdev/ethdev_private.c eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp,

Quoted 10 lines
lib/librte_ethdev/ethdev_private.c +2 -4
 
 	result = sscanf(str, "%hu-%hu", &lo, &hi);
 	if (result == 1) {
-		if (*len_list >= max_list)
-			return -ENOMEM;
-		list[(*len_list)++] = lo;
+		if (rte_eth_devargs_enlist(list, len_list, max_list, lo) != 0)
+			return NULL;
 	} else if (result == 2) {
-		if (lo >= hi || lo > RTE_MAX_ETHPORTS || hi >

RTE_MAX_ETHPORTS)

Strictly speaking removal of comparision vs RTE_MAX_ETHPORTS is a separate logical change with a separate motivation.

Quoted 6 lines
Quoted 3 lines

To make this function comment for controller/pf/vf/sf parsing, the max value is passed in as parameter and checked in rte_eth_devargs_enlist(). Caller code in rte_eth_devargs_process_list() decide the max value.

Which maximum? Maximum number of elements in array and maximum element value are different things.

My bad, after another check, it should be max number of elements in array, not max element value. Will update, thanks!

Quoted 2 lines

[snip]

#99 lore raw

Re: [dpdk-dev] [PATCH v5 7/9] devarg: change representor ID to bitmap

In reply to Andrew Rybchenko
Quoted 45 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 4:21 PM
To: Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>; Ajit Khaparde <[email protected]>; Somnath Kotur <[email protected]>; John Daley <[email protected]>; Hyong Youb Kim <[email protected]>; Beilei Xing <[email protected]>; Jeff Guo <[email protected]>; Haiyue Wang <[email protected]>; Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Ray Kinsella <[email protected]>; Neil Horman <[email protected]>
Subject: Re: [PATCH v5 7/9] devarg: change representor ID to bitmap

Quoted 5 lines · Xueming Li

The NIC can have multiple PCIe links and can be attached to multiple hosts, for example the same single NIC can be shared for multiple server units in the rack. On each PCIe link NIC can provide multiple PFs and VFs/SFs based on these ones. The full representor identifier consists of three indices - controller index, PF index, and VF or SF index (if

any).

Quoted 15 lines

SR-IOV and SubFunction are created on top of PF. PF index is introduced because there might be multiple PFs in the bonding configuration and only bonding device is probed.

In eth representor comparator callback, ethdev was compared with devarg. Since ethdev representor port didn't contain controller index and PF index information, callback returned representor from other PF or controller.

This patch changes representor ID to bitmap so that the ethdev representor comparer callback returns correct ethdev by comparing full representor information including: controller index, PF index, representor type, SF or VF index.

Quoted 6 lines

Representor ID bitmap definition:
xxxx xxxx xxxx xxxx

 |||| |LLL LLLL LLLL vf/sf id
 |||| L 1:sf, 0:vf
 ||LL pf id

LL controller(host) id

Quoted 8 lines

What about PF representor case? I.e. representor for entire PF.

Also it implies that controller ID 0 is the caller. I.e. special meaning. So, space for just 3 specific contoller left

Similar for PF. In fact it is worse. E.g. PMD is bound to the second PF (PF number 1). If so, vf0 means the first VF of the PF itself, i.e. PF 1 VF 0. But, pf0vf0 should mean PF 1 VF 1.

Agree, need to extend bits width in LTS release.

PF representor is not considered here, how about moving one bit from vf/sf id? 1k SF devices should be fine for me so far.

The controller ID and PF ID is related to the context device, how device configured and bonding state is critical for PMD to interpret the IDs. For example:
"<BDF>,representor=pf1vf1" is valid for bonding device, invalid for standalone device. "c#" is meaningful for multi-host scenario, invalid for normal NIC. PMD is responsible to encode representor ID correctly according to device configuration to make Device+ReprID unique, because the ReprID is used in device iterator. So the user app should specify representor syntax with necessary parts to cover device configuration, PMD should extract required info according to device state.

Quoted 208 lines
Quoted 31 lines

This approach keeps binary compatibility with all drivers, VF representor id matches with simple id for non-bonding and non-multi-host configurations.

In the future, the representor ID field and each section should extend to bigger width to support more devices.

lib/librte_ethdev/rte_class_eth.c +2 -2
index efe6149df5..994db96960 100644
@@ -66,8 +66,8 @@ eth_representor_cmp(const char *key __rte_unused,
 	int ret;
 	char *values;
 	const struct rte_eth_dev_data *data = opaque;
-	struct rte_eth_devargs representors;
-	uint16_t index;
+	struct rte_eth_devargs eth_da;
+	uint16_t index, c, p, f;
 
 	if ((data->dev_flags & RTE_ETH_DEV_REPRESENTOR) == 0)
 		return -1; /* not a representor port */ @@ -76,17 +76,39 @@

eth_representor_cmp(const char *key __rte_unused,

lib/librte_ethdev/rte_class_eth.c eth_representor_cmp(const char *key __rte_unused,

Quoted 5 lines
lib/librte_ethdev/rte_class_eth.c +0 -2
 	values = strdup(value);
 	if (values == NULL)
 		return -1;
-	memset(&representors, 0, sizeof(representors));
-	ret = rte_eth_devargs_parse_representor_ports(values,

&representors);

lib/librte_ethdev/rte_ethdev.c rte_eth_devargs_parse(const char *dargs, struct

Quoted 45 lines
lib/librte_ethdev/rte_class_eth.c +28 -4
+	memset(&eth_da, 0, sizeof(eth_da));
+	ret = rte_eth_devargs_parse_representor_ports(values, &eth_da);
 	free(values);
 	if (ret != 0)
 		return -1; /* invalid devargs value */
 
+	/* Set default values. */
+	if (eth_da.nb_mh_controllers == 0) {
+		eth_da.nb_mh_controllers = 1;
+		eth_da.mh_controllers[0] = 0;
+	}
+	if (eth_da.nb_ports == 0) {
+		eth_da.nb_ports = 1;
+		eth_da.ports[0] = 0;
+	}
+	if (eth_da.nb_representor_ports == 0) {
+		eth_da.nb_representor_ports = 1;
+		eth_da.representor_ports[0] = 0;
+	}
 	/* Return 0 if representor id is matching one of the values. */
-	for (index = 0; index < representors.nb_representor_ports; index++)
-		if (data->representor_id ==
-				representors.representor_ports[index])
-			return 0;
+	for (c = 0; c < eth_da.nb_mh_controllers; ++c) {
+		for (p = 0; p < eth_da.nb_ports; ++p) {
+			for (f = 0; f < eth_da.nb_representor_ports; ++f) {
+				index = rte_eth_representor_id_encode(
+					eth_da.mh_controllers[c],
+					eth_da.ports[p],
+					eth_da.type,
+					eth_da.representor_ports[f]);
+				if (data->representor_id == index)
+					return 0;
+			}
+		}
+	}
 	return -1; /* no match */
 }
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_ethdev.c index 91b3263338..2cac0ccfbd 100644

lib/librte_ethdev/rte_ethdev.c +0 -0
@@ -5575,6 +5575,32 @@ rte_eth_devargs_parse(const char *dargs, struct

rte_eth_devargs *eth_da)

Quoted 9 lines
lib/librte_ethdev/rte_ethdev.c +6 -0
 	return result;
 }
 
+uint16_t
+rte_eth_representor_id_encode(uint16_t controller, uint16_t pf,
+			      enum rte_eth_representor_type type,
+			      uint16_t representor_port)
+{
+	return (((controller & 3) << 14) |

lib/librte_ethdev/rte_ethdev.c rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da) · line 5594

Quoted 10 lines
lib/librte_ethdev/rte_ethdev.c +10 -0
+		((pf & 3) << 12) |
+		(!!(type == RTE_ETH_REPRESENTOR_SF) << 11) |
+		(representor_port & 0x7ff));
+}
+
+uint16_t
+rte_eth_representor_id_parse(const uint16_t representor_id,
+			     uint16_t *controller, uint16_t *pf,
+			     enum rte_eth_representor_type *type) {
+	if (controller)

Compare vs NULL in accordance with DPDK coding style guide

lib/librte_ethdev/rte_ethdev.c rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da) · line 5596

Quoted 2 lines
lib/librte_ethdev/rte_ethdev.c +2 -0
+		*controller = (representor_id >> 14) & 3;
+	if (pf)

Compare vs NULL in accordance with DPDK coding style guide

lib/librte_ethdev/rte_ethdev.c rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da) · line 5598

Quoted 2 lines
lib/librte_ethdev/rte_ethdev.c +2 -0
+		*pf = (representor_id >> 12) & 3;
+	if (type)

Compare vs NULL in accordance with DPDK coding style guide

lib/librte_ethdev/rte_ethdev.c rte_eth_devargs_parse(const char *dargs, struct · line 5599

Quoted 2 lines
lib/librte_ethdev/rte_ethdev.c +2 -0
+		*type = ((representor_id >> 11) & 1) ?
+			RTE_ETH_REPRESENTOR_SF :

RTE_ETH_REPRESENTOR_VF;

Quoted 12 lines
lib/librte_ethdev/rte_ethdev.c +3 -0
+	return representor_id & 0x7ff;
+}
+
 static int
 eth_dev_handle_port_list(const char *cmd __rte_unused,
 		const char *params __rte_unused,
lib/librte_ethdev/rte_ethdev_driver.h +0 -0
index b01f118965..57253c8f90 100644

lib/librte_ethdev/rte_ethdev_driver.h struct rte_eth_devargs { · line 1220

Quoted 3 lines
lib/librte_ethdev/rte_ethdev_driver.h +1 -0
@@ -1218,6 +1218,59 @@ struct rte_eth_devargs {
 	enum rte_eth_representor_type type; /* type of representor */  };
 
+#define RTE_NO_REPRESENTOR_ID UINT16_MAX /**< No representor ID.

*/

Quoted 60 lines
lib/librte_ethdev/rte_ethdev_driver.h +52 -0
+
+/**
+ * PMD helper function to encode representor ID
+ *
+ * The compact format is used for device iterator that comparing
+ * ethdev representor ID with target devargs.
+ *
+ * xxxx xxxx xxxx xxxx
+ * |||| |LLL LLLL LLLL vf/sf id
+ * |||| L 1:sf, 0:vf
+ * ||LL pf id
+ * LL controller(host) id
+ *
+ * @param controller
+ *  Controller ID.
+ * @param pf
+ *  PF port ID.
+ * @param type
+ *  Representor type.
+ * @param representor_port
+ *  Representor port ID.
+ *
+ * @return
+ *   Encoded representor ID.
+ */
+__rte_internal
+uint16_t
+rte_eth_representor_id_encode(uint16_t controller, uint16_t pf,
+			      enum rte_eth_representor_type type,
+			      uint16_t representor_port);
+
+/**
+ * PMD helper function to parse representor ID
+ *
+ * @param representor_id
+ *  Representor ID.
+ * @param controller
+ *  Parsed controller ID.
+ * @param pf
+ *  Parsed PF port ID.
+ * @param type
+ *  Parsed representor type.
+ *
+ * @return
+ *   Parsed representor port ID.
+ */
+__rte_internal
+uint16_t
+rte_eth_representor_id_parse(const uint16_t representor_id,
+			     uint16_t *controller, uint16_t *pf,
+			     enum rte_eth_representor_type *type);
+
 /**
  * PMD helper function to parse ethdev arguments
  *
(quoted diff) +0 -0

b/lib/librte_ethdev/version.map index d3f5410806..44edaed507 100644

lib/librte_ethdev/version.map INTERNAL { · line 261

Quoted 5 lines
lib/librte_ethdev/version.map +2 -0
@@ -257,6 +257,8 @@ INTERNAL {
 	rte_eth_dev_release_port;
 	rte_eth_dev_internal_reset;
 	rte_eth_devargs_parse;
+	rte_eth_representor_id_encode;
+	rte_eth_representor_id_parse;

The place looks wrong. It must be sorted or added at bottom with the comment with version number. I'd prefer to have it simply alphanumberically sorted.

Quoted 4 lines
lib/librte_ethdev/version.map +0 -0
 	rte_eth_dma_zone_free;
 	rte_eth_dma_zone_reserve;
 	rte_eth_hairpin_queue_peer_bind;
#100 lore raw

Re: [dpdk-dev] [PATCH v5 7/9] devarg: change representor ID to bitmap

Quoted 47 lines · Xueming(Steven) Li
Quoted 47 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 4:21 PM
To: Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>; Ajit Khaparde <[email protected]>; Somnath Kotur <[email protected]>; John Daley <[email protected]>; Hyong Youb Kim <[email protected]>; Beilei Xing <[email protected]>; Jeff Guo <[email protected]>; Haiyue Wang <[email protected]>; Matan Azrad <[email protected]>; Shahaf Shuler <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Ray Kinsella <[email protected]>; Neil Horman <[email protected]>
Subject: Re: [PATCH v5 7/9] devarg: change representor ID to bitmap

Quoted 5 lines · Xueming Li

The NIC can have multiple PCIe links and can be attached to multiple hosts, for example the same single NIC can be shared for multiple server units in the rack. On each PCIe link NIC can provide multiple PFs and VFs/SFs based on these ones. The full representor identifier consists of three indices - controller index, PF index, and VF or SF index (if

any).

Quoted 15 lines

SR-IOV and SubFunction are created on top of PF. PF index is introduced because there might be multiple PFs in the bonding configuration and only bonding device is probed.

In eth representor comparator callback, ethdev was compared with devarg. Since ethdev representor port didn't contain controller index and PF index information, callback returned representor from other PF or controller.

This patch changes representor ID to bitmap so that the ethdev representor comparer callback returns correct ethdev by comparing full representor information including: controller index, PF index, representor type, SF or VF index.

Quoted 6 lines

Representor ID bitmap definition:
xxxx xxxx xxxx xxxx

 |||| |LLL LLLL LLLL vf/sf id
 |||| L 1:sf, 0:vf
 ||LL pf id

LL controller(host) id

What about PF representor case? I.e. representor for entire PF.

Quoted 8 lines
Quoted 6 lines

Also it implies that controller ID 0 is the caller. I.e. special meaning. So, space for just 3 specific contoller left

Similar for PF. In fact it is worse. E.g. PMD is bound to the second PF (PF number 1). If so, vf0 means the first VF of the PF itself, i.e. PF 1 VF 0. But, pf0vf0 should mean PF 1 VF 1.

Agree, need to extend bits width in LTS release.

See my reply to cover mail.

Quoted 2 lines

PF representor is not considered here, how about moving one bit from vf/sf id? 1k SF devices should be fine for me so far.

We could reserve max VF/SF number to denote PF itself.

Quoted 3 lines

The controller ID and PF ID is related to the context device, how device configured and bonding state is critical for PMD to interpret the IDs. For example:
"<BDF>,representor=pf1vf1" is valid for bonding device, invalid for standalone device.

I guess it is mlx5 specific. IMHO, pf1vf1 makes sense even without bonding.

Quoted 5 lines

"c#" is meaningful for multi-host scenario, invalid for normal NIC. PMD is responsible to encode representor ID correctly according to device configuration to make Device+ReprID unique, because the ReprID is used in device iterator. So the user app should specify representor syntax with necessary parts to cover device configuration, PMD should extract required info according to device state.

See cover mail reply.

#103 lore raw

Re: [dpdk-dev] [PATCH v5 8/9] ethdev: add capability of sub-function representor

In reply to Andrew Rybchenko
Quoted 10 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 4:06 PM
To: Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>
Subject: Re: [PATCH v5 8/9] ethdev: add capability of sub-function representor

Quoted 8 lines
Quoted 4 lines · Xueming Li

Old DPDK version or some drivers didn't support SubFunction representor. For application to adapt different DPDK version automatically, or to be used for different NICs, this patch introduces new eth device capability of supporting SubFunction representor device.

Sorry, it does not sound sufficient motivation to introduce the capability. I simply need real life example why application need to know it.

I had same internal discussion on this as well :)
A simple example, for customer running DPDK based app with NICs from different vendors, app need a flag to know whether the device support SF representor, hotplug SF if the capability shows "support". This also happens with different model/fw even from same vendor. PMD report device+driver capability that whether SF supported.

Quoted 8 lines
Quoted 8 lines
---
 lib/librte_ethdev/rte_ethdev.h | 2 ++
 1 file changed, 2 insertions(+)
Quoted 12 lines

lib/librte_ethdev/rte_ethdev.h struct rte_eth_conf { · line 1437

Quoted 10 lines
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_ethdev.h index 2cbce958cf..da65adf1ab 100644

lib/librte_ethdev/rte_ethdev.h +0 -0
@@ -1433,6 +1433,8 @@ struct rte_eth_conf {  #define

RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP 0x00000001
/** Device supports Tx queue setup after device started. */ #define
RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP 0x00000002

lib/librte_ethdev/rte_ethdev.h +2 -0
+/** Device supports SubFunction representor. */
+#define RTE_ETH_DEV_CAPA_REPRESENTOR_SF         0x00000004

Will we have a PMD which supports it in the release cycle?

Please see reply above, it also reflect device hw capability.

Quoted 4 lines
Quoted 4 lines

/**@}*/

/*

#104 lore raw

Re: [dpdk-dev] [PATCH v5 8/9] ethdev: add capability of sub-function representor

Quoted 16 lines · Xueming(Steven) Li
Quoted 16 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 4:06 PM
To: Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>
Subject: Re: [PATCH v5 8/9] ethdev: add capability of sub-function representor

Quoted 4 lines · Xueming Li

Old DPDK version or some drivers didn't support SubFunction representor. For application to adapt different DPDK version automatically, or to be used for different NICs, this patch introduces new eth device capability of supporting SubFunction representor device.

Quoted 8 lines
Quoted 2 lines

Sorry, it does not sound sufficient motivation to introduce the capability. I simply need real life example why application need to know it.

I had same internal discussion on this as well :)
A simple example, for customer running DPDK based app with NICs from different vendors, app need a flag to know whether the device support SF representor, hotplug SF if the capability shows "support". This also happens with different model/fw even from same vendor. PMD report device+driver capability that whether SF supported.

Single feature bit is insufficient. Application needs to know how many SF may be used on which PF.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

[snip]

#90 lore raw

Re: [dpdk-dev] [PATCH v5 5/9] ethdev: support PF index in representor

In reply to Andrew Rybchenko
Quoted 95 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 5:36 PM
To: Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>
Subject: Re: [PATCH v5 5/9] ethdev: support PF index in representor

Quoted 84 lines · Xueming(Steven) Li

Hi Andrew,

Quoted 20 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 4:01 PM
To: Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>
Subject: Re: [PATCH v5 5/9] ethdev: support PF index in representor

Quoted 8 lines · Xueming Li

With Kernel bonding, multiple underlying PFs are bonded, VFs come from different PF, need to identify representor of VFs unambiguously by adding PF index.

This patch introduces optional 'pf' section to representor devargs syntax, examples:
representor=pf0vf0 - single VF representor
representor=pf[0-1]sf[0-1023] - SF representors from 2 PFs

Quoted 3 lines

Don't we need
representor=pf3
i.e. without VF or sub-function?

Standalone PF not used by Mellnaox PMD, but should be supported. Will update.

Quoted 55 lines
Quoted 24 lines
---
 doc/guides/prog_guide/poll_mode_drv.rst |  2 ++
 lib/librte_ethdev/ethdev_private.c      | 13 +++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
doc/guides/prog_guide/poll_mode_drv.rst +2 -0
index 86e5867f1b..b2147aad30 100644
@@ -382,6 +382,8 @@ parameters to those ports.
    -a DBDF,representor=sf[1,3,5]
    -a DBDF,representor=sf[0-1023]
    -a DBDF,representor=sf[0,2-4,7,9-11]
+   -a DBDF,representor=pf1vf0
+   -a DBDF,representor=pf[0-1]sf[0-127]
 
 Note: PMDs are not required to support the standard device
Quoted 2 lines

arguments and users should consult the relevant PMD documentation to see support

devargs.

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_process_list(char *str, uint16_t

Quoted 6 lines
lib/librte_ethdev/ethdev_private.c +0 -0
index d513f035d0..b9fdbd0f72 100644
@@ -120,8 +120,8 @@ rte_eth_devargs_process_list(char *str, uint16_t

*list, uint16_t *len_list,

Quoted 11 lines
lib/librte_ethdev/ethdev_private.c +2 -2
  *
  * Representor format:
  *   #: range or single number of VF representor - legacy
- *   vf#: VF port representor/s
- *   sf#: SF port representor/s
+ *   [pf#]vf#: VF port representor/s
+ *   [pf#]sf#: SF port representor/s
  *
  * Examples of #:
  *  2               - single

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char · line 140

Quoted 8 lines
lib/librte_ethdev/ethdev_private.c +5 -0
@@ -133,6 +133,14 @@ rte_eth_devargs_parse_representor_ports(char
 *str, void *data)  {
 	struct rte_eth_devargs *eth_da = data;
 
+	if (str[0] == 'p' && str[1] == 'f') {
+		eth_da->type = RTE_ETH_REPRESENTOR_PF;
+		str += 2;
+		str = rte_eth_devargs_process_list(str, eth_da->ports,
+				&eth_da->nb_ports, RTE_MAX_ETHPORTS);

May be RTE_MAX_ETHPORTS -> RTE_DIM(eth_da->ports) ?

Quoted 4 lines
Quoted 1 line

Same here, the dim could be different than MAX value.

Hold on, just for my understanding. The maximum says how many entries could be added to the array. So, why?

Right, will change to RTE_DIM(), thanks!

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char *str, void *data) · line 142

Quoted 4 lines
lib/librte_ethdev/ethdev_private.c +2 -0
+		if (str == NULL)
+			goto err;

Below we should not allow legacy VF syntax without "vf" prefix.

Quoted 5 lines
Quoted 2 lines

For backward compatibility, default numbers to "vf", otherwise some existing app like OVS that working with VF will break.

I mean if new syntax is used (i.e. we have pfX prefix), we must deny legacy syntax for VFs below.

Correct, will add check, thanks!

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_parse_representor_ports(char · line 152

Quoted 8 lines
lib/librte_ethdev/ethdev_private.c +1 -0
+	}
 	if (str[0] == 'v' && str[1] == 'f') {
 		eth_da->type = RTE_ETH_REPRESENTOR_VF;
 		str += 2;
@@ -144,6 +152,7 @@ rte_eth_devargs_parse_representor_ports(char
 *str,

void *data)

Quoted 8 lines
lib/librte_ethdev/ethdev_private.c +1 -0
 	}
 	str = rte_eth_devargs_process_list(str, eth_da->representor_ports,
 		&eth_da->nb_representor_ports, RTE_MAX_ETHPORTS);
+err:
 	if (str == NULL)
 		RTE_LOG(ERR, EAL, "wrong representor format: %s\n", str);

return str == NULL ? -1 : 0;

#65 lore raw

Re: [dpdk-dev] [PATCH v5 0/9] ethdev: support SubFunction representor

In reply to Andrew Rybchenko
Quoted 32 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 4:41 PM
To: Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v5 0/9] ethdev: support SubFunction representor

Quoted 3 lines · Xueming Li

dedicated queues(txq, rxq). A SF netdev supports E-Switch representation offload similar to existing PF and VF representors. A SF shares PCI level resources with other SFs and/or with its parent PCI

function.

Quoted 11 lines
Quoted 2 lines

From SmartNIC perspective, when PCI device is shared for multi-host,

representors for host controller and host PF is required.

This patch set introduces new representor types in addtion to existing VF representor. Syntax:

[[c#]pf#]vf#: VF port representor/s from controller/pf [[c#]pf#]sf#: SF port representor/s from controller/pf #: VF representor - for backwards compatibility

Quoted 5 lines

"#" is number instance, list or range, valid examples:
1, [1,3,5], [0-3], [0,2-4,6]

For backward compatibility, this patch also introduces new netdev capability to indicate the capability of supportting SF representor.

Quoted 7 lines

The patch series looks really nice. Thanks.

As before, my biggest concern is making representor ID a bitmap. See my comments to a specific patch.
Plus absence of defined semantics of caller function.
Basically it is looks like it is assumed that controller #0 and PF #0 is the caller. However, it could be wrong.

From devargs syntax perspective, a VF representor on PF1 could be referenced either way:

  1:  <PF0_BDF>,representor=pf1vfX
  2:  <PF1_BDF>,representor=vfX
  3:  <PF1_BDF>,representor=pf0vfX // works but not suggested, use PF0 BDF as caller

If probe a device with PF0 BDF and locate it with PF1 BDF, the device iterator will fail, devargs is parsed by api, EAL layer simply compare PCI BDF and then representor ID, i.e. "c#pf#vf#". The caller device should be consistent, better to use the first device.

Devrg "<PF1_BDF>,representor=vfX" will work, representor controller ID and pf ID default to #0, relative to caller context PF1 BDF.

Is it good to add such suggestion/behavior on rte_eth_devargs comments?

Quoted 16 lines

The next biggest concert is the absence of capability reporting API. How many controller are available?
How many PFs on each controller are available?
How many VFs on each controller/PF are available?
How many SFs?

From the first sight it sounds not that important right now and an extra feature which could be added in the follow up patches, but IMHO addition of the API would allow to avoid making representor ID a bitmap. Basically capabilities API can provide an array of available functions with representor ID assigned to each entry. Also it could make the entire patch series optional since it would allow to interpret numbers in representor=[....] as representor IDs which are mapped to controller/PF/VF/SF by the capabilities reporting API.

Quoted 2 lines

I realize that sometimes it could be more convenient to use syntax suggested here. Mainly for human.

Agree, mostly for human. Regarding to capability reporting API, how about remove current one and enhance it later with a complete patch set?

#59 lore raw

Re: [dpdk-dev] [PATCH v4 7/9] devarg: change representor ID to bitmap

In reply to Ajit Khaparde
Quoted 50 lines

-----Original Message-----
From: Ajit Khaparde <[email protected]>
Sent: Tuesday, January 19, 2021 3:02 AM
To: Xueming(Steven) Li <[email protected]>
Cc: NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>; Olivier Matz <[email protected]>; dpdk-dev <[email protected]>; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v4 7/9] devarg: change representor ID to bitmap

Quoted 35 lines · Xueming Li

The NIC can have multiple PCIe links and can be attached to multiple hosts, for example the same single NIC can be shared for multiple server units in the rack. On each PCIe link NIC can provide multiple PFs and VFs/SFs based on these ones. The full representor identifier consists of three indices - controller index, PF index, and VF or SF index (if any).

SR-IOV and SubFunction are created on top of PF. PF index is introduced because there might be multiple PFs in the bonding configuration and only bonding device is probed.

In eth representor comparator callback, ethdev was compared with devarg. Since ethdev representor port didn't contain controller index and PF index information, callback returned representor from other PF or controller.

This patch changes representor ID to bitmap so that the ethdev representor comparer callback returns correct ethdev by comparing full representor information including: controller index, PF index, representor type, SF or VF index.

Representor ID bitmap definition:
xxxx xxxx xxxx xxxx

 |||| |LLL LLLL LLLL vf/sf id
 |||| L 1:sf, 0:vf
 ||LL pf id

LL controller(host) id

This approach keeps binary compatibility with all drivers, VF representor id matches with simple id for non-bonding and non-multi-host configurations.

In the future, the representor ID field and each section should extend to bigger width to support more devices.

Quoted 6 lines
Quoted 2 lines

Not just in this patch, there is a lot of info in the commit logs. Unless I missed it, I don't see an update to doc/guides/prog_guide/switch_representation.rst
Can you please update that.

Thanks, updated in next version.

Quoted 296 lines

drivers/net/bnxt/bnxt_reps.c int bnxt_representor_init(struct rte_eth_dev

Quoted 19 lines
---
 drivers/net/bnxt/bnxt_reps.c             |  3 +-
 drivers/net/enic/enic_vf_representor.c   |  3 +-
 drivers/net/i40e/i40e_vf_representor.c   |  3 +-
 drivers/net/ixgbe/ixgbe_vf_representor.c |  3 +-
 drivers/net/mlx5/linux/mlx5_os.c         |  4 +-
 lib/librte_ethdev/ethdev_private.c       |  5 ++-
 lib/librte_ethdev/rte_class_eth.c        | 38 +++++++++++++----
 lib/librte_ethdev/rte_ethdev.c           | 26 ++++++++++++
 lib/librte_ethdev/rte_ethdev_driver.h    | 53 ++++++++++++++++++++++++
 lib/librte_ethdev/version.map            |  2 +
 10 files changed, 126 insertions(+), 14 deletions(-)
drivers/net/bnxt/bnxt_reps.c +0 -0
index f7bbf77d3f..34febc2d1e 100644
@@ -186,7 +186,8 @@ int bnxt_representor_init(struct rte_eth_dev

*eth_dev, void *params)

Review

Quoted 10 lines
drivers/net/bnxt/bnxt_reps.c +2 -1
        eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
                                        RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-       eth_dev->data->representor_id = rep_params->vf_id;
+       eth_dev->data->representor_id = rte_eth_representor_id_encode(
+               0, 0, RTE_ETH_REPRESENTOR_VF, rep_params->vf_id);
 
        rte_eth_random_addr(vf_rep_bp->dflt_mac_addr);
        memcpy(vf_rep_bp->mac_addr, vf_rep_bp->dflt_mac_addr,
(quoted diff) +0 -0

b/drivers/net/enic/enic_vf_representor.c

drivers/net/enic/enic_vf_representor.c int enic_vf_representor_init(struct rte_eth_dev

Quoted 4 lines

index c2c03c0281..632317af15 100644

drivers/net/enic/enic_vf_representor.c +0 -0
@@ -674,7 +674,8 @@ int enic_vf_representor_init(struct rte_eth_dev

*eth_dev, void *init_params)

Review

Quoted 10 lines
drivers/net/enic/enic_vf_representor.c +2 -1
        eth_dev->dev_ops = &enic_vf_representor_dev_ops;
        eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
                                        RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-       eth_dev->data->representor_id = vf->vf_id;
+       eth_dev->data->representor_id = rte_eth_representor_id_encode(
+               0, 0, RTE_ETH_REPRESENTOR_VF, vf->vf_id);
        eth_dev->data->mac_addrs = rte_zmalloc("enic_mac_addr_vf",
                sizeof(struct rte_ether_addr) *
                ENIC_UNICAST_PERFECT_FILTERS, 0);
(quoted diff) +0 -0

b/drivers/net/i40e/i40e_vf_representor.c

drivers/net/i40e/i40e_vf_representor.c i40e_vf_representor_init(struct rte_eth_dev *ethdev,

Quoted 4 lines

index 9e40406a3d..d90d0fdb9d 100644

drivers/net/i40e/i40e_vf_representor.c +0 -0
@@ -510,7 +510,8 @@ i40e_vf_representor_init(struct rte_eth_dev *ethdev,

void *init_params)

Review

Quoted 10 lines
drivers/net/i40e/i40e_vf_representor.c +2 -1
        ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR |
                                        RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
-       ethdev->data->representor_id = representor->vf_id;
+       ethdev->data->representor_id = rte_eth_representor_id_encode(
+                       0, 0, RTE_ETH_REPRESENTOR_VF, representor->vf_id);
 
        /* Setting the number queues allocated to the VF */
        ethdev->data->nb_rx_queues = vf->vsi->nb_qps;
(quoted diff) +0 -0

b/drivers/net/ixgbe/ixgbe_vf_representor.c

drivers/net/ixgbe/ixgbe_vf_representor.c ixgbe_vf_representor_init(struct rte_eth_dev

Quoted 4 lines

index 8185f0d3bb..e15b794761 100644

drivers/net/ixgbe/ixgbe_vf_representor.c +0 -0
@@ -196,7 +196,8 @@ ixgbe_vf_representor_init(struct rte_eth_dev

*ethdev, void *init_params)

Review

Quoted 10 lines
drivers/net/ixgbe/ixgbe_vf_representor.c +2 -1
                return -ENODEV;
 
        ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
-       ethdev->data->representor_id = representor->vf_id;
+       ethdev->data->representor_id = rte_eth_representor_id_encode(
+                       0, 0, RTE_ETH_REPRESENTOR_VF, representor->vf_id);
 
        /* Set representor device ops */
        ethdev->dev_ops = &ixgbe_vf_representor_dev_ops;
(quoted diff) +0 -0

b/drivers/net/mlx5/linux/mlx5_os.c

Review

Quoted 15 lines

index caead107b0..4d7940bcca 100644

drivers/net/mlx5/linux/mlx5_os.c +3 -1
@@ -1025,7 +1025,9 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 #endif
        /* representor_id field keeps the unmodified VF index. */
        priv->representor_id = switch_info->representor ?
-                              switch_info->port_name : -1;
+               rte_eth_representor_id_encode(0, 0, RTE_ETH_REPRESENTOR_VF,
+                                             switch_info->port_name) :
+               -1;
        /*
         * Look for sibling devices in order to reuse their switch domain
         * if any, otherwise allocate one.
(quoted diff) +0 -0

b/lib/librte_ethdev/ethdev_private.c

lib/librte_ethdev/ethdev_private.c rte_eth_devargs_process_list(char *str, uint16_t

Quoted 4 lines

index 57473b5a39..0b3b4aa871 100644

lib/librte_ethdev/ethdev_private.c +0 -0
@@ -106,10 +106,13 @@ rte_eth_devargs_process_list(char *str, uint16_t

*list, uint16_t *len_list,

Review

Quoted 15 lines
lib/librte_ethdev/ethdev_private.c +4 -1
 }
 
 /*
- * representor format:
+ * Parse representor ports, expand and update representor port ID.
+ * Representor format:
  *   #: range or single number of VF representor - legacy
  *   [[c#]pf#]vf#: VF port representor/s
  *   [[c#]pf#]sf#: SF port representor/s
+ *
+ * See RTE_ETH_REPR() for representor ID format.
  */
 int
 rte_eth_devargs_parse_representor_ports(char *str, void *data)
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_class_eth.c

lib/librte_ethdev/rte_ethdev.c rte_eth_devargs_parse(const char *dargs, struct

Quoted 65 lines

index efe6149df5..994db96960 100644

lib/librte_ethdev/rte_class_eth.c +30 -8
@@ -66,8 +66,8 @@ eth_representor_cmp(const char *key __rte_unused,
        int ret;
        char *values;
        const struct rte_eth_dev_data *data = opaque;
-       struct rte_eth_devargs representors;
-       uint16_t index;
+       struct rte_eth_devargs eth_da;
+       uint16_t index, c, p, f;
 
        if ((data->dev_flags & RTE_ETH_DEV_REPRESENTOR) == 0)
                return -1; /* not a representor port */
@@ -76,17 +76,39 @@ eth_representor_cmp(const char *key __rte_unused,
        values = strdup(value);
        if (values == NULL)
                return -1;
-       memset(&representors, 0, sizeof(representors));
-       ret = rte_eth_devargs_parse_representor_ports(values, &representors);
+       memset(&eth_da, 0, sizeof(eth_da));
+       ret = rte_eth_devargs_parse_representor_ports(values, &eth_da);
        free(values);
        if (ret != 0)
                return -1; /* invalid devargs value */
 
+       /* Set default values. */
+       if (eth_da.nb_mh_controllers == 0) {
+               eth_da.nb_mh_controllers = 1;
+               eth_da.mh_controllers[0] = 0;
+       }
+       if (eth_da.nb_ports == 0) {
+               eth_da.nb_ports = 1;
+               eth_da.ports[0] = 0;
+       }
+       if (eth_da.nb_representor_ports == 0) {
+               eth_da.nb_representor_ports = 1;
+               eth_da.representor_ports[0] = 0;
+       }
        /* Return 0 if representor id is matching one of the values. */
-       for (index = 0; index < representors.nb_representor_ports; index++)
-               if (data->representor_id ==
-                               representors.representor_ports[index])
-                       return 0;
+       for (c = 0; c < eth_da.nb_mh_controllers; ++c) {
+               for (p = 0; p < eth_da.nb_ports; ++p) {
+                       for (f = 0; f < eth_da.nb_representor_ports; ++f) {
+                               index = rte_eth_representor_id_encode(
+                                       eth_da.mh_controllers[c],
+                                       eth_da.ports[p],
+                                       eth_da.type,
+                                       eth_da.representor_ports[f]);
+                               if (data->representor_id == index)
+                                       return 0;
+                       }
+               }
+       }
        return -1; /* no match */
 }
 
lib/librte_ethdev/rte_ethdev.c +0 -0
index 2ac51ac149..276f42e54b 100644
@@ -5556,6 +5556,32 @@ rte_eth_devargs_parse(const char *dargs, struct

rte_eth_devargs *eth_da)

Review

Quoted 33 lines
lib/librte_ethdev/rte_ethdev.c +26 -0
        return result;
 }
 
+uint16_t
+rte_eth_representor_id_encode(uint16_t controller, uint16_t pf,
+                             enum rte_eth_representor_type type,
+                             uint16_t representor_port)
+{
+       return (((controller & 3) << 14) |
+               ((pf & 3) << 12) |
+               (!!(type == RTE_ETH_REPRESENTOR_SF) << 11) |
+               (representor_port & 0x7ff));
+}
+
+uint16_t
+rte_eth_representor_id_parse(const uint16_t representor_id,
+                            uint16_t *controller, uint16_t *pf,
+                            enum rte_eth_representor_type *type)
+{
+       if (controller)
+               *controller = (representor_id >> 14) & 3;
+       if (pf)
+               *pf = (representor_id >> 12) & 3;
+       if (type)
+               *type = ((representor_id >> 11) & 1) ?
+                       RTE_ETH_REPRESENTOR_SF : RTE_ETH_REPRESENTOR_VF;
+       return representor_id & 0x7ff;
+}
+
 static int
 eth_dev_handle_port_list(const char *cmd __rte_unused,
                const char *params __rte_unused,
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_ethdev_driver.h

lib/librte_ethdev/rte_ethdev_driver.h struct rte_eth_devargs { · line 1221

Quoted 8 lines

index 8e04634660..0d8893693e 100644

lib/librte_ethdev/rte_ethdev_driver.h +1 -0
@@ -1218,6 +1218,59 @@ struct rte_eth_devargs {
        enum rte_eth_representor_type type; /* type of representor */
 };
 
+#define RTE_NO_REPRESENTOR_ID UINT16_MAX /**< No representor ID.

*/

Quoted 71 lines
lib/librte_ethdev/rte_ethdev_driver.h +52 -0
+
+/**
+ * PMD helper function to encode representor ID
+ *
+ * The compact format is used for device iterator that comparing
+ * ethdev representor ID with target devargs.
+ *
+ * xxxx xxxx xxxx xxxx
+ * |||| |LLL LLLL LLLL vf/sf id
+ * |||| L 1:sf, 0:vf
+ * ||LL pf id
+ * LL controller(host) id
+ *
+ * @param controller
+ *  Controller ID.
+ * @param pf
+ *  PF port ID.
+ * @param type
+ *  Representor type.
+ * @param representor_port
+ *  Representor port ID.
+ *
+ * @return
+ *   Encoded representor ID.
+ */
+__rte_internal
+uint16_t
+rte_eth_representor_id_encode(uint16_t controller, uint16_t pf,
+                             enum rte_eth_representor_type type,
+                             uint16_t representor_port);
+
+/**
+ * PMD helper function to parse representor ID
+ *
+ * @param representor_id
+ *  Representor ID.
+ * @param controller
+ *  Parsed controller ID.
+ * @param pf
+ *  Parsed PF port ID.
+ * @param type
+ *  Parsed representor type.
+ *
+ * @return
+ *   Parsed representor port ID.
+ */
+__rte_internal
+uint16_t
+rte_eth_representor_id_parse(const uint16_t representor_id,
+                            uint16_t *controller, uint16_t *pf,
+                            enum rte_eth_representor_type *type);
+
 /**
  * PMD helper function to parse ethdev arguments
  *
lib/librte_ethdev/version.map +2 -1
index d3f5410806..44edaed507 100644
@@ -257,6 +257,8 @@ INTERNAL {
        rte_eth_dev_release_port;
        rte_eth_dev_internal_reset;
        rte_eth_devargs_parse;
+       rte_eth_representor_id_encode;
+       rte_eth_representor_id_parse;
        rte_eth_dma_zone_free;
        rte_eth_dma_zone_reserve;
        rte_eth_hairpin_queue_peer_bind;
--

2.25.1

#77 lore raw

Re: [dpdk-dev] [PATCH v5 0/9] ethdev: support SubFunction representor

In reply to Xueming Li
Quoted 37 lines

dedicated queues(txq, rxq). A SF netdev supports E-Switch representation offload similar to existing PF and VF representors. A SF shares PCI level resources with other SFs and/or with its parent PCI function.

From SmartNIC perspective, when PCI device is shared for multi-host, representors for host controller and host PF is required.

This patch set introduces new representor types in addtion to existing VF representor. Syntax:

[[c#]pf#]vf#: VF port representor/s from controller/pf [[c#]pf#]sf#: SF port representor/s from controller/pf #: VF representor - for backwards compatibility

"#" is number instance, list or range, valid examples:
1, [1,3,5], [0-3], [0,2-4,6]

For backward compatibility, this patch also introduces new netdev capability to indicate the capability of supportting SF representor.

Version history:
RFC:
initial version [2]
V2:
- separate patch for represnetor infrastructure, controller, pf and sf.
- replace representor ID macro with functions:
rte_eth_representor_id_encode() rte_eth_representor_id_parse()
- new patch to allow devargs with same PCI BDF but different representors.
- other minor code updates according to comments, thanks Andrew!
- update document
V3:
- improve probing of allowed devargs with same name.
- parse single word of kvargs as key.
- update kvargs test cases.

Quoted 8 lines

V4:
- split first representor refactor patch into
1: add representor type
2: refector representor list parsing
- push the patch supporting multi-devargs for same device.
V5:
- add comments for parsing functions
- update switch_representation.rst - Thanks Ajit

Hi,

The series can't recognize i40e device, so testpmd start failed.

	./x86_64-native-linuxapp-gcc/app/dpdk-testpmd -l 4-8 -n 6 -a 17:00.0 -- -i --txq=2 --rxq=2
	<...>
	EAL: Probe PCI driver: net_i40e (8086:158b) device: 0000:17:00.0 (socket 0)
	EAL: No legacy callbacks, legacy socket not created
	testpmd: No probed ethernet devices
	Interactive-mode selected
	Fail: input txq (2) can't be greater than max_tx_queues (0) of port 0
	EAL: Error - exiting with code: 1
	  Cause: txq 2 invalid - must be >= 0 && <= 0

thanks

#66 lore raw

Re: [dpdk-dev] [PATCH v5 0/9] ethdev: support SubFunction representor

In reply to Xueming(Steven) Li
Quoted 44 lines · Xueming(Steven) Li
Quoted 32 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 4:41 PM
To: Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v5 0/9] ethdev: support SubFunction representor

Quoted 3 lines · Xueming Li

dedicated queues(txq, rxq). A SF netdev supports E-Switch representation offload similar to existing PF and VF representors. A SF shares PCI level resources with other SFs and/or with its parent PCI

function.

Quoted 11 lines
Quoted 2 lines

From SmartNIC perspective, when PCI device is shared for multi-host,

representors for host controller and host PF is required.

This patch set introduces new representor types in addtion to existing VF representor. Syntax:

[[c#]pf#]vf#: VF port representor/s from controller/pf [[c#]pf#]sf#: SF port representor/s from controller/pf #: VF representor - for backwards compatibility

Quoted 5 lines

"#" is number instance, list or range, valid examples:
1, [1,3,5], [0-3], [0,2-4,6]

For backward compatibility, this patch also introduces new netdev capability to indicate the capability of supportting SF representor.

Quoted 7 lines

The patch series looks really nice. Thanks.

As before, my biggest concern is making representor ID a bitmap. See my comments to a specific patch.
Plus absence of defined semantics of caller function.
Basically it is looks like it is assumed that controller #0 and PF #0 is the caller. However, it could be wrong.

From devargs syntax perspective, a VF representor on PF1 could be referenced either way:

  1:  <PF0_BDF>,representor=pf1vfX
  2:  <PF1_BDF>,representor=vfX
  3:  <PF1_BDF>,representor=pf0vfX // works but not suggested, use PF0 BDF as caller
Quoted 8 lines

If probe a device with PF0 BDF and locate it with PF1 BDF, the device iterator will fail, devargs is parsed by api, EAL layer simply compare PCI BDF and then representor ID, i.e. "c#pf#vf#". The caller device should be consistent, better to use the first device.

Devrg "<PF1_BDF>,representor=vfX" will work, representor controller ID and pf ID default to #0, relative to caller context PF1 BDF.

Is it good to add such suggestion/behavior on rte_eth_devargs comments?

Sorry, but I disagree. Solution with vf1 and pf0vf1 making the same representor ID sounds not acceptable to me. It is definitely different things if I pass it to PF1.

Quoted 16 lines
Quoted 16 lines

The next biggest concert is the absence of capability reporting API. How many controller are available?
How many PFs on each controller are available?
How many VFs on each controller/PF are available?
How many SFs?

From the first sight it sounds not that important right now and an extra feature which could be added in the follow up patches, but IMHO addition of the API would allow to avoid making representor ID a bitmap. Basically capabilities API can provide an array of available functions with representor ID assigned to each entry. Also it could make the entire patch series optional since it would allow to interpret numbers in representor=[....] as representor IDs which are mapped to controller/PF/VF/SF by the capabilities reporting API.

Quoted 6 lines
Quoted 2 lines

I realize that sometimes it could be more convenient to use syntax suggested here. Mainly for human.

Agree, mostly for human. Regarding to capability reporting API, how about remove current one and enhance it later with a complete patch set?

Current one? Sorry I don't understand.

Andrew.

#67 lore raw

Re: [dpdk-dev] [PATCH v5 0/9] ethdev: support SubFunction representor

Hi Andrew,

Quoted 63 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Friday, January 22, 2021 4:21 PM
To: Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v5 0/9] ethdev: support SubFunction representor

Quoted 34 lines · Xueming(Steven) Li
Quoted 34 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 4:41 PM
To: Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v5 0/9] ethdev: support SubFunction representor

Quoted 4 lines · Xueming Li

dedicated queues(txq, rxq). A SF netdev supports E-Switch representation offload similar to existing PF and VF representors. A SF shares PCI level resources with other SFs and/or with its parent PCI

function.

Quoted 17 lines
Quoted 3 lines

From SmartNIC perspective, when PCI device is shared for multi-host,

representors for host controller and host PF is required.

This patch set introduces new representor types in addtion to existing VF representor. Syntax:

[[c#]pf#]vf#: VF port representor/s from controller/pf [[c#]pf#]sf#: SF port representor/s from controller/pf #: VF representor - for backwards compatibility

"#" is number instance, list or range, valid examples:
1, [1,3,5], [0-3], [0,2-4,6]

For backward compatibility, this patch also introduces new netdev capability to indicate the capability of supportting SF representor.

Quoted 6 lines
Quoted 6 lines

The patch series looks really nice. Thanks.

As before, my biggest concern is making representor ID a bitmap. See my comments to a specific patch.
Plus absence of defined semantics of caller function.
Basically it is looks like it is assumed that controller #0 and PF #0 is the

caller.

Quoted 3 lines
Quoted 1 line

However, it could be wrong.

From devargs syntax perspective, a VF representor on PF1 could be

referenced either way:

Quoted 6 lines
  1:  <PF0_BDF>,representor=pf1vfX
  2:  <PF1_BDF>,representor=vfX
  3:  <PF1_BDF>,representor=pf0vfX // works but not suggested, use PF0

BDF as caller If probe a device with PF0 BDF and locate it with PF1 BDF, the device iterator will fail, devargs is parsed by api, EAL layer simply compare PCI BDF and then representor ID, i.e. "c#pf#vf#". The

caller device should be consistent, better to use the first device.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

Devrg "<PF1_BDF>,representor=vfX" will work, representor controller ID and pf ID default to #0, relative to caller context PF1 BDF.

Is it good to add such suggestion/behavior on rte_eth_devargs comments?

Sorry, but I disagree. Solution with vf1 and pf0vf1 making the same representor ID sounds not acceptable to me. It is definitely different things if I pass it to PF1.

My understanding is that representor is an "offset" to caller(context) PF, so the caller PF has to be the lowest, i.e. PF0. The usage for mlx5 PMD is to probe VF representor on a kernel bonding:
1. PF0 is the only device for PMD to probe the bonding device, PMD detects underlay PFs.
2. PF0_BDF,reprensetor=pf1vf0, to probe the representor for first VF on PF1. PF1_BDF,reprenstor=pf0vf0 works for the same representor, but not encouraged because it confuses EAL device iterator which can't tell the difference, as you said: "mainly for human"

Controller ID is not used by mlx5 PMD currently, just a place holder for now, but I think same policy applies: lowest as caller(context).

Your suggestion of reserving an c# and pf# ID for caller device which c# or pf# not specified looks good, it makes the usage of the representor ID bitmap flexible, but considering some NIC with 4 PFs, it's hard to choose, as you know, only 3 controller and 3 PFs left.

BTW, I guess your assumption is that representor as "absolute" to caller PF, can't default to 0. Is there a scenario for PF1 as caller?

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines

The next biggest concert is the absence of capability reporting API. How many controller are available?
How many PFs on each controller are available?
How many VFs on each controller/PF are available?
How many SFs?

From the first sight it sounds not that important right now and an extra feature which could be added in the follow up patches, but IMHO addition of the API would allow to avoid making representor ID a bitmap. Basically capabilities API can provide an array of available functions with representor ID assigned to each entry. Also it could make the entire patch series optional since it would allow to interpret numbers in representor=[....] as representor IDs which are mapped to controller/PF/VF/SF by the capabilities reporting API.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I realize that sometimes it could be more convenient to use syntax suggested here. Mainly for human.

Agree, mostly for human. Regarding to capability reporting API, how about remove current one and enhance it later with a complete patch set?

Current one? Sorry I don't understand.

The patch of device SF capability, but seems I misunderstood your suggestion.
Let me explain process to create a SF:
1. SF can be created on the fly with scripts, unlike VF which is statically pre-created.
2. SF is created on a PF with a SF number. SF number is named per PF, different PF may have same SF number.
3. For standalone PF, hot plug to DPDK using "PF#_BDF,representor=sf#", no need to use pf#sf# here.
4. For bonding netdev, hot plug to DPDK using "PF0_BDF,representor=pf#sf#"
If using new api to return all representor IDs, need some way locate the new created SF by PF and SF number, that's why "pf#sf#" is used in this patch set.

In the future, I think representor could be processed by PMD, so PMD could have enough flexibility to support more device expressions and types. But that will introduce a fundamental change of devargs and device management, need a full plan.

Quoted 2 lines

Andrew.

#68 lore raw

Re: [dpdk-dev] [PATCH v5 0/9] ethdev: support SubFunction representor

Quoted 68 lines · Xueming(Steven) Li

Hi Andrew,

Quoted 66 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Friday, January 22, 2021 4:21 PM
To: Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v5 0/9] ethdev: support SubFunction representor

Quoted 34 lines · Xueming(Steven) Li
Quoted 34 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, January 19, 2021 4:41 PM
To: Xueming(Steven) Li <[email protected]>
Cc: [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v5 0/9] ethdev: support SubFunction representor

Quoted 4 lines · Xueming Li

dedicated queues(txq, rxq). A SF netdev supports E-Switch representation offload similar to existing PF and VF representors. A SF shares PCI level resources with other SFs and/or with its parent PCI

function.

Quoted 17 lines
Quoted 3 lines

From SmartNIC perspective, when PCI device is shared for multi-host,

representors for host controller and host PF is required.

This patch set introduces new representor types in addtion to existing VF representor. Syntax:

[[c#]pf#]vf#: VF port representor/s from controller/pf [[c#]pf#]sf#: SF port representor/s from controller/pf #: VF representor - for backwards compatibility

"#" is number instance, list or range, valid examples:
1, [1,3,5], [0-3], [0,2-4,6]

For backward compatibility, this patch also introduces new netdev capability to indicate the capability of supportting SF representor.

Quoted 6 lines
Quoted 6 lines

The patch series looks really nice. Thanks.

As before, my biggest concern is making representor ID a bitmap. See my comments to a specific patch.
Plus absence of defined semantics of caller function.
Basically it is looks like it is assumed that controller #0 and PF #0 is the

caller.

Quoted 3 lines
Quoted 1 line

However, it could be wrong.

From devargs syntax perspective, a VF representor on PF1 could be

referenced either way:

Quoted 6 lines
  1:  <PF0_BDF>,representor=pf1vfX
  2:  <PF1_BDF>,representor=vfX
  3:  <PF1_BDF>,representor=pf0vfX // works but not suggested, use PF0

BDF as caller If probe a device with PF0 BDF and locate it with PF1 BDF, the device iterator will fail, devargs is parsed by api, EAL layer simply compare PCI BDF and then representor ID, i.e. "c#pf#vf#". The

caller device should be consistent, better to use the first device.

Quoted 4 lines

Devrg "<PF1_BDF>,representor=vfX" will work, representor controller ID and pf ID default to #0, relative to caller context PF1 BDF.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Is it good to add such suggestion/behavior on rte_eth_devargs comments?

Sorry, but I disagree. Solution with vf1 and pf0vf1 making the same representor ID sounds not acceptable to me. It is definitely different things if I pass it to PF1.

My understanding is that representor is an "offset" to caller(context) PF, so the caller PF has to be the lowest, i.e. PF0.

Sorry, how to address PF0 from PF1?

Quoted 7 lines

The usage for mlx5 PMD is to probe VF
representor on a kernel bonding:
1. PF0 is the only device for PMD to probe the bonding device, PMD detects underlay PFs.
2. PF0_BDF,reprensetor=pf1vf0, to probe the representor for first VF on PF1. PF1_BDF,reprenstor=pf0vf0 works for the same representor, but not encouraged because it confuses EAL device iterator which can't tell the difference, as you said: "mainly for human"

Quoted 6 lines

Controller ID is not used by mlx5 PMD currently, just a place holder for now, but I think same policy applies: lowest as caller(context).

Your suggestion of reserving an c# and pf# ID for caller device which c# or pf# not specified looks good, it makes the usage of the representor ID bitmap flexible, but considering some NIC with 4 PFs, it's hard to choose, as you know, only 3 controller and 3 PFs left.

I'd prefer the option if we make a choice between these two. At least it a bit more consistent.
But IMHO anyway bitmap is a road to wrong direction.

Quoted 2 lines

BTW, I guess your assumption is that representor as "absolute" to caller PF, can't default to 0. Is there a scenario for PF1 as caller?

Yes.

Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 16 lines

The next biggest concert is the absence of capability reporting API. How many controller are available?
How many PFs on each controller are available?
How many VFs on each controller/PF are available?
How many SFs?

From the first sight it sounds not that important right now and an extra feature which could be added in the follow up patches, but IMHO addition of the API would allow to avoid making representor ID a bitmap. Basically capabilities API can provide an array of available functions with representor ID assigned to each entry. Also it could make the entire patch series optional since it would allow to interpret numbers in representor=[....] as representor IDs which are mapped to controller/PF/VF/SF by the capabilities reporting API.

Quoted 2 lines

I realize that sometimes it could be more convenient to use syntax suggested here. Mainly for human.

Agree, mostly for human. Regarding to capability reporting API, how about remove current one and enhance it later with a complete patch set?

Quoted 5 lines
Quoted 1 line

Current one? Sorry I don't understand.

The patch of device SF capability, but seems I misunderstood your suggestion. Let me explain process to create a SF:
1. SF can be created on the fly with scripts, unlike VF which is statically pre-created.

Is there a maximum index and maximum total number of SF's created? How to find it?

Quoted 5 lines

2. SF is created on a PF with a SF number. SF number is named per PF, different PF may have same SF number.
3. For standalone PF, hot plug to DPDK using "PF#_BDF,representor=sf#", no need to use pf#sf# here.
4. For bonding netdev, hot plug to DPDK using "PF0_BDF,representor=pf#sf#"
If using new api to return all representor IDs, need some way locate the new created SF by PF and SF number, that's why "pf#sf#" is used in this patch set.

I think the API should simply reserve/report space for maximum number of SFs. So, IDs are stable across restart/reboot in assumption that NIC is not reconfigured (changed maximum number of VF or maximum number of SFs of any PF).

Quoted 8 lines

In the future, I think representor could be processed by PMD, so PMD could have enough flexibility to support more device expressions and types. But that will introduce a fundamental change of devargs and device management, need a full plan.

Quoted 2 lines

Andrew.

#75 lore raw

Re: [dpdk-dev] [PATCH v5 0/9] ethdev: support SubFunction representor

In reply to Xueming(Steven) Li
Quoted 1 line · Xueming(Steven) Li

::::[snip]::::

Quoted 9 lines

The patch of device SF capability, but seems I misunderstood your suggestion.
Let me explain process to create a SF:
1. SF can be created on the fly with scripts, unlike VF which is statically pre-created.
2. SF is created on a PF with a SF number. SF number is named per PF, different PF may have same SF number.
3. For standalone PF, hot plug to DPDK using "PF#_BDF,representor=sf#", no need to use pf#sf# here.
4. For bonding netdev, hot plug to DPDK using "PF0_BDF,representor=pf#sf#"
If using new api to return all representor IDs, need some way locate the new created SF by PF and SF number, that's why "pf#sf#" is used in this patch set.

Quoted 3 lines

In the future, I think representor could be processed by PMD, so PMD could have enough flexibility to support more device expressions and types. But that will introduce a fundamental change of devargs and device management, need a full plan.

Do you mean all changes will be contained within the PMD? The fundamental changes will be in the PMD?
More types of what?

Quoted 4 lines
Quoted 3 lines

Andrew.

#76 lore raw

Re: [dpdk-dev] [PATCH v5 0/9] ethdev: support SubFunction representor

Hi Ajit,

Quoted 28 lines

-----Original Message-----
From: Ajit Khaparde <[email protected]>
Sent: Thursday, January 28, 2021 1:43 AM
To: Xueming(Steven) Li <[email protected]>
Cc: Andrew Rybchenko <[email protected]>; [email protected]; Slava Ovsiienko <[email protected]>; Asaf Penso <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v5 0/9] ethdev: support SubFunction representor

Quoted 1 line · Xueming(Steven) Li

::::[snip]::::

Quoted 1 line

The patch of device SF capability, but seems I misunderstood your

suggestion.

Quoted 2 lines

Let me explain process to create a SF:
1. SF can be created on the fly with scripts, unlike VF which is statically pre-

created.

Quoted 1 line

2. SF is created on a PF with a SF number. SF number is named per PF,

different PF may have same SF number.

Quoted 1 line

3. For standalone PF, hot plug to DPDK using "PF#_BDF,representor=sf#", no

need to use pf#sf# here.

Quoted 1 line

4. For bonding netdev, hot plug to DPDK using

"PF0_BDF,representor=pf#sf#"

Quoted 1 line

If using new api to return all representor IDs, need some way locate the new

created SF by PF and SF number,

Quoted 2 lines

that's why "pf#sf#" is used in this patch set.

Quoted 7 lines
Quoted 1 line

In the future, I think representor could be processed by PMD, so PMD could

have enough flexibility

Quoted 1 line

to support more device expressions and types. But that will introduce a

fundamental change of devargs and

Quoted 1 line

device management, need a full plan.

Do you mean all changes will be contained within the PMD? The fundamental changes will be in the PMD?

Yes, PMD detect device type and IDs from devargs and figure out a unique name for device.

Quoted 1 line

More types of what?

SF, representor of SF, representor of VF...

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

Andrew.

#69 lore raw

Re: [dpdk-dev] [PATCH v5 0/9] ethdev: support SubFunction representor

In reply to Andrew Rybchenko

<snip>

Quoted 5 lines
Quoted 3 lines

The patch of device SF capability, but seems I misunderstood your suggestion. Let me explain process to create a SF:
1. SF can be created on the fly with scripts, unlike VF which is statically pre-created.

Is there a maximum index and maximum total number of SF's created? How to find it?

The maximum index is defined by firmware configuration, all SF's information could be found from sysfs. To create a SF, both PCI and sfnum have to be specified.

Quoted 9 lines
Quoted 6 lines

2. SF is created on a PF with a SF number. SF number is named per PF, different PF may have same SF number.
3. For standalone PF, hot plug to DPDK using "PF#_BDF,representor=sf#", no need to use pf#sf# here.
4. For bonding netdev, hot plug to DPDK using "PF0_BDF,representor=pf#sf#"
If using new api to return all representor IDs, need some way locate
the new created SF by PF and SF number, that's why "pf#sf#" is used in this patch set.

I think the API should simply reserve/report space for maximum number of SFs. So, IDs are stable across restart/reboot in assumption that NIC is not reconfigured (changed maximum number of VF or maximum number of SFs of any PF).

Yes, IDs should be stable as long as no NIC firmware configuration change.

Just clarify, this api should be common enough to report all devices that a bus device supports:
1. name, might contains controller and pf info, example: "eth:representor:c0pf1vf"
2. ID range, example: 0-127
The api describes ID ranges for each sub device type, users have to query the api and choose representor ID to probe.

Prototype:

struct rte_bus_device_range {
	char name[64];
	uint32_t base;
	uint32_t number;
}

/* return number of ranges filled, or number of ranges if list is NULL. */ int rte_bus_ dev_range_get(struct rte_bus_device_range *list, int n);

Quoted 1 line

<snip>

#70 lore raw

Re: [dpdk-dev] [PATCH v5 0/9] ethdev: support SubFunction representor

Quoted 9 lines · Xueming(Steven) Li

<snip>

Quoted 5 lines
Quoted 3 lines

The patch of device SF capability, but seems I misunderstood your suggestion. Let me explain process to create a SF:
1. SF can be created on the fly with scripts, unlike VF which is statically pre-created.

Is there a maximum index and maximum total number of SF's created? How to find it?

The maximum index is defined by firmware configuration, all SF's information could be found from sysfs. To create a SF, both PCI and sfnum have to be specified.

sysfs is obviously Linux specific. I think the information should be available via DPDK API.

Quoted 17 lines
Quoted 9 lines
Quoted 6 lines

2. SF is created on a PF with a SF number. SF number is named per PF, different PF may have same SF number.
3. For standalone PF, hot plug to DPDK using "PF#_BDF,representor=sf#", no need to use pf#sf# here.
4. For bonding netdev, hot plug to DPDK using "PF0_BDF,representor=pf#sf#"
If using new api to return all representor IDs, need some way locate
the new created SF by PF and SF number, that's why "pf#sf#" is used in this patch set.

I think the API should simply reserve/report space for maximum number of SFs. So, IDs are stable across restart/reboot in assumption that NIC is not reconfigured (changed maximum number of VF or maximum number of SFs of any PF).

Yes, IDs should be stable as long as no NIC firmware configuration change.

Just clarify, this api should be common enough to report all devices that a bus device supports:
1. name, might contains controller and pf info, example: "eth:representor:c0pf1vf"
2. ID range, example: 0-127
The api describes ID ranges for each sub device type, users have to query the api and choose representor ID to probe.

Quoted 8 lines

Prototype:

struct rte_bus_device_range {
	char name[64];
	uint32_t base;
	uint32_t number;
}

/* return number of ranges filled, or number of ranges if list is NULL. */ int rte_bus_ dev_range_get(struct rte_bus_device_range *list, int n);

Hm, I thought about more port representor specific API. For me it is hard to tell if such generic naming is good or bad. I think it should be proven that such generic API makes sense. Any other potential users / use cases?

I've considered ethdev API which returns (in similar way as above) list of possible port representors which could be controlled by the device. Also I think it would be useful to include type information (enum with PF, VF, SF), controller ID.

There is one more bit which is not in the picture yet - switch_info.port_id. Should it be equal to representor ID? Or different and provided in the info structure?