Commit 1983a800 authored by Ido Schimmel's avatar Ido Schimmel Committed by David S. Miller
Browse files

mlxsw: Implement ethtool operation to write to a transceiver module EEPROM



Implement the ethtool_ops::set_module_eeprom_by_page operation to allow
ethtool to write to a transceiver module EEPROM, in a similar fashion to
the ethtool_ops::get_module_eeprom_by_page operation.

Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
Reviewed-by: default avatarPetr Machata <petrm@nvidia.com>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 69540b79
Loading
Loading
Loading
Loading
+57 −0
Original line number Diff line number Diff line
@@ -513,6 +513,63 @@ mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core,
}
EXPORT_SYMBOL(mlxsw_env_get_module_eeprom_by_page);

int
mlxsw_env_set_module_eeprom_by_page(struct mlxsw_core *mlxsw_core,
				    u8 slot_index, u8 module,
				    const struct ethtool_module_eeprom *page,
				    struct netlink_ext_ack *extack)
{
	struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core);
	u32 bytes_written = 0;
	u16 device_addr;
	int err;

	if (!mlxsw_env_linecard_is_active(mlxsw_env, slot_index)) {
		NL_SET_ERR_MSG_MOD(extack,
				   "Cannot write to EEPROM of a module on an inactive line card");
		return -EIO;
	}

	err = mlxsw_env_validate_module_type(mlxsw_core, slot_index, module);
	if (err) {
		NL_SET_ERR_MSG_MOD(extack, "EEPROM is not equipped on port module type");
		return err;
	}

	device_addr = page->offset;

	while (bytes_written < page->length) {
		char mcia_pl[MLXSW_REG_MCIA_LEN];
		char eeprom_tmp[128] = {};
		u8 size;

		size = min_t(u8, page->length - bytes_written,
			     mlxsw_env->max_eeprom_len);

		mlxsw_reg_mcia_pack(mcia_pl, slot_index, module, page->page,
				    device_addr + bytes_written, size,
				    page->i2c_address);
		mlxsw_reg_mcia_bank_number_set(mcia_pl, page->bank);
		memcpy(eeprom_tmp, page->data + bytes_written, size);
		mlxsw_reg_mcia_eeprom_memcpy_to(mcia_pl, eeprom_tmp);

		err = mlxsw_reg_write(mlxsw_core, MLXSW_REG(mcia), mcia_pl);
		if (err) {
			NL_SET_ERR_MSG_MOD(extack, "Failed to access module's EEPROM");
			return err;
		}

		err = mlxsw_env_mcia_status_process(mcia_pl, extack);
		if (err)
			return err;

		bytes_written += size;
	}

	return 0;
}
EXPORT_SYMBOL(mlxsw_env_set_module_eeprom_by_page);

static int mlxsw_env_module_reset(struct mlxsw_core *mlxsw_core, u8 slot_index,
				  u8 module)
{
+6 −0
Original line number Diff line number Diff line
@@ -28,6 +28,12 @@ mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core,
				    const struct ethtool_module_eeprom *page,
				    struct netlink_ext_ack *extack);

int
mlxsw_env_set_module_eeprom_by_page(struct mlxsw_core *mlxsw_core,
				    u8 slot_index, u8 module,
				    const struct ethtool_module_eeprom *page,
				    struct netlink_ext_ack *extack);

int mlxsw_env_reset_module(struct net_device *netdev,
			   struct mlxsw_core *mlxsw_core, u8 slot_index,
			   u8 module, u32 *flags);
+15 −0
Original line number Diff line number Diff line
@@ -140,6 +140,20 @@ mlxsw_m_get_module_eeprom_by_page(struct net_device *netdev,
						   page, extack);
}

static int
mlxsw_m_set_module_eeprom_by_page(struct net_device *netdev,
				  const struct ethtool_module_eeprom *page,
				  struct netlink_ext_ack *extack)
{
	struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev);
	struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core;

	return mlxsw_env_set_module_eeprom_by_page(core,
						   mlxsw_m_port->slot_index,
						   mlxsw_m_port->module,
						   page, extack);
}

static int mlxsw_m_reset(struct net_device *netdev, u32 *flags)
{
	struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev);
@@ -181,6 +195,7 @@ static const struct ethtool_ops mlxsw_m_port_ethtool_ops = {
	.get_module_info	= mlxsw_m_get_module_info,
	.get_module_eeprom	= mlxsw_m_get_module_eeprom,
	.get_module_eeprom_by_page = mlxsw_m_get_module_eeprom_by_page,
	.set_module_eeprom_by_page = mlxsw_m_set_module_eeprom_by_page,
	.reset			= mlxsw_m_reset,
	.get_module_power_mode	= mlxsw_m_get_module_power_mode,
	.set_module_power_mode	= mlxsw_m_set_module_power_mode,
+15 −0
Original line number Diff line number Diff line
@@ -1067,6 +1067,20 @@ mlxsw_sp_get_module_eeprom_by_page(struct net_device *dev,
						   module, page, extack);
}

static int
mlxsw_sp_set_module_eeprom_by_page(struct net_device *dev,
				   const struct ethtool_module_eeprom *page,
				   struct netlink_ext_ack *extack)
{
	struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
	struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
	u8 slot_index = mlxsw_sp_port->mapping.slot_index;
	u8 module = mlxsw_sp_port->mapping.module;

	return mlxsw_env_set_module_eeprom_by_page(mlxsw_sp->core, slot_index,
						   module, page, extack);
}

static int
mlxsw_sp_get_ts_info(struct net_device *netdev, struct ethtool_ts_info *info)
{
@@ -1256,6 +1270,7 @@ const struct ethtool_ops mlxsw_sp_port_ethtool_ops = {
	.get_module_info		= mlxsw_sp_get_module_info,
	.get_module_eeprom		= mlxsw_sp_get_module_eeprom,
	.get_module_eeprom_by_page	= mlxsw_sp_get_module_eeprom_by_page,
	.set_module_eeprom_by_page	= mlxsw_sp_set_module_eeprom_by_page,
	.get_ts_info			= mlxsw_sp_get_ts_info,
	.get_eth_phy_stats		= mlxsw_sp_get_eth_phy_stats,
	.get_eth_mac_stats		= mlxsw_sp_get_eth_mac_stats,