Skip to content

Commit

Permalink
mlxsw: core: Add support for temperature thresholds reading for QSFP-…
Browse files Browse the repository at this point in the history
…DD transceivers

Allow QSFP-DD transceivers temperature thresholds reading for hardware
monitoring and thermal control.

For this type, the thresholds are located in page 02h according to the
"Module and Lane Thresholds" description from Common Management
Interface Specification.

Signed-off-by: Vadim Pasternak <[email protected]>
Signed-off-by: Ido Schimmel <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
mellanoxbmc authored and davem330 committed Jul 28, 2020
1 parent 6af496a commit f152b41
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
32 changes: 22 additions & 10 deletions drivers/net/ethernet/mellanox/mlxsw/core_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "reg.h"

static int mlxsw_env_validate_cable_ident(struct mlxsw_core *core, int id,
bool *qsfp)
bool *qsfp, bool *cmis)
{
char eeprom_tmp[MLXSW_REG_MCIA_EEPROM_SIZE];
char mcia_pl[MLXSW_REG_MCIA_LEN];
Expand All @@ -25,15 +25,19 @@ static int mlxsw_env_validate_cable_ident(struct mlxsw_core *core, int id,
return err;
mlxsw_reg_mcia_eeprom_memcpy_from(mcia_pl, eeprom_tmp);
ident = eeprom_tmp[0];
*cmis = false;
switch (ident) {
case MLXSW_REG_MCIA_EEPROM_MODULE_INFO_ID_SFP:
*qsfp = false;
break;
case MLXSW_REG_MCIA_EEPROM_MODULE_INFO_ID_QSFP: /* fall-through */
case MLXSW_REG_MCIA_EEPROM_MODULE_INFO_ID_QSFP_PLUS: /* fall-through */
case MLXSW_REG_MCIA_EEPROM_MODULE_INFO_ID_QSFP28: /* fall-through */
case MLXSW_REG_MCIA_EEPROM_MODULE_INFO_ID_QSFP28:
*qsfp = true;
break;
case MLXSW_REG_MCIA_EEPROM_MODULE_INFO_ID_QSFP_DD:
*qsfp = true;
*cmis = true;
break;
default:
return -EINVAL;
Expand Down Expand Up @@ -117,7 +121,8 @@ int mlxsw_env_module_temp_thresholds_get(struct mlxsw_core *core, int module,
char mcia_pl[MLXSW_REG_MCIA_LEN] = {0};
char mtmp_pl[MLXSW_REG_MTMP_LEN];
unsigned int module_temp;
bool qsfp;
bool qsfp, cmis;
int page;
int err;

mlxsw_reg_mtmp_pack(mtmp_pl, MLXSW_REG_MTMP_MODULE_INDEX_MIN + module,
Expand All @@ -141,21 +146,28 @@ int mlxsw_env_module_temp_thresholds_get(struct mlxsw_core *core, int module,
*/

/* Validate module identifier value. */
err = mlxsw_env_validate_cable_ident(core, module, &qsfp);
err = mlxsw_env_validate_cable_ident(core, module, &qsfp, &cmis);
if (err)
return err;

if (qsfp)
mlxsw_reg_mcia_pack(mcia_pl, module, 0,
MLXSW_REG_MCIA_TH_PAGE_NUM,
if (qsfp) {
/* For QSFP/CMIS module-defined thresholds are located in page
* 02h, otherwise in page 03h.
*/
if (cmis)
page = MLXSW_REG_MCIA_TH_PAGE_CMIS_NUM;
else
page = MLXSW_REG_MCIA_TH_PAGE_NUM;
mlxsw_reg_mcia_pack(mcia_pl, module, 0, page,
MLXSW_REG_MCIA_TH_PAGE_OFF + off,
MLXSW_REG_MCIA_TH_ITEM_SIZE,
MLXSW_REG_MCIA_I2C_ADDR_LOW);
else
} else {
mlxsw_reg_mcia_pack(mcia_pl, module, 0,
MLXSW_REG_MCIA_PAGE0_LO,
off, MLXSW_REG_MCIA_TH_ITEM_SIZE,
MLXSW_REG_MCIA_I2C_ADDR_HIGH);
}

err = mlxsw_reg_query(core, MLXSW_REG(mcia), mcia_pl);
if (err)
Expand Down Expand Up @@ -252,16 +264,16 @@ int mlxsw_env_get_module_eeprom(struct net_device *netdev,
{
int offset = ee->offset;
unsigned int read_size;
bool qsfp, cmis;
int i = 0;
bool qsfp;
int err;

if (!ee->len)
return -EINVAL;

memset(data, 0, ee->len);
/* Validate module identifier value. */
err = mlxsw_env_validate_cable_ident(mlxsw_core, module, &qsfp);
err = mlxsw_env_validate_cable_ident(mlxsw_core, module, &qsfp, &cmis);
if (err)
return err;

Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/mellanox/mlxsw/reg.h
Original file line number Diff line number Diff line change
Expand Up @@ -8605,6 +8605,7 @@ MLXSW_ITEM32(reg, mcia, size, 0x08, 0, 16);
#define MLXSW_REG_MCIA_PAGE0_LO_OFF 0xa0
#define MLXSW_REG_MCIA_TH_ITEM_SIZE 2
#define MLXSW_REG_MCIA_TH_PAGE_NUM 3
#define MLXSW_REG_MCIA_TH_PAGE_CMIS_NUM 2
#define MLXSW_REG_MCIA_PAGE0_LO 0
#define MLXSW_REG_MCIA_TH_PAGE_OFF 0x80
#define MLXSW_REG_MCIA_EEPROM_CMIS_FLAT_MEMORY BIT(7)
Expand Down

0 comments on commit f152b41

Please sign in to comment.