mei: create proper iAMT watchdog driver
Subsystems (4)
v4 cover mei: create proper iAMT watchdog driver
Instead of integrating the iAMT watchdog within the mei core driver we will create a watchdog device on the mei client bus and create a proper watchdog driver for it.
V4:
1. Rebase the code over patchset : "watchdog: Replace driver based refcounting"
2. Address comments from Guenter
3. Drop one unrelated patch from the series
V3:
1. Revert to dynamically allocated watchdog device wrapper
2. Export activation state to via debugfs
3. Move runtime unregistration to the BDW patch
V2:
1. The watchdog device is no longer dynamically allocated in separate structure
2. Export device internal status via debugfs
3. Address few comments from Guenter
4. Reworked de/registration
The patches should apply and compile char-misc-next
trees/branches, though the new changes from whatchdog-next are required for proper execution.
I would prefer this will go via char-misc-next as this is the tree
we work against.
Alexander Usyskin (3):
mei: wd: drop the watchdog code from the core mei driver
watchdog: mei_wdt: register wd device only if required
watchdog: mei_wdt: re-register device on event
Tomas Winkler (4):
watchdog: mei_wdt: implement MEI iAMT watchdog driver
watchdog: mei_wdt: add status debugfs entry
mei: bus: whitelist the watchdog client
watchdog: mei_wdt: add activation debugfs entry
Documentation/misc-devices/mei/mei.txt | 12 +- MAINTAINERS | 1 + drivers/misc/mei/Kconfig | 6 +- drivers/misc/mei/Makefile | 1 - drivers/misc/mei/bus-fixup.c | 29 ++ drivers/misc/mei/client.c | 12 +- drivers/misc/mei/client.h | 4 - drivers/misc/mei/init.c | 10 +- drivers/misc/mei/interrupt.c | 15 - drivers/misc/mei/mei_dev.h | 61 +-- drivers/misc/mei/wd.c | 391 ------------------ drivers/watchdog/Kconfig | 15 + drivers/watchdog/Makefile | 1 + drivers/watchdog/mei_wdt.c | 720 +++++++++++++++++++++++++++++++++ 14 files changed, 781 insertions(+), 497 deletions(-) delete mode 100644 drivers/misc/mei/wd.c create mode 100644 drivers/watchdog/mei_wdt.c
Signature · 1 line
2.4.3
PATCH v4 1/7 mei: wd: drop the watchdog code from the core mei driver
From: Alexander Usyskin <[email protected]>
Instead of integrating the iAMT watchdog in the mei core driver we will create a watchdog device on the mei client bus and create a driver for it.
This patch removes the watchdog code from the mei core driver.
---
V2-V4: resend
drivers/misc/mei/Kconfig | 6 +- drivers/misc/mei/Makefile | 1 - drivers/misc/mei/client.c | 12 +- drivers/misc/mei/client.h | 4 - drivers/misc/mei/init.c | 10 +- drivers/misc/mei/interrupt.c | 15 -- drivers/misc/mei/mei_dev.h | 61 +------ drivers/misc/mei/wd.c | 391 ------------------------------------------- 8 files changed, 9 insertions(+), 491 deletions(-) delete mode 100644 drivers/misc/mei/wd.c
drivers/misc/mei/Kconfig +3 -3
@@ -1,6 +1,6 @@ config INTEL_MEI tristate "Intel Management Engine Interface" - depends on X86 && PCI && WATCHDOG_CORE + depends on X86 && PCI help The Intel Management Engine (Intel ME) provides Manageability, Security and Media services for system containing Intel chipsets.
@@ -12,7 +12,7 @@ config INTEL_MEI config INTEL_MEI_ME tristate "ME Enabled Intel Chipsets" select INTEL_MEI - depends on X86 && PCI && WATCHDOG_CORE + depends on X86 && PCI help MEI support for ME Enabled Intel chipsets.
@@ -37,7 +37,7 @@ config INTEL_MEI_ME config INTEL_MEI_TXE tristate "Intel Trusted Execution Environment with ME Interface" select INTEL_MEI - depends on X86 && PCI && WATCHDOG_CORE + depends on X86 && PCI help MEI Support for Trusted Execution Environment device on Intel SoCs
drivers/misc/mei/Makefile +0 -1
@@ -9,7 +9,6 @@ mei-objs += interrupt.o mei-objs += client.o mei-objs += main.o mei-objs += amthif.o -mei-objs += wd.o mei-objs += bus.o mei-objs += bus-fixup.o mei-$(CONFIG_DEBUG_FS) += debugfs.o
drivers/misc/mei/client.c +3 -9
@@ -648,7 +648,7 @@ int mei_cl_unlink(struct mei_cl *cl)if (!cl)return 0 ; -/* wd and amthif might not be initialized */ +/* amthif might not be initialized */ if (!cl->dev)return 0 ;
@@ -679,17 +679,11 @@ void mei_host_client_init(struct work_struct *work)mutex_lock (&dev->device_lock); - me_cl =mei_me_cl_by_uuid (dev, &mei_amthif_guid);if (me_cl)mei_amthif_host_init (dev, me_cl);mei_me_cl_put (me_cl); - me_cl =mei_me_cl_by_uuid (dev, &mei_wd_guid); -if (me_cl) -mei_wd_host_init (dev, me_cl); -mei_me_cl_put (me_cl); - dev->dev_state =MEI_DEV_ENABLED ; dev->reset_count =0 ;mutex_unlock (&dev->device_lock);
@@ -1153,7 +1147,7 @@ err:* * Return: 1 if mei_flow_ctrl_creds >0, 0 - otherwise. */ -int mei_cl_flow_ctrl_creds (struct mei_cl *cl) +static int mei_cl_flow_ctrl_creds (struct mei_cl *cl) {int rets;
@@ -1186,7 +1180,7 @@ int mei_cl_flow_ctrl_creds(struct mei_cl *cl)* 0 on success * -EINVAL when ctrl credits are <= 0 */ -int mei_cl_flow_ctrl_reduce (struct mei_cl *cl) +static int mei_cl_flow_ctrl_reduce (struct mei_cl *cl) {if (WARN_ON (!cl || !cl->me_cl))return -EINVAL ;
drivers/misc/mei/client.h +0 -4
@@ -18,7 +18,6 @@#define _MEI_CLIENT_H_#include <linux/types.h> -#include <linux/watchdog.h> #include <linux/poll.h> #include <linux/mei.h>
@@ -120,9 +119,6 @@ struct mei_cl_cb *mei_cl_alloc_cb(struct mei_cl *cl, size_t length, enum mei_cb_file_ops type, struct file *fp);int mei_cl_flush_queues (struct mei_cl *cl,const struct file *fp); -int mei_cl_flow_ctrl_creds (struct mei_cl *cl); - -int mei_cl_flow_ctrl_reduce (struct mei_cl *cl);/* * MEI input output function prototype */
drivers/misc/mei/init.c +1 -9
@@ -156,8 +156,7 @@ int mei_reset(struct mei_device *dev)mei_cl_all_wakeup (dev);/* remove entry if already in list */ -dev_dbg (dev->dev,"remove iamthif and wd from the file list.\n" ); -mei_cl_unlink (&dev->wd_cl); +dev_dbg (dev->dev,"remove iamthif from the file list.\n" );mei_cl_unlink (&dev->iamthif_cl);mei_amthif_reset_params (dev); }
@@ -165,7 +164,6 @@ int mei_reset(struct mei_device *dev)mei_hbm_reset (dev); dev->rd_msg_hdr =0 ; - dev->wd_pending = false;if (ret) {dev_err (dev->dev,"hw_reset failed ret = %d\n" , ret);
@@ -335,16 +333,12 @@ void mei_stop(struct mei_device *dev)mutex_lock (&dev->device_lock); -mei_wd_stop (dev); - dev->dev_state =MEI_DEV_POWER_DOWN ;mei_reset (dev);/* move device to disabled state unconditionally */ dev->dev_state =MEI_DEV_DISABLED ;mutex_unlock (&dev->device_lock); - -mei_watchdog_unregister (dev); }EXPORT_SYMBOL_GPL (mei_stop);
@@ -394,7 +388,6 @@ void mei_device_init(struct mei_device *dev,init_waitqueue_head (&dev->wait_hw_ready);init_waitqueue_head (&dev->wait_pg);init_waitqueue_head (&dev->wait_hbm_start); -init_waitqueue_head (&dev->wait_stop_wd); dev->dev_state =MEI_DEV_INITIALIZING ; dev->reset_count =0 ;
@@ -407,7 +400,6 @@ void mei_device_init(struct mei_device *dev,INIT_WORK (&dev->init_work, mei_host_client_init);INIT_WORK (&dev->reset_work, mei_reset_work); -INIT_LIST_HEAD (&dev->wd_cl.link);INIT_LIST_HEAD (&dev->iamthif_cl.link);mei_io_list_init (&dev->amthif_cmd_list);mei_io_list_init (&dev->amthif_rd_complete_list);
drivers/misc/mei/interrupt.c +0 -15
@@ -360,21 +360,6 @@ int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list)list_move_tail (&cb->list, &cmpl_list->list); } -if (dev->wd_state ==MEI_WD_STOPPING ) { - dev->wd_state =MEI_WD_IDLE ; -wake_up (&dev->wait_stop_wd); - } - -if (mei_cl_is_connected (&dev->wd_cl)) { -if (dev->wd_pending && -mei_cl_flow_ctrl_creds (&dev->wd_cl) >0 ) { - ret =mei_wd_send (dev); -if (ret) -return ret; - dev->wd_pending = false; - } - } -/* complete control write list CB */ dev_dbg (dev->dev,"complete control write list cb.\n" );list_for_each_entry_safe (cb, next, &dev->ctrl_wr_list.list, list) {
drivers/misc/mei/mei_dev.h +2 -59
121 lines not on this page · raw message
drivers/misc/mei/wd.c deleted +0 -391
391 lines not on this page · raw message
Signature · 1 line
2.4.3
PATCH v4 2/7 watchdog: mei_wdt: implement MEI iAMT watchdog driver
In reply to Tomas WinklerCreate a driver with the generic watchdog interface for the MEI iAMT watchdog device.
---
V2: The watchdog device is no longer dynamically allocated in separate structure
V3: Revert back to dynamically allocated watchdog device wrapper
V4: Rebase the code over patchset : "watchdog: Replace driver based refcounting"
drop mei_wdt_dev structure
Documentation/misc-devices/mei/mei.txt | 12 +- MAINTAINERS | 1 + drivers/watchdog/Kconfig | 15 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/mei_wdt.c | 404 +++++++++++++++++++++++++++++++++ 5 files changed, 427 insertions(+), 6 deletions(-) create mode 100644 drivers/watchdog/mei_wdt.c
Documentation/misc-devices/mei/mei.txt +6 -6
@@ -231,15 +231,15 @@ IT knows when a platform crashes even when there is a hard failure on the host. The Intel AMT Watchdog is composed of two parts: 1) Firmware feature - receives the heartbeats and sends an event when the heartbeats stop. - 2) Intel MEI driver - connects to the watchdog feature, configures the - watchdog and sends the heartbeats. + 2) Intel MEI iAMT watchdog driver - connects to the watchdog feature, + configures the watchdog and sends the heartbeats. -The Intel MEI driver uses the kernel watchdog API to configure the Intel AMT -Watchdog and to send heartbeats to it. The default timeout of the +The Intel iAMT watchdog MEI driver uses the kernel watchdog API to configure +the Intel AMT Watchdog and to send heartbeats to it. The default timeout of the watchdog is 120 seconds. -If the Intel AMT Watchdog feature does not exist (i.e. the connection failed), -the Intel MEI driver will disable the sending of heartbeats. +If the Intel AMT is not enabled in the firmware then the watchdog client won't enumerate +on the me client bus and watchdog devices won't be exposed. Supported Chipsets
MAINTAINERS +1 -0
@@ -5666,6 +5666,7 @@ S: Supported F: include/uapi/linux/mei.h F: include/linux/mei_cl_bus.h F: drivers/misc/mei/* +F: drivers/watchdog/mei_wdt.c F: Documentation/misc-devices/mei/* INTEL MIC DRIVERS (mic)
drivers/watchdog/Kconfig +15 -0
@@ -1154,6 +1154,21 @@ config SBC_EPX_C3_WATCHDOG To compile this driver as a module, choose M here: the module will be called sbc_epx_c3. +config INTEL_MEI_WDT + tristate "Intel MEI iAMT Watchdog" + depends on INTEL_MEI && X86 + select WATCHDOG_CORE + ---help--- + A device driver for the Intel MEI iAMT watchdog. + + The Intel AMT Watchdog is an OS Health (Hang/Crash) watchdog. + Whenever the OS hangs or crashes, iAMT will send an event + to any subscriber to this event. The watchdog doesn't reset the + the platform. + + To compile this driver as a module, choose M here: + the module will be called mei_wdt. + # M32R Architecture # M68K Architecture
drivers/watchdog/Makefile +1 -0
@@ -123,6 +123,7 @@ obj-$(CONFIG_MACHZ_WDT) += machzwd.o obj-$(CONFIG_SBC_EPX_C3_WATCHDOG) += sbc_epx_c3.o obj-$(CONFIG_INTEL_SCU_WATCHDOG) += intel_scu_watchdog.o obj-$(CONFIG_INTEL_MID_WATCHDOG) += intel-mid_wdt.o +obj-$(CONFIG_INTEL_MEI_WDT) += mei_wdt.o # M32R Architecture
drivers/watchdog/mei_wdt.c new file +404 -0
404 lines not on this page · raw message
Signature · 1 line
2.4.3
PATCH v4 3/7 watchdog: mei_wdt: add status debugfs entry
In reply to Tomas WinklerAdd entry for displaying current watchdog internal state
cat <debugfs>/mei_wdt/state
IDLE|START|RUNNING|STOPPING
---
V2: new in the series
V3: rebase
V4: cleanup the code
drivers/watchdog/mei_wdt.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)
drivers/watchdog/mei_wdt.c +87 -0
@@ -15,6 +15,7 @@#include <linux/module.h> #include <linux/slab.h> #include <linux/interrupt.h> +#include <linux/debugfs.h> #include <linux/watchdog.h> #include <linux/uuid.h>
@@ -54,6 +55,24 @@ enum mei_wdt_state { MEI_WDT_STOPPING, }; +#if IS_ENABLED (CONFIG_DEBUG_FS ) +static const char *mei_wdt_state_str (enum mei_wdt_state state) +{ +switch (state) { +case MEI_WDT_IDLE : +return "IDLE" ; +case MEI_WDT_START : +return "START" ; +case MEI_WDT_RUNNING : +return "RUNNING" ; +case MEI_WDT_STOPPING : +return "STOPPING" ; +default : +return "unknown" ; + } +} +#endif /* CONFIG_DEBUG_FS */ +/** * struct mei_wdt - mei watchdog driver * @wdd: watchdog device
@@ -61,6 +80,8 @@ enum mei_wdt_state {* @cldev: mei watchdog client device * @state: watchdog internal state * @timeout: watchdog current timeout +* +* @dbgfs_dir: debugfs dir entry */ struct mei_wdt {struct watchdog_device wdd;
@@ -68,6 +89,10 @@ struct mei_wdt {struct mei_cl_device *cldev;enum mei_wdt_state state;u16 timeout; + +#if IS_ENABLED (CONFIG_DEBUG_FS ) +struct dentry *dbgfs_dir; +#endif /* CONFIG_DEBUG_FS */ };/*
@@ -310,6 +335,63 @@ static int mei_wdt_register(struct mei_wdt *wdt)return ret; } +#if IS_ENABLED (CONFIG_DEBUG_FS ) + +static ssize_t mei_dbgfs_read_state (struct file *file,char __user *ubuf, +size_t cnt,loff_t *ppos) +{ +struct mei_wdt *wdt = file->private_data; +const size_t bufsz =32 ; +char buf[bufsz]; +ssize_t pos; + + pos =scnprintf (buf, bufsz,"state: %s\n" , +mei_wdt_state_str (wdt->state)); + +return simple_read_from_buffer (ubuf, cnt, ppos, buf, pos); +} + +static const struct file_operations dbgfs_fops_state = { + .open = simple_open, + .read = mei_dbgfs_read_state, + .llseek = generic_file_llseek, +}; + +static void dbgfs_unregister (struct mei_wdt *wdt) +{ +debugfs_remove_recursive (wdt->dbgfs_dir); + wdt->dbgfs_dir =NULL ; +} + +static int dbgfs_register (struct mei_wdt *wdt) +{ +struct dentry *dir, *f; + + dir =debugfs_create_dir (KBUILD_MODNAME ,NULL ); +if (!dir) +return -ENOMEM ; + + wdt->dbgfs_dir = dir; + f =debugfs_create_file ("state" ,S_IRUSR , dir, wdt, &dbgfs_fops_state); +if (!f) + goto err; + +return 0 ; +err: +dbgfs_unregister (wdt); +return -ENODEV ; +} + +#else + +static inline void dbgfs_unregister (struct mei_wdt *wdt) {} + +static inline int dbgfs_register (struct mei_wdt *wdt) +{ +return 0 ; +} +#endif /* CONFIG_DEBUG_FS */ +static int mei_wdt_probe (struct mei_cl_device *cldev,const struct mei_cl_device_id *id) {
@@ -337,6 +419,9 @@ static int mei_wdt_probe(struct mei_cl_device *cldev,if (ret) goto err_disable; +if (dbgfs_register (wdt)) +dev_warn (&cldev->dev,"cannot register debugfs\n" ); +return 0 ; err_disable:
@@ -356,6 +441,8 @@ static int mei_wdt_remove(struct mei_cl_device *cldev)mei_cldev_disable (cldev); +dbgfs_unregister (wdt); +kfree (wdt);return 0 ;
Signature · 1 line
2.4.3
PATCH v4 4/7 mei: bus: whitelist the watchdog client
In reply to Tomas WinklerThe iAMT WD client has to be whitelisted sice it has two connections and is filtered out by number_of_connections fixup.
Also the API has changed for BDW and SKL but firmware haven't updated the protocol version.
---
V2-V4: resend
drivers/misc/mei/bus-fixup.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
drivers/misc/mei/bus-fixup.c +29 -0
@@ -35,6 +35,9 @@ static const uuid_le mei_nfc_info_guid = MEI_UUID_NFC_INFO;#define MEI_UUID_NFC_HCI UUID_LE(0x0bb17a78, 0x2a8e, 0x4c50, \ 0x94, 0xd4, 0x50, 0x26, 0x67, 0x23, 0x77, 0x5c) +#define MEI_UUID_WD UUID_LE(0x05B79A6F, 0x4628, 0x4D7F, \ + 0x89, 0x9D, 0xA9, 0x15, 0x14, 0xCB, 0x32, 0xAB) +#define MEI_UUID_ANY NULL_UUID_LE/**
@@ -66,6 +69,31 @@ static void blacklist(struct mei_cl_device *cldev) cldev->do_match =0 ; } +/** +* mei_wd - wd client on the bus, change protocol version +* as the API has changed. +* +* @cldev: me clients device +*/ +#if IS_ENABLED (CONFIG_INTEL_MEI_ME ) +#include <linux/pci.h> +#include "hw-me-regs.h" +static void mei_wd (struct mei_cl_device *cldev) +{ +struct pci_dev *pdev =to_pci_dev (cldev->dev.parent); + +dev_dbg (&cldev->dev,"running hook %s\n" , __func__); +if (pdev->device ==MEI_DEV_ID_WPT_LP || + pdev->device ==MEI_DEV_ID_SPT || + pdev->device ==MEI_DEV_ID_SPT_H ) + cldev->me_cl->props.protocol_version =0x2 ; + + cldev->do_match =1 ; +} +#else +static inline void mei_wd (struct mei_cl_device *cldev) {} +#endif /* CONFIG_INTEL_MEI_ME */ +struct mei_nfc_cmd {u8 command;u8 status;
@@ -280,6 +308,7 @@ static struct mei_fixup {MEI_FIXUP (MEI_UUID_ANY , number_of_connections),MEI_FIXUP (MEI_UUID_NFC_INFO , blacklist),MEI_FIXUP (MEI_UUID_NFC_HCI , mei_nfc), + MEI_FIXUP(MEI_UUID_WD, mei_wd), };/**
Signature · 1 line
2.4.3
PATCH v4 5/7 watchdog: mei_wdt: register wd device only if required
In reply to Tomas WinklerFrom: Alexander Usyskin <[email protected]>
For Intel Broadwell and newer platforms, the ME device can inform the host whether the watchdog functionality is activated or not. If the watchdog functionality is not activated then the watchdog interface can be not registered and eliminate unnecessary pings and hence lower the power consumption by avoiding waking up the device.
The feature can be deactivated also without reboot
in that case the watchdog device should be unregistered at runtime.
---
V2: rework unregistration
V3: rebase; implement unregistraion also at runtime
V4: Rebase the code over patchset : "watchdog: Replace driver based refcounting"
drivers/watchdog/mei_wdt.c | 196 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 187 insertions(+), 9 deletions(-)
drivers/watchdog/mei_wdt.c +187 -9
@@ -16,6 +16,7 @@#include <linux/slab.h> #include <linux/interrupt.h> #include <linux/debugfs.h> +#include <linux/completion.h> #include <linux/watchdog.h> #include <linux/uuid.h>
@@ -38,27 +39,35 @@/* Sub Commands */ #define MEI_MC_START_WD_TIMER_REQ 0x13 +#define MEI_MC_START_WD_TIMER_RES 0x83 +#define MEI_WDT_STATUS_SUCCESS 0 +#define MEI_WDT_WDSTATE_NOT_REQUIRED 0x1#define MEI_MC_STOP_WD_TIMER_REQ 0x14/** * 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 { +MEI_WDT_PROBE ,MEI_WDT_IDLE ,MEI_WDT_START ,MEI_WDT_RUNNING ,MEI_WDT_STOPPING , +MEI_WDT_NOT_REQUIRED , }; -#if IS_ENABLED (CONFIG_DEBUG_FS )static const char *mei_wdt_state_str (enum mei_wdt_state state) {switch (state) { +case MEI_WDT_PROBE : +return "PROBE" ;case MEI_WDT_IDLE :return "IDLE" ;case MEI_WDT_START :
@@ -67,11 +76,12 @@ static const char *mei_wdt_state_str(enum mei_wdt_state state)return "RUNNING" ;case MEI_WDT_STOPPING :return "STOPPING" ; +case MEI_WDT_NOT_REQUIRED : +return "NOT_REQUIRED" ;default :return "unknown" ; } } -#endif /* CONFIG_DEBUG_FS */ /** * struct mei_wdt - mei watchdog driver
@@ -79,6 +89,10 @@ static const char *mei_wdt_state_str(enum mei_wdt_state state)* * @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
@@ -88,6 +102,10 @@ struct mei_wdt {struct mei_cl_device *cldev;enum mei_wdt_state state; +bool resp_required; +struct completion response; +struct work_struct unregister; +struct mutex reg_lock;u16 timeout;#if IS_ENABLED (CONFIG_DEBUG_FS )
@@ -124,6 +142,19 @@ 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 { +struct mei_mc_hdr hdr; +u8 status; +u8 wdstate; +} __packed; + +/** * struct mei_wdt_stop_request - watchdog stop * * @hdr: Management Control Command Header
@@ -244,13 +275,18 @@ static int mei_wdt_ops_ping(struct watchdog_device *wdd)if (wdt->state !=MEI_WDT_START && wdt->state !=MEI_WDT_RUNNING )return 0 ; +if (wdt->resp_required) +init_completion (&wdt->response); + + wdt->state =MEI_WDT_RUNNING ; ret =mei_wdt_ping (wdt);if (ret)return ret; - wdt->state =MEI_WDT_RUNNING ; +if (wdt->resp_required) + ret =wait_for_completion_killable (&wdt->response); -return 0 ; +return ret; }/**
@@ -291,14 +327,34 @@ 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) +{ +return !!watchdog_get_drvdata (&wdt->wdd); +} + +/** * mei_wdt_unregister - unregister from the watchdog subsystem * * @wdt: mei watchdog device */ static void mei_wdt_unregister (struct mei_wdt *wdt) { -watchdog_unregister_device (&wdt->wdd); -watchdog_set_drvdata (&wdt->wdd,NULL ); +mutex_lock (&wdt->reg_lock); + +if (__mei_wdt_is_registered (wdt)) { +watchdog_unregister_device (&wdt->wdd); +watchdog_set_drvdata (&wdt->wdd,NULL ); +memset (&wdt->wdd,0 ,sizeof (wdt->wdd)); + } + +mutex_unlock (&wdt->reg_lock); }/**
@@ -318,6 +374,13 @@ static int mei_wdt_register(struct mei_wdt *wdt) dev = &wdt->cldev->dev; +mutex_lock (&wdt->reg_lock); + +if (__mei_wdt_is_registered (wdt)) { + ret =0 ; + goto out; + } + wdt->wdd.info = &wd_info; wdt->wdd.ops = &wd_ops; wdt->wdd.parent = dev;
@@ -332,9 +395,102 @@ static int mei_wdt_register(struct mei_wdt *wdt)watchdog_set_drvdata (&wdt->wdd,NULL ); } + wdt->state =MEI_WDT_IDLE ; + +out: +mutex_unlock (&wdt->reg_lock);return ret; } +static void mei_wdt_unregister_work (struct work_struct *work) +{ + struct mei_wdt *wdt = container_of(work, struct mei_wdt, unregister); + +mei_wdt_unregister (wdt); +} + +/** +* mei_wdt_event_rx - callback for data receive +* +* @cldev: bus device +*/ +static void mei_wdt_event_rx (struct mei_cl_device *cldev) +{ +struct mei_wdt *wdt =mei_cldev_get_drvdata (cldev); +struct mei_wdt_start_response res; +const size_t res_len =sizeof (res); +int ret; + + ret =mei_cldev_recv (wdt->cldev, (u8 *)&res, res_len); +if (ret <0 ) { +dev_err (&cldev->dev,"failure in recv %d\n" , ret); +return ; + } + +/* Empty response can be sent on stop */ +if (ret ==0 ) +return ; + +if (ret <sizeof (struct mei_mc_hdr )) { +dev_err (&cldev->dev,"recv small data %d\n" , ret); +return ; + } + +if (res.hdr.command !=MEI_MANAGEMENT_CONTROL || + res.hdr.versionnumber !=MEI_MC_VERSION_NUMBER ) { +dev_err (&cldev->dev,"wrong command received\n" ); +return ; + } + +if (res.hdr.subcommand !=MEI_MC_START_WD_TIMER_RES ) { +dev_warn (&cldev->dev,"unsupported command %d :%s[%d]\n" , + res.hdr.subcommand, +mei_wdt_state_str (wdt->state), + wdt->state); +return ; + } + +if (wdt->state ==MEI_WDT_RUNNING ) { +if (res.wdstate &MEI_WDT_WDSTATE_NOT_REQUIRED ) { + wdt->state =MEI_WDT_NOT_REQUIRED ; +schedule_work (&wdt->unregister); + } + goto out; + } + +if (wdt->state ==MEI_WDT_PROBE ) { +if (res.wdstate &MEI_WDT_WDSTATE_NOT_REQUIRED ) { + wdt->state =MEI_WDT_NOT_REQUIRED ; + }else { +/* stop the watchdog and register watchdog device */ +mei_wdt_stop (wdt); +mei_wdt_register (wdt); + } +return ; + } + +dev_warn (&cldev->dev,"not in correct state %s[%d]\n" , +mei_wdt_state_str (wdt->state), wdt->state); + +out: +if (!completion_done (&wdt->response)) +complete (&wdt->response); +} + +/** +* mei_wdt_event - callback for event receive +* +* @cldev: bus device +* @events: event mask +* @context: callback context +*/ +static void mei_wdt_event (struct mei_cl_device *cldev, +u32 events,void *context) +{ +if (events &BIT (MEI_CL_EVENT_RX )) +mei_wdt_event_rx (cldev); +} +#if IS_ENABLED (CONFIG_DEBUG_FS ) static ssize_t mei_dbgfs_read_state(struct file *file, char __user *ubuf,
@@ -403,8 +559,13 @@ static int mei_wdt_probe(struct mei_cl_device *cldev,return -ENOMEM ; wdt->timeout =MEI_WDT_DEFAULT_TIMEOUT ; - wdt->state =MEI_WDT_IDLE ; + wdt->state =MEI_WDT_PROBE ; wdt->cldev = cldev; + wdt->resp_required =mei_cldev_ver (cldev) >0x1 ; +mutex_init (&wdt->reg_lock); +init_completion (&wdt->response); +INIT_WORK (&wdt->unregister, mei_wdt_unregister_work); +mei_cldev_set_drvdata (cldev, wdt); ret =mei_cldev_enable (cldev);
@@ -413,9 +574,20 @@ static int mei_wdt_probe(struct mei_cl_device *cldev, goto err_out; } + ret =mei_cldev_register_event_cb (wdt->cldev,BIT (MEI_CL_EVENT_RX ), + mei_wdt_event,NULL ); +if (ret) { +dev_err (&cldev->dev,"Could not register event ret=%d\n" , ret); + goto err_disable; + } + wd_info.firmware_version =mei_cldev_ver (cldev); - ret =mei_wdt_register (wdt); +if (wdt->resp_required) + ret =mei_wdt_ping (wdt); +else + ret =mei_wdt_register (wdt); +if (ret) goto err_disable;
@@ -437,6 +609,12 @@ static int mei_wdt_remove(struct mei_cl_device *cldev) {struct mei_wdt *wdt =mei_cldev_get_drvdata (cldev); +/* Free the caller in case of fw initiated or unexpected reset */ +if (!completion_done (&wdt->response)) +complete (&wdt->response); + +cancel_work_sync (&wdt->unregister); +mei_wdt_unregister (wdt);mei_cldev_disable (cldev);
@@ -452,7 +630,7 @@ static int mei_wdt_remove(struct mei_cl_device *cldev) 0x89, 0x9D, 0xA9, 0x15, 0x14, 0xCB, 0x32, 0xAB)static struct mei_cl_device_id mei_wdt_tbl[] = { - { .uuid =MEI_UUID_WD , .version =0x1 }, + { .uuid =MEI_UUID_WD , .version =MEI_CL_VERSION_ANY },/* required last entry */ { } };
Signature · 1 line
2.4.3
Guenter Roeck
maintainerRe: [char-misc-next, v4, 5/7] watchdog: mei_wdt: register wd device only if required
Hi Tomas,
Quoted 25 lines · Tomas
From: Alexander Usyskin <[email protected]>
For Intel Broadwell and newer platforms, the ME device can inform the host whether the watchdog functionality is activated or not. If the watchdog functionality is not activated then the watchdog interface can be not registered and eliminate unnecessary pings and hence lower the power consumption by avoiding waking up the device.
The feature can be deactivated also without reboot
in that case the watchdog device should be unregistered at runtime.Signed-off-by Alexander Usyskin <[email protected]>Signed-off-by Tomas Winkler <[email protected]>---
V2: rework unregistration
V3: rebase; implement unregistraion also at runtime
V4: Rebase the code over patchset : "watchdog: Replace driver based refcounting"drivers/watchdog/mei_wdt.c | 196 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 187 insertions(+), 9 deletions(-)drivers/watchdog/mei_wdt.c +0
-0
[ ... ]
drivers/watchdog/mei_wdt.c static int mei_wdt_register(struct mei_wdt *wdt) · line 410
Quoted 6 lines
drivers/watchdog/mei_wdt.c +6
-0+static void mei_wdt_unregister_work (struct work_struct *work) +{ + struct mei_wdt *wdt = container_of(work, struct mei_wdt, unregister); + +mei_wdt_unregister (wdt); +}
Registration is synchronous, unregistration is asynchronous.
Assuming that is on purpose, I think it warrants an explanation.
Thanks,
Guenter
RE: [char-misc-next, v4, 5/7] watchdog: mei_wdt: register wd device only if required
Quoted 52 lines
-----Original Message-----
From: Guenter Roeck [mailto:[email protected]]
Sent: Sunday, January 17, 2016 19:13
To: Winkler, Tomas
Cc: Greg Kroah-Hartman; Wim Van Sebroeck; Usyskin, Alexander; linux- [email protected]; [email protected]
Subject: Re: [char-misc-next, v4, 5/7] watchdog:mei_wdt: register wd device only if requiredHi Tomas,
Quoted 10 lines · Tomas
From: Alexander Usyskin <[email protected]>
For Intel Broadwell and newer platforms, the ME device can inform the host whether the watchdog functionality is activated or not. If the watchdog functionality is not activated then the watchdog interface can be not registered and eliminate unnecessary pings and hence lower the power consumption by avoiding waking up the device.
The feature can be deactivated also without reboot
in that case the watchdog device should be unregistered at runtime.Quoted 6 lines
Signed-off-by Alexander Usyskin <[email protected]>Signed-off-by Tomas Winkler <[email protected]>---
V2: rework unregistration
V3: rebase; implement unregistraion also at runtime
V4: Rebase the code over patchset : "watchdog: Replace driver basedrefcounting"
Quoted 2 lines
drivers/watchdog/mei_wdt.c | 196++++++++++++++++++++++++++++++++++++++++++---
Quoted 7 lines
1 file changed, 187 insertions(+), 9 deletions(-)drivers/watchdog/mei_wdt.c +0
-0[ ... ]
drivers/watchdog/mei_wdt.c static int mei_wdt_register(struct mei_wdt *wdt) · line 410
Quoted 6 lines
drivers/watchdog/mei_wdt.c +6
-0+static void mei_wdt_unregister_work (struct work_struct *work) +{ + struct mei_wdt *wdt = container_of(work, struct mei_wdt, unregister); + +mei_wdt_unregister (wdt); +}Registration is synchronous, unregistration is asynchronous.
Quoted 2 lines
Assuming that is on purpose, I think it warrants an explanation.
The unregistration is detected on response from the ping, which is run under same mutex as unregistration. Tomas
Guenter Roeck
maintainerRe: [char-misc-next, v4, 5/7] watchdog: mei_wdt: register wd device only if required
Quoted 52 lines · Tomas
Quoted 52 lines
-----Original Message-----
From: Guenter Roeck [mailto:[email protected]]
Sent: Sunday, January 17, 2016 19:13
To: Winkler, Tomas
Cc: Greg Kroah-Hartman; Wim Van Sebroeck; Usyskin, Alexander; linux- [email protected]; [email protected]
Subject: Re: [char-misc-next, v4, 5/7] watchdog:mei_wdt: register wd device only if requiredHi Tomas,
Quoted 10 lines · Tomas
From: Alexander Usyskin <[email protected]>
For Intel Broadwell and newer platforms, the ME device can inform the host whether the watchdog functionality is activated or not. If the watchdog functionality is not activated then the watchdog interface can be not registered and eliminate unnecessary pings and hence lower the power consumption by avoiding waking up the device.
The feature can be deactivated also without reboot
in that case the watchdog device should be unregistered at runtime.Quoted 6 lines
Signed-off-by Alexander Usyskin <[email protected]>Signed-off-by Tomas Winkler <[email protected]>---
V2: rework unregistration
V3: rebase; implement unregistraion also at runtime
V4: Rebase the code over patchset : "watchdog: Replace driver basedrefcounting"
Quoted 2 lines
drivers/watchdog/mei_wdt.c | 196++++++++++++++++++++++++++++++++++++++++++---
Quoted 7 lines
1 file changed, 187 insertions(+), 9 deletions(-)drivers/watchdog/mei_wdt.c +0
-0[ ... ]
drivers/watchdog/mei_wdt.c static int mei_wdt_register(struct mei_wdt *wdt) · line 410
Quoted 6 lines
drivers/watchdog/mei_wdt.c +6
-0+static void mei_wdt_unregister_work (struct work_struct *work) +{ + struct mei_wdt *wdt = container_of(work, struct mei_wdt, unregister); + +mei_wdt_unregister (wdt); +}Registration is synchronous, unregistration is asynchronous.
Quoted 6 lines
Quoted 2 lines
Assuming that is on purpose, I think it warrants an explanation.
The unregistration is detected on response from the ping, which is run under same mutex as unregistration. Tomas
And that explains why registration can be synchronous and unregistration has to be asynchronous ?
Guenter
RE: [char-misc-next, v4, 5/7] watchdog: mei_wdt: register wd device only if required
Quoted 48 lines
only
Quoted 45 lines
Quoted 45 lines
if required
Hi Tomas,
Quoted 10 lines · Tomas
From: Alexander Usyskin <[email protected]>
For Intel Broadwell and newer platforms, the ME device can inform the host whether the watchdog functionality is activated or not. If the watchdog functionality is not activated then the watchdog interface can be not registered and eliminate unnecessary pings and hence lower the power consumption by avoiding waking up the device.
The feature can be deactivated also without reboot
in that case the watchdog device should be unregistered at runtime.Quoted 6 lines
Signed-off-by Alexander Usyskin <[email protected]>Signed-off-by Tomas Winkler <[email protected]>---
V2: rework unregistration
V3: rebase; implement unregistraion also at runtime
V4: Rebase the code over patchset : "watchdog: Replace driver basedrefcounting"
Quoted 2 lines
drivers/watchdog/mei_wdt.c | 196++++++++++++++++++++++++++++++++++++++++++---
Quoted 7 lines
1 file changed, 187 insertions(+), 9 deletions(-)drivers/watchdog/mei_wdt.c +0
-0[ ... ]
drivers/watchdog/mei_wdt.c static int mei_wdt_register(struct mei_wdt *wdt) · line 410
Quoted 6 lines
drivers/watchdog/mei_wdt.c +6
-0+static void mei_wdt_unregister_work (struct work_struct *work) +{ + struct mei_wdt *wdt = container_of(work, struct mei_wdt, unregister); + +mei_wdt_unregister (wdt); +}Registration is synchronous, unregistration is asynchronous.
Assuming that is on purpose, I think it warrants an explanation.
Quoted 7 lines
Quoted 1 line
The unregistration is detected on response from the ping, which is run under
same mutex as unregistration.
Quoted 3 lines
Tomas
And that explains why registration can be synchronous and unregistration has to be asynchronous ?
You need to connect the dots but yes.
The registration is run from the internal ping request (in probe) or from an internal event (in runtime), so the flow is not already locked by the watchdog mutex. Hope it helps.
Tomas
Guenter Roeck
maintainerRe: [char-misc-next, v4, 5/7] watchdog: mei_wdt: register wd device only if required
Quoted 53 lines · Tomas
Quoted 53 lines
only
Quoted 43 lines
Quoted 43 lines
if required
Hi Tomas,
Quoted 10 lines · Tomas
From: Alexander Usyskin <[email protected]>
For Intel Broadwell and newer platforms, the ME device can inform the host whether the watchdog functionality is activated or not. If the watchdog functionality is not activated then the watchdog interface can be not registered and eliminate unnecessary pings and hence lower the power consumption by avoiding waking up the device.
The feature can be deactivated also without reboot
in that case the watchdog device should be unregistered at runtime.Quoted 6 lines
Signed-off-by Alexander Usyskin <[email protected]>Signed-off-by Tomas Winkler <[email protected]>---
V2: rework unregistration
V3: rebase; implement unregistraion also at runtime
V4: Rebase the code over patchset : "watchdog: Replace driver basedrefcounting"
Quoted 2 lines
drivers/watchdog/mei_wdt.c | 196++++++++++++++++++++++++++++++++++++++++++---
Quoted 7 lines
1 file changed, 187 insertions(+), 9 deletions(-)drivers/watchdog/mei_wdt.c +0
-0[ ... ]
drivers/watchdog/mei_wdt.c static int mei_wdt_register(struct mei_wdt *wdt) · line 410
Quoted 6 lines
drivers/watchdog/mei_wdt.c +6
-0+static void mei_wdt_unregister_work (struct work_struct *work) +{ + struct mei_wdt *wdt = container_of(work, struct mei_wdt, unregister); + +mei_wdt_unregister (wdt); +}Registration is synchronous, unregistration is asynchronous.
Quoted 3 lines
Quoted 2 lines
Assuming that is on purpose, I think it warrants an explanation.
The unregistration is detected on response from the ping, which is run under
same mutex as unregistration.
Quoted 3 lines
Tomas
Quoted 6 lines
Quoted 2 lines
And that explains why registration can be synchronous and unregistration has to be asynchronous ?
You need to connect the dots but yes.
The registration is run from the internal ping request (in probe) or from an internal event (in runtime), so the flow is not already locked by the watchdog mutex. Hope it helps.
What I was asking for is a comment such as
"We can not unregister directly because a ping operation (triggered through the watchdog subsystem) is pending and must be completed first."
Guenter
RE: [char-misc-next, v4, 5/7] watchdog: mei_wdt: register wd device only if required
Quoted 62 lines · Tomas
Quoted 7 lines
Quoted 7 lines
only
Quoted 4 lines
Quoted 4 lines
if required
Hi Tomas,
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines · Tomas
Quoted 6 lines
From: Alexander Usyskin <[email protected]>
For Intel Broadwell and newer platforms, the ME device can inform the host whether the watchdog functionality is activated or not. If the watchdog functionality is not activated then the watchdog interface can be not registered and eliminate unnecessary pings and hence lower
the
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 10 lines
power consumption by avoiding waking up the device.
The feature can be deactivated also without reboot
in that case the watchdog device should be unregistered at runtime.Signed-off-by Alexander Usyskin <[email protected]>Signed-off-by Tomas Winkler <[email protected]>---
V2: rework unregistration
V3: rebase; implement unregistraion also at runtime
V4: Rebase the code over patchset : "watchdog: Replace driver basedrefcounting"
Quoted 2 lines
drivers/watchdog/mei_wdt.c | 196++++++++++++++++++++++++++++++++++++++++++---
Quoted 7 lines
1 file changed, 187 insertions(+), 9 deletions(-)drivers/watchdog/mei_wdt.c +0
-0[ ... ]
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/watchdog/mei_wdt.c static int mei_wdt_register(struct mei_wdt *wdt)
Quoted 3 lines
drivers/watchdog/mei_wdt.c +3
-0+static void mei_wdt_unregister_work (struct work_struct *work) +{ + struct mei_wdt *wdt = container_of(work, struct mei_wdt,unregister);
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
drivers/watchdog/mei_wdt.c static int mei_wdt_register(struct mei_wdt *wdt) · line 410
Quoted 3 lines
drivers/watchdog/mei_wdt.c +3
-0+ +mei_wdt_unregister (wdt); +}Registration is synchronous, unregistration is asynchronous.
Assuming that is on purpose, I think it warrants an explanation.
The unregistration is detected on response from the ping, which is run under
same mutex as unregistration.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Tomas
And that explains why registration can be synchronous and unregistration has to be asynchronous ?
You need to connect the dots but yes.
The registration is run from the internal ping request (in probe) or from an
Quoted 8 lines
internal event (in runtime), so the flow is not already locked by the watchdog mutex.
Quoted 1 line
Hope it helps.
What I was asking for is a comment such as
"We can not unregister directly because a ping operation (triggered through the watchdog subsystem) is pending and must be completed first."
You can put it also that way, but in the bottom line you will get deadlock.
According your comment I'm guessing that you are asking me to update the commit message, please be more direct, I'm not native English speaker and may miss little nuances.
Thanks
Tomas
Guenter Roeck
maintainerRe: [char-misc-next, v4, 5/7] watchdog: mei_wdt: register wd device only if required
Quoted 64 lines · Tomas
Quoted 64 lines · Tomas
Quoted 7 lines
Quoted 7 lines
only
Quoted 4 lines
Quoted 4 lines
if required
Hi Tomas,
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines · Tomas
Quoted 6 lines
From: Alexander Usyskin <[email protected]>
For Intel Broadwell and newer platforms, the ME device can inform the host whether the watchdog functionality is activated or not. If the watchdog functionality is not activated then the watchdog interface can be not registered and eliminate unnecessary pings and hence lower
the
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 10 lines
power consumption by avoiding waking up the device.
The feature can be deactivated also without reboot
in that case the watchdog device should be unregistered at runtime.Signed-off-by Alexander Usyskin <[email protected]>Signed-off-by Tomas Winkler <[email protected]>---
V2: rework unregistration
V3: rebase; implement unregistraion also at runtime
V4: Rebase the code over patchset : "watchdog: Replace driver basedrefcounting"
Quoted 2 lines
drivers/watchdog/mei_wdt.c | 196++++++++++++++++++++++++++++++++++++++++++---
Quoted 7 lines
1 file changed, 187 insertions(+), 9 deletions(-)drivers/watchdog/mei_wdt.c +0
-0[ ... ]
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/watchdog/mei_wdt.c
Quoted 3 lines
drivers/watchdog/mei_wdt.c +3
-0+static void mei_wdt_unregister_work (struct work_struct *work) +{ + struct mei_wdt *wdt = container_of(work, struct mei_wdt,unregister);
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
drivers/watchdog/mei_wdt.c
Quoted 3 lines
drivers/watchdog/mei_wdt.c +3
-0+ +mei_wdt_unregister (wdt); +}Registration is synchronous, unregistration is asynchronous.
Assuming that is on purpose, I think it warrants an explanation.
The unregistration is detected on response from the ping, which is run under
same mutex as unregistration.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Tomas
And that explains why registration can be synchronous and unregistration has to be asynchronous ?
You need to connect the dots but yes.
The registration is run from the internal ping request (in probe) or from aninternal event (in runtime), so the flow is not already locked by the watchdog mutex.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Hope it helps.
What I was asking for is a comment such as
"We can not unregister directly because a ping operation (triggered through the watchdog subsystem) is pending and must be completed first."
You can put it also that way, but in the bottom line you will get deadlock.
Yes, understood. Maybe that should be part of the comment.
Quoted 3 lines
According your comment I'm guessing that you are asking me to update the commit message, please be more direct, I'm not native English speaker and may miss little nuances.
Hi Tomas,
please add a comment into the source code, describing why unregistration has to be asynchronous. It took me a while to understand the context, and we want to make sure that others don't have to repeat that exercise.
Other than that, the series is fine with me, except that the patches affecting the mei directory don't apply to the current mainline as of this morning (possibly due to some other changes in that directory).
I would suggest to add the comment, wait for -rc1, rebase, and re-send the series with my Acked-by: added to all patches.
Thanks,
Guenter
RE: [char-misc-next, v4, 5/7] watchdog: mei_wdt: register wd device only if required
Quoted 85 lines · Tomas
Quoted 7 lines
Quoted 7 lines · Tomas
Quoted 5 lines
Quoted 5 lines
only
Quoted 2 lines
Quoted 2 lines
if required
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Hi Tomas,
Quoted 5 lines · Tomas
From: Alexander Usyskin <[email protected]>
For Intel Broadwell and newer platforms, the ME device can inform the host whether the watchdog functionality is activated or not. If the watchdog functionality is not activated then the watchdog
interface
Quoted 35 lines
Quoted 35 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
can be not registered and eliminate unnecessary pings and hence lower
the
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 10 lines
power consumption by avoiding waking up the device.
The feature can be deactivated also without reboot
in that case the watchdog device should be unregistered at runtime.Signed-off-by Alexander Usyskin <[email protected]>Signed-off-by Tomas Winkler <[email protected]>---
V2: rework unregistration
V3: rebase; implement unregistraion also at runtime
V4: Rebase the code over patchset : "watchdog: Replace driver basedrefcounting"
Quoted 2 lines
drivers/watchdog/mei_wdt.c | 196++++++++++++++++++++++++++++++++++++++++++---
Quoted 7 lines
1 file changed, 187 insertions(+), 9 deletions(-)drivers/watchdog/mei_wdt.c +0
-0[ ... ]
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/watchdog/mei_wdt.c
Quoted 3 lines
drivers/watchdog/mei_wdt.c +3
-0+static void mei_wdt_unregister_work (struct work_struct *work) +{ + struct mei_wdt *wdt = container_of(work, struct mei_wdt,unregister);
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/watchdog/mei_wdt.c
Quoted 3 lines
drivers/watchdog/mei_wdt.c +3
-0+ +mei_wdt_unregister (wdt); +}Registration is synchronous, unregistration is asynchronous.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Assuming that is on purpose, I think it warrants an explanation.
The unregistration is detected on response from the ping, which is run
under
Quoted 11 lines
Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
same mutex as unregistration.
Quoted 3 lines
Tomas
And that explains why registration can be synchronous and unregistration has to be asynchronous ?
You need to connect the dots but yes.
The registration is run from the internal ping request (in probe) or from aninternal event (in runtime), so the flow is not already locked by the watchdog mutex.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Hope it helps.
What I was asking for is a comment such as
"We can not unregister directly because a ping operation (triggered through the watchdog subsystem) is pending and must be completed first."
You can put it also that way, but in the bottom line you will get deadlock.
Yes, understood. Maybe that should be part of the comment.
Quoted 1 line
According your comment I'm guessing that you are asking me to update the
commit message, please be more direct,
Quoted 2 lines
I'm not native English speaker and may miss little nuances.
Quoted 7 lines
Hi Tomas,
please add a comment into the source code, describing why unregistration has to be
asynchronous. It took me a while to understand the context, and we want to make
sure that others don't have to repeat that exercise.
Sure, no problem.
Quoted 3 lines
Other than that, the series is fine with me, except that the patches affecting the mei directory don't apply to the current mainline as of this morning (possibly due to some other changes in that directory).
There are other pending patches that weren't merged yet and are not related to watchdog, we see if they require rebase after the merging window is closed.
Quoted 3 lines
I would suggest to add the comment, wait for -rc1, rebase, and re-send the series with my Acked-by: added to all patches.
Thanks and I appreciate your time reviewing this series. Tomas
PATCH v4 6/7 watchdog: mei_wdt: add activation debugfs entry
In reply to Tomas WinklerAdd entry for displaying whether the device has activated or deactivated watchdog fw application.
cat <debugfs>/mei_wdt/activation
activated | deactivated
---
V3: new in the series
V4: Rebase the code over patchset : "watchdog: Replace driver based refcounting"
drivers/watchdog/mei_wdt.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
drivers/watchdog/mei_wdt.c +27 -0
@@ -493,6 +493,28 @@ static void mei_wdt_event(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) +{ +struct mei_wdt *wdt = file->private_data; +const size_t bufsz =32 ; +char buf[bufsz]; +ssize_t pos; + +mutex_lock (&wdt->reg_lock); + pos =scnprintf (buf, bufsz,"%s\n" , +__mei_wdt_is_registered (wdt) ?"activated" :"deactivated" ); +mutex_unlock (&wdt->reg_lock); + +return simple_read_from_buffer (ubuf, cnt, ppos, buf, pos); +} + +static const struct file_operations dbgfs_fops_activation = { + .open = simple_open, + .read = mei_dbgfs_read_activation, + .llseek = generic_file_llseek, +}; +static ssize_t mei_dbgfs_read_state (struct file *file,char __user *ubuf,size_t cnt,loff_t *ppos) {
@@ -532,6 +554,11 @@ static int dbgfs_register(struct mei_wdt *wdt)if (!f) goto err; + f =debugfs_create_file ("activation" ,S_IRUSR , + dir, wdt, &dbgfs_fops_activation); +if (!f) + goto err; +return 0 ; err:dbgfs_unregister (wdt);
Signature · 1 line
2.4.3
PATCH v4 7/7 watchdog: mei_wdt: re-register device on event
In reply to Tomas WinklerFrom: Alexander Usyskin <[email protected]>
For Intel SKL platform the ME device can inform the host via asynchronous notification that the watchdog feature was activated on the device. The activation doesn't require reboot.
In that case the driver registers the watchdog device with the kernel.
---
V2: rework un/registration in runtime
V3: rebase, runtime unregistration was moved to BDW patch.
V4: Rebase the code over patchset : "watchdog: Replace driver based refcounting"
drivers/watchdog/mei_wdt.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)
drivers/watchdog/mei_wdt.c +26 -2
@@ -477,6 +477,21 @@ out:complete (&wdt->response); } +/* +* mei_wdt_notify_event - callback for event notification +* +* @cldev: bus device +*/ +static void mei_wdt_notify_event (struct mei_cl_device *cldev) +{ +struct mei_wdt *wdt =mei_cldev_get_drvdata (cldev); + +if (wdt->state !=MEI_WDT_NOT_REQUIRED ) +return ; + +mei_wdt_register (wdt); +} +/** * mei_wdt_event - callback for event receive *
@@ -489,6 +504,9 @@ static void mei_wdt_event(struct mei_cl_device *cldev, {if (events &BIT (MEI_CL_EVENT_RX ))mei_wdt_event_rx (cldev); + +if (events &BIT (MEI_CL_EVENT_NOTIF )) +mei_wdt_notify_event (cldev); }#if IS_ENABLED (CONFIG_DEBUG_FS )
@@ -601,9 +619,15 @@ static int mei_wdt_probe(struct mei_cl_device *cldev, goto err_out; } - ret =mei_cldev_register_event_cb (wdt->cldev,BIT (MEI_CL_EVENT_RX ), + ret =mei_cldev_register_event_cb (wdt->cldev, +BIT (MEI_CL_EVENT_RX ) | +BIT (MEI_CL_EVENT_NOTIF ), mei_wdt_event,NULL ); -if (ret) { + +/* on legacy devices notification is not supported +* this doesn't fail the registration for RX event +*/ +if (ret && ret != -EOPNOTSUPP ) {dev_err (&cldev->dev,"Could not register event ret=%d\n" , ret); goto err_disable; }
Signature · 1 line
2.4.3
Greg Kroah-Hartman
maintainerQuoted 4 lines · Tomas Winkler
Instead of integrating the iAMT watchdog within the mei core driver we will create a watchdog device on the mei client bus and create a proper watchdog driver for it.
I applied the first 4 patches here, please fix up the rest and resend.
thanks,
greg k-h