meta-ibm: network: Split ncsi-netlink service
Since P9 systems need only to stop the link failover, and P10 systems
need only to set the gigabit link speed, split the nsci-netlink
service into two and make it per-interface. Use the systemd network
check to make sure the link is up first. Use a helper script to fetch
the ifindex for the network interface
Signed-off-by: Eddie James <eajames@us.ibm.com>
Change-Id: I6558787a2234575b528864bb71705964a63c0498
diff --git a/meta-ibm/recipes-phosphor/network/network/ibm-ac-server/ncsi-netlink.service b/meta-ibm/recipes-phosphor/network/network/ibm-ac-server/ncsi-netlink.service
deleted file mode 100644
index 890551e..0000000
--- a/meta-ibm/recipes-phosphor/network/network/ibm-ac-server/ncsi-netlink.service
+++ /dev/null
@@ -1,12 +0,0 @@
-[Unit]
-Description=Stop the ethernet link failover
-After=network.service
-
-[Service]
-Restart=no
-ExecStart=/usr/bin/env ncsi-netlink --set -x 2 -p 0 -c 0
-SyslogIdentifier=ncsi-netlink
-Type=oneshot
-
-[Install]
-WantedBy=multi-user.target
diff --git a/meta-ibm/recipes-phosphor/network/network/mihawk/ncsi-netlink.service b/meta-ibm/recipes-phosphor/network/network/mihawk/ncsi-netlink.service
deleted file mode 100644
index 890551e..0000000
--- a/meta-ibm/recipes-phosphor/network/network/mihawk/ncsi-netlink.service
+++ /dev/null
@@ -1,12 +0,0 @@
-[Unit]
-Description=Stop the ethernet link failover
-After=network.service
-
-[Service]
-Restart=no
-ExecStart=/usr/bin/env ncsi-netlink --set -x 2 -p 0 -c 0
-SyslogIdentifier=ncsi-netlink
-Type=oneshot
-
-[Install]
-WantedBy=multi-user.target
diff --git a/meta-ibm/recipes-phosphor/network/network/ncsi-failover@.service b/meta-ibm/recipes-phosphor/network/network/ncsi-failover@.service
new file mode 100644
index 0000000..3f674d0
--- /dev/null
+++ b/meta-ibm/recipes-phosphor/network/network/ncsi-failover@.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=Stop %i link failover
+After=network.target
+
+[Service]
+Restart=no
+ExecCondition=/lib/systemd/systemd-networkd-wait-online --timeout 30 -i %i
+ExecStart=/usr/libexec/ncsi-netlink-ifindex %i --set -p 0 -c 0
+SyslogIdentifier=nsci-failover
+Type=oneshot
+
+[Install]
+WantedBy=network.target
diff --git a/meta-ibm/recipes-phosphor/network/network/ncsi-linkspeed@.service b/meta-ibm/recipes-phosphor/network/network/ncsi-linkspeed@.service
new file mode 100644
index 0000000..00bce85
--- /dev/null
+++ b/meta-ibm/recipes-phosphor/network/network/ncsi-linkspeed@.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=Set %i gigabit link speed
+After=network.target
+
+[Service]
+Restart=no
+ExecCondition=/lib/systemd/systemd-networkd-wait-online --timeout 30 -i %i
+# package 0, channel 0, oem command, see Intel I210 datasheet section 10.6.3.10.1
+ExecStart=/usr/libexec/ncsi-netlink-ifindex %i -p 0 -c 0 -o 00000157200001
+SyslogIdentifier=nsci-linkspeed
+Type=oneshot
+
+[Install]
+WantedBy=network.target
diff --git a/meta-ibm/recipes-phosphor/network/network/ncsi-netlink-ifindex b/meta-ibm/recipes-phosphor/network/network/ncsi-netlink-ifindex
new file mode 100644
index 0000000..9b9b748
--- /dev/null
+++ b/meta-ibm/recipes-phosphor/network/network/ncsi-netlink-ifindex
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+IFPATH="/sys/class/net/$1/ifindex"
+
+if [ ! -f "${IFPATH}" ]
+then
+ echo Error: "${IFPATH}" does not exist 1>&2
+ exit 2
+fi
+
+shift
+ncsi-netlink -x "$(cat "${IFPATH}")" "$@"
diff --git a/meta-ibm/recipes-phosphor/network/network/p10bmc/ncsi-netlink.service b/meta-ibm/recipes-phosphor/network/network/p10bmc/ncsi-netlink.service
deleted file mode 100644
index 890551e..0000000
--- a/meta-ibm/recipes-phosphor/network/network/p10bmc/ncsi-netlink.service
+++ /dev/null
@@ -1,12 +0,0 @@
-[Unit]
-Description=Stop the ethernet link failover
-After=network.service
-
-[Service]
-Restart=no
-ExecStart=/usr/bin/env ncsi-netlink --set -x 2 -p 0 -c 0
-SyslogIdentifier=ncsi-netlink
-Type=oneshot
-
-[Install]
-WantedBy=multi-user.target
diff --git a/meta-ibm/recipes-phosphor/network/network/witherspoon-tacoma/ncsi-netlink.service b/meta-ibm/recipes-phosphor/network/network/witherspoon-tacoma/ncsi-netlink.service
deleted file mode 100644
index 890551e..0000000
--- a/meta-ibm/recipes-phosphor/network/network/witherspoon-tacoma/ncsi-netlink.service
+++ /dev/null
@@ -1,12 +0,0 @@
-[Unit]
-Description=Stop the ethernet link failover
-After=network.service
-
-[Service]
-Restart=no
-ExecStart=/usr/bin/env ncsi-netlink --set -x 2 -p 0 -c 0
-SyslogIdentifier=ncsi-netlink
-Type=oneshot
-
-[Install]
-WantedBy=multi-user.target
diff --git a/meta-ibm/recipes-phosphor/network/phosphor-network_%.bbappend b/meta-ibm/recipes-phosphor/network/phosphor-network_%.bbappend
index 0aee776..7f2ef91 100644
--- a/meta-ibm/recipes-phosphor/network/phosphor-network_%.bbappend
+++ b/meta-ibm/recipes-phosphor/network/phosphor-network_%.bbappend
@@ -1,18 +1,46 @@
FILESEXTRAPATHS:prepend := "${THISDIR}/network:"
-SRC_URI += " file://ncsi-netlink.service"
-SYSTEMD_SERVICE:${PN} += " ncsi-netlink.service"
+inherit obmc-phosphor-systemd
+
+OBMC_NETWORK_INTERFACES ?= "eth0"
+OBMC_NETWORK_INTERFACES:append:p10bmc = " eth1"
+
+FAILOVER_TMPL = "ncsi-failover@.service"
+LINKSPEED_TMPL = "ncsi-linkspeed@.service"
+
+SRC_URI += " file://ncsi-netlink-ifindex"
+SRC_URI:append:ibm-ac-server = " file://${FAILOVER_TMPL}"
+SRC_URI:append:mihawk = " file://${FAILOVER_TMPL}"
+SRC_URI:append:p10bmc = " file://${LINKSPEED_TMPL}"
+
+SYSTEMD_SERVICE:${PN}:append:ibm-ac-server = " ${FAILOVER_TMPL}"
+SYSTEMD_SERVICE:${PN}:append:mihawk = " ${FAILOVER_TMPL}"
+SYSTEMD_SERVICE:${PN}:append:p10bmc = " ${LINKSPEED_TMPL}"
+
+FAILOVER_TGTFMT = "ncsi-failover@{0}.service"
+LINKSPEED_TGTFMT = "ncsi-linkspeed@{0}.service"
+FAILOVER_FMT = "../${FAILOVER_TMPL}:network.target.wants/${FAILOVER_TGTFMT}"
+LINKSPEED_FMT = "../${LINKSPEED_TMPL}:network.target.wants/${LINKSPEED_TGTFMT}"
+
+SYSTEMD_LINK:${PN}:append:ibm-ac-server = "${@compose_list(d, 'FAILOVER_FMT', 'OBMC_NETWORK_INTERFACES')}"
+SYSTEMD_LINK:${PN}:append:mihawk = "${@compose_list(d, 'FAILOVER_FMT', 'OBMC_NETWORK_INTERFACES')}"
+SYSTEMD_LINK:${PN}:append:p10bmc = "${@compose_list(d, 'LINKSPEED_FMT', 'OBMC_NETWORK_INTERFACES')}"
+
+FILES:${PN} += "${libexecdir}/ncsi-netlink-ifindex"
FILES:${PN} += "${datadir}/network/*.json"
PACKAGECONFIG:append = " sync-mac"
install_network_configuration(){
- install -d ${D}${systemd_system_unitdir}
- install -m 0644 ${WORKDIR}/ncsi-netlink.service ${D}${systemd_system_unitdir}
install -d ${D}${datadir}/network/
install -m 0644 ${WORKDIR}/inventory-object-map.json ${D}${datadir}/network/config.json
}
+do_install:append() {
+ install -d ${D}${libexecdir}
+ install -m 0755 ${WORKDIR}/ncsi-netlink-ifindex ${D}${libexecdir}
+}
+
SRC_URI:append:p10bmc = " file://inventory-object-map.json"
do_install:append:p10bmc(){
install_network_configuration