lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <14a24f93-f8d6-4bc7-8b87-86489bcedb28@ans.pl>
Date: Wed, 11 Sep 2024 23:38:45 -0700
From: Krzysztof Olędzki <ole@....pl>
To: Ido Schimmel <idosch@...dia.com>, Tariq Toukan <tariqt@...dia.com>,
        "David S. Miller" <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>, Saeed Mahameed <saeedm@...dia.com>,
        Leon Romanovsky <leon@...nel.org>, Yishai Hadas <yishaih@...dia.com>
Cc: "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
        linux-rdma@...r.kernel.org
Subject: [PATCH net-next 1/4] mlx4/mlx5: {mlx4,mlx5e}_en_get_module_info
 cleanup

Use SFF8024 constants defined in linux/sfp.h instead of private ones.

Make mlx4_en_get_module_info() and mlx5e_get_module_info() to look
as close as possible to each other.

Simplify the logic for selecting SFF_8436 vs SFF_8636.

Signed-off-by: Krzysztof Piotr Oledzki <ole@....pl>
---
 .../net/ethernet/mellanox/mlx4/en_ethtool.c   | 33 ++++++++++---------
 drivers/net/ethernet/mellanox/mlx4/port.c     |  9 ++---
 .../ethernet/mellanox/mlx5/core/en_ethtool.c  | 28 +++++++++-------
 .../net/ethernet/mellanox/mlx5/core/port.c    |  9 ++---
 include/linux/mlx4/device.h                   |  7 ----
 include/linux/mlx5/port.h                     |  8 -----
 6 files changed, 44 insertions(+), 50 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
index cd17a3f4faf8..4c985d62af12 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
@@ -40,6 +40,7 @@
 #include <net/ip.h>
 #include <linux/bitmap.h>
 #include <linux/mii.h>
+#include <linux/sfp.h>
 
 #include "mlx4_en.h"
 #include "en_port.h"
@@ -2029,33 +2030,35 @@ static int mlx4_en_get_module_info(struct net_device *dev,
 
 	/* Read first 2 bytes to get Module & REV ID */
 	ret = mlx4_get_module_info(mdev->dev, priv->port,
-				   0/*offset*/, 2/*size*/, data);
+				   0 /*offset*/, 2 /*size*/, data);
 	if (ret < 2)
 		return -EIO;
 
-	switch (data[0] /* identifier */) {
-	case MLX4_MODULE_ID_QSFP:
-		modinfo->type = ETH_MODULE_SFF_8436;
+	/* data[0] = identifier byte */
+	switch (data[0]) {
+	case SFF8024_ID_QSFP_8438:
+		modinfo->type       = ETH_MODULE_SFF_8436;
 		modinfo->eeprom_len = ETH_MODULE_SFF_8436_MAX_LEN;
 		break;
-	case MLX4_MODULE_ID_QSFP_PLUS:
-		if (data[1] >= 0x3) { /* revision id */
-			modinfo->type = ETH_MODULE_SFF_8636;
-			modinfo->eeprom_len = ETH_MODULE_SFF_8636_MAX_LEN;
-		} else {
-			modinfo->type = ETH_MODULE_SFF_8436;
+	case SFF8024_ID_QSFP_8436_8636:
+		/* data[1] = revision id */
+		if (data[1] < 0x3) {
+			modinfo->type       = ETH_MODULE_SFF_8436;
 			modinfo->eeprom_len = ETH_MODULE_SFF_8436_MAX_LEN;
+			break;
 		}
-		break;
-	case MLX4_MODULE_ID_QSFP28:
-		modinfo->type = ETH_MODULE_SFF_8636;
+		fallthrough;
+	case SFF8024_ID_QSFP28_8636:
+		modinfo->type       = ETH_MODULE_SFF_8636;
 		modinfo->eeprom_len = ETH_MODULE_SFF_8636_MAX_LEN;
 		break;
-	case MLX4_MODULE_ID_SFP:
-		modinfo->type = ETH_MODULE_SFF_8472;
+	case SFF8024_ID_SFP:
+		modinfo->type       = ETH_MODULE_SFF_8472;
 		modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
 		break;
 	default:
+		netdev_err(dev, "%s: cable type not recognized: 0x%x\n",
+			   __func__, data[0]);
 		return -EINVAL;
 	}
 
diff --git a/drivers/net/ethernet/mellanox/mlx4/port.c b/drivers/net/ethernet/mellanox/mlx4/port.c
index 4e43f4a7d246..6dbd505e7f30 100644
--- a/drivers/net/ethernet/mellanox/mlx4/port.c
+++ b/drivers/net/ethernet/mellanox/mlx4/port.c
@@ -34,6 +34,7 @@
 #include <linux/if_ether.h>
 #include <linux/if_vlan.h>
 #include <linux/export.h>
+#include <linux/sfp.h>
 
 #include <linux/mlx4/cmd.h>
 
@@ -2139,12 +2140,12 @@ int mlx4_get_module_info(struct mlx4_dev *dev, u8 port,
 		return ret;
 
 	switch (module_id) {
-	case MLX4_MODULE_ID_SFP:
+	case SFF8024_ID_SFP:
 		mlx4_sfp_eeprom_params_set(&i2c_addr, &page_num, &offset);
 		break;
-	case MLX4_MODULE_ID_QSFP:
-	case MLX4_MODULE_ID_QSFP_PLUS:
-	case MLX4_MODULE_ID_QSFP28:
+	case SFF8024_ID_QSFP_8438:
+	case SFF8024_ID_QSFP_8436_8636:
+	case SFF8024_ID_QSFP28_8636:
 		mlx4_qsfp_eeprom_params_set(&i2c_addr, &page_num, &offset);
 		break;
 	default:
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
index 4d123dae912c..12a22e5c60ae 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
@@ -32,6 +32,7 @@
 
 #include <linux/dim.h>
 #include <linux/ethtool_netlink.h>
+#include <linux/sfp.h>
 
 #include "en.h"
 #include "en/channels.h"
@@ -1899,36 +1900,39 @@ static int mlx5e_get_module_info(struct net_device *netdev,
 {
 	struct mlx5e_priv *priv = netdev_priv(netdev);
 	struct mlx5_core_dev *dev = priv->mdev;
-	int size_read = 0;
+	int ret;
 	u8 data[4] = {0};
 
-	size_read = mlx5_query_module_eeprom(dev, 0, 2, data);
-	if (size_read < 2)
+	/* Read first 2 bytes to get Module & REV ID */
+	ret = mlx5_query_module_eeprom(dev,
+				       0 /*offset*/, 2 /*size*/, data);
+	if (ret < 2)
 		return -EIO;
 
 	/* data[0] = identifier byte */
 	switch (data[0]) {
-	case MLX5_MODULE_ID_QSFP:
+	case SFF8024_ID_QSFP_8438:
 		modinfo->type       = ETH_MODULE_SFF_8436;
 		modinfo->eeprom_len = ETH_MODULE_SFF_8436_MAX_LEN;
 		break;
-	case MLX5_MODULE_ID_QSFP_PLUS:
-	case MLX5_MODULE_ID_QSFP28:
+	case SFF8024_ID_QSFP_8436_8636:
 		/* data[1] = revision id */
-		if (data[0] == MLX5_MODULE_ID_QSFP28 || data[1] >= 0x3) {
-			modinfo->type       = ETH_MODULE_SFF_8636;
-			modinfo->eeprom_len = ETH_MODULE_SFF_8636_MAX_LEN;
-		} else {
+		if (data[1] < 0x3) {
 			modinfo->type       = ETH_MODULE_SFF_8436;
 			modinfo->eeprom_len = ETH_MODULE_SFF_8436_MAX_LEN;
+			break;
 		}
+		fallthrough;
+	case SFF8024_ID_QSFP28_8636:
+		modinfo->type       = ETH_MODULE_SFF_8636;
+		modinfo->eeprom_len = ETH_MODULE_SFF_8636_MAX_LEN;
 		break;
-	case MLX5_MODULE_ID_SFP:
+	case SFF8024_ID_SFP:
 		modinfo->type       = ETH_MODULE_SFF_8472;
 		modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
 		break;
 	default:
-		netdev_err(priv->netdev, "%s: cable type not recognized:0x%x\n",
+		netdev_err(priv->netdev, "%s: cable type not recognized: 0x%x\n",
 			   __func__, data[0]);
 		return -EINVAL;
 	}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/port.c b/drivers/net/ethernet/mellanox/mlx5/core/port.c
index 50931584132b..4258489a5782 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/port.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/port.c
@@ -30,6 +30,7 @@
  * SOFTWARE.
  */
 
+#include <linux/sfp.h>
 #include <linux/mlx5/port.h>
 #include "mlx5_core.h"
 
@@ -425,12 +426,12 @@ int mlx5_query_module_eeprom(struct mlx5_core_dev *dev,
 		return err;
 
 	switch (module_id) {
-	case MLX5_MODULE_ID_SFP:
+	case SFF8024_ID_SFP:
 		mlx5_sfp_eeprom_params_set(&query.i2c_address, &query.page, &offset);
 		break;
-	case MLX5_MODULE_ID_QSFP:
-	case MLX5_MODULE_ID_QSFP_PLUS:
-	case MLX5_MODULE_ID_QSFP28:
+	case SFF8024_ID_QSFP_8438:
+	case SFF8024_ID_QSFP_8436_8636:
+	case SFF8024_ID_QSFP28_8636:
 		mlx5_qsfp_eeprom_params_set(&query.i2c_address, &query.page, &offset);
 		break;
 	default:
diff --git a/include/linux/mlx4/device.h b/include/linux/mlx4/device.h
index 27f42f713c89..a75bfb2a4438 100644
--- a/include/linux/mlx4/device.h
+++ b/include/linux/mlx4/device.h
@@ -487,13 +487,6 @@ enum {
 #define MSTR_SM_CHANGE_MASK (MLX4_EQ_PORT_INFO_MSTR_SM_SL_CHANGE_MASK | \
 			     MLX4_EQ_PORT_INFO_MSTR_SM_LID_CHANGE_MASK)
 
-enum mlx4_module_id {
-	MLX4_MODULE_ID_SFP              = 0x3,
-	MLX4_MODULE_ID_QSFP             = 0xC,
-	MLX4_MODULE_ID_QSFP_PLUS        = 0xD,
-	MLX4_MODULE_ID_QSFP28           = 0x11,
-};
-
 enum { /* rl */
 	MLX4_QP_RATE_LIMIT_NONE		= 0,
 	MLX4_QP_RATE_LIMIT_KBS		= 1,
diff --git a/include/linux/mlx5/port.h b/include/linux/mlx5/port.h
index e68d42b8ce65..e9495271160f 100644
--- a/include/linux/mlx5/port.h
+++ b/include/linux/mlx5/port.h
@@ -40,14 +40,6 @@ enum mlx5_beacon_duration {
 	MLX5_BEACON_DURATION_INF = 0xffff,
 };
 
-enum mlx5_module_id {
-	MLX5_MODULE_ID_SFP              = 0x3,
-	MLX5_MODULE_ID_QSFP             = 0xC,
-	MLX5_MODULE_ID_QSFP_PLUS        = 0xD,
-	MLX5_MODULE_ID_QSFP28           = 0x11,
-	MLX5_MODULE_ID_DSFP		= 0x1B,
-};
-
 enum mlx5_an_status {
 	MLX5_AN_UNAVAILABLE = 0,
 	MLX5_AN_COMPLETE    = 1,
-- 
2.46.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ