c35241
From 87a898756a7bd54898c1f6d2a5441efb1f810b67 Mon Sep 17 00:00:00 2001
c35241
From: qctbmc <qct.bmc@gmail.com>
c35241
Date: Tue, 10 Jul 2018 11:21:55 +0800
c35241
Subject: [PATCH] oem: Add basic support for Quanta
c35241
c35241
---
c35241
 include/ipmitool/Makefile.am      |   2 +-
c35241
 include/ipmitool/ipmi_quantaoem.h |  55 +++++++++
c35241
 lib/Makefile.am                   |   2 +-
c35241
 lib/ipmi_main.c                   |   1 +
c35241
 lib/ipmi_oem.c                    |  14 +++
c35241
 lib/ipmi_quantaoem.c              | 184 ++++++++++++++++++++++++++++++
c35241
 lib/ipmi_sel.c                    |  21 +++-
c35241
 src/ipmitool.c                    |   1 +
c35241
 8 files changed, 274 insertions(+), 6 deletions(-)
c35241
 create mode 100644 include/ipmitool/ipmi_quantaoem.h
c35241
 create mode 100644 lib/ipmi_quantaoem.c
c35241
c35241
diff --git a/include/ipmitool/Makefile.am b/include/ipmitool/Makefile.am
c35241
index 9093a56..8bc584a 100644
c35241
--- a/include/ipmitool/Makefile.am
c35241
+++ b/include/ipmitool/Makefile.am
c35241
@@ -39,4 +39,4 @@ noinst_HEADERS = log.h bswap.h hpm2.h helper.h ipmi.h ipmi_cc.h ipmi_intf.h \
c35241
 	ipmi_fwum.h ipmi_main.h ipmi_tsol.h ipmi_firewall.h \
c35241
 	ipmi_kontronoem.h ipmi_ekanalyzer.h ipmi_gendev.h ipmi_ime.h \
c35241
 	ipmi_delloem.h ipmi_dcmi.h ipmi_vita.h ipmi_sel_supermicro.h \
c35241
-	ipmi_cfgp.h ipmi_lanp6.h
c35241
+	ipmi_cfgp.h ipmi_lanp6.h ipmi_quantaoem.h
c35241
diff --git a/include/ipmitool/ipmi_quantaoem.h b/include/ipmitool/ipmi_quantaoem.h
c35241
new file mode 100644
c35241
index 0000000..544f510
c35241
--- /dev/null
c35241
+++ b/include/ipmitool/ipmi_quantaoem.h
c35241
@@ -0,0 +1,55 @@
c35241
+/*
c35241
+ * Copyright (c) 2018 Quanta Computer Inc. All rights reserved.
c35241
+ *
c35241
+ * Redistribution and use in source and binary forms, with or without
c35241
+ * modification, are permitted provided that the following conditions
c35241
+ * are met:
c35241
+ *
c35241
+ * Redistribution of source code must retain the above copyright
c35241
+ * notice, this list of conditions and the following disclaimer.
c35241
+ *
c35241
+ * Redistribution in binary form must reproduce the above copyright
c35241
+ * notice, this list of conditions and the following disclaimer in the
c35241
+ * documentation and/or other materials provided with the distribution.
c35241
+ *
c35241
+ * Neither the name of Quanta Computer Inc. or the names of
c35241
+ * contributors may be used to endorse or promote products derived
c35241
+ * from this software without specific prior written permission.
c35241
+ *
c35241
+ * This software is provided "AS IS," without a warranty of any kind.
c35241
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
c35241
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
c35241
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
c35241
+ * Quanta Computer Inc. AND ITS LICENSORS SHALL NOT BE LIABLE
c35241
+ * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
c35241
+ * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.  IN NO EVENT WILL
c35241
+ * Quanta Computer Inc. OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
c35241
+ * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
c35241
+ * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
c35241
+ * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
c35241
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
c35241
+ */
c35241
+
c35241
+#ifndef IPMI_QUANTAOEM_H
c35241
+#define IPMI_QUANTAOEM_H
c35241
+
c35241
+#if HAVE_CONFIG_H
c35241
+# include <config.h>
c35241
+#endif
c35241
+#include <ipmitool/ipmi.h>
c35241
+#include <ipmitool/ipmi_sdr.h>
c35241
+
c35241
+#define OEM_QCT_NETFN 0x36
c35241
+#define OEM_QCT_GET_INFO 0x65
c35241
+
c35241
+typedef enum
c35241
+{
c35241
+	OEM_QCT_PLATFORM_UNKNOWN = 0,
c35241
+	OEM_QCT_PLATFORM_GRANTLEY,
c35241
+	OEM_QCT_PLATFORM_PURLEY
c35241
+} qct_platform_t;
c35241
+
c35241
+qct_platform_t oem_qct_get_platform_id(struct ipmi_intf *intf);
c35241
+char *oem_qct_get_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec);
c35241
+
c35241
+#endif /*IPMI_QUANTAOEM_H*/
c35241
diff --git a/lib/Makefile.am b/lib/Makefile.am
c35241
index cc69a8f..e7568f3 100644
c35241
--- a/lib/Makefile.am
c35241
+++ b/lib/Makefile.am
c35241
@@ -41,7 +41,7 @@ libipmitool_la_SOURCES	= helper.c ipmi_sdr.c ipmi_sel.c ipmi_sol.c ipmi_pef.c \
c35241
 				  ipmi_main.c ipmi_tsol.c ipmi_firewall.c ipmi_kontronoem.c        \
c35241
 				  ipmi_hpmfwupg.c ipmi_sdradd.c ipmi_ekanalyzer.c ipmi_gendev.c    \
c35241
 				  ipmi_ime.c ipmi_delloem.c ipmi_dcmi.c hpm2.c ipmi_vita.c \
c35241
-				  ipmi_lanp6.c ipmi_cfgp.c \
c35241
+				  ipmi_lanp6.c ipmi_cfgp.c ipmi_quantaoem.c \
c35241
 				  ../src/plugins/lan/md5.c ../src/plugins/lan/md5.h
c35241
 
c35241
 libipmitool_la_LDFLAGS		= -export-dynamic
c35241
diff --git a/lib/ipmi_main.c b/lib/ipmi_main.c
c35241
index 6aee102..9d4a148 100644
c35241
--- a/lib/ipmi_main.c
c35241
+++ b/lib/ipmi_main.c
c35241
@@ -75,6 +75,7 @@
c35241
 #include <ipmitool/ipmi_picmg.h>
c35241
 #include <ipmitool/ipmi_kontronoem.h>
c35241
 #include <ipmitool/ipmi_vita.h>
c35241
+#include <ipmitool/ipmi_quantaoem.h>
c35241
 
c35241
 #ifdef HAVE_CONFIG_H
c35241
 # include <config.h>
c35241
diff --git a/lib/ipmi_oem.c b/lib/ipmi_oem.c
c35241
index 96db2ea..86fd803 100644
c35241
--- a/lib/ipmi_oem.c
c35241
+++ b/lib/ipmi_oem.c
c35241
@@ -39,6 +39,7 @@
c35241
 
c35241
 static int ipmi_oem_supermicro(struct ipmi_intf * intf);
c35241
 static int ipmi_oem_ibm(struct ipmi_intf * intf);
c35241
+static int ipmi_oem_quanta(struct ipmi_intf * intf);
c35241
 
c35241
 static struct ipmi_oem_handle ipmi_oem_list[] = {
c35241
 	{
c35241
@@ -71,6 +72,11 @@ static struct ipmi_oem_handle ipmi_oem_list[] = {
c35241
 		.name = "kontron",
c35241
 		.desc = "Kontron OEM big buffer support"
c35241
 	},
c35241
+	{
c35241
+		.name = "quanta",
c35241
+		.desc = "Quanta IPMIv1.5 BMC with OEM LAN authentication support",
c35241
+		.setup = ipmi_oem_quanta,
c35241
+	},
c35241
 	{ 0 }
c35241
 };
c35241
 
c35241
@@ -93,6 +99,14 @@ ipmi_oem_ibm(struct ipmi_intf * intf)
c35241
 	return ipmi_sel_oem_init((const char *)filename);
c35241
 }
c35241
 
c35241
+/* Quanta IPMIv2 BMCs use OEM authtype */
c35241
+static int
c35241
+ipmi_oem_quanta(struct ipmi_intf * intf)
c35241
+{
c35241
+	ipmi_intf_session_set_authtype(intf, IPMI_SESSION_AUTHTYPE_OEM);
c35241
+	return 0;
c35241
+}
c35241
+
c35241
 /* ipmi_oem_print  -  print list of OEM handles
c35241
  */
c35241
 void
c35241
diff --git a/lib/ipmi_quantaoem.c b/lib/ipmi_quantaoem.c
c35241
new file mode 100644
c35241
index 0000000..7b4c5c6
c35241
--- /dev/null
c35241
+++ b/lib/ipmi_quantaoem.c
c35241
@@ -0,0 +1,184 @@
c35241
+/*
c35241
+ * Copyright (c) 2018 Quanta Computer Inc. All rights reserved.
c35241
+ *
c35241
+ * Redistribution and use in source and binary forms, with or without
c35241
+ * modification, are permitted provided that the following conditions
c35241
+ * are met:
c35241
+ *
c35241
+ * Redistribution of source code must retain the above copyright
c35241
+ * notice, this list of conditions and the following disclaimer.
c35241
+ *
c35241
+ * Redistribution in binary form must reproduce the above copyright
c35241
+ * notice, this list of conditions and the following disclaimer in the
c35241
+ * documentation and/or other materials provided with the distribution.
c35241
+ *
c35241
+ * Neither the name of Quanta Computer Inc. or the names of
c35241
+ * contributors may be used to endorse or promote products derived
c35241
+ * from this software without specific prior written permission.
c35241
+ *
c35241
+ * This software is provided "AS IS," without a warranty of any kind.
c35241
+ * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
c35241
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
c35241
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
c35241
+ * Quanta Computer Inc. AND ITS LICENSORS SHALL NOT BE LIABLE
c35241
+ * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
c35241
+ * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.  IN NO EVENT WILL
c35241
+ * Quanta Computer Inc. OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
c35241
+ * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
c35241
+ * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
c35241
+ * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
c35241
+ * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
c35241
+ */
c35241
+#define _XOPEN_SOURCE
c35241
+
c35241
+#include <stdlib.h>
c35241
+#include <stdio.h>
c35241
+#include <string.h>
c35241
+#include <strings.h>
c35241
+#include <sys/socket.h>
c35241
+#include <netinet/in.h>
c35241
+#include <arpa/inet.h>
c35241
+#include <errno.h>
c35241
+#include <time.h>
c35241
+#include <unistd.h>
c35241
+#include <signal.h>
c35241
+#include <ctype.h>
c35241
+#include <sys/time.h>
c35241
+#include <limits.h>
c35241
+#include <fcntl.h>
c35241
+#include <sys/select.h>
c35241
+#include <termios.h>
c35241
+#include <ipmitool/ipmi.h>
c35241
+#include <ipmitool/ipmi_mc.h>
c35241
+#include <ipmitool/ipmi_intf.h>
c35241
+#include <ipmitool/helper.h>
c35241
+#include <ipmitool/log.h>
c35241
+#include <ipmitool/ipmi_sel.h>
c35241
+#include <ipmitool/ipmi_sdr.h>
c35241
+#include <ipmitool/ipmi_strings.h>
c35241
+#include <ipmitool/ipmi_channel.h>
c35241
+#include <ipmitool/ipmi_quantaoem.h>
c35241
+#include <ipmitool/ipmi_raw.h>
c35241
+
c35241
+/* Max Size of the description String to be displyed for the Each sel entry */
c35241
+#define	SIZE_OF_DESC 128
c35241
+
c35241
+#define CPU_SHIFT 6
c35241
+#define CPU_MASK 0X03
c35241
+#define CPU_NUM(x) (((x) >> CPU_SHIFT) & CPU_MASK)
c35241
+
c35241
+#define CHANNEL_BASE 0x41
c35241
+#define CHANNEL_SHIFT 3
c35241
+#define CHANNEL_MASK 0x07
c35241
+#define CHANNEL_OFFSET(x) (((x) >> CHANNEL_SHIFT) & CHANNEL_MASK)
c35241
+#define CHANNEL_NUM(x) (CHANNEL_BASE + CHANNEL_OFFSET(x))
c35241
+
c35241
+#define DIMM_MASK 0x07
c35241
+#define DIMM_NUM(x) ((x) & DIMM_MASK)
c35241
+
c35241
+#define	GET_PLATFORM_ID_DATA_SIZE 4
c35241
+
c35241
+// Magic code to check if it's valid command
c35241
+#define QCT_MAGIC_1 0x4C
c35241
+#define QCT_MAGIC_2 0x1C
c35241
+#define QCT_MAGIC_3 0x00
c35241
+#define QCT_MAGIC_4 0x02
c35241
+
c35241
+qct_platform_t
c35241
+oem_qct_get_platform_id(struct ipmi_intf *intf)
c35241
+{
c35241
+	/* Execute a Get platform ID command to determine the board */
c35241
+	struct ipmi_rs *rsp;
c35241
+	struct ipmi_rq req;
c35241
+	qct_platform_t platform_id;
c35241
+	uint8_t msg_data[GET_PLATFORM_ID_DATA_SIZE];
c35241
+
c35241
+	/* Ask for IPMI v2 data as well */
c35241
+	msg_data[0] = QCT_MAGIC_1;
c35241
+	msg_data[1] = QCT_MAGIC_2;
c35241
+	msg_data[2] = QCT_MAGIC_3;
c35241
+	msg_data[3] = QCT_MAGIC_4;
c35241
+
c35241
+	memset(&req, 0, sizeof(req));
c35241
+	req.msg.netfn = OEM_QCT_NETFN;
c35241
+	req.msg.cmd = OEM_QCT_GET_INFO;
c35241
+	req.msg.data = msg_data;
c35241
+	req.msg.data_len = sizeof(msg_data);
c35241
+
c35241
+	rsp = intf->sendrecv(intf, &req;;
c35241
+	if (rsp == NULL) {
c35241
+		lprintf(LOG_ERR, "Get Platform ID command failed");
c35241
+		return 0;
c35241
+	}
c35241
+	if (rsp->ccode) {
c35241
+		lprintf(LOG_ERR, "Get Platform ID command failed: %#x %s",
c35241
+		        rsp->ccode, val2str(rsp->ccode, completion_code_vals));
c35241
+		return 0;
c35241
+	}
c35241
+	platform_id = rsp->data[0];
c35241
+	lprintf(LOG_DEBUG,"Platform ID: %hhx", rsp->data[0]);
c35241
+	return platform_id;
c35241
+}
c35241
+
c35241
+char *
c35241
+oem_qct_get_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec)
c35241
+{
c35241
+	struct ipmi_rs *rsp;
c35241
+	struct ipmi_rq req;
c35241
+	char *desc = NULL;
c35241
+	int data;
c35241
+	int sensor_type;
c35241
+	qct_platform_t platform_id;
c35241
+
c35241
+	/* Get the OEM event Bytes of the SEL Records byte 15 to data */
c35241
+	data = rec->sel_type.standard_type.event_data[2];
c35241
+	/* Check for the Standard Event type == 0x6F */
c35241
+	if (rec->sel_type.standard_type.event_type != 0x6F) {
c35241
+		goto out;
c35241
+	}
c35241
+	/* Allocate mem for te Description string */
c35241
+	desc = malloc(SIZE_OF_DESC);
c35241
+	if (desc == NULL) {
c35241
+		lprintf(LOG_ERR, "ipmitool: malloc failure");
c35241
+		goto out;
c35241
+	}
c35241
+	memset(desc, 0, SIZE_OF_DESC);
c35241
+	sensor_type = rec->sel_type.standard_type.sensor_type;
c35241
+	switch (sensor_type) {
c35241
+	case SENSOR_TYPE_MEMORY:
c35241
+		memset(&req, 0, sizeof (req));
c35241
+		req.msg.netfn = IPMI_NETFN_APP;
c35241
+		req.msg.lun = 0;
c35241
+		req.msg.cmd = BMC_GET_DEVICE_ID;
c35241
+		req.msg.data = NULL;
c35241
+		req.msg.data_len = 0;
c35241
+
c35241
+		rsp = intf->sendrecv(intf, &req;;
c35241
+		if (rsp == NULL) {
c35241
+			lprintf(LOG_ERR, " Error getting system info");
c35241
+			goto out;
c35241
+		} else if (rsp->ccode) {
c35241
+			lprintf(LOG_ERR, " Error getting system info: %s",
c35241
+			        val2str(rsp->ccode, completion_code_vals));
c35241
+			goto out;
c35241
+		}
c35241
+		/* check the platform type */
c35241
+		platform_id = oem_qct_get_platform_id(intf);
c35241
+		if (OEM_QCT_PLATFORM_PURLEY == platform_id) {
c35241
+			snprintf(desc, SIZE_OF_DESC, "CPU%d_%c%d",
c35241
+			         CPU_NUM(data),
c35241
+			         CHANNEL_NUM(data),
c35241
+			         DIMM_NUM(data));
c35241
+		}
c35241
+		break;
c35241
+	default:
c35241
+		goto out;
c35241
+	}
c35241
+	return desc;
c35241
+out:
c35241
+	if (desc) {
c35241
+		free(desc);
c35241
+		desc = NULL;
c35241
+	}
c35241
+	return desc;
c35241
+}
c35241
diff --git a/lib/ipmi_sel.c b/lib/ipmi_sel.c
c35241
index 8b0395e..a54fefd 100644
c35241
--- a/lib/ipmi_sel.c
c35241
+++ b/lib/ipmi_sel.c
c35241
@@ -50,6 +50,7 @@
c35241
 #include <ipmitool/ipmi_fru.h>
c35241
 #include <ipmitool/ipmi_sensor.h>
c35241
 #include <ipmitool/ipmi_strings.h>
c35241
+#include <ipmitool/ipmi_quantaoem.h>
c35241
 
c35241
 extern int verbose;
c35241
 static int sel_extended = 0;
c35241
@@ -1244,6 +1245,9 @@ ipmi_get_oem_desc(struct ipmi_intf * intf, struct sel_event_record * rec)
c35241
 	case IPMI_OEM_SUPERMICRO_47488:
c35241
 		desc = get_supermicro_evt_desc(intf, rec);
c35241
 		break;
c35241
+	case IPMI_OEM_QUANTA:
c35241
+		desc = oem_qct_get_evt_desc(intf, rec);
c35241
+		break;
c35241
 	case IPMI_OEM_UNKNOWN:
c35241
 	default:
c35241
 		break;
c35241
@@ -1349,6 +1353,9 @@ ipmi_get_event_desc(struct ipmi_intf * intf, struct sel_event_record * rec, char
c35241
 					sfx = ipmi_get_oem_desc(intf, rec);
c35241
 					break;
c35241
 				 /* add your oem sensor assignation here */
c35241
+				case IPMI_OEM_QUANTA:
c35241
+					sfx = ipmi_get_oem_desc(intf, rec);
c35241
+					break;
c35241
 				default:
c35241
 					lprintf(LOG_DEBUG, "oem sensor type %x  using standard type supplied description",
c35241
 						rec->sel_type.standard_type.sensor_type );
c35241
@@ -1359,9 +1366,12 @@ ipmi_get_event_desc(struct ipmi_intf * intf, struct sel_event_record * rec, char
c35241
 				case IPMI_OEM_SUPERMICRO:
c35241
 				case IPMI_OEM_SUPERMICRO_47488:
c35241
 					sfx = ipmi_get_oem_desc(intf, rec);
c35241
-				 break;
c35241
+					break;
c35241
+				case IPMI_OEM_QUANTA:
c35241
+					sfx = ipmi_get_oem_desc(intf, rec);
c35241
+					break;
c35241
 				default:
c35241
-				 break;
c35241
+					break;
c35241
 			}
c35241
 		}
c35241
 		/*
c35241
@@ -1986,9 +1996,12 @@ ipmi_sel_print_std_entry(struct ipmi_intf * intf, struct sel_event_record * evt)
c35241
 			case IPMI_OEM_SUPERMICRO:
c35241
 			case IPMI_OEM_SUPERMICRO_47488:
c35241
 				print_sensor = 0;
c35241
-			 break;
c35241
+				break;
c35241
+			case IPMI_OEM_QUANTA:
c35241
+				print_sensor = 0;
c35241
+				break;
c35241
 			default:
c35241
-			 break;
c35241
+				break;
c35241
 		}
c35241
 		/*
c35241
 		 * Sensor-Specific Discrete
c35241
diff --git a/src/ipmitool.c b/src/ipmitool.c
c35241
index 5e19c6e..ec0b741 100644
c35241
--- a/src/ipmitool.c
c35241
+++ b/src/ipmitool.c
c35241
@@ -66,6 +66,7 @@
c35241
 #include <ipmitool/ipmi_ime.h>
c35241
 #include <ipmitool/ipmi_dcmi.h>
c35241
 #include <ipmitool/ipmi_vita.h>
c35241
+#include <ipmitool/ipmi_quantaoem.h>
c35241
 
c35241
 #ifdef HAVE_CONFIG_H
c35241
 # include <config.h>
c35241
-- 
c35241
2.20.1
c35241