]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mei: store kind as enum
authorAlexander Usyskin <alexander.usyskin@intel.com>
Thu, 9 Apr 2026 12:55:22 +0000 (15:55 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 23 May 2026 11:47:33 +0000 (13:47 +0200)
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>
Link: https://patch.msgid.link/20260409125524.111530-2-alexander.usyskin@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/mei/hw-me.c
drivers/misc/mei/hw-me.h
drivers/misc/mei/main.c
drivers/misc/mei/mei_dev.h
drivers/misc/mei/pci-txe.c
drivers/misc/mei/platform-vsc.c

index e286763b52ec1d17436365394d5c97cdf3eb80ba..28fbd432d80da931104acfb9cc3b0d0625065dd2 100644 (file)
@@ -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;
 }
index 8da8662a9d61a27cfdea5ea9cd1ef27590c97766..884736d76fbb3c024303671b2bff6e961244d7b7 100644 (file)
@@ -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;
index 54f70f513482fc7911978484277a7fa060ccff4a..43667e5d370801ef009b15eab1a88c3744f70c88 100644 (file)
@@ -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);
 
index d8634a7269901950692a6f28cce3cc961e94a5f7..6d081c496cccb3530f9ac15b0fd35a8d8c8127a3 100644 (file)
@@ -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
index 98d1bc2c7f4b521495537d48a4990143ae830b5a..f5441bc5efe281a5e9099908eb7acc6faedbf3b7 100644 (file)
@@ -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);
 
index 9787b9cee71ca67b20e56375d90c83a22a5ab999..5100234ba5b690b68f743f0edcb6443492854267 100644 (file)
@@ -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);