From f9ba36fff663f319425cb0b3a490a4df78906b70 Mon Sep 17 00:00:00 2001 From: Kelvin Cao Date: Mon, 27 Nov 2023 16:50:49 -0800 Subject: [PATCH] cli: support temp command for Gen5 Gen5 revB switch introduces a new MRPC sub-command for getting die temperature. It reports temperature values from four on die sensors. Support this method with this patch. --- inc/switchtec/mrpc.h | 1 + lib/switchtec.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/inc/switchtec/mrpc.h b/inc/switchtec/mrpc.h index 0441c5ba..b5b7882a 100644 --- a/inc/switchtec/mrpc.h +++ b/inc/switchtec/mrpc.h @@ -180,6 +180,7 @@ enum mrpc_sub_cmd { MRPC_DIETEMP_GET = 2, MRPC_DIETEMP_STOP = 3, MRPC_DIETEMP_GET_GEN4 = 2, + MRPC_DIETEMP_GET_GEN5 = 4, MRPC_MULTI_CFG_SUPPORTED = 0, MRPC_MULTI_CFG_COUNT = 1, diff --git a/lib/switchtec.c b/lib/switchtec.c index acdcc600..ed8dc7af 100644 --- a/lib/switchtec.c +++ b/lib/switchtec.c @@ -1806,12 +1806,20 @@ float switchtec_die_temp(struct switchtec_dev *dev) sizeof(sub_cmd_id), &temp, sizeof(temp)); if (ret) return -100.0; - } else { + } 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; + } else { + sub_cmd_id = MRPC_DIETEMP_GET_GEN5; + uint32_t temps[4]; + ret = switchtec_cmd(dev, MRPC_DIETEMP, &sub_cmd_id, + sizeof(sub_cmd_id), temps, sizeof(temps)); + if (ret) + return -100.0; + temp = (temps[0] + temps[1] + temps[2] + temps[3]) / 4; } return le32toh(temp) / 100.;