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