]> git.itanic.dy.fi Git - linux-stable/commitdiff
mlxsw: core_env: Read transceiver module EEPROM in 128 bytes chunks
authorIdo Schimmel <idosch@nvidia.com>
Tue, 25 Jul 2023 12:04:05 +0000 (14:04 +0200)
committerJakub Kicinski <kuba@kernel.org>
Thu, 27 Jul 2023 04:49:27 +0000 (21:49 -0700)
Old firmware versions could only read up to 48 bytes from a transceiver
module's EEPROM in one go. Newer versions can read up to 128 bytes,
resulting in fewer transactions.

Query support for the new capability during driver initialization and if
supported, read up to 128 bytes in one go.

This is going to be especially useful for upcoming transceiver module
firmware flashing support.

Before:

 # perf stat -e devlink:devlink_hwmsg -- ethtool -m swp11 page 0x1 offset 128 length 128 i2c 0x50
 [...]
  Performance counter stats for 'ethtool -m swp11 page 0x1 offset 128 length 128 i2c 0x50':

                  3      devlink:devlink_hwmsg

After:

 # perf stat -e devlink:devlink_hwmsg -- ethtool -m swp11 page 0x1 offset 128 length 128 i2c 0x50
 [...]
  Performance counter stats for 'ethtool -m swp11 page 0x1 offset 128 length 128 i2c 0x50':

                  1      devlink:devlink_hwmsg

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
Link: https://lore.kernel.org/r/99d1618e8cd5acefb2f795dfde1a5b41caa07dcb.1690281940.git.petrm@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlxsw/core_env.c
drivers/net/ethernet/mellanox/mlxsw/reg.h

index 679f7488ba10fcb07098c5672234a37ed7bc4de3..d637c0348fa15e9abbd8653055b542000f985505 100644 (file)
@@ -32,6 +32,7 @@ struct mlxsw_env {
        const struct mlxsw_bus_info *bus_info;
        u8 max_module_count; /* Maximum number of modules per-slot. */
        u8 num_of_slots; /* Including the main board. */
+       u8 max_eeprom_len; /* Maximum module EEPROM transaction length. */
        struct mutex line_cards_lock; /* Protects line cards. */
        struct mlxsw_env_line_card *line_cards[];
 };
@@ -146,6 +147,7 @@ mlxsw_env_query_module_eeprom(struct mlxsw_core *mlxsw_core, u8 slot_index,
                              int module, u16 offset, u16 size, void *data,
                              bool qsfp, unsigned int *p_read_size)
 {
+       struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core);
        char mcia_pl[MLXSW_REG_MCIA_LEN];
        char *eeprom_tmp;
        u16 i2c_addr;
@@ -153,11 +155,7 @@ mlxsw_env_query_module_eeprom(struct mlxsw_core *mlxsw_core, u8 slot_index,
        int status;
        int err;
 
-       /* MCIA register accepts buffer size <= 48. Page of size 128 should be
-        * read by chunks of size 48, 48, 32. Align the size of the last chunk
-        * to avoid reading after the end of the page.
-        */
-       size = min_t(u16, size, MLXSW_REG_MCIA_EEPROM_SIZE);
+       size = min_t(u16, size, mlxsw_env->max_eeprom_len);
 
        if (offset < MLXSW_REG_MCIA_EEPROM_PAGE_LENGTH &&
            offset + size > MLXSW_REG_MCIA_EEPROM_PAGE_LENGTH)
@@ -489,7 +487,7 @@ mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core,
                u8 size;
 
                size = min_t(u8, page->length - bytes_read,
-                            MLXSW_REG_MCIA_EEPROM_SIZE);
+                            mlxsw_env->max_eeprom_len);
 
                mlxsw_reg_mcia_pack(mcia_pl, slot_index, module, page->page,
                                    device_addr + bytes_read, size,
@@ -1359,6 +1357,26 @@ static struct mlxsw_linecards_event_ops mlxsw_env_event_ops = {
        .got_inactive = mlxsw_env_got_inactive,
 };
 
+static int mlxsw_env_max_module_eeprom_len_query(struct mlxsw_env *mlxsw_env)
+{
+       char mcam_pl[MLXSW_REG_MCAM_LEN];
+       bool mcia_128b_supported;
+       int err;
+
+       mlxsw_reg_mcam_pack(mcam_pl,
+                           MLXSW_REG_MCAM_FEATURE_GROUP_ENHANCED_FEATURES);
+       err = mlxsw_reg_query(mlxsw_env->core, MLXSW_REG(mcam), mcam_pl);
+       if (err)
+               return err;
+
+       mlxsw_reg_mcam_unpack(mcam_pl, MLXSW_REG_MCAM_MCIA_128B,
+                             &mcia_128b_supported);
+
+       mlxsw_env->max_eeprom_len = mcia_128b_supported ? 128 : 48;
+
+       return 0;
+}
+
 int mlxsw_env_init(struct mlxsw_core *mlxsw_core,
                   const struct mlxsw_bus_info *bus_info,
                   struct mlxsw_env **p_env)
@@ -1427,10 +1445,15 @@ int mlxsw_env_init(struct mlxsw_core *mlxsw_core,
        if (err)
                goto err_type_set;
 
+       err = mlxsw_env_max_module_eeprom_len_query(env);
+       if (err)
+               goto err_eeprom_len_query;
+
        env->line_cards[0]->active = true;
 
        return 0;
 
+err_eeprom_len_query:
 err_type_set:
        mlxsw_env_module_event_disable(env, 0);
 err_mlxsw_env_module_event_enable:
index 7a0023ae958637a806ac8ee79ccf02c6d2e4c5b2..4b90ae44b4765343f36cdb7be3dea6809c8656f7 100644 (file)
@@ -9708,7 +9708,6 @@ MLXSW_ITEM32(reg, mcia, size, 0x08, 0, 16);
 
 #define MLXSW_REG_MCIA_EEPROM_PAGE_LENGTH      256
 #define MLXSW_REG_MCIA_EEPROM_UP_PAGE_LENGTH   128
-#define MLXSW_REG_MCIA_EEPROM_SIZE             48
 #define MLXSW_REG_MCIA_I2C_ADDR_LOW            0x50
 #define MLXSW_REG_MCIA_I2C_ADDR_HIGH           0x51
 #define MLXSW_REG_MCIA_PAGE0_LO_OFF            0xa0
@@ -9745,7 +9744,7 @@ enum mlxsw_reg_mcia_eeprom_module_info {
  * Bytes to read/write.
  * Access: RW
  */
-MLXSW_ITEM_BUF(reg, mcia, eeprom, 0x10, MLXSW_REG_MCIA_EEPROM_SIZE);
+MLXSW_ITEM_BUF(reg, mcia, eeprom, 0x10, 128);
 
 /* This is used to access the optional upper pages (1-3) in the QSFP+
  * memory map. Page 1 is available on offset 256 through 383, page 2 -