astlpc: Ship udev rules to help with device and driver transition
Currently the OpenBMC kernel has a hacky device driver at
drivers/char/misc/mctp-lpc.c that only works against KCS channel 4 on
Aspeed BMCs. This hacky driver exposes an `mctp0` device node.
The intent is to replace it with one that is slightly less
hacky at drivers/char/ipmi/kcs_bmc_cdev_raw.c[1], though eventually this
too will be replaced by an in-kernel implementation of the entire LPC
MCTP binding.
kcs_bmc_dev_raw.c works against all KCS devices in both Aspeed and
Nuvoton BMC SoCs.
We need to move away from KCS channel 4 on the Aspeed BMCs as the way
the hardware initialises the status bits conflicts with the protocol
definition for the LPC MCTP binding[2].
Kill two birds with one stone by shipping udev rules that accomodate the
new device node names that come with kcs_bmc_dev_raw.c, and symlink them
upon creation to /dev/mctp0 to emulate the original mctp-lpc.c
interface.
[1] https://lore.kernel.org/openbmc/20210510064955.1704652-1-andrew@aj.id.au/T/#me02d9a0e6ce82c9e0602cd615ccdad66d242af87
[2] https://github.com/openbmc/libmctp/blob/eba19a3b122a39ef2b5dbda49b418a202f78a48d/docs/bindings/vendor-ibm-astlpc.md#kcs-status-register-layout
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I21446936cea6c5e4024ec6536ad5983dd360deb2
diff --git a/Makefile.am b/Makefile.am
index fc8e937..6011a8e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -26,6 +26,11 @@
pkgconfig_DATA = libmctp.pc
+if LIBMCTP_UDEV_RAW_KCS
+udevrules_DATA = udev/rules.d/mctp0-raw-kcs3.rules \
+ udev/rules.d/mctp0-raw-kcs4.rules
+endif
+
if AUTOCONF_CODE_COVERAGE_2019_01_06
include $(top_srcdir)/aminclude_static.am
clean-local: code-coverage-clean
diff --git a/configure.ac b/configure.ac
index eaa9b7e..c66458c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,6 +21,16 @@
# pkg-config
PKG_PROG_PKG_CONFIG
PKG_INSTALLDIR
+PKG_CHECK_MODULES(udev,
+ udev,
+ [PKG_CHECK_VAR(udevrulesdir, udev, udevdir)],
+ [])
+
+AC_ARG_ENABLE([astlpc-raw-kcs],
+ [AS_HELP_STRING([--enable-astlpc-raw-kcs],
+ [Use udev rules to symlink raw-kcs device nodes for the astlpc binding])])
+AM_CONDITIONAL([LIBMCTP_UDEV_RAW_KCS], [test -n "$udevrulesdir" -a "x$enable_astlpc_raw_kcs" = "xyes"])
+
AC_ARG_WITH([systemdsystemunitdir],
[AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files])],
[],
@@ -143,5 +153,6 @@
[AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [false])])
AX_ADD_AM_MACRO_STATIC([])
-AC_CONFIG_FILES([Makefile libmctp.pc])
+AC_CONFIG_FILES([Makefile libmctp.pc udev/rules.d/mctp0-raw-kcs3.rules
+ udev/rules.d/mctp0-raw-kcs4.rules])
AC_OUTPUT
diff --git a/udev/rules.d/mctp0-raw-kcs3.rules.in b/udev/rules.d/mctp0-raw-kcs3.rules.in
new file mode 100644
index 0000000..bf4a76f
--- /dev/null
+++ b/udev/rules.d/mctp0-raw-kcs3.rules.in
@@ -0,0 +1 @@
+ACTION=="add", DEVPATH=="/devices/virtual/misc/raw-kcs3", SUBSYSTEM=="misc", SYMLINK+="mctp0"
diff --git a/udev/rules.d/mctp0-raw-kcs4.rules.in b/udev/rules.d/mctp0-raw-kcs4.rules.in
new file mode 100644
index 0000000..1df8e9f
--- /dev/null
+++ b/udev/rules.d/mctp0-raw-kcs4.rules.in
@@ -0,0 +1 @@
+ACTION=="add", DEVPATH=="/devices/virtual/misc/raw-kcs4", SUBSYSTEM=="misc", SYMLINK+="mctp0"