Skip to content

Commit

Permalink
lib: Add API switchtec_die_temps for multiple die sensor readings
Browse files Browse the repository at this point in the history
Gen5 introduces a new MRPC for multiple die sensor readings. Add this
API to get the individual reading for each die sensor.
  • Loading branch information
kelvin-cao committed Dec 2, 2023
1 parent f9ba36f commit 98626c9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions inc/switchtec/switchtec.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ int switchtec_log_def_to_file(struct switchtec_dev *dev,
enum switchtec_log_def_type type,
FILE* file);
float switchtec_die_temp(struct switchtec_dev *dev);
int switchtec_die_temps(struct switchtec_dev *dev, int nr_sensor,
float *sensor_readings);
int switchtec_calc_lane_id(struct switchtec_dev *dev, int phys_port_id,
int lane_id, struct switchtec_status *port);
int switchtec_calc_port_lane(struct switchtec_dev *dev, int lane_id,
Expand Down
58 changes: 58 additions & 0 deletions lib/switchtec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,64 @@ float switchtec_die_temp(struct switchtec_dev *dev)
return le32toh(temp) / 100.;
}

/**
* @brief Get the die temperature sensor readings of the switchtec device
* @param[in] dev Switchtec device handle
* @param[in] nr_sensor Number of temp sensors to read
* @param[out] sensor_readings Array of sensor readings (in degrees celsius)
* @return The number of sensor readings or a negative value on failure
*/
int switchtec_die_temps(struct switchtec_dev *dev, int nr_sensor,
float *sensor_readings)
{
int ret;
uint32_t sub_cmd_id;
uint32_t temp;

if (nr_sensor <= 0 || !sensor_readings)
return 0;

if (switchtec_is_gen3(dev)) {
sub_cmd_id = MRPC_DIETEMP_SET_MEAS;
ret = switchtec_cmd(dev, MRPC_DIETEMP, &sub_cmd_id,
sizeof(sub_cmd_id), NULL, 0);
if (ret)
return -100.0;

sub_cmd_id = MRPC_DIETEMP_GET;
ret = switchtec_cmd(dev, MRPC_DIETEMP, &sub_cmd_id,
sizeof(sub_cmd_id), &temp, sizeof(temp));
if (ret)
return -100.0;

sensor_readings[0] = le32toh(temp) / 100.;
return 1;
} else if (switchtec_is_gen4(dev)) {
sub_cmd_id = MRPC_DIETEMP_GET_GEN4;
ret = switchtec_cmd(dev, MRPC_DIETEMP, &sub_cmd_id,
sizeof(sub_cmd_id), &temp, sizeof(temp));
if (ret)
return -100.0;

sensor_readings[0] = le32toh(temp) / 100.;
return 1;
} else {
sub_cmd_id = MRPC_DIETEMP_GET_GEN5;
uint32_t temps[4];
int i;

ret = switchtec_cmd(dev, MRPC_DIETEMP, &sub_cmd_id,
sizeof(sub_cmd_id), temps, sizeof(temps));
if (ret)
return -100.0;

for (i = 0; i < nr_sensor && i < 4; i++)
sensor_readings[i] = le32toh(temps[i]) / 100.;

return i;
}
}

int switchtec_bind_info(struct switchtec_dev *dev,
struct switchtec_bind_status_out *status, int phy_port)
{
Expand Down

0 comments on commit 98626c9

Please sign in to comment.