|
Packit |
ac2ffc |
/*
|
|
Packit |
ac2ffc |
* Copyright (c) 2018 Quanta Computer Inc. All rights reserved.
|
|
Packit |
ac2ffc |
*
|
|
Packit |
ac2ffc |
* Redistribution and use in source and binary forms, with or without
|
|
Packit |
ac2ffc |
* modification, are permitted provided that the following conditions
|
|
Packit |
ac2ffc |
* are met:
|
|
Packit |
ac2ffc |
*
|
|
Packit |
ac2ffc |
* Redistribution of source code must retain the above copyright
|
|
Packit |
ac2ffc |
* notice, this list of conditions and the following disclaimer.
|
|
Packit |
ac2ffc |
*
|
|
Packit |
ac2ffc |
* Redistribution in binary form must reproduce the above copyright
|
|
Packit |
ac2ffc |
* notice, this list of conditions and the following disclaimer in the
|
|
Packit |
ac2ffc |
* documentation and/or other materials provided with the distribution.
|
|
Packit |
ac2ffc |
*
|
|
Packit |
ac2ffc |
* Neither the name of Quanta Computer Inc. or the names of
|
|
Packit |
ac2ffc |
* contributors may be used to endorse or promote products derived
|
|
Packit |
ac2ffc |
* from this software without specific prior written permission.
|
|
Packit |
ac2ffc |
*
|
|
Packit |
ac2ffc |
* This software is provided "AS IS," without a warranty of any kind.
|
|
Packit |
ac2ffc |
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
|
|
Packit |
ac2ffc |
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
|
|
Packit |
ac2ffc |
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
|
|
Packit |
ac2ffc |
* Quanta Computer Inc. AND ITS LICENSORS SHALL NOT BE LIABLE
|
|
Packit |
ac2ffc |
* FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
|
|
Packit |
ac2ffc |
* OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
|
|
Packit |
ac2ffc |
* Quanta Computer Inc. OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
|
|
Packit |
ac2ffc |
* OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
|
|
Packit |
ac2ffc |
* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
|
|
Packit |
ac2ffc |
* LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
|
|
Packit |
ac2ffc |
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
Packit |
ac2ffc |
*/
|
|
Packit |
ac2ffc |
#define _XOPEN_SOURCE
|
|
Packit |
ac2ffc |
|
|
Packit |
ac2ffc |
#include <stdlib.h>
|
|
Packit |
ac2ffc |
#include <stdio.h>
|
|
Packit |
ac2ffc |
#include <string.h>
|
|
Packit |
ac2ffc |
#include <strings.h>
|
|
Packit |
ac2ffc |
#include <sys/socket.h>
|
|
Packit |
ac2ffc |
#include <netinet/in.h>
|
|
Packit |
ac2ffc |
#include <arpa/inet.h>
|
|
Packit |
ac2ffc |
#include <errno.h>
|
|
Packit |
ac2ffc |
#include <time.h>
|
|
Packit |
ac2ffc |
#include <unistd.h>
|
|
Packit |
ac2ffc |
#include <signal.h>
|
|
Packit |
ac2ffc |
#include <ctype.h>
|
|
Packit |
ac2ffc |
#include <sys/time.h>
|
|
Packit |
ac2ffc |
#include <limits.h>
|
|
Packit |
ac2ffc |
#include <fcntl.h>
|
|
Packit |
ac2ffc |
#include <sys/select.h>
|
|
Packit |
ac2ffc |
#include <termios.h>
|
|
Packit |
ac2ffc |
#include <ipmitool/ipmi.h>
|
|
Packit |
ac2ffc |
#include <ipmitool/ipmi_mc.h>
|
|
Packit |
ac2ffc |
#include <ipmitool/ipmi_intf.h>
|
|
Packit |
ac2ffc |
#include <ipmitool/helper.h>
|
|
Packit |
ac2ffc |
#include <ipmitool/log.h>
|
|
Packit |
ac2ffc |
#include <ipmitool/ipmi_sel.h>
|
|
Packit |
ac2ffc |
#include <ipmitool/ipmi_sdr.h>
|
|
Packit |
ac2ffc |
#include <ipmitool/ipmi_strings.h>
|
|
Packit |
ac2ffc |
#include <ipmitool/ipmi_channel.h>
|
|
Packit |
ac2ffc |
#include <ipmitool/ipmi_quantaoem.h>
|
|
Packit |
ac2ffc |
#include <ipmitool/ipmi_raw.h>
|
|
Packit |
ac2ffc |
|
|
Packit |
ac2ffc |
/* Max Size of the description String to be displyed for the Each sel entry */
|
|
Packit |
ac2ffc |
#define SIZE_OF_DESC 128
|
|
Packit |
ac2ffc |
|
|
Packit |
ac2ffc |
#define CPU_SHIFT 6
|
|
Packit |
ac2ffc |
#define CPU_MASK 0X03
|
|
Packit |
ac2ffc |
#define CPU_NUM(x) (((x) >> CPU_SHIFT) & CPU_MASK)
|
|
Packit |
ac2ffc |
|
|
Packit |
ac2ffc |
#define CHANNEL_BASE 0x41
|
|
Packit |
ac2ffc |
#define CHANNEL_SHIFT 3
|
|
Packit |
ac2ffc |
#define CHANNEL_MASK 0x07
|
|
Packit |
ac2ffc |
#define CHANNEL_OFFSET(x) (((x) >> CHANNEL_SHIFT) & CHANNEL_MASK)
|
|
Packit |
ac2ffc |
#define CHANNEL_NUM(x) (CHANNEL_BASE + CHANNEL_OFFSET(x))
|
|
Packit |
ac2ffc |
|
|
Packit |
ac2ffc |
#define DIMM_MASK 0x07
|
|
Packit |
ac2ffc |
#define DIMM_NUM(x) ((x) & DIMM_MASK)
|
|
Packit |
ac2ffc |
|
|
Packit |
ac2ffc |
#define GET_PLATFORM_ID_DATA_SIZE 4
|
|
Packit |
ac2ffc |
|
|
Packit |
ac2ffc |
// Magic code to check if it's valid command
|
|
Packit |
ac2ffc |
#define QCT_MAGIC_1 0x4C
|
|
Packit |
ac2ffc |
#define QCT_MAGIC_2 0x1C
|
|
Packit |
ac2ffc |
#define QCT_MAGIC_3 0x00
|
|
Packit |
ac2ffc |
#define QCT_MAGIC_4 0x02
|
|
Packit |
ac2ffc |
|
|
Packit |
ac2ffc |
qct_platform_t
|
|
Packit |
ac2ffc |
oem_qct_get_platform_id(struct ipmi_intf *intf)
|
|
Packit |
ac2ffc |
{
|
|
Packit |
ac2ffc |
/* Execute a Get platform ID command to determine the board */
|
|
Packit |
ac2ffc |
struct ipmi_rs *rsp;
|
|
Packit |
ac2ffc |
struct ipmi_rq req;
|
|
Packit |
ac2ffc |
qct_platform_t platform_id;
|
|
Packit |
ac2ffc |
uint8_t msg_data[GET_PLATFORM_ID_DATA_SIZE];
|
|
Packit |
ac2ffc |
|
|
Packit |
ac2ffc |
/* Ask for IPMI v2 data as well */
|
|
Packit |
ac2ffc |
msg_data[0] = QCT_MAGIC_1;
|
|
Packit |
ac2ffc |
msg_data[1] = QCT_MAGIC_2;
|
|
Packit |
ac2ffc |
msg_data[2] = QCT_MAGIC_3;
|
|
Packit |
ac2ffc |
msg_data[3] = QCT_MAGIC_4;
|
|
Packit |
ac2ffc |
|
|
Packit |
ac2ffc |
memset(&req, 0, sizeof(req));
|
|
Packit |
ac2ffc |
req.msg.netfn = OEM_QCT_NETFN;
|
|
Packit |
ac2ffc |
req.msg.cmd = OEM_QCT_GET_INFO;
|
|
Packit |
ac2ffc |
req.msg.data = msg_data;
|
|
Packit |
ac2ffc |
req.msg.data_len = sizeof(msg_data);
|
|
Packit |
ac2ffc |
|
|
Packit |
ac2ffc |
rsp = intf->sendrecv(intf, &req;;
|
|
Packit |
ac2ffc |
if (rsp == NULL) {
|
|
Packit |
ac2ffc |
lprintf(LOG_ERR, "Get Platform ID command failed");
|
|
Packit |
ac2ffc |
return 0;
|
|
Packit |
ac2ffc |
}
|
|
Packit |
ac2ffc |
if (rsp->ccode) {
|
|
Packit |
ac2ffc |
lprintf(LOG_ERR, "Get Platform ID command failed: %#x %s",
|
|
Packit |
ac2ffc |
rsp->ccode, val2str(rsp->ccode, completion_code_vals));
|
|
Packit |
ac2ffc |
return 0;
|
|
Packit |
ac2ffc |
}
|
|
Packit |
ac2ffc |
platform_id = rsp->data[0];
|
|
Packit |
ac2ffc |
lprintf(LOG_DEBUG,"Platform ID: %hhx", rsp->data[0]);
|
|
Packit |
ac2ffc |
return platform_id;
|
|
Packit |
ac2ffc |
}
|
|
Packit |
ac2ffc |
|
|
Packit |
ac2ffc |
char *
|
|
Packit |
ac2ffc |
oem_qct_get_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec)
|
|
Packit |
ac2ffc |
{
|
|
Packit |
ac2ffc |
struct ipmi_rs *rsp;
|
|
Packit |
ac2ffc |
struct ipmi_rq req;
|
|
Packit |
ac2ffc |
char *desc = NULL;
|
|
Packit |
ac2ffc |
int data;
|
|
Packit |
ac2ffc |
int sensor_type;
|
|
Packit |
ac2ffc |
qct_platform_t platform_id;
|
|
Packit |
ac2ffc |
|
|
Packit |
ac2ffc |
/* Get the OEM event Bytes of the SEL Records byte 15 to data */
|
|
Packit |
ac2ffc |
data = rec->sel_type.standard_type.event_data[2];
|
|
Packit |
ac2ffc |
/* Check for the Standard Event type == 0x6F */
|
|
Packit |
ac2ffc |
if (rec->sel_type.standard_type.event_type != 0x6F) {
|
|
Packit |
ac2ffc |
goto out;
|
|
Packit |
ac2ffc |
}
|
|
Packit |
ac2ffc |
/* Allocate mem for te Description string */
|
|
Packit |
ac2ffc |
desc = malloc(SIZE_OF_DESC);
|
|
Packit |
ac2ffc |
if (desc == NULL) {
|
|
Packit |
ac2ffc |
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
|
Packit |
ac2ffc |
goto out;
|
|
Packit |
ac2ffc |
}
|
|
Packit |
ac2ffc |
memset(desc, 0, SIZE_OF_DESC);
|
|
Packit |
ac2ffc |
sensor_type = rec->sel_type.standard_type.sensor_type;
|
|
Packit |
ac2ffc |
switch (sensor_type) {
|
|
Packit |
ac2ffc |
case SENSOR_TYPE_MEMORY:
|
|
Packit |
ac2ffc |
memset(&req, 0, sizeof (req));
|
|
Packit |
ac2ffc |
req.msg.netfn = IPMI_NETFN_APP;
|
|
Packit |
ac2ffc |
req.msg.lun = 0;
|
|
Packit |
ac2ffc |
req.msg.cmd = BMC_GET_DEVICE_ID;
|
|
Packit |
ac2ffc |
req.msg.data = NULL;
|
|
Packit |
ac2ffc |
req.msg.data_len = 0;
|
|
Packit |
ac2ffc |
|
|
Packit |
ac2ffc |
rsp = intf->sendrecv(intf, &req;;
|
|
Packit |
ac2ffc |
if (rsp == NULL) {
|
|
Packit |
ac2ffc |
lprintf(LOG_ERR, " Error getting system info");
|
|
Packit |
ac2ffc |
goto out;
|
|
Packit |
ac2ffc |
} else if (rsp->ccode) {
|
|
Packit |
ac2ffc |
lprintf(LOG_ERR, " Error getting system info: %s",
|
|
Packit |
ac2ffc |
val2str(rsp->ccode, completion_code_vals));
|
|
Packit |
ac2ffc |
goto out;
|
|
Packit |
ac2ffc |
}
|
|
Packit |
ac2ffc |
/* check the platform type */
|
|
Packit |
ac2ffc |
platform_id = oem_qct_get_platform_id(intf);
|
|
Packit |
ac2ffc |
if (OEM_QCT_PLATFORM_PURLEY == platform_id) {
|
|
Packit |
ac2ffc |
snprintf(desc, SIZE_OF_DESC, "CPU%d_%c%d",
|
|
Packit |
ac2ffc |
CPU_NUM(data),
|
|
Packit |
ac2ffc |
CHANNEL_NUM(data),
|
|
Packit |
ac2ffc |
DIMM_NUM(data));
|
|
Packit |
ac2ffc |
}
|
|
Packit |
ac2ffc |
break;
|
|
Packit |
ac2ffc |
default:
|
|
Packit |
ac2ffc |
goto out;
|
|
Packit |
ac2ffc |
}
|
|
Packit |
ac2ffc |
return desc;
|
|
Packit |
ac2ffc |
out:
|
|
Packit |
ac2ffc |
if (desc) {
|
|
Packit |
ac2ffc |
free(desc);
|
|
Packit |
ac2ffc |
desc = NULL;
|
|
Packit |
ac2ffc |
}
|
|
Packit |
ac2ffc |
return desc;
|
|
Packit |
ac2ffc |
}
|