svn commit: r347810 - stable/11/sys/dev/mlx5/mlx5_en

Hans Petter Selasky hselasky at FreeBSD.org
Thu May 16 17:21:29 UTC 2019


Author: hselasky
Date: Thu May 16 17:21:27 2019
New Revision: 347810
URL: https://svnweb.freebsd.org/changeset/base/347810

Log:
  MFC r347260 and r347326:
  Correct number of elements for priority to traffic class mappings in mlx5en(4).
  
  The number of priorities is always 8, while the number of traffic classes
  supported can vary. While at it convert the sysctl node into an array.
  
  Sponsored by:	Mellanox Technologies

Modified:
  stable/11/sys/dev/mlx5/mlx5_en/en.h
  stable/11/sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c
  stable/11/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/mlx5/mlx5_en/en.h
==============================================================================
--- stable/11/sys/dev/mlx5/mlx5_en/en.h	Thu May 16 17:19:48 2019	(r347809)
+++ stable/11/sys/dev/mlx5/mlx5_en/en.h	Thu May 16 17:21:27 2019	(r347810)
@@ -72,6 +72,9 @@
 #include <dev/mlx5/mlx5_core/transobj.h>
 #include <dev/mlx5/mlx5_core/mlx5_core.h>
 
+#define	MLX5E_MAX_PRIORITY 8
+
+/* IEEE 802.1Qaz standard supported values */
 #define	IEEE_8021QAZ_MAX_TCS	8
 
 #define	MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE                0x7
@@ -481,10 +484,10 @@ struct mlx5e_params {
 	u16	rx_hash_log_tbl_sz;
 	u32	tx_pauseframe_control __aligned(4);
 	u32	rx_pauseframe_control __aligned(4);
-	u32	tx_priority_flow_control __aligned(4);
-	u32	rx_priority_flow_control __aligned(4);
 	u16	tx_max_inline;
 	u8	tx_min_inline_mode;
+	u8	tx_priority_flow_control;
+	u8	rx_priority_flow_control;
 	u8	channels_rsss;
 };
 
@@ -523,7 +526,7 @@ struct mlx5e_params_ethtool {
 	MLX5E_PARAMS(MLX5E_STATS_VAR)
 	u64	max_bw_value[IEEE_8021QAZ_MAX_TCS];
 	u8	max_bw_share[IEEE_8021QAZ_MAX_TCS];
-	u8	prio_tc[IEEE_8021QAZ_MAX_TCS];
+	u8	prio_tc[MLX5E_MAX_PRIORITY];
 	u8	dscp2prio[MLX5_MAX_SUPPORTED_DSCP];
 	u8	trust_state;
 };

Modified: stable/11/sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c
==============================================================================
--- stable/11/sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c	Thu May 16 17:19:48 2019	(r347809)
+++ stable/11/sys/dev/mlx5/mlx5_en/mlx5_en_ethtool.c	Thu May 16 17:21:27 2019	(r347810)
@@ -298,8 +298,8 @@ mlx5e_get_prio_tc(struct mlx5e_priv *priv)
 		return (EOPNOTSUPP);
 	}
 
-	for (i = 0; i <= mlx5_max_tc(priv->mdev); i++) {
-		err = -mlx5_query_port_prio_tc(mdev, i, &(priv->params_ethtool.prio_tc[i]));
+	for (i = 0; i != MLX5E_MAX_PRIORITY; i++) {
+		err = -mlx5_query_port_prio_tc(mdev, i, priv->params_ethtool.prio_tc + i);
 		if (err)
 			break;
 	}
@@ -311,29 +311,35 @@ static int
 mlx5e_prio_to_tc_handler(SYSCTL_HANDLER_ARGS)
 {
 	struct mlx5e_priv *priv = arg1;
-	int prio_index = arg2;
 	struct mlx5_core_dev *mdev = priv->mdev;
+	uint8_t temp[MLX5E_MAX_PRIORITY];
 	int err;
-	uint8_t result;
+	int i;
 
 	PRIV_LOCK(priv);
-	result = priv->params_ethtool.prio_tc[prio_index];
-	err = sysctl_handle_8(oidp, &result, 0, req);
-	if (err || !req->newptr ||
-	    result == priv->params_ethtool.prio_tc[prio_index])
+	err = SYSCTL_OUT(req, priv->params_ethtool.prio_tc, MLX5E_MAX_PRIORITY);
+	if (err || !req->newptr)
 		goto done;
-
-	if (result > mlx5_max_tc(mdev)) {
-		err = ERANGE;
-		goto done;
-	}
-
-	err = -mlx5_set_port_prio_tc(mdev, prio_index, result);
+	err = SYSCTL_IN(req, temp, MLX5E_MAX_PRIORITY);
 	if (err)
 		goto done;
 
-	priv->params_ethtool.prio_tc[prio_index] = result;
+	for (i = 0; i != MLX5E_MAX_PRIORITY; i++) {
+		if (temp[i] > mlx5_max_tc(mdev)) {
+			err = ERANGE;
+			goto done;
+		}
+	}
 
+	for (i = 0; i != MLX5E_MAX_PRIORITY; i++) {
+		if (temp[i] == priv->params_ethtool.prio_tc[i])
+			continue;
+		err = -mlx5_set_port_prio_tc(mdev, i, temp[i]);
+		if (err)
+			goto done;
+		/* update cached value */
+		priv->params_ethtool.prio_tc[i] = temp[i];
+	}
 done:
 	PRIV_UNLOCK(priv);
 	return (err);
@@ -1135,7 +1141,6 @@ mlx5e_create_diagnostics(struct mlx5e_priv *priv)
 void
 mlx5e_create_ethtool(struct mlx5e_priv *priv)
 {
-	struct mlx5_core_dev *mdev = priv->mdev;
 	struct sysctl_oid *node, *qos_node;
 	const char *pnameunit;
 	unsigned x;
@@ -1262,14 +1267,10 @@ mlx5e_create_ethtool(struct mlx5e_priv *priv)
 
 	/* Priority to traffic class mapping */
 	if (mlx5e_get_prio_tc(priv) == 0) {
-		for (i = 0; i <= mlx5_max_tc(mdev); i++) {
-			char name[32];
-			snprintf(name, sizeof(name), "prio_%d_to_tc", i);
-			SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(qos_node),
-				OID_AUTO, name, CTLTYPE_U8 | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
-				priv, i, mlx5e_prio_to_tc_handler, "CU",
-				"Set priority to traffic class");
-		}
+		SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(qos_node),
+		    OID_AUTO, "prio_0_7_tc", CTLTYPE_U8 | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
+		    priv, 0, mlx5e_prio_to_tc_handler, "CU",
+		    "Set traffic class 0 to 7 for priority 0 to 7 inclusivly");
 	}
 
 	/* DSCP support */
@@ -1287,7 +1288,7 @@ mlx5e_create_ethtool(struct mlx5e_priv *priv)
 		SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(qos_node),
 		    OID_AUTO, "trust_state", CTLTYPE_U8 | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
 		    priv, 0, mlx5e_trust_state_handler, "CU",
-		    MLX5_CAP_QCAM_FEATURE(mdev, qpts_trust_both) ?
+		    MLX5_CAP_QCAM_FEATURE(priv->mdev, qpts_trust_both) ?
 		    A B : A);
 #undef B
 #undef A

Modified: stable/11/sys/dev/mlx5/mlx5_en/mlx5_en_main.c
==============================================================================
--- stable/11/sys/dev/mlx5/mlx5_en/mlx5_en_main.c	Thu May 16 17:19:48 2019	(r347809)
+++ stable/11/sys/dev/mlx5/mlx5_en/mlx5_en_main.c	Thu May 16 17:21:27 2019	(r347810)
@@ -281,7 +281,9 @@ mlx5e_set_port_pfc(struct mlx5e_priv *priv)
 {
 	int error;
 
-	if (priv->params.rx_pauseframe_control ||
+	if (priv->gone != 0) {
+		error = -ENXIO;
+	} else if (priv->params.rx_pauseframe_control ||
 	    priv->params.tx_pauseframe_control) {
 		if_printf(priv->ifp,
 		    "Global pauseframes must be disabled before enabling PFC.\n");
@@ -3329,79 +3331,98 @@ static int
 mlx5e_sysctl_tx_priority_flow_control(SYSCTL_HANDLER_ARGS)
 {
 	struct mlx5e_priv *priv = arg1;
+	uint8_t temp[MLX5E_MAX_PRIORITY];
 	uint32_t tx_pfc;
-	uint32_t value;
-	int error;
+	int err;
+	int i;
 
 	PRIV_LOCK(priv);
 
 	tx_pfc = priv->params.tx_priority_flow_control;
 
-	/* get current value */
-	value = (tx_pfc >> arg2) & 1;
+	for (i = 0; i != MLX5E_MAX_PRIORITY; i++)
+		temp[i] = (tx_pfc >> i) & 1;
 
-	error = sysctl_handle_32(oidp, &value, 0, req);
+	err = SYSCTL_OUT(req, temp, MLX5E_MAX_PRIORITY);
+	if (err || !req->newptr)
+		goto done;
+	err = SYSCTL_IN(req, temp, MLX5E_MAX_PRIORITY);
+	if (err)
+		goto done;
 
-	/* range check value */
-	if (value != 0)
-		priv->params.tx_priority_flow_control |= (1 << arg2);
-	else
-		priv->params.tx_priority_flow_control &= ~(1 << arg2);
+	priv->params.tx_priority_flow_control = 0;
 
-	/* check if update is required */
-	if (error == 0 && priv->gone == 0 &&
-	    tx_pfc != priv->params.tx_priority_flow_control) {
-		error = -mlx5e_set_port_pfc(priv);
-		/* restore previous value */
-		if (error != 0)
-			priv->params.tx_priority_flow_control= tx_pfc;
+	/* range check input value */
+	for (i = 0; i != MLX5E_MAX_PRIORITY; i++) {
+		if (temp[i] > 1) {
+			err = ERANGE;
+			goto done;
+		}
+		priv->params.tx_priority_flow_control |= (temp[i] << i);
 	}
+
+	/* check if update is required */
+	if (tx_pfc != priv->params.tx_priority_flow_control)
+		err = -mlx5e_set_port_pfc(priv);
+done:
+	if (err != 0)
+		priv->params.tx_priority_flow_control= tx_pfc;
 	PRIV_UNLOCK(priv);
 
-	return (error);
+	return (err);
 }
 
 static int
 mlx5e_sysctl_rx_priority_flow_control(SYSCTL_HANDLER_ARGS)
 {
 	struct mlx5e_priv *priv = arg1;
+	uint8_t temp[MLX5E_MAX_PRIORITY];
 	uint32_t rx_pfc;
-	uint32_t value;
-	int error;
+	int err;
+	int i;
 
 	PRIV_LOCK(priv);
 
 	rx_pfc = priv->params.rx_priority_flow_control;
 
-	/* get current value */
-	value = (rx_pfc >> arg2) & 1;
+	for (i = 0; i != MLX5E_MAX_PRIORITY; i++)
+		temp[i] = (rx_pfc >> i) & 1;
 
-	error = sysctl_handle_32(oidp, &value, 0, req);
+	err = SYSCTL_OUT(req, temp, MLX5E_MAX_PRIORITY);
+	if (err || !req->newptr)
+		goto done;
+	err = SYSCTL_IN(req, temp, MLX5E_MAX_PRIORITY);
+	if (err)
+		goto done;
 
-	/* range check value */
-	if (value != 0)
-		priv->params.rx_priority_flow_control |= (1 << arg2);
-	else
-		priv->params.rx_priority_flow_control &= ~(1 << arg2);
+	priv->params.rx_priority_flow_control = 0;
 
-	/* check if update is required */
-	if (error == 0 && priv->gone == 0 &&
-	    rx_pfc != priv->params.rx_priority_flow_control) {
-		error = -mlx5e_set_port_pfc(priv);
-		/* restore previous value */
-		if (error != 0)
-			priv->params.rx_priority_flow_control= rx_pfc;
+	/* range check input value */
+	for (i = 0; i != MLX5E_MAX_PRIORITY; i++) {
+		if (temp[i] > 1) {
+			err = ERANGE;
+			goto done;
+		}
+		priv->params.rx_priority_flow_control |= (temp[i] << i);
 	}
+
+	/* check if update is required */
+	if (rx_pfc != priv->params.rx_priority_flow_control)
+		err = -mlx5e_set_port_pfc(priv);
+done:
+	if (err != 0)
+		priv->params.rx_priority_flow_control= rx_pfc;
 	PRIV_UNLOCK(priv);
 
-	return (error);
+	return (err);
 }
 
 static void
 mlx5e_setup_pauseframes(struct mlx5e_priv *priv)
 {
-	unsigned int x;
+#if (__FreeBSD_version < 1100000)
 	char path[96];
+#endif
 	int error;
 
 	/* enable pauseframes by default */
@@ -3426,25 +3447,6 @@ mlx5e_setup_pauseframes(struct mlx5e_priv *priv)
 
 	/* try to fetch tunable, if any */
 	TUNABLE_INT_FETCH(path, &priv->params.rx_pauseframe_control);
-
-	for (x = 0; x != 8; x++) {
-
-		/* compute path for sysctl */
-		snprintf(path, sizeof(path), "dev.mce.%d.tx_priority_flow_control_%u",
-		    device_get_unit(priv->mdev->pdev->dev.bsddev), x);
-
-		/* try to fetch tunable, if any */
-		if (TUNABLE_INT_FETCH(path, &value) == 0 && value != 0)
-			priv->params.tx_priority_flow_control |= 1 << x;
-
-		/* compute path for sysctl */
-		snprintf(path, sizeof(path), "dev.mce.%d.rx_priority_flow_control_%u",
-		    device_get_unit(priv->mdev->pdev->dev.bsddev), x);
-
-		/* try to fetch tunable, if any */
-		if (TUNABLE_INT_FETCH(path, &value) == 0 && value != 0)
-			priv->params.rx_priority_flow_control |= 1 << x;
-	}
 #endif
 
 	/* register pauseframe SYSCTLs */
@@ -3458,22 +3460,16 @@ mlx5e_setup_pauseframes(struct mlx5e_priv *priv)
 	    &priv->params.rx_pauseframe_control, 0,
 	    "Set to enable RX pause frames. Clear to disable.");
 
-	/* register priority_flow control, PFC, SYSCTLs */
-	for (x = 0; x != 8; x++) {
-		snprintf(path, sizeof(path), "tx_priority_flow_control_%u", x);
+	/* register priority flow control, PFC, SYSCTLs */
+	SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(priv->sysctl_ifnet),
+	    OID_AUTO, "tx_priority_flow_control", CTLTYPE_U8 | CTLFLAG_RWTUN |
+	    CTLFLAG_MPSAFE, priv, 0, &mlx5e_sysctl_tx_priority_flow_control, "CU",
+	    "Set to enable TX ports flow control frames for priorities 0..7. Clear to disable.");
 
-		SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(priv->sysctl_ifnet),
-		    OID_AUTO, path, CTLTYPE_UINT | CTLFLAG_RWTUN |
-		    CTLFLAG_MPSAFE, priv, x, &mlx5e_sysctl_tx_priority_flow_control, "IU",
-		    "Set to enable TX ports flow control frames for given priority. Clear to disable.");
-
-		snprintf(path, sizeof(path), "rx_priority_flow_control_%u", x);
-
-		SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(priv->sysctl_ifnet),
-		    OID_AUTO, path, CTLTYPE_UINT | CTLFLAG_RWTUN |
-		    CTLFLAG_MPSAFE, priv, x, &mlx5e_sysctl_rx_priority_flow_control, "IU",
-		    "Set to enable RX ports flow control frames for given priority. Clear to disable.");
-	}
+	SYSCTL_ADD_PROC(&priv->sysctl_ctx, SYSCTL_CHILDREN(priv->sysctl_ifnet),
+	    OID_AUTO, "rx_priority_flow_control", CTLTYPE_U8 | CTLFLAG_RWTUN |
+	    CTLFLAG_MPSAFE, priv, 0, &mlx5e_sysctl_rx_priority_flow_control, "CU",
+	    "Set to enable RX ports flow control frames for priorities 0..7. Clear to disable.");
 
 	PRIV_LOCK(priv);
 


More information about the svn-src-all mailing list