mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexander Usyskin <alexander.usyskin@intel.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Menachem Adin <menachem.adin@intel.com>,
	Alexander Usyskin <alexander.usyskin@intel.com>,
	linux-kernel@vger.kernel.org,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Reuven Abliyev <reuvenab@gmail.com>
Subject: [char-misc-next 1/3] mei: store kind as enum
Date: Thu,  9 Apr 2026 15:55:22 +0300	[thread overview]
Message-ID: <20260409125524.111530-2-alexander.usyskin@intel.com> (raw)
In-Reply-To: <20260409125524.111530-1-alexander.usyskin@intel.com>

Simplify flows and prepare for future flexibility by
storing kind as enum and converting to string only in sysfs.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Co-developed-by: Reuven Abliyev <reuvenab@gmail.com>
Signed-off-by: Reuven Abliyev <reuvenab@gmail.com>
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
---
 drivers/misc/mei/hw-me.c        | 59 ++++++++++++++++++++++++++-------
 drivers/misc/mei/hw-me.h        |  4 +--
 drivers/misc/mei/main.c         | 18 ++++++----
 drivers/misc/mei/mei_dev.h      | 27 ++++++++++++---
 drivers/misc/mei/pci-txe.c      |  1 +
 drivers/misc/mei/platform-vsc.c |  2 +-
 6 files changed, 85 insertions(+), 26 deletions(-)

diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c
index e286763b52ec..28fbd432d80d 100644
--- a/drivers/misc/mei/hw-me.c
+++ b/drivers/misc/mei/hw-me.c
@@ -1584,17 +1584,40 @@ static bool mei_me_fw_type_sps_ign(const struct pci_dev *pdev)
 	       fw_type == PCI_CFG_HFS_3_FW_SKU_SPS;
 }
 
-#define MEI_CFG_KIND_ITOUCH                     \
-	.kind = "itouch"
+#define MEI_CFG_FW_SPS_IGN                      \
+	.quirk_probe = mei_me_fw_type_sps_ign
 
-#define MEI_CFG_TYPE_GSC                        \
-	.kind = "gsc"
+static enum mei_dev_kind mei_cfg_kind_mei(const struct device *parent)
+{
+	return MEI_DEV_KIND_MEI;
+}
 
-#define MEI_CFG_TYPE_GSCFI                      \
-	.kind = "gscfi"
+#define MEI_CFG_KIND_MEI                     \
+	.get_kind = mei_cfg_kind_mei
 
-#define MEI_CFG_FW_SPS_IGN                      \
-	.quirk_probe = mei_me_fw_type_sps_ign
+static enum mei_dev_kind mei_cfg_kind_itouch(const struct device *parent)
+{
+	return MEI_DEV_KIND_ITOUCH;
+}
+
+#define MEI_CFG_KIND_ITOUCH                  \
+	.get_kind = mei_cfg_kind_itouch
+
+static enum mei_dev_kind mei_cfg_kind_gsc(const struct device *parent)
+{
+	return MEI_DEV_KIND_GSC;
+}
+
+#define MEI_CFG_KIND_GSC                     \
+	.get_kind = mei_cfg_kind_gsc
+
+static enum mei_dev_kind mei_cfg_kind_gscfi(const struct device *parent)
+{
+	return MEI_DEV_KIND_GSCFI;
+}
+
+#define MEI_CFG_KIND_GSCFI                   \
+	.get_kind = mei_cfg_kind_gscfi
 
 #define MEI_CFG_FW_VER_SUPP                     \
 	.fw_ver_supported = 1
@@ -1630,27 +1653,32 @@ static bool mei_me_fw_type_sps_ign(const struct pci_dev *pdev)
 
 /* ICH Legacy devices */
 static const struct mei_cfg mei_me_ich_cfg = {
+	MEI_CFG_KIND_MEI,
 	MEI_CFG_ICH_HFS,
 };
 
 /* ICH devices */
 static const struct mei_cfg mei_me_ich10_cfg = {
+	MEI_CFG_KIND_MEI,
 	MEI_CFG_ICH10_HFS,
 };
 
 /* PCH6 devices */
 static const struct mei_cfg mei_me_pch6_cfg = {
+	MEI_CFG_KIND_MEI,
 	MEI_CFG_PCH_HFS,
 };
 
 /* PCH7 devices */
 static const struct mei_cfg mei_me_pch7_cfg = {
+	MEI_CFG_KIND_MEI,
 	MEI_CFG_PCH_HFS,
 	MEI_CFG_FW_VER_SUPP,
 };
 
 /* PCH Cougar Point and Patsburg with quirk for Node Manager exclusion */
 static const struct mei_cfg mei_me_pch_cpt_pbg_cfg = {
+	MEI_CFG_KIND_MEI,
 	MEI_CFG_PCH_HFS,
 	MEI_CFG_FW_VER_SUPP,
 	MEI_CFG_FW_NM,
@@ -1658,6 +1686,7 @@ static const struct mei_cfg mei_me_pch_cpt_pbg_cfg = {
 
 /* PCH8 Lynx Point and newer devices */
 static const struct mei_cfg mei_me_pch8_cfg = {
+	MEI_CFG_KIND_MEI,
 	MEI_CFG_PCH8_HFS,
 	MEI_CFG_FW_VER_SUPP,
 };
@@ -1671,6 +1700,7 @@ static const struct mei_cfg mei_me_pch8_itouch_cfg = {
 
 /* PCH8 Lynx Point with quirk for SPS Firmware exclusion */
 static const struct mei_cfg mei_me_pch8_sps_4_cfg = {
+	MEI_CFG_KIND_MEI,
 	MEI_CFG_PCH8_HFS,
 	MEI_CFG_FW_VER_SUPP,
 	MEI_CFG_FW_SPS_4,
@@ -1678,6 +1708,7 @@ static const struct mei_cfg mei_me_pch8_sps_4_cfg = {
 
 /* LBG with quirk for SPS (4.0) Firmware exclusion */
 static const struct mei_cfg mei_me_pch12_sps_4_cfg = {
+	MEI_CFG_KIND_MEI,
 	MEI_CFG_PCH8_HFS,
 	MEI_CFG_FW_VER_SUPP,
 	MEI_CFG_FW_SPS_4,
@@ -1685,6 +1716,7 @@ static const struct mei_cfg mei_me_pch12_sps_4_cfg = {
 
 /* Cannon Lake and newer devices */
 static const struct mei_cfg mei_me_pch12_cfg = {
+	MEI_CFG_KIND_MEI,
 	MEI_CFG_PCH8_HFS,
 	MEI_CFG_FW_VER_SUPP,
 	MEI_CFG_DMA_128,
@@ -1692,6 +1724,7 @@ static const struct mei_cfg mei_me_pch12_cfg = {
 
 /* Cannon Lake with quirk for SPS 5.0 and newer Firmware exclusion */
 static const struct mei_cfg mei_me_pch12_sps_cfg = {
+	MEI_CFG_KIND_MEI,
 	MEI_CFG_PCH8_HFS,
 	MEI_CFG_FW_VER_SUPP,
 	MEI_CFG_DMA_128,
@@ -1710,6 +1743,7 @@ static const struct mei_cfg mei_me_pch12_itouch_sps_cfg = {
 
 /* Tiger Lake and newer devices */
 static const struct mei_cfg mei_me_pch15_cfg = {
+	MEI_CFG_KIND_MEI,
 	MEI_CFG_PCH8_HFS,
 	MEI_CFG_FW_VER_SUPP,
 	MEI_CFG_DMA_128,
@@ -1718,6 +1752,7 @@ static const struct mei_cfg mei_me_pch15_cfg = {
 
 /* Tiger Lake with quirk for SPS 5.0 and newer Firmware exclusion */
 static const struct mei_cfg mei_me_pch15_sps_cfg = {
+	MEI_CFG_KIND_MEI,
 	MEI_CFG_PCH8_HFS,
 	MEI_CFG_FW_VER_SUPP,
 	MEI_CFG_DMA_128,
@@ -1727,21 +1762,21 @@ static const struct mei_cfg mei_me_pch15_sps_cfg = {
 
 /* Graphics System Controller */
 static const struct mei_cfg mei_me_gsc_cfg = {
-	MEI_CFG_TYPE_GSC,
+	MEI_CFG_KIND_GSC,
 	MEI_CFG_PCH8_HFS,
 	MEI_CFG_FW_VER_SUPP,
 };
 
 /* Graphics System Controller Firmware Interface */
 static const struct mei_cfg mei_me_gscfi_cfg = {
-	MEI_CFG_TYPE_GSCFI,
+	MEI_CFG_KIND_GSCFI,
 	MEI_CFG_PCH8_HFS,
 	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_KIND_GSCFI,
 	MEI_CFG_PCH8_HFS,
 	MEI_CFG_FW_VER_SUPP,
 };
@@ -1812,7 +1847,7 @@ struct mei_device *mei_me_dev_init(struct device *parent,
 
 	dev->fw_f_fw_ver_supported = cfg->fw_ver_supported;
 
-	dev->kind = cfg->kind;
+	dev->kind = cfg->get_kind(parent);
 
 	return dev;
 }
diff --git a/drivers/misc/mei/hw-me.h b/drivers/misc/mei/hw-me.h
index 8da8662a9d61..884736d76fbb 100644
--- a/drivers/misc/mei/hw-me.h
+++ b/drivers/misc/mei/hw-me.h
@@ -19,7 +19,7 @@
  *
  * @fw_status: FW status
  * @quirk_probe: device exclusion quirk
- * @kind: MEI head kind
+ * @get_kind: MEI head kind helper
  * @dma_size: device DMA buffers size
  * @fw_ver_supported: is fw version retrievable from FW
  * @hw_trc_supported: does the hw support trc register
@@ -27,7 +27,7 @@
 struct mei_cfg {
 	const struct mei_fw_status fw_status;
 	bool (*quirk_probe)(const struct pci_dev *pdev);
-	const char *kind;
+	enum mei_dev_kind (*get_kind)(const struct device *parent);
 	size_t dma_size[DMA_DSCR_NUM];
 	u32 fw_ver_supported:1;
 	u32 hw_trc_supported:1;
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c
index 54f70f513482..43667e5d3708 100644
--- a/drivers/misc/mei/main.c
+++ b/drivers/misc/mei/main.c
@@ -1165,6 +1165,15 @@ void mei_set_devstate(struct mei_device *dev, enum mei_dev_state state)
 	}
 }
 
+static const char * const mei_kind_names[] = {
+	"mei",
+	"itouch",
+	"gsc",
+	"gscfi",
+	"ivsc",
+};
+static_assert(ARRAY_SIZE(mei_kind_names) == MEI_DEV_KIND_MAX);
+
 /**
  * kind_show - display device kind
  *
@@ -1178,14 +1187,11 @@ static ssize_t kind_show(struct device *device,
 			 struct device_attribute *attr, char *buf)
 {
 	struct mei_device *dev = dev_get_drvdata(device);
-	ssize_t ret;
 
-	if (dev->kind)
-		ret = sprintf(buf, "%s\n", dev->kind);
-	else
-		ret = sprintf(buf, "%s\n", "mei");
+	if (dev->kind < MEI_DEV_KIND_MEI || dev->kind >= MEI_DEV_KIND_MAX)
+		return -EINVAL;
 
-	return ret;
+	return sysfs_emit(buf, "%s\n", mei_kind_names[dev->kind]);
 }
 static DEVICE_ATTR_RO(kind);
 
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h
index d8634a726990..6d081c496ccc 100644
--- a/drivers/misc/mei/mei_dev.h
+++ b/drivers/misc/mei/mei_dev.h
@@ -469,6 +469,25 @@ struct mei_dev_timeouts {
 	unsigned long link_reset_wait; /* link reset wait timeout, in jiffies */
 };
 
+/**
+ * enum mei_dev_kind - device type
+ *
+ * @MEI_DEV_KIND_MEI: basic device
+ * @MEI_DEV_KIND_ITOUCH: itouch support
+ * @MEI_DEV_KIND_GSC: discete graphics content protection
+ * @MEI_DEV_KIND_GSCFI: discete graphics chassis controller
+ * @MEI_DEV_KIND_IVSC: visual sensing controller
+ * @MEI_DEV_KIND_MAX: sentinel
+ */
+enum mei_dev_kind {
+	MEI_DEV_KIND_MEI,
+	MEI_DEV_KIND_ITOUCH,
+	MEI_DEV_KIND_GSC,
+	MEI_DEV_KIND_GSCFI,
+	MEI_DEV_KIND_IVSC,
+	MEI_DEV_KIND_MAX
+};
+
 /**
  * struct mei_device -  MEI private device struct
  *
@@ -650,7 +669,7 @@ struct mei_device {
 	struct list_head device_list;
 	struct mutex cl_bus_lock;
 
-	const char *kind;
+	enum mei_dev_kind kind;
 
 #if IS_ENABLED(CONFIG_DEBUG_FS)
 	struct dentry *dbgfs_dir;
@@ -911,8 +930,7 @@ static inline ssize_t mei_fw_status_str(struct mei_device *dev,
  */
 static inline bool kind_is_gsc(struct mei_device *dev)
 {
-	/* check kind for NULL because it may be not set, like at the fist call to hw_start */
-	return dev->kind && (strcmp(dev->kind, "gsc") == 0);
+	return dev->kind == MEI_DEV_KIND_GSC;
 }
 
 /**
@@ -924,7 +942,6 @@ static inline bool kind_is_gsc(struct mei_device *dev)
  */
 static inline bool kind_is_gscfi(struct mei_device *dev)
 {
-	/* check kind for NULL because it may be not set, like at the fist call to hw_start */
-	return dev->kind && (strcmp(dev->kind, "gscfi") == 0);
+	return dev->kind == MEI_DEV_KIND_GSCFI;
 }
 #endif
diff --git a/drivers/misc/mei/pci-txe.c b/drivers/misc/mei/pci-txe.c
index 98d1bc2c7f4b..f5441bc5efe2 100644
--- a/drivers/misc/mei/pci-txe.c
+++ b/drivers/misc/mei/pci-txe.c
@@ -84,6 +84,7 @@ static int mei_txe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		err = -ENOMEM;
 		goto end;
 	}
+	dev->kind = MEI_DEV_KIND_MEI;
 	hw = to_txe_hw(dev);
 	hw->mem_addr = pcim_iomap_table(pdev);
 
diff --git a/drivers/misc/mei/platform-vsc.c b/drivers/misc/mei/platform-vsc.c
index 9787b9cee71c..5100234ba5b6 100644
--- a/drivers/misc/mei/platform-vsc.c
+++ b/drivers/misc/mei/platform-vsc.c
@@ -350,7 +350,7 @@ static int mei_vsc_probe(struct platform_device *pdev)
 	mei_device_init(mei_dev, dev, false, &mei_vsc_hw_ops);
 
 	mei_dev->fw_f_fw_ver_supported = 0;
-	mei_dev->kind = "ivsc";
+	mei_dev->kind = MEI_DEV_KIND_IVSC;
 
 	hw = mei_dev_to_vsc_hw(mei_dev);
 	atomic_set(&hw->write_lock_cnt, 0);
-- 
2.43.0


  reply	other threads:[~2026-04-09 13:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-09 12:55 [char-misc-next 0/3] mei: expose device kind for ioe device Alexander Usyskin
2026-04-09 12:55 ` Alexander Usyskin [this message]
2026-04-09 12:55 ` [char-misc-next 2/3] " Alexander Usyskin
2026-04-09 12:55 ` [char-misc-next 3/3] mei: me: remove comma from mei_cfg_idx sentinel Alexander Usyskin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260409125524.111530-2-alexander.usyskin@intel.com \
    --to=alexander.usyskin@intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=menachem.adin@intel.com \
    --cc=reuvenab@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®