Skip to content

Commit

Permalink
mlxsw: minimal: Add validation for FW version
Browse files Browse the repository at this point in the history
Add validation for FW version in order to prevent driver initialization
in case FW version is older than expected. FW version validation is
necessary, because use of a new field 'num_of_modules' in MGPIR register
is not backward compatible. FW 'minor' and 'subminor' versions are
expected to be greater than or equal to 2000 and 1886, respectively.

Signed-off-by: Vadim Pasternak <vadimp@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Vadim Pasternak authored and David S. Miller committed Oct 6, 2019
1 parent 762effa commit 6935af8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions drivers/net/ethernet/mellanox/mlxsw/minimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@

static const char mlxsw_m_driver_name[] = "mlxsw_minimal";

#define MLXSW_M_FWREV_MINOR 2000
#define MLXSW_M_FWREV_SUBMINOR 1886

static const struct mlxsw_fw_rev mlxsw_m_fw_rev = {
.minor = MLXSW_M_FWREV_MINOR,
.subminor = MLXSW_M_FWREV_SUBMINOR,
};

struct mlxsw_m_port;

struct mlxsw_m {
Expand Down Expand Up @@ -326,6 +334,24 @@ static void mlxsw_m_ports_remove(struct mlxsw_m *mlxsw_m)
kfree(mlxsw_m->ports);
}

static int mlxsw_m_fw_rev_validate(struct mlxsw_m *mlxsw_m)
{
const struct mlxsw_fw_rev *rev = &mlxsw_m->bus_info->fw_rev;

/* Validate driver and FW are compatible.
* Do not check major version, since it defines chip type, while
* driver is supposed to support any type.
*/
if (mlxsw_core_fw_rev_minor_subminor_validate(rev, &mlxsw_m_fw_rev))
return 0;

dev_err(mlxsw_m->bus_info->dev, "The firmware version %d.%d.%d is incompatible with the driver (required >= %d.%d.%d)\n",
rev->major, rev->minor, rev->subminor, rev->major,
mlxsw_m_fw_rev.minor, mlxsw_m_fw_rev.subminor);

return -EINVAL;
}

static int mlxsw_m_init(struct mlxsw_core *mlxsw_core,
const struct mlxsw_bus_info *mlxsw_bus_info,
struct netlink_ext_ack *extack)
Expand All @@ -336,6 +362,10 @@ static int mlxsw_m_init(struct mlxsw_core *mlxsw_core,
mlxsw_m->core = mlxsw_core;
mlxsw_m->bus_info = mlxsw_bus_info;

err = mlxsw_m_fw_rev_validate(mlxsw_m);
if (err)
return err;

err = mlxsw_m_base_mac_get(mlxsw_m);
if (err) {
dev_err(mlxsw_m->bus_info->dev, "Failed to get base mac\n");
Expand Down

0 comments on commit 6935af8

Please sign in to comment.