Commit 25f428f9 authored by David S. Miller's avatar David S. Miller

Merge branch 'mlxsw-line-card-prep'

Ido Schimmel says:

====================
mlxsw: Preparations for line cards support

Currently, mlxsw registers thermal zones as well as hwmon entries for
objects such as transceiver modules and gearboxes. In upcoming modular
systems, these objects are no longer found on the main board (i.e., slot
0), but on plug-able line cards. This patchset prepares mlxsw for such
systems in terms of hwmon, thermal and cable access support.

Patches #1-#3 gradually prepare mlxsw for transceiver modules access
support for line cards by splitting some of the internal structures and
some APIs.

Patches #4-#5 gradually prepare mlxsw for hwmon support for line cards
by splitting some of the internal structures and augmenting them with a
slot index.

Patches #6-#7 do the same for thermal zones.

Patch #8 selects cooling device for binding to a thermal zone by exact
name match to prevent binding to non-relevant devices.

Patch #9 replaces internal define for thermal zone name length with a
common define.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents be52d266 03978fb8
...@@ -21,19 +21,36 @@ struct mlxsw_env_module_info { ...@@ -21,19 +21,36 @@ struct mlxsw_env_module_info {
enum mlxsw_reg_pmtm_module_type type; enum mlxsw_reg_pmtm_module_type type;
}; };
struct mlxsw_env { struct mlxsw_env_line_card {
struct mlxsw_core *core;
u8 module_count; u8 module_count;
struct mutex module_info_lock; /* Protects 'module_info'. */
struct mlxsw_env_module_info module_info[]; struct mlxsw_env_module_info module_info[];
}; };
static int __mlxsw_env_validate_module_type(struct mlxsw_core *core, u8 module) struct mlxsw_env {
struct mlxsw_core *core;
u8 max_module_count; /* Maximum number of modules per-slot. */
u8 num_of_slots; /* Including the main board. */
struct mutex line_cards_lock; /* Protects line cards. */
struct mlxsw_env_line_card *line_cards[];
};
static struct
mlxsw_env_module_info *mlxsw_env_module_info_get(struct mlxsw_core *mlxsw_core,
u8 slot_index, u8 module)
{ {
struct mlxsw_env *mlxsw_env = mlxsw_core_env(core); struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core);
return &mlxsw_env->line_cards[slot_index]->module_info[module];
}
static int __mlxsw_env_validate_module_type(struct mlxsw_core *core,
u8 slot_index, u8 module)
{
struct mlxsw_env_module_info *module_info;
int err; int err;
switch (mlxsw_env->module_info[module].type) { module_info = mlxsw_env_module_info_get(core, slot_index, module);
switch (module_info->type) {
case MLXSW_REG_PMTM_MODULE_TYPE_TWISTED_PAIR: case MLXSW_REG_PMTM_MODULE_TYPE_TWISTED_PAIR:
err = -EINVAL; err = -EINVAL;
break; break;
...@@ -44,33 +61,35 @@ static int __mlxsw_env_validate_module_type(struct mlxsw_core *core, u8 module) ...@@ -44,33 +61,35 @@ static int __mlxsw_env_validate_module_type(struct mlxsw_core *core, u8 module)
return err; return err;
} }
static int mlxsw_env_validate_module_type(struct mlxsw_core *core, u8 module) static int mlxsw_env_validate_module_type(struct mlxsw_core *core,
u8 slot_index, u8 module)
{ {
struct mlxsw_env *mlxsw_env = mlxsw_core_env(core); struct mlxsw_env *mlxsw_env = mlxsw_core_env(core);
int err; int err;
mutex_lock(&mlxsw_env->module_info_lock); mutex_lock(&mlxsw_env->line_cards_lock);
err = __mlxsw_env_validate_module_type(core, module); err = __mlxsw_env_validate_module_type(core, slot_index, module);
mutex_unlock(&mlxsw_env->module_info_lock); mutex_unlock(&mlxsw_env->line_cards_lock);
return err; return err;
} }
static int static int
mlxsw_env_validate_cable_ident(struct mlxsw_core *core, int id, bool *qsfp, mlxsw_env_validate_cable_ident(struct mlxsw_core *core, u8 slot_index, int id,
bool *cmis) bool *qsfp, bool *cmis)
{ {
char mcia_pl[MLXSW_REG_MCIA_LEN]; char mcia_pl[MLXSW_REG_MCIA_LEN];
char *eeprom_tmp; char *eeprom_tmp;
u8 ident; u8 ident;
int err; int err;
err = mlxsw_env_validate_module_type(core, id); err = mlxsw_env_validate_module_type(core, slot_index, id);
if (err) if (err)
return err; return err;
mlxsw_reg_mcia_pack(mcia_pl, 0, id, 0, MLXSW_REG_MCIA_PAGE0_LO_OFF, 0, mlxsw_reg_mcia_pack(mcia_pl, slot_index, id, 0,
1, MLXSW_REG_MCIA_I2C_ADDR_LOW); MLXSW_REG_MCIA_PAGE0_LO_OFF, 0, 1,
MLXSW_REG_MCIA_I2C_ADDR_LOW);
err = mlxsw_reg_query(core, MLXSW_REG(mcia), mcia_pl); err = mlxsw_reg_query(core, MLXSW_REG(mcia), mcia_pl);
if (err) if (err)
return err; return err;
...@@ -99,8 +118,8 @@ mlxsw_env_validate_cable_ident(struct mlxsw_core *core, int id, bool *qsfp, ...@@ -99,8 +118,8 @@ mlxsw_env_validate_cable_ident(struct mlxsw_core *core, int id, bool *qsfp,
} }
static int static int
mlxsw_env_query_module_eeprom(struct mlxsw_core *mlxsw_core, int module, mlxsw_env_query_module_eeprom(struct mlxsw_core *mlxsw_core, u8 slot_index,
u16 offset, u16 size, void *data, int module, u16 offset, u16 size, void *data,
bool qsfp, unsigned int *p_read_size) bool qsfp, unsigned int *p_read_size)
{ {
char mcia_pl[MLXSW_REG_MCIA_LEN]; char mcia_pl[MLXSW_REG_MCIA_LEN];
...@@ -145,7 +164,7 @@ mlxsw_env_query_module_eeprom(struct mlxsw_core *mlxsw_core, int module, ...@@ -145,7 +164,7 @@ mlxsw_env_query_module_eeprom(struct mlxsw_core *mlxsw_core, int module,
} }
} }
mlxsw_reg_mcia_pack(mcia_pl, 0, module, 0, page, offset, size, mlxsw_reg_mcia_pack(mcia_pl, slot_index, module, 0, page, offset, size,
i2c_addr); i2c_addr);
err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mcia), mcia_pl); err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mcia), mcia_pl);
...@@ -163,8 +182,9 @@ mlxsw_env_query_module_eeprom(struct mlxsw_core *mlxsw_core, int module, ...@@ -163,8 +182,9 @@ mlxsw_env_query_module_eeprom(struct mlxsw_core *mlxsw_core, int module,
return 0; return 0;
} }
int mlxsw_env_module_temp_thresholds_get(struct mlxsw_core *core, int module, int
int off, int *temp) mlxsw_env_module_temp_thresholds_get(struct mlxsw_core *core, u8 slot_index,
int module, int off, int *temp)
{ {
unsigned int module_temp, module_crit, module_emerg; unsigned int module_temp, module_crit, module_emerg;
union { union {
...@@ -178,8 +198,9 @@ int mlxsw_env_module_temp_thresholds_get(struct mlxsw_core *core, int module, ...@@ -178,8 +198,9 @@ int mlxsw_env_module_temp_thresholds_get(struct mlxsw_core *core, int module,
int page; int page;
int err; int err;
mlxsw_reg_mtmp_pack(mtmp_pl, 0, MLXSW_REG_MTMP_MODULE_INDEX_MIN + module, mlxsw_reg_mtmp_pack(mtmp_pl, slot_index,
false, false); MLXSW_REG_MTMP_MODULE_INDEX_MIN + module, false,
false);
err = mlxsw_reg_query(core, MLXSW_REG(mtmp), mtmp_pl); err = mlxsw_reg_query(core, MLXSW_REG(mtmp), mtmp_pl);
if (err) if (err)
return err; return err;
...@@ -208,7 +229,8 @@ int mlxsw_env_module_temp_thresholds_get(struct mlxsw_core *core, int module, ...@@ -208,7 +229,8 @@ int mlxsw_env_module_temp_thresholds_get(struct mlxsw_core *core, int module,
*/ */
/* Validate module identifier value. */ /* Validate module identifier value. */
err = mlxsw_env_validate_cable_ident(core, module, &qsfp, &cmis); err = mlxsw_env_validate_cable_ident(core, slot_index, module, &qsfp,
&cmis);
if (err) if (err)
return err; return err;
...@@ -220,12 +242,12 @@ int mlxsw_env_module_temp_thresholds_get(struct mlxsw_core *core, int module, ...@@ -220,12 +242,12 @@ int mlxsw_env_module_temp_thresholds_get(struct mlxsw_core *core, int module,
page = MLXSW_REG_MCIA_TH_PAGE_CMIS_NUM; page = MLXSW_REG_MCIA_TH_PAGE_CMIS_NUM;
else else
page = MLXSW_REG_MCIA_TH_PAGE_NUM; page = MLXSW_REG_MCIA_TH_PAGE_NUM;
mlxsw_reg_mcia_pack(mcia_pl, 0, module, 0, page, mlxsw_reg_mcia_pack(mcia_pl, slot_index, module, 0, page,
MLXSW_REG_MCIA_TH_PAGE_OFF + off, MLXSW_REG_MCIA_TH_PAGE_OFF + off,
MLXSW_REG_MCIA_TH_ITEM_SIZE, MLXSW_REG_MCIA_TH_ITEM_SIZE,
MLXSW_REG_MCIA_I2C_ADDR_LOW); MLXSW_REG_MCIA_I2C_ADDR_LOW);
} else { } else {
mlxsw_reg_mcia_pack(mcia_pl, 0, module, 0, mlxsw_reg_mcia_pack(mcia_pl, slot_index, module, 0,
MLXSW_REG_MCIA_PAGE0_LO, MLXSW_REG_MCIA_PAGE0_LO,
off, MLXSW_REG_MCIA_TH_ITEM_SIZE, off, MLXSW_REG_MCIA_TH_ITEM_SIZE,
MLXSW_REG_MCIA_I2C_ADDR_HIGH); MLXSW_REG_MCIA_I2C_ADDR_HIGH);
...@@ -243,8 +265,8 @@ int mlxsw_env_module_temp_thresholds_get(struct mlxsw_core *core, int module, ...@@ -243,8 +265,8 @@ int mlxsw_env_module_temp_thresholds_get(struct mlxsw_core *core, int module,
} }
int mlxsw_env_get_module_info(struct net_device *netdev, int mlxsw_env_get_module_info(struct net_device *netdev,
struct mlxsw_core *mlxsw_core, int module, struct mlxsw_core *mlxsw_core, u8 slot_index,
struct ethtool_modinfo *modinfo) int module, struct ethtool_modinfo *modinfo)
{ {
u8 module_info[MLXSW_REG_MCIA_EEPROM_MODULE_INFO_SIZE]; u8 module_info[MLXSW_REG_MCIA_EEPROM_MODULE_INFO_SIZE];
u16 offset = MLXSW_REG_MCIA_EEPROM_MODULE_INFO_SIZE; u16 offset = MLXSW_REG_MCIA_EEPROM_MODULE_INFO_SIZE;
...@@ -252,15 +274,16 @@ int mlxsw_env_get_module_info(struct net_device *netdev, ...@@ -252,15 +274,16 @@ int mlxsw_env_get_module_info(struct net_device *netdev,
unsigned int read_size; unsigned int read_size;
int err; int err;
err = mlxsw_env_validate_module_type(mlxsw_core, module); err = mlxsw_env_validate_module_type(mlxsw_core, slot_index, module);
if (err) { if (err) {
netdev_err(netdev, netdev_err(netdev,
"EEPROM is not equipped on port module type"); "EEPROM is not equipped on port module type");
return err; return err;
} }
err = mlxsw_env_query_module_eeprom(mlxsw_core, module, 0, offset, err = mlxsw_env_query_module_eeprom(mlxsw_core, slot_index, module, 0,
module_info, false, &read_size); offset, module_info, false,
&read_size);
if (err) if (err)
return err; return err;
...@@ -289,9 +312,10 @@ int mlxsw_env_get_module_info(struct net_device *netdev, ...@@ -289,9 +312,10 @@ int mlxsw_env_get_module_info(struct net_device *netdev,
break; break;
case MLXSW_REG_MCIA_EEPROM_MODULE_INFO_ID_SFP: case MLXSW_REG_MCIA_EEPROM_MODULE_INFO_ID_SFP:
/* Verify if transceiver provides diagnostic monitoring page */ /* Verify if transceiver provides diagnostic monitoring page */
err = mlxsw_env_query_module_eeprom(mlxsw_core, module, err = mlxsw_env_query_module_eeprom(mlxsw_core, slot_index,
SFP_DIAGMON, 1, &diag_mon, module, SFP_DIAGMON, 1,
false, &read_size); &diag_mon, false,
&read_size);
if (err) if (err)
return err; return err;
...@@ -330,8 +354,9 @@ int mlxsw_env_get_module_info(struct net_device *netdev, ...@@ -330,8 +354,9 @@ int mlxsw_env_get_module_info(struct net_device *netdev,
EXPORT_SYMBOL(mlxsw_env_get_module_info); EXPORT_SYMBOL(mlxsw_env_get_module_info);
int mlxsw_env_get_module_eeprom(struct net_device *netdev, int mlxsw_env_get_module_eeprom(struct net_device *netdev,
struct mlxsw_core *mlxsw_core, int module, struct mlxsw_core *mlxsw_core, u8 slot_index,
struct ethtool_eeprom *ee, u8 *data) int module, struct ethtool_eeprom *ee,
u8 *data)
{ {
int offset = ee->offset; int offset = ee->offset;
unsigned int read_size; unsigned int read_size;
...@@ -344,12 +369,14 @@ int mlxsw_env_get_module_eeprom(struct net_device *netdev, ...@@ -344,12 +369,14 @@ int mlxsw_env_get_module_eeprom(struct net_device *netdev,
memset(data, 0, ee->len); memset(data, 0, ee->len);
/* Validate module identifier value. */ /* Validate module identifier value. */
err = mlxsw_env_validate_cable_ident(mlxsw_core, module, &qsfp, &cmis); err = mlxsw_env_validate_cable_ident(mlxsw_core, slot_index, module,
&qsfp, &cmis);
if (err) if (err)
return err; return err;
while (i < ee->len) { while (i < ee->len) {
err = mlxsw_env_query_module_eeprom(mlxsw_core, module, offset, err = mlxsw_env_query_module_eeprom(mlxsw_core, slot_index,
module, offset,
ee->len - i, data + i, ee->len - i, data + i,
qsfp, &read_size); qsfp, &read_size);
if (err) { if (err) {
...@@ -395,7 +422,8 @@ static int mlxsw_env_mcia_status_process(const char *mcia_pl, ...@@ -395,7 +422,8 @@ static int mlxsw_env_mcia_status_process(const char *mcia_pl,
} }
int int
mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core, u8 module, mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core,
u8 slot_index, u8 module,
const struct ethtool_module_eeprom *page, const struct ethtool_module_eeprom *page,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
...@@ -403,7 +431,7 @@ mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core, u8 module, ...@@ -403,7 +431,7 @@ mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core, u8 module,
u16 device_addr; u16 device_addr;
int err; int err;
err = mlxsw_env_validate_module_type(mlxsw_core, module); err = mlxsw_env_validate_module_type(mlxsw_core, slot_index, module);
if (err) { if (err) {
NL_SET_ERR_MSG_MOD(extack, "EEPROM is not equipped on port module type"); NL_SET_ERR_MSG_MOD(extack, "EEPROM is not equipped on port module type");
return err; return err;
...@@ -420,7 +448,7 @@ mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core, u8 module, ...@@ -420,7 +448,7 @@ mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core, u8 module,
size = min_t(u8, page->length - bytes_read, size = min_t(u8, page->length - bytes_read,
MLXSW_REG_MCIA_EEPROM_SIZE); MLXSW_REG_MCIA_EEPROM_SIZE);
mlxsw_reg_mcia_pack(mcia_pl, 0, module, 0, page->page, mlxsw_reg_mcia_pack(mcia_pl, slot_index, module, 0, page->page,
device_addr + bytes_read, size, device_addr + bytes_read, size,
page->i2c_address); page->i2c_address);
mlxsw_reg_mcia_bank_number_set(mcia_pl, page->bank); mlxsw_reg_mcia_bank_number_set(mcia_pl, page->bank);
...@@ -444,20 +472,23 @@ mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core, u8 module, ...@@ -444,20 +472,23 @@ mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core, u8 module,
} }
EXPORT_SYMBOL(mlxsw_env_get_module_eeprom_by_page); EXPORT_SYMBOL(mlxsw_env_get_module_eeprom_by_page);
static int mlxsw_env_module_reset(struct mlxsw_core *mlxsw_core, u8 module) static int mlxsw_env_module_reset(struct mlxsw_core *mlxsw_core, u8 slot_index,
u8 module)
{ {
char pmaos_pl[MLXSW_REG_PMAOS_LEN]; char pmaos_pl[MLXSW_REG_PMAOS_LEN];
mlxsw_reg_pmaos_pack(pmaos_pl, 0, module); mlxsw_reg_pmaos_pack(pmaos_pl, slot_index, module);
mlxsw_reg_pmaos_rst_set(pmaos_pl, true); mlxsw_reg_pmaos_rst_set(pmaos_pl, true);
return mlxsw_reg_write(mlxsw_core, MLXSW_REG(pmaos), pmaos_pl); return mlxsw_reg_write(mlxsw_core, MLXSW_REG(pmaos), pmaos_pl);
} }
int mlxsw_env_reset_module(struct net_device *netdev, int mlxsw_env_reset_module(struct net_device *netdev,
struct mlxsw_core *mlxsw_core, u8 module, u32 *flags) struct mlxsw_core *mlxsw_core, u8 slot_index,
u8 module, u32 *flags)
{ {
struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core); struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core);
struct mlxsw_env_module_info *module_info;
u32 req = *flags; u32 req = *flags;
int err; int err;
...@@ -465,28 +496,29 @@ int mlxsw_env_reset_module(struct net_device *netdev, ...@@ -465,28 +496,29 @@ int mlxsw_env_reset_module(struct net_device *netdev,
!(req & (ETH_RESET_PHY << ETH_RESET_SHARED_SHIFT))) !(req & (ETH_RESET_PHY << ETH_RESET_SHARED_SHIFT)))
return 0; return 0;
mutex_lock(&mlxsw_env->module_info_lock); mutex_lock(&mlxsw_env->line_cards_lock);
err = __mlxsw_env_validate_module_type(mlxsw_core, module); err = __mlxsw_env_validate_module_type(mlxsw_core, slot_index, module);
if (err) { if (err) {
netdev_err(netdev, "Reset module is not supported on port module type\n"); netdev_err(netdev, "Reset module is not supported on port module type\n");
goto out; goto out;
} }
if (mlxsw_env->module_info[module].num_ports_up) { module_info = mlxsw_env_module_info_get(mlxsw_core, slot_index, module);
if (module_info->num_ports_up) {
netdev_err(netdev, "Cannot reset module when ports using it are administratively up\n"); netdev_err(netdev, "Cannot reset module when ports using it are administratively up\n");
err = -EINVAL; err = -EINVAL;
goto out; goto out;
} }
if (mlxsw_env->module_info[module].num_ports_mapped > 1 && if (module_info->num_ports_mapped > 1 &&
!(req & (ETH_RESET_PHY << ETH_RESET_SHARED_SHIFT))) { !(req & (ETH_RESET_PHY << ETH_RESET_SHARED_SHIFT))) {
netdev_err(netdev, "Cannot reset module without \"phy-shared\" flag when shared by multiple ports\n"); netdev_err(netdev, "Cannot reset module without \"phy-shared\" flag when shared by multiple ports\n");
err = -EINVAL; err = -EINVAL;
goto out; goto out;
} }
err = mlxsw_env_module_reset(mlxsw_core, module); err = mlxsw_env_module_reset(mlxsw_core, slot_index, module);
if (err) { if (err) {
netdev_err(netdev, "Failed to reset module\n"); netdev_err(netdev, "Failed to reset module\n");
goto out; goto out;
...@@ -495,32 +527,35 @@ int mlxsw_env_reset_module(struct net_device *netdev, ...@@ -495,32 +527,35 @@ int mlxsw_env_reset_module(struct net_device *netdev,
*flags &= ~(ETH_RESET_PHY | (ETH_RESET_PHY << ETH_RESET_SHARED_SHIFT)); *flags &= ~(ETH_RESET_PHY | (ETH_RESET_PHY << ETH_RESET_SHARED_SHIFT));
out: out:
mutex_unlock(&mlxsw_env->module_info_lock); mutex_unlock(&mlxsw_env->line_cards_lock);
return err; return err;
} }
EXPORT_SYMBOL(mlxsw_env_reset_module); EXPORT_SYMBOL(mlxsw_env_reset_module);
int int
mlxsw_env_get_module_power_mode(struct mlxsw_core *mlxsw_core, u8 module, mlxsw_env_get_module_power_mode(struct mlxsw_core *mlxsw_core, u8 slot_index,
u8 module,
struct ethtool_module_power_mode_params *params, struct ethtool_module_power_mode_params *params,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core); struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core);
struct mlxsw_env_module_info *module_info;
char mcion_pl[MLXSW_REG_MCION_LEN]; char mcion_pl[MLXSW_REG_MCION_LEN];
u32 status_bits; u32 status_bits;
int err; int err;
mutex_lock(&mlxsw_env->module_info_lock); mutex_lock(&mlxsw_env->line_cards_lock);
err = __mlxsw_env_validate_module_type(mlxsw_core, module); err = __mlxsw_env_validate_module_type(mlxsw_core, slot_index, module);
if (err) { if (err) {
NL_SET_ERR_MSG_MOD(extack, "Power mode is not supported on port module type"); NL_SET_ERR_MSG_MOD(extack, "Power mode is not supported on port module type");
goto out; goto out;
} }
params->policy = mlxsw_env->module_info[module].power_mode_policy; module_info = mlxsw_env_module_info_get(mlxsw_core, slot_index, module);
params->policy = module_info->power_mode_policy;
mlxsw_reg_mcion_pack(mcion_pl, 0, module); mlxsw_reg_mcion_pack(mcion_pl, slot_index, module);
err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mcion), mcion_pl); err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mcion), mcion_pl);
if (err) { if (err) {
NL_SET_ERR_MSG_MOD(extack, "Failed to retrieve module's power mode"); NL_SET_ERR_MSG_MOD(extack, "Failed to retrieve module's power mode");
...@@ -537,18 +572,18 @@ mlxsw_env_get_module_power_mode(struct mlxsw_core *mlxsw_core, u8 module, ...@@ -537,18 +572,18 @@ mlxsw_env_get_module_power_mode(struct mlxsw_core *mlxsw_core, u8 module,
params->mode = ETHTOOL_MODULE_POWER_MODE_HIGH; params->mode = ETHTOOL_MODULE_POWER_MODE_HIGH;
out: out:
mutex_unlock(&mlxsw_env->module_info_lock); mutex_unlock(&mlxsw_env->line_cards_lock);
return err; return err;
} }
EXPORT_SYMBOL(mlxsw_env_get_module_power_mode); EXPORT_SYMBOL(mlxsw_env_get_module_power_mode);
static int mlxsw_env_module_enable_set(struct mlxsw_core *mlxsw_core, static int mlxsw_env_module_enable_set(struct mlxsw_core *mlxsw_core,
u8 module, bool enable) u8 slot_index, u8 module, bool enable)
{ {
enum mlxsw_reg_pmaos_admin_status admin_status; enum mlxsw_reg_pmaos_admin_status admin_status;
char pmaos_pl[MLXSW_REG_PMAOS_LEN]; char pmaos_pl[MLXSW_REG_PMAOS_LEN];
mlxsw_reg_pmaos_pack(pmaos_pl, 0, module); mlxsw_reg_pmaos_pack(pmaos_pl, slot_index, module);
admin_status = enable ? MLXSW_REG_PMAOS_ADMIN_STATUS_ENABLED : admin_status = enable ? MLXSW_REG_PMAOS_ADMIN_STATUS_ENABLED :
MLXSW_REG_PMAOS_ADMIN_STATUS_DISABLED; MLXSW_REG_PMAOS_ADMIN_STATUS_DISABLED;
mlxsw_reg_pmaos_admin_status_set(pmaos_pl, admin_status); mlxsw_reg_pmaos_admin_status_set(pmaos_pl, admin_status);
...@@ -558,12 +593,13 @@ static int mlxsw_env_module_enable_set(struct mlxsw_core *mlxsw_core, ...@@ -558,12 +593,13 @@ static int mlxsw_env_module_enable_set(struct mlxsw_core *mlxsw_core,
} }
static int mlxsw_env_module_low_power_set(struct mlxsw_core *mlxsw_core, static int mlxsw_env_module_low_power_set(struct mlxsw_core *mlxsw_core,
u8 module, bool low_power) u8 slot_index, u8 module,
bool low_power)
{ {
u16 eeprom_override_mask, eeprom_override; u16 eeprom_override_mask, eeprom_override;
char pmmp_pl[MLXSW_REG_PMMP_LEN]; char pmmp_pl[MLXSW_REG_PMMP_LEN];
mlxsw_reg_pmmp_pack(pmmp_pl, 0, module); mlxsw_reg_pmmp_pack(pmmp_pl, slot_index, module);
mlxsw_reg_pmmp_sticky_set(pmmp_pl, true); mlxsw_reg_pmmp_sticky_set(pmmp_pl, true);
/* Mask all the bits except low power mode. */ /* Mask all the bits except low power mode. */
eeprom_override_mask = ~MLXSW_REG_PMMP_EEPROM_OVERRIDE_LOW_POWER_MASK; eeprom_override_mask = ~MLXSW_REG_PMMP_EEPROM_OVERRIDE_LOW_POWER_MASK;
...@@ -576,24 +612,26 @@ static int mlxsw_env_module_low_power_set(struct mlxsw_core *mlxsw_core, ...@@ -576,24 +612,26 @@ static int mlxsw_env_module_low_power_set(struct mlxsw_core *mlxsw_core,
} }
static int __mlxsw_env_set_module_power_mode(struct mlxsw_core *mlxsw_core, static int __mlxsw_env_set_module_power_mode(struct mlxsw_core *mlxsw_core,
u8 module, bool low_power, u8 slot_index, u8 module,
bool low_power,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
int err; int err;
err = mlxsw_env_module_enable_set(mlxsw_core, module, false); err = mlxsw_env_module_enable_set(mlxsw_core, slot_index, module, false);
if (err) { if (err) {
NL_SET_ERR_MSG_MOD(extack, "Failed to disable module"); NL_SET_ERR_MSG_MOD(extack, "Failed to disable module");
return err; return err;
} }
err = mlxsw_env_module_low_power_set(mlxsw_core, module, low_power); err = mlxsw_env_module_low_power_set(mlxsw_core, slot_index, module,
low_power);
if (err) { if (err) {
NL_SET_ERR_MSG_MOD(extack, "Failed to set module's power mode"); NL_SET_ERR_MSG_MOD(extack, "Failed to set module's power mode");
goto err_module_low_power_set; goto err_module_low_power_set;
} }
err = mlxsw_env_module_enable_set(mlxsw_core, module, true); err = mlxsw_env_module_enable_set(mlxsw_core, slot_index, module, true);
if (err) { if (err) {
NL_SET_ERR_MSG_MOD(extack, "Failed to enable module"); NL_SET_ERR_MSG_MOD(extack, "Failed to enable module");
goto err_module_enable_set; goto err_module_enable_set;
...@@ -602,18 +640,21 @@ static int __mlxsw_env_set_module_power_mode(struct mlxsw_core *mlxsw_core, ...@@ -602,18 +640,21 @@ static int __mlxsw_env_set_module_power_mode(struct mlxsw_core *mlxsw_core,
return 0; return 0;
err_module_enable_set: err_module_enable_set:
mlxsw_env_module_low_power_set(mlxsw_core, module, !low_power); mlxsw_env_module_low_power_set(mlxsw_core, slot_index, module,
!low_power);
err_module_low_power_set: err_module_low_power_set:
mlxsw_env_module_enable_set(mlxsw_core, module, true); mlxsw_env_module_enable_set(mlxsw_core, slot_index, module, true);
return err; return err;
} }
int int
mlxsw_env_set_module_power_mode(struct mlxsw_core *mlxsw_core, u8 module, mlxsw_env_set_module_power_mode(struct mlxsw_core *mlxsw_core, u8 slot_index,
u8 module,
enum ethtool_module_power_mode_policy policy, enum ethtool_module_power_mode_policy policy,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core); struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core);
struct mlxsw_env_module_info *module_info;
bool low_power; bool low_power;
int err = 0; int err = 0;
...@@ -623,45 +664,46 @@ mlxsw_env_set_module_power_mode(struct mlxsw_core *mlxsw_core, u8 module, ...@@ -623,45 +664,46 @@ mlxsw_env_set_module_power_mode(struct mlxsw_core *mlxsw_core, u8 module,
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
mutex_lock(&mlxsw_env->module_info_lock); mutex_lock(&mlxsw_env->line_cards_lock);
err = __mlxsw_env_validate_module_type(mlxsw_core, module); err = __mlxsw_env_validate_module_type(mlxsw_core, slot_index, module);
if (err) { if (err) {
NL_SET_ERR_MSG_MOD(extack, NL_SET_ERR_MSG_MOD(extack,
"Power mode set is not supported on port module type"); "Power mode set is not supported on port module type");
goto out; goto out;
} }
if (mlxsw_env->module_info[module].power_mode_policy == policy) module_info = mlxsw_env_module_info_get(mlxsw_core, slot_index, module);
if (module_info->power_mode_policy == policy)
goto out; goto out;
/* If any ports are up, we are already in high power mode. */ /* If any ports are up, we are already in high power mode. */
if (mlxsw_env->module_info[module].num_ports_up) if (module_info->num_ports_up)
goto out_set_policy; goto out_set_policy;
low_power = policy == ETHTOOL_MODULE_POWER_MODE_POLICY_AUTO; low_power = policy == ETHTOOL_MODULE_POWER_MODE_POLICY_AUTO;
err = __mlxsw_env_set_module_power_mode(mlxsw_core, module, low_power, err = __mlxsw_env_set_module_power_mode(mlxsw_core, slot_index, module,
extack); low_power, extack);
if (err) if (err)
goto out; goto out;
out_set_policy: out_set_policy:
mlxsw_env->module_info[module].power_mode_policy = policy; module_info->power_mode_policy = policy;
out: out:
mutex_unlock(&mlxsw_env->module_info_lock); mutex_unlock(&mlxsw_env->line_cards_lock);
return err; return err;
} }
EXPORT_SYMBOL(mlxsw_env_set_module_power_mode); EXPORT_SYMBOL(mlxsw_env_set_module_power_mode);
static int mlxsw_env_module_has_temp_sensor(struct mlxsw_core *mlxsw_core, static int mlxsw_env_module_has_temp_sensor(struct mlxsw_core *mlxsw_core,
u8 module, u8 slot_index, u8 module,
bool *p_has_temp_sensor) bool *p_has_temp_sensor)
{ {
char mtbr_pl[MLXSW_REG_MTBR_LEN]; char mtbr_pl[MLXSW_REG_MTBR_LEN];
u16 temp; u16 temp;
int err; int err;
mlxsw_reg_mtbr_pack(mtbr_pl, 0, mlxsw_reg_mtbr_pack(mtbr_pl, slot_index,
MLXSW_REG_MTBR_BASE_MODULE_INDEX + module, 1); MLXSW_REG_MTBR_BASE_MODULE_INDEX + module, 1);
err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mtbr), mtbr_pl); err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mtbr), mtbr_pl);
if (err) if (err)
...@@ -682,13 +724,15 @@ static int mlxsw_env_module_has_temp_sensor(struct mlxsw_core *mlxsw_core, ...@@ -682,13 +724,15 @@ static int mlxsw_env_module_has_temp_sensor(struct mlxsw_core *mlxsw_core,
return 0; return 0;
} }
static int mlxsw_env_temp_event_set(struct mlxsw_core *mlxsw_core, static int
mlxsw_env_temp_event_set(struct mlxsw_core *mlxsw_core, u8 slot_index,
u16 sensor_index, bool enable) u16 sensor_index, bool enable)
{ {
char mtmp_pl[MLXSW_REG_MTMP_LEN] = {0}; char mtmp_pl[MLXSW_REG_MTMP_LEN] = {0};
enum mlxsw_reg_mtmp_tee tee; enum mlxsw_reg_mtmp_tee tee;
int err, threshold_hi; int err, threshold_hi;
mlxsw_reg_mtmp_slot_index_set(mtmp_pl, slot_index);
mlxsw_reg_mtmp_sensor_index_set(mtmp_pl, sensor_index); mlxsw_reg_mtmp_sensor_index_set(mtmp_pl, sensor_index);
err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mtmp), mtmp_pl); err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mtmp), mtmp_pl);
if (err) if (err)
...@@ -696,6 +740,7 @@ static int mlxsw_env_temp_event_set(struct mlxsw_core *mlxsw_core, ...@@ -696,6 +740,7 @@ static int mlxsw_env_temp_event_set(struct mlxsw_core *mlxsw_core,
if (enable) { if (enable) {
err = mlxsw_env_module_temp_thresholds_get(mlxsw_core, err = mlxsw_env_module_temp_thresholds_get(mlxsw_core,
slot_index,
sensor_index - sensor_index -
MLXSW_REG_MTMP_MODULE_INDEX_MIN, MLXSW_REG_MTMP_MODULE_INDEX_MIN,
SFP_TEMP_HIGH_WARN, SFP_TEMP_HIGH_WARN,
...@@ -722,14 +767,16 @@ static int mlxsw_env_temp_event_set(struct mlxsw_core *mlxsw_core, ...@@ -722,14 +767,16 @@ static int mlxsw_env_temp_event_set(struct mlxsw_core *mlxsw_core,
return mlxsw_reg_write(mlxsw_core, MLXSW_REG(mtmp), mtmp_pl); return mlxsw_reg_write(mlxsw_core, MLXSW_REG(mtmp), mtmp_pl);
} }
static int mlxsw_env_module_temp_event_enable(struct mlxsw_core *mlxsw_core) static int mlxsw_env_module_temp_event_enable(struct mlxsw_core *mlxsw_core,
u8 slot_index)
{ {
struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core);
int i, err, sensor_index; int i, err, sensor_index;
bool has_temp_sensor; bool has_temp_sensor;
for (i = 0; i < mlxsw_core_env(mlxsw_core)->module_count; i++) { for (i = 0; i < mlxsw_env->line_cards[slot_index]->module_count; i++) {
err = mlxsw_env_module_has_temp_sensor(mlxsw_core, i, err = mlxsw_env_module_has_temp_sensor(mlxsw_core, slot_index,
&has_temp_sensor); i, &has_temp_sensor);
if (err) if (err)
return err; return err;
...@@ -737,7 +784,8 @@ static int mlxsw_env_module_temp_event_enable(struct mlxsw_core *mlxsw_core) ...@@ -737,7 +784,8 @@ static int mlxsw_env_module_temp_event_enable(struct mlxsw_core *mlxsw_core)
continue; continue;
sensor_index = i + MLXSW_REG_MTMP_MODULE_INDEX_MIN; sensor_index = i + MLXSW_REG_MTMP_MODULE_INDEX_MIN;
err = mlxsw_env_temp_event_set(mlxsw_core, sensor_index, true); err = mlxsw_env_temp_event_set(mlxsw_core, slot_index,
sensor_index, true);
if (err) if (err)
return err; return err;
} }
...@@ -754,6 +802,7 @@ struct mlxsw_env_module_temp_warn_event { ...@@ -754,6 +802,7 @@ struct mlxsw_env_module_temp_warn_event {
static void mlxsw_env_mtwe_event_work(struct work_struct *work) static void mlxsw_env_mtwe_event_work(struct work_struct *work)
{ {
struct mlxsw_env_module_temp_warn_event *event; struct mlxsw_env_module_temp_warn_event *event;
struct mlxsw_env_module_info *module_info;
struct mlxsw_env *mlxsw_env; struct mlxsw_env *mlxsw_env;
int i, sensor_warning; int i, sensor_warning;
bool is_overheat; bool is_overheat;
...@@ -762,7 +811,7 @@ static void mlxsw_env_mtwe_event_work(struct work_struct *work) ...@@ -762,7 +811,7 @@ static void mlxsw_env_mtwe_event_work(struct work_struct *work)
work); work);
mlxsw_env = event->mlxsw_env; mlxsw_env = event->mlxsw_env;
for (i = 0; i < mlxsw_env->module_count; i++) { for (i = 0; i < mlxsw_env->max_module_count; i++) {
/* 64-127 of sensor_index are mapped to the port modules /* 64-127 of sensor_index are mapped to the port modules
* sequentially (module 0 is mapped to sensor_index 64, * sequentially (module 0 is mapped to sensor_index 64,
* module 1 to sensor_index 65 and so on) * module 1 to sensor_index 65 and so on)
...@@ -770,9 +819,10 @@ static void mlxsw_env_mtwe_event_work(struct work_struct *work) ...@@ -770,9 +819,10 @@ static void mlxsw_env_mtwe_event_work(struct work_struct *work)
sensor_warning = sensor_warning =
mlxsw_reg_mtwe_sensor_warning_get(event->mtwe_pl, mlxsw_reg_mtwe_sensor_warning_get(event->mtwe_pl,
i + MLXSW_REG_MTMP_MODULE_INDEX_MIN); i + MLXSW_REG_MTMP_MODULE_INDEX_MIN);
mutex_lock(&mlxsw_env->module_info_lock); mutex_lock(&mlxsw_env->line_cards_lock);
is_overheat = /* MTWE only supports main board. */
mlxsw_env->module_info[i].is_overheat; module_info = mlxsw_env_module_info_get(mlxsw_env->core, 0, i);
is_overheat = module_info->is_overheat;
if ((is_overheat && sensor_warning) || if ((is_overheat && sensor_warning) ||
(!is_overheat && !sensor_warning)) { (!is_overheat && !sensor_warning)) {
...@@ -780,21 +830,21 @@ static void mlxsw_env_mtwe_event_work(struct work_struct *work) ...@@ -780,21 +830,21 @@ static void mlxsw_env_mtwe_event_work(struct work_struct *work)
* warning OR current state in "no warning" and MTWE * warning OR current state in "no warning" and MTWE
* does not report warning. * does not report warning.
*/ */
mutex_unlock(&mlxsw_env->module_info_lock); mutex_unlock(&mlxsw_env->line_cards_lock);
continue; continue;
} else if (is_overheat && !sensor_warning) { } else if (is_overheat && !sensor_warning) {
/* MTWE reports "no warning", turn is_overheat off. /* MTWE reports "no warning", turn is_overheat off.
*/ */
mlxsw_env->module_info[i].is_overheat = false; module_info->is_overheat = false;
mutex_unlock(&mlxsw_env->module_info_lock); mutex_unlock(&mlxsw_env->line_cards_lock);
} else { } else {
/* Current state is "no warning" and MTWE reports /* Current state is "no warning" and MTWE reports
* "warning", increase the counter and turn is_overheat * "warning", increase the counter and turn is_overheat
* on. * on.
*/ */
mlxsw_env->module_info[i].is_overheat = true; module_info->is_overheat = true;
mlxsw_env->module_info[i].module_overheat_counter++; module_info->module_overheat_counter++;
mutex_unlock(&mlxsw_env->module_info_lock); mutex_unlock(&mlxsw_env->line_cards_lock);
} }
} }
...@@ -838,6 +888,7 @@ static void mlxsw_env_temp_warn_event_unregister(struct mlxsw_env *mlxsw_env) ...@@ -838,6 +888,7 @@ static void mlxsw_env_temp_warn_event_unregister(struct mlxsw_env *mlxsw_env)
struct mlxsw_env_module_plug_unplug_event { struct mlxsw_env_module_plug_unplug_event {
struct mlxsw_env *mlxsw_env; struct mlxsw_env *mlxsw_env;
u8 slot_index;
u8 module; u8 module;
struct work_struct work; struct work_struct work;
}; };
...@@ -845,6 +896,7 @@ struct mlxsw_env_module_plug_unplug_event { ...@@ -845,6 +896,7 @@ struct mlxsw_env_module_plug_unplug_event {
static void mlxsw_env_pmpe_event_work(struct work_struct *work) static void mlxsw_env_pmpe_event_work(struct work_struct *work)
{ {
struct mlxsw_env_module_plug_unplug_event *event; struct mlxsw_env_module_plug_unplug_event *event;
struct mlxsw_env_module_info *module_info;
struct mlxsw_env *mlxsw_env; struct mlxsw_env *mlxsw_env;
bool has_temp_sensor; bool has_temp_sensor;
u16 sensor_index; u16 sensor_index;
...@@ -854,11 +906,16 @@ static void mlxsw_env_pmpe_event_work(struct work_struct *work) ...@@ -854,11 +906,16 @@ static void mlxsw_env_pmpe_event_work(struct work_struct *work)
work); work);
mlxsw_env = event->mlxsw_env; mlxsw_env = event->mlxsw_env;
mutex_lock(&mlxsw_env->module_info_lock); mutex_lock(&mlxsw_env->line_cards_lock);
mlxsw_env->module_info[event->module].is_overheat = false; module_info = mlxsw_env_module_info_get(mlxsw_env->core,
mutex_unlock(&mlxsw_env->module_info_lock); event->slot_index,
event->module);
module_info->is_overheat = false;
mutex_unlock(&mlxsw_env->line_cards_lock);
err = mlxsw_env_module_has_temp_sensor(mlxsw_env->core, event->module, err = mlxsw_env_module_has_temp_sensor(mlxsw_env->core,
event->slot_index,
event->module,
&has_temp_sensor); &has_temp_sensor);
/* Do not disable events on modules without sensors or faulty sensors /* Do not disable events on modules without sensors or faulty sensors
* because FW returns errors. * because FW returns errors.
...@@ -870,7 +927,8 @@ static void mlxsw_env_pmpe_event_work(struct work_struct *work) ...@@ -870,7 +927,8 @@ static void mlxsw_env_pmpe_event_work(struct work_struct *work)
goto out; goto out;
sensor_index = event->module + MLXSW_REG_MTMP_MODULE_INDEX_MIN; sensor_index = event->module + MLXSW_REG_MTMP_MODULE_INDEX_MIN;
mlxsw_env_temp_event_set(mlxsw_env->core, sensor_index, true); mlxsw_env_temp_event_set(mlxsw_env->core, event->slot_index,
sensor_index, true);
out: out:
kfree(event); kfree(event);
...@@ -880,12 +938,14 @@ static void ...@@ -880,12 +938,14 @@ static void
mlxsw_env_pmpe_listener_func(const struct mlxsw_reg_info *reg, char *pmpe_pl, mlxsw_env_pmpe_listener_func(const struct mlxsw_reg_info *reg, char *pmpe_pl,
void *priv) void *priv)
{ {
u8 slot_index = mlxsw_reg_pmpe_slot_index_get(pmpe_pl);
struct mlxsw_env_module_plug_unplug_event *event; struct mlxsw_env_module_plug_unplug_event *event;
enum mlxsw_reg_pmpe_module_status module_status; enum mlxsw_reg_pmpe_module_status module_status;
u8 module = mlxsw_reg_pmpe_module_get(pmpe_pl); u8 module = mlxsw_reg_pmpe_module_get(pmpe_pl);
struct mlxsw_env *mlxsw_env = priv; struct mlxsw_env *mlxsw_env = priv;
if (WARN_ON_ONCE(module >= mlxsw_env->module_count)) if (WARN_ON_ONCE(module >= mlxsw_env->max_module_count ||
slot_index >= mlxsw_env->num_of_slots))
return; return;
module_status = mlxsw_reg_pmpe_module_status_get(pmpe_pl); module_status = mlxsw_reg_pmpe_module_status_get(pmpe_pl);
...@@ -897,6 +957,7 @@ mlxsw_env_pmpe_listener_func(const struct mlxsw_reg_info *reg, char *pmpe_pl, ...@@ -897,6 +957,7 @@ mlxsw_env_pmpe_listener_func(const struct mlxsw_reg_info *reg, char *pmpe_pl,
return; return;
event->mlxsw_env = mlxsw_env; event->mlxsw_env = mlxsw_env;
event->slot_index = slot_index;
event->module = module; event->module = module;
INIT_WORK(&event->work, mlxsw_env_pmpe_event_work); INIT_WORK(&event->work, mlxsw_env_pmpe_event_work);
mlxsw_core_schedule_work(&event->work); mlxsw_core_schedule_work(&event->work);
...@@ -924,14 +985,16 @@ mlxsw_env_module_plug_event_unregister(struct mlxsw_env *mlxsw_env) ...@@ -924,14 +985,16 @@ mlxsw_env_module_plug_event_unregister(struct mlxsw_env *mlxsw_env)
} }
static int static int
mlxsw_env_module_oper_state_event_enable(struct mlxsw_core *mlxsw_core) mlxsw_env_module_oper_state_event_enable(struct mlxsw_core *mlxsw_core,
u8 slot_index)
{ {
struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core);
int i, err; int i, err;
for (i = 0; i < mlxsw_core_env(mlxsw_core)->module_count; i++) { for (i = 0; i < mlxsw_env->line_cards[slot_index]->module_count; i++) {
char pmaos_pl[MLXSW_REG_PMAOS_LEN]; char pmaos_pl[MLXSW_REG_PMAOS_LEN];
mlxsw_reg_pmaos_pack(pmaos_pl, 0, i); mlxsw_reg_pmaos_pack(pmaos_pl, slot_index, i);
mlxsw_reg_pmaos_e_set(pmaos_pl, mlxsw_reg_pmaos_e_set(pmaos_pl,
MLXSW_REG_PMAOS_E_GENERATE_EVENT); MLXSW_REG_PMAOS_E_GENERATE_EVENT);
mlxsw_reg_pmaos_ee_set(pmaos_pl, true); mlxsw_reg_pmaos_ee_set(pmaos_pl, true);
...@@ -943,111 +1006,189 @@ mlxsw_env_module_oper_state_event_enable(struct mlxsw_core *mlxsw_core) ...@@ -943,111 +1006,189 @@ mlxsw_env_module_oper_state_event_enable(struct mlxsw_core *mlxsw_core)
} }
int int
mlxsw_env_module_overheat_counter_get(struct mlxsw_core *mlxsw_core, u8 module, mlxsw_env_module_overheat_counter_get(struct mlxsw_core *mlxsw_core, u8 slot_index,
u64 *p_counter) u8 module, u64 *p_counter)
{ {
struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core); struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core);
struct mlxsw_env_module_info *module_info;
mutex_lock(&mlxsw_env->module_info_lock); mutex_lock(&mlxsw_env->line_cards_lock);
*p_counter = mlxsw_env->module_info[module].module_overheat_counter; module_info = mlxsw_env_module_info_get(mlxsw_core, slot_index, module);
mutex_unlock(&mlxsw_env->module_info_lock); *p_counter = module_info->module_overheat_counter;
mutex_unlock(&mlxsw_env->line_cards_lock);
return 0; return 0;
} }
EXPORT_SYMBOL(mlxsw_env_module_overheat_counter_get); EXPORT_SYMBOL(mlxsw_env_module_overheat_counter_get);
void mlxsw_env_module_port_map(struct mlxsw_core *mlxsw_core, u8 module) void mlxsw_env_module_port_map(struct mlxsw_core *mlxsw_core, u8 slot_index,
u8 module)
{ {
struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core); struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core);
struct mlxsw_env_module_info *module_info;
mutex_lock(&mlxsw_env->module_info_lock); mutex_lock(&mlxsw_env->line_cards_lock);
mlxsw_env->module_info[module].num_ports_mapped++; module_info = mlxsw_env_module_info_get(mlxsw_core, slot_index, module);
mutex_unlock(&mlxsw_env->module_info_lock); module_info->num_ports_mapped++;
mutex_unlock(&mlxsw_env->line_cards_lock);
} }
EXPORT_SYMBOL(mlxsw_env_module_port_map); EXPORT_SYMBOL(mlxsw_env_module_port_map);
void mlxsw_env_module_port_unmap(struct mlxsw_core *mlxsw_core, u8 module) void mlxsw_env_module_port_unmap(struct mlxsw_core *mlxsw_core, u8 slot_index,
u8 module)
{ {
struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core); struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core);
struct mlxsw_env_module_info *module_info;
mutex_lock(&mlxsw_env->module_info_lock); mutex_lock(&mlxsw_env->line_cards_lock);
mlxsw_env->module_info[module].num_ports_mapped--; module_info = mlxsw_env_module_info_get(mlxsw_core, slot_index, module);
mutex_unlock(&mlxsw_env->module_info_lock); module_info->num_ports_mapped--;
mutex_unlock(&mlxsw_env->line_cards_lock);
} }
EXPORT_SYMBOL(mlxsw_env_module_port_unmap); EXPORT_SYMBOL(mlxsw_env_module_port_unmap);
int mlxsw_env_module_port_up(struct mlxsw_core *mlxsw_core, u8 module) int mlxsw_env_module_port_up(struct mlxsw_core *mlxsw_core, u8 slot_index,
u8 module)
{ {
struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core); struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core);
struct mlxsw_env_module_info *module_info;
int err = 0; int err = 0;
mutex_lock(&mlxsw_env->module_info_lock); mutex_lock(&mlxsw_env->line_cards_lock);
if (mlxsw_env->module_info[module].power_mode_policy != module_info = mlxsw_env_module_info_get(mlxsw_core, slot_index, module);
if (module_info->power_mode_policy !=
ETHTOOL_MODULE_POWER_MODE_POLICY_AUTO) ETHTOOL_MODULE_POWER_MODE_POLICY_AUTO)
goto out_inc; goto out_inc;
if (mlxsw_env->module_info[module].num_ports_up != 0) if (module_info->num_ports_up != 0)
goto out_inc; goto out_inc;
/* Transition to high power mode following first port using the module /* Transition to high power mode following first port using the module
* being put administratively up. * being put administratively up.
*/ */
err = __mlxsw_env_set_module_power_mode(mlxsw_core, module, false, err = __mlxsw_env_set_module_power_mode(mlxsw_core, slot_index, module,
NULL); false, NULL);
if (err) if (err)
goto out_unlock; goto out_unlock;
out_inc: out_inc:
mlxsw_env->module_info[module].num_ports_up++; module_info->num_ports_up++;
out_unlock: out_unlock:
mutex_unlock(&mlxsw_env->module_info_lock); mutex_unlock(&mlxsw_env->line_cards_lock);
return err; return err;
} }
EXPORT_SYMBOL(mlxsw_env_module_port_up); EXPORT_SYMBOL(mlxsw_env_module_port_up);
void mlxsw_env_module_port_down(struct mlxsw_core *mlxsw_core, u8 module) void mlxsw_env_module_port_down(struct mlxsw_core *mlxsw_core, u8 slot_index,
u8 module)
{ {
struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core); struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core);
struct mlxsw_env_module_info *module_info;
mutex_lock(&mlxsw_env->module_info_lock); mutex_lock(&mlxsw_env->line_cards_lock);
mlxsw_env->module_info[module].num_ports_up--; module_info = mlxsw_env_module_info_get(mlxsw_core, slot_index, module);
module_info->num_ports_up--;
if (mlxsw_env->module_info[module].power_mode_policy != if (module_info->power_mode_policy !=
ETHTOOL_MODULE_POWER_MODE_POLICY_AUTO) ETHTOOL_MODULE_POWER_MODE_POLICY_AUTO)
goto out_unlock; goto out_unlock;
if (mlxsw_env->module_info[module].num_ports_up != 0) if (module_info->num_ports_up != 0)
goto out_unlock; goto out_unlock;
/* Transition to low power mode following last port using the module /* Transition to low power mode following last port using the module
* being put administratively down. * being put administratively down.
*/ */
__mlxsw_env_set_module_power_mode(mlxsw_core, module, true, NULL); __mlxsw_env_set_module_power_mode(mlxsw_core, slot_index, module, true,
NULL);
out_unlock: out_unlock:
mutex_unlock(&mlxsw_env->module_info_lock); mutex_unlock(&mlxsw_env->line_cards_lock);
} }
EXPORT_SYMBOL(mlxsw_env_module_port_down); EXPORT_SYMBOL(mlxsw_env_module_port_down);
static int mlxsw_env_line_cards_alloc(struct mlxsw_env *env)
{
struct mlxsw_env_module_info *module_info;
int i, j;
for (i = 0; i < env->num_of_slots; i++) {
env->line_cards[i] = kzalloc(struct_size(env->line_cards[i],
module_info,
env->max_module_count),
GFP_KERNEL);
if (!env->line_cards[i])
goto kzalloc_err;
/* Firmware defaults to high power mode policy where modules
* are transitioned to high power mode following plug-in.
*/
for (j = 0; j < env->max_module_count; j++) {
module_info = &env->line_cards[i]->module_info[j];
module_info->power_mode_policy =
ETHTOOL_MODULE_POWER_MODE_POLICY_HIGH;
}
}
return 0;
kzalloc_err:
for (i--; i >= 0; i--)
kfree(env->line_cards[i]);
return -ENOMEM;
}
static void mlxsw_env_line_cards_free(struct mlxsw_env *env)
{
int i = env->num_of_slots;
for (i--; i >= 0; i--)
kfree(env->line_cards[i]);
}
static int
mlxsw_env_module_event_enable(struct mlxsw_env *mlxsw_env, u8 slot_index)
{
int err;
err = mlxsw_env_module_oper_state_event_enable(mlxsw_env->core,
slot_index);
if (err)
return err;
err = mlxsw_env_module_temp_event_enable(mlxsw_env->core, slot_index);
if (err)
return err;
return 0;
}
static void
mlxsw_env_module_event_disable(struct mlxsw_env *mlxsw_env, u8 slot_index)
{
}
static int static int
mlxsw_env_module_type_set(struct mlxsw_core *mlxsw_core) mlxsw_env_module_type_set(struct mlxsw_core *mlxsw_core, u8 slot_index)
{ {
struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core); struct mlxsw_env *mlxsw_env = mlxsw_core_env(mlxsw_core);
int i; int i;
for (i = 0; i < mlxsw_env->module_count; i++) { for (i = 0; i < mlxsw_env->line_cards[slot_index]->module_count; i++) {
struct mlxsw_env_module_info *module_info;
char pmtm_pl[MLXSW_REG_PMTM_LEN]; char pmtm_pl[MLXSW_REG_PMTM_LEN];
int err; int err;
mlxsw_reg_pmtm_pack(pmtm_pl, 0, i); mlxsw_reg_pmtm_pack(pmtm_pl, slot_index, i);
err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(pmtm), pmtm_pl); err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(pmtm), pmtm_pl);
if (err) if (err)
return err; return err;
mlxsw_env->module_info[i].type = module_info = mlxsw_env_module_info_get(mlxsw_core, slot_index,
mlxsw_reg_pmtm_module_type_get(pmtm_pl); i);
module_info->type = mlxsw_reg_pmtm_module_type_get(pmtm_pl);
} }
return 0; return 0;
...@@ -1055,32 +1196,38 @@ mlxsw_env_module_type_set(struct mlxsw_core *mlxsw_core) ...@@ -1055,32 +1196,38 @@ mlxsw_env_module_type_set(struct mlxsw_core *mlxsw_core)
int mlxsw_env_init(struct mlxsw_core *mlxsw_core, struct mlxsw_env **p_env) int mlxsw_env_init(struct mlxsw_core *mlxsw_core, struct mlxsw_env **p_env)
{ {
u8 module_count, num_of_slots, max_module_count;
char mgpir_pl[MLXSW_REG_MGPIR_LEN]; char mgpir_pl[MLXSW_REG_MGPIR_LEN];
struct mlxsw_env *env; struct mlxsw_env *env;
u8 module_count; int err;
int i, err;
mlxsw_reg_mgpir_pack(mgpir_pl, 0); mlxsw_reg_mgpir_pack(mgpir_pl, 0);
err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mgpir), mgpir_pl); err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mgpir), mgpir_pl);
if (err) if (err)
return err; return err;
mlxsw_reg_mgpir_unpack(mgpir_pl, NULL, NULL, NULL, &module_count, NULL); mlxsw_reg_mgpir_unpack(mgpir_pl, NULL, NULL, NULL, &module_count,
&num_of_slots);
/* If the system is modular, get the maximum number of modules per-slot.
* Otherwise, get the maximum number of modules on the main board.
*/
max_module_count = num_of_slots ?
mlxsw_reg_mgpir_max_modules_per_slot_get(mgpir_pl) :
module_count;
env = kzalloc(struct_size(env, module_info, module_count), GFP_KERNEL); env = kzalloc(struct_size(env, line_cards, num_of_slots + 1),
GFP_KERNEL);
if (!env) if (!env)
return -ENOMEM; return -ENOMEM;
/* Firmware defaults to high power mode policy where modules are
* transitioned to high power mode following plug-in.
*/
for (i = 0; i < module_count; i++)
env->module_info[i].power_mode_policy =
ETHTOOL_MODULE_POWER_MODE_POLICY_HIGH;
mutex_init(&env->module_info_lock);
env->core = mlxsw_core; env->core = mlxsw_core;
env->module_count = module_count; env->num_of_slots = num_of_slots + 1;
env->max_module_count = max_module_count;
err = mlxsw_env_line_cards_alloc(env);
if (err)
goto err_mlxsw_env_line_cards_alloc;
mutex_init(&env->line_cards_lock);
*p_env = env; *p_env = env;
err = mlxsw_env_temp_warn_event_register(mlxsw_core); err = mlxsw_env_temp_warn_event_register(mlxsw_core);
...@@ -1091,38 +1238,46 @@ int mlxsw_env_init(struct mlxsw_core *mlxsw_core, struct mlxsw_env **p_env) ...@@ -1091,38 +1238,46 @@ int mlxsw_env_init(struct mlxsw_core *mlxsw_core, struct mlxsw_env **p_env)
if (err) if (err)
goto err_module_plug_event_register; goto err_module_plug_event_register;
err = mlxsw_env_module_oper_state_event_enable(mlxsw_core); /* Set 'module_count' only for main board. Actual count for line card
if (err) * is to be set after line card is activated.
goto err_oper_state_event_enable; */
env->line_cards[0]->module_count = num_of_slots ? 0 : module_count;
err = mlxsw_env_module_temp_event_enable(mlxsw_core); /* Enable events only for main board. Line card events are to be
* configured only after line card is activated. Before that, access to
* modules on line cards is not allowed.
*/
err = mlxsw_env_module_event_enable(env, 0);
if (err) if (err)
goto err_temp_event_enable; goto err_mlxsw_env_module_event_enable;
err = mlxsw_env_module_type_set(mlxsw_core); err = mlxsw_env_module_type_set(mlxsw_core, 0);
if (err) if (err)
goto err_type_set; goto err_type_set;
return 0; return 0;
err_type_set: err_type_set:
err_temp_event_enable: mlxsw_env_module_event_disable(env, 0);
err_oper_state_event_enable: err_mlxsw_env_module_event_enable:
mlxsw_env_module_plug_event_unregister(env); mlxsw_env_module_plug_event_unregister(env);
err_module_plug_event_register: err_module_plug_event_register:
mlxsw_env_temp_warn_event_unregister(env); mlxsw_env_temp_warn_event_unregister(env);
err_temp_warn_event_register: err_temp_warn_event_register:
mutex_destroy(&env->module_info_lock); mutex_destroy(&env->line_cards_lock);
mlxsw_env_line_cards_free(env);
err_mlxsw_env_line_cards_alloc:
kfree(env); kfree(env);
return err; return err;
} }
void mlxsw_env_fini(struct mlxsw_env *env) void mlxsw_env_fini(struct mlxsw_env *env)
{ {
mlxsw_env_module_event_disable(env, 0);
mlxsw_env_module_plug_event_unregister(env); mlxsw_env_module_plug_event_unregister(env);
/* Make sure there is no more event work scheduled. */ /* Make sure there is no more event work scheduled. */
mlxsw_core_flush_owq(); mlxsw_core_flush_owq();
mlxsw_env_temp_warn_event_unregister(env); mlxsw_env_temp_warn_event_unregister(env);
mutex_destroy(&env->module_info_lock); mutex_destroy(&env->line_cards_lock);
mlxsw_env_line_cards_free(env);
kfree(env); kfree(env);
} }
...@@ -9,47 +9,56 @@ ...@@ -9,47 +9,56 @@
struct ethtool_modinfo; struct ethtool_modinfo;
struct ethtool_eeprom; struct ethtool_eeprom;
int mlxsw_env_module_temp_thresholds_get(struct mlxsw_core *core, int module, int mlxsw_env_module_temp_thresholds_get(struct mlxsw_core *core,
int off, int *temp); u8 slot_index, int module, int off,
int *temp);
int mlxsw_env_get_module_info(struct net_device *netdev, int mlxsw_env_get_module_info(struct net_device *netdev,
struct mlxsw_core *mlxsw_core, int module, struct mlxsw_core *mlxsw_core, u8 slot_index,
struct ethtool_modinfo *modinfo); int module, struct ethtool_modinfo *modinfo);
int mlxsw_env_get_module_eeprom(struct net_device *netdev, int mlxsw_env_get_module_eeprom(struct net_device *netdev,
struct mlxsw_core *mlxsw_core, int module, struct mlxsw_core *mlxsw_core, u8 slot_index,
struct ethtool_eeprom *ee, u8 *data); int module, struct ethtool_eeprom *ee,
u8 *data);
int int
mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core, u8 module, mlxsw_env_get_module_eeprom_by_page(struct mlxsw_core *mlxsw_core,
u8 slot_index, u8 module,
const struct ethtool_module_eeprom *page, const struct ethtool_module_eeprom *page,
struct netlink_ext_ack *extack); struct netlink_ext_ack *extack);
int mlxsw_env_reset_module(struct net_device *netdev, int mlxsw_env_reset_module(struct net_device *netdev,
struct mlxsw_core *mlxsw_core, u8 module, struct mlxsw_core *mlxsw_core, u8 slot_index,
u32 *flags); u8 module, u32 *flags);
int int
mlxsw_env_get_module_power_mode(struct mlxsw_core *mlxsw_core, u8 module, mlxsw_env_get_module_power_mode(struct mlxsw_core *mlxsw_core, u8 slot_index,
u8 module,
struct ethtool_module_power_mode_params *params, struct ethtool_module_power_mode_params *params,
struct netlink_ext_ack *extack); struct netlink_ext_ack *extack);
int int
mlxsw_env_set_module_power_mode(struct mlxsw_core *mlxsw_core, u8 module, mlxsw_env_set_module_power_mode(struct mlxsw_core *mlxsw_core, u8 slot_index,
u8 module,
enum ethtool_module_power_mode_policy policy, enum ethtool_module_power_mode_policy policy,
struct netlink_ext_ack *extack); struct netlink_ext_ack *extack);
int int
mlxsw_env_module_overheat_counter_get(struct mlxsw_core *mlxsw_core, u8 module, mlxsw_env_module_overheat_counter_get(struct mlxsw_core *mlxsw_core, u8 slot_index,
u64 *p_counter); u8 module, u64 *p_counter);
void mlxsw_env_module_port_map(struct mlxsw_core *mlxsw_core, u8 module); void mlxsw_env_module_port_map(struct mlxsw_core *mlxsw_core, u8 slot_index,
u8 module);
void mlxsw_env_module_port_unmap(struct mlxsw_core *mlxsw_core, u8 module); void mlxsw_env_module_port_unmap(struct mlxsw_core *mlxsw_core, u8 slot_index,
u8 module);
int mlxsw_env_module_port_up(struct mlxsw_core *mlxsw_core, u8 module); int mlxsw_env_module_port_up(struct mlxsw_core *mlxsw_core, u8 slot_index,
u8 module);
void mlxsw_env_module_port_down(struct mlxsw_core *mlxsw_core, u8 module); void mlxsw_env_module_port_down(struct mlxsw_core *mlxsw_core, u8 slot_index,
u8 module);
int mlxsw_env_init(struct mlxsw_core *core, struct mlxsw_env **p_env); int mlxsw_env_init(struct mlxsw_core *core, struct mlxsw_env **p_env);
void mlxsw_env_fini(struct mlxsw_env *env); void mlxsw_env_fini(struct mlxsw_env *env);
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
struct mlxsw_hwmon_attr { struct mlxsw_hwmon_attr {
struct device_attribute dev_attr; struct device_attribute dev_attr;
struct mlxsw_hwmon *hwmon; struct mlxsw_hwmon_dev *mlxsw_hwmon_dev;
unsigned int type_index; unsigned int type_index;
char name[32]; char name[32];
}; };
...@@ -40,9 +40,8 @@ static int mlxsw_hwmon_get_attr_index(int index, int count) ...@@ -40,9 +40,8 @@ static int mlxsw_hwmon_get_attr_index(int index, int count)
return index; return index;
} }
struct mlxsw_hwmon { struct mlxsw_hwmon_dev {
struct mlxsw_core *core; struct mlxsw_hwmon *hwmon;
const struct mlxsw_bus_info *bus_info;
struct device *hwmon_dev; struct device *hwmon_dev;
struct attribute_group group; struct attribute_group group;
const struct attribute_group *groups[2]; const struct attribute_group *groups[2];
...@@ -51,6 +50,13 @@ struct mlxsw_hwmon { ...@@ -51,6 +50,13 @@ struct mlxsw_hwmon {
unsigned int attrs_count; unsigned int attrs_count;
u8 sensor_count; u8 sensor_count;
u8 module_sensor_max; u8 module_sensor_max;
u8 slot_index;
};
struct mlxsw_hwmon {
struct mlxsw_core *core;
const struct mlxsw_bus_info *bus_info;
struct mlxsw_hwmon_dev line_cards[];
}; };
static ssize_t mlxsw_hwmon_temp_show(struct device *dev, static ssize_t mlxsw_hwmon_temp_show(struct device *dev,
...@@ -59,14 +65,16 @@ static ssize_t mlxsw_hwmon_temp_show(struct device *dev, ...@@ -59,14 +65,16 @@ static ssize_t mlxsw_hwmon_temp_show(struct device *dev,
{ {
struct mlxsw_hwmon_attr *mlxsw_hwmon_attr = struct mlxsw_hwmon_attr *mlxsw_hwmon_attr =
container_of(attr, struct mlxsw_hwmon_attr, dev_attr); container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_attr->hwmon; struct mlxsw_hwmon_dev *mlxsw_hwmon_dev = mlxsw_hwmon_attr->mlxsw_hwmon_dev;
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon;
char mtmp_pl[MLXSW_REG_MTMP_LEN]; char mtmp_pl[MLXSW_REG_MTMP_LEN];
int temp, index; int temp, index;
int err; int err;
index = mlxsw_hwmon_get_attr_index(mlxsw_hwmon_attr->type_index, index = mlxsw_hwmon_get_attr_index(mlxsw_hwmon_attr->type_index,
mlxsw_hwmon->module_sensor_max); mlxsw_hwmon_dev->module_sensor_max);
mlxsw_reg_mtmp_pack(mtmp_pl, 0, index, false, false); mlxsw_reg_mtmp_pack(mtmp_pl, mlxsw_hwmon_dev->slot_index, index, false,
false);
err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl); err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl);
if (err) { if (err) {
dev_err(mlxsw_hwmon->bus_info->dev, "Failed to query temp sensor\n"); dev_err(mlxsw_hwmon->bus_info->dev, "Failed to query temp sensor\n");
...@@ -82,14 +90,16 @@ static ssize_t mlxsw_hwmon_temp_max_show(struct device *dev, ...@@ -82,14 +90,16 @@ static ssize_t mlxsw_hwmon_temp_max_show(struct device *dev,
{ {
struct mlxsw_hwmon_attr *mlxsw_hwmon_attr = struct mlxsw_hwmon_attr *mlxsw_hwmon_attr =
container_of(attr, struct mlxsw_hwmon_attr, dev_attr); container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_attr->hwmon; struct mlxsw_hwmon_dev *mlxsw_hwmon_dev = mlxsw_hwmon_attr->mlxsw_hwmon_dev;
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon;
char mtmp_pl[MLXSW_REG_MTMP_LEN]; char mtmp_pl[MLXSW_REG_MTMP_LEN];
int temp_max, index; int temp_max, index;
int err; int err;
index = mlxsw_hwmon_get_attr_index(mlxsw_hwmon_attr->type_index, index = mlxsw_hwmon_get_attr_index(mlxsw_hwmon_attr->type_index,
mlxsw_hwmon->module_sensor_max); mlxsw_hwmon_dev->module_sensor_max);
mlxsw_reg_mtmp_pack(mtmp_pl, 0, index, false, false); mlxsw_reg_mtmp_pack(mtmp_pl, mlxsw_hwmon_dev->slot_index, index, false,
false);
err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl); err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl);
if (err) { if (err) {
dev_err(mlxsw_hwmon->bus_info->dev, "Failed to query temp sensor\n"); dev_err(mlxsw_hwmon->bus_info->dev, "Failed to query temp sensor\n");
...@@ -105,8 +115,9 @@ static ssize_t mlxsw_hwmon_temp_rst_store(struct device *dev, ...@@ -105,8 +115,9 @@ static ssize_t mlxsw_hwmon_temp_rst_store(struct device *dev,
{ {
struct mlxsw_hwmon_attr *mlxsw_hwmon_attr = struct mlxsw_hwmon_attr *mlxsw_hwmon_attr =
container_of(attr, struct mlxsw_hwmon_attr, dev_attr); container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_attr->hwmon; struct mlxsw_hwmon_dev *mlxsw_hwmon_dev = mlxsw_hwmon_attr->mlxsw_hwmon_dev;
char mtmp_pl[MLXSW_REG_MTMP_LEN] = {0}; struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon;
char mtmp_pl[MLXSW_REG_MTMP_LEN];
unsigned long val; unsigned long val;
int index; int index;
int err; int err;
...@@ -118,8 +129,9 @@ static ssize_t mlxsw_hwmon_temp_rst_store(struct device *dev, ...@@ -118,8 +129,9 @@ static ssize_t mlxsw_hwmon_temp_rst_store(struct device *dev,
return -EINVAL; return -EINVAL;
index = mlxsw_hwmon_get_attr_index(mlxsw_hwmon_attr->type_index, index = mlxsw_hwmon_get_attr_index(mlxsw_hwmon_attr->type_index,
mlxsw_hwmon->module_sensor_max); mlxsw_hwmon_dev->module_sensor_max);
mlxsw_reg_mtmp_slot_index_set(mtmp_pl, mlxsw_hwmon_dev->slot_index);
mlxsw_reg_mtmp_sensor_index_set(mtmp_pl, index); mlxsw_reg_mtmp_sensor_index_set(mtmp_pl, index);
err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl); err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl);
if (err) if (err)
...@@ -140,7 +152,8 @@ static ssize_t mlxsw_hwmon_fan_rpm_show(struct device *dev, ...@@ -140,7 +152,8 @@ static ssize_t mlxsw_hwmon_fan_rpm_show(struct device *dev,
{ {
struct mlxsw_hwmon_attr *mlxsw_hwmon_attr = struct mlxsw_hwmon_attr *mlxsw_hwmon_attr =
container_of(attr, struct mlxsw_hwmon_attr, dev_attr); container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_attr->hwmon; struct mlxsw_hwmon_dev *mlxsw_hwmon_dev = mlxsw_hwmon_attr->mlxsw_hwmon_dev;
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon;
char mfsm_pl[MLXSW_REG_MFSM_LEN]; char mfsm_pl[MLXSW_REG_MFSM_LEN];
int err; int err;
...@@ -159,7 +172,8 @@ static ssize_t mlxsw_hwmon_fan_fault_show(struct device *dev, ...@@ -159,7 +172,8 @@ static ssize_t mlxsw_hwmon_fan_fault_show(struct device *dev,
{ {
struct mlxsw_hwmon_attr *mlxsw_hwmon_attr = struct mlxsw_hwmon_attr *mlxsw_hwmon_attr =
container_of(attr, struct mlxsw_hwmon_attr, dev_attr); container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_attr->hwmon; struct mlxsw_hwmon_dev *mlxsw_hwmon_dev = mlxsw_hwmon_attr->mlxsw_hwmon_dev;
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon;
char fore_pl[MLXSW_REG_FORE_LEN]; char fore_pl[MLXSW_REG_FORE_LEN];
bool fault; bool fault;
int err; int err;
...@@ -180,7 +194,8 @@ static ssize_t mlxsw_hwmon_pwm_show(struct device *dev, ...@@ -180,7 +194,8 @@ static ssize_t mlxsw_hwmon_pwm_show(struct device *dev,
{ {
struct mlxsw_hwmon_attr *mlxsw_hwmon_attr = struct mlxsw_hwmon_attr *mlxsw_hwmon_attr =
container_of(attr, struct mlxsw_hwmon_attr, dev_attr); container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_attr->hwmon; struct mlxsw_hwmon_dev *mlxsw_hwmon_dev = mlxsw_hwmon_attr->mlxsw_hwmon_dev;
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon;
char mfsc_pl[MLXSW_REG_MFSC_LEN]; char mfsc_pl[MLXSW_REG_MFSC_LEN];
int err; int err;
...@@ -200,7 +215,8 @@ static ssize_t mlxsw_hwmon_pwm_store(struct device *dev, ...@@ -200,7 +215,8 @@ static ssize_t mlxsw_hwmon_pwm_store(struct device *dev,
{ {
struct mlxsw_hwmon_attr *mlxsw_hwmon_attr = struct mlxsw_hwmon_attr *mlxsw_hwmon_attr =
container_of(attr, struct mlxsw_hwmon_attr, dev_attr); container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_attr->hwmon; struct mlxsw_hwmon_dev *mlxsw_hwmon_dev = mlxsw_hwmon_attr->mlxsw_hwmon_dev;
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon;
char mfsc_pl[MLXSW_REG_MFSC_LEN]; char mfsc_pl[MLXSW_REG_MFSC_LEN];
unsigned long val; unsigned long val;
int err; int err;
...@@ -226,13 +242,14 @@ static int mlxsw_hwmon_module_temp_get(struct device *dev, ...@@ -226,13 +242,14 @@ static int mlxsw_hwmon_module_temp_get(struct device *dev,
{ {
struct mlxsw_hwmon_attr *mlxsw_hwmon_attr = struct mlxsw_hwmon_attr *mlxsw_hwmon_attr =
container_of(attr, struct mlxsw_hwmon_attr, dev_attr); container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_attr->hwmon; struct mlxsw_hwmon_dev *mlxsw_hwmon_dev = mlxsw_hwmon_attr->mlxsw_hwmon_dev;
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon;
char mtmp_pl[MLXSW_REG_MTMP_LEN]; char mtmp_pl[MLXSW_REG_MTMP_LEN];
u8 module; u8 module;
int err; int err;
module = mlxsw_hwmon_attr->type_index - mlxsw_hwmon->sensor_count; module = mlxsw_hwmon_attr->type_index - mlxsw_hwmon_dev->sensor_count;
mlxsw_reg_mtmp_pack(mtmp_pl, 0, mlxsw_reg_mtmp_pack(mtmp_pl, mlxsw_hwmon_dev->slot_index,
MLXSW_REG_MTMP_MODULE_INDEX_MIN + module, false, MLXSW_REG_MTMP_MODULE_INDEX_MIN + module, false,
false); false);
err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl); err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl);
...@@ -264,14 +281,15 @@ static ssize_t mlxsw_hwmon_module_temp_fault_show(struct device *dev, ...@@ -264,14 +281,15 @@ static ssize_t mlxsw_hwmon_module_temp_fault_show(struct device *dev,
{ {
struct mlxsw_hwmon_attr *mlxsw_hwmon_attr = struct mlxsw_hwmon_attr *mlxsw_hwmon_attr =
container_of(attr, struct mlxsw_hwmon_attr, dev_attr); container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_attr->hwmon; struct mlxsw_hwmon_dev *mlxsw_hwmon_dev = mlxsw_hwmon_attr->mlxsw_hwmon_dev;
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon;
char mtbr_pl[MLXSW_REG_MTBR_LEN] = {0}; char mtbr_pl[MLXSW_REG_MTBR_LEN] = {0};
u8 module, fault; u8 module, fault;
u16 temp; u16 temp;
int err; int err;
module = mlxsw_hwmon_attr->type_index - mlxsw_hwmon->sensor_count; module = mlxsw_hwmon_attr->type_index - mlxsw_hwmon_dev->sensor_count;
mlxsw_reg_mtbr_pack(mtbr_pl, 0, mlxsw_reg_mtbr_pack(mtbr_pl, mlxsw_hwmon_dev->slot_index,
MLXSW_REG_MTBR_BASE_MODULE_INDEX + module, 1); MLXSW_REG_MTBR_BASE_MODULE_INDEX + module, 1);
err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtbr), mtbr_pl); err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtbr), mtbr_pl);
if (err) { if (err) {
...@@ -306,13 +324,16 @@ static int mlxsw_hwmon_module_temp_critical_get(struct device *dev, ...@@ -306,13 +324,16 @@ static int mlxsw_hwmon_module_temp_critical_get(struct device *dev,
{ {
struct mlxsw_hwmon_attr *mlxsw_hwmon_attr = struct mlxsw_hwmon_attr *mlxsw_hwmon_attr =
container_of(attr, struct mlxsw_hwmon_attr, dev_attr); container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_attr->hwmon; struct mlxsw_hwmon_dev *mlxsw_hwmon_dev = mlxsw_hwmon_attr->mlxsw_hwmon_dev;
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon;
u8 module; u8 module;
int err; int err;
module = mlxsw_hwmon_attr->type_index - mlxsw_hwmon->sensor_count; module = mlxsw_hwmon_attr->type_index - mlxsw_hwmon_dev->sensor_count;
err = mlxsw_env_module_temp_thresholds_get(mlxsw_hwmon->core, module, err = mlxsw_env_module_temp_thresholds_get(mlxsw_hwmon->core,
SFP_TEMP_HIGH_WARN, p_temp); mlxsw_hwmon_dev->slot_index,
module, SFP_TEMP_HIGH_WARN,
p_temp);
if (err) { if (err) {
dev_err(dev, "Failed to query module temperature thresholds\n"); dev_err(dev, "Failed to query module temperature thresholds\n");
return err; return err;
...@@ -340,13 +361,16 @@ static int mlxsw_hwmon_module_temp_emergency_get(struct device *dev, ...@@ -340,13 +361,16 @@ static int mlxsw_hwmon_module_temp_emergency_get(struct device *dev,
{ {
struct mlxsw_hwmon_attr *mlxsw_hwmon_attr = struct mlxsw_hwmon_attr *mlxsw_hwmon_attr =
container_of(attr, struct mlxsw_hwmon_attr, dev_attr); container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_attr->hwmon; struct mlxsw_hwmon_dev *mlxsw_hwmon_dev = mlxsw_hwmon_attr->mlxsw_hwmon_dev;
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon;
u8 module; u8 module;
int err; int err;
module = mlxsw_hwmon_attr->type_index - mlxsw_hwmon->sensor_count; module = mlxsw_hwmon_attr->type_index - mlxsw_hwmon_dev->sensor_count;
err = mlxsw_env_module_temp_thresholds_get(mlxsw_hwmon->core, module, err = mlxsw_env_module_temp_thresholds_get(mlxsw_hwmon->core,
SFP_TEMP_HIGH_ALARM, p_temp); mlxsw_hwmon_dev->slot_index,
module, SFP_TEMP_HIGH_ALARM,
p_temp);
if (err) { if (err) {
dev_err(dev, "Failed to query module temperature thresholds\n"); dev_err(dev, "Failed to query module temperature thresholds\n");
return err; return err;
...@@ -388,9 +412,9 @@ mlxsw_hwmon_gbox_temp_label_show(struct device *dev, ...@@ -388,9 +412,9 @@ mlxsw_hwmon_gbox_temp_label_show(struct device *dev,
{ {
struct mlxsw_hwmon_attr *mlxsw_hwmon_attr = struct mlxsw_hwmon_attr *mlxsw_hwmon_attr =
container_of(attr, struct mlxsw_hwmon_attr, dev_attr); container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_attr->hwmon; struct mlxsw_hwmon_dev *mlxsw_hwmon_dev = mlxsw_hwmon_attr->mlxsw_hwmon_dev;
int index = mlxsw_hwmon_attr->type_index - int index = mlxsw_hwmon_attr->type_index -
mlxsw_hwmon->module_sensor_max + 1; mlxsw_hwmon_dev->module_sensor_max + 1;
return sprintf(buf, "gearbox %03u\n", index); return sprintf(buf, "gearbox %03u\n", index);
} }
...@@ -459,14 +483,15 @@ enum mlxsw_hwmon_attr_type { ...@@ -459,14 +483,15 @@ enum mlxsw_hwmon_attr_type {
MLXSW_HWMON_ATTR_TYPE_TEMP_EMERGENCY_ALARM, MLXSW_HWMON_ATTR_TYPE_TEMP_EMERGENCY_ALARM,
}; };
static void mlxsw_hwmon_attr_add(struct mlxsw_hwmon *mlxsw_hwmon, static void mlxsw_hwmon_attr_add(struct mlxsw_hwmon_dev *mlxsw_hwmon_dev,
enum mlxsw_hwmon_attr_type attr_type, enum mlxsw_hwmon_attr_type attr_type,
unsigned int type_index, unsigned int num) { unsigned int type_index, unsigned int num)
{
struct mlxsw_hwmon_attr *mlxsw_hwmon_attr; struct mlxsw_hwmon_attr *mlxsw_hwmon_attr;
unsigned int attr_index; unsigned int attr_index;
attr_index = mlxsw_hwmon->attrs_count; attr_index = mlxsw_hwmon_dev->attrs_count;
mlxsw_hwmon_attr = &mlxsw_hwmon->hwmon_attrs[attr_index]; mlxsw_hwmon_attr = &mlxsw_hwmon_dev->hwmon_attrs[attr_index];
switch (attr_type) { switch (attr_type) {
case MLXSW_HWMON_ATTR_TYPE_TEMP: case MLXSW_HWMON_ATTR_TYPE_TEMP:
...@@ -566,16 +591,17 @@ static void mlxsw_hwmon_attr_add(struct mlxsw_hwmon *mlxsw_hwmon, ...@@ -566,16 +591,17 @@ static void mlxsw_hwmon_attr_add(struct mlxsw_hwmon *mlxsw_hwmon,
} }
mlxsw_hwmon_attr->type_index = type_index; mlxsw_hwmon_attr->type_index = type_index;
mlxsw_hwmon_attr->hwmon = mlxsw_hwmon; mlxsw_hwmon_attr->mlxsw_hwmon_dev = mlxsw_hwmon_dev;
mlxsw_hwmon_attr->dev_attr.attr.name = mlxsw_hwmon_attr->name; mlxsw_hwmon_attr->dev_attr.attr.name = mlxsw_hwmon_attr->name;
sysfs_attr_init(&mlxsw_hwmon_attr->dev_attr.attr); sysfs_attr_init(&mlxsw_hwmon_attr->dev_attr.attr);
mlxsw_hwmon->attrs[attr_index] = &mlxsw_hwmon_attr->dev_attr.attr; mlxsw_hwmon_dev->attrs[attr_index] = &mlxsw_hwmon_attr->dev_attr.attr;
mlxsw_hwmon->attrs_count++; mlxsw_hwmon_dev->attrs_count++;
} }
static int mlxsw_hwmon_temp_init(struct mlxsw_hwmon *mlxsw_hwmon) static int mlxsw_hwmon_temp_init(struct mlxsw_hwmon_dev *mlxsw_hwmon_dev)
{ {
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon;
char mtcap_pl[MLXSW_REG_MTCAP_LEN] = {0}; char mtcap_pl[MLXSW_REG_MTCAP_LEN] = {0};
int i; int i;
int err; int err;
...@@ -585,10 +611,12 @@ static int mlxsw_hwmon_temp_init(struct mlxsw_hwmon *mlxsw_hwmon) ...@@ -585,10 +611,12 @@ static int mlxsw_hwmon_temp_init(struct mlxsw_hwmon *mlxsw_hwmon)
dev_err(mlxsw_hwmon->bus_info->dev, "Failed to get number of temp sensors\n"); dev_err(mlxsw_hwmon->bus_info->dev, "Failed to get number of temp sensors\n");
return err; return err;
} }
mlxsw_hwmon->sensor_count = mlxsw_reg_mtcap_sensor_count_get(mtcap_pl); mlxsw_hwmon_dev->sensor_count = mlxsw_reg_mtcap_sensor_count_get(mtcap_pl);
for (i = 0; i < mlxsw_hwmon->sensor_count; i++) { for (i = 0; i < mlxsw_hwmon_dev->sensor_count; i++) {
char mtmp_pl[MLXSW_REG_MTMP_LEN] = {0}; char mtmp_pl[MLXSW_REG_MTMP_LEN] = {0};
mlxsw_reg_mtmp_slot_index_set(mtmp_pl,
mlxsw_hwmon_dev->slot_index);
mlxsw_reg_mtmp_sensor_index_set(mtmp_pl, i); mlxsw_reg_mtmp_sensor_index_set(mtmp_pl, i);
err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp), err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp),
mtmp_pl); mtmp_pl);
...@@ -603,18 +631,19 @@ static int mlxsw_hwmon_temp_init(struct mlxsw_hwmon *mlxsw_hwmon) ...@@ -603,18 +631,19 @@ static int mlxsw_hwmon_temp_init(struct mlxsw_hwmon *mlxsw_hwmon)
i); i);
return err; return err;
} }
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon_dev,
MLXSW_HWMON_ATTR_TYPE_TEMP, i, i); MLXSW_HWMON_ATTR_TYPE_TEMP, i, i);
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon_dev,
MLXSW_HWMON_ATTR_TYPE_TEMP_MAX, i, i); MLXSW_HWMON_ATTR_TYPE_TEMP_MAX, i, i);
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon_dev,
MLXSW_HWMON_ATTR_TYPE_TEMP_RST, i, i); MLXSW_HWMON_ATTR_TYPE_TEMP_RST, i, i);
} }
return 0; return 0;
} }
static int mlxsw_hwmon_fans_init(struct mlxsw_hwmon *mlxsw_hwmon) static int mlxsw_hwmon_fans_init(struct mlxsw_hwmon_dev *mlxsw_hwmon_dev)
{ {
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon;
char mfcr_pl[MLXSW_REG_MFCR_LEN] = {0}; char mfcr_pl[MLXSW_REG_MFCR_LEN] = {0};
enum mlxsw_reg_mfcr_pwm_frequency freq; enum mlxsw_reg_mfcr_pwm_frequency freq;
unsigned int type_index; unsigned int type_index;
...@@ -632,10 +661,10 @@ static int mlxsw_hwmon_fans_init(struct mlxsw_hwmon *mlxsw_hwmon) ...@@ -632,10 +661,10 @@ static int mlxsw_hwmon_fans_init(struct mlxsw_hwmon *mlxsw_hwmon)
num = 0; num = 0;
for (type_index = 0; type_index < MLXSW_MFCR_TACHOS_MAX; type_index++) { for (type_index = 0; type_index < MLXSW_MFCR_TACHOS_MAX; type_index++) {
if (tacho_active & BIT(type_index)) { if (tacho_active & BIT(type_index)) {
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon_dev,
MLXSW_HWMON_ATTR_TYPE_FAN_RPM, MLXSW_HWMON_ATTR_TYPE_FAN_RPM,
type_index, num); type_index, num);
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon_dev,
MLXSW_HWMON_ATTR_TYPE_FAN_FAULT, MLXSW_HWMON_ATTR_TYPE_FAN_FAULT,
type_index, num++); type_index, num++);
} }
...@@ -643,20 +672,21 @@ static int mlxsw_hwmon_fans_init(struct mlxsw_hwmon *mlxsw_hwmon) ...@@ -643,20 +672,21 @@ static int mlxsw_hwmon_fans_init(struct mlxsw_hwmon *mlxsw_hwmon)
num = 0; num = 0;
for (type_index = 0; type_index < MLXSW_MFCR_PWMS_MAX; type_index++) { for (type_index = 0; type_index < MLXSW_MFCR_PWMS_MAX; type_index++) {
if (pwm_active & BIT(type_index)) if (pwm_active & BIT(type_index))
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon_dev,
MLXSW_HWMON_ATTR_TYPE_PWM, MLXSW_HWMON_ATTR_TYPE_PWM,
type_index, num++); type_index, num++);
} }
return 0; return 0;
} }
static int mlxsw_hwmon_module_init(struct mlxsw_hwmon *mlxsw_hwmon) static int mlxsw_hwmon_module_init(struct mlxsw_hwmon_dev *mlxsw_hwmon_dev)
{ {
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon;
char mgpir_pl[MLXSW_REG_MGPIR_LEN]; char mgpir_pl[MLXSW_REG_MGPIR_LEN];
u8 module_sensor_max; u8 module_sensor_max;
int i, err; int i, err;
mlxsw_reg_mgpir_pack(mgpir_pl, 0); mlxsw_reg_mgpir_pack(mgpir_pl, mlxsw_hwmon_dev->slot_index);
err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mgpir), mgpir_pl); err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mgpir), mgpir_pl);
if (err) if (err)
return err; return err;
...@@ -669,28 +699,28 @@ static int mlxsw_hwmon_module_init(struct mlxsw_hwmon *mlxsw_hwmon) ...@@ -669,28 +699,28 @@ static int mlxsw_hwmon_module_init(struct mlxsw_hwmon *mlxsw_hwmon)
* sensor_count are already utilized by the sensors connected through * sensor_count are already utilized by the sensors connected through
* mtmp register by mlxsw_hwmon_temp_init(). * mtmp register by mlxsw_hwmon_temp_init().
*/ */
mlxsw_hwmon->module_sensor_max = mlxsw_hwmon->sensor_count + mlxsw_hwmon_dev->module_sensor_max = mlxsw_hwmon_dev->sensor_count +
module_sensor_max; module_sensor_max;
for (i = mlxsw_hwmon->sensor_count; for (i = mlxsw_hwmon_dev->sensor_count;
i < mlxsw_hwmon->module_sensor_max; i++) { i < mlxsw_hwmon_dev->module_sensor_max; i++) {
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon_dev,
MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE, i, i); MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE, i, i);
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon_dev,
MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_FAULT, MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_FAULT,
i, i); i, i);
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon_dev,
MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_CRIT, i, MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_CRIT, i,
i); i);
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon_dev,
MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_EMERG, MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_EMERG,
i, i); i, i);
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon_dev,
MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_LABEL, MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_LABEL,
i, i); i, i);
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon_dev,
MLXSW_HWMON_ATTR_TYPE_TEMP_CRIT_ALARM, MLXSW_HWMON_ATTR_TYPE_TEMP_CRIT_ALARM,
i, i); i, i);
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon_dev,
MLXSW_HWMON_ATTR_TYPE_TEMP_EMERGENCY_ALARM, MLXSW_HWMON_ATTR_TYPE_TEMP_EMERGENCY_ALARM,
i, i); i, i);
} }
...@@ -698,8 +728,9 @@ static int mlxsw_hwmon_module_init(struct mlxsw_hwmon *mlxsw_hwmon) ...@@ -698,8 +728,9 @@ static int mlxsw_hwmon_module_init(struct mlxsw_hwmon *mlxsw_hwmon)
return 0; return 0;
} }
static int mlxsw_hwmon_gearbox_init(struct mlxsw_hwmon *mlxsw_hwmon) static int mlxsw_hwmon_gearbox_init(struct mlxsw_hwmon_dev *mlxsw_hwmon_dev)
{ {
struct mlxsw_hwmon *mlxsw_hwmon = mlxsw_hwmon_dev->hwmon;
enum mlxsw_reg_mgpir_device_type device_type; enum mlxsw_reg_mgpir_device_type device_type;
int index, max_index, sensor_index; int index, max_index, sensor_index;
char mgpir_pl[MLXSW_REG_MGPIR_LEN]; char mgpir_pl[MLXSW_REG_MGPIR_LEN];
...@@ -707,7 +738,7 @@ static int mlxsw_hwmon_gearbox_init(struct mlxsw_hwmon *mlxsw_hwmon) ...@@ -707,7 +738,7 @@ static int mlxsw_hwmon_gearbox_init(struct mlxsw_hwmon *mlxsw_hwmon)
u8 gbox_num; u8 gbox_num;
int err; int err;
mlxsw_reg_mgpir_pack(mgpir_pl, 0); mlxsw_reg_mgpir_pack(mgpir_pl, mlxsw_hwmon_dev->slot_index);
err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mgpir), mgpir_pl); err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mgpir), mgpir_pl);
if (err) if (err)
return err; return err;
...@@ -718,12 +749,13 @@ static int mlxsw_hwmon_gearbox_init(struct mlxsw_hwmon *mlxsw_hwmon) ...@@ -718,12 +749,13 @@ static int mlxsw_hwmon_gearbox_init(struct mlxsw_hwmon *mlxsw_hwmon)
!gbox_num) !gbox_num)
return 0; return 0;
index = mlxsw_hwmon->module_sensor_max; index = mlxsw_hwmon_dev->module_sensor_max;
max_index = mlxsw_hwmon->module_sensor_max + gbox_num; max_index = mlxsw_hwmon_dev->module_sensor_max + gbox_num;
while (index < max_index) { while (index < max_index) {
sensor_index = index % mlxsw_hwmon->module_sensor_max + sensor_index = index % mlxsw_hwmon_dev->module_sensor_max +
MLXSW_REG_MTMP_GBOX_INDEX_MIN; MLXSW_REG_MTMP_GBOX_INDEX_MIN;
mlxsw_reg_mtmp_pack(mtmp_pl, 0, sensor_index, true, true); mlxsw_reg_mtmp_pack(mtmp_pl, mlxsw_hwmon_dev->slot_index,
sensor_index, true, true);
err = mlxsw_reg_write(mlxsw_hwmon->core, err = mlxsw_reg_write(mlxsw_hwmon->core,
MLXSW_REG(mtmp), mtmp_pl); MLXSW_REG(mtmp), mtmp_pl);
if (err) { if (err) {
...@@ -731,15 +763,15 @@ static int mlxsw_hwmon_gearbox_init(struct mlxsw_hwmon *mlxsw_hwmon) ...@@ -731,15 +763,15 @@ static int mlxsw_hwmon_gearbox_init(struct mlxsw_hwmon *mlxsw_hwmon)
sensor_index); sensor_index);
return err; return err;
} }
mlxsw_hwmon_attr_add(mlxsw_hwmon, MLXSW_HWMON_ATTR_TYPE_TEMP, mlxsw_hwmon_attr_add(mlxsw_hwmon_dev,
index, index); MLXSW_HWMON_ATTR_TYPE_TEMP, index, index);
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon_dev,
MLXSW_HWMON_ATTR_TYPE_TEMP_MAX, index, MLXSW_HWMON_ATTR_TYPE_TEMP_MAX, index,
index); index);
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon_dev,
MLXSW_HWMON_ATTR_TYPE_TEMP_RST, index, MLXSW_HWMON_ATTR_TYPE_TEMP_RST, index,
index); index);
mlxsw_hwmon_attr_add(mlxsw_hwmon, mlxsw_hwmon_attr_add(mlxsw_hwmon_dev,
MLXSW_HWMON_ATTR_TYPE_TEMP_GBOX_LABEL, MLXSW_HWMON_ATTR_TYPE_TEMP_GBOX_LABEL,
index, index); index, index);
index++; index++;
...@@ -752,44 +784,59 @@ int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core, ...@@ -752,44 +784,59 @@ int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
const struct mlxsw_bus_info *mlxsw_bus_info, const struct mlxsw_bus_info *mlxsw_bus_info,
struct mlxsw_hwmon **p_hwmon) struct mlxsw_hwmon **p_hwmon)
{ {
char mgpir_pl[MLXSW_REG_MGPIR_LEN];
struct mlxsw_hwmon *mlxsw_hwmon; struct mlxsw_hwmon *mlxsw_hwmon;
struct device *hwmon_dev; struct device *hwmon_dev;
u8 num_of_slots;
int err; int err;
mlxsw_hwmon = kzalloc(sizeof(*mlxsw_hwmon), GFP_KERNEL); mlxsw_reg_mgpir_pack(mgpir_pl, 0);
err = mlxsw_reg_query(mlxsw_core, MLXSW_REG(mgpir), mgpir_pl);
if (err)
return err;
mlxsw_reg_mgpir_unpack(mgpir_pl, NULL, NULL, NULL, NULL,
&num_of_slots);
mlxsw_hwmon = kzalloc(struct_size(mlxsw_hwmon, line_cards,
num_of_slots + 1), GFP_KERNEL);
if (!mlxsw_hwmon) if (!mlxsw_hwmon)
return -ENOMEM; return -ENOMEM;
mlxsw_hwmon->core = mlxsw_core; mlxsw_hwmon->core = mlxsw_core;
mlxsw_hwmon->bus_info = mlxsw_bus_info; mlxsw_hwmon->bus_info = mlxsw_bus_info;
mlxsw_hwmon->line_cards[0].hwmon = mlxsw_hwmon;
mlxsw_hwmon->line_cards[0].slot_index = 0;
err = mlxsw_hwmon_temp_init(mlxsw_hwmon); err = mlxsw_hwmon_temp_init(&mlxsw_hwmon->line_cards[0]);
if (err) if (err)
goto err_temp_init; goto err_temp_init;
err = mlxsw_hwmon_fans_init(mlxsw_hwmon); err = mlxsw_hwmon_fans_init(&mlxsw_hwmon->line_cards[0]);
if (err) if (err)
goto err_fans_init; goto err_fans_init;
err = mlxsw_hwmon_module_init(mlxsw_hwmon); err = mlxsw_hwmon_module_init(&mlxsw_hwmon->line_cards[0]);
if (err) if (err)
goto err_temp_module_init; goto err_temp_module_init;
err = mlxsw_hwmon_gearbox_init(mlxsw_hwmon); err = mlxsw_hwmon_gearbox_init(&mlxsw_hwmon->line_cards[0]);
if (err) if (err)
goto err_temp_gearbox_init; goto err_temp_gearbox_init;
mlxsw_hwmon->groups[0] = &mlxsw_hwmon->group; mlxsw_hwmon->line_cards[0].groups[0] = &mlxsw_hwmon->line_cards[0].group;
mlxsw_hwmon->group.attrs = mlxsw_hwmon->attrs; mlxsw_hwmon->line_cards[0].group.attrs = mlxsw_hwmon->line_cards[0].attrs;
hwmon_dev = hwmon_device_register_with_groups(mlxsw_bus_info->dev, hwmon_dev = hwmon_device_register_with_groups(mlxsw_bus_info->dev,
"mlxsw", mlxsw_hwmon, "mlxsw",
mlxsw_hwmon->groups); &mlxsw_hwmon->line_cards[0],
mlxsw_hwmon->line_cards[0].groups);
if (IS_ERR(hwmon_dev)) { if (IS_ERR(hwmon_dev)) {
err = PTR_ERR(hwmon_dev); err = PTR_ERR(hwmon_dev);
goto err_hwmon_register; goto err_hwmon_register;
} }
mlxsw_hwmon->hwmon_dev = hwmon_dev; mlxsw_hwmon->line_cards[0].hwmon_dev = hwmon_dev;
*p_hwmon = mlxsw_hwmon; *p_hwmon = mlxsw_hwmon;
return 0; return 0;
...@@ -804,6 +851,6 @@ int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core, ...@@ -804,6 +851,6 @@ int mlxsw_hwmon_init(struct mlxsw_core *mlxsw_core,
void mlxsw_hwmon_fini(struct mlxsw_hwmon *mlxsw_hwmon) void mlxsw_hwmon_fini(struct mlxsw_hwmon *mlxsw_hwmon)
{ {
hwmon_device_unregister(mlxsw_hwmon->hwmon_dev); hwmon_device_unregister(mlxsw_hwmon->line_cards[0].hwmon_dev);
kfree(mlxsw_hwmon); kfree(mlxsw_hwmon);
} }
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#define MLXSW_THERMAL_ASIC_TEMP_HOT 105000 /* 105C */ #define MLXSW_THERMAL_ASIC_TEMP_HOT 105000 /* 105C */
#define MLXSW_THERMAL_HYSTERESIS_TEMP 5000 /* 5C */ #define MLXSW_THERMAL_HYSTERESIS_TEMP 5000 /* 5C */
#define MLXSW_THERMAL_MODULE_TEMP_SHIFT (MLXSW_THERMAL_HYSTERESIS_TEMP * 2) #define MLXSW_THERMAL_MODULE_TEMP_SHIFT (MLXSW_THERMAL_HYSTERESIS_TEMP * 2)
#define MLXSW_THERMAL_ZONE_MAX_NAME 16
#define MLXSW_THERMAL_TEMP_SCORE_MAX GENMASK(31, 0) #define MLXSW_THERMAL_TEMP_SCORE_MAX GENMASK(31, 0)
#define MLXSW_THERMAL_MAX_STATE 10 #define MLXSW_THERMAL_MAX_STATE 10
#define MLXSW_THERMAL_MIN_STATE 2 #define MLXSW_THERMAL_MIN_STATE 2
...@@ -82,6 +81,15 @@ struct mlxsw_thermal_module { ...@@ -82,6 +81,15 @@ struct mlxsw_thermal_module {
struct thermal_zone_device *tzdev; struct thermal_zone_device *tzdev;
struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS];
int module; /* Module or gearbox number */ int module; /* Module or gearbox number */
u8 slot_index;
};
struct mlxsw_thermal_area {
struct mlxsw_thermal_module *tz_module_arr;
u8 tz_module_num;
struct mlxsw_thermal_module *tz_gearbox_arr;
u8 tz_gearbox_num;
u8 slot_index;
}; };
struct mlxsw_thermal { struct mlxsw_thermal {
...@@ -92,12 +100,9 @@ struct mlxsw_thermal { ...@@ -92,12 +100,9 @@ struct mlxsw_thermal {
struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX];
u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1];
struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS];
struct mlxsw_thermal_module *tz_module_arr;
u8 tz_module_num;
struct mlxsw_thermal_module *tz_gearbox_arr;
u8 tz_gearbox_num;
unsigned int tz_highest_score; unsigned int tz_highest_score;
struct thermal_zone_device *tz_highest_dev; struct thermal_zone_device *tz_highest_dev;
struct mlxsw_thermal_area line_cards[];
}; };
static inline u8 mlxsw_state_to_duty(int state) static inline u8 mlxsw_state_to_duty(int state)
...@@ -123,8 +128,7 @@ static int mlxsw_get_cooling_device_idx(struct mlxsw_thermal *thermal, ...@@ -123,8 +128,7 @@ static int mlxsw_get_cooling_device_idx(struct mlxsw_thermal *thermal,
/* Allow mlxsw thermal zone binding to an external cooling device */ /* Allow mlxsw thermal zone binding to an external cooling device */
for (i = 0; i < ARRAY_SIZE(mlxsw_thermal_external_allowed_cdev); i++) { for (i = 0; i < ARRAY_SIZE(mlxsw_thermal_external_allowed_cdev); i++) {
if (strnstr(cdev->type, mlxsw_thermal_external_allowed_cdev[i], if (!strcmp(cdev->type, mlxsw_thermal_external_allowed_cdev[i]))
strlen(cdev->type)))
return 0; return 0;
} }
...@@ -150,13 +154,15 @@ mlxsw_thermal_module_trips_update(struct device *dev, struct mlxsw_core *core, ...@@ -150,13 +154,15 @@ mlxsw_thermal_module_trips_update(struct device *dev, struct mlxsw_core *core,
* EEPROM if we got valid thresholds from MTMP. * EEPROM if we got valid thresholds from MTMP.
*/ */
if (!emerg_temp || !crit_temp) { if (!emerg_temp || !crit_temp) {
err = mlxsw_env_module_temp_thresholds_get(core, tz->module, err = mlxsw_env_module_temp_thresholds_get(core, tz->slot_index,
tz->module,
SFP_TEMP_HIGH_WARN, SFP_TEMP_HIGH_WARN,
&crit_temp); &crit_temp);
if (err) if (err)
return err; return err;
err = mlxsw_env_module_temp_thresholds_get(core, tz->module, err = mlxsw_env_module_temp_thresholds_get(core, tz->slot_index,
tz->module,
SFP_TEMP_HIGH_ALARM, SFP_TEMP_HIGH_ALARM,
&emerg_temp); &emerg_temp);
if (err) if (err)
...@@ -423,15 +429,16 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev, ...@@ -423,15 +429,16 @@ static int mlxsw_thermal_module_unbind(struct thermal_zone_device *tzdev,
static void static void
mlxsw_thermal_module_temp_and_thresholds_get(struct mlxsw_core *core, mlxsw_thermal_module_temp_and_thresholds_get(struct mlxsw_core *core,
u16 sensor_index, int *p_temp, u8 slot_index, u16 sensor_index,
int *p_crit_temp, int *p_temp, int *p_crit_temp,
int *p_emerg_temp) int *p_emerg_temp)
{ {
char mtmp_pl[MLXSW_REG_MTMP_LEN]; char mtmp_pl[MLXSW_REG_MTMP_LEN];
int err; int err;
/* Read module temperature and thresholds. */ /* Read module temperature and thresholds. */
mlxsw_reg_mtmp_pack(mtmp_pl, 0, sensor_index, false, false); mlxsw_reg_mtmp_pack(mtmp_pl, slot_index, sensor_index,
false, false);
err = mlxsw_reg_query(core, MLXSW_REG(mtmp), mtmp_pl); err = mlxsw_reg_query(core, MLXSW_REG(mtmp), mtmp_pl);
if (err) { if (err) {
/* Set temperature and thresholds to zero to avoid passing /* Set temperature and thresholds to zero to avoid passing
...@@ -462,6 +469,7 @@ static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev, ...@@ -462,6 +469,7 @@ static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev,
/* Read module temperature and thresholds. */ /* Read module temperature and thresholds. */
mlxsw_thermal_module_temp_and_thresholds_get(thermal->core, mlxsw_thermal_module_temp_and_thresholds_get(thermal->core,
tz->slot_index,
sensor_index, &temp, sensor_index, &temp,
&crit_temp, &emerg_temp); &crit_temp, &emerg_temp);
*p_temp = temp; *p_temp = temp;
...@@ -576,7 +584,7 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, ...@@ -576,7 +584,7 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev,
int err; int err;
index = MLXSW_REG_MTMP_GBOX_INDEX_MIN + tz->module; index = MLXSW_REG_MTMP_GBOX_INDEX_MIN + tz->module;
mlxsw_reg_mtmp_pack(mtmp_pl, 0, index, false, false); mlxsw_reg_mtmp_pack(mtmp_pl, tz->slot_index, index, false, false);
err = mlxsw_reg_query(thermal->core, MLXSW_REG(mtmp), mtmp_pl); err = mlxsw_reg_query(thermal->core, MLXSW_REG(mtmp), mtmp_pl);
if (err) if (err)
...@@ -672,9 +680,13 @@ static const struct thermal_cooling_device_ops mlxsw_cooling_ops = { ...@@ -672,9 +680,13 @@ static const struct thermal_cooling_device_ops mlxsw_cooling_ops = {
static int static int
mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz)
{ {
char tz_name[MLXSW_THERMAL_ZONE_MAX_NAME]; char tz_name[THERMAL_NAME_LENGTH];
int err; int err;
if (module_tz->slot_index)
snprintf(tz_name, sizeof(tz_name), "mlxsw-lc%d-module%d",
module_tz->slot_index, module_tz->module + 1);
else
snprintf(tz_name, sizeof(tz_name), "mlxsw-module%d", snprintf(tz_name, sizeof(tz_name), "mlxsw-module%d",
module_tz->module + 1); module_tz->module + 1);
module_tz->tzdev = thermal_zone_device_register(tz_name, module_tz->tzdev = thermal_zone_device_register(tz_name,
...@@ -704,25 +716,28 @@ static void mlxsw_thermal_module_tz_fini(struct thermal_zone_device *tzdev) ...@@ -704,25 +716,28 @@ static void mlxsw_thermal_module_tz_fini(struct thermal_zone_device *tzdev)
static int static int
mlxsw_thermal_module_init(struct device *dev, struct mlxsw_core *core, mlxsw_thermal_module_init(struct device *dev, struct mlxsw_core *core,
struct mlxsw_thermal *thermal, u8 module) struct mlxsw_thermal *thermal,
struct mlxsw_thermal_area *area, u8 module)
{ {
struct mlxsw_thermal_module *module_tz; struct mlxsw_thermal_module *module_tz;
int dummy_temp, crit_temp, emerg_temp; int dummy_temp, crit_temp, emerg_temp;
u16 sensor_index; u16 sensor_index;
sensor_index = MLXSW_REG_MTMP_MODULE_INDEX_MIN + module; sensor_index = MLXSW_REG_MTMP_MODULE_INDEX_MIN + module;
module_tz = &thermal->tz_module_arr[module]; module_tz = &area->tz_module_arr[module];
/* Skip if parent is already set (case of port split). */ /* Skip if parent is already set (case of port split). */
if (module_tz->parent) if (module_tz->parent)
return 0; return 0;
module_tz->module = module; module_tz->module = module;
module_tz->slot_index = area->slot_index;
module_tz->parent = thermal; module_tz->parent = thermal;
memcpy(module_tz->trips, default_thermal_trips, memcpy(module_tz->trips, default_thermal_trips,
sizeof(thermal->trips)); sizeof(thermal->trips));
/* Initialize all trip point. */ /* Initialize all trip point. */
mlxsw_thermal_module_trips_reset(module_tz); mlxsw_thermal_module_trips_reset(module_tz);
/* Read module temperature and thresholds. */ /* Read module temperature and thresholds. */
mlxsw_thermal_module_temp_and_thresholds_get(core, sensor_index, &dummy_temp, mlxsw_thermal_module_temp_and_thresholds_get(core, area->slot_index,
sensor_index, &dummy_temp,
&crit_temp, &emerg_temp); &crit_temp, &emerg_temp);
/* Update trip point according to the module data. */ /* Update trip point according to the module data. */
return mlxsw_thermal_module_trips_update(dev, core, module_tz, return mlxsw_thermal_module_trips_update(dev, core, module_tz,
...@@ -740,34 +755,39 @@ static void mlxsw_thermal_module_fini(struct mlxsw_thermal_module *module_tz) ...@@ -740,34 +755,39 @@ static void mlxsw_thermal_module_fini(struct mlxsw_thermal_module *module_tz)
static int static int
mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core, mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core,
struct mlxsw_thermal *thermal) struct mlxsw_thermal *thermal,
struct mlxsw_thermal_area *area)
{ {
struct mlxsw_thermal_module *module_tz; struct mlxsw_thermal_module *module_tz;
char mgpir_pl[MLXSW_REG_MGPIR_LEN]; char mgpir_pl[MLXSW_REG_MGPIR_LEN];
int i, err; int i, err;
mlxsw_reg_mgpir_pack(mgpir_pl, 0); mlxsw_reg_mgpir_pack(mgpir_pl, area->slot_index);
err = mlxsw_reg_query(core, MLXSW_REG(mgpir), mgpir_pl); err = mlxsw_reg_query(core, MLXSW_REG(mgpir), mgpir_pl);
if (err) if (err)
return err; return err;
mlxsw_reg_mgpir_unpack(mgpir_pl, NULL, NULL, NULL, mlxsw_reg_mgpir_unpack(mgpir_pl, NULL, NULL, NULL,
&thermal->tz_module_num, NULL); &area->tz_module_num, NULL);
thermal->tz_module_arr = kcalloc(thermal->tz_module_num, /* For modular system module counter could be zero. */
sizeof(*thermal->tz_module_arr), if (!area->tz_module_num)
return 0;
area->tz_module_arr = kcalloc(area->tz_module_num,
sizeof(*area->tz_module_arr),
GFP_KERNEL); GFP_KERNEL);
if (!thermal->tz_module_arr) if (!area->tz_module_arr)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < thermal->tz_module_num; i++) { for (i = 0; i < area->tz_module_num; i++) {
err = mlxsw_thermal_module_init(dev, core, thermal, i); err = mlxsw_thermal_module_init(dev, core, thermal, area, i);
if (err) if (err)
goto err_thermal_module_init; goto err_thermal_module_init;
} }
for (i = 0; i < thermal->tz_module_num; i++) { for (i = 0; i < area->tz_module_num; i++) {
module_tz = &thermal->tz_module_arr[i]; module_tz = &area->tz_module_arr[i];
if (!module_tz->parent) if (!module_tz->parent)
continue; continue;
err = mlxsw_thermal_module_tz_init(module_tz); err = mlxsw_thermal_module_tz_init(module_tz);
...@@ -779,28 +799,33 @@ mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core, ...@@ -779,28 +799,33 @@ mlxsw_thermal_modules_init(struct device *dev, struct mlxsw_core *core,
err_thermal_module_tz_init: err_thermal_module_tz_init:
err_thermal_module_init: err_thermal_module_init:
for (i = thermal->tz_module_num - 1; i >= 0; i--) for (i = area->tz_module_num - 1; i >= 0; i--)
mlxsw_thermal_module_fini(&thermal->tz_module_arr[i]); mlxsw_thermal_module_fini(&area->tz_module_arr[i]);
kfree(thermal->tz_module_arr); kfree(area->tz_module_arr);
return err; return err;
} }
static void static void
mlxsw_thermal_modules_fini(struct mlxsw_thermal *thermal) mlxsw_thermal_modules_fini(struct mlxsw_thermal *thermal,
struct mlxsw_thermal_area *area)
{ {
int i; int i;
for (i = thermal->tz_module_num - 1; i >= 0; i--) for (i = area->tz_module_num - 1; i >= 0; i--)
mlxsw_thermal_module_fini(&thermal->tz_module_arr[i]); mlxsw_thermal_module_fini(&area->tz_module_arr[i]);
kfree(thermal->tz_module_arr); kfree(area->tz_module_arr);
} }
static int static int
mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz)
{ {
char tz_name[MLXSW_THERMAL_ZONE_MAX_NAME]; char tz_name[THERMAL_NAME_LENGTH];
int ret; int ret;
if (gearbox_tz->slot_index)
snprintf(tz_name, sizeof(tz_name), "mlxsw-lc%d-gearbox%d",
gearbox_tz->slot_index, gearbox_tz->module + 1);
else
snprintf(tz_name, sizeof(tz_name), "mlxsw-gearbox%d", snprintf(tz_name, sizeof(tz_name), "mlxsw-gearbox%d",
gearbox_tz->module + 1); gearbox_tz->module + 1);
gearbox_tz->tzdev = thermal_zone_device_register(tz_name, gearbox_tz->tzdev = thermal_zone_device_register(tz_name,
...@@ -828,7 +853,8 @@ mlxsw_thermal_gearbox_tz_fini(struct mlxsw_thermal_module *gearbox_tz) ...@@ -828,7 +853,8 @@ mlxsw_thermal_gearbox_tz_fini(struct mlxsw_thermal_module *gearbox_tz)
static int static int
mlxsw_thermal_gearboxes_init(struct device *dev, struct mlxsw_core *core, mlxsw_thermal_gearboxes_init(struct device *dev, struct mlxsw_core *core,
struct mlxsw_thermal *thermal) struct mlxsw_thermal *thermal,
struct mlxsw_thermal_area *area)
{ {
enum mlxsw_reg_mgpir_device_type device_type; enum mlxsw_reg_mgpir_device_type device_type;
struct mlxsw_thermal_module *gearbox_tz; struct mlxsw_thermal_module *gearbox_tz;
...@@ -837,7 +863,7 @@ mlxsw_thermal_gearboxes_init(struct device *dev, struct mlxsw_core *core, ...@@ -837,7 +863,7 @@ mlxsw_thermal_gearboxes_init(struct device *dev, struct mlxsw_core *core,
int i; int i;
int err; int err;
mlxsw_reg_mgpir_pack(mgpir_pl, 0); mlxsw_reg_mgpir_pack(mgpir_pl, area->slot_index);
err = mlxsw_reg_query(core, MLXSW_REG(mgpir), mgpir_pl); err = mlxsw_reg_query(core, MLXSW_REG(mgpir), mgpir_pl);
if (err) if (err)
return err; return err;
...@@ -848,19 +874,20 @@ mlxsw_thermal_gearboxes_init(struct device *dev, struct mlxsw_core *core, ...@@ -848,19 +874,20 @@ mlxsw_thermal_gearboxes_init(struct device *dev, struct mlxsw_core *core,
!gbox_num) !gbox_num)
return 0; return 0;
thermal->tz_gearbox_num = gbox_num; area->tz_gearbox_num = gbox_num;
thermal->tz_gearbox_arr = kcalloc(thermal->tz_gearbox_num, area->tz_gearbox_arr = kcalloc(area->tz_gearbox_num,
sizeof(*thermal->tz_gearbox_arr), sizeof(*area->tz_gearbox_arr),
GFP_KERNEL); GFP_KERNEL);
if (!thermal->tz_gearbox_arr) if (!area->tz_gearbox_arr)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < thermal->tz_gearbox_num; i++) { for (i = 0; i < area->tz_gearbox_num; i++) {
gearbox_tz = &thermal->tz_gearbox_arr[i]; gearbox_tz = &area->tz_gearbox_arr[i];
memcpy(gearbox_tz->trips, default_thermal_trips, memcpy(gearbox_tz->trips, default_thermal_trips,
sizeof(thermal->trips)); sizeof(thermal->trips));
gearbox_tz->module = i; gearbox_tz->module = i;
gearbox_tz->parent = thermal; gearbox_tz->parent = thermal;
gearbox_tz->slot_index = area->slot_index;
err = mlxsw_thermal_gearbox_tz_init(gearbox_tz); err = mlxsw_thermal_gearbox_tz_init(gearbox_tz);
if (err) if (err)
goto err_thermal_gearbox_tz_init; goto err_thermal_gearbox_tz_init;
...@@ -870,19 +897,20 @@ mlxsw_thermal_gearboxes_init(struct device *dev, struct mlxsw_core *core, ...@@ -870,19 +897,20 @@ mlxsw_thermal_gearboxes_init(struct device *dev, struct mlxsw_core *core,
err_thermal_gearbox_tz_init: err_thermal_gearbox_tz_init:
for (i--; i >= 0; i--) for (i--; i >= 0; i--)
mlxsw_thermal_gearbox_tz_fini(&thermal->tz_gearbox_arr[i]); mlxsw_thermal_gearbox_tz_fini(&area->tz_gearbox_arr[i]);
kfree(thermal->tz_gearbox_arr); kfree(area->tz_gearbox_arr);
return err; return err;
} }
static void static void
mlxsw_thermal_gearboxes_fini(struct mlxsw_thermal *thermal) mlxsw_thermal_gearboxes_fini(struct mlxsw_thermal *thermal,
struct mlxsw_thermal_area *area)
{ {
int i; int i;
for (i = thermal->tz_gearbox_num - 1; i >= 0; i--) for (i = area->tz_gearbox_num - 1; i >= 0; i--)
mlxsw_thermal_gearbox_tz_fini(&thermal->tz_gearbox_arr[i]); mlxsw_thermal_gearbox_tz_fini(&area->tz_gearbox_arr[i]);
kfree(thermal->tz_gearbox_arr); kfree(area->tz_gearbox_arr);
} }
int mlxsw_thermal_init(struct mlxsw_core *core, int mlxsw_thermal_init(struct mlxsw_core *core,
...@@ -892,12 +920,21 @@ int mlxsw_thermal_init(struct mlxsw_core *core, ...@@ -892,12 +920,21 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
char mfcr_pl[MLXSW_REG_MFCR_LEN] = { 0 }; char mfcr_pl[MLXSW_REG_MFCR_LEN] = { 0 };
enum mlxsw_reg_mfcr_pwm_frequency freq; enum mlxsw_reg_mfcr_pwm_frequency freq;
struct device *dev = bus_info->dev; struct device *dev = bus_info->dev;
char mgpir_pl[MLXSW_REG_MGPIR_LEN];
struct mlxsw_thermal *thermal; struct mlxsw_thermal *thermal;
u8 pwm_active, num_of_slots;
u16 tacho_active; u16 tacho_active;
u8 pwm_active;
int err, i; int err, i;
thermal = devm_kzalloc(dev, sizeof(*thermal), mlxsw_reg_mgpir_pack(mgpir_pl, 0);
err = mlxsw_reg_query(core, MLXSW_REG(mgpir), mgpir_pl);
if (err)
return err;
mlxsw_reg_mgpir_unpack(mgpir_pl, NULL, NULL, NULL, NULL,
&num_of_slots);
thermal = kzalloc(struct_size(thermal, line_cards, num_of_slots + 1),
GFP_KERNEL); GFP_KERNEL);
if (!thermal) if (!thermal)
return -ENOMEM; return -ENOMEM;
...@@ -905,6 +942,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, ...@@ -905,6 +942,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
thermal->core = core; thermal->core = core;
thermal->bus_info = bus_info; thermal->bus_info = bus_info;
memcpy(thermal->trips, default_thermal_trips, sizeof(thermal->trips)); memcpy(thermal->trips, default_thermal_trips, sizeof(thermal->trips));
thermal->line_cards[0].slot_index = 0;
err = mlxsw_reg_query(thermal->core, MLXSW_REG(mfcr), mfcr_pl); err = mlxsw_reg_query(thermal->core, MLXSW_REG(mfcr), mfcr_pl);
if (err) { if (err) {
...@@ -970,11 +1008,13 @@ int mlxsw_thermal_init(struct mlxsw_core *core, ...@@ -970,11 +1008,13 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
goto err_thermal_zone_device_register; goto err_thermal_zone_device_register;
} }
err = mlxsw_thermal_modules_init(dev, core, thermal); err = mlxsw_thermal_modules_init(dev, core, thermal,
&thermal->line_cards[0]);
if (err) if (err)
goto err_thermal_modules_init; goto err_thermal_modules_init;
err = mlxsw_thermal_gearboxes_init(dev, core, thermal); err = mlxsw_thermal_gearboxes_init(dev, core, thermal,
&thermal->line_cards[0]);
if (err) if (err)
goto err_thermal_gearboxes_init; goto err_thermal_gearboxes_init;
...@@ -986,9 +1026,9 @@ int mlxsw_thermal_init(struct mlxsw_core *core, ...@@ -986,9 +1026,9 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
return 0; return 0;
err_thermal_zone_device_enable: err_thermal_zone_device_enable:
mlxsw_thermal_gearboxes_fini(thermal); mlxsw_thermal_gearboxes_fini(thermal, &thermal->line_cards[0]);
err_thermal_gearboxes_init: err_thermal_gearboxes_init:
mlxsw_thermal_modules_fini(thermal); mlxsw_thermal_modules_fini(thermal, &thermal->line_cards[0]);
err_thermal_modules_init: err_thermal_modules_init:
if (thermal->tzdev) { if (thermal->tzdev) {
thermal_zone_device_unregister(thermal->tzdev); thermal_zone_device_unregister(thermal->tzdev);
...@@ -1001,7 +1041,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, ...@@ -1001,7 +1041,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
thermal_cooling_device_unregister(thermal->cdevs[i]); thermal_cooling_device_unregister(thermal->cdevs[i]);
err_reg_write: err_reg_write:
err_reg_query: err_reg_query:
devm_kfree(dev, thermal); kfree(thermal);
return err; return err;
} }
...@@ -1009,8 +1049,8 @@ void mlxsw_thermal_fini(struct mlxsw_thermal *thermal) ...@@ -1009,8 +1049,8 @@ void mlxsw_thermal_fini(struct mlxsw_thermal *thermal)
{ {
int i; int i;
mlxsw_thermal_gearboxes_fini(thermal); mlxsw_thermal_gearboxes_fini(thermal, &thermal->line_cards[0]);
mlxsw_thermal_modules_fini(thermal); mlxsw_thermal_modules_fini(thermal, &thermal->line_cards[0]);
if (thermal->tzdev) { if (thermal->tzdev) {
thermal_zone_device_unregister(thermal->tzdev); thermal_zone_device_unregister(thermal->tzdev);
thermal->tzdev = NULL; thermal->tzdev = NULL;
...@@ -1023,5 +1063,5 @@ void mlxsw_thermal_fini(struct mlxsw_thermal *thermal) ...@@ -1023,5 +1063,5 @@ void mlxsw_thermal_fini(struct mlxsw_thermal *thermal)
} }
} }
devm_kfree(thermal->bus_info->dev, thermal); kfree(thermal);
} }
...@@ -59,7 +59,8 @@ static int mlxsw_m_port_open(struct net_device *dev) ...@@ -59,7 +59,8 @@ static int mlxsw_m_port_open(struct net_device *dev)
struct mlxsw_m_port *mlxsw_m_port = netdev_priv(dev); struct mlxsw_m_port *mlxsw_m_port = netdev_priv(dev);
struct mlxsw_m *mlxsw_m = mlxsw_m_port->mlxsw_m; struct mlxsw_m *mlxsw_m = mlxsw_m_port->mlxsw_m;
return mlxsw_env_module_port_up(mlxsw_m->core, mlxsw_m_port->module); return mlxsw_env_module_port_up(mlxsw_m->core, 0,
mlxsw_m_port->module);
} }
static int mlxsw_m_port_stop(struct net_device *dev) static int mlxsw_m_port_stop(struct net_device *dev)
...@@ -67,7 +68,7 @@ static int mlxsw_m_port_stop(struct net_device *dev) ...@@ -67,7 +68,7 @@ static int mlxsw_m_port_stop(struct net_device *dev)
struct mlxsw_m_port *mlxsw_m_port = netdev_priv(dev); struct mlxsw_m_port *mlxsw_m_port = netdev_priv(dev);
struct mlxsw_m *mlxsw_m = mlxsw_m_port->mlxsw_m; struct mlxsw_m *mlxsw_m = mlxsw_m_port->mlxsw_m;
mlxsw_env_module_port_down(mlxsw_m->core, mlxsw_m_port->module); mlxsw_env_module_port_down(mlxsw_m->core, 0, mlxsw_m_port->module);
return 0; return 0;
} }
...@@ -110,7 +111,7 @@ static int mlxsw_m_get_module_info(struct net_device *netdev, ...@@ -110,7 +111,7 @@ static int mlxsw_m_get_module_info(struct net_device *netdev,
struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev); struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev);
struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core;
return mlxsw_env_get_module_info(netdev, core, mlxsw_m_port->module, return mlxsw_env_get_module_info(netdev, core, 0, mlxsw_m_port->module,
modinfo); modinfo);
} }
...@@ -121,8 +122,8 @@ mlxsw_m_get_module_eeprom(struct net_device *netdev, struct ethtool_eeprom *ee, ...@@ -121,8 +122,8 @@ mlxsw_m_get_module_eeprom(struct net_device *netdev, struct ethtool_eeprom *ee,
struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev); struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev);
struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core;
return mlxsw_env_get_module_eeprom(netdev, core, mlxsw_m_port->module, return mlxsw_env_get_module_eeprom(netdev, core, 0,
ee, data); mlxsw_m_port->module, ee, data);
} }
static int static int
...@@ -133,7 +134,8 @@ mlxsw_m_get_module_eeprom_by_page(struct net_device *netdev, ...@@ -133,7 +134,8 @@ mlxsw_m_get_module_eeprom_by_page(struct net_device *netdev,
struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev); struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev);
struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core;
return mlxsw_env_get_module_eeprom_by_page(core, mlxsw_m_port->module, return mlxsw_env_get_module_eeprom_by_page(core, 0,
mlxsw_m_port->module,
page, extack); page, extack);
} }
...@@ -142,7 +144,7 @@ static int mlxsw_m_reset(struct net_device *netdev, u32 *flags) ...@@ -142,7 +144,7 @@ static int mlxsw_m_reset(struct net_device *netdev, u32 *flags)
struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev); struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev);
struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core;
return mlxsw_env_reset_module(netdev, core, mlxsw_m_port->module, return mlxsw_env_reset_module(netdev, core, 0, mlxsw_m_port->module,
flags); flags);
} }
...@@ -154,7 +156,7 @@ mlxsw_m_get_module_power_mode(struct net_device *netdev, ...@@ -154,7 +156,7 @@ mlxsw_m_get_module_power_mode(struct net_device *netdev,
struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev); struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev);
struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core;
return mlxsw_env_get_module_power_mode(core, mlxsw_m_port->module, return mlxsw_env_get_module_power_mode(core, 0, mlxsw_m_port->module,
params, extack); params, extack);
} }
...@@ -166,7 +168,7 @@ mlxsw_m_set_module_power_mode(struct net_device *netdev, ...@@ -166,7 +168,7 @@ mlxsw_m_set_module_power_mode(struct net_device *netdev,
struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev); struct mlxsw_m_port *mlxsw_m_port = netdev_priv(netdev);
struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core;
return mlxsw_env_set_module_power_mode(core, mlxsw_m_port->module, return mlxsw_env_set_module_power_mode(core, 0, mlxsw_m_port->module,
params->policy, extack); params->policy, extack);
} }
...@@ -311,7 +313,7 @@ static int mlxsw_m_port_module_map(struct mlxsw_m *mlxsw_m, u16 local_port, ...@@ -311,7 +313,7 @@ static int mlxsw_m_port_module_map(struct mlxsw_m *mlxsw_m, u16 local_port,
if (WARN_ON_ONCE(module >= max_ports)) if (WARN_ON_ONCE(module >= max_ports))
return -EINVAL; return -EINVAL;
mlxsw_env_module_port_map(mlxsw_m->core, module); mlxsw_env_module_port_map(mlxsw_m->core, 0, module);
mlxsw_m->module_to_port[module] = ++mlxsw_m->max_ports; mlxsw_m->module_to_port[module] = ++mlxsw_m->max_ports;
return 0; return 0;
...@@ -320,7 +322,7 @@ static int mlxsw_m_port_module_map(struct mlxsw_m *mlxsw_m, u16 local_port, ...@@ -320,7 +322,7 @@ static int mlxsw_m_port_module_map(struct mlxsw_m *mlxsw_m, u16 local_port,
static void mlxsw_m_port_module_unmap(struct mlxsw_m *mlxsw_m, u8 module) static void mlxsw_m_port_module_unmap(struct mlxsw_m *mlxsw_m, u8 module)
{ {
mlxsw_m->module_to_port[module] = -1; mlxsw_m->module_to_port[module] = -1;
mlxsw_env_module_port_unmap(mlxsw_m->core, module); mlxsw_env_module_port_unmap(mlxsw_m->core, 0, module);
} }
static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m) static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m)
......
...@@ -539,7 +539,7 @@ mlxsw_sp_port_module_map(struct mlxsw_sp *mlxsw_sp, u16 local_port, ...@@ -539,7 +539,7 @@ mlxsw_sp_port_module_map(struct mlxsw_sp *mlxsw_sp, u16 local_port,
char pmlp_pl[MLXSW_REG_PMLP_LEN]; char pmlp_pl[MLXSW_REG_PMLP_LEN];
int i, err; int i, err;
mlxsw_env_module_port_map(mlxsw_sp->core, port_mapping->module); mlxsw_env_module_port_map(mlxsw_sp->core, 0, port_mapping->module);
mlxsw_reg_pmlp_pack(pmlp_pl, local_port); mlxsw_reg_pmlp_pack(pmlp_pl, local_port);
mlxsw_reg_pmlp_width_set(pmlp_pl, port_mapping->width); mlxsw_reg_pmlp_width_set(pmlp_pl, port_mapping->width);
...@@ -554,19 +554,19 @@ mlxsw_sp_port_module_map(struct mlxsw_sp *mlxsw_sp, u16 local_port, ...@@ -554,19 +554,19 @@ mlxsw_sp_port_module_map(struct mlxsw_sp *mlxsw_sp, u16 local_port,
return 0; return 0;
err_pmlp_write: err_pmlp_write:
mlxsw_env_module_port_unmap(mlxsw_sp->core, port_mapping->module); mlxsw_env_module_port_unmap(mlxsw_sp->core, 0, port_mapping->module);
return err; return err;
} }
static void mlxsw_sp_port_module_unmap(struct mlxsw_sp *mlxsw_sp, u16 local_port, static void mlxsw_sp_port_module_unmap(struct mlxsw_sp *mlxsw_sp, u16 local_port,
u8 module) u8 slot_index, u8 module)
{ {
char pmlp_pl[MLXSW_REG_PMLP_LEN]; char pmlp_pl[MLXSW_REG_PMLP_LEN];
mlxsw_reg_pmlp_pack(pmlp_pl, local_port); mlxsw_reg_pmlp_pack(pmlp_pl, local_port);
mlxsw_reg_pmlp_width_set(pmlp_pl, 0); mlxsw_reg_pmlp_width_set(pmlp_pl, 0);
mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pmlp), pmlp_pl); mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pmlp), pmlp_pl);
mlxsw_env_module_port_unmap(mlxsw_sp->core, module); mlxsw_env_module_port_unmap(mlxsw_sp->core, slot_index, module);
} }
static int mlxsw_sp_port_open(struct net_device *dev) static int mlxsw_sp_port_open(struct net_device *dev)
...@@ -575,7 +575,7 @@ static int mlxsw_sp_port_open(struct net_device *dev) ...@@ -575,7 +575,7 @@ static int mlxsw_sp_port_open(struct net_device *dev)
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
int err; int err;
err = mlxsw_env_module_port_up(mlxsw_sp->core, err = mlxsw_env_module_port_up(mlxsw_sp->core, 0,
mlxsw_sp_port->mapping.module); mlxsw_sp_port->mapping.module);
if (err) if (err)
return err; return err;
...@@ -586,7 +586,7 @@ static int mlxsw_sp_port_open(struct net_device *dev) ...@@ -586,7 +586,7 @@ static int mlxsw_sp_port_open(struct net_device *dev)
return 0; return 0;
err_port_admin_status_set: err_port_admin_status_set:
mlxsw_env_module_port_down(mlxsw_sp->core, mlxsw_env_module_port_down(mlxsw_sp->core, 0,
mlxsw_sp_port->mapping.module); mlxsw_sp_port->mapping.module);
return err; return err;
} }
...@@ -598,7 +598,7 @@ static int mlxsw_sp_port_stop(struct net_device *dev) ...@@ -598,7 +598,7 @@ static int mlxsw_sp_port_stop(struct net_device *dev)
netif_stop_queue(dev); netif_stop_queue(dev);
mlxsw_sp_port_admin_status_set(mlxsw_sp_port, false); mlxsw_sp_port_admin_status_set(mlxsw_sp_port, false);
mlxsw_env_module_port_down(mlxsw_sp->core, mlxsw_env_module_port_down(mlxsw_sp->core, 0,
mlxsw_sp_port->mapping.module); mlxsw_sp_port->mapping.module);
return 0; return 0;
} }
...@@ -1449,7 +1449,7 @@ static int mlxsw_sp_port_overheat_init_val_set(struct mlxsw_sp_port *mlxsw_sp_po ...@@ -1449,7 +1449,7 @@ static int mlxsw_sp_port_overheat_init_val_set(struct mlxsw_sp_port *mlxsw_sp_po
u64 overheat_counter; u64 overheat_counter;
int err; int err;
err = mlxsw_env_module_overheat_counter_get(mlxsw_sp->core, module, err = mlxsw_env_module_overheat_counter_get(mlxsw_sp->core, 0, module,
&overheat_counter); &overheat_counter);
if (err) if (err)
return err; return err;
...@@ -1775,7 +1775,8 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u16 local_port, ...@@ -1775,7 +1775,8 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u16 local_port,
mlxsw_sp_port_swid_set(mlxsw_sp, local_port, mlxsw_sp_port_swid_set(mlxsw_sp, local_port,
MLXSW_PORT_SWID_DISABLED_PORT); MLXSW_PORT_SWID_DISABLED_PORT);
err_port_swid_set: err_port_swid_set:
mlxsw_sp_port_module_unmap(mlxsw_sp, local_port, port_mapping->module); mlxsw_sp_port_module_unmap(mlxsw_sp, local_port, 0,
port_mapping->module);
return err; return err;
} }
...@@ -1804,7 +1805,7 @@ static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u16 local_port) ...@@ -1804,7 +1805,7 @@ static void mlxsw_sp_port_remove(struct mlxsw_sp *mlxsw_sp, u16 local_port)
mlxsw_core_port_fini(mlxsw_sp->core, local_port); mlxsw_core_port_fini(mlxsw_sp->core, local_port);
mlxsw_sp_port_swid_set(mlxsw_sp, local_port, mlxsw_sp_port_swid_set(mlxsw_sp, local_port,
MLXSW_PORT_SWID_DISABLED_PORT); MLXSW_PORT_SWID_DISABLED_PORT);
mlxsw_sp_port_module_unmap(mlxsw_sp, local_port, module); mlxsw_sp_port_module_unmap(mlxsw_sp, local_port, 0, module);
} }
static int mlxsw_sp_cpu_port_create(struct mlxsw_sp *mlxsw_sp) static int mlxsw_sp_cpu_port_create(struct mlxsw_sp *mlxsw_sp)
......
...@@ -573,7 +573,7 @@ mlxsw_sp_port_get_transceiver_overheat_stats(struct mlxsw_sp_port *mlxsw_sp_port ...@@ -573,7 +573,7 @@ mlxsw_sp_port_get_transceiver_overheat_stats(struct mlxsw_sp_port *mlxsw_sp_port
u64 stats; u64 stats;
int err; int err;
err = mlxsw_env_module_overheat_counter_get(mlxsw_core, err = mlxsw_env_module_overheat_counter_get(mlxsw_core, 0,
port_mapping.module, port_mapping.module,
&stats); &stats);
if (err) if (err)
...@@ -1035,7 +1035,7 @@ static int mlxsw_sp_get_module_info(struct net_device *netdev, ...@@ -1035,7 +1035,7 @@ static int mlxsw_sp_get_module_info(struct net_device *netdev,
struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(netdev); struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(netdev);
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
return mlxsw_env_get_module_info(netdev, mlxsw_sp->core, return mlxsw_env_get_module_info(netdev, mlxsw_sp->core, 0,
mlxsw_sp_port->mapping.module, mlxsw_sp_port->mapping.module,
modinfo); modinfo);
} }
...@@ -1046,7 +1046,7 @@ static int mlxsw_sp_get_module_eeprom(struct net_device *netdev, ...@@ -1046,7 +1046,7 @@ static int mlxsw_sp_get_module_eeprom(struct net_device *netdev,
struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(netdev); struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(netdev);
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
return mlxsw_env_get_module_eeprom(netdev, mlxsw_sp->core, return mlxsw_env_get_module_eeprom(netdev, mlxsw_sp->core, 0,
mlxsw_sp_port->mapping.module, ee, mlxsw_sp_port->mapping.module, ee,
data); data);
} }
...@@ -1060,8 +1060,8 @@ mlxsw_sp_get_module_eeprom_by_page(struct net_device *dev, ...@@ -1060,8 +1060,8 @@ mlxsw_sp_get_module_eeprom_by_page(struct net_device *dev,
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
u8 module = mlxsw_sp_port->mapping.module; u8 module = mlxsw_sp_port->mapping.module;
return mlxsw_env_get_module_eeprom_by_page(mlxsw_sp->core, module, page, return mlxsw_env_get_module_eeprom_by_page(mlxsw_sp->core, 0, module,
extack); page, extack);
} }
static int static int
...@@ -1204,7 +1204,7 @@ static int mlxsw_sp_reset(struct net_device *dev, u32 *flags) ...@@ -1204,7 +1204,7 @@ static int mlxsw_sp_reset(struct net_device *dev, u32 *flags)
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
u8 module = mlxsw_sp_port->mapping.module; u8 module = mlxsw_sp_port->mapping.module;
return mlxsw_env_reset_module(dev, mlxsw_sp->core, module, flags); return mlxsw_env_reset_module(dev, mlxsw_sp->core, 0, module, flags);
} }
static int static int
...@@ -1216,8 +1216,8 @@ mlxsw_sp_get_module_power_mode(struct net_device *dev, ...@@ -1216,8 +1216,8 @@ mlxsw_sp_get_module_power_mode(struct net_device *dev,
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
u8 module = mlxsw_sp_port->mapping.module; u8 module = mlxsw_sp_port->mapping.module;
return mlxsw_env_get_module_power_mode(mlxsw_sp->core, module, params, return mlxsw_env_get_module_power_mode(mlxsw_sp->core, 0, module,
extack); params, extack);
} }
static int static int
...@@ -1229,7 +1229,7 @@ mlxsw_sp_set_module_power_mode(struct net_device *dev, ...@@ -1229,7 +1229,7 @@ mlxsw_sp_set_module_power_mode(struct net_device *dev,
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
u8 module = mlxsw_sp_port->mapping.module; u8 module = mlxsw_sp_port->mapping.module;
return mlxsw_env_set_module_power_mode(mlxsw_sp->core, module, return mlxsw_env_set_module_power_mode(mlxsw_sp->core, 0, module,
params->policy, extack); params->policy, extack);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment