mlxsw: spectrum: Prepare for multiple FW versions for Spectrum and Spectrum-2
authorJiri Pirko <jiri@mellanox.com>
Sun, 8 Jul 2018 20:51:26 +0000 (23:51 +0300)
committerDavid S. Miller <davem@davemloft.net>
Mon, 9 Jul 2018 23:24:17 +0000 (16:24 -0700)
Prepare for Spectrum-2 FW version checking and
make mlxsw_sp_fw_rev_validate() per-ASIC as well as required FW revision
and FW filename.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum.c
drivers/net/ethernet/mellanox/mlxsw/spectrum.h

index 64c4259866bb6cf2995605a9d3a58022389195b9..5b2f4c6f5e57367f9636d4887d90a633d929f23a 100644 (file)
 #include "spectrum_span.h"
 #include "../mlxfw/mlxfw.h"
 
-#define MLXSW_FWREV_MAJOR 13
-#define MLXSW_FWREV_MINOR 1620
-#define MLXSW_FWREV_SUBMINOR 192
-#define MLXSW_FWREV_MINOR_TO_BRANCH(minor) ((minor) / 100)
+#define MLXSW_SP_FWREV_MINOR_TO_BRANCH(minor) ((minor) / 100)
 
-#define MLXSW_SP_FW_FILENAME \
-       "mellanox/mlxsw_spectrum-" __stringify(MLXSW_FWREV_MAJOR) \
-       "." __stringify(MLXSW_FWREV_MINOR) \
-       "." __stringify(MLXSW_FWREV_SUBMINOR) ".mfa2"
+#define MLXSW_SP1_FWREV_MAJOR 13
+#define MLXSW_SP1_FWREV_MINOR 1620
+#define MLXSW_SP1_FWREV_SUBMINOR 192
+
+static const struct mlxsw_fw_rev mlxsw_sp1_fw_rev = {
+       .major = MLXSW_SP1_FWREV_MAJOR,
+       .minor = MLXSW_SP1_FWREV_MINOR,
+       .subminor = MLXSW_SP1_FWREV_SUBMINOR,
+};
+
+#define MLXSW_SP1_FW_FILENAME \
+       "mellanox/mlxsw_spectrum-" __stringify(MLXSW_SP1_FWREV_MAJOR) \
+       "." __stringify(MLXSW_SP1_FWREV_MINOR) \
+       "." __stringify(MLXSW_SP1_FWREV_SUBMINOR) ".mfa2"
 
 static const char mlxsw_sp_driver_name[] = "mlxsw_spectrum";
 static const char mlxsw_sp_driver_version[] = "1.0";
@@ -338,29 +345,35 @@ static int mlxsw_sp_firmware_flash(struct mlxsw_sp *mlxsw_sp,
 static int mlxsw_sp_fw_rev_validate(struct mlxsw_sp *mlxsw_sp)
 {
        const struct mlxsw_fw_rev *rev = &mlxsw_sp->bus_info->fw_rev;
+       const struct mlxsw_fw_rev *req_rev = mlxsw_sp->req_rev;
+       const char *fw_filename = mlxsw_sp->fw_filename;
        const struct firmware *firmware;
        int err;
 
+       /* Don't check if driver does not require it */
+       if (!req_rev || !fw_filename)
+               return 0;
+
        /* Validate driver & FW are compatible */
-       if (rev->major != MLXSW_FWREV_MAJOR) {
+       if (rev->major != req_rev->major) {
                WARN(1, "Mismatch in major FW version [%d:%d] is never expected; Please contact support\n",
-                    rev->major, MLXSW_FWREV_MAJOR);
+                    rev->major, req_rev->major);
                return -EINVAL;
        }
-       if (MLXSW_FWREV_MINOR_TO_BRANCH(rev->minor) ==
-           MLXSW_FWREV_MINOR_TO_BRANCH(MLXSW_FWREV_MINOR))
+       if (MLXSW_SP_FWREV_MINOR_TO_BRANCH(rev->minor) ==
+           MLXSW_SP_FWREV_MINOR_TO_BRANCH(req_rev->minor))
                return 0;
 
        dev_info(mlxsw_sp->bus_info->dev, "The firmware version %d.%d.%d is incompatible with the driver\n",
                 rev->major, rev->minor, rev->subminor);
        dev_info(mlxsw_sp->bus_info->dev, "Flashing firmware using file %s\n",
-                MLXSW_SP_FW_FILENAME);
+                fw_filename);
 
-       err = request_firmware_direct(&firmware, MLXSW_SP_FW_FILENAME,
+       err = request_firmware_direct(&firmware, fw_filename,
                                      mlxsw_sp->bus_info->dev);
        if (err) {
                dev_err(mlxsw_sp->bus_info->dev, "Could not request firmware file %s\n",
-                       MLXSW_SP_FW_FILENAME);
+                       fw_filename);
                return err;
        }
 
@@ -3621,6 +3634,8 @@ static int mlxsw_sp_init(struct mlxsw_core *mlxsw_core,
        struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
        int err;
 
+       mlxsw_sp->req_rev = &mlxsw_sp1_fw_rev;
+       mlxsw_sp->fw_filename = MLXSW_SP1_FW_FILENAME;
        mlxsw_sp->kvdl_ops = &mlxsw_sp1_kvdl_ops;
        mlxsw_sp->afa_ops = &mlxsw_sp1_act_afa_ops;
        mlxsw_sp->afk_ops = &mlxsw_sp1_afk_ops;
@@ -4745,4 +4760,4 @@ MODULE_LICENSE("Dual BSD/GPL");
 MODULE_AUTHOR("Jiri Pirko <jiri@mellanox.com>");
 MODULE_DESCRIPTION("Mellanox Spectrum driver");
 MODULE_DEVICE_TABLE(pci, mlxsw_sp_pci_id_table);
-MODULE_FIRMWARE(MLXSW_SP_FW_FILENAME);
+MODULE_FIRMWARE(MLXSW_SP1_FW_FILENAME);
index aa07f5b9bb5d814dfe928c5b8ab6d3d7a4c3ace7..eb3d3c0bdb037a60bda49f6b1374efd705cf1cfa 100644 (file)
@@ -171,6 +171,8 @@ struct mlxsw_sp {
                struct mlxsw_sp_span_entry *entries;
                int entries_count;
        } span;
+       const struct mlxsw_fw_rev *req_rev;
+       const char *fw_filename;
        const struct mlxsw_sp_kvdl_ops *kvdl_ops;
        const struct mlxsw_afa_ops *afa_ops;
        const struct mlxsw_afk_ops *afk_ops;