[dpdk-dev,v1,03/48] net/mlx4: check max number of ports dynamically

Message ID 04ea7bf54d1ddba834fb187ae169b3de79b5aaa0.1501598384.git.adrien.mazarguil@6wind.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Adrien Mazarguil Aug. 1, 2017, 4:53 p.m. UTC
  Use maximum number reported by hardware capabilities as replacement for the
static check on MLX4_PMD_MAX_PHYS_PORTS.

Cc: Gaëtan Rivet <gaetan.rivet@6wind.com>
Cc: Allain Legacy <allain.legacy@windriver.com>
Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
 drivers/net/mlx4/mlx4.c | 43 +++++++++++++++++++++++++------------------
 drivers/net/mlx4/mlx4.h |  3 ---
 2 files changed, 25 insertions(+), 21 deletions(-)
  

Comments

Allain Legacy Aug. 1, 2017, 5:35 p.m. UTC | #1
> -----Original Message-----

> From: Adrien Mazarguil [mailto:adrien.mazarguil@6wind.com]

> Sent: Tuesday, August 01, 2017 12:54 PM

<...>
> @@ -5946,12 +5949,11 @@ mlx4_arg_parse(const char *key, const char *val,

> void *out)

>  		return -errno;

>  	}

>  	if (strcmp(MLX4_PMD_PORT_KVARG, key) == 0) {

> -		if (tmp >= MLX4_PMD_MAX_PHYS_PORTS) {

> -			ERROR("invalid port index %lu (max: %u)",

> -				tmp, MLX4_PMD_MAX_PHYS_PORTS - 1);

> +		if (!(conf->ports.present & (1 << tmp))) {

> +			ERROR("invalid port index %lu", tmp);


The original error included the max value.  Wouldn't it be useful to report this to the 
user to help them understand their mistake?


> @@ -6085,16 +6092,16 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv,

> struct rte_pci_device *pci_dev)

>  	}

>  	INFO("%u port(s) detected", device_attr.phys_port_cnt);

> 

> +	for (i = 0; i < device_attr.phys_port_cnt; ++i)

> +		conf.ports.present |= 1 << i;


The loop could be avoided with:

	conf.ports.present = (1 << device_attr.phys_port_cnt) - 1;


Regards,
Allain
  
Adrien Mazarguil Aug. 2, 2017, 7:52 a.m. UTC | #2
On Tue, Aug 01, 2017 at 05:35:30PM +0000, Legacy, Allain wrote:
> > -----Original Message-----
> > From: Adrien Mazarguil [mailto:adrien.mazarguil@6wind.com]
> > Sent: Tuesday, August 01, 2017 12:54 PM
> <...>
> > @@ -5946,12 +5949,11 @@ mlx4_arg_parse(const char *key, const char *val,
> > void *out)
> >  		return -errno;
> >  	}
> >  	if (strcmp(MLX4_PMD_PORT_KVARG, key) == 0) {
> > -		if (tmp >= MLX4_PMD_MAX_PHYS_PORTS) {
> > -			ERROR("invalid port index %lu (max: %u)",
> > -				tmp, MLX4_PMD_MAX_PHYS_PORTS - 1);
> > +		if (!(conf->ports.present & (1 << tmp))) {
> > +			ERROR("invalid port index %lu", tmp);
> 
> The original error included the max value.  Wouldn't it be useful to report this to the 
> user to help them understand their mistake?

Makes sense, I'll add it back.

> > @@ -6085,16 +6092,16 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv,
> > struct rte_pci_device *pci_dev)
> >  	}
> >  	INFO("%u port(s) detected", device_attr.phys_port_cnt);
> > 
> > +	for (i = 0; i < device_attr.phys_port_cnt; ++i)
> > +		conf.ports.present |= 1 << i;
> 
> The loop could be avoided with:
> 
> 	conf.ports.present = (1 << device_attr.phys_port_cnt) - 1;

I will also make that change in the next iteration, thanks.
  

Patch

diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c
index 0ae78e0..e28928c 100644
--- a/drivers/net/mlx4/mlx4.c
+++ b/drivers/net/mlx4/mlx4.c
@@ -118,8 +118,12 @@  struct mlx4_secondary_data {
 	rte_spinlock_t lock; /* Port configuration lock. */
 } mlx4_secondary_data[RTE_MAX_ETHPORTS];
 
+/** Configuration structure for device arguments. */
 struct mlx4_conf {
-	uint8_t active_ports;
+	struct {
+		uint32_t present; /**< Bit-field for existing ports. */
+		uint32_t enabled; /**< Bit-field for user-enabled ports. */
+	} ports;
 };
 
 /* Available parameters list. */
@@ -5927,16 +5931,15 @@  mlx4_rx_intr_disable(struct rte_eth_dev *dev, uint16_t idx)
  *   Key argument to verify.
  * @param[in] val
  *   Value associated with key.
- * @param out
- *   User data.
+ * @param[in, out] conf
+ *   Shared configuration data.
  *
  * @return
  *   0 on success, negative errno value on failure.
  */
 static int
-mlx4_arg_parse(const char *key, const char *val, void *out)
+mlx4_arg_parse(const char *key, const char *val, struct mlx4_conf *conf)
 {
-	struct mlx4_conf *conf = out;
 	unsigned long tmp;
 
 	errno = 0;
@@ -5946,12 +5949,11 @@  mlx4_arg_parse(const char *key, const char *val, void *out)
 		return -errno;
 	}
 	if (strcmp(MLX4_PMD_PORT_KVARG, key) == 0) {
-		if (tmp >= MLX4_PMD_MAX_PHYS_PORTS) {
-			ERROR("invalid port index %lu (max: %u)",
-				tmp, MLX4_PMD_MAX_PHYS_PORTS - 1);
+		if (!(conf->ports.present & (1 << tmp))) {
+			ERROR("invalid port index %lu", tmp);
 			return -EINVAL;
 		}
-		conf->active_ports |= 1 << tmp;
+		conf->ports.enabled |= 1 << tmp;
 	} else {
 		WARN("%s: unknown parameter", key);
 		return -EINVAL;
@@ -5987,8 +5989,13 @@  mlx4_args(struct rte_devargs *devargs, struct mlx4_conf *conf)
 	for (i = 0; pmd_mlx4_init_params[i]; ++i) {
 		arg_count = rte_kvargs_count(kvlist, MLX4_PMD_PORT_KVARG);
 		while (arg_count-- > 0) {
-			ret = rte_kvargs_process(kvlist, MLX4_PMD_PORT_KVARG,
-					mlx4_arg_parse, conf);
+			ret = rte_kvargs_process(kvlist,
+						 MLX4_PMD_PORT_KVARG,
+						 (int (*)(const char *,
+							  const char *,
+							  void *))
+						 mlx4_arg_parse,
+						 conf);
 			if (ret != 0)
 				goto free_kvlist;
 		}
@@ -6023,7 +6030,7 @@  mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 	struct ibv_context *attr_ctx = NULL;
 	struct ibv_device_attr device_attr;
 	struct mlx4_conf conf = {
-		.active_ports = 0,
+		.ports.present = 0,
 	};
 	unsigned int vf;
 	int i;
@@ -6085,16 +6092,16 @@  mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 	}
 	INFO("%u port(s) detected", device_attr.phys_port_cnt);
 
+	for (i = 0; i < device_attr.phys_port_cnt; ++i)
+		conf.ports.present |= 1 << i;
 	if (mlx4_args(pci_dev->device.devargs, &conf)) {
 		ERROR("failed to process device arguments");
 		err = EINVAL;
 		goto error;
 	}
 	/* Use all ports when none are defined */
-	if (conf.active_ports == 0) {
-		for (i = 0; i < MLX4_PMD_MAX_PHYS_PORTS; i++)
-			conf.active_ports |= 1 << i;
-	}
+	if (!conf.ports.enabled)
+		conf.ports.enabled = conf.ports.present;
 	for (i = 0; i < device_attr.phys_port_cnt; i++) {
 		uint32_t port = i + 1; /* ports are indexed from one */
 		struct ibv_context *ctx = NULL;
@@ -6107,8 +6114,8 @@  mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 #endif /* HAVE_EXP_QUERY_DEVICE */
 		struct ether_addr mac;
 
-		/* If port is not active, skip. */
-		if (!(conf.active_ports & (1 << i)))
+		/* If port is not enabled, skip. */
+		if (!(conf.ports.enabled & (1 << i)))
 			continue;
 #ifdef HAVE_EXP_QUERY_DEVICE
 		exp_device_attr.comp_mask = IBV_EXP_DEVICE_ATTR_EXP_CAP_FLAGS;
diff --git a/drivers/net/mlx4/mlx4.h b/drivers/net/mlx4/mlx4.h
index 6421c91..25a7212 100644
--- a/drivers/net/mlx4/mlx4.h
+++ b/drivers/net/mlx4/mlx4.h
@@ -81,9 +81,6 @@ 
 /* Request send completion once in every 64 sends, might be less. */
 #define MLX4_PMD_TX_PER_COMP_REQ 64
 
-/* Maximum number of physical ports. */
-#define MLX4_PMD_MAX_PHYS_PORTS 2
-
 /* Maximum number of Scatter/Gather Elements per Work Request. */
 #ifndef MLX4_PMD_SGE_WR_N
 #define MLX4_PMD_SGE_WR_N 4