19fff0425STomas Winkler /* SPDX-License-Identifier: GPL-2.0 */
29dc64d6aSTomas Winkler /*
35b063995STomas Winkler * Copyright (c) 2012-2022, Intel Corporation. All rights reserved.
466ef5ea9STomas Winkler * Intel Management Engine Interface (Intel MEI) Linux driver
566ef5ea9STomas Winkler */
666ef5ea9STomas Winkler
79dc64d6aSTomas Winkler #ifndef _MEI_INTERFACE_H_
89dc64d6aSTomas Winkler #define _MEI_INTERFACE_H_
99dc64d6aSTomas Winkler
1081ec5502SBjorn Helgaas #include <linux/irqreturn.h>
114ad96db6STomas Winkler #include <linux/pci.h>
124ad96db6STomas Winkler #include <linux/mei.h>
134ad96db6STomas Winkler
149dc64d6aSTomas Winkler #include "mei_dev.h"
1552c34561STomas Winkler #include "client.h"
1666ef5ea9STomas Winkler
174ad96db6STomas Winkler /*
184ad96db6STomas Winkler * mei_cfg - mei device configuration
194ad96db6STomas Winkler *
204ad96db6STomas Winkler * @fw_status: FW status
214ad96db6STomas Winkler * @quirk_probe: device exclusion quirk
222f79d3d1SAlexander Usyskin * @kind: MEI head kind
237026a5fdSAlexander Usyskin * @dma_size: device DMA buffers size
24f8204f0dSAlexander Usyskin * @fw_ver_supported: is fw version retrievable from FW
2552f6efdfSAlexander Usyskin * @hw_trc_supported: does the hw support trc register
264ad96db6STomas Winkler */
274ad96db6STomas Winkler struct mei_cfg {
284ad96db6STomas Winkler const struct mei_fw_status fw_status;
2945a2c762STomas Winkler bool (*quirk_probe)(const struct pci_dev *pdev);
302f79d3d1SAlexander Usyskin const char *kind;
317026a5fdSAlexander Usyskin size_t dma_size[DMA_DSCR_NUM];
32f8204f0dSAlexander Usyskin u32 fw_ver_supported:1;
3352f6efdfSAlexander Usyskin u32 hw_trc_supported:1;
344ad96db6STomas Winkler };
354ad96db6STomas Winkler
364ad96db6STomas Winkler
374ad96db6STomas Winkler #define MEI_PCI_DEVICE(dev, cfg) \
384ad96db6STomas Winkler .vendor = PCI_VENDOR_ID_INTEL, .device = (dev), \
394ad96db6STomas Winkler .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, \
40f5ac3c49STomas Winkler .driver_data = (kernel_ulong_t)(cfg),
414ad96db6STomas Winkler
42180ea05bSTomas Winkler #define MEI_ME_RPM_TIMEOUT 500 /* ms */
43180ea05bSTomas Winkler
444ad96db6STomas Winkler /**
45ce23139cSAlexander Usyskin * struct mei_me_hw - me hw specific data
46ce23139cSAlexander Usyskin *
474ad96db6STomas Winkler * @cfg: per device generation config and ops
48ce23139cSAlexander Usyskin * @mem_addr: io memory address
49261b3e1fSAlexander Usyskin * @irq: irq number
50ce23139cSAlexander Usyskin * @pg_state: power gating state
51bb9f4d26SAlexander Usyskin * @d0i3_supported: di03 support
528c8d964cSTomas Winkler * @hbuf_depth: depth of hardware host/write buffer in slots
53261e071aSTomas Winkler * @read_fws: read FW status register handler
545b063995STomas Winkler * @polling_thread: interrupt polling thread
555b063995STomas Winkler * @wait_active: the polling thread activity wait queue
565b063995STomas Winkler * @is_active: the device is active
574ad96db6STomas Winkler */
5852c34561STomas Winkler struct mei_me_hw {
594ad96db6STomas Winkler const struct mei_cfg *cfg;
6052c34561STomas Winkler void __iomem *mem_addr;
61261b3e1fSAlexander Usyskin int irq;
62ba9cdd0eSTomas Winkler enum mei_pg_state pg_state;
63bb9f4d26SAlexander Usyskin bool d0i3_supported;
648c8d964cSTomas Winkler u8 hbuf_depth;
65261e071aSTomas Winkler int (*read_fws)(const struct mei_device *dev, int where, u32 *val);
665b063995STomas Winkler /* polling */
675b063995STomas Winkler struct task_struct *polling_thread;
685b063995STomas Winkler wait_queue_head_t wait_active;
695b063995STomas Winkler bool is_active;
7052c34561STomas Winkler };
7166ef5ea9STomas Winkler
7252c34561STomas Winkler #define to_me_hw(dev) (struct mei_me_hw *)((dev)->hw)
7352c34561STomas Winkler
mei_me_hw_use_polling(const struct mei_me_hw * hw)745b063995STomas Winkler static inline bool mei_me_hw_use_polling(const struct mei_me_hw *hw)
755b063995STomas Winkler {
765b063995STomas Winkler return hw->irq < 0;
775b063995STomas Winkler }
785b063995STomas Winkler
79f5ac3c49STomas Winkler /**
80f5ac3c49STomas Winkler * enum mei_cfg_idx - indices to platform specific configurations.
81f5ac3c49STomas Winkler *
82f5ac3c49STomas Winkler * Note: has to be synchronized with mei_cfg_list[]
83f5ac3c49STomas Winkler *
84f5ac3c49STomas Winkler * @MEI_ME_UNDEF_CFG: Lower sentinel.
85f5ac3c49STomas Winkler * @MEI_ME_ICH_CFG: I/O Controller Hub legacy devices.
86f5ac3c49STomas Winkler * @MEI_ME_ICH10_CFG: I/O Controller Hub platforms Gen10
87f8204f0dSAlexander Usyskin * @MEI_ME_PCH6_CFG: Platform Controller Hub platforms (Gen6).
88f8204f0dSAlexander Usyskin * @MEI_ME_PCH7_CFG: Platform Controller Hub platforms (Gen7).
89f5ac3c49STomas Winkler * @MEI_ME_PCH_CPT_PBG_CFG:Platform Controller Hub workstations
90f5ac3c49STomas Winkler * with quirk for Node Manager exclusion.
91f5ac3c49STomas Winkler * @MEI_ME_PCH8_CFG: Platform Controller Hub Gen8 and newer
92f5ac3c49STomas Winkler * client platforms.
932f79d3d1SAlexander Usyskin * @MEI_ME_PCH8_ITOUCH_CFG:Platform Controller Hub Gen8 and newer
942f79d3d1SAlexander Usyskin * client platforms (iTouch).
95f76d77f5STomas Winkler * @MEI_ME_PCH8_SPS_4_CFG: Platform Controller Hub Gen8 and newer
96f5ac3c49STomas Winkler * servers platforms with quirk for
97f5ac3c49STomas Winkler * SPS firmware exclusion.
987026a5fdSAlexander Usyskin * @MEI_ME_PCH12_CFG: Platform Controller Hub Gen12 and newer
99f76d77f5STomas Winkler * @MEI_ME_PCH12_SPS_4_CFG:Platform Controller Hub Gen12 up to 4.0
100f76d77f5STomas Winkler * servers platforms with quirk for
101f76d77f5STomas Winkler * SPS firmware exclusion.
102f76d77f5STomas Winkler * @MEI_ME_PCH12_SPS_CFG: Platform Controller Hub Gen12 5.0 and newer
103d76bc820STomas Winkler * servers platforms with quirk for
104d76bc820STomas Winkler * SPS firmware exclusion.
105*d37b59c7STomas Winkler * @MEI_ME_PCH12_SPS_ITOUCH_CFG: Platform Controller Hub Gen12
106*d37b59c7STomas Winkler * client platforms (iTouch)
10752f6efdfSAlexander Usyskin * @MEI_ME_PCH15_CFG: Platform Controller Hub Gen15 and newer
1088c289ea0SAlexander Usyskin * @MEI_ME_PCH15_SPS_CFG: Platform Controller Hub Gen15 and newer
1098c289ea0SAlexander Usyskin * servers platforms with quirk for
1108c289ea0SAlexander Usyskin * SPS firmware exclusion.
111*d37b59c7STomas Winkler * @MEI_ME_GSC_CFG: Graphics System Controller
112*d37b59c7STomas Winkler * @MEI_ME_GSCFI_CFG: Graphics System Controller Firmware Interface
113f5ac3c49STomas Winkler * @MEI_ME_NUM_CFG: Upper Sentinel.
114f5ac3c49STomas Winkler */
115f5ac3c49STomas Winkler enum mei_cfg_idx {
116f5ac3c49STomas Winkler MEI_ME_UNDEF_CFG,
117f5ac3c49STomas Winkler MEI_ME_ICH_CFG,
118f5ac3c49STomas Winkler MEI_ME_ICH10_CFG,
119f8204f0dSAlexander Usyskin MEI_ME_PCH6_CFG,
120f8204f0dSAlexander Usyskin MEI_ME_PCH7_CFG,
121f5ac3c49STomas Winkler MEI_ME_PCH_CPT_PBG_CFG,
122f5ac3c49STomas Winkler MEI_ME_PCH8_CFG,
1232f79d3d1SAlexander Usyskin MEI_ME_PCH8_ITOUCH_CFG,
124f76d77f5STomas Winkler MEI_ME_PCH8_SPS_4_CFG,
1257026a5fdSAlexander Usyskin MEI_ME_PCH12_CFG,
126f76d77f5STomas Winkler MEI_ME_PCH12_SPS_4_CFG,
127d76bc820STomas Winkler MEI_ME_PCH12_SPS_CFG,
1282f79d3d1SAlexander Usyskin MEI_ME_PCH12_SPS_ITOUCH_CFG,
12952f6efdfSAlexander Usyskin MEI_ME_PCH15_CFG,
1308c289ea0SAlexander Usyskin MEI_ME_PCH15_SPS_CFG,
131a98c30fdSTomas Winkler MEI_ME_GSC_CFG,
132a98c30fdSTomas Winkler MEI_ME_GSCFI_CFG,
133f5ac3c49STomas Winkler MEI_ME_NUM_CFG,
134f5ac3c49STomas Winkler };
135f5ac3c49STomas Winkler
136f5ac3c49STomas Winkler const struct mei_cfg *mei_me_get_cfg(kernel_ulong_t idx);
1378d929d48SAlexander Usyskin
138907b471cSTomas Winkler struct mei_device *mei_me_dev_init(struct device *parent,
13995953618SAlexander Usyskin const struct mei_cfg *cfg, bool slow_fw);
14066ef5ea9STomas Winkler
1412d1995fcSAlexander Usyskin int mei_me_pg_enter_sync(struct mei_device *dev);
1422d1995fcSAlexander Usyskin int mei_me_pg_exit_sync(struct mei_device *dev);
143ba9cdd0eSTomas Winkler
14406ecd645STomas Winkler irqreturn_t mei_me_irq_quick_handler(int irq, void *dev_id);
14506ecd645STomas Winkler irqreturn_t mei_me_irq_thread_handler(int irq, void *dev_id);
1465b063995STomas Winkler int mei_me_polling_thread(void *_dev);
14706ecd645STomas Winkler
1489dc64d6aSTomas Winkler #endif /* _MEI_INTERFACE_H_ */
149