summaryrefslogtreecommitdiffstats
path: root/meta-facebook/meta-yosemite/recipes-yosemite/bic-cached/files
diff options
context:
space:
mode:
Diffstat (limited to 'meta-facebook/meta-yosemite/recipes-yosemite/bic-cached/files')
-rw-r--r--meta-facebook/meta-yosemite/recipes-yosemite/bic-cached/files/Makefile10
-rw-r--r--meta-facebook/meta-yosemite/recipes-yosemite/bic-cached/files/bic-cached.c133
-rw-r--r--meta-facebook/meta-yosemite/recipes-yosemite/bic-cached/files/setup-bic-cached.sh33
3 files changed, 176 insertions, 0 deletions
diff --git a/meta-facebook/meta-yosemite/recipes-yosemite/bic-cached/files/Makefile b/meta-facebook/meta-yosemite/recipes-yosemite/bic-cached/files/Makefile
new file mode 100644
index 0000000..478b25e
--- /dev/null
+++ b/meta-facebook/meta-yosemite/recipes-yosemite/bic-cached/files/Makefile
@@ -0,0 +1,10 @@
+# Copyright 2015-present Facebook. All Rights Reserved.
+all: bic-cached
+
+bic-cached: bic-cached.c
+ $(CC) -pthread -lbic -std=c99 -o $@ $^ $(LDFLAGS)
+
+.PHONY: clean
+
+clean:
+ rm -rf *.o bic-cached
diff --git a/meta-facebook/meta-yosemite/recipes-yosemite/bic-cached/files/bic-cached.c b/meta-facebook/meta-yosemite/recipes-yosemite/bic-cached/files/bic-cached.c
new file mode 100644
index 0000000..3a2dd28
--- /dev/null
+++ b/meta-facebook/meta-yosemite/recipes-yosemite/bic-cached/files/bic-cached.c
@@ -0,0 +1,133 @@
+/*
+ *
+ * Copyright 2015-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 <string.h>
+#include <pthread.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <openbmc/ipmi.h>
+#include <openbmc/ipmb.h>
+#include <facebook/bic.h>
+
+#define LAST_RECORD_ID 0xFFFF
+#define MAX_SENSOR_NUM 0xFF
+#define BYTES_ENTIRE_RECORD 0xFF
+
+void
+fruid_cache_init(uint8_t slot_id) {
+ // Initialize Slot0's fruid
+ int ret;
+ int i;
+ char fruid_temp_path[64] = {0};
+ char fruid_path[64] = {0};
+
+ sprintf(fruid_temp_path, "/tmp/tfruid_slot%d.bin", slot_id);
+ sprintf(fruid_path, "/tmp/fruid_slot%d.bin", slot_id);
+
+ ret = bic_read_fruid(slot_id, 0, fruid_temp_path);
+ if (ret) {
+ syslog(LOG_ALERT, "fruid_cache_init: bic_read_fruid returns %d\n", ret);
+ }
+
+ rename(fruid_temp_path, fruid_path);
+
+ return;
+}
+
+void
+sdr_cache_init(uint8_t slot_id) {
+ int ret;
+ int fd;
+ uint8_t rlen;
+ uint8_t rbuf[MAX_IPMB_RES_LEN] = {0};
+ char *path = NULL;
+ char sdr_temp_path[64] = {0};
+ char sdr_path[64] = {0};
+
+ sprintf(sdr_temp_path, "/tmp/tsdr_slot%d.bin", slot_id);
+ sprintf(sdr_path, "/tmp/sdr_slot%d.bin", slot_id);
+
+ ipmi_sel_sdr_req_t req;
+ ipmi_sel_sdr_res_t *res = (ipmi_sel_sdr_res_t *) rbuf;
+
+ req.rsv_id = 0;
+ req.rec_id = 0;
+ req.offset = 0;
+ req.nbytes = BYTES_ENTIRE_RECORD;
+
+ // Read Slot0's SDR records and store
+ path = sdr_temp_path;
+ unlink(path);
+ fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0666);
+ if (fd < 0) {
+ syslog(LOG_ALERT, "sdr_cache_init: open fails for path: %s\n", path);
+ return;
+ }
+
+ while (1) {
+ ret = bic_get_sdr(slot_id, &req, res, &rlen);
+ if (ret) {
+ syslog(LOG_ALERT, "sdr_cache_init:bic_get_sdr returns %d\n", ret);
+ continue;
+ }
+
+ sdr_full_t *sdr = res->data;
+
+ write(fd, sdr, sizeof(sdr_full_t));
+
+ req.rec_id = res->next_rec_id;
+ if (req.rec_id == LAST_RECORD_ID) {
+ // syslog(LOG_INFO, "This record is LAST record\n");
+ break;
+ }
+ }
+
+ rename(sdr_temp_path, sdr_path);
+}
+
+int
+main (int argc, char * const argv[])
+{
+ int ret;
+ ipmi_dev_id_t id = {0};
+ uint8_t slot_id;
+
+ if (argc != 2) {
+ return -1;
+ }
+
+ slot_id = atoi(argv[1]);
+
+ do {
+ ret = bic_get_dev_id(slot_id, &id);
+ sleep(5);
+ } while (ret != 0);
+
+ fruid_cache_init(slot_id);
+ sdr_cache_init(slot_id);
+
+ return 0;
+}
diff --git a/meta-facebook/meta-yosemite/recipes-yosemite/bic-cached/files/setup-bic-cached.sh b/meta-facebook/meta-yosemite/recipes-yosemite/bic-cached/files/setup-bic-cached.sh
new file mode 100644
index 0000000..45eb1e3
--- /dev/null
+++ b/meta-facebook/meta-yosemite/recipes-yosemite/bic-cached/files/setup-bic-cached.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# Copyright 2015-present Facebook. All Rights Reserved.
+#
+### BEGIN INIT INFO
+# Provides: setup-bic-cached
+# Required-Start:
+# Required-Stop:
+# Default-Start: S
+# Default-Stop:
+# Short-Description: Set Cachcing for Bridge IC info
+### END INIT INFO
+
+. /usr/local/fbpackages/utils/ast-functions
+
+echo -n "Setup Caching for Bridge IC info.."
+if [ $(is_server_prsnt 1) == "1" ]; then
+ /usr/local/bin/bic-cached 1 > /dev/null 2>&1 &
+fi
+
+if [ $(is_server_prsnt 2) == "1" ]; then
+/usr/local/bin/bic-cached 2 > /dev/null 2>&1 &
+fi
+
+if [ $(is_server_prsnt 3) == "1" ]; then
+/usr/local/bin/bic-cached 3 > /dev/null 2>&1 &
+fi
+
+if [ $(is_server_prsnt 4) == "1" ]; then
+/usr/local/bin/bic-cached 4 > /dev/null 2>&1 &
+fi
+
+echo "done."
OpenPOWER on IntegriCloud