|
Packit |
534379 |
// Copyright(c) 2018-2020, Intel Corporation
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// Redistribution and use in source and binary forms, with or without
|
|
Packit |
534379 |
// modification, are permitted provided that the following conditions are met:
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// * Redistributions of source code must retain the above copyright notice,
|
|
Packit |
534379 |
// this list of conditions and the following disclaimer.
|
|
Packit |
534379 |
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
Packit |
534379 |
// this list of conditions and the following disclaimer in the documentation
|
|
Packit |
534379 |
// and/or other materials provided with the distribution.
|
|
Packit |
534379 |
// * Neither the name of Intel Corporation nor the names of its contributors
|
|
Packit |
534379 |
// may be used to endorse or promote products derived from this software
|
|
Packit |
534379 |
// without specific prior written permission.
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
534379 |
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
534379 |
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit |
534379 |
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
Packit |
534379 |
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
Packit |
534379 |
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
Packit |
534379 |
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit |
534379 |
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
Packit |
534379 |
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit |
534379 |
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
Packit |
534379 |
// POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#include <getopt.h>
|
|
Packit |
534379 |
#include "fpgainfo.h"
|
|
Packit |
534379 |
#include "tempinfo.h"
|
|
Packit |
534379 |
#include "bmcdata.h"
|
|
Packit |
534379 |
#include "board.h"
|
|
Packit |
534379 |
#include <sys/stat.h>
|
|
Packit |
534379 |
#include <opae/fpga.h>
|
|
Packit |
534379 |
#include <wchar.h>
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/*
|
|
Packit |
534379 |
* Print help
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
void temp_help(void)
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
printf("\nPrint thermal metrics\n"
|
|
Packit |
534379 |
" fpgainfo temp [-h]\n"
|
|
Packit |
534379 |
" -h,--help Print this help\n"
|
|
Packit |
534379 |
"\n");
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
static void print_temp_info(fpga_token token)
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
fpga_properties props;
|
|
Packit |
534379 |
fpga_object obj = NULL;
|
|
Packit |
534379 |
fpga_metric_info metrics_info[METRICS_MAX_NUM];
|
|
Packit |
534379 |
fpga_metric metrics[METRICS_MAX_NUM];
|
|
Packit |
534379 |
uint64_t num_metrics;
|
|
Packit |
534379 |
uint64_t num_metrics_info;
|
|
Packit |
534379 |
fpga_result res = FPGA_OK;
|
|
Packit |
534379 |
uint64_t pkg_temp;
|
|
Packit |
534379 |
struct stat st;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
res = fpgaGetProperties(token, &props;;
|
|
Packit |
534379 |
ON_FPGAINFO_ERR_GOTO(res, out_destroy, "Failure reading properties from token");
|
|
Packit |
534379 |
|
|
Packit |
534379 |
fpgainfo_board_info(token);
|
|
Packit |
534379 |
fpgainfo_print_common("//****** TEMP ******//", props);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (!stat("/sys/bus/pci/drivers/intel-fpga-pci", &st)) {
|
|
Packit |
534379 |
|
|
Packit |
534379 |
res = fpgaTokenGetObject(token, PKG_TEMP_NAME, &obj, FPGA_OBJECT_GLOB);
|
|
Packit |
534379 |
ON_FPGAINFO_ERR_GOTO(res, out_destroy, "Failure getting temp object from token");
|
|
Packit |
534379 |
res = fpgaObjectRead64(obj, &pkg_temp, FPGA_OBJECT_SYNC);
|
|
Packit |
534379 |
ON_FPGAINFO_ERR_GOTO(res, out_destroy, "Failure reading package temperature value");
|
|
Packit |
534379 |
printf("%-32s : %02ld %s\n", "Package Temperature", pkg_temp, "Centigrade");
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if (!stat("/sys/bus/pci/drivers/dfl-pci", &st)) {
|
|
Packit |
534379 |
|
|
Packit |
534379 |
res = fpgaTokenGetObject(token, PKG_TEMP_UPS_DRV_NAME, &obj, FPGA_OBJECT_GLOB);
|
|
Packit |
534379 |
ON_FPGAINFO_ERR_GOTO(res, out_destroy, "Failure getting temp object from token");
|
|
Packit |
534379 |
res = fpgaObjectRead64(obj, &pkg_temp, FPGA_OBJECT_SYNC);
|
|
Packit |
534379 |
ON_FPGAINFO_ERR_GOTO(res, out_destroy, "Failure reading package temperature value");
|
|
Packit |
534379 |
printf("%-32s : %02ld %s\n", "Package Temperature", pkg_temp, "Milli Centigrade");
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
res = get_metrics(token, FPGA_THERMAL, metrics_info, &num_metrics_info, metrics, &num_metrics);
|
|
Packit |
534379 |
ON_FPGAINFO_ERR_GOTO(res, out_destroy, "reading metrics from BMC");
|
|
Packit |
534379 |
|
|
Packit |
534379 |
print_metrics(metrics_info, num_metrics_info, metrics, num_metrics);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
out_destroy:
|
|
Packit |
534379 |
if (obj) {
|
|
Packit |
534379 |
res = fpgaDestroyObject(&obj);
|
|
Packit |
534379 |
ON_FPGAINFO_ERR_GOTO(res, out_exit, "destroying object");
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
res = fpgaDestroyProperties(&props;;
|
|
Packit |
534379 |
ON_FPGAINFO_ERR_GOTO(res, out_exit, "destroying properties");
|
|
Packit |
534379 |
|
|
Packit |
534379 |
out_exit:
|
|
Packit |
534379 |
return;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
fpga_result temp_filter(fpga_properties *filter, int argc, char *argv[])
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
(void)argc;
|
|
Packit |
534379 |
(void)argv;
|
|
Packit |
534379 |
fpga_result res = FPGA_OK;
|
|
Packit |
534379 |
res = fpgaPropertiesSetObjectType(*filter, FPGA_DEVICE);
|
|
Packit |
534379 |
fpgainfo_print_err("setting type to FPGA_DEVICE", res);
|
|
Packit |
534379 |
return res;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
fpga_result temp_command(fpga_token *tokens, int num_tokens, int argc,
|
|
Packit |
534379 |
char *argv[])
|
|
Packit |
534379 |
{
|
|
Packit |
534379 |
(void)tokens;
|
|
Packit |
534379 |
(void)num_tokens;
|
|
Packit |
534379 |
(void)argc;
|
|
Packit |
534379 |
(void)argv;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
fpga_result res = FPGA_OK;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
optind = 0;
|
|
Packit |
534379 |
struct option longopts[] = {
|
|
Packit |
534379 |
{"help", no_argument, NULL, 'h'},
|
|
Packit |
534379 |
{0, 0, 0, 0},
|
|
Packit |
534379 |
};
|
|
Packit |
534379 |
|
|
Packit |
534379 |
int getopt_ret;
|
|
Packit |
534379 |
int option_index;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
while (-1
|
|
Packit |
534379 |
!= (getopt_ret = getopt_long(argc, argv, ":h", longopts,
|
|
Packit |
534379 |
&option_index))) {
|
|
Packit |
534379 |
const char *tmp_optarg = optarg;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
if ((optarg) && ('=' == *tmp_optarg)) {
|
|
Packit |
534379 |
++tmp_optarg;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
switch (getopt_ret) {
|
|
Packit |
534379 |
case 'h': /* help */
|
|
Packit |
534379 |
temp_help();
|
|
Packit |
534379 |
return res;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
case ':': /* missing option argument */
|
|
Packit |
534379 |
fprintf(stderr, "Missing option argument\n");
|
|
Packit |
534379 |
temp_help();
|
|
Packit |
534379 |
return FPGA_INVALID_PARAM;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
case '?':
|
|
Packit |
534379 |
default: /* invalid option */
|
|
Packit |
534379 |
fprintf(stderr, "Invalid cmdline options\n");
|
|
Packit |
534379 |
temp_help();
|
|
Packit |
534379 |
return FPGA_INVALID_PARAM;
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
int i = 0;
|
|
Packit |
534379 |
for (i = 0; i < num_tokens; ++i) {
|
|
Packit |
534379 |
print_temp_info(tokens[i]);
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
|
|
Packit |
534379 |
return res;
|
|
Packit |
534379 |
}
|