net/mlx5: Refactor module EEPROM query
Prepare for ethtool_ops::get_module_eeprom_data() implementation by extracting common part of mlx5_query_module_eeprom() into a separate function. Signed-off-by: Vladyslav Tarasiuk <vladyslavt@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
c781ff12a2
commit
e19b0a3474
|
@ -353,50 +353,23 @@ static void mlx5_sfp_eeprom_params_set(u16 *i2c_addr, int *page_num, u16 *offset
|
|||
*offset -= MLX5_EEPROM_PAGE_LENGTH;
|
||||
}
|
||||
|
||||
int mlx5_query_module_eeprom(struct mlx5_core_dev *dev,
|
||||
u16 offset, u16 size, u8 *data)
|
||||
static int mlx5_query_mcia(struct mlx5_core_dev *dev,
|
||||
struct mlx5_module_eeprom_query_params *params, u8 *data)
|
||||
{
|
||||
int module_num, status, err, page_num = 0;
|
||||
u32 in[MLX5_ST_SZ_DW(mcia_reg)] = {};
|
||||
u32 out[MLX5_ST_SZ_DW(mcia_reg)];
|
||||
u16 i2c_addr = 0;
|
||||
u8 module_id;
|
||||
int status, err;
|
||||
void *ptr;
|
||||
u16 size;
|
||||
|
||||
err = mlx5_query_module_num(dev, &module_num);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = mlx5_query_module_id(dev, module_num, &module_id);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
switch (module_id) {
|
||||
case MLX5_MODULE_ID_SFP:
|
||||
mlx5_sfp_eeprom_params_set(&i2c_addr, &page_num, &offset);
|
||||
break;
|
||||
case MLX5_MODULE_ID_QSFP:
|
||||
case MLX5_MODULE_ID_QSFP_PLUS:
|
||||
case MLX5_MODULE_ID_QSFP28:
|
||||
mlx5_qsfp_eeprom_params_set(&i2c_addr, &page_num, &offset);
|
||||
break;
|
||||
default:
|
||||
mlx5_core_err(dev, "Module ID not recognized: 0x%x\n", module_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (offset + size > MLX5_EEPROM_PAGE_LENGTH)
|
||||
/* Cross pages read, read until offset 256 in low page */
|
||||
size -= offset + size - MLX5_EEPROM_PAGE_LENGTH;
|
||||
|
||||
size = min_t(int, size, MLX5_EEPROM_MAX_BYTES);
|
||||
size = min_t(int, params->size, MLX5_EEPROM_MAX_BYTES);
|
||||
|
||||
MLX5_SET(mcia_reg, in, l, 0);
|
||||
MLX5_SET(mcia_reg, in, module, module_num);
|
||||
MLX5_SET(mcia_reg, in, i2c_device_address, i2c_addr);
|
||||
MLX5_SET(mcia_reg, in, page_number, page_num);
|
||||
MLX5_SET(mcia_reg, in, device_address, offset);
|
||||
MLX5_SET(mcia_reg, in, size, size);
|
||||
MLX5_SET(mcia_reg, in, module, params->module_number);
|
||||
MLX5_SET(mcia_reg, in, device_address, params->offset);
|
||||
MLX5_SET(mcia_reg, in, page_number, params->page);
|
||||
MLX5_SET(mcia_reg, in, i2c_device_address, params->i2c_address);
|
||||
|
||||
err = mlx5_core_access_reg(dev, in, sizeof(in), out,
|
||||
sizeof(out), MLX5_REG_MCIA, 0, 0);
|
||||
|
@ -415,6 +388,44 @@ int mlx5_query_module_eeprom(struct mlx5_core_dev *dev,
|
|||
|
||||
return size;
|
||||
}
|
||||
|
||||
int mlx5_query_module_eeprom(struct mlx5_core_dev *dev,
|
||||
u16 offset, u16 size, u8 *data)
|
||||
{
|
||||
struct mlx5_module_eeprom_query_params query = {0};
|
||||
u8 module_id;
|
||||
int err;
|
||||
|
||||
err = mlx5_query_module_num(dev, &query.module_number);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = mlx5_query_module_id(dev, query.module_number, &module_id);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
switch (module_id) {
|
||||
case MLX5_MODULE_ID_SFP:
|
||||
mlx5_sfp_eeprom_params_set(&query.i2c_address, &query.page, &query.offset);
|
||||
break;
|
||||
case MLX5_MODULE_ID_QSFP:
|
||||
case MLX5_MODULE_ID_QSFP_PLUS:
|
||||
case MLX5_MODULE_ID_QSFP28:
|
||||
mlx5_qsfp_eeprom_params_set(&query.i2c_address, &query.page, &query.offset);
|
||||
break;
|
||||
default:
|
||||
mlx5_core_err(dev, "Module ID not recognized: 0x%x\n", module_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (query.offset + size > MLX5_EEPROM_PAGE_LENGTH)
|
||||
/* Cross pages read, read until offset 256 in low page */
|
||||
size -= offset + size - MLX5_EEPROM_PAGE_LENGTH;
|
||||
|
||||
query.size = size;
|
||||
|
||||
return mlx5_query_mcia(dev, &query, data);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mlx5_query_module_eeprom);
|
||||
|
||||
static int mlx5_query_port_pvlc(struct mlx5_core_dev *dev, u32 *pvlc,
|
||||
|
|
|
@ -62,6 +62,15 @@ enum mlx5_an_status {
|
|||
#define MLX5_EEPROM_PAGE_LENGTH 256
|
||||
#define MLX5_EEPROM_HIGH_PAGE_LENGTH 128
|
||||
|
||||
struct mlx5_module_eeprom_query_params {
|
||||
u16 size;
|
||||
u16 offset;
|
||||
u16 i2c_address;
|
||||
u32 page;
|
||||
u32 bank;
|
||||
u32 module_number;
|
||||
};
|
||||
|
||||
enum mlx5e_link_mode {
|
||||
MLX5E_1000BASE_CX_SGMII = 0,
|
||||
MLX5E_1000BASE_KX = 1,
|
||||
|
|
Loading…
Reference in New Issue