meta-facebook: harma: Add MCTP PLDM support
Add MCTP PLDM support for PSOC sensor readings and
firmware update.
Testing:
root@bmc:~# busctl tree xyz.openbmc_project.MCTP
└─ /xyz
└─ /xyz/openbmc_project
└─ /xyz/openbmc_project/mctp
└─ /xyz/openbmc_project/mctp/1
├─ /xyz/openbmc_project/mctp/1/10
└─ /xyz/openbmc_project/mctp/1/8
root@bmc:~# pldmtool raw -d 0x80 0x05 0x02 -m 0x0a
pldmtool: Tx: 80 05 02
pldmtool: Rx: 00 05 02 00 00 00 00 00 07 00 01 0a
00 00 32 30 32 33 2e 34 38 2e 30 31 ff ff 00 00 00
00 00 00 00 01 0c 00 00 00 00 00 00 00 00 00 00 00
00 01 00 00 00 00 00 00 00 00 00 20 00 00 00 00 00
4d 50 53 20 33 64 65 37 34 39 62 61 ff ff 01 00 00
00 00 00 00 01 0c 00 00 00 00 00 00 00 00 00 00 00
00 01 00 00 00 00 00 00 00 00 00 20 00 00 00 00 00
4d 50 53 20 33 64 65 37 34 39 62 61 ff ff 03 00 00
00 00 00 00 01 07 00 00 00 00 00 00 00 00 00 00 00
00 01 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00
45 52 52 4f 52 3a 38 ff ff 04 00 00 00 00 00 00 01
07 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00
00 00 00 00 00 00 10 00 00 00 00 00 45 52 52 4f 52
3a 38 ff ff 05 00 00 00 00 00 00 01 07 00 00 00 00
00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00
00 10 00 00 00 00 00 45 52 52 4f 52 3a 38 ff ff 06
00 00 00 00 00 00 01 07 00 00 00 00 00 00 00 00 00
00 00 00 01 00 00 00 00 00 00 00 00 00 10 00 00 00
00 00 45 52 52 4f 52 3a 38 ff ff 07 00 00 00 00 00
00 01 08 00 00 00 00 00 00 00 00 00 00 00 00 01 00
00 00 00 00 00 00 00 00 20 00 00 00 00 00 30 30 30
32 30 30 30 31
Change-Id: Ib375325b49ddf6759785d079790c72581db668b5
Signed-off-by: Daniel Hsu <Daniel-Hsu@quantatw.com>
diff --git a/meta-facebook/meta-harma/conf/machine/harma.conf b/meta-facebook/meta-harma/conf/machine/harma.conf
index 3beb5e1..2454694 100644
--- a/meta-facebook/meta-harma/conf/machine/harma.conf
+++ b/meta-facebook/meta-harma/conf/machine/harma.conf
@@ -12,6 +12,7 @@
OBMC_COMPATIBLE_NAMES = "com.meta.Hardware.BMC.Model.Harma"
require conf/distro/include/phosphor-static-norootfs.inc
+require conf/distro/include/pldm.inc
require conf/machine/include/facebook-compute-singlehost.inc
require conf/machine/include/ast2600.inc
require conf/machine/include/obmc-bsp-common.inc
diff --git a/meta-facebook/meta-harma/recipes-kernel/linux/linux-aspeed/harma.cfg b/meta-facebook/meta-harma/recipes-kernel/linux/linux-aspeed/harma.cfg
index c49f3f8..1298b63 100644
--- a/meta-facebook/meta-harma/recipes-kernel/linux/linux-aspeed/harma.cfg
+++ b/meta-facebook/meta-harma/recipes-kernel/linux/linux-aspeed/harma.cfg
@@ -80,3 +80,8 @@
# SPI GPIO
CONFIG_SPI_GPIO=y
+
+# I2C mqueue for mctp
+CONFIG_I2C_SLAVE_MQUEUE=m
+CONFIG_I2C_SLAVE_MQUEUE_QUEUE_SIZE=32
+CONFIG_I2C_SLAVE_MQUEUE_MESSAGE_SIZE=256
diff --git a/meta-facebook/meta-harma/recipes-networking/mctp/files/setup-bic-eid b/meta-facebook/meta-harma/recipes-networking/mctp/files/setup-bic-eid
new file mode 100644
index 0000000..da51310
--- /dev/null
+++ b/meta-facebook/meta-harma/recipes-networking/mctp/files/setup-bic-eid
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+# Set BIC EID
+bic_addr=0x20
+busnum=9
+maxRetries=10
+retryInterval=1
+
+retry_command() {
+
+ command="$1"
+ retries=0
+
+ while [ $retries -lt $maxRetries ]; do
+ if bash -c "$command"; then
+ return 0
+ else
+ retries=$((retries + 1))
+ echo "Retry $retries/$maxRetries: Command failed. Retrying in $retryInterval seconds..."
+ sleep $retryInterval
+ fi
+ done
+
+ return 1
+}
+
+command="
+ busctl call xyz.openbmc_project.MCTP \
+ /xyz/openbmc_project/mctp \
+ au.com.CodeConstruct.MCTP \
+ LearnEndpoint \
+ say mctpi2c${busnum} 1 ${bic_addr}"
+
+if ! retry_command "$command"; then
+ echo "Failed to busctl call after $maxRetries attempts."
+ exit 1
+fi
+echo "BIC EID set to ${bic_addr}"
+exit 0
\ No newline at end of file
diff --git a/meta-facebook/meta-harma/recipes-networking/mctp/files/setup-eid.conf b/meta-facebook/meta-harma/recipes-networking/mctp/files/setup-eid.conf
new file mode 100644
index 0000000..d936d30
--- /dev/null
+++ b/meta-facebook/meta-harma/recipes-networking/mctp/files/setup-eid.conf
@@ -0,0 +1,9 @@
+[Unit]
+After=mctpd.service
+Requires=mctpd.service
+
+[Service]
+ExecStartPre=-/usr/share/mctp/setup-local-eid
+ExecStartPost=-/usr/share/mctp/setup-bic-eid
+Restart=always
+RestartSec=10
\ No newline at end of file
diff --git a/meta-facebook/meta-harma/recipes-networking/mctp/files/setup-local-eid b/meta-facebook/meta-harma/recipes-networking/mctp/files/setup-local-eid
new file mode 100644
index 0000000..a72606f
--- /dev/null
+++ b/meta-facebook/meta-harma/recipes-networking/mctp/files/setup-local-eid
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+# Set mctpi2c link up and assign local address.
+localEid=8
+busNum=9
+maxRetries=5
+retryInterval=1
+
+retry_command() {
+
+ command="$1"
+ retries=0
+
+ while [ $retries -lt $maxRetries ]; do
+ if bash -c "$command"; then
+ return 0
+ else
+ retries=$((retries + 1))
+ echo "Retry $retries/$maxRetries: Command failed. Retrying in $retryInterval seconds..."
+ sleep $retryInterval
+ fi
+ done
+
+ return 1
+}
+
+# Retry mctp link command
+if ! retry_command "mctp link set mctpi2c${busNum} up"; then
+ echo "Failed to set mctp link after $maxRetries attempts."
+ exit 1
+fi
+
+# Check if local EID is already set
+mctpOutput=$(mctp address show)
+if echo "$mctpOutput" | grep -q "mctpi2c${busNum}"; then
+ echo "mctpi2c${busNum} local EID already set"
+else
+ # Retry mctp addr add command
+ if ! retry_command "mctp addr add ${localEid} dev mctpi2c${busNum}"; then
+ echo "Failed to add mctp address after $maxRetries attempts."
+ exit 1
+ fi
+fi
+echo "mctpi2c${busNum} local EID set to ${localEid}"
+exit 0
\ No newline at end of file
diff --git a/meta-facebook/meta-harma/recipes-networking/mctp/mctp_%.bbappend b/meta-facebook/meta-harma/recipes-networking/mctp/mctp_%.bbappend
new file mode 100644
index 0000000..58af028
--- /dev/null
+++ b/meta-facebook/meta-harma/recipes-networking/mctp/mctp_%.bbappend
@@ -0,0 +1,25 @@
+FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
+
+
+SRC_URI += " \
+ file://setup-eid.conf \
+ file://setup-local-eid \
+ file://setup-bic-eid \
+"
+
+RDEPENDS:${PN} += " bash"
+FILES:${PN} += "${systemd_system_unitdir}/*"
+
+do_install:append () {
+ override_dir=${D}${systemd_system_unitdir}/mctpd.service.d
+ install -d ${D}${systemd_system_unitdir}/mctpd.service.d
+ install -d ${D}${datadir}/mctp
+
+ install -m 0644 ${WORKDIR}/setup-eid.conf \
+ ${override_dir}/setup-eid.conf
+
+ install -m 0755 ${WORKDIR}/setup-local-eid \
+ ${D}${datadir}/mctp/
+ install -m 0755 ${WORKDIR}/setup-bic-eid \
+ ${D}${datadir}/mctp/
+}