// SPDX-License-Identifier: GPL-2.0 /* * Intel Management Engine Interface (Intel MEI) Linux driver * Copyright (c) 2015, Intel Corporation. */ #include <linux/module.h> #include <linux/slab.h> #include <linux/interrupt.h> #include <linux/debugfs.h> #include <linux/completion.h> #include <linux/watchdog.h> #include <linux/uuid.h> #include <linux/mei_cl_bus.h> /* * iAMT Watchdog Device */ #define INTEL_AMT_WATCHDOG_ID … #define MEI_WDT_DEFAULT_TIMEOUT … #define MEI_WDT_MIN_TIMEOUT … #define MEI_WDT_MAX_TIMEOUT … /* Commands */ #define MEI_MANAGEMENT_CONTROL … /* MEI Management Control version number */ #define MEI_MC_VERSION_NUMBER … /* Sub Commands */ #define MEI_MC_START_WD_TIMER_REQ … #define MEI_MC_START_WD_TIMER_RES … #define MEI_WDT_STATUS_SUCCESS … #define MEI_WDT_WDSTATE_NOT_REQUIRED … #define MEI_MC_STOP_WD_TIMER_REQ … /** * enum mei_wdt_state - internal watchdog state * * @MEI_WDT_PROBE: wd in probing stage * @MEI_WDT_IDLE: wd is idle and not opened * @MEI_WDT_START: wd was opened, start was called * @MEI_WDT_RUNNING: wd is expecting keep alive pings * @MEI_WDT_STOPPING: wd is stopping and will move to IDLE * @MEI_WDT_NOT_REQUIRED: wd device is not required */ enum mei_wdt_state { … }; static const char *mei_wdt_state_str(enum mei_wdt_state state) { … } /** * struct mei_wdt - mei watchdog driver * @wdd: watchdog device * * @cldev: mei watchdog client device * @state: watchdog internal state * @resp_required: ping required response * @response: ping response completion * @unregister: unregister worker * @reg_lock: watchdog device registration lock * @timeout: watchdog current timeout * * @dbgfs_dir: debugfs dir entry */ struct mei_wdt { … }; /** * struct mei_mc_hdr - Management Control Command Header * * @command: Management Control (0x2) * @bytecount: Number of bytes in the message beyond this byte * @subcommand: Management Control Subcommand * @versionnumber: Management Control Version (0x10) */ struct mei_mc_hdr { … }; /** * struct mei_wdt_start_request - watchdog start/ping * * @hdr: Management Control Command Header * @timeout: timeout value * @reserved: reserved (legacy) */ struct mei_wdt_start_request { … } __packed; /** * struct mei_wdt_start_response - watchdog start/ping response * * @hdr: Management Control Command Header * @status: operation status * @wdstate: watchdog status bit mask */ struct mei_wdt_start_response { … } __packed; /** * struct mei_wdt_stop_request - watchdog stop * * @hdr: Management Control Command Header */ struct mei_wdt_stop_request { … } __packed; /** * mei_wdt_ping - send wd start/ping command * * @wdt: mei watchdog device * * Return: 0 on success, * negative errno code on failure */ static int mei_wdt_ping(struct mei_wdt *wdt) { … } /** * mei_wdt_stop - send wd stop command * * @wdt: mei watchdog device * * Return: 0 on success, * negative errno code on failure */ static int mei_wdt_stop(struct mei_wdt *wdt) { … } /** * mei_wdt_ops_start - wd start command from the watchdog core. * * @wdd: watchdog device * * Return: 0 on success or -ENODEV; */ static int mei_wdt_ops_start(struct watchdog_device *wdd) { … } /** * mei_wdt_ops_stop - wd stop command from the watchdog core. * * @wdd: watchdog device * * Return: 0 if success, negative errno code for failure */ static int mei_wdt_ops_stop(struct watchdog_device *wdd) { … } /** * mei_wdt_ops_ping - wd ping command from the watchdog core. * * @wdd: watchdog device * * Return: 0 if success, negative errno code on failure */ static int mei_wdt_ops_ping(struct watchdog_device *wdd) { … } /** * mei_wdt_ops_set_timeout - wd set timeout command from the watchdog core. * * @wdd: watchdog device * @timeout: timeout value to set * * Return: 0 if success, negative errno code for failure */ static int mei_wdt_ops_set_timeout(struct watchdog_device *wdd, unsigned int timeout) { … } static const struct watchdog_ops wd_ops = …; /* not const as the firmware_version field need to be retrieved */ static struct watchdog_info wd_info = …; /** * __mei_wdt_is_registered - check if wdt is registered * * @wdt: mei watchdog device * * Return: true if the wdt is registered with the watchdog subsystem * Locking: should be called under wdt->reg_lock */ static inline bool __mei_wdt_is_registered(struct mei_wdt *wdt) { … } /** * mei_wdt_unregister - unregister from the watchdog subsystem * * @wdt: mei watchdog device */ static void mei_wdt_unregister(struct mei_wdt *wdt) { … } /** * mei_wdt_register - register with the watchdog subsystem * * @wdt: mei watchdog device * * Return: 0 if success, negative errno code for failure */ static int mei_wdt_register(struct mei_wdt *wdt) { … } static void mei_wdt_unregister_work(struct work_struct *work) { … } /** * mei_wdt_rx - callback for data receive * * @cldev: bus device */ static void mei_wdt_rx(struct mei_cl_device *cldev) { … } /** * mei_wdt_notif - callback for event notification * * @cldev: bus device */ static void mei_wdt_notif(struct mei_cl_device *cldev) { … } #if IS_ENABLED(CONFIG_DEBUG_FS) static ssize_t mei_dbgfs_read_activation(struct file *file, char __user *ubuf, size_t cnt, loff_t *ppos) { … } static const struct file_operations dbgfs_fops_activation = …; static ssize_t mei_dbgfs_read_state(struct file *file, char __user *ubuf, size_t cnt, loff_t *ppos) { … } static const struct file_operations dbgfs_fops_state = …; static void dbgfs_unregister(struct mei_wdt *wdt) { … } static void dbgfs_register(struct mei_wdt *wdt) { … } #else static inline void dbgfs_unregister(struct mei_wdt *wdt) {} static inline void dbgfs_register(struct mei_wdt *wdt) {} #endif /* CONFIG_DEBUG_FS */ static int mei_wdt_probe(struct mei_cl_device *cldev, const struct mei_cl_device_id *id) { … } static void mei_wdt_remove(struct mei_cl_device *cldev) { … } #define MEI_UUID_WD … static const struct mei_cl_device_id mei_wdt_tbl[] = …; MODULE_DEVICE_TABLE(mei, mei_wdt_tbl); static struct mei_cl_driver mei_wdt_driver = …; module_mei_cl_driver(…) …; MODULE_AUTHOR(…) …; MODULE_LICENSE(…) …; MODULE_DESCRIPTION(…) …;