]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net/mlx5: Refactor EEPROM query error handling to return status separately
authorGal Pressman <gal@nvidia.com>
Mon, 17 Nov 2025 21:42:05 +0000 (23:42 +0200)
committerJakub Kicinski <kuba@kernel.org>
Wed, 19 Nov 2025 02:53:33 +0000 (18:53 -0800)
Matthew and Jakub reported [1] issues where inventory automation tools
are calling EEPROM query repeatedly on a port that doesn't have an SFP
connected, resulting in millions of error prints.

Move MCIA register status extraction from the query functions to the
callers, allowing use of extack reporting instead of a dmesg print when
using the netlink API.

[1] https://lore.kernel.org/netdev/20251028194011.39877-1-mattc@purestorage.com/

Cc: Matthew W Carlis <mattc@purestorage.com>
Signed-off-by: Gal Pressman <gal@nvidia.com>
Reviewed-by: Jianbo Liu <jianbol@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/1763415729-1238421-2-git-send-email-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
drivers/net/ethernet/mellanox/mlx5/core/port.c

index 939e274779b39702d753dca0da5b19c6744cdd61..727d7a833110f9f6baa84d847851598fee88e4b3 100644 (file)
@@ -2027,7 +2027,7 @@ static int mlx5e_get_module_info(struct net_device *netdev,
        int size_read = 0;
        u8 data[4] = {0};
 
-       size_read = mlx5_query_module_eeprom(dev, 0, 2, data);
+       size_read = mlx5_query_module_eeprom(dev, 0, 2, data, NULL);
        if (size_read < 2)
                return -EIO;
 
@@ -2069,6 +2069,7 @@ static int mlx5e_get_module_eeprom(struct net_device *netdev,
        struct mlx5_core_dev *mdev = priv->mdev;
        int offset = ee->offset;
        int size_read;
+       u8 status = 0;
        int i = 0;
 
        if (!ee->len)
@@ -2078,15 +2079,15 @@ static int mlx5e_get_module_eeprom(struct net_device *netdev,
 
        while (i < ee->len) {
                size_read = mlx5_query_module_eeprom(mdev, offset, ee->len - i,
-                                                    data + i);
-
+                                                    data + i, &status);
                if (!size_read)
                        /* Done reading */
                        return 0;
 
                if (size_read < 0) {
-                       netdev_err(priv->netdev, "%s: mlx5_query_eeprom failed:0x%x\n",
-                                  __func__, size_read);
+                       netdev_err(netdev,
+                                  "%s: mlx5_query_eeprom failed:0x%x, status %u\n",
+                                  __func__, size_read, status);
                        return size_read;
                }
 
@@ -2106,6 +2107,7 @@ static int mlx5e_get_module_eeprom_by_page(struct net_device *netdev,
        struct mlx5_core_dev *mdev = priv->mdev;
        u8 *data = page_data->data;
        int size_read;
+       u8 status = 0;
        int i = 0;
 
        if (!page_data->length)
@@ -2119,7 +2121,8 @@ static int mlx5e_get_module_eeprom_by_page(struct net_device *netdev,
        query.page = page_data->page;
        while (i < page_data->length) {
                query.size = page_data->length - i;
-               size_read = mlx5_query_module_eeprom_by_page(mdev, &query, data + i);
+               size_read = mlx5_query_module_eeprom_by_page(mdev, &query,
+                                                            data + i, &status);
 
                /* Done reading, return how many bytes was read */
                if (!size_read)
@@ -2128,8 +2131,8 @@ static int mlx5e_get_module_eeprom_by_page(struct net_device *netdev,
                if (size_read < 0) {
                        NL_SET_ERR_MSG_FMT_MOD(
                                extack,
-                               "Query module eeprom by page failed, read %u bytes, err %d",
-                               i, size_read);
+                               "Query module eeprom by page failed, read %u bytes, err %d, status %u",
+                               i, size_read, status);
                        return size_read;
                }
 
index acef7d0ffa0978544144e7dd4e0534c84e8bbbae..cfebc110c02fd94d7f3b7796f6f0702e999e8c76 100644 (file)
@@ -357,11 +357,11 @@ int mlx5_set_port_fcs(struct mlx5_core_dev *mdev, u8 enable);
 void mlx5_query_port_fcs(struct mlx5_core_dev *mdev, bool *supported,
                         bool *enabled);
 int mlx5_query_module_eeprom(struct mlx5_core_dev *dev,
-                            u16 offset, u16 size, u8 *data);
+                            u16 offset, u16 size, u8 *data, u8 *status);
 int
 mlx5_query_module_eeprom_by_page(struct mlx5_core_dev *dev,
                                 struct mlx5_module_eeprom_query_params *params,
-                                u8 *data);
+                                u8 *data, u8 *status);
 
 int mlx5_query_port_dcbx_param(struct mlx5_core_dev *mdev, u32 *out);
 int mlx5_set_port_dcbx_param(struct mlx5_core_dev *mdev, u32 *in);
index aa9f2b0a77d36f64f65d87600390a349961fa0fc..e4b1dfafb41fda1f0c0b3ce5658c9867f2c931a0 100644 (file)
@@ -289,11 +289,11 @@ int mlx5_query_module_num(struct mlx5_core_dev *dev, int *module_num)
 }
 
 static int mlx5_query_module_id(struct mlx5_core_dev *dev, int module_num,
-                               u8 *module_id)
+                               u8 *module_id, u8 *status)
 {
        u32 in[MLX5_ST_SZ_DW(mcia_reg)] = {};
        u32 out[MLX5_ST_SZ_DW(mcia_reg)];
-       int err, status;
+       int err;
        u8 *ptr;
 
        MLX5_SET(mcia_reg, in, i2c_device_address, MLX5_I2C_ADDR_LOW);
@@ -308,12 +308,12 @@ static int mlx5_query_module_id(struct mlx5_core_dev *dev, int module_num,
        if (err)
                return err;
 
-       status = MLX5_GET(mcia_reg, out, status);
-       if (status) {
-               mlx5_core_err(dev, "query_mcia_reg failed: status: 0x%x\n",
-                             status);
+       if (MLX5_GET(mcia_reg, out, status)) {
+               if (status)
+                       *status = MLX5_GET(mcia_reg, out, status);
                return -EIO;
        }
+
        ptr = MLX5_ADDR_OF(mcia_reg, out, dword_0);
 
        *module_id = ptr[0];
@@ -370,13 +370,14 @@ static int mlx5_mcia_max_bytes(struct mlx5_core_dev *dev)
 }
 
 static int mlx5_query_mcia(struct mlx5_core_dev *dev,
-                          struct mlx5_module_eeprom_query_params *params, u8 *data)
+                          struct mlx5_module_eeprom_query_params *params,
+                          u8 *data, u8 *status)
 {
        u32 in[MLX5_ST_SZ_DW(mcia_reg)] = {};
        u32 out[MLX5_ST_SZ_DW(mcia_reg)];
-       int status, err;
        void *ptr;
        u16 size;
+       int err;
 
        size = min_t(int, params->size, mlx5_mcia_max_bytes(dev));
 
@@ -392,12 +393,9 @@ static int mlx5_query_mcia(struct mlx5_core_dev *dev,
        if (err)
                return err;
 
-       status = MLX5_GET(mcia_reg, out, status);
-       if (status) {
-               mlx5_core_err(dev, "query_mcia_reg failed: status: 0x%x\n",
-                             status);
+       *status = MLX5_GET(mcia_reg, out, status);
+       if (*status)
                return -EIO;
-       }
 
        ptr = MLX5_ADDR_OF(mcia_reg, out, dword_0);
        memcpy(data, ptr, size);
@@ -406,7 +404,7 @@ static int mlx5_query_mcia(struct mlx5_core_dev *dev,
 }
 
 int mlx5_query_module_eeprom(struct mlx5_core_dev *dev,
-                            u16 offset, u16 size, u8 *data)
+                            u16 offset, u16 size, u8 *data, u8 *status)
 {
        struct mlx5_module_eeprom_query_params query = {0};
        u8 module_id;
@@ -416,7 +414,8 @@ int mlx5_query_module_eeprom(struct mlx5_core_dev *dev,
        if (err)
                return err;
 
-       err = mlx5_query_module_id(dev, query.module_number, &module_id);
+       err = mlx5_query_module_id(dev, query.module_number, &module_id,
+                                  status);
        if (err)
                return err;
 
@@ -441,12 +440,12 @@ int mlx5_query_module_eeprom(struct mlx5_core_dev *dev,
        query.size = size;
        query.offset = offset;
 
-       return mlx5_query_mcia(dev, &query, data);
+       return mlx5_query_mcia(dev, &query, data, status);
 }
 
 int mlx5_query_module_eeprom_by_page(struct mlx5_core_dev *dev,
                                     struct mlx5_module_eeprom_query_params *params,
-                                    u8 *data)
+                                    u8 *data, u8 *status)
 {
        int err;
 
@@ -460,7 +459,7 @@ int mlx5_query_module_eeprom_by_page(struct mlx5_core_dev *dev,
                return -EINVAL;
        }
 
-       return mlx5_query_mcia(dev, params, data);
+       return mlx5_query_mcia(dev, params, data, status);
 }
 
 static int mlx5_query_port_pvlc(struct mlx5_core_dev *dev, u32 *pvlc,