summaryrefslogtreecommitdiffstats
path: root/meta-facebook/meta-wedge/recipes-wedge/fblibs/files
diff options
context:
space:
mode:
Diffstat (limited to 'meta-facebook/meta-wedge/recipes-wedge/fblibs/files')
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/Makefile11
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.c117
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.h64
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/Makefile11
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/ipmi.c81
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/ipmi.h35
6 files changed, 319 insertions, 0 deletions
diff --git a/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/Makefile b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/Makefile
new file mode 100644
index 0000000..74ce8f3
--- /dev/null
+++ b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/Makefile
@@ -0,0 +1,11 @@
+# Copyright 2014-present Facebook. All Rights Reserved.
+lib: libalert_control.so
+
+libalert_control.so: alert_control.c
+ $(CC) $(CCFLAGS) -fPIC -c -o alert_control.o alert_control.c
+ $(CC) -shared -o libalert_control.so alert_control.o -lc
+
+.PHONY: clean
+
+clean:
+ rm -rf *.o libalert_control.so
diff --git a/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.c b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.c
new file mode 100644
index 0000000..81b0329
--- /dev/null
+++ b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.c
@@ -0,0 +1,117 @@
+/*
+ *
+ * Copyright 2014-present Facebook. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <syslog.h>
+#include "alert_control.h"
+
+#define PATH_ALERT_STATUS "/sys/bus/i2c/drivers/panther_plus/4-0040/alert_status"
+#define PATH_ALERT_CONTROL "/sys/bus/i2c/drivers/panther_plus/4-0040/alert_control"
+
+#define MASK_ALERT_SMS_KCS 0x01
+
+/*
+ * Function to enable/disable alert signal generation for a given Function Block
+ */
+int
+alert_control(e_fbid_t id, e_flag_t cflag) {
+ FILE *fp;
+ unsigned char rbuf[5] = {0};
+ unsigned char tbuf[3] = {0};
+ int count = 0;
+
+ fp = fopen(PATH_ALERT_CONTROL, "r+");
+ if (!fp) {
+ return -1;
+ }
+
+ count = fread(rbuf, sizeof(unsigned char), sizeof(rbuf), fp);
+ if (count == 0x0) {
+ fclose(fp);
+ return -1;
+ }
+
+ // Size of the request
+ tbuf[0] = 0x02;
+
+ switch(id) {
+ case FBID_SMS_KCS:
+ if (cflag == FLAG_ENABLE)
+ tbuf[1] = rbuf[2] | (0x01 << FBID_SMS_KCS);
+ else
+ tbuf[1] = rbuf[2] & (~(0x01 << FBID_SMS_KCS));
+
+ tbuf[2] = rbuf[3];
+ break;
+ // TODO: Add logic for other Function Blocks here
+ default:
+ tbuf[0] = rbuf[2];
+ tbuf[1] = rbuf[3];
+ break;
+ }
+
+ count = fwrite(tbuf, sizeof(unsigned char), sizeof(tbuf), fp);
+ if (count != sizeof(tbuf)) {
+ fclose(fp);
+ return (-1);
+ }
+
+ fclose(fp);
+
+ return 0;
+}
+
+/*
+ * Function to check if the alert for a given Function Block is asserted or not
+ */
+bool
+is_alert_present(e_fbid_t id) {
+ FILE *fp;
+ unsigned char buf[5] = {0};
+ int count = 0;
+
+ fp = fopen(PATH_ALERT_STATUS, "r");
+
+ if (!fp) {
+ return false;
+ }
+
+ count = fread(buf, sizeof(unsigned char), sizeof(buf), fp);
+ if (count == 0x0) {
+ fclose(fp);
+ sleep(2);
+ return false;
+ }
+
+ fclose(fp);
+
+ switch(id) {
+ case FBID_SMS_KCS:
+ if (buf[2] & (0x01 << FBID_SMS_KCS))
+ return true;
+ else
+ return false;
+ //TODO: Add logic for other Function Blocks here
+ default:
+ return false;
+ }
+}
diff --git a/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.h b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.h
new file mode 100644
index 0000000..ca72591
--- /dev/null
+++ b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/alert_control/alert_control.h
@@ -0,0 +1,64 @@
+/*
+ *
+ * Copyright 2014-present Facebook. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __ALERT_CONTROL_H__
+#define __ALERT_CONTROL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdbool.h>
+
+typedef enum {
+ FLAG_DISABLE = 0x00,
+ FLAG_ENABLE,
+} e_flag_t;
+
+typedef enum {
+ FBID_SMS_KCS = 0x00,
+ FBID_SMM_KCS,
+ FBID_COM1_DATA,
+ FBID_COM2_DATA,
+ FBID_COM1_STAT_CTRL,
+ FBID_COM2_STAT_CTRL,
+ FBID_POST,
+ FBID_I2C_PROXY1_MASTER,
+ FBID_I2C_PROXY1_STAT,
+ FBID_I2C_PROXY2_MASTER,
+ FBID_I2C_PROXY2_STAT,
+ FBID_GPIO_CONFIG,
+ FBID_GPIO_OUTPUT,
+ FBID_GPIO_INPUT,
+ FBID_GPIO_INTR,
+ FBID_GPIO_EVENT,
+ FBID_REG_READ,
+ FBID_ALERT_CTRL = 0xFD,
+ FBID_AERT_STAT = 0xFE,
+ FBID_DISCOVERY = 0xFF,
+} e_fbid_t;
+
+int alert_control(e_fbid_t id, e_flag_t cflag);
+bool is_alert_present(e_fbid_t id);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif /* __ALERT_CONTROL_H__ */
diff --git a/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/Makefile b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/Makefile
new file mode 100644
index 0000000..8cb69e7
--- /dev/null
+++ b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/Makefile
@@ -0,0 +1,11 @@
+# Copyright 2014-present Facebook. All Rights Reserved.
+lib: libipmi.so
+
+libipmi.so: ipmi.c
+ $(CC) $(CCFLAGS) -fPIC -c -o ipmi.o ipmi.c
+ $(CC) -shared -o libipmi.so ipmi.o -lc
+
+.PHONY: clean
+
+clean:
+ rm -rf *.o libipmi.so
diff --git a/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/ipmi.c b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/ipmi.c
new file mode 100644
index 0000000..b5a3e19
--- /dev/null
+++ b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/ipmi.c
@@ -0,0 +1,81 @@
+/*
+ *
+ * Copyright 2014-present Facebook. All Rights Reserved.
+ *
+ * This file contains code to support IPMI2.0 Specificaton available @
+ * http://www.intel.com/content/www/us/en/servers/ipmi/ipmi-specifications.html
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "ipmi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <syslog.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#define SOCK_PATH "/tmp/ipmi_socket"
+#define MAX_IPMI_RES_LEN 100
+
+/*
+ * Function to handle IPMI messages
+ */
+void
+ipmi_handle(unsigned char *request, unsigned char req_len,
+ unsigned char *response, unsigned char *res_len) {
+
+ int s, t, len;
+ struct sockaddr_un remote;
+
+ // TODO: Need to update to reuse the socket instead of creating new
+ if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
+ syslog(LOG_ALERT, "ipmi_handle: socket() failed\n");
+ return;
+ }
+
+ remote.sun_family = AF_UNIX;
+ strcpy(remote.sun_path, SOCK_PATH);
+ len = strlen(remote.sun_path) + sizeof(remote.sun_family);
+
+ if (connect(s, (struct sockaddr *)&remote, len) == -1) {
+ syslog(LOG_ALERT, "ipmi_handle: connect() failed\n");
+ return;
+ }
+
+ if (send(s, request, req_len, 0) == -1) {
+ syslog(LOG_ALERT, "ipmi_handle: send() failed\n");
+ return;
+ }
+
+ if ((t=recv(s, response, MAX_IPMI_RES_LEN, 0)) > 0) {
+ *res_len = t;
+ } else {
+ if (t < 0) {
+ syslog(LOG_ALERT, "ipmi_handle: recv() failed\n");
+ } else {
+ printf("Server closed connection");
+ }
+
+ return;
+ }
+
+ close(s);
+
+ return;
+}
diff --git a/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/ipmi.h b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/ipmi.h
new file mode 100644
index 0000000..4c6ed62
--- /dev/null
+++ b/meta-facebook/meta-wedge/recipes-wedge/fblibs/files/ipmi/ipmi.h
@@ -0,0 +1,35 @@
+/*
+ *
+ * Copyright 2014-present Facebook. All Rights Reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __IPMI_H__
+#define __IPMI_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void ipmi_handle(unsigned char *request, unsigned char req_len,
+ unsigned char *response, unsigned char *res_len);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif /* __IPMI_H__ */
OpenPOWER on IntegriCloud