Skip to contentSkip to conversation

LoongArch: Add Loongson-2K BMC support

PATCH Superseded Binbin Zhou 3 participants 12 messages Jun 13, 2025 – Jun 16, 2025

Subsystems (4)

v4 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
author maintainer
#1 lore raw

PATCH v4 1/3 mfd: ls2kbmc: Introduce Loongson-2K BMC core driver

In reply to Binbin Zhou

The Loongson-2K Board Management Controller provides an PCIe interface to the host to access the feature implemented in the BMC.

The BMC is assembled on a server similar to the server machine with Loongson-3 CPU. It supports multiple sub-devices like DRM or IPMI.

---
 drivers/mfd/Kconfig       |  12 +++
 drivers/mfd/Makefile      |   2 +
 drivers/mfd/ls2kbmc-mfd.c | 156 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 170 insertions(+)
 create mode 100644 drivers/mfd/ls2kbmc-mfd.c
drivers/mfd/Kconfig +12 -0
index 96992af22565..10e3d1728e13 100644
@@ -2389,6 +2389,18 @@ config MFD_INTEL_M10_BMC_PMCI
 	  additional drivers must be enabled in order to use the functionality
 	  of the device.
 
+config MFD_LS2K_BMC
+	bool "Loongson-2K Board Management Controller Support"
+	depends on LOONGARCH
+	default y if LOONGARCH
+	select MFD_CORE
+	help
+	  Say yes here to add support for the Loongson-2K BMC which is a Board
+	  Management Controller connected to the PCIe bus. The device supports
+	  multiple sub-devices like DRM. This driver provides common support for
+	  accessing the devices; additional drivers must be enabled in order to
+	  use the functionality of the BMC device.
+
 config MFD_QNAP_MCU
 	tristate "QNAP microcontroller unit core driver"
 	depends on SERIAL_DEV_BUS
drivers/mfd/Makefile +2 -0
index 5e5cc279af60..bd4282c36ed2 100644
@@ -282,6 +282,8 @@ obj-$(CONFIG_MFD_INTEL_M10_BMC_CORE)   += intel-m10-bmc-core.o
 obj-$(CONFIG_MFD_INTEL_M10_BMC_SPI)    += intel-m10-bmc-spi.o
 obj-$(CONFIG_MFD_INTEL_M10_BMC_PMCI)   += intel-m10-bmc-pmci.o
 
+obj-$(CONFIG_MFD_LS2K_BMC)	+= ls2kbmc-mfd.o
+
 obj-$(CONFIG_MFD_ATC260X)	+= atc260x-core.o
 obj-$(CONFIG_MFD_ATC260X_I2C)	+= atc260x-i2c.o
 
drivers/mfd/ls2kbmc-mfd.c new file +156 -0

156 lines not on this page · raw message

Signature · 1 line
2.47.1
author maintainer
#2 lore raw

PATCH v4 2/3 mfd: ls2kbmc: Add Loongson-2K BMC reset function support

In reply to Binbin Zhou

Since the display is a sub-function of the Loongson-2K BMC, when the BMC reset, the entire BMC PCIe is disconnected, including the display which is interrupted.

Quick overview of the entire LS2K BMC reset process:

There are two types of reset methods: soft reset (BMC-initiated reboot of IPMI reset command) and BMC watchdog reset (watchdog timeout).

First, regardless of the method, an interrupt is generated (PCIe interrupt for soft reset/GPIO interrupt for watchdog reset);

Second, during the interrupt process, the system enters bmc_reset_work, clears the bus/IO/mem resources of the LS7A PCI-E bridge, waits for the BMC reset to begin, then restores the parent device's PCI configuration space, waits for the BMC reset to complete, and finally restores the BMC PCI configuration space.

Display restoration occurs last.

---
 drivers/mfd/ls2kbmc-mfd.c | 329 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 329 insertions(+)
drivers/mfd/ls2kbmc-mfd.c +329 -0
index 310ca70700c0..2c8e86194cb3 100644
@@ -10,8 +10,12 @@
  */
 
 #include <linux/aperture.h>
+#include <linux/bitfield.h>
+#include <linux/delay.h>
 #include <linux/errno.h>
 #include <linux/init.h>
+#include <linux/iopoll.h>
+#include <linux/kbd_kern.h>
 #include <linux/kernel.h>
 #include <linux/mfd/core.h>
 #include <linux/module.h>
@@ -19,6 +23,8 @@
 #include <linux/pci_ids.h>
 #include <linux/platform_data/simplefb.h>
 #include <linux/platform_device.h>
+#include <linux/stop_machine.h>
+#include <linux/vt_kern.h>
 
 /* LS2K BMC resources */
 #define LS2K_DISPLAY_RES_START		(SZ_16M + SZ_2M)
@@ -29,6 +35,48 @@
 #define LS2K_IPMI3_RES_START		(LS2K_IPMI2_RES_START + LS2K_IPMI_RES_SIZE)
 #define LS2K_IPMI4_RES_START		(LS2K_IPMI3_RES_START + LS2K_IPMI_RES_SIZE)
 
+#define LS7A_PCI_CFG_SIZE		0x100
+
+/* LS7A bridge registers */
+#define LS7A_PCIE_PORT_CTL0		0x0
+#define LS7A_PCIE_PORT_STS1		0xC
+#define LS7A_GEN2_CTL			0x80C
+#define LS7A_SYMBOL_TIMER		0x71C
+
+/* Bits of LS7A_PCIE_PORT_CTL0 */
+#define LS2K_BMC_PCIE_LTSSM_ENABLE	BIT(3)
+
+/* Bits of LS7A_PCIE_PORT_STS1 */
+#define LS2K_BMC_PCIE_LTSSM_STS		GENMASK(5, 0)
+#define LS2K_BMC_PCIE_CONNECTED		0x11
+
+#define LS2K_BMC_PCIE_DELAY_US		1000
+#define LS2K_BMC_PCIE_TIMEOUT_US	1000000
+
+/* Bits of LS7A_GEN2_CTL */
+#define LS7A_GEN2_SPEED_CHANG		BIT(17)
+#define LS7A_CONF_PHY_TX		BIT(18)
+
+/* Bits of LS7A_SYMBOL_TIMER */
+#define LS7A_MASK_LEN_MATCH		BIT(26)
+
+/* Interval between interruptions */
+#define LS2K_BMC_INT_INTERVAL		(60 * HZ)
+
+/* Maximum time to wait for U-Boot and DDR to be ready with ms. */
+#define LS2K_BMC_RESET_WAIT_TIME	10000
+
+/* It's an experience value */
+#define LS7A_BAR0_CHECK_MAX_TIMES	2000
+
+#define LS2K_BMC_RESET_GPIO		14
+#define LOONGSON_GPIO_REG_BASE		0x1FE00500
+#define LOONGSON_GPIO_REG_SIZE		0x18
+#define LOONGSON_GPIO_OEN		0x0
+#define LOONGSON_GPIO_FUNC		0x4
+#define LOONGSON_GPIO_INTPOL		0x10
+#define LOONGSON_GPIO_INTEN		0x14
+
 static struct resource ls2k_display_resources[] = {
 	DEFINE_RES_MEM_NAMED(LS2K_DISPLAY_RES_START, SZ_4M, "simpledrm-res"),
 };
@@ -62,6 +110,274 @@ static struct mfd_cell ls2k_bmc_cells[] = {
 	MFD_CELL_RES("ls2k-ipmi-si", ls2k_ipmi4_resources),
 };
 
+/* Index of the BMC PCI configuration space to be restored at BMC reset. */
+struct ls2k_bmc_pci_data {
+	u32 pci_command;
+	u32 base_address0;
+	u32 interrupt_line;
+};
+
+/* Index of the parent PCI configuration space to be restored at BMC reset. */
+struct ls2k_bmc_bridge_pci_data {
+	u32 pci_command;
+	u32 base_address[6];
+	u32 rom_addreess;
+	u32 interrupt_line;
+	u32 msi_hi;
+	u32 msi_lo;
+	u32 devctl;
+	u32 linkcap;
+	u32 linkctl_sts;
+	u32 symbol_timer;
+	u32 gen2_ctrl;
+};
+
+struct ls2k_bmc_pdata {
+	struct device *dev;
+	struct work_struct bmc_reset_work;
+	struct ls2k_bmc_pci_data bmc_pci_data;
+	struct ls2k_bmc_bridge_pci_data bridge_pci_data;
+};
+
+static bool ls2k_bmc_bar0_addr_is_set(struct pci_dev *ppdev)
+{
+	u32 addr;
+
+	pci_read_config_dword(ppdev, PCI_BASE_ADDRESS_0, &addr);
+
+	return addr & PCI_BASE_ADDRESS_MEM_MASK ? true : false;
+}
+
+static bool ls2k_bmc_pcie_is_connected(struct pci_dev *parent, struct ls2k_bmc_pdata *priv)
+{
+	void __iomem *base;
+	int sts, ret;
+
+	base = pci_iomap(parent, 0, LS7A_PCI_CFG_SIZE);
+	if (!base)
+		return false;
+
+	writel(readl(base + LS7A_PCIE_PORT_CTL0) | LS2K_BMC_PCIE_LTSSM_ENABLE,
+	       base + LS7A_PCIE_PORT_CTL0);
+
+	ret = readl_poll_timeout_atomic(base + LS7A_PCIE_PORT_STS1, sts,
+					(sts & LS2K_BMC_PCIE_LTSSM_STS) == LS2K_BMC_PCIE_CONNECTED,
+					LS2K_BMC_PCIE_DELAY_US, LS2K_BMC_PCIE_TIMEOUT_US);
+	if (ret) {
+		pci_iounmap(parent, base);
+		dev_err(priv->dev, "PCIE train failed status=0x%x\n", sts);
+		return false;
+	}
+
+	pci_iounmap(parent, base);
+	return true;
+}
+
+static void ls2k_bmc_restore_bridge_pci_data(struct pci_dev *parent, struct ls2k_bmc_pdata *priv)
+{
+	int base, i = 0;
+
+	pci_write_config_dword(parent, PCI_COMMAND, priv->bridge_pci_data.pci_command);
+
+	for (base = PCI_BASE_ADDRESS_0; base <= PCI_BASE_ADDRESS_5; base += 4, i++)
+		pci_write_config_dword(parent, base, priv->bridge_pci_data.base_address[i]);
+
+	pci_write_config_dword(parent, PCI_ROM_ADDRESS, priv->bridge_pci_data.rom_addreess);
+	pci_write_config_dword(parent, PCI_INTERRUPT_LINE, priv->bridge_pci_data.interrupt_line);
+
+	pci_write_config_dword(parent, parent->msi_cap + PCI_MSI_ADDRESS_LO,
+			       priv->bridge_pci_data.msi_lo);
+	pci_write_config_dword(parent, parent->msi_cap + PCI_MSI_ADDRESS_HI,
+			       priv->bridge_pci_data.msi_hi);
+	pci_write_config_dword(parent, parent->pcie_cap + PCI_EXP_DEVCTL,
+			       priv->bridge_pci_data.devctl);
+	pci_write_config_dword(parent, parent->pcie_cap + PCI_EXP_LNKCAP,
+			       priv->bridge_pci_data.linkcap);
+	pci_write_config_dword(parent, parent->pcie_cap + PCI_EXP_LNKCTL,
+			       priv->bridge_pci_data.linkctl_sts);
+
+	pci_write_config_dword(parent, LS7A_GEN2_CTL, priv->bridge_pci_data.gen2_ctrl);
+	pci_write_config_dword(parent, LS7A_SYMBOL_TIMER, priv->bridge_pci_data.symbol_timer);
+}
+
+static int ls2k_bmc_recover_pci_data(void *data)
+{
+	struct ls2k_bmc_pdata *priv = data;
+	struct pci_dev *pdev = to_pci_dev(priv->dev);
+	struct pci_dev *parent = pdev->bus->self;
+	u32 i;
+
+	/*
+	 * Clear the bus, io and mem resources of the PCI-E bridge to zero, so that
+	 * the processor can not access the LS2K PCI-E port, to avoid crashing due to
+	 * the lack of return signal from accessing the LS2K PCI-E port.
+	 */
+	pci_write_config_dword(parent, PCI_BASE_ADDRESS_2, 0);
+	pci_write_config_dword(parent, PCI_BASE_ADDRESS_3, 0);
+	pci_write_config_dword(parent, PCI_BASE_ADDRESS_4, 0);
+
+	/*
+	 * When the LS2K BMC is reset, the LS7A PCI-E port is also reset, and its PCI
+	 * BAR0 register is cleared. Due to the time gap between the GPIO interrupt
+	 * generation and the LS2K BMC reset, the LS7A PCI BAR0 register is read to
+	 * determine whether the reset has begun.
+	 */
+	for (i = LS7A_BAR0_CHECK_MAX_TIMES; i > 0 ; i--) {
+		if (!ls2k_bmc_bar0_addr_is_set(parent))
+			break;
+		mdelay(1);
+	};
+
+	if (i == 0)
+		return false;
+
+	ls2k_bmc_restore_bridge_pci_data(parent, priv);
+
+	/* Check if PCI-E is connected */
+	if (!ls2k_bmc_pcie_is_connected(parent, priv))
+		return false;
+
+	/* Waiting for U-Boot and DDR ready */
+	mdelay(LS2K_BMC_RESET_WAIT_TIME);
+	if (!ls2k_bmc_bar0_addr_is_set(parent))
+		return false;
+
+	/* Restore LS2K BMC PCI-E config data */
+	pci_write_config_dword(pdev, PCI_COMMAND, priv->bmc_pci_data.pci_command);
+	pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, priv->bmc_pci_data.base_address0);
+	pci_write_config_dword(pdev, PCI_INTERRUPT_LINE, priv->bmc_pci_data.interrupt_line);
+
+	return 0;
+}
+
+static void ls2k_bmc_events_fn(struct work_struct *work)
+{
+	struct ls2k_bmc_pdata *priv = container_of(work, struct ls2k_bmc_pdata, bmc_reset_work);
+
+	/*
+	 * The PCI-E is lost when the BMC resets, at which point access to the PCI-E
+	 * from other CPUs is suspended to prevent a crash.
+	 */
+	stop_machine(ls2k_bmc_recover_pci_data, priv, NULL);
+
+#ifdef CONFIG_VT
+	/* Re-push the display due to previous PCI-E loss. */
+	set_console(vt_move_to_console(MAX_NR_CONSOLES - 1, 1));
+#endif
+}
+
+static irqreturn_t ls2k_bmc_interrupt(int irq, void *arg)
+{
+	struct ls2k_bmc_pdata *priv = arg;
+	static unsigned long last_jiffies;
+
+	if (system_state != SYSTEM_RUNNING)
+		return IRQ_HANDLED;
+
+	/* Skip interrupt in LS2K_BMC_INT_INTERVAL */
+	if (time_after(jiffies, last_jiffies + LS2K_BMC_INT_INTERVAL)) {
+		schedule_work(&priv->bmc_reset_work);
+		last_jiffies = jiffies;
+	}
+
+	return IRQ_HANDLED;
+}
+
+/*
+ * Saves the BMC parent device (LS7A) and its own PCI configuration space registers
+ * that need to be restored after BMC reset.
+ */
+static void ls2k_bmc_save_pci_data(struct pci_dev *pdev, struct ls2k_bmc_pdata *priv)
+{
+	struct pci_dev *parent = pdev->bus->self;
+	int base, i = 0;
+
+	pci_read_config_dword(parent, PCI_COMMAND, &priv->bridge_pci_data.pci_command);
+
+	for (base = PCI_BASE_ADDRESS_0; base <= PCI_BASE_ADDRESS_5; base += 4, i++)
+		pci_read_config_dword(parent, base, &priv->bridge_pci_data.base_address[i]);
+
+	pci_read_config_dword(parent, PCI_ROM_ADDRESS, &priv->bridge_pci_data.rom_addreess);
+	pci_read_config_dword(parent, PCI_INTERRUPT_LINE, &priv->bridge_pci_data.interrupt_line);
+
+	pci_read_config_dword(parent, parent->msi_cap + PCI_MSI_ADDRESS_LO,
+			      &priv->bridge_pci_data.msi_lo);
+	pci_read_config_dword(parent, parent->msi_cap + PCI_MSI_ADDRESS_HI,
+			      &priv->bridge_pci_data.msi_hi);
+
+	pci_read_config_dword(parent, parent->pcie_cap + PCI_EXP_DEVCTL,
+			      &priv->bridge_pci_data.devctl);
+	pci_read_config_dword(parent, parent->pcie_cap + PCI_EXP_LNKCAP,
+			      &priv->bridge_pci_data.linkcap);
+	pci_read_config_dword(parent, parent->pcie_cap + PCI_EXP_LNKCTL,
+			      &priv->bridge_pci_data.linkctl_sts);
+
+	pci_read_config_dword(parent, LS7A_GEN2_CTL, &priv->bridge_pci_data.gen2_ctrl);
+	priv->bridge_pci_data.gen2_ctrl |= FIELD_PREP(LS7A_GEN2_SPEED_CHANG, 0x1)
+					| FIELD_PREP(LS7A_CONF_PHY_TX, 0x0);
+
+	pci_read_config_dword(parent, LS7A_SYMBOL_TIMER, &priv->bridge_pci_data.symbol_timer);
+	priv->bridge_pci_data.symbol_timer |= LS7A_MASK_LEN_MATCH;
+
+	pci_read_config_dword(pdev, PCI_COMMAND, &priv->bmc_pci_data.pci_command);
+	pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &priv->bmc_pci_data.base_address0);
+	pci_read_config_dword(pdev, PCI_INTERRUPT_LINE, &priv->bmc_pci_data.interrupt_line);
+}
+
+static int ls2k_bmc_pdata_initial(struct pci_dev *pdev, struct ls2k_bmc_pdata *priv)
+{
+	int gsi = 16 + (LS2K_BMC_RESET_GPIO & 7);
+	void __iomem *gpio_base;
+	int irq, ret;
+
+	ls2k_bmc_save_pci_data(pdev, priv);
+
+	INIT_WORK(&priv->bmc_reset_work, ls2k_bmc_events_fn);
+
+	ret = devm_request_irq(&pdev->dev, pdev->irq, ls2k_bmc_interrupt,
+			       IRQF_SHARED | IRQF_TRIGGER_FALLING, "ls2kbmc pcie", priv);
+	if (ret) {
+		dev_err(priv->dev, "LS2KBMC PCI-E request_irq(%d) failed\n", pdev->irq);
+		return ret;
+	}
+
+	/*
+	 * Since Loongson-3 hardware does not support GPIO interrupt cascade,
+	 * chip->gpio_to_irq() cannot be implemented, here acpi_register_gsi() is used
+	 * to get the GPIO irq.
+	 * The GPIO interrupt is a watchdog interrupt that is triggered when the BMC resets.
+	 */
+	irq = acpi_register_gsi(NULL, gsi, ACPI_EDGE_SENSITIVE, ACPI_ACTIVE_LOW);
+	if (irq < 0)
+		return irq;
+
+	gpio_base = ioremap(LOONGSON_GPIO_REG_BASE, LOONGSON_GPIO_REG_SIZE);
+	if (!gpio_base) {
+		ret = PTR_ERR(gpio_base);
+		goto acpi_failed;
+	}
+
+	writel(readl(gpio_base + LOONGSON_GPIO_OEN) | BIT(LS2K_BMC_RESET_GPIO),
+	       gpio_base + LOONGSON_GPIO_OEN);
+	writel(readl(gpio_base + LOONGSON_GPIO_FUNC) & ~BIT(LS2K_BMC_RESET_GPIO),
+	       gpio_base + LOONGSON_GPIO_FUNC);
+	writel(readl(gpio_base + LOONGSON_GPIO_INTPOL) & ~BIT(LS2K_BMC_RESET_GPIO),
+	       gpio_base + LOONGSON_GPIO_INTPOL);
+	writel(readl(gpio_base + LOONGSON_GPIO_INTEN) | BIT(LS2K_BMC_RESET_GPIO),
+	       gpio_base + LOONGSON_GPIO_INTEN);
+
+	ret = devm_request_irq(priv->dev, irq, ls2k_bmc_interrupt,
+			       IRQF_SHARED | IRQF_TRIGGER_FALLING, "ls2kbmc gpio", priv);
+	if (ret)
+		dev_err(priv->dev, "LS2KBMC GPIO request_irq(%d) failed\n", irq);
+
+	iounmap(gpio_base);
+
+acpi_failed:
+	acpi_unregister_gsi(gsi);
+	return ret;
+}
+
 /*
  * Currently the Loongson-2K BMC hardware does not have an I2C interface to adapt to the
  * resolution. We set the resolution by presetting "video=1280x1024-16@2M" to the BMC memory.
@@ -101,6 +417,7 @@ static int ls2k_bmc_parse_mode(struct pci_dev *pdev, struct simplefb_platform_da
 static int ls2k_bmc_probe(struct pci_dev *dev, const struct pci_device_id *id)
 {
 	struct simplefb_platform_data pd;
+	struct ls2k_bmc_pdata *priv;
 	resource_size_t base;
 	int ret;
 
@@ -108,6 +425,18 @@ static int ls2k_bmc_probe(struct pci_dev *dev, const struct pci_device_id *id)
 	if (ret)
 		return ret;
 
+	priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL);
+	if (IS_ERR(priv)) {
+		ret = -ENOMEM;
+		goto disable_pci;
+	}
+
+	priv->dev = &dev->dev;
+
+	ret = ls2k_bmc_pdata_initial(dev, priv);
+	if (ret)
+		goto disable_pci;
+
 	ret = ls2k_bmc_parse_mode(dev, &pd);
 	if (ret)
 		goto disable_pci;
Signature · 1 line
2.47.1

Binbin Zhou

author maintainer
#0 lore raw

v4 cover LoongArch: Add Loongson-2K BMC support

Hi all:

This patch set introduces the Loongson-2K BMC.

It is a PCIe device present on servers similar to the Loongson-3 CPUs. And it is a multifunctional device (MFD), such as display as a sub-function of it.

For IPMI, according to the existing design, we use software simulation to implement the KCS interface registers: Stauts/Command/Data_Out/Data_In.

Also since both host side and BMC side read and write kcs status, we use fifo pointer to ensure data consistency.

For the display, based on simpledrm, the resolution is read from a fixed position in the BMC since the hardware does not support auto-detection of the resolution. Of course, we will try to support multiple resolutions later, through a vbios-like approach.

Especially, for the BMC reset function, since the display will be disconnected when BMC reset, we made a special treatment of re-push.

Based on this, I will present it in four patches:
patch-1: BMC device PCI resource allocation.
patch-2: BMC reset function support
patch-3: IPMI implementation

Thanks.

-------
V4:
- Add Reviewed-by tag;
- Change the order of the patches.
Patch (1/3):
- Fix build warning by lkp: Kconfig tristate -> bool
- https://lore.kernel.org/all/[email protected]/
- Update commit message;
- Move MFD_LS2K_BMC after MFD_INTEL_M10_BMC_PMCI in Kconfig and Makefile.
Patch (2/3):
- Remove unnecessary newlines;
- Rename ls2k_bmc_check_pcie_connected() to

    ls2k_bmc_pcie_is_connected();

- Update comment message.
Patch (3/3):
- Remove unnecessary newlines.

Link to V3:
https://lore.kernel.org/all/[email protected]/

V3:
Patch (1/3):
- Drop "MFD" in title and comment;
- Fromatting code;
- Add clearer comments.
Patch (2/3):
- Rebase linux-ipmi/next tree;
- Use readx()/writex() to read and write IPMI data instead of structure pointer references;
- CONFIG_LOONGARCH -> MFD_LS2K_BMC;
- Drop unused output.
Patch (3/3):
- Inline the ls2k_bmc_gpio_reset_handler() function to ls2k_bmc_pdata_initial();
- Add clearer comments.
- Use proper multi-line commentary as per the Coding Style documentation;
- Define all magic numbers.

Link to V2:
https://lore.kernel.org/all/[email protected]/

V2:
- Drop ls2kdrm, use simpledrm instead.
Patch (1/3):
- Use DEFINE_RES_MEM_NAMED/MFD_CELL_RES simplified code;
- Add resolution fetching due to replacing the original display solution with simpledrm;
- Add aperture_remove_conflicting_devices() to avoid efifb conflict with simpledrm.
Patch (3/3):
- This part of the function, moved from the original ls2kdrm to mfd;
- Use set_console to implement the Re-push display function.

Link to V1:
https://lore.kernel.org/all/[email protected]/

Binbin Zhou (3):
mfd: ls2kbmc: Introduce Loongson-2K BMC core driver
mfd: ls2kbmc: Add Loongson-2K BMC reset function support
ipmi: Add Loongson-2K BMC support

 drivers/char/ipmi/Makefile       |   1 +
 drivers/char/ipmi/ipmi_si.h      |   7 +
 drivers/char/ipmi/ipmi_si_intf.c |   3 +
 drivers/char/ipmi/ipmi_si_ls2k.c | 189 ++++++++++++
 drivers/mfd/Kconfig              |  12 +
 drivers/mfd/Makefile             |   2 +
 drivers/mfd/ls2kbmc-mfd.c        | 485 +++++++++++++++++++++++++++++++
 7 files changed, 699 insertions(+)
 create mode 100644 drivers/char/ipmi/ipmi_si_ls2k.c
 create mode 100644 drivers/mfd/ls2kbmc-mfd.c

base-commit: cd2e103d57e5615f9bb027d772f93b9efd567224

Signature · 1 line
2.47.1
author maintainer
#3 lore raw

PATCH v4 3/3 ipmi: Add Loongson-2K BMC support

This patch adds Loongson-2K BMC IPMI support.

According to the existing design, we use software simulation to implement the KCS interface registers: Stauts/Command/Data_Out/Data_In.

Also since both host side and BMC side read and write kcs status, fifo flag is used to ensure data consistency.

The single KCS message block is as follows:

+-------------------------------------------------------------------------+
|FIFO flags| KCS register data | CMD data | KCS version | WR REQ | WR ACK |
+-------------------------------------------------------------------------+
---
 drivers/char/ipmi/Makefile       |   1 +
 drivers/char/ipmi/ipmi_si.h      |   7 ++
 drivers/char/ipmi/ipmi_si_intf.c |   3 +
 drivers/char/ipmi/ipmi_si_ls2k.c | 189 +++++++++++++++++++++++++++++++
 4 files changed, 200 insertions(+)
 create mode 100644 drivers/char/ipmi/ipmi_si_ls2k.c
drivers/char/ipmi/Makefile +1 -0
index e0944547c9d0..17308dd6be20 100644
@@ -8,6 +8,7 @@ ipmi_si-y := ipmi_si_intf.o ipmi_kcs_sm.o ipmi_smic_sm.o ipmi_bt_sm.o \
 	ipmi_si_mem_io.o
 ipmi_si-$(CONFIG_HAS_IOPORT) += ipmi_si_port_io.o
 ipmi_si-$(CONFIG_PCI) += ipmi_si_pci.o
+ipmi_si-$(CONFIG_MFD_LS2K_BMC) += ipmi_si_ls2k.o
 ipmi_si-$(CONFIG_PARISC) += ipmi_si_parisc.o
 
 obj-$(CONFIG_IPMI_HANDLER) += ipmi_msghandler.o
drivers/char/ipmi/ipmi_si.h +7 -0
index 508c3fd45877..f38ea4f4c891 100644
@@ -101,6 +101,13 @@ void ipmi_si_pci_shutdown(void);
 static inline void ipmi_si_pci_init(void) { }
 static inline void ipmi_si_pci_shutdown(void) { }
 #endif
+#ifdef CONFIG_MFD_LS2K_BMC
+void ipmi_si_ls2k_init(void);
+void ipmi_si_ls2k_shutdown(void);
+#else
+static inline void ipmi_si_ls2k_init(void) { }
+static inline void ipmi_si_ls2k_shutdown(void) { }
+#endif
 #ifdef CONFIG_PARISC
 void ipmi_si_parisc_init(void);
 void ipmi_si_parisc_shutdown(void);
drivers/char/ipmi/ipmi_si_intf.c +4 -0
index 7fe891783a37..c13d5132fffc 100644
@@ -2120,6 +2120,8 @@ static int __init init_ipmi_si(void)
 
 	ipmi_si_pci_init();
 
+	ipmi_si_ls2k_init();
+
 	ipmi_si_parisc_init();
 
 	mutex_lock(&smi_infos_lock);
@@ -2334,6 +2335,8 @@ static void cleanup_ipmi_si(void)
 
 	ipmi_si_pci_shutdown();
 
+	ipmi_si_ls2k_shutdown();
+
 	ipmi_si_parisc_shutdown();
 
 	ipmi_si_platform_shutdown();
drivers/char/ipmi/ipmi_si_ls2k.c new file +189 -0

189 lines not on this page · raw message

Signature · 1 line
2.47.1
maintainer
#4 lore raw
In reply to Binbin Zhou
Quoted 7 lines · Binbin Zhou

Hi all:

This patch set introduces the Loongson-2K BMC.

It is a PCIe device present on servers similar to the Loongson-3 CPUs. And it is a multifunctional device (MFD), such as display as a sub-function of it.

I've asked this before, but I haven't gotten a answer, I don't think.

Is this really a multi-function device? Is there (or will there be) another driver that uses the MFD code?

If nothing else is going to use this, then it's really not a multi-function device and all the code can go into the IPMI directory. That simplifies maintenance.

If it is a multi-function device, then I want two separate Kconfig items, one for the MFD and one for the IPMI portion. That way it's ready and you don't have to bother about the IPMI portion when adding the other device.

All else looks good, I think.

-corey

Quoted 99 lines

For IPMI, according to the existing design, we use software simulation to implement the KCS interface registers: Stauts/Command/Data_Out/Data_In.

Also since both host side and BMC side read and write kcs status, we use fifo pointer to ensure data consistency.

For the display, based on simpledrm, the resolution is read from a fixed position in the BMC since the hardware does not support auto-detection of the resolution. Of course, we will try to support multiple resolutions later, through a vbios-like approach.

Especially, for the BMC reset function, since the display will be disconnected when BMC reset, we made a special treatment of re-push.

Based on this, I will present it in four patches:
patch-1: BMC device PCI resource allocation.
patch-2: BMC reset function support
patch-3: IPMI implementation

Thanks.

-------
V4:
- Add Reviewed-by tag;
- Change the order of the patches.
Patch (1/3):
- Fix build warning by lkp: Kconfig tristate -> bool
- https://lore.kernel.org/all/[email protected]/
- Update commit message;
- Move MFD_LS2K_BMC after MFD_INTEL_M10_BMC_PMCI in Kconfig and Makefile.
Patch (2/3):
- Remove unnecessary newlines;
- Rename ls2k_bmc_check_pcie_connected() to

    ls2k_bmc_pcie_is_connected();

- Update comment message.
Patch (3/3):
- Remove unnecessary newlines.

Link to V3:
https://lore.kernel.org/all/[email protected]/

V3:
Patch (1/3):
- Drop "MFD" in title and comment;
- Fromatting code;
- Add clearer comments.
Patch (2/3):
- Rebase linux-ipmi/next tree;
- Use readx()/writex() to read and write IPMI data instead of structure pointer references;
- CONFIG_LOONGARCH -> MFD_LS2K_BMC;
- Drop unused output.
Patch (3/3):
- Inline the ls2k_bmc_gpio_reset_handler() function to ls2k_bmc_pdata_initial();
- Add clearer comments.
- Use proper multi-line commentary as per the Coding Style documentation;
- Define all magic numbers.

Link to V2:
https://lore.kernel.org/all/[email protected]/

V2:
- Drop ls2kdrm, use simpledrm instead.
Patch (1/3):
- Use DEFINE_RES_MEM_NAMED/MFD_CELL_RES simplified code;
- Add resolution fetching due to replacing the original display solution with simpledrm;
- Add aperture_remove_conflicting_devices() to avoid efifb conflict with simpledrm.
Patch (3/3):
- This part of the function, moved from the original ls2kdrm to mfd;
- Use set_console to implement the Re-push display function.

Link to V1:
https://lore.kernel.org/all/[email protected]/

Binbin Zhou (3):
mfd: ls2kbmc: Introduce Loongson-2K BMC core driver
mfd: ls2kbmc: Add Loongson-2K BMC reset function support
ipmi: Add Loongson-2K BMC support

 drivers/char/ipmi/Makefile       |   1 +
 drivers/char/ipmi/ipmi_si.h      |   7 +
 drivers/char/ipmi/ipmi_si_intf.c |   3 +
 drivers/char/ipmi/ipmi_si_ls2k.c | 189 ++++++++++++
 drivers/mfd/Kconfig              |  12 +
 drivers/mfd/Makefile             |   2 +
 drivers/mfd/ls2kbmc-mfd.c        | 485 +++++++++++++++++++++++++++++++
 7 files changed, 699 insertions(+)
 create mode 100644 drivers/char/ipmi/ipmi_si_ls2k.c
 create mode 100644 drivers/mfd/ls2kbmc-mfd.c

base-commit: cd2e103d57e5615f9bb027d772f93b9efd567224

Signature · 1 line
2.47.1
#5 lore raw

Hi Corey:

Quoted 6 lines · Corey Minyard
Quoted 4 lines · Binbin Zhou

Hi all:

This patch set introduces the Loongson-2K BMC.

Quoted 8 lines
Quoted 3 lines

It is a PCIe device present on servers similar to the Loongson-3 CPUs. And it is a multifunctional device (MFD), such as display as a sub-function of it.

I've asked this before, but I haven't gotten a answer, I don't think.

Is this really a multi-function device? Is there (or will there be) another driver that uses the MFD code?

I am very sorry, I may have overlooked your previous question.

And I also may not have a thorough understanding of multifunction devices.

The Loongson-2K BMC device provides two functions: display and IPMI. For display, we pass the simplefb_platform_data parameter and register the simpledrm device, as shown in patch-1.

Therefore, I think this should be considered a multifunction device.

Quoted 113 lines

If nothing else is going to use this, then it's really not a multi-function device and all the code can go into the IPMI directory. That simplifies maintenance.

If it is a multi-function device, then I want two separate Kconfig items, one for the MFD and one for the IPMI portion. That way it's ready and you don't have to bother about the IPMI portion when adding the other device.

All else looks good, I think.

-corey

Quoted 99 lines

For IPMI, according to the existing design, we use software simulation to implement the KCS interface registers: Stauts/Command/Data_Out/Data_In.

Also since both host side and BMC side read and write kcs status, we use fifo pointer to ensure data consistency.

For the display, based on simpledrm, the resolution is read from a fixed position in the BMC since the hardware does not support auto-detection of the resolution. Of course, we will try to support multiple resolutions later, through a vbios-like approach.

Especially, for the BMC reset function, since the display will be disconnected when BMC reset, we made a special treatment of re-push.

Based on this, I will present it in four patches:
patch-1: BMC device PCI resource allocation.
patch-2: BMC reset function support
patch-3: IPMI implementation

Thanks.

-------
V4:
- Add Reviewed-by tag;
- Change the order of the patches.
Patch (1/3):
- Fix build warning by lkp: Kconfig tristate -> bool
- https://lore.kernel.org/all/[email protected]/
- Update commit message;
- Move MFD_LS2K_BMC after MFD_INTEL_M10_BMC_PMCI in Kconfig and Makefile.
Patch (2/3):
- Remove unnecessary newlines;
- Rename ls2k_bmc_check_pcie_connected() to

    ls2k_bmc_pcie_is_connected();

- Update comment message.
Patch (3/3):
- Remove unnecessary newlines.

Link to V3:
https://lore.kernel.org/all/[email protected]/

V3:
Patch (1/3):
- Drop "MFD" in title and comment;
- Fromatting code;
- Add clearer comments.
Patch (2/3):
- Rebase linux-ipmi/next tree;
- Use readx()/writex() to read and write IPMI data instead of structure pointer references;
- CONFIG_LOONGARCH -> MFD_LS2K_BMC;
- Drop unused output.
Patch (3/3):
- Inline the ls2k_bmc_gpio_reset_handler() function to ls2k_bmc_pdata_initial();
- Add clearer comments.
- Use proper multi-line commentary as per the Coding Style documentation;
- Define all magic numbers.

Link to V2:
https://lore.kernel.org/all/[email protected]/

V2:
- Drop ls2kdrm, use simpledrm instead.
Patch (1/3):
- Use DEFINE_RES_MEM_NAMED/MFD_CELL_RES simplified code;
- Add resolution fetching due to replacing the original display solution with simpledrm;
- Add aperture_remove_conflicting_devices() to avoid efifb conflict with simpledrm.
Patch (3/3):
- This part of the function, moved from the original ls2kdrm to mfd;
- Use set_console to implement the Re-push display function.

Link to V1:
https://lore.kernel.org/all/[email protected]/

Binbin Zhou (3):
mfd: ls2kbmc: Introduce Loongson-2K BMC core driver
mfd: ls2kbmc: Add Loongson-2K BMC reset function support
ipmi: Add Loongson-2K BMC support

 drivers/char/ipmi/Makefile       |   1 +
 drivers/char/ipmi/ipmi_si.h      |   7 +
 drivers/char/ipmi/ipmi_si_intf.c |   3 +
 drivers/char/ipmi/ipmi_si_ls2k.c | 189 ++++++++++++
 drivers/mfd/Kconfig              |  12 +
 drivers/mfd/Makefile             |   2 +
 drivers/mfd/ls2kbmc-mfd.c        | 485 +++++++++++++++++++++++++++++++
 7 files changed, 699 insertions(+)
 create mode 100644 drivers/char/ipmi/ipmi_si_ls2k.c
 create mode 100644 drivers/mfd/ls2kbmc-mfd.c

base-commit: cd2e103d57e5615f9bb027d772f93b9efd567224 --
2.47.1

Signature · 2 lines
Thanks.
Binbin
maintainer
#6 lore raw
Quoted 20 lines · Binbin Zhou

Hi Corey:

Quoted 6 lines · Corey Minyard
Quoted 4 lines · Binbin Zhou

Hi all:

This patch set introduces the Loongson-2K BMC.

Quoted 8 lines
Quoted 3 lines

It is a PCIe device present on servers similar to the Loongson-3 CPUs. And it is a multifunctional device (MFD), such as display as a sub-function of it.

I've asked this before, but I haven't gotten a answer, I don't think.

Is this really a multi-function device? Is there (or will there be) another driver that uses the MFD code?

I am very sorry, I may have overlooked your previous question.

Quoted 7 lines

And I also may not have a thorough understanding of multifunction devices.

The Loongson-2K BMC device provides two functions: display and IPMI. For display, we pass the simplefb_platform_data parameter and register the simpledrm device, as shown in patch-1.

Therefore, I think this should be considered a multifunction device.

Ok, that's clear, thank you.

However, that's not really very clear from the patches you have provided. Particularly, the "bmc" in the name from patch 1 makes one think that it's only a bmc.

The "bmc" name is also a little confusing; the devices with a "bmc" in the name are all the BMC side, but you are doing a host side device.

If you look at most of the other MFDs, they have a "core" section then various other parts that use the core. And possibly parts in other directories for individual functions. I think you need to do the same design. Have a "core" section that both the display and bmc use, then a separate display and bmc driver.

That way, you can use the display without the IPMI interface, or the IPMI interface without the display.

I would like to see:

* A core mfd device named ls2k-core.c that has the core functions. It would have its own config item (MFD_LS2K) that would be selected if either the display or IPMI device is enabled.

* A separate display device in its own file with its own config item. This isn't my area, so I'm not sure where this should go.

* The IPMI device in the ipmi directory named ipmi_ls2k.c, again with it's own config item (IPMI_LS2K).

Does that make sense? I don't want to make things too hard, but that's the way pretty much everything else is done on MFDs.

Thanks,

-corey

Quoted 119 lines
Quoted 114 lines

If nothing else is going to use this, then it's really not a multi-function device and all the code can go into the IPMI directory. That simplifies maintenance.

If it is a multi-function device, then I want two separate Kconfig items, one for the MFD and one for the IPMI portion. That way it's ready and you don't have to bother about the IPMI portion when adding the other device.

All else looks good, I think.

-corey

Quoted 99 lines

For IPMI, according to the existing design, we use software simulation to implement the KCS interface registers: Stauts/Command/Data_Out/Data_In.

Also since both host side and BMC side read and write kcs status, we use fifo pointer to ensure data consistency.

For the display, based on simpledrm, the resolution is read from a fixed position in the BMC since the hardware does not support auto-detection of the resolution. Of course, we will try to support multiple resolutions later, through a vbios-like approach.

Especially, for the BMC reset function, since the display will be disconnected when BMC reset, we made a special treatment of re-push.

Based on this, I will present it in four patches:
patch-1: BMC device PCI resource allocation.
patch-2: BMC reset function support
patch-3: IPMI implementation

Thanks.

-------
V4:
- Add Reviewed-by tag;
- Change the order of the patches.
Patch (1/3):
- Fix build warning by lkp: Kconfig tristate -> bool
- https://lore.kernel.org/all/[email protected]/
- Update commit message;
- Move MFD_LS2K_BMC after MFD_INTEL_M10_BMC_PMCI in Kconfig and Makefile.
Patch (2/3):
- Remove unnecessary newlines;
- Rename ls2k_bmc_check_pcie_connected() to

    ls2k_bmc_pcie_is_connected();

- Update comment message.
Patch (3/3):
- Remove unnecessary newlines.

Link to V3:
https://lore.kernel.org/all/[email protected]/

V3:
Patch (1/3):
- Drop "MFD" in title and comment;
- Fromatting code;
- Add clearer comments.
Patch (2/3):
- Rebase linux-ipmi/next tree;
- Use readx()/writex() to read and write IPMI data instead of structure pointer references;
- CONFIG_LOONGARCH -> MFD_LS2K_BMC;
- Drop unused output.
Patch (3/3):
- Inline the ls2k_bmc_gpio_reset_handler() function to ls2k_bmc_pdata_initial();
- Add clearer comments.
- Use proper multi-line commentary as per the Coding Style documentation;
- Define all magic numbers.

Link to V2:
https://lore.kernel.org/all/[email protected]/

V2:
- Drop ls2kdrm, use simpledrm instead.
Patch (1/3):
- Use DEFINE_RES_MEM_NAMED/MFD_CELL_RES simplified code;
- Add resolution fetching due to replacing the original display solution with simpledrm;
- Add aperture_remove_conflicting_devices() to avoid efifb conflict with simpledrm.
Patch (3/3):
- This part of the function, moved from the original ls2kdrm to mfd;
- Use set_console to implement the Re-push display function.

Link to V1:
https://lore.kernel.org/all/[email protected]/

Binbin Zhou (3):
mfd: ls2kbmc: Introduce Loongson-2K BMC core driver
mfd: ls2kbmc: Add Loongson-2K BMC reset function support
ipmi: Add Loongson-2K BMC support

 drivers/char/ipmi/Makefile       |   1 +
 drivers/char/ipmi/ipmi_si.h      |   7 +
 drivers/char/ipmi/ipmi_si_intf.c |   3 +
 drivers/char/ipmi/ipmi_si_ls2k.c | 189 ++++++++++++
 drivers/mfd/Kconfig              |  12 +
 drivers/mfd/Makefile             |   2 +
 drivers/mfd/ls2kbmc-mfd.c        | 485 +++++++++++++++++++++++++++++++
 7 files changed, 699 insertions(+)
 create mode 100644 drivers/char/ipmi/ipmi_si_ls2k.c
 create mode 100644 drivers/mfd/ls2kbmc-mfd.c

base-commit: cd2e103d57e5615f9bb027d772f93b9efd567224 --
2.47.1

Signature · 2 lines
Thanks.
Binbin
#7 lore raw

Hi Corey:

Thanks for your detailed suggestions.

Quoted 36 lines · Corey Minyard
Quoted 20 lines · Binbin Zhou

Hi Corey:

Quoted 6 lines · Corey Minyard
Quoted 4 lines · Binbin Zhou

Hi all:

This patch set introduces the Loongson-2K BMC.

Quoted 8 lines
Quoted 3 lines

It is a PCIe device present on servers similar to the Loongson-3 CPUs. And it is a multifunctional device (MFD), such as display as a sub-function of it.

I've asked this before, but I haven't gotten a answer, I don't think.

Is this really a multi-function device? Is there (or will there be) another driver that uses the MFD code?

I am very sorry, I may have overlooked your previous question.

Quoted 7 lines

And I also may not have a thorough understanding of multifunction devices.

The Loongson-2K BMC device provides two functions: display and IPMI. For display, we pass the simplefb_platform_data parameter and register the simpledrm device, as shown in patch-1.

Therefore, I think this should be considered a multifunction device.

Ok, that's clear, thank you.

However, that's not really very clear from the patches you have provided. Particularly, the "bmc" in the name from patch 1 makes one think that it's only a bmc.

Quoted 8 lines

The "bmc" name is also a little confusing; the devices with a "bmc" in the name are all the BMC side, but you are doing a host side device.

If you look at most of the other MFDs, they have a "core" section then various other parts that use the core. And possibly parts in other directories for individual functions. I think you need to do the same design. Have a "core" section that both the display and bmc use, then a separate display and bmc driver.

If it can be reconstructed in this way, it should be clearer.

However, there is a key point in my mind: if the display and IPMI are separated into two parts, they should at least be able to be probed separately, but in fact they belong to the same PCI-E device, just allocated different resource intervals.

static struct pci_device_id ls2k_bmc_devices[] = {
       { PCI_DEVICE(PCI_VENDOR_ID_LOONGSON, 0x1a05) },
       { }
};

MODULE_DEVICE_TABLE(pci, ls2k_bmc_devices);

I'm not sure if my understanding is correct?

Quoted 142 lines

That way, you can use the display without the IPMI interface, or the IPMI interface without the display.

I would like to see:

* A core mfd device named ls2k-core.c that has the core functions. It would have its own config item (MFD_LS2K) that would be selected if either the display or IPMI device is enabled.

* A separate display device in its own file with its own config item. This isn't my area, so I'm not sure where this should go.

* The IPMI device in the ipmi directory named ipmi_ls2k.c, again with it's own config item (IPMI_LS2K).

Does that make sense? I don't want to make things too hard, but that's the way pretty much everything else is done on MFDs.

Thanks,

-corey

Quoted 119 lines
Quoted 6 lines

If nothing else is going to use this, then it's really not a multi-function device and all the code can go into the IPMI directory. That simplifies maintenance.

Quoted 108 lines

If it is a multi-function device, then I want two separate Kconfig items, one for the MFD and one for the IPMI portion. That way it's ready and you don't have to bother about the IPMI portion when adding the other device.

All else looks good, I think.

-corey

Quoted 99 lines

For IPMI, according to the existing design, we use software simulation to implement the KCS interface registers: Stauts/Command/Data_Out/Data_In.

Also since both host side and BMC side read and write kcs status, we use fifo pointer to ensure data consistency.

For the display, based on simpledrm, the resolution is read from a fixed position in the BMC since the hardware does not support auto-detection of the resolution. Of course, we will try to support multiple resolutions later, through a vbios-like approach.

Especially, for the BMC reset function, since the display will be disconnected when BMC reset, we made a special treatment of re-push.

Based on this, I will present it in four patches:
patch-1: BMC device PCI resource allocation.
patch-2: BMC reset function support
patch-3: IPMI implementation

Thanks.

-------
V4:
- Add Reviewed-by tag;
- Change the order of the patches.
Patch (1/3):
- Fix build warning by lkp: Kconfig tristate -> bool
- https://lore.kernel.org/all/[email protected]/
- Update commit message;
- Move MFD_LS2K_BMC after MFD_INTEL_M10_BMC_PMCI in Kconfig and Makefile.
Patch (2/3):
- Remove unnecessary newlines;
- Rename ls2k_bmc_check_pcie_connected() to

    ls2k_bmc_pcie_is_connected();

- Update comment message.
Patch (3/3):
- Remove unnecessary newlines.

Link to V3:
https://lore.kernel.org/all/[email protected]/

V3:
Patch (1/3):
- Drop "MFD" in title and comment;
- Fromatting code;
- Add clearer comments.
Patch (2/3):
- Rebase linux-ipmi/next tree;
- Use readx()/writex() to read and write IPMI data instead of structure pointer references;
- CONFIG_LOONGARCH -> MFD_LS2K_BMC;
- Drop unused output.
Patch (3/3):
- Inline the ls2k_bmc_gpio_reset_handler() function to ls2k_bmc_pdata_initial();
- Add clearer comments.
- Use proper multi-line commentary as per the Coding Style documentation;
- Define all magic numbers.

Link to V2:
https://lore.kernel.org/all/[email protected]/

V2:
- Drop ls2kdrm, use simpledrm instead.
Patch (1/3):
- Use DEFINE_RES_MEM_NAMED/MFD_CELL_RES simplified code;
- Add resolution fetching due to replacing the original display solution with simpledrm;
- Add aperture_remove_conflicting_devices() to avoid efifb conflict with simpledrm.
Patch (3/3):
- This part of the function, moved from the original ls2kdrm to mfd;
- Use set_console to implement the Re-push display function.

Link to V1:
https://lore.kernel.org/all/[email protected]/

Binbin Zhou (3):
mfd: ls2kbmc: Introduce Loongson-2K BMC core driver
mfd: ls2kbmc: Add Loongson-2K BMC reset function support
ipmi: Add Loongson-2K BMC support

 drivers/char/ipmi/Makefile       |   1 +
 drivers/char/ipmi/ipmi_si.h      |   7 +
 drivers/char/ipmi/ipmi_si_intf.c |   3 +
 drivers/char/ipmi/ipmi_si_ls2k.c | 189 ++++++++++++
 drivers/mfd/Kconfig              |  12 +
 drivers/mfd/Makefile             |   2 +
 drivers/mfd/ls2kbmc-mfd.c        | 485 +++++++++++++++++++++++++++++++
 7 files changed, 699 insertions(+)
 create mode 100644 drivers/char/ipmi/ipmi_si_ls2k.c
 create mode 100644 drivers/mfd/ls2kbmc-mfd.c

base-commit: cd2e103d57e5615f9bb027d772f93b9efd567224 --
2.47.1

--
Thanks.
Binbin

Signature · 2 lines
Thanks.
Binbin
maintainer
#8 lore raw
Quoted 57 lines · Binbin Zhou

Hi Corey:

Thanks for your detailed suggestions.

Quoted 36 lines · Corey Minyard
Quoted 20 lines · Binbin Zhou

Hi Corey:

Quoted 6 lines · Corey Minyard
Quoted 4 lines · Binbin Zhou

Hi all:

This patch set introduces the Loongson-2K BMC.

Quoted 8 lines
Quoted 3 lines

It is a PCIe device present on servers similar to the Loongson-3 CPUs. And it is a multifunctional device (MFD), such as display as a sub-function of it.

I've asked this before, but I haven't gotten a answer, I don't think.

Is this really a multi-function device? Is there (or will there be) another driver that uses the MFD code?

I am very sorry, I may have overlooked your previous question.

Quoted 7 lines

And I also may not have a thorough understanding of multifunction devices.

The Loongson-2K BMC device provides two functions: display and IPMI. For display, we pass the simplefb_platform_data parameter and register the simpledrm device, as shown in patch-1.

Therefore, I think this should be considered a multifunction device.

Ok, that's clear, thank you.

However, that's not really very clear from the patches you have provided. Particularly, the "bmc" in the name from patch 1 makes one think that it's only a bmc.

Quoted 8 lines

The "bmc" name is also a little confusing; the devices with a "bmc" in the name are all the BMC side, but you are doing a host side device.

If you look at most of the other MFDs, they have a "core" section then various other parts that use the core. And possibly parts in other directories for individual functions. I think you need to do the same design. Have a "core" section that both the display and bmc use, then a separate display and bmc driver.

If it can be reconstructed in this way, it should be clearer.

However, there is a key point in my mind: if the display and IPMI are separated into two parts, they should at least be able to be probed separately, but in fact they belong to the same PCI-E device, just allocated different resource intervals.

Quoted 7 lines
static struct pci_device_id ls2k_bmc_devices[] = {
       { PCI_DEVICE(PCI_VENDOR_ID_LOONGSON, 0x1a05) },
       { }
};

MODULE_DEVICE_TABLE(pci, ls2k_bmc_devices);

I'm not sure if my understanding is correct?

You are already doing this, it appears. I spent a little time to learn how this works. You are using the standard frame buffer driver, so no special driver is required there (per earlier discussions). And you are registering it all as an MFD device, so the display buffer and IPMI interface will pick it up there.

So from a design point of view this all looks good.

The IPMI interface needs to be separately selectable from the main mfd device in the Kconfigs. Add an IPMI_LS2K config in the IPMI section that enables the IPMI interface and selects MFD_LS2K_BMC. And both configs need to be tristate, not bool, so they can be modules.

I don't know if you want to make the display part so it can be enabled separately, I'm not sure how you would do that. But that's not my concern, really.

Thanks,

-corey

Quoted 147 lines
Quoted 143 lines

That way, you can use the display without the IPMI interface, or the IPMI interface without the display.

I would like to see:

* A core mfd device named ls2k-core.c that has the core functions. It would have its own config item (MFD_LS2K) that would be selected if either the display or IPMI device is enabled.

* A separate display device in its own file with its own config item. This isn't my area, so I'm not sure where this should go.

* The IPMI device in the ipmi directory named ipmi_ls2k.c, again with it's own config item (IPMI_LS2K).

Does that make sense? I don't want to make things too hard, but that's the way pretty much everything else is done on MFDs.

Thanks,

-corey

Quoted 119 lines
Quoted 6 lines

If nothing else is going to use this, then it's really not a multi-function device and all the code can go into the IPMI directory. That simplifies maintenance.

Quoted 108 lines

If it is a multi-function device, then I want two separate Kconfig items, one for the MFD and one for the IPMI portion. That way it's ready and you don't have to bother about the IPMI portion when adding the other device.

All else looks good, I think.

-corey

Quoted 99 lines

For IPMI, according to the existing design, we use software simulation to implement the KCS interface registers: Stauts/Command/Data_Out/Data_In.

Also since both host side and BMC side read and write kcs status, we use fifo pointer to ensure data consistency.

For the display, based on simpledrm, the resolution is read from a fixed position in the BMC since the hardware does not support auto-detection of the resolution. Of course, we will try to support multiple resolutions later, through a vbios-like approach.

Especially, for the BMC reset function, since the display will be disconnected when BMC reset, we made a special treatment of re-push.

Based on this, I will present it in four patches:
patch-1: BMC device PCI resource allocation.
patch-2: BMC reset function support
patch-3: IPMI implementation

Thanks.

-------
V4:
- Add Reviewed-by tag;
- Change the order of the patches.
Patch (1/3):
- Fix build warning by lkp: Kconfig tristate -> bool
- https://lore.kernel.org/all/[email protected]/
- Update commit message;
- Move MFD_LS2K_BMC after MFD_INTEL_M10_BMC_PMCI in Kconfig and Makefile.
Patch (2/3):
- Remove unnecessary newlines;
- Rename ls2k_bmc_check_pcie_connected() to

    ls2k_bmc_pcie_is_connected();

- Update comment message.
Patch (3/3):
- Remove unnecessary newlines.

Link to V3:
https://lore.kernel.org/all/[email protected]/

V3:
Patch (1/3):
- Drop "MFD" in title and comment;
- Fromatting code;
- Add clearer comments.
Patch (2/3):
- Rebase linux-ipmi/next tree;
- Use readx()/writex() to read and write IPMI data instead of structure pointer references;
- CONFIG_LOONGARCH -> MFD_LS2K_BMC;
- Drop unused output.
Patch (3/3):
- Inline the ls2k_bmc_gpio_reset_handler() function to ls2k_bmc_pdata_initial();
- Add clearer comments.
- Use proper multi-line commentary as per the Coding Style documentation;
- Define all magic numbers.

Link to V2:
https://lore.kernel.org/all/[email protected]/

V2:
- Drop ls2kdrm, use simpledrm instead.
Patch (1/3):
- Use DEFINE_RES_MEM_NAMED/MFD_CELL_RES simplified code;
- Add resolution fetching due to replacing the original display solution with simpledrm;
- Add aperture_remove_conflicting_devices() to avoid efifb conflict with simpledrm.
Patch (3/3):
- This part of the function, moved from the original ls2kdrm to mfd;
- Use set_console to implement the Re-push display function.

Link to V1:
https://lore.kernel.org/all/[email protected]/

Binbin Zhou (3):
mfd: ls2kbmc: Introduce Loongson-2K BMC core driver
mfd: ls2kbmc: Add Loongson-2K BMC reset function support
ipmi: Add Loongson-2K BMC support

 drivers/char/ipmi/Makefile       |   1 +
 drivers/char/ipmi/ipmi_si.h      |   7 +
 drivers/char/ipmi/ipmi_si_intf.c |   3 +
 drivers/char/ipmi/ipmi_si_ls2k.c | 189 ++++++++++++
 drivers/mfd/Kconfig              |  12 +
 drivers/mfd/Makefile             |   2 +
 drivers/mfd/ls2kbmc-mfd.c        | 485 +++++++++++++++++++++++++++++++
 7 files changed, 699 insertions(+)
 create mode 100644 drivers/char/ipmi/ipmi_si_ls2k.c
 create mode 100644 drivers/mfd/ls2kbmc-mfd.c

base-commit: cd2e103d57e5615f9bb027d772f93b9efd567224 --
2.47.1

--
Thanks.
Binbin

Signature · 2 lines
Thanks.
Binbin
#9 lore raw

Hi Corey:

Thanks for your detailed review.

Quoted 73 lines · Corey Minyard
Quoted 57 lines · Binbin Zhou

Hi Corey:

Thanks for your detailed suggestions.

Quoted 36 lines · Corey Minyard
Quoted 20 lines · Binbin Zhou

Hi Corey:

Quoted 6 lines · Corey Minyard
Quoted 4 lines · Binbin Zhou

Hi all:

This patch set introduces the Loongson-2K BMC.

Quoted 8 lines
Quoted 3 lines

It is a PCIe device present on servers similar to the Loongson-3 CPUs. And it is a multifunctional device (MFD), such as display as a sub-function of it.

I've asked this before, but I haven't gotten a answer, I don't think.

Is this really a multi-function device? Is there (or will there be) another driver that uses the MFD code?

I am very sorry, I may have overlooked your previous question.

Quoted 7 lines

And I also may not have a thorough understanding of multifunction devices.

The Loongson-2K BMC device provides two functions: display and IPMI. For display, we pass the simplefb_platform_data parameter and register the simpledrm device, as shown in patch-1.

Therefore, I think this should be considered a multifunction device.

Ok, that's clear, thank you.

However, that's not really very clear from the patches you have provided. Particularly, the "bmc" in the name from patch 1 makes one think that it's only a bmc.

Quoted 8 lines

The "bmc" name is also a little confusing; the devices with a "bmc" in the name are all the BMC side, but you are doing a host side device.

If you look at most of the other MFDs, they have a "core" section then various other parts that use the core. And possibly parts in other directories for individual functions. I think you need to do the same design. Have a "core" section that both the display and bmc use, then a separate display and bmc driver.

If it can be reconstructed in this way, it should be clearer.

However, there is a key point in my mind: if the display and IPMI are separated into two parts, they should at least be able to be probed separately, but in fact they belong to the same PCI-E device, just allocated different resource intervals.

Quoted 7 lines
static struct pci_device_id ls2k_bmc_devices[] = {
       { PCI_DEVICE(PCI_VENDOR_ID_LOONGSON, 0x1a05) },
       { }
};

MODULE_DEVICE_TABLE(pci, ls2k_bmc_devices);

I'm not sure if my understanding is correct?

You are already doing this, it appears. I spent a little time to learn how this works. You are using the standard frame buffer driver, so no special driver is required there (per earlier discussions). And you are registering it all as an MFD device, so the display buffer and IPMI interface will pick it up there.

Quoted 6 lines

So from a design point of view this all looks good.

The IPMI interface needs to be separately selectable from the main mfd device in the Kconfigs. Add an IPMI_LS2K config in the IPMI section that enables the IPMI interface and selects MFD_LS2K_BMC. And both configs need to be tristate, not bool, so they can be modules.

I tried rewriting Kconfig as follows:

IPMI Kconfig:

config IPMI_LS2K
bool 'Loongson-2K IPMI interface'
depends on LOONGARCH
select MFD_LS2K_BMC_CORE
help
Provides a driver for Loongson-2K IPMI interfaces.

MFD Kconfig:

config MFD_LS2K_BMC_CORE
bool "Loongson-2K Board Management Controller Support" select MFD_CORE

However, tristate does not seem to work.
On the IPMI side, in order to better reuse code, our driver is not actually a completely independent driver; it is part of ipmi_si.

drivers/char/ipmi/ipmi_si_intf.c +4 -0
index 7fe891783a37..c13d5132fffc 100644
@@ -2120,6 +2120,8 @@ static int __init init_ipmi_si(void)
 
        ipmi_si_pci_init();
 
+       ipmi_si_ls2k_init();
+
        ipmi_si_parisc_init();
 
        mutex_lock(&smi_infos_lock);
@@ -2334,6 +2335,8 @@ static void cleanup_ipmi_si(void)
 
        ipmi_si_pci_shutdown();
 
+       ipmi_si_ls2k_shutdown();
+
        ipmi_si_parisc_shutdown();
 
        ipmi_si_platform_shutdown();

Therefore, it seems that we can only use bool here, otherwise an error will occur during compilation, as seen in the V3 patchset[1]:

[1]: https://lore.kernel.org/all/[email protected]/

Quoted 156 lines

I don't know if you want to make the display part so it can be enabled separately, I'm not sure how you would do that. But that's not my concern, really.

Thanks,

-corey

Quoted 147 lines
Quoted 17 lines

That way, you can use the display without the IPMI interface, or the IPMI interface without the display.

I would like to see:

* A core mfd device named ls2k-core.c that has the core functions. It would have its own config item (MFD_LS2K) that would be selected if either the display or IPMI device is enabled.

* A separate display device in its own file with its own config item. This isn't my area, so I'm not sure where this should go.

* The IPMI device in the ipmi directory named ipmi_ls2k.c, again with it's own config item (IPMI_LS2K).

Quoted 126 lines

Does that make sense? I don't want to make things too hard, but that's the way pretty much everything else is done on MFDs.

Thanks,

-corey

Quoted 119 lines
Quoted 6 lines

If nothing else is going to use this, then it's really not a multi-function device and all the code can go into the IPMI directory. That simplifies maintenance.

Quoted 108 lines

If it is a multi-function device, then I want two separate Kconfig items, one for the MFD and one for the IPMI portion. That way it's ready and you don't have to bother about the IPMI portion when adding the other device.

All else looks good, I think.

-corey

Quoted 99 lines

For IPMI, according to the existing design, we use software simulation to implement the KCS interface registers: Stauts/Command/Data_Out/Data_In.

Also since both host side and BMC side read and write kcs status, we use fifo pointer to ensure data consistency.

For the display, based on simpledrm, the resolution is read from a fixed position in the BMC since the hardware does not support auto-detection of the resolution. Of course, we will try to support multiple resolutions later, through a vbios-like approach.

Especially, for the BMC reset function, since the display will be disconnected when BMC reset, we made a special treatment of re-push.

Based on this, I will present it in four patches:
patch-1: BMC device PCI resource allocation.
patch-2: BMC reset function support
patch-3: IPMI implementation

Thanks.

-------
V4:
- Add Reviewed-by tag;
- Change the order of the patches.
Patch (1/3):
- Fix build warning by lkp: Kconfig tristate -> bool
- https://lore.kernel.org/all/[email protected]/
- Update commit message;
- Move MFD_LS2K_BMC after MFD_INTEL_M10_BMC_PMCI in Kconfig and Makefile.
Patch (2/3):
- Remove unnecessary newlines;
- Rename ls2k_bmc_check_pcie_connected() to

    ls2k_bmc_pcie_is_connected();

- Update comment message.
Patch (3/3):
- Remove unnecessary newlines.

Link to V3:
https://lore.kernel.org/all/[email protected]/

V3:
Patch (1/3):
- Drop "MFD" in title and comment;
- Fromatting code;
- Add clearer comments.
Patch (2/3):
- Rebase linux-ipmi/next tree;
- Use readx()/writex() to read and write IPMI data instead of structure pointer references;
- CONFIG_LOONGARCH -> MFD_LS2K_BMC;
- Drop unused output.
Patch (3/3):
- Inline the ls2k_bmc_gpio_reset_handler() function to ls2k_bmc_pdata_initial();
- Add clearer comments.
- Use proper multi-line commentary as per the Coding Style documentation;
- Define all magic numbers.

Link to V2:
https://lore.kernel.org/all/[email protected]/

V2:
- Drop ls2kdrm, use simpledrm instead.
Patch (1/3):
- Use DEFINE_RES_MEM_NAMED/MFD_CELL_RES simplified code;
- Add resolution fetching due to replacing the original display solution with simpledrm;
- Add aperture_remove_conflicting_devices() to avoid efifb conflict with simpledrm.
Patch (3/3):
- This part of the function, moved from the original ls2kdrm to mfd;
- Use set_console to implement the Re-push display function.

Link to V1:
https://lore.kernel.org/all/[email protected]/

Binbin Zhou (3):
mfd: ls2kbmc: Introduce Loongson-2K BMC core driver
mfd: ls2kbmc: Add Loongson-2K BMC reset function support
ipmi: Add Loongson-2K BMC support

 drivers/char/ipmi/Makefile       |   1 +
 drivers/char/ipmi/ipmi_si.h      |   7 +
 drivers/char/ipmi/ipmi_si_intf.c |   3 +
 drivers/char/ipmi/ipmi_si_ls2k.c | 189 ++++++++++++
 drivers/mfd/Kconfig              |  12 +
 drivers/mfd/Makefile             |   2 +
 drivers/mfd/ls2kbmc-mfd.c        | 485 +++++++++++++++++++++++++++++++
 7 files changed, 699 insertions(+)
 create mode 100644 drivers/char/ipmi/ipmi_si_ls2k.c
 create mode 100644 drivers/mfd/ls2kbmc-mfd.c

base-commit: cd2e103d57e5615f9bb027d772f93b9efd567224 --
2.47.1

--
Thanks.
Binbin

--
Thanks.
Binbin

Signature · 2 lines
Thanks.
Binbin
maintainer
#10 lore raw
Quoted 98 lines · Binbin Zhou

Hi Corey:

Thanks for your detailed review.

Quoted 73 lines · Corey Minyard
Quoted 57 lines · Binbin Zhou

Hi Corey:

Thanks for your detailed suggestions.

Quoted 36 lines · Corey Minyard
Quoted 20 lines · Binbin Zhou

Hi Corey:

Quoted 6 lines · Corey Minyard
Quoted 4 lines · Binbin Zhou

Hi all:

This patch set introduces the Loongson-2K BMC.

Quoted 8 lines
Quoted 3 lines

It is a PCIe device present on servers similar to the Loongson-3 CPUs. And it is a multifunctional device (MFD), such as display as a sub-function of it.

I've asked this before, but I haven't gotten a answer, I don't think.

Is this really a multi-function device? Is there (or will there be) another driver that uses the MFD code?

I am very sorry, I may have overlooked your previous question.

Quoted 7 lines

And I also may not have a thorough understanding of multifunction devices.

The Loongson-2K BMC device provides two functions: display and IPMI. For display, we pass the simplefb_platform_data parameter and register the simpledrm device, as shown in patch-1.

Therefore, I think this should be considered a multifunction device.

Ok, that's clear, thank you.

However, that's not really very clear from the patches you have provided. Particularly, the "bmc" in the name from patch 1 makes one think that it's only a bmc.

Quoted 8 lines

The "bmc" name is also a little confusing; the devices with a "bmc" in the name are all the BMC side, but you are doing a host side device.

If you look at most of the other MFDs, they have a "core" section then various other parts that use the core. And possibly parts in other directories for individual functions. I think you need to do the same design. Have a "core" section that both the display and bmc use, then a separate display and bmc driver.

If it can be reconstructed in this way, it should be clearer.

However, there is a key point in my mind: if the display and IPMI are separated into two parts, they should at least be able to be probed separately, but in fact they belong to the same PCI-E device, just allocated different resource intervals.

Quoted 7 lines
static struct pci_device_id ls2k_bmc_devices[] = {
       { PCI_DEVICE(PCI_VENDOR_ID_LOONGSON, 0x1a05) },
       { }
};

MODULE_DEVICE_TABLE(pci, ls2k_bmc_devices);

I'm not sure if my understanding is correct?

You are already doing this, it appears. I spent a little time to learn how this works. You are using the standard frame buffer driver, so no special driver is required there (per earlier discussions). And you are registering it all as an MFD device, so the display buffer and IPMI interface will pick it up there.

Quoted 6 lines

So from a design point of view this all looks good.

The IPMI interface needs to be separately selectable from the main mfd device in the Kconfigs. Add an IPMI_LS2K config in the IPMI section that enables the IPMI interface and selects MFD_LS2K_BMC. And both configs need to be tristate, not bool, so they can be modules.

I tried rewriting Kconfig as follows:

IPMI Kconfig:

config IPMI_LS2K
bool 'Loongson-2K IPMI interface'
depends on LOONGARCH
select MFD_LS2K_BMC_CORE
help
Provides a driver for Loongson-2K IPMI interfaces.

MFD Kconfig:

Quoted 8 lines

config MFD_LS2K_BMC_CORE
bool "Loongson-2K Board Management Controller Support" select MFD_CORE

However, tristate does not seem to work.
On the IPMI side, in order to better reuse code, our driver is not actually a completely independent driver; it is part of ipmi_si.

Ah, yes, that is true. The trouble with the above is it will select MFD_LS2K_BMC_CORE as "y" even if ipmi_si is a module. And that will force MFD_CORE to be "y" as well. At least I think it works that way. Anyway, that's not terrible, but it would be nice to have the core code as a module if possible.

Another issue is you don't have help text on MFD_LS2K_BMC_CORE code. You probably want to mention there that it enables the display on the BMC.

-corey

Quoted 190 lines
drivers/char/ipmi/ipmi_si_intf.c +4 -0
index 7fe891783a37..c13d5132fffc 100644
@@ -2120,6 +2120,8 @@ static int __init init_ipmi_si(void)
 
        ipmi_si_pci_init();
 
+       ipmi_si_ls2k_init();
+
        ipmi_si_parisc_init();
 
        mutex_lock(&smi_infos_lock);
@@ -2334,6 +2335,8 @@ static void cleanup_ipmi_si(void)
 
        ipmi_si_pci_shutdown();
 
+       ipmi_si_ls2k_shutdown();
+
        ipmi_si_parisc_shutdown();
 
        ipmi_si_platform_shutdown();

Therefore, it seems that we can only use bool here, otherwise an error will occur during compilation, as seen in the V3 patchset[1]:

[1]: https://lore.kernel.org/all/[email protected]/

Quoted 156 lines

I don't know if you want to make the display part so it can be enabled separately, I'm not sure how you would do that. But that's not my concern, really.

Thanks,

-corey

Quoted 147 lines
Quoted 17 lines

That way, you can use the display without the IPMI interface, or the IPMI interface without the display.

I would like to see:

* A core mfd device named ls2k-core.c that has the core functions. It would have its own config item (MFD_LS2K) that would be selected if either the display or IPMI device is enabled.

* A separate display device in its own file with its own config item. This isn't my area, so I'm not sure where this should go.

* The IPMI device in the ipmi directory named ipmi_ls2k.c, again with it's own config item (IPMI_LS2K).

Quoted 126 lines

Does that make sense? I don't want to make things too hard, but that's the way pretty much everything else is done on MFDs.

Thanks,

-corey

Quoted 119 lines
Quoted 6 lines

If nothing else is going to use this, then it's really not a multi-function device and all the code can go into the IPMI directory. That simplifies maintenance.

Quoted 108 lines

If it is a multi-function device, then I want two separate Kconfig items, one for the MFD and one for the IPMI portion. That way it's ready and you don't have to bother about the IPMI portion when adding the other device.

All else looks good, I think.

-corey

Quoted 99 lines

For IPMI, according to the existing design, we use software simulation to implement the KCS interface registers: Stauts/Command/Data_Out/Data_In.

Also since both host side and BMC side read and write kcs status, we use fifo pointer to ensure data consistency.

For the display, based on simpledrm, the resolution is read from a fixed position in the BMC since the hardware does not support auto-detection of the resolution. Of course, we will try to support multiple resolutions later, through a vbios-like approach.

Especially, for the BMC reset function, since the display will be disconnected when BMC reset, we made a special treatment of re-push.

Based on this, I will present it in four patches:
patch-1: BMC device PCI resource allocation.
patch-2: BMC reset function support
patch-3: IPMI implementation

Thanks.

-------
V4:
- Add Reviewed-by tag;
- Change the order of the patches.
Patch (1/3):
- Fix build warning by lkp: Kconfig tristate -> bool
- https://lore.kernel.org/all/[email protected]/
- Update commit message;
- Move MFD_LS2K_BMC after MFD_INTEL_M10_BMC_PMCI in Kconfig and Makefile.
Patch (2/3):
- Remove unnecessary newlines;
- Rename ls2k_bmc_check_pcie_connected() to

    ls2k_bmc_pcie_is_connected();

- Update comment message.
Patch (3/3):
- Remove unnecessary newlines.

Link to V3:
https://lore.kernel.org/all/[email protected]/

V3:
Patch (1/3):
- Drop "MFD" in title and comment;
- Fromatting code;
- Add clearer comments.
Patch (2/3):
- Rebase linux-ipmi/next tree;
- Use readx()/writex() to read and write IPMI data instead of structure pointer references;
- CONFIG_LOONGARCH -> MFD_LS2K_BMC;
- Drop unused output.
Patch (3/3):
- Inline the ls2k_bmc_gpio_reset_handler() function to ls2k_bmc_pdata_initial();
- Add clearer comments.
- Use proper multi-line commentary as per the Coding Style documentation;
- Define all magic numbers.

Link to V2:
https://lore.kernel.org/all/[email protected]/

V2:
- Drop ls2kdrm, use simpledrm instead.
Patch (1/3):
- Use DEFINE_RES_MEM_NAMED/MFD_CELL_RES simplified code;
- Add resolution fetching due to replacing the original display solution with simpledrm;
- Add aperture_remove_conflicting_devices() to avoid efifb conflict with simpledrm.
Patch (3/3):
- This part of the function, moved from the original ls2kdrm to mfd;
- Use set_console to implement the Re-push display function.

Link to V1:
https://lore.kernel.org/all/[email protected]/

Binbin Zhou (3):
mfd: ls2kbmc: Introduce Loongson-2K BMC core driver
mfd: ls2kbmc: Add Loongson-2K BMC reset function support
ipmi: Add Loongson-2K BMC support

 drivers/char/ipmi/Makefile       |   1 +
 drivers/char/ipmi/ipmi_si.h      |   7 +
 drivers/char/ipmi/ipmi_si_intf.c |   3 +
 drivers/char/ipmi/ipmi_si_ls2k.c | 189 ++++++++++++
 drivers/mfd/Kconfig              |  12 +
 drivers/mfd/Makefile             |   2 +
 drivers/mfd/ls2kbmc-mfd.c        | 485 +++++++++++++++++++++++++++++++
 7 files changed, 699 insertions(+)
 create mode 100644 drivers/char/ipmi/ipmi_si_ls2k.c
 create mode 100644 drivers/mfd/ls2kbmc-mfd.c

base-commit: cd2e103d57e5615f9bb027d772f93b9efd567224 --
2.47.1

--
Thanks.
Binbin

--
Thanks.
Binbin

Signature · 2 lines
Thanks.
Binbin
#11 lore raw
Quoted 115 lines · Corey Minyard
Quoted 98 lines · Binbin Zhou

Hi Corey:

Thanks for your detailed review.

Quoted 73 lines · Corey Minyard
Quoted 57 lines · Binbin Zhou

Hi Corey:

Thanks for your detailed suggestions.

Quoted 36 lines · Corey Minyard
Quoted 20 lines · Binbin Zhou

Hi Corey:

Quoted 6 lines · Corey Minyard
Quoted 4 lines · Binbin Zhou

Hi all:

This patch set introduces the Loongson-2K BMC.

Quoted 8 lines
Quoted 3 lines

It is a PCIe device present on servers similar to the Loongson-3 CPUs. And it is a multifunctional device (MFD), such as display as a sub-function of it.

I've asked this before, but I haven't gotten a answer, I don't think.

Is this really a multi-function device? Is there (or will there be) another driver that uses the MFD code?

I am very sorry, I may have overlooked your previous question.

Quoted 7 lines

And I also may not have a thorough understanding of multifunction devices.

The Loongson-2K BMC device provides two functions: display and IPMI. For display, we pass the simplefb_platform_data parameter and register the simpledrm device, as shown in patch-1.

Therefore, I think this should be considered a multifunction device.

Ok, that's clear, thank you.

However, that's not really very clear from the patches you have provided. Particularly, the "bmc" in the name from patch 1 makes one think that it's only a bmc.

Quoted 8 lines

The "bmc" name is also a little confusing; the devices with a "bmc" in the name are all the BMC side, but you are doing a host side device.

If you look at most of the other MFDs, they have a "core" section then various other parts that use the core. And possibly parts in other directories for individual functions. I think you need to do the same design. Have a "core" section that both the display and bmc use, then a separate display and bmc driver.

If it can be reconstructed in this way, it should be clearer.

However, there is a key point in my mind: if the display and IPMI are separated into two parts, they should at least be able to be probed separately, but in fact they belong to the same PCI-E device, just allocated different resource intervals.

Quoted 7 lines
static struct pci_device_id ls2k_bmc_devices[] = {
       { PCI_DEVICE(PCI_VENDOR_ID_LOONGSON, 0x1a05) },
       { }
};

MODULE_DEVICE_TABLE(pci, ls2k_bmc_devices);

I'm not sure if my understanding is correct?

You are already doing this, it appears. I spent a little time to learn how this works. You are using the standard frame buffer driver, so no special driver is required there (per earlier discussions). And you are registering it all as an MFD device, so the display buffer and IPMI interface will pick it up there.

Quoted 6 lines

So from a design point of view this all looks good.

The IPMI interface needs to be separately selectable from the main mfd device in the Kconfigs. Add an IPMI_LS2K config in the IPMI section that enables the IPMI interface and selects MFD_LS2K_BMC. And both configs need to be tristate, not bool, so they can be modules.

I tried rewriting Kconfig as follows:

IPMI Kconfig:

config IPMI_LS2K
bool 'Loongson-2K IPMI interface'
depends on LOONGARCH
select MFD_LS2K_BMC_CORE
help
Provides a driver for Loongson-2K IPMI interfaces.

MFD Kconfig:

Quoted 8 lines

config MFD_LS2K_BMC_CORE
bool "Loongson-2K Board Management Controller Support" select MFD_CORE

However, tristate does not seem to work.
On the IPMI side, in order to better reuse code, our driver is not actually a completely independent driver; it is part of ipmi_si.

Ah, yes, that is true. The trouble with the above is it will select MFD_LS2K_BMC_CORE as "y" even if ipmi_si is a module. And that will force MFD_CORE to be "y" as well. At least I think it works that way. Anyway, that's not terrible, but it would be nice to have the core code as a module if possible.

Quoted 3 lines

Another issue is you don't have help text on MFD_LS2K_BMC_CORE code. You probably want to mention there that it enables the display on the BMC.

Of course, I will add some information about BMC in the help text.

Finally, I would like to thanks you again for taking the time to review my patch. I have benefited greatly from it.

Quoted 193 lines

-corey

Quoted 190 lines
drivers/char/ipmi/ipmi_si_intf.c +4 -0
index 7fe891783a37..c13d5132fffc 100644
@@ -2120,6 +2120,8 @@ static int __init init_ipmi_si(void)
 
        ipmi_si_pci_init();
 
+       ipmi_si_ls2k_init();
+
        ipmi_si_parisc_init();
 
        mutex_lock(&smi_infos_lock);
@@ -2334,6 +2335,8 @@ static void cleanup_ipmi_si(void)
 
        ipmi_si_pci_shutdown();
 
+       ipmi_si_ls2k_shutdown();
+
        ipmi_si_parisc_shutdown();
 
        ipmi_si_platform_shutdown();

Therefore, it seems that we can only use bool here, otherwise an error will occur during compilation, as seen in the V3 patchset[1]:

[1]: https://lore.kernel.org/all/[email protected]/

Quoted 156 lines

I don't know if you want to make the display part so it can be enabled separately, I'm not sure how you would do that. But that's not my concern, really.

Thanks,

-corey

Quoted 147 lines
Quoted 17 lines

That way, you can use the display without the IPMI interface, or the IPMI interface without the display.

I would like to see:

* A core mfd device named ls2k-core.c that has the core functions. It would have its own config item (MFD_LS2K) that would be selected if either the display or IPMI device is enabled.

* A separate display device in its own file with its own config item. This isn't my area, so I'm not sure where this should go.

* The IPMI device in the ipmi directory named ipmi_ls2k.c, again with it's own config item (IPMI_LS2K).

Quoted 126 lines

Does that make sense? I don't want to make things too hard, but that's the way pretty much everything else is done on MFDs.

Thanks,

-corey

Quoted 119 lines
Quoted 6 lines

If nothing else is going to use this, then it's really not a multi-function device and all the code can go into the IPMI directory. That simplifies maintenance.

Quoted 108 lines

If it is a multi-function device, then I want two separate Kconfig items, one for the MFD and one for the IPMI portion. That way it's ready and you don't have to bother about the IPMI portion when adding the other device.

All else looks good, I think.

-corey

Quoted 99 lines

For IPMI, according to the existing design, we use software simulation to implement the KCS interface registers: Stauts/Command/Data_Out/Data_In.

Also since both host side and BMC side read and write kcs status, we use fifo pointer to ensure data consistency.

For the display, based on simpledrm, the resolution is read from a fixed position in the BMC since the hardware does not support auto-detection of the resolution. Of course, we will try to support multiple resolutions later, through a vbios-like approach.

Especially, for the BMC reset function, since the display will be disconnected when BMC reset, we made a special treatment of re-push.

Based on this, I will present it in four patches:
patch-1: BMC device PCI resource allocation.
patch-2: BMC reset function support
patch-3: IPMI implementation

Thanks.

-------
V4:
- Add Reviewed-by tag;
- Change the order of the patches.
Patch (1/3):
- Fix build warning by lkp: Kconfig tristate -> bool
- https://lore.kernel.org/all/[email protected]/
- Update commit message;
- Move MFD_LS2K_BMC after MFD_INTEL_M10_BMC_PMCI in Kconfig and Makefile.
Patch (2/3):
- Remove unnecessary newlines;
- Rename ls2k_bmc_check_pcie_connected() to

    ls2k_bmc_pcie_is_connected();

- Update comment message.
Patch (3/3):
- Remove unnecessary newlines.

Link to V3:
https://lore.kernel.org/all/[email protected]/

V3:
Patch (1/3):
- Drop "MFD" in title and comment;
- Fromatting code;
- Add clearer comments.
Patch (2/3):
- Rebase linux-ipmi/next tree;
- Use readx()/writex() to read and write IPMI data instead of structure pointer references;
- CONFIG_LOONGARCH -> MFD_LS2K_BMC;
- Drop unused output.
Patch (3/3):
- Inline the ls2k_bmc_gpio_reset_handler() function to ls2k_bmc_pdata_initial();
- Add clearer comments.
- Use proper multi-line commentary as per the Coding Style documentation;
- Define all magic numbers.

Link to V2:
https://lore.kernel.org/all/[email protected]/

V2:
- Drop ls2kdrm, use simpledrm instead.
Patch (1/3):
- Use DEFINE_RES_MEM_NAMED/MFD_CELL_RES simplified code;
- Add resolution fetching due to replacing the original display solution with simpledrm;
- Add aperture_remove_conflicting_devices() to avoid efifb conflict with simpledrm.
Patch (3/3):
- This part of the function, moved from the original ls2kdrm to mfd;
- Use set_console to implement the Re-push display function.

Link to V1:
https://lore.kernel.org/all/[email protected]/

Binbin Zhou (3):
mfd: ls2kbmc: Introduce Loongson-2K BMC core driver
mfd: ls2kbmc: Add Loongson-2K BMC reset function support
ipmi: Add Loongson-2K BMC support

 drivers/char/ipmi/Makefile       |   1 +
 drivers/char/ipmi/ipmi_si.h      |   7 +
 drivers/char/ipmi/ipmi_si_intf.c |   3 +
 drivers/char/ipmi/ipmi_si_ls2k.c | 189 ++++++++++++
 drivers/mfd/Kconfig              |  12 +
 drivers/mfd/Makefile             |   2 +
 drivers/mfd/ls2kbmc-mfd.c        | 485 +++++++++++++++++++++++++++++++
 7 files changed, 699 insertions(+)
 create mode 100644 drivers/char/ipmi/ipmi_si_ls2k.c
 create mode 100644 drivers/mfd/ls2kbmc-mfd.c

base-commit: cd2e103d57e5615f9bb027d772f93b9efd567224 --
2.47.1

--
Thanks.
Binbin

--
Thanks.
Binbin

--
Thanks.
Binbin

Signature · 2 lines
Thanks.
Binbin