Skip to contentSkip to conversation

mei: csc: support controller with separate PCI device

PATCH New Alexander Usyskin 1 participant 8 messages Feb 1

Subsystems (2)
lore
Share & tools
lore

Alexander Usyskin

author maintainer
#0 lore raw

cover mei: csc: support controller with separate PCI device

Intel PCI driver for chassis controller embedded in Intel graphics devices.

An MEI device here called CSC can be embedded in discrete Intel graphics devices having separate PCI device, to support a range of chassis tasks such as graphics card firmware update and security tasks.

First five patches are cleanups and preparations.
Then the new component added and additional fix for power management for this new component only.

Alexander Usyskin (7):
mei: me: use PCI_DEVICE_DATA macro
mei: fix idle print specifiers
mei: me: move trace into firmware status read
mei: trace: print return value of pci_cfg_read
mei: convert PCI error to common errno
mei: csc: support controller with separate PCI device
mei: csc: wake device while reading firmware status

 drivers/misc/mei/Kconfig      |  11 ++
 drivers/misc/mei/Makefile     |   3 +
 drivers/misc/mei/bus-fixup.c  |   6 +-
 drivers/misc/mei/gsc-me.c     |   3 +-
 drivers/misc/mei/hw-me-regs.h | 165 ++++++++++-----------
 drivers/misc/mei/hw-me.c      |  53 +++++--
 drivers/misc/mei/hw-me.h      |  10 +-
 drivers/misc/mei/hw-txe.c     |   4 +-
 drivers/misc/mei/init.c       |   4 +-
 drivers/misc/mei/main.c       |  18 ++-
 drivers/misc/mei/mei-trace.h  |  10 +-
 drivers/misc/mei/mei_dev.h    |   5 +
 drivers/misc/mei/pci-csc.c    | 261 ++++++++++++++++++++++++++++++++++
 drivers/misc/mei/pci-me.c     | 216 ++++++++++++++--------------
 14 files changed, 546 insertions(+), 223 deletions(-)
 create mode 100644 drivers/misc/mei/pci-csc.c
Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH 1/7 mei: me: use PCI_DEVICE_DATA macro

Drop old local MEI_PCI_DEVICE macro and use common PCI_DEVICE_DATA instead.
Update defines to adhere to current naming convention.

---
 drivers/misc/mei/bus-fixup.c  |   6 +-
 drivers/misc/mei/hw-me-regs.h | 162 +++++++++++++-------------
 drivers/misc/mei/hw-me.h      |   6 -
 drivers/misc/mei/pci-me.c     | 208 +++++++++++++++++-----------------
 4 files changed, 188 insertions(+), 194 deletions(-)
drivers/misc/mei/bus-fixup.c +3 -3
index e6a1d3534663..bea7a47d216e 100644
@@ -303,9 +303,9 @@ static void mei_wd(struct mei_cl_device *cldev)
 {
 	struct pci_dev *pdev = to_pci_dev(cldev->dev.parent);
 
-	if (pdev->device == MEI_DEV_ID_WPT_LP ||
-	    pdev->device == MEI_DEV_ID_SPT ||
-	    pdev->device == MEI_DEV_ID_SPT_H)
+	if (pdev->device == PCI_DEVICE_ID_INTEL_MEI_WPT_LP ||
+	    pdev->device == PCI_DEVICE_ID_INTEL_MEI_SPT ||
+	    pdev->device == PCI_DEVICE_ID_INTEL_MEI_SPT_H)
 		cldev->me_cl->props.protocol_version = 0x2;
 
 	cldev->do_match = 1;
drivers/misc/mei/hw-me-regs.h +81 -81

201 lines not on this page · raw message

drivers/misc/mei/hw-me.h +0 -6
index 204b92af6c47..843ec2497b52 100644
@@ -33,12 +33,6 @@ struct mei_cfg {
 	u32 hw_trc_supported:1;
 };
 
-
-#define MEI_PCI_DEVICE(dev, cfg) \
-	.vendor = PCI_VENDOR_ID_INTEL, .device = (dev), \
-	.subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, \
-	.driver_data = (kernel_ulong_t)(cfg),
-
 #define MEI_ME_RPM_TIMEOUT    500 /* ms */
 
 /**
drivers/misc/mei/pci-me.c +104 -104

214 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#2 lore raw

PATCH 2/7 mei: fix idle print specifiers

In reply to Alexander Usyskin

%01d is equal to %d, simplify the format.

---
 drivers/misc/mei/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/mei/init.c +1 -1
index b789c4d9c709..f54991b40fc7 100644
@@ -348,7 +348,7 @@ bool mei_write_is_idle(struct mei_device *dev)
 		list_empty(&dev->write_list)   &&
 		list_empty(&dev->write_waiting_list));
 
-	dev_dbg(&dev->dev, "write pg: is idle[%d] state=%s ctrl=%01d write=%01d wwait=%01d\n",
+	dev_dbg(&dev->dev, "write pg: is idle[%d] state=%s ctrl=%d write=%d wwait=%d\n",
 		idle,
 		mei_dev_state_str(dev->dev_state),
 		list_empty(&dev->ctrl_wr_list),
Signature · 1 line
2.43.0
author maintainer
#3 lore raw

PATCH 3/7 mei: me: move trace into firmware status read

In reply to Alexander Usyskin

Move register trace near it actual read in the firmware status callback and make it adhere to the actual read type.

---
 drivers/misc/mei/gsc-me.c |  3 ++-
 drivers/misc/mei/hw-me.c  | 11 +++--------
 drivers/misc/mei/hw-me.h  |  2 +-
 drivers/misc/mei/pci-me.c |  8 ++++++--
 4 files changed, 12 insertions(+), 12 deletions(-)
drivers/misc/mei/gsc-me.c +2 -1
index 93cba090ea08..73d5beeb9c34 100644
@@ -23,11 +23,12 @@
 
 #define MEI_GSC_RPM_TIMEOUT 500
 
-static int mei_gsc_read_hfs(const struct mei_device *dev, int where, u32 *val)
+static int mei_gsc_read_hfs(const struct mei_device *dev, int where, const char *name, u32 *val)
 {
 	struct mei_me_hw *hw = to_me_hw(dev);
 
 	*val = ioread32(hw->mem_addr + where + 0xC00);
+	trace_mei_reg_read(&dev->dev, name, where, *val);
 
 	return 0;
 }
drivers/misc/mei/hw-me.c +3 -8
index d4612c659784..c0d4a02d9cae 100644
@@ -215,11 +215,8 @@ static int mei_me_fw_status(struct mei_device *dev,
 
 	fw_status->count = fw_src->count;
 	for (i = 0; i < fw_src->count && i < MEI_FW_STATUS_MAX; i++) {
-		ret = hw->read_fws(dev, fw_src->status[i],
+		ret = hw->read_fws(dev, fw_src->status[i], "PCI_CFG_HFS_X",
 				   &fw_status->status[i]);
-		trace_mei_pci_cfg_read(&dev->dev, "PCI_CFG_HFS_X",
-				       fw_src->status[i],
-				       fw_status->status[i]);
 		if (ret)
 			return ret;
 	}
@@ -250,8 +247,7 @@ static int mei_me_hw_config(struct mei_device *dev)
 	hw->hbuf_depth = (hcsr & H_CBD) >> 24;
 
 	reg = 0;
-	hw->read_fws(dev, PCI_CFG_HFS_1, &reg);
-	trace_mei_pci_cfg_read(&dev->dev, "PCI_CFG_HFS_1", PCI_CFG_HFS_1, reg);
+	hw->read_fws(dev, PCI_CFG_HFS_1, "PCI_CFG_HFS_1", &reg);
 	hw->d0i3_supported =
 		((reg & PCI_CFG_HFS_1_D0I3_MSK) == PCI_CFG_HFS_1_D0I3_MSK);
 
@@ -446,8 +442,7 @@ static void mei_gsc_pxp_check(struct mei_device *dev)
 	if (!kind_is_gsc(dev) && !kind_is_gscfi(dev))
 		return;
 
-	hw->read_fws(dev, PCI_CFG_HFS_5, &fwsts5);
-	trace_mei_pci_cfg_read(&dev->dev, "PCI_CFG_HFS_5", PCI_CFG_HFS_5, fwsts5);
+	hw->read_fws(dev, PCI_CFG_HFS_5, "PCI_CFG_HFS_5", &fwsts5);
 
 	if ((fwsts5 & GSC_CFG_HFS_5_BOOT_TYPE_MSK) == GSC_CFG_HFS_5_BOOT_TYPE_PXP) {
 		if (dev->gsc_reset_to_pxp == MEI_DEV_RESET_TO_PXP_DEFAULT)
drivers/misc/mei/hw-me.h +1 -1
index 843ec2497b52..9df5899d2602 100644
@@ -56,7 +56,7 @@ struct mei_me_hw {
 	enum mei_pg_state pg_state;
 	bool d0i3_supported;
 	u8 hbuf_depth;
-	int (*read_fws)(const struct mei_device *dev, int where, u32 *val);
+	int (*read_fws)(const struct mei_device *dev, int where, const char *name, u32 *val);
 	/* polling */
 	struct task_struct *polling_thread;
 	wait_queue_head_t wait_active;
drivers/misc/mei/pci-me.c +6 -2
index fe5d5aee074c..b4c9526857bb 100644
@@ -23,6 +23,7 @@
 #include "client.h"
 #include "hw-me-regs.h"
 #include "hw-me.h"
+#include "mei-trace.h"
 
 /* mei_pci_tbl - PCI Device ID Table */
 static const struct pci_device_id mei_me_pci_tbl[] = {
@@ -145,11 +146,14 @@ static inline void mei_me_set_pm_domain(struct mei_device *dev) {}
 static inline void mei_me_unset_pm_domain(struct mei_device *dev) {}
 #endif /* CONFIG_PM */
 
-static int mei_me_read_fws(const struct mei_device *dev, int where, u32 *val)
+static int mei_me_read_fws(const struct mei_device *dev, int where, const char *name, u32 *val)
 {
 	struct pci_dev *pdev = to_pci_dev(dev->parent);
+	int ret;
 
-	return pci_read_config_dword(pdev, where, val);
+	ret = pci_read_config_dword(pdev, where, val);
+	trace_mei_pci_cfg_read(&dev->dev, name, where, *val);
+	return ret;
 }
 
 /**
Signature · 1 line
2.43.0
author maintainer
#4 lore raw

PATCH 4/7 mei: trace: print return value of pci_cfg_read

In reply to Alexander Usyskin

Extend debug capabilities.
Add return value print in the trace_mei_pci_cfg_read().

---
 drivers/misc/mei/hw-me.c     | 15 +++++++++------
 drivers/misc/mei/hw-txe.c    |  2 +-
 drivers/misc/mei/mei-trace.h | 10 ++++++----
 drivers/misc/mei/pci-me.c    |  2 +-
 4 files changed, 17 insertions(+), 12 deletions(-)
drivers/misc/mei/hw-me.c +9 -6
index c0d4a02d9cae..72a7cfb2989f 100644
@@ -1505,10 +1505,11 @@ static bool mei_me_fw_type_nm(const struct pci_dev *pdev)
 {
 	u32 reg;
 	unsigned int devfn;
+	int ret;
 
 	devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0);
-	pci_bus_read_config_dword(pdev->bus, devfn, PCI_CFG_HFS_2, &reg);
-	trace_mei_pci_cfg_read(&pdev->dev, "PCI_CFG_HFS_2", PCI_CFG_HFS_2, reg);
+	ret = pci_bus_read_config_dword(pdev->bus, devfn, PCI_CFG_HFS_2, &reg);
+	trace_mei_pci_cfg_read(&pdev->dev, "PCI_CFG_HFS_2", PCI_CFG_HFS_2, reg, ret);
 	/* make sure that bit 9 (NM) is up and bit 10 (DM) is down */
 	return (reg & 0x600) == 0x200;
 }
@@ -1531,10 +1532,11 @@ static bool mei_me_fw_type_sps_4(const struct pci_dev *pdev)
 {
 	u32 reg;
 	unsigned int devfn;
+	int ret;
 
 	devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0);
-	pci_bus_read_config_dword(pdev->bus, devfn, PCI_CFG_HFS_1, &reg);
-	trace_mei_pci_cfg_read(&pdev->dev, "PCI_CFG_HFS_1", PCI_CFG_HFS_1, reg);
+	ret = pci_bus_read_config_dword(pdev->bus, devfn, PCI_CFG_HFS_1, &reg);
+	trace_mei_pci_cfg_read(&pdev->dev, "PCI_CFG_HFS_1", PCI_CFG_HFS_1, reg, ret);
 	return (reg & PCI_CFG_HFS_1_OPMODE_MSK) == PCI_CFG_HFS_1_OPMODE_SPS;
 }
 
@@ -1556,10 +1558,11 @@ static bool mei_me_fw_type_sps_ign(const struct pci_dev *pdev)
 	u32 reg;
 	u32 fw_type;
 	unsigned int devfn;
+	int ret;
 
 	devfn = PCI_DEVFN(PCI_SLOT(pdev->devfn), 0);
-	pci_bus_read_config_dword(pdev->bus, devfn, PCI_CFG_HFS_3, &reg);
-	trace_mei_pci_cfg_read(&pdev->dev, "PCI_CFG_HFS_3", PCI_CFG_HFS_3, reg);
+	ret = pci_bus_read_config_dword(pdev->bus, devfn, PCI_CFG_HFS_3, &reg);
+	trace_mei_pci_cfg_read(&pdev->dev, "PCI_CFG_HFS_3", PCI_CFG_HFS_3, reg, ret);
 	fw_type = (reg & PCI_CFG_HFS_3_FW_SKU_MSK);
 
 	dev_dbg(&pdev->dev, "fw type is %d\n", fw_type);
drivers/misc/mei/hw-txe.c +1 -1
index e4688c391027..008cb1ede56c 100644
@@ -651,7 +651,7 @@ static int mei_txe_fw_status(struct mei_device *dev,
 					    &fw_status->status[i]);
 		trace_mei_pci_cfg_read(&dev->dev, "PCI_CFG_HSF_X",
 				       fw_src->status[i],
-				       fw_status->status[i]);
+				       fw_status->status[i], ret);
 		if (ret)
 			return ret;
 	}
drivers/misc/mei/mei-trace.h +6 -4
index 24fa321d88bd..fa5224e5353a 100644
@@ -55,22 +55,24 @@ TRACE_EVENT(mei_reg_write,
 );
 
 TRACE_EVENT(mei_pci_cfg_read,
-	TP_PROTO(const struct device *dev, const char *reg, u32 offs, u32 val),
-	TP_ARGS(dev, reg, offs, val),
+	TP_PROTO(const struct device *dev, const char *reg, u32 offs, u32 val, int ret),
+	TP_ARGS(dev, reg, offs, val, ret),
 	TP_STRUCT__entry(
 		__string(dev, dev_name(dev))
 		__string(reg, reg)
 		__field(u32, offs)
 		__field(u32, val)
+		__field(int, ret)
 	),
 	TP_fast_assign(
 		__assign_str(dev);
 		__assign_str(reg);
 		__entry->offs = offs;
 		__entry->val = val;
+		__entry->ret = ret;
 	),
-	TP_printk("[%s] pci cfg read %s:[%#x] = %#x",
-		  __get_str(dev), __get_str(reg), __entry->offs, __entry->val)
+	TP_printk("[%s] pci cfg read %s:[%#x] = %#x, ret = %d",
+		  __get_str(dev), __get_str(reg), __entry->offs, __entry->val, __entry->ret)
 );
 
 #endif /* _MEI_TRACE_H_ */
drivers/misc/mei/pci-me.c +1 -1
index b4c9526857bb..a75773cc8fb7 100644
@@ -152,7 +152,7 @@ static int mei_me_read_fws(const struct mei_device *dev, int where, const char *
 	int ret;
 
 	ret = pci_read_config_dword(pdev, where, val);
-	trace_mei_pci_cfg_read(&dev->dev, name, where, *val);
+	trace_mei_pci_cfg_read(&dev->dev, name, where, *val, ret);
 	return ret;
 }
 
Signature · 1 line
2.43.0
author maintainer
#5 lore raw

PATCH 5/7 mei: convert PCI error to common errno

In reply to Alexander Usyskin

Ensure that callers receive only < 0 return value on error. Convert PCI error returned by pci_read_config_dword() to common errno before returning from function.

---
 drivers/misc/mei/hw-txe.c | 2 +-
 drivers/misc/mei/pci-me.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/misc/mei/hw-txe.c +1 -1
index 008cb1ede56c..a83de653c603 100644
@@ -653,7 +653,7 @@ static int mei_txe_fw_status(struct mei_device *dev,
 				       fw_src->status[i],
 				       fw_status->status[i], ret);
 		if (ret)
-			return ret;
+			return pcibios_err_to_errno(ret);
 	}
 
 	return 0;
drivers/misc/mei/pci-me.c +1 -1
index a75773cc8fb7..8d16bfa6027c 100644
@@ -153,7 +153,7 @@ static int mei_me_read_fws(const struct mei_device *dev, int where, const char *
 
 	ret = pci_read_config_dword(pdev, where, val);
 	trace_mei_pci_cfg_read(&dev->dev, name, where, *val, ret);
-	return ret;
+	return pcibios_err_to_errno(ret);
 }
 
 /**
Signature · 1 line
2.43.0
author maintainer
#6 lore raw

PATCH 6/7 mei: csc: support controller with separate PCI device

In reply to Alexander Usyskin

Intel PCI driver for chassis controller embedded in Intel graphics devices.

An MEI device here called CSC can be embedded in discrete Intel graphics devices having separate PCI device, to support a range of chassis tasks such as graphics card firmware update and security tasks.

---
 drivers/misc/mei/Kconfig      |  11 ++
 drivers/misc/mei/Makefile     |   3 +
 drivers/misc/mei/hw-me-regs.h |   3 +
 drivers/misc/mei/hw-me.c      |  27 ++++
 drivers/misc/mei/hw-me.h      |   2 +
 drivers/misc/mei/init.c       |   4 +-
 drivers/misc/mei/mei_dev.h    |   3 +
 drivers/misc/mei/pci-csc.c    | 259 ++++++++++++++++++++++++++++++++++
 8 files changed, 311 insertions(+), 1 deletion(-)
 create mode 100644 drivers/misc/mei/pci-csc.c
drivers/misc/mei/Kconfig +11 -0
index 5902dd1ee44b..8d192c3a1d59 100644
@@ -58,6 +58,17 @@ config INTEL_MEI_GSC
 	  tasks such as graphics card firmware update and security
 	  tasks.
 
+config INTEL_MEI_CSC
+	tristate "Intel MEI CSC embedded device"
+	depends on INTEL_MEI_ME
+	help
+	  Intel PCI driver for the chassis controller embedded in Intel graphics devices.
+
+	  An MEI device here called CSC can be embedded in discrete
+	  Intel graphics devices, to support a range of chassis
+	  tasks such as graphics card firmware update and security
+	  tasks.
+
 config INTEL_MEI_VSC_HW
 	tristate "Intel visual sensing controller device transport driver"
 	depends on ACPI && SPI
drivers/misc/mei/Makefile +3 -0
index a203ed766b33..9a6aa335921e 100644
@@ -21,6 +21,9 @@ mei-me-objs += hw-me.o
 obj-$(CONFIG_INTEL_MEI_GSC) += mei-gsc.o
 mei-gsc-objs := gsc-me.o
 
+obj-$(CONFIG_INTEL_MEI_CSC) += mei-csc.o
+mei-csc-objs := pci-csc.o
+
 obj-$(CONFIG_INTEL_MEI_TXE) += mei-txe.o
 mei-txe-objs := pci-txe.o
 mei-txe-objs += hw-txe.o
drivers/misc/mei/hw-me-regs.h +3 -0
index 840e1fd2714c..9b1675f98404 100644
@@ -124,6 +124,8 @@
 
 #define PCI_DEVICE_ID_INTEL_MEI_NVL_S      0x6E68  /* Nova Lake Point S */
 
+#define PCI_DEVICE_ID_INTEL_MEI_CRI        0x6766  /* Crescent Island */
+
 /*
  * MEI HW Section
  */
@@ -134,6 +136,7 @@
 #  define PCI_CFG_HFS_1_OPMODE_MSK 0xf0000 /* OP MODE Mask: SPS <= 4.0 */
 #  define PCI_CFG_HFS_1_OPMODE_SPS 0xf0000 /* SPS SKU : SPS <= 4.0 */
 #define PCI_CFG_HFS_2         0x48
+#  define PCI_CFG_HFS_2_D3_BLOCK              BIT(7)
 #  define PCI_CFG_HFS_2_PM_CMOFF_TO_CMX_ERROR 0x1000000 /* CMoff->CMx wake after an error */
 #  define PCI_CFG_HFS_2_PM_CM_RESET_ERROR     0x5000000 /* CME reset due to exception */
 #  define PCI_CFG_HFS_2_PM_EVENT_MASK         0xf000000
drivers/misc/mei/hw-me.c +27 -0
index 72a7cfb2989f..3412a7b5b0e8 100644
@@ -224,6 +224,15 @@ static int mei_me_fw_status(struct mei_device *dev,
 	return 0;
 }
 
+static bool mei_csc_pg_blocked(struct mei_device *dev)
+{
+	struct mei_me_hw *hw = to_me_hw(dev);
+	u32 reg = 0;
+
+	hw->read_fws(dev, PCI_CFG_HFS_2, "PCI_CFG_HFS_2", &reg);
+	return (reg & PCI_CFG_HFS_2_D3_BLOCK) == PCI_CFG_HFS_2_D3_BLOCK;
+}
+
 /**
  * mei_me_hw_config - configure hw dependent settings
  *
@@ -1206,6 +1215,7 @@ static int mei_me_hw_reset(struct mei_device *dev, bool intr_enable)
 				return ret;
 		} else {
 			hw->pg_state = MEI_PG_OFF;
+			dev->pg_blocked = mei_csc_pg_blocked(dev);
 		}
 	}
 
@@ -1294,6 +1304,7 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id)
 {
 	struct mei_device *dev = (struct mei_device *) dev_id;
 	struct list_head cmpl_list;
+	bool pg_blocked;
 	s32 slots;
 	u32 hcsr;
 	int rets = 0;
@@ -1351,6 +1362,14 @@ irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id)
 		}
 		goto end;
 	}
+
+	pg_blocked = mei_csc_pg_blocked(dev);
+	if (pg_blocked && !dev->pg_blocked) /* PG block requested */
+		pm_request_resume(&dev->dev);
+	else if (!pg_blocked && dev->pg_blocked) /* PG block lifted */
+		pm_request_autosuspend(&dev->dev);
+	dev->pg_blocked = pg_blocked;
+
 	/* check slots available for reading */
 	slots = mei_count_full_read_slots(dev);
 	while (slots > 0) {
@@ -1726,6 +1745,13 @@ static const struct mei_cfg mei_me_gscfi_cfg = {
 	MEI_CFG_FW_VER_SUPP,
 };
 
+/* Chassis System Controller Firmware Interface */
+static const struct mei_cfg mei_me_csc_cfg = {
+	MEI_CFG_TYPE_GSCFI,
+	MEI_CFG_PCH8_HFS,
+	MEI_CFG_FW_VER_SUPP,
+};
+
 /*
  * mei_cfg_list - A list of platform platform specific configurations.
  * Note: has to be synchronized with  enum mei_cfg_idx.
@@ -1748,6 +1774,7 @@ static const struct mei_cfg *const mei_cfg_list[] = {
 	[MEI_ME_PCH15_SPS_CFG] = &mei_me_pch15_sps_cfg,
 	[MEI_ME_GSC_CFG] = &mei_me_gsc_cfg,
 	[MEI_ME_GSCFI_CFG] = &mei_me_gscfi_cfg,
+	[MEI_ME_CSC_CFG] = &mei_me_csc_cfg,
 };
 
 const struct mei_cfg *mei_me_get_cfg(kernel_ulong_t idx)
drivers/misc/mei/hw-me.h +2 -0
index 9df5899d2602..8da8662a9d61 100644
@@ -104,6 +104,7 @@ static inline bool mei_me_hw_use_polling(const struct mei_me_hw *hw)
  *                         SPS firmware exclusion.
  * @MEI_ME_GSC_CFG:        Graphics System Controller
  * @MEI_ME_GSCFI_CFG:      Graphics System Controller Firmware Interface
+ * @MEI_ME_CSC_CFG:        Chassis System Controller Firmware Interface
  * @MEI_ME_NUM_CFG:        Upper Sentinel.
  */
 enum mei_cfg_idx {
@@ -124,6 +125,7 @@ enum mei_cfg_idx {
 	MEI_ME_PCH15_SPS_CFG,
 	MEI_ME_GSC_CFG,
 	MEI_ME_GSCFI_CFG,
+	MEI_ME_CSC_CFG,
 	MEI_ME_NUM_CFG,
 };
 
drivers/misc/mei/init.c +3 -1
index f54991b40fc7..766f119f7ed0 100644
@@ -344,13 +344,15 @@ EXPORT_SYMBOL_GPL(mei_stop);
 bool mei_write_is_idle(struct mei_device *dev)
 {
 	bool idle = (dev->dev_state == MEI_DEV_ENABLED &&
+		!dev->pg_blocked &&
 		list_empty(&dev->ctrl_wr_list) &&
 		list_empty(&dev->write_list)   &&
 		list_empty(&dev->write_waiting_list));
 
-	dev_dbg(&dev->dev, "write pg: is idle[%d] state=%s ctrl=%d write=%d wwait=%d\n",
+	dev_dbg(&dev->dev, "write pg: is idle[%d] state=%s blocked=%d ctrl=%d write=%d wwait=%d\n",
 		idle,
 		mei_dev_state_str(dev->dev_state),
+		dev->pg_blocked,
 		list_empty(&dev->ctrl_wr_list),
 		list_empty(&dev->write_list),
 		list_empty(&dev->write_waiting_list));
drivers/misc/mei/mei_dev.h +3 -0
index 0bf8d552c3ea..1796c6793a94 100644
@@ -490,6 +490,7 @@ struct mei_dev_timeouts {
  * @timer_work  : MEI timer delayed work (timeouts)
  *
  * @recvd_hw_ready : hw ready message received flag
+ * @pg_blocked  : low power mode is not allowed
  *
  * @wait_hw_ready : wait queue for receive HW ready message form FW
  * @wait_pg     : wait queue for receive PG message from FW
@@ -575,6 +576,8 @@ struct mei_device {
 	struct delayed_work timer_work;
 
 	bool recvd_hw_ready;
+	bool pg_blocked;
+
 	/*
 	 * waiting queue for receive message from FW
 	 */
drivers/misc/mei/pci-csc.c new file +259 -0

259 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#7 lore raw

PATCH 7/7 mei: csc: wake device while reading firmware status

In reply to Alexander Usyskin

The CSC has firmware status registers in MMIO and they may be unaccessible while device is suspended.
Wake device while reading firmware status via sysfs.

---
 drivers/misc/mei/main.c    | 18 ++++++++++++++----
 drivers/misc/mei/mei_dev.h |  2 ++
 drivers/misc/mei/pci-csc.c |  2 ++
 3 files changed, 18 insertions(+), 4 deletions(-)
drivers/misc/mei/main.c +14 -4
index 6f26d5160788..54f70f513482 100644
@@ -4,6 +4,7 @@
  * Intel Management Engine Interface (Intel MEI) Linux driver
  */
 
+#include <linux/cleanup.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
@@ -13,6 +14,7 @@
 #include <linux/errno.h>
 #include <linux/types.h>
 #include <linux/fcntl.h>
+#include <linux/pm_runtime.h>
 #include <linux/poll.h>
 #include <linux/init.h>
 #include <linux/ioctl.h>
@@ -982,14 +984,22 @@ static DEVICE_ATTR_RO(trc);
 static ssize_t fw_status_show(struct device *device,
 		struct device_attribute *attr, char *buf)
 {
-	struct mei_device *dev = dev_get_drvdata(device);
+	struct mei_device *mdev = dev_get_drvdata(device);
 	struct mei_fw_status fw_status;
 	int err, i;
 	ssize_t cnt = 0;
 
-	mutex_lock(&dev->device_lock);
-	err = mei_fw_status(dev, &fw_status);
-	mutex_unlock(&dev->device_lock);
+	if (mdev->read_fws_need_resume) {
+		err = pm_runtime_resume_and_get(mdev->parent);
+		if (err) {
+			dev_err(device, "read fw_status resume error = %d\n", err);
+			return err;
+		}
+	}
+	scoped_guard(mutex, &mdev->device_lock)
+		err = mei_fw_status(mdev, &fw_status);
+	if (mdev->read_fws_need_resume)
+		pm_runtime_put_autosuspend(mdev->parent);
 	if (err) {
 		dev_err(device, "read fw_status error = %d\n", err);
 		return err;
drivers/misc/mei/mei_dev.h +2 -0
index 1796c6793a94..d8634a726990 100644
@@ -491,6 +491,7 @@ struct mei_dev_timeouts {
  *
  * @recvd_hw_ready : hw ready message received flag
  * @pg_blocked  : low power mode is not allowed
+ * @read_fws_need_resume: the FW status handler needs HW woken from sleep
  *
  * @wait_hw_ready : wait queue for receive HW ready message form FW
  * @wait_pg     : wait queue for receive PG message from FW
@@ -577,6 +578,7 @@ struct mei_device {
 
 	bool recvd_hw_ready;
 	bool pg_blocked;
+	bool read_fws_need_resume;
 
 	/*
 	 * waiting queue for receive message from FW
drivers/misc/mei/pci-csc.c +2 -0
index 15e170b1e0b6..70792bf9b3c0 100644
@@ -67,6 +67,8 @@ static int mei_csc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (!mdev)
 		return -ENOMEM;
 
+	mdev->read_fws_need_resume = true;
+
 	hw = to_me_hw(mdev);
 
 	/*
Signature · 1 line
2.43.0