All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH linux dev-5.10 v2 0/7] Rework use of KCS devices for P10 platforms
@ 2021-06-23  3:38 Andrew Jeffery
  2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 1/7] ipmi: kcs_bmc_aspeed: Fix less than zero comparison of a unsigned int Andrew Jeffery
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Andrew Jeffery @ 2021-06-23  3:38 UTC (permalink / raw)
  To: joel; +Cc: openbmc

Hello,

v2 of this series rebases against the tip of dev-5.10 and fixes up the "nobody
cared" warning identified in the raw chardev implementation from v1.

The v1 series can be found here with a complete outline of the motivations and
benefits:

https://lore.kernel.org/openbmc/20210618035858.4024689-1-andrew@aj.id.au/

Please review!

Andrew

Andrew Jeffery (6):
  ipmi: kcs_bmc: Add a "raw" character device interface
  ARM: configs: Enable IPMI KCS raw chardev
  ARM: dts: p10bmc: Drop the openbmc,mctp-lpc node
  misc: Remove obsolete mctp-lpc chardev
  ARM: dts: p10bmc: Switch to KCS 3 for MCTP binding
  ARM: dts: p10bmc: Enable KCS channel 2

Colin Ian King (1):
  ipmi: kcs_bmc_aspeed: Fix less than zero comparison of a unsigned int

 Documentation/ABI/testing/dev-raw-kcs        |  25 ++
 arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts |  16 +-
 arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts |  16 +-
 arch/arm/configs/aspeed_g5_defconfig         |   2 +-
 drivers/char/ipmi/Kconfig                    |  17 +
 drivers/char/ipmi/Makefile                   |   1 +
 drivers/char/ipmi/kcs_bmc_aspeed.c           |   8 +-
 drivers/char/ipmi/kcs_bmc_cdev_raw.c         | 447 +++++++++++++++++++
 drivers/misc/Kconfig                         |   7 -
 drivers/misc/Makefile                        |   1 -
 drivers/misc/mctp-lpc.c                      | 443 ------------------
 11 files changed, 518 insertions(+), 465 deletions(-)
 create mode 100644 Documentation/ABI/testing/dev-raw-kcs
 create mode 100644 drivers/char/ipmi/kcs_bmc_cdev_raw.c
 delete mode 100644 drivers/misc/mctp-lpc.c

-- 
2.30.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH linux dev-5.10 v2 1/7] ipmi: kcs_bmc_aspeed: Fix less than zero comparison of a unsigned int
  2021-06-23  3:38 [PATCH linux dev-5.10 v2 0/7] Rework use of KCS devices for P10 platforms Andrew Jeffery
@ 2021-06-23  3:38 ` Andrew Jeffery
  2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 2/7] ipmi: kcs_bmc: Add a "raw" character device interface Andrew Jeffery
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andrew Jeffery @ 2021-06-23  3:38 UTC (permalink / raw)
  To: joel; +Cc: openbmc

From: Colin Ian King <colin.king@canonical.com>

The comparisons of the unsigned int hw_type to less than zero always
false because it is unsigned. Fix this by using an int for the
assignment and less than zero check.

Addresses-Coverity: ("Unsigned compared against 0")
Fixes: 9d2df9a0ad80 ("ipmi: kcs_bmc_aspeed: Implement KCS SerIRQ configuration")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Message-Id: <20210616162913.15259-1-colin.king@canonical.com>
Signed-off-by: Corey Minyard <cminyard@mvista.com>
---
 drivers/char/ipmi/kcs_bmc_aspeed.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c b/drivers/char/ipmi/kcs_bmc_aspeed.c
index 9753ed0a5be6..b555286016b1 100644
--- a/drivers/char/ipmi/kcs_bmc_aspeed.c
+++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
@@ -301,13 +301,15 @@ static inline int aspeed_kcs_map_serirq_type(u32 dt_type)
 static int aspeed_kcs_config_upstream_irq(struct aspeed_kcs_bmc *priv, u32 id, u32 dt_type)
 {
 	unsigned int mask, val, hw_type;
+	int ret;
 
 	if (id > 15)
 		return -EINVAL;
 
-	hw_type = aspeed_kcs_map_serirq_type(dt_type);
-	if (hw_type < 0)
-		return hw_type;
+	ret = aspeed_kcs_map_serirq_type(dt_type);
+	if (ret < 0)
+		return ret;
+	hw_type = ret;
 
 	priv->upstream_irq.mode = aspeed_kcs_irq_serirq;
 	priv->upstream_irq.id = id;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH linux dev-5.10 v2 2/7] ipmi: kcs_bmc: Add a "raw" character device interface
  2021-06-23  3:38 [PATCH linux dev-5.10 v2 0/7] Rework use of KCS devices for P10 platforms Andrew Jeffery
  2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 1/7] ipmi: kcs_bmc_aspeed: Fix less than zero comparison of a unsigned int Andrew Jeffery
@ 2021-06-23  3:38 ` Andrew Jeffery
  2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 3/7] ARM: configs: Enable IPMI KCS raw chardev Andrew Jeffery
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andrew Jeffery @ 2021-06-23  3:38 UTC (permalink / raw)
  To: joel; +Cc: openbmc

The existing IPMI chardev encodes IPMI behaviours as the name suggests.
However, KCS devices are useful beyond IPMI (or keyboards), as they
provide a means to generate IRQs and exchange arbitrary data between a
BMC and its host system.

Implement a "raw" KCS character device that exposes the IDR, ODR and STR
registers to userspace via read() and write() implemented on a character
device:

+--------+--------+---------+
| Offset | read() | write() |
+--------+--------+---------+
|   0    |   IDR  |   ODR   |
+--------+--------+---------+
|   1    |   STR  |   STR   |
+--------+--------+---------+

This interface allows userspace to implement arbitrary (though somewhat
inefficient) protocols for exchanging information between a BMC and host
firmware. Conceptually the KCS interface can be used as an out-of-band
mechanism for interrupt-signaled control messages while bulk data
transfers occur over more appropriate interfaces between the BMC and the
host (which may lack their own interrupt mechanism, e.g. LPC FW cycles).

poll() is provided, which will wait for IBF or OBE conditions for data
reads and writes respectively. Reads of STR on its own never blocks,
though accessing both offsets in the one system call may block if the
data registers are not ready.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
---
 Documentation/ABI/testing/dev-raw-kcs |  25 ++
 drivers/char/ipmi/Kconfig             |  17 +
 drivers/char/ipmi/Makefile            |   1 +
 drivers/char/ipmi/kcs_bmc_cdev_raw.c  | 447 ++++++++++++++++++++++++++
 4 files changed, 490 insertions(+)
 create mode 100644 Documentation/ABI/testing/dev-raw-kcs
 create mode 100644 drivers/char/ipmi/kcs_bmc_cdev_raw.c

diff --git a/Documentation/ABI/testing/dev-raw-kcs b/Documentation/ABI/testing/dev-raw-kcs
new file mode 100644
index 000000000000..06e7e2071562
--- /dev/null
+++ b/Documentation/ABI/testing/dev-raw-kcs
@@ -0,0 +1,25 @@
+What:		/dev/raw-kcs*
+Date:		2021-02-15
+KernelVersion:	5.13
+Contact:	openbmc@lists.ozlabs.org
+Contact:	openipmi-developer@lists.sourceforge.net
+Contact:	Andrew Jeffery <andrew@aj.id.au>
+Description:	``/dev/raw-kcs*`` exposes to userspace the data and
+		status registers of Keyboard-Controller-Style (KCS) IPMI
+		interfaces via read() and write() syscalls. Direct
+		exposure of the data and status registers enables
+		inefficient but arbitrary protocols to be implemented
+		over the device. A typical approach is to use KCS
+		devices for out-of-band signalling for bulk data
+		transfers over other interfaces between a Baseboard
+		Management Controller and its host.
+
+		+--------+--------+---------+
+		| Offset | read() | write() |
+		+--------+--------+---------+
+		|   0    |   IDR  |   ODR   |
+		+--------+--------+---------+
+		|   1    |   STR  |   STR   |
+		+--------+--------+---------+
+
+Users:		libmctp: https://github.com/openbmc/libmctp
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index 249b31197eea..19f1efc0bc3d 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -151,6 +151,23 @@ config IPMI_KCS_BMC_SERIO
 	  This support is also available as a module. The module will be
 	  called kcs_bmc_serio.
 
+config IPMI_KCS_BMC_CDEV_RAW
+	depends on IPMI_KCS_BMC
+	tristate "Raw character device interface for BMC KCS devices"
+	help
+	  Provides a BMC-side character device directly exposing the
+	  data and status registers of a KCS device to userspace. While
+	  KCS devices are commonly used to implement IPMI message
+	  passing, they provide a general interface for exchange of
+	  interrupts, data and status information between the BMC and
+	  its host.
+
+	  Say YES if you wish to use the KCS devices to implement
+	  protocols that are not IPMI.
+
+	  This support is also available as a module. The module will be
+	  called kcs_bmc_cdev_raw.
+
 config ASPEED_BT_IPMI_BMC
 	depends on ARCH_ASPEED || COMPILE_TEST
 	depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 84f47d18007f..3390985b4802 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_IPMI_POWEROFF) += ipmi_poweroff.o
 obj-$(CONFIG_IPMI_KCS_BMC) += kcs_bmc.o
 obj-$(CONFIG_IPMI_KCS_BMC_SERIO) += kcs_bmc_serio.o
 obj-$(CONFIG_IPMI_KCS_BMC_CDEV_IPMI) += kcs_bmc_cdev_ipmi.o
+obj-$(CONFIG_IPMI_KCS_BMC_CDEV_RAW) += kcs_bmc_cdev_raw.o
 obj-$(CONFIG_ASPEED_BT_IPMI_BMC) += bt-bmc.o
 obj-$(CONFIG_ASPEED_KCS_IPMI_BMC) += kcs_bmc_aspeed.o
 obj-$(CONFIG_NPCM7XX_KCS_IPMI_BMC) += kcs_bmc_npcm7xx.o
diff --git a/drivers/char/ipmi/kcs_bmc_cdev_raw.c b/drivers/char/ipmi/kcs_bmc_cdev_raw.c
new file mode 100644
index 000000000000..6865628476e1
--- /dev/null
+++ b/drivers/char/ipmi/kcs_bmc_cdev_raw.c
@@ -0,0 +1,447 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) 2021 IBM Corp. */
+
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/errno.h>
+#include <linux/fs.h>
+#include <linux/list.h>
+#include <linux/miscdevice.h>
+#include <linux/module.h>
+#include <linux/poll.h>
+
+#include "kcs_bmc_client.h"
+
+#define DEVICE_NAME "raw-kcs"
+
+struct kcs_bmc_raw {
+	struct list_head entry;
+
+	struct kcs_bmc_client client;
+
+	wait_queue_head_t queue;
+	u8 events;
+	bool writable;
+	bool readable;
+	u8 idr;
+
+	struct miscdevice miscdev;
+};
+
+static inline struct kcs_bmc_raw *client_to_kcs_bmc_raw(struct kcs_bmc_client *client)
+{
+	return container_of(client, struct kcs_bmc_raw, client);
+}
+
+/* Call under priv->queue.lock */
+static void kcs_bmc_raw_update_event_mask(struct kcs_bmc_raw *priv, u8 mask, u8 state)
+{
+	kcs_bmc_update_event_mask(priv->client.dev, mask, state);
+	priv->events &= ~mask;
+	priv->events |= state & mask;
+}
+
+static irqreturn_t kcs_bmc_raw_event(struct kcs_bmc_client *client)
+{
+	struct kcs_bmc_raw *priv;
+	struct device *dev;
+	u8 status, handled;
+
+	priv = client_to_kcs_bmc_raw(client);
+	dev = priv->miscdev.this_device;
+
+	spin_lock(&priv->queue.lock);
+
+	status = kcs_bmc_read_status(client->dev);
+	handled = 0;
+
+	if ((priv->events & KCS_BMC_EVENT_TYPE_IBF) && (status & KCS_BMC_STR_IBF)) {
+		if (priv->readable)
+			dev_err(dev, "Unexpected IBF IRQ, dropping data");
+
+		dev_dbg(dev, "Disabling IDR events for back-pressure\n");
+		kcs_bmc_raw_update_event_mask(priv, KCS_BMC_EVENT_TYPE_IBF, 0);
+		priv->idr = kcs_bmc_read_data(client->dev);
+		priv->readable = true;
+
+		dev_dbg(dev, "IDR read, waking waiters\n");
+		wake_up_locked(&priv->queue);
+
+		handled |= KCS_BMC_EVENT_TYPE_IBF;
+	}
+
+	if ((priv->events & KCS_BMC_EVENT_TYPE_OBE) && !(status & KCS_BMC_STR_OBF)) {
+		kcs_bmc_raw_update_event_mask(priv, KCS_BMC_EVENT_TYPE_OBE, 0);
+		priv->writable = true;
+
+		dev_dbg(dev, "ODR writable, waking waiters\n");
+		wake_up_locked(&priv->queue);
+
+		handled |= KCS_BMC_EVENT_TYPE_OBE;
+	}
+
+	spin_unlock(&priv->queue.lock);
+
+	return handled ? IRQ_HANDLED : IRQ_NONE;
+}
+
+static const struct kcs_bmc_client_ops kcs_bmc_raw_client_ops = {
+	.event = kcs_bmc_raw_event,
+};
+
+static inline struct kcs_bmc_raw *file_to_kcs_bmc_raw(struct file *filp)
+{
+	return container_of(filp->private_data, struct kcs_bmc_raw, miscdev);
+}
+
+static int kcs_bmc_raw_open(struct inode *inode, struct file *filp)
+{
+	struct kcs_bmc_raw *priv = file_to_kcs_bmc_raw(filp);
+	int rc;
+
+	priv->events = KCS_BMC_EVENT_TYPE_IBF;
+	rc = kcs_bmc_enable_device(priv->client.dev, &priv->client);
+	if (rc)
+		priv->events = 0;
+
+	return rc;
+}
+
+static bool kcs_bmc_raw_prepare_obe(struct kcs_bmc_raw *priv)
+{
+	bool writable;
+
+	/* Enable the OBE event so we can catch the host clearing OBF */
+	kcs_bmc_raw_update_event_mask(priv, KCS_BMC_EVENT_TYPE_OBE, KCS_BMC_EVENT_TYPE_OBE);
+
+	/* Now that we'll catch an OBE event, check if it's already occurred */
+	writable = !(kcs_bmc_read_status(priv->client.dev) & KCS_BMC_STR_OBF);
+
+	/* If OBF is clear we've missed the OBE event, so disable it */
+	if (writable)
+		kcs_bmc_raw_update_event_mask(priv, KCS_BMC_EVENT_TYPE_OBE, 0);
+
+	return writable;
+}
+
+static __poll_t kcs_bmc_raw_poll(struct file *filp, poll_table *wait)
+{
+	struct kcs_bmc_raw *priv;
+	__poll_t events = 0;
+
+	priv = file_to_kcs_bmc_raw(filp);
+
+	poll_wait(filp, &priv->queue, wait);
+
+	spin_lock_irq(&priv->queue.lock);
+	if (kcs_bmc_raw_prepare_obe(priv))
+		events |= (EPOLLOUT | EPOLLWRNORM);
+
+	if (priv->readable || (kcs_bmc_read_status(priv->client.dev) & KCS_BMC_STR_IBF))
+		events |= (EPOLLIN | EPOLLRDNORM);
+	spin_unlock_irq(&priv->queue.lock);
+
+	return events;
+}
+
+static ssize_t kcs_bmc_raw_read(struct file *filp, char __user *buf,
+			     size_t count, loff_t *ppos)
+{
+	struct kcs_bmc_device *kcs_bmc;
+	struct kcs_bmc_raw *priv;
+	bool read_idr, read_str;
+	struct device *dev;
+	u8 idr, str;
+	ssize_t rc;
+
+	priv = file_to_kcs_bmc_raw(filp);
+	kcs_bmc = priv->client.dev;
+	dev = priv->miscdev.this_device;
+
+	if (!count)
+		return 0;
+
+	if (count > 2 || *ppos > 1)
+		return -EINVAL;
+
+	if (*ppos + count > 2)
+		return -EINVAL;
+
+	read_idr = (*ppos == 0);
+	read_str = (*ppos == 1) || (count == 2);
+
+	spin_lock_irq(&priv->queue.lock);
+	if (read_idr) {
+		dev_dbg(dev, "Waiting for IBF\n");
+		str = kcs_bmc_read_status(kcs_bmc);
+		if ((filp->f_flags & O_NONBLOCK) && (str & KCS_BMC_STR_IBF)) {
+			rc = -EWOULDBLOCK;
+			goto out;
+		}
+
+		rc = wait_event_interruptible_locked(priv->queue,
+						     priv->readable || (str & KCS_BMC_STR_IBF));
+		if (rc < 0)
+			goto out;
+
+		if (signal_pending(current)) {
+			dev_dbg(dev, "Interrupted waiting for IBF\n");
+			rc = -EINTR;
+			goto out;
+		}
+
+		/*
+		 * Re-enable events prior to possible read of IDR (which clears
+		 * IBF) to ensure we receive interrupts for subsequent writes
+		 * to IDR. Writes to IDR by the host should not occur while IBF
+		 * is set.
+		 */
+		dev_dbg(dev, "Woken by IBF, enabling IRQ\n");
+		kcs_bmc_raw_update_event_mask(priv, KCS_BMC_EVENT_TYPE_IBF,
+					      KCS_BMC_EVENT_TYPE_IBF);
+
+		/* Read data out of IDR into internal storage if necessary */
+		if (!priv->readable) {
+			WARN(!(str & KCS_BMC_STR_IBF), "Unknown reason for wakeup!");
+
+			priv->idr = kcs_bmc_read_data(kcs_bmc);
+		}
+
+		/* Copy data from internal storage to userspace */
+		idr = priv->idr;
+
+		/* We're done consuming the internally stored value */
+		priv->readable = false;
+	}
+
+	if (read_str) {
+		str = kcs_bmc_read_status(kcs_bmc);
+		if (*ppos == 0 || priv->readable)
+			/*
+			 * If we got this far with `*ppos == 0` then we've read
+			 * data out of IDR, so set IBF when reporting back to
+			 * userspace so userspace knows the IDR value is valid.
+			 */
+			str |= KCS_BMC_STR_IBF;
+
+		dev_dbg(dev, "Read status 0x%x\n", str);
+
+	}
+
+	rc = count;
+out:
+	spin_unlock_irq(&priv->queue.lock);
+
+	if (rc < 0)
+		return rc;
+
+	/* Now copy the data in to the userspace buffer */
+
+	if (read_idr)
+		if (copy_to_user(buf++, &idr, sizeof(idr)))
+			return -EFAULT;
+
+	if (read_str)
+		if (copy_to_user(buf, &str, sizeof(str)))
+			return -EFAULT;
+
+	return count;
+}
+
+static ssize_t kcs_bmc_raw_write(struct file *filp, const char __user *buf,
+			      size_t count, loff_t *ppos)
+{
+	struct kcs_bmc_device *kcs_bmc;
+	bool write_odr, write_str;
+	struct kcs_bmc_raw *priv;
+	struct device *dev;
+	ssize_t result;
+	u8 data[2];
+	u8 str;
+
+	priv = file_to_kcs_bmc_raw(filp);
+	kcs_bmc = priv->client.dev;
+	dev = priv->miscdev.this_device;
+
+	if (!count)
+		return count;
+
+	if (count > 2)
+		return -EINVAL;
+
+	if (*ppos >= 2)
+		return -EINVAL;
+
+	if (*ppos + count > 2)
+		return -EINVAL;
+
+	if (copy_from_user(data, buf, count))
+		return -EFAULT;
+
+	write_odr = (*ppos == 0);
+	write_str = (*ppos == 1) || (count == 2);
+
+	spin_lock_irq(&priv->queue.lock);
+
+	/* Always write status before data, we generate the SerIRQ by writing ODR */
+	if (write_str) {
+		/* The index of STR in the userspace buffer depends on whether ODR is written */
+		str = data[*ppos == 0];
+		if (!(str & KCS_BMC_STR_OBF))
+			dev_warn(dev, "Clearing OBF with status write: 0x%x\n", str);
+		dev_dbg(dev, "Writing status 0x%x\n", str);
+		kcs_bmc_write_status(kcs_bmc, str);
+	}
+
+	if (write_odr) {
+		/* If we're writing ODR it's always the first byte in the buffer */
+		u8 odr = data[0];
+
+		str = kcs_bmc_read_status(kcs_bmc);
+		if (str & KCS_BMC_STR_OBF) {
+			if (filp->f_flags & O_NONBLOCK) {
+				result = -EWOULDBLOCK;
+				goto out;
+			}
+
+			priv->writable = kcs_bmc_raw_prepare_obe(priv);
+
+			/* Now either OBF is already clear, or we'll get an OBE event to wake us */
+			dev_dbg(dev, "Waiting for OBF to clear\n");
+			wait_event_interruptible_locked(priv->queue, priv->writable);
+
+			if (signal_pending(current)) {
+				kcs_bmc_raw_update_event_mask(priv, KCS_BMC_EVENT_TYPE_OBE, 0);
+				result = -EINTR;
+				goto out;
+			}
+
+			WARN_ON(kcs_bmc_read_status(kcs_bmc) & KCS_BMC_STR_OBF);
+		}
+
+		dev_dbg(dev, "Writing 0x%x to ODR\n", odr);
+		kcs_bmc_write_data(kcs_bmc, odr);
+	}
+
+	result = count;
+out:
+	spin_unlock_irq(&priv->queue.lock);
+
+	return result;
+}
+
+static int kcs_bmc_raw_release(struct inode *inode, struct file *filp)
+{
+	struct kcs_bmc_raw *priv = file_to_kcs_bmc_raw(filp);
+
+	kcs_bmc_disable_device(priv->client.dev, &priv->client);
+	priv->events = 0;
+
+	return 0;
+}
+
+static const struct file_operations kcs_bmc_raw_fops = {
+	.owner          = THIS_MODULE,
+	.open		= kcs_bmc_raw_open,
+	.llseek		= no_seek_end_llseek,
+	.read           = kcs_bmc_raw_read,
+	.write          = kcs_bmc_raw_write,
+	.poll		= kcs_bmc_raw_poll,
+	.release	= kcs_bmc_raw_release,
+};
+
+static DEFINE_SPINLOCK(kcs_bmc_raw_instances_lock);
+static LIST_HEAD(kcs_bmc_raw_instances);
+
+static int kcs_bmc_raw_add_device(struct kcs_bmc_device *kcs_bmc)
+{
+	struct kcs_bmc_raw *priv;
+	int rc;
+
+	priv = devm_kzalloc(kcs_bmc->dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->client.dev = kcs_bmc;
+	priv->client.ops = &kcs_bmc_raw_client_ops;
+
+	init_waitqueue_head(&priv->queue);
+	priv->writable = false;
+	priv->readable = false;
+
+	priv->miscdev.minor = MISC_DYNAMIC_MINOR;
+	priv->miscdev.name = devm_kasprintf(kcs_bmc->dev, GFP_KERNEL, "%s%u", DEVICE_NAME,
+					   kcs_bmc->channel);
+	if (!priv->miscdev.name)
+		return -EINVAL;
+
+	priv->miscdev.fops = &kcs_bmc_raw_fops;
+
+	/* Disable interrupts until userspace opens the the chardev */
+	kcs_bmc_raw_update_event_mask(priv, (KCS_BMC_EVENT_TYPE_IBF | KCS_BMC_EVENT_TYPE_OBE), 0);
+
+	rc = misc_register(&priv->miscdev);
+	if (rc) {
+		dev_err(kcs_bmc->dev, "Unable to register device\n");
+		return rc;
+	}
+
+	spin_lock_irq(&kcs_bmc_raw_instances_lock);
+	list_add(&priv->entry, &kcs_bmc_raw_instances);
+	spin_unlock_irq(&kcs_bmc_raw_instances_lock);
+
+	dev_info(kcs_bmc->dev, "Initialised raw client for channel %d", kcs_bmc->channel);
+
+	return 0;
+}
+
+static int kcs_bmc_raw_remove_device(struct kcs_bmc_device *kcs_bmc)
+{
+	struct kcs_bmc_raw *priv = NULL, *pos;
+
+	spin_lock_irq(&kcs_bmc_raw_instances_lock);
+	list_for_each_entry(pos, &kcs_bmc_raw_instances, entry) {
+		if (pos->client.dev == kcs_bmc) {
+			priv = pos;
+			list_del(&pos->entry);
+			break;
+		}
+	}
+	spin_unlock_irq(&kcs_bmc_raw_instances_lock);
+
+	if (!priv)
+		return -ENODEV;
+
+	misc_deregister(&priv->miscdev);
+	kcs_bmc_disable_device(kcs_bmc, &priv->client);
+	devm_kfree(priv->client.dev->dev, priv);
+
+	return 0;
+}
+
+static const struct kcs_bmc_driver_ops kcs_bmc_raw_driver_ops = {
+	.add_device = kcs_bmc_raw_add_device,
+	.remove_device = kcs_bmc_raw_remove_device,
+};
+
+static struct kcs_bmc_driver kcs_bmc_raw_driver = {
+	.ops = &kcs_bmc_raw_driver_ops,
+};
+
+static int kcs_bmc_raw_init(void)
+{
+	kcs_bmc_register_driver(&kcs_bmc_raw_driver);
+
+	return 0;
+}
+module_init(kcs_bmc_raw_init);
+
+static void kcs_bmc_raw_exit(void)
+{
+	kcs_bmc_unregister_driver(&kcs_bmc_raw_driver);
+}
+module_exit(kcs_bmc_raw_exit);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Andrew Jeffery <andrew@aj.id.au>");
+MODULE_DESCRIPTION("Character device for raw access to a KCS device");
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH linux dev-5.10 v2 3/7] ARM: configs: Enable IPMI KCS raw chardev
  2021-06-23  3:38 [PATCH linux dev-5.10 v2 0/7] Rework use of KCS devices for P10 platforms Andrew Jeffery
  2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 1/7] ipmi: kcs_bmc_aspeed: Fix less than zero comparison of a unsigned int Andrew Jeffery
  2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 2/7] ipmi: kcs_bmc: Add a "raw" character device interface Andrew Jeffery
@ 2021-06-23  3:38 ` Andrew Jeffery
  2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 4/7] ARM: dts: p10bmc: Drop the openbmc, mctp-lpc node Andrew Jeffery
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andrew Jeffery @ 2021-06-23  3:38 UTC (permalink / raw)
  To: joel; +Cc: openbmc

The raw KCS chardev is used by libmctp's vendor-defined LPC binding.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
---
 arch/arm/configs/aspeed_g5_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/aspeed_g5_defconfig b/arch/arm/configs/aspeed_g5_defconfig
index cefbec257bd8..045d383ce5ce 100644
--- a/arch/arm/configs/aspeed_g5_defconfig
+++ b/arch/arm/configs/aspeed_g5_defconfig
@@ -180,6 +180,7 @@ CONFIG_SERIAL_8250_DW=y
 CONFIG_SERIAL_OF_PLATFORM=y
 CONFIG_ASPEED_KCS_IPMI_BMC=y
 CONFIG_IPMI_KCS_BMC_SERIO=y
+CONFIG_IPMI_KCS_BMC_CDEV_RAW=y
 CONFIG_ASPEED_BT_IPMI_BMC=y
 CONFIG_HW_RANDOM=y
 CONFIG_HW_RANDOM_TIMERIOMEM=y
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH linux dev-5.10 v2 4/7] ARM: dts: p10bmc: Drop the openbmc, mctp-lpc node
  2021-06-23  3:38 [PATCH linux dev-5.10 v2 0/7] Rework use of KCS devices for P10 platforms Andrew Jeffery
                   ` (2 preceding siblings ...)
  2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 3/7] ARM: configs: Enable IPMI KCS raw chardev Andrew Jeffery
@ 2021-06-23  3:38 ` Andrew Jeffery
  2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 5/7] misc: Remove obsolete mctp-lpc chardev Andrew Jeffery
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andrew Jeffery @ 2021-06-23  3:38 UTC (permalink / raw)
  To: joel; +Cc: openbmc

The MCTP LPC driver was loaded by hacking up the compatible in the
devicetree node for KCS 4. With the introduction of the raw KCS driver
this hack is no-longer required. Use the regular compatible string for
KCS 4 and configure the appropriate SerIRQ.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
---
 arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts | 11 ++++++-----
 arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts | 11 ++++++-----
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts b/arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts
index 1c9e4ff5388b..d899c9620286 100644
--- a/arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts
@@ -4049,11 +4049,6 @@ &lpc_ctrl {
 	memory-region = <&flash_memory>;
 };
 
-&kcs4 {
-	compatible = "openbmc,mctp-lpc";
-	status = "okay";
-};
-
 &mac2 {
 	status = "okay";
 	pinctrl-names = "default";
@@ -4092,3 +4087,9 @@ &xdma {
 	status = "okay";
 	memory-region = <&vga_memory>;
 };
+
+&kcs4 {
+	status = "okay";
+	aspeed,lpc-io-reg = <0xca2>;
+	aspeed,lpc-interrupts = <11 IRQ_TYPE_LEVEL_LOW>;
+};
diff --git a/arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts b/arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts
index 73e94be5424b..9ea3864651d6 100644
--- a/arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts
@@ -1717,11 +1717,6 @@ &lpc_ctrl {
 	memory-region = <&flash_memory>;
 };
 
-&kcs4 {
-	compatible = "openbmc,mctp-lpc";
-	status = "okay";
-};
-
 &mac2 {
 	status = "okay";
 	pinctrl-names = "default";
@@ -1784,3 +1779,9 @@ &xdma {
 	status = "okay";
 	memory-region = <&vga_memory>;
 };
+
+&kcs4 {
+	status = "okay";
+	aspeed,lpc-io-reg = <0xca2>;
+	aspeed,lpc-interrupts = <11 IRQ_TYPE_LEVEL_LOW>;
+};
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH linux dev-5.10 v2 5/7] misc: Remove obsolete mctp-lpc chardev
  2021-06-23  3:38 [PATCH linux dev-5.10 v2 0/7] Rework use of KCS devices for P10 platforms Andrew Jeffery
                   ` (3 preceding siblings ...)
  2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 4/7] ARM: dts: p10bmc: Drop the openbmc, mctp-lpc node Andrew Jeffery
@ 2021-06-23  3:38 ` Andrew Jeffery
  2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 6/7] ARM: dts: p10bmc: Switch to KCS 3 for MCTP binding Andrew Jeffery
  2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 7/7] ARM: dts: p10bmc: Enable KCS channel 2 Andrew Jeffery
  6 siblings, 0 replies; 8+ messages in thread
From: Andrew Jeffery @ 2021-06-23  3:38 UTC (permalink / raw)
  To: joel; +Cc: openbmc

The mctp-lpc chardev is replaced (temporarily) by the raw KCS chardev.
The raw chardev is required for IBM's purposes until Jeremy's
socket-based MCTP patches are merged[1][2].

[1] https://github.com/openbmc/docs/blob/master/designs/mctp/mctp-kernel.md
[2] https://lore.kernel.org/openbmc/f4f5fa66542401e8d5e78c1fb30153195d384b62.camel@codeconstruct.com.au/

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
---
 arch/arm/configs/aspeed_g5_defconfig |   1 -
 drivers/misc/Kconfig                 |   7 -
 drivers/misc/Makefile                |   1 -
 drivers/misc/mctp-lpc.c              | 443 ---------------------------
 4 files changed, 452 deletions(-)
 delete mode 100644 drivers/misc/mctp-lpc.c

diff --git a/arch/arm/configs/aspeed_g5_defconfig b/arch/arm/configs/aspeed_g5_defconfig
index 045d383ce5ce..550884fee892 100644
--- a/arch/arm/configs/aspeed_g5_defconfig
+++ b/arch/arm/configs/aspeed_g5_defconfig
@@ -111,7 +111,6 @@ CONFIG_MTD_UBI_FASTMAP=y
 CONFIG_MTD_UBI_BLOCK=y
 CONFIG_BLK_DEV_LOOP=y
 CONFIG_BLK_DEV_NBD=y
-CONFIG_MCTP_LPC=y
 CONFIG_EEPROM_AT24=y
 CONFIG_EEPROM_AT25=y
 CONFIG_MD=y
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index c1322e9bee8a..54cfb599cd3e 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -444,13 +444,6 @@ config XILINX_SDFEC
 
 	  If unsure, say N.
 
-config MCTP_LPC
-	tristate "MCTP LPC binding implementation for ASPEED BMCs"
-	depends on REGMAP
-	help
-	  Implements the MCTP LPC binding via KCS LPC IO cycles for control and
-          LPC FWH cycles for data
-
 config MISC_RTSX
 	tristate
 	default MISC_RTSX_PCI || MISC_RTSX_USB
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index bcc79a1d7a72..39e5ba5d0985 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -60,4 +60,3 @@ obj-$(CONFIG_HISI_HIKEY_USB)	+= hisi_hikey_usb.o
 obj-$(CONFIG_NPCM7XX_LPC_BPC)	+= npcm7xx-lpc-bpc.o
 obj-$(CONFIG_NPCM7XX_PCI_MBOX)	+= npcm7xx-pci-mbox.o
 obj-$(CONFIG_NPCM7XX_JTAG_MASTER)	+= npcm7xx-jtag-master.o
-obj-$(CONFIG_MCTP_LPC)		+= mctp-lpc.o
diff --git a/drivers/misc/mctp-lpc.c b/drivers/misc/mctp-lpc.c
deleted file mode 100644
index 0228f6bbf1a7..000000000000
--- a/drivers/misc/mctp-lpc.c
+++ /dev/null
@@ -1,443 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright (c) 2019, IBM Corp.
- */
-
-#include <linux/errno.h>
-#include <linux/fs.h>
-#include <linux/interrupt.h>
-#include <linux/io.h>
-#include <linux/mfd/syscon.h>
-#include <linux/miscdevice.h>
-#include <linux/module.h>
-#include <linux/of.h>
-#include <linux/platform_device.h>
-#include <linux/poll.h>
-#include <linux/regmap.h>
-#include <linux/sched/signal.h>
-#include <linux/uaccess.h>
-#include <linux/wait.h>
-
-#define LPC_HICRB            0x100
-#define     LPC_HICRB_IBFIF4         BIT(1)
-#define     LPC_HICRB_LPC4E          BIT(0)
-#define LPC_HICRC            0x104
-#define     LPC_KCS4_IRQSEL_MASK     GENMASK(7, 4)
-#define     LPC_KCS4_IRQSEL_SHIFT    4
-#define     LPC_KCS4_IRQTYPE_MASK    GENMASK(3, 2)
-#define     LPC_KCS4_IRQTYPE_SHIFT   2
-#define     LPC_KCS4_IRQTYPE_LOW     0b00
-#define     LPC_KCS4_IRQTYPE_HIGH    0b01
-#define     LPC_KCS4_IRQTYPE_RSVD    0b10
-#define     LPC_KCS4_IRQTYPE_RISING  0b11
-#define     LPC_KCS4_OBF4_AUTO_CLR   BIT(1)
-#define     LPC_KCS4_IRQ_HOST	     BIT(0)
-#define LPC_LADR4            0x110
-#define LPC_IDR4             0x114
-#define LPC_ODR4             0x118
-#define LPC_STR4             0x11C
-#define     STR4_IBF	     (1 << 1)
-#define     STR4_OBF	     (1 << 0)
-
-#define HOST_ODR             0xca2
-#define HOST_STR             0xca3
-#define HOST_SERIRQ_ID       11
-#define HOST_SERIRQ_TYPE     LPC_KCS4_IRQTYPE_LOW
-
-#define RX_BUF_SIZE 1024
-
-struct mctp_lpc {
-	struct miscdevice miscdev;
-	struct regmap *map;
-
-	wait_queue_head_t rx;
-	bool pending;
-	u8 idr;
-};
-
-static irqreturn_t mctp_lpc_irq(int irq, void *data)
-{
-	struct mctp_lpc *priv = data;
-	unsigned long flags;
-	unsigned int hicrb;
-	struct device *dev;
-	unsigned int str;
-	irqreturn_t ret;
-
-	dev = priv->miscdev.this_device;
-
-	spin_lock_irqsave(&priv->rx.lock, flags);
-
-	regmap_read(priv->map, LPC_STR4, &str);
-	regmap_read(priv->map, LPC_HICRB, &hicrb);
-
-	if ((str & STR4_IBF) && (hicrb & LPC_HICRB_IBFIF4)) {
-		unsigned int val;
-
-		if (priv->pending)
-			dev_err(dev, "Storm brewing!");
-
-		/* Mask the IRQ / Enter polling mode */
-		dev_dbg(dev, "Received IRQ %d, disabling to provide back-pressure\n",
-			irq);
-		regmap_update_bits(priv->map, LPC_HICRB, LPC_HICRB_IBFIF4, 0);
-
-		/*
-		 * Extract the IDR4 value to ack the IRQ. Reading IDR clears
-		 * IBF and allows the host to write another value, however as
-		 * we have disabled IRQs the back-pressure is still applied
-		 * until userspace starts servicing the interface.
-		 */
-		regmap_read(priv->map, LPC_IDR4, &val);
-		priv->idr = val & 0xff;
-		priv->pending = true;
-
-		dev_dbg(dev, "Set pending, waking waiters\n");
-		wake_up_locked(&priv->rx);
-		ret = IRQ_HANDLED;
-	} else {
-		dev_dbg(dev, "LPC IRQ triggered, but not for us (str=0x%x, hicrb=0x%x)\n",
-			str, hicrb);
-		ret = IRQ_NONE;
-	}
-
-	spin_unlock_irqrestore(&priv->rx.lock, flags);
-
-	return ret;
-}
-
-static inline struct mctp_lpc *to_mctp_lpc(struct file *filp)
-{
-	return container_of(filp->private_data, struct mctp_lpc, miscdev);
-}
-
-static ssize_t mctp_lpc_read(struct file *filp, char __user *buf,
-			     size_t count, loff_t *ppos)
-{
-	struct mctp_lpc *priv;
-	struct device *dev;
-	size_t remaining;
-	ssize_t rc;
-
-	priv = to_mctp_lpc(filp);
-	dev = priv->miscdev.this_device;
-
-	if (!count)
-		return 0;
-
-	if (count > 2 || *ppos > 1)
-		return -EINVAL;
-
-	remaining = count;
-
-	spin_lock_irq(&priv->rx.lock);
-	if (*ppos == 0) {
-		unsigned int val;
-		u8 str;
-
-		/* YOLO blocking, non-block not supported */
-		dev_dbg(dev, "Waiting for IBF\n");
-		regmap_read(priv->map, LPC_STR4, &val);
-		str = val & 0xff;
-		rc = wait_event_interruptible_locked(priv->rx, (priv->pending || str & STR4_IBF));
-		if (rc < 0)
-			goto out;
-
-		if (signal_pending(current)) {
-			dev_dbg(dev, "Interrupted waiting for IBF\n");
-			rc = -EINTR;
-			goto out;
-		}
-
-		/*
-		 * Re-enable IRQs prior to possible read of IDR (which clears
-		 * IBF) to ensure we receive interrupts for subsequent writes
-		 * to IDR. Writes to IDR by the host should not occur while IBF
-		 * is set.
-		 */
-		dev_dbg(dev, "Woken by IBF, enabling IRQ\n");
-		regmap_update_bits(priv->map, LPC_HICRB, LPC_HICRB_IBFIF4,
-				   LPC_HICRB_IBFIF4);
-
-		/* Read data out of IDR into internal storage if necessary */
-		if (!priv->pending) {
-			WARN(!(str & STR4_IBF), "Unknown reason for wakeup!");
-
-			/* Extract the IDR4 value to ack the IRQ */
-			regmap_read(priv->map, LPC_IDR4, &val);
-			priv->idr = val & 0xff;
-		}
-
-		/* Copy data from internal storage to userspace */
-		if (copy_to_user(buf, &priv->idr, sizeof(priv->idr))) {
-			rc = -EFAULT;
-			goto out;
-		}
-
-		/* We're done consuming the internally stored value */
-		priv->pending = false;
-
-		remaining--;
-		buf++;
-	}
-
-	if (remaining) {
-		/* Either:
-		 *
-		 * 1. (count == 1 && *ppos == 1)
-		 * 2. (count == 2 && *ppos == 0)
-		 */
-		unsigned int val;
-		u8 str;
-
-		regmap_read(priv->map, LPC_STR4, &val);
-		str = val & 0xff;
-		if (*ppos == 0 || priv->pending)
-			/*
-			 * If we got this far with `*ppos == 0` then we've read
-			 * data out of IDR, so set IBF when reporting back to
-			 * userspace so userspace knows the IDR value is valid.
-			 */
-			str |= STR4_IBF;
-
-		dev_dbg(dev, "Read status 0x%x\n", str);
-		if (copy_to_user(buf, &str, sizeof(str))) {
-			rc = -EFAULT;
-			goto out;
-		}
-
-		remaining--;
-	}
-
-	WARN_ON(remaining);
-
-	rc = count;
-
-out:
-	spin_unlock_irq(&priv->rx.lock);
-
-	return rc;
-}
-
-static ssize_t mctp_lpc_write(struct file *filp, const char __user *buf,
-			      size_t count, loff_t *ppos)
-{
-	uint8_t _data[2], *data = &_data[0];
-	struct mctp_lpc *priv;
-	struct device *dev;
-	size_t remaining;
-	unsigned int str;
-
-	priv = to_mctp_lpc(filp);
-	dev = priv->miscdev.this_device;
-
-	if (!count)
-		return count;
-
-	if (count > 2)
-		return -EINVAL;
-
-	if (*ppos >= 2)
-		return -EINVAL;
-
-	if (*ppos + count > 2)
-		return -EINVAL;
-
-	if (copy_from_user(data, buf, count))
-		return -EFAULT;
-
-	remaining = count;
-
-	if (*ppos == 0) {
-		/* Wait until OBF is clear - we don't get an IRQ */
-		dev_dbg(dev, "Waiting for OBF to clear\n");
-		for (;;) {
-			if (signal_pending(current))
-				return -EINTR;
-
-			regmap_read(priv->map, LPC_STR4, &str);
-			if (!(str & STR4_OBF))
-				break;
-
-			msleep(1);
-		}
-
-		dev_dbg(dev, "Writing 0x%x to ODR\n", *data);
-		regmap_write(priv->map, LPC_ODR4, *data);
-		remaining--;
-		data++;
-	}
-
-	if (remaining) {
-		if (!(*data & STR4_OBF))
-			dev_err(dev, "Clearing OBF with status write: 0x%x\n",
-				*data);
-		dev_dbg(dev, "Writing status 0x%x\n", *data);
-		regmap_write(priv->map, LPC_STR4, *data);
-		remaining--;
-	}
-
-	WARN_ON(remaining);
-
-	regmap_read(priv->map, LPC_STR4, &str);
-	dev_dbg(dev, "Triggering SerIRQ (current str=0x%x)\n", str);
-
-	/*
-	 * Trigger Host IRQ on ODR write. Do this after any STR write in case
-	 * we need to write ODR to indicate an STR update (which we do).
-	 */
-	if (*ppos == 0)
-		regmap_update_bits(priv->map, LPC_HICRC, LPC_KCS4_IRQ_HOST,
-				   LPC_KCS4_IRQ_HOST);
-
-	return count;
-}
-
-static __poll_t mctp_lpc_poll(struct file *filp, poll_table *wait)
-{
-	struct mctp_lpc *priv;
-	struct device *dev;
-	unsigned int val;
-	bool ibf;
-
-	priv = to_mctp_lpc(filp);
-	dev = priv->miscdev.this_device;
-
-	regmap_read(priv->map, LPC_STR4, &val);
-
-	spin_lock_irq(&priv->rx.lock);
-
-	ibf = priv->pending || val & STR4_IBF;
-
-	if (!ibf) {
-		dev_dbg(dev, "Polling on IBF\n");
-
-		spin_unlock_irq(&priv->rx.lock);
-
-		poll_wait(filp, &priv->rx, wait);
-		if (signal_pending(current)) {
-			dev_dbg(dev, "Polling IBF was interrupted\n");
-			goto out;
-		}
-
-		spin_lock_irq(&priv->rx.lock);
-
-		regmap_read(priv->map, LPC_STR4, &val);
-
-		ibf = priv->pending || val & STR4_IBF;
-	}
-
-	spin_unlock_irq(&priv->rx.lock);
-
-out:
-	dev_dbg(dev, "Polled IBF state: %s\n", ibf ? "set" : "clear");
-
-	return ibf ? EPOLLIN : 0;
-}
-
-static const struct file_operations mctp_lpc_fops = {
-	.owner          = THIS_MODULE,
-	.llseek		= no_seek_end_llseek,
-	.read           = mctp_lpc_read,
-	.write          = mctp_lpc_write,
-	.poll		= mctp_lpc_poll,
-};
-
-static int mctp_lpc_probe(struct platform_device *pdev)
-{
-	struct device *dev = &pdev->dev;
-	unsigned int mask, val;
-	struct mctp_lpc *priv;
-	int irq;
-	int rc;
-
-	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv)
-		return -ENOMEM;
-
-	priv->map = syscon_node_to_regmap(dev->parent->of_node);
-	if (IS_ERR(priv->map)) {
-		dev_err(dev, "Couldn't get regmap\n");
-		return -ENODEV;
-	}
-
-	/*
-	 * Set the LPC address. Simultaneously, test our MMIO regmap works. All
-	 * subsequent accesses are assumed to work
-	 */
-	rc = regmap_write(priv->map, LPC_LADR4, ((HOST_STR) << 16) | HOST_ODR);
-	if (rc < 0)
-		return rc;
-
-	/* Set up the SerIRQ */
-	mask = LPC_KCS4_IRQSEL_MASK
-		| LPC_KCS4_IRQTYPE_MASK
-		| LPC_KCS4_OBF4_AUTO_CLR;
-	val = (HOST_SERIRQ_ID << LPC_KCS4_IRQSEL_SHIFT)
-		| (HOST_SERIRQ_TYPE << LPC_KCS4_IRQTYPE_SHIFT);
-	val &= ~LPC_KCS4_OBF4_AUTO_CLR; /* Unnecessary, just documentation */
-	regmap_update_bits(priv->map, LPC_HICRC, mask, val);
-
-	/* Trigger waiters from IRQ */
-	init_waitqueue_head(&priv->rx);
-
-	dev_set_drvdata(dev, priv);
-
-	/* Set up the miscdevice */
-	priv->miscdev.minor = MISC_DYNAMIC_MINOR;
-	priv->miscdev.name = "mctp0";
-	priv->miscdev.fops = &mctp_lpc_fops;
-
-	/* Configure the IRQ handler */
-	irq = platform_get_irq(pdev, 0);
-	if (irq < 0)
-		return irq;
-
-	rc = devm_request_irq(dev, irq, mctp_lpc_irq, IRQF_SHARED,
-			      dev_name(dev), priv);
-	if (rc < 0)
-		return rc;
-
-	/* Register the device */
-	rc = misc_register(&priv->miscdev);
-	if (rc) {
-		dev_err(dev, "Unable to register device\n");
-		return rc;
-	}
-
-	/* Enable the channel */
-	regmap_update_bits(priv->map, LPC_HICRB,
-			LPC_HICRB_IBFIF4 | LPC_HICRB_LPC4E,
-			LPC_HICRB_IBFIF4 | LPC_HICRB_LPC4E);
-
-	return 0;
-}
-
-static int mctp_lpc_remove(struct platform_device *pdev)
-{
-	struct mctp_lpc *ctx = dev_get_drvdata(&pdev->dev);
-
-	misc_deregister(&ctx->miscdev);
-
-	return 0;
-}
-
-static const struct of_device_id mctp_lpc_match[] = {
-	{ .compatible = "openbmc,mctp-lpc" },
-	{ }
-};
-MODULE_DEVICE_TABLE(of, mctp_lpc_match);
-
-static struct platform_driver mctp_lpc = {
-	.driver = {
-		.name           = "mctp-lpc",
-		.of_match_table = mctp_lpc_match,
-	},
-	.probe  = mctp_lpc_probe,
-	.remove = mctp_lpc_remove,
-};
-module_platform_driver(mctp_lpc);
-
-MODULE_LICENSE("GPL v2+");
-MODULE_AUTHOR("Andrew Jeffery <andrew@aj.id.au>");
-MODULE_DESCRIPTION("OpenBMC MCTP LPC binding on ASPEED KCS");
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH linux dev-5.10 v2 6/7] ARM: dts: p10bmc: Switch to KCS 3 for MCTP binding
  2021-06-23  3:38 [PATCH linux dev-5.10 v2 0/7] Rework use of KCS devices for P10 platforms Andrew Jeffery
                   ` (4 preceding siblings ...)
  2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 5/7] misc: Remove obsolete mctp-lpc chardev Andrew Jeffery
@ 2021-06-23  3:38 ` Andrew Jeffery
  2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 7/7] ARM: dts: p10bmc: Enable KCS channel 2 Andrew Jeffery
  6 siblings, 0 replies; 8+ messages in thread
From: Andrew Jeffery @ 2021-06-23  3:38 UTC (permalink / raw)
  To: joel; +Cc: openbmc

The reset state of the status bits on KCS 4 is inappropriate for the
MCTP LPC binding. Switch to KCS 3 which has a different reset behaviour.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
---
 arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts | 2 +-
 arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts b/arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts
index d899c9620286..738785390fa3 100644
--- a/arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts
@@ -4088,7 +4088,7 @@ &xdma {
 	memory-region = <&vga_memory>;
 };
 
-&kcs4 {
+&kcs3 {
 	status = "okay";
 	aspeed,lpc-io-reg = <0xca2>;
 	aspeed,lpc-interrupts = <11 IRQ_TYPE_LEVEL_LOW>;
diff --git a/arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts b/arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts
index 9ea3864651d6..9d57f9f6a1c3 100644
--- a/arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts
@@ -1780,7 +1780,7 @@ &xdma {
 	memory-region = <&vga_memory>;
 };
 
-&kcs4 {
+&kcs3 {
 	status = "okay";
 	aspeed,lpc-io-reg = <0xca2>;
 	aspeed,lpc-interrupts = <11 IRQ_TYPE_LEVEL_LOW>;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH linux dev-5.10 v2 7/7] ARM: dts: p10bmc: Enable KCS channel 2
  2021-06-23  3:38 [PATCH linux dev-5.10 v2 0/7] Rework use of KCS devices for P10 platforms Andrew Jeffery
                   ` (5 preceding siblings ...)
  2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 6/7] ARM: dts: p10bmc: Switch to KCS 3 for MCTP binding Andrew Jeffery
@ 2021-06-23  3:38 ` Andrew Jeffery
  6 siblings, 0 replies; 8+ messages in thread
From: Andrew Jeffery @ 2021-06-23  3:38 UTC (permalink / raw)
  To: joel; +Cc: openbmc

Rainier uses KCS channel 2 as the source for the debug-trigger
application outlined at [1] and implemented at [2].

[1] https://github.com/openbmc/docs/blob/master/designs/bmc-service-failure-debug-and-recovery.md
[2] https://github.com/openbmc/debug-trigger

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
---
 arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts | 5 +++++
 arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts b/arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts
index 738785390fa3..43d998e39f65 100644
--- a/arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts
@@ -4088,6 +4088,11 @@ &xdma {
 	memory-region = <&vga_memory>;
 };
 
+&kcs2 {
+	status = "okay";
+	aspeed,lpc-io-reg = <0xca8 0xcac>;
+};
+
 &kcs3 {
 	status = "okay";
 	aspeed,lpc-io-reg = <0xca2>;
diff --git a/arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts b/arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts
index 9d57f9f6a1c3..5e071b548cb1 100644
--- a/arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts
@@ -1780,6 +1780,11 @@ &xdma {
 	memory-region = <&vga_memory>;
 };
 
+&kcs2 {
+	status = "okay";
+	aspeed,lpc-io-reg = <0xca8 0xcac>;
+};
+
 &kcs3 {
 	status = "okay";
 	aspeed,lpc-io-reg = <0xca2>;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-06-23  3:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-23  3:38 [PATCH linux dev-5.10 v2 0/7] Rework use of KCS devices for P10 platforms Andrew Jeffery
2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 1/7] ipmi: kcs_bmc_aspeed: Fix less than zero comparison of a unsigned int Andrew Jeffery
2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 2/7] ipmi: kcs_bmc: Add a "raw" character device interface Andrew Jeffery
2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 3/7] ARM: configs: Enable IPMI KCS raw chardev Andrew Jeffery
2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 4/7] ARM: dts: p10bmc: Drop the openbmc, mctp-lpc node Andrew Jeffery
2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 5/7] misc: Remove obsolete mctp-lpc chardev Andrew Jeffery
2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 6/7] ARM: dts: p10bmc: Switch to KCS 3 for MCTP binding Andrew Jeffery
2021-06-23  3:38 ` [PATCH linux dev-5.10 v2 7/7] ARM: dts: p10bmc: Enable KCS channel 2 Andrew Jeffery

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.