Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin-cao committed Dec 6, 2023
2 parents 3c0e7ab + 27dbfd7 commit e7c351c
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 8 deletions.
38 changes: 30 additions & 8 deletions cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1284,26 +1284,48 @@ static int test(int argc, char **argv)
static int temp(int argc, char **argv)
{
float ret;
int nr_reading;
float temps[4];

static struct {
struct switchtec_dev *dev;
int verbose;
} cfg = {};
const struct argconfig_options opts[] = {
DEVICE_OPTION,
{"verbose", 'v', "", CFG_NONE, &cfg.verbose, no_argument,
"print individual die temperature sensor reading"},
{NULL}};

argconfig_parse(argc, argv, CMD_DESC_TEMP, opts, &cfg, sizeof(cfg));

ret = switchtec_die_temp(cfg.dev);
if (ret < 0) {
switchtec_perror("die_temp");
return 1;
if (!cfg.verbose) {
ret = switchtec_die_temp(cfg.dev);
if (ret < 0) {
switchtec_perror("die_temp");
return 1;
}

if (have_decent_term())
printf("%.3g °C\n", ret);
else
printf("%.3g degC\n", ret);
} else {
int i;
nr_reading = switchtec_die_temps(cfg.dev, 4, temps);
if (nr_reading < 0) {
switchtec_perror("die_temp");
return 1;
}

for (i = 0; i < nr_reading; i++) {
if (have_decent_term())
printf("Sensor %d: %.3g °C\n", i, temps[i]);
else
printf("Sensor %d: %.3g degC\n", i, temps[i]);
}
}

if (have_decent_term())
printf("%.3g °C\n", ret);
else
printf("%.3g degC\n", ret);
return 0;
}

Expand Down
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 e7c351c

Please sign in to comment.