Blame SOURCES/0010-quanta-oem-support.patch

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