mfd / platform: cros_ec: Query EC protocol version if EC transitions between RO/RW
Subsystems (2)
PATCH v2 1/1 mfd / platform: cros_ec: Query EC protocol version if EC transitions between RO/RW
RO and RW of EC may have different EC protocol version. If EC transitions between RO and RW, but AP does not reboot (this is true for fingerprint microcontroller / cros_fp, but not true for main ec / cros_ec), the AP still uses the protocol version queried before transition, which can cause problems. In the case of fingerprint microcontroller, this causes AP to send the wrong version of EC_CMD_GET_NEXT_EVENT to RO in the interrupt handler, which in turn prevents RO to clear the interrupt line to AP, in an infinite loop.
Once an EC_HOST_EVENT_INTERFACE_READY is received, we know that there might have been a transition between RO and RW, so re-query the protocol.
--- drivers/platform/chrome/cros_ec.c | 23 +++++++++++++++++++++ include/linux/platform_data/cros_ec_proto.h | 5 +++++ 2 files changed, 28 insertions(+)
drivers/platform/chrome/cros_ec.c +23 -0
@@ -104,6 +104,22 @@ static int cros_ec_sleep_event(struct cros_ec_device *ec_dev, u8 sleep_event)return ret; } +static int cros_ec_ready_event (struct notifier_block *nb, +unsigned long queued_during_suspend,void *_notify) +{ + struct cros_ec_device *ec_dev = container_of(nb, struct cros_ec_device, + notifier_ready); +u32 host_event =cros_ec_get_host_event (ec_dev); + +if (host_event &EC_HOST_EVENT_MASK (EC_HOST_EVENT_INTERFACE_READY )) { +mutex_lock (&ec_dev->lock); +cros_ec_query_all (ec_dev); +mutex_unlock (&ec_dev->lock); +return NOTIFY_OK ; + +return NOTIFY_DONE ; +} +/** * cros_ec_register() - Register a new ChromeOS EC, using the provided info. * @ec_dev: Device to register.
@@ -201,6 +217,13 @@ int cros_ec_register(struct cros_ec_device *ec_dev)dev_dbg (ec_dev->dev,"Error %d clearing sleep event to ec" , err); +/* Register the notifier for EC_HOST_EVENT_INTERFACE_READY event. */ + ec_dev->notifier_ready.notifier_call = cros_ec_ready_event; + err =blocking_notifier_chain_register (&ec_dev->event_notifier, + &ec_dev->notifier_ready); +if (err) +return err; +dev_info (dev,"Chrome EC device registered\n" );return 0 ;
include/linux/platform_data/cros_ec_proto.h +5 -0
@@ -161,6 +161,11 @@ struct cros_ec_device {int event_size;u32 host_event_wake_mask;u32 last_resume_result; +/* +* The notifier block to let the kernel re-query EC communication +* protocol when the EC sends EC_HOST_EVENT_INTERFACE_READY. +*/ +struct notifier_block notifier_ready;/* The platform devices used by the mfd driver */ struct platform_device *ec;
Signature · 1 line
2.21.0
Hi,
Quoted 28 lines · Yicheng Li
RO and RW of EC may have different EC protocol version. If EC transitions between RO and RW, but AP does not reboot (this is true for fingerprint microcontroller /
cros_fp, but not true for main ec /cros_ec), the AP still uses the protocol version queried before transition, which can cause problems. In the case of fingerprint microcontroller, this causes AP to send the wrong version ofEC_CMD_GET_NEXT_EVENTto RO in the interrupt handler, which in turn prevents RO to clear the interrupt line to AP, in an infinite loop.Once an
EC_HOST_EVENT_INTERFACE_READYis received, we know that there might have been a transition between RO and RW, so re-query the protocol.Signed-off-by Yicheng Li <[email protected]>--- drivers/platform/chrome/cros_ec.c | 23 +++++++++++++++++++++ include/linux/platform_data/cros_ec_proto.h | 5 +++++ 2 files changed, 28 insertions(+)drivers/platform/chrome/cros_ec.c +2
-0@@ -104,6 +104,22 @@ static int cros_ec_sleep_event(struct cros_ec_device *ec_dev, u8 sleep_event)return ret; } +static int cros_ec_ready_event (struct notifier_block *nb, +unsigned long queued_during_suspend,void *_notify)
drivers/platform/chrome/cros_ec.c static int cros_ec_sleep_event(struct cros_ec_device *ec_dev, u8 sleep_event) · line 118
Quoted 10 lines
drivers/platform/chrome/cros_ec.c +10
-0+{ + struct cros_ec_device *ec_dev = container_of(nb, struct cros_ec_device, + notifier_ready); +u32 host_event =cros_ec_get_host_event (ec_dev); + +if (host_event &EC_HOST_EVENT_MASK (EC_HOST_EVENT_INTERFACE_READY )) { +mutex_lock (&ec_dev->lock); +cros_ec_query_all (ec_dev); +mutex_unlock (&ec_dev->lock); +return NOTIFY_OK ;
I think you're missing a closing bracket here. Please make sure to do a build test before sending the patches to the mailing list.
Quoted 26 lines
drivers/platform/chrome/cros_ec.c +11
-0+ +return NOTIFY_DONE ; +} +/** * cros_ec_register() - Register a new ChromeOS EC, using the provided info. * @ec_dev: Device to register. @@ -201,6 +217,13 @@ int cros_ec_register(struct cros_ec_device *ec_dev)dev_dbg (ec_dev->dev,"Error %d clearing sleep event to ec" , err); +/* Register the notifier for EC_HOST_EVENT_INTERFACE_READY event. */ + ec_dev->notifier_ready.notifier_call = cros_ec_ready_event; + err =blocking_notifier_chain_register (&ec_dev->event_notifier, + &ec_dev->notifier_ready); +if (err) +return err; +dev_info (dev,"Chrome EC device registered\n" );return 0 ;include/linux/platform_data/cros_ec_proto.h +0
-0
include/linux/platform_data/cros_ec_proto.h struct cros_ec_device { · line 167
Quoted 7 lines
include/linux/platform_data/cros_ec_proto.h +4
-0@@ -161,6 +161,11 @@ struct cros_ec_device {int event_size;u32 host_event_wake_mask;u32 last_resume_result; +/* +* The notifier block to let the kernel re-query EC communication +* protocol when the EC sends EC_HOST_EVENT_INTERFACE_READY. +*/
The comment should go in the documentation of the struct, above struct cros_ec_device in correct kernel-doc format, not here.
Thanks,
Enric
Quoted 5 lines
include/linux/platform_data/cros_ec_proto.h +1
-0+struct notifier_block notifier_ready;/* The platform devices used by the mfd driver */ struct platform_device *ec;
PATCH v3 1/1 mfd / platform: cros_ec: Query EC protocol version if EC transitions between RO/RW
RO and RW of EC may have different EC protocol version. If EC transitions between RO and RW, but AP does not reboot (this is true for fingerprint microcontroller / cros_fp, but not true for main ec / cros_ec), the AP still uses the protocol version queried before transition, which can cause problems. In the case of fingerprint microcontroller, this causes AP to send the wrong version of EC_CMD_GET_NEXT_EVENT to RO in the interrupt handler, which in turn prevents RO to clear the interrupt line to AP, in an infinite loop.
Once an EC_HOST_EVENT_INTERFACE_READY is received, we know that there might have been a transition between RO and RW, so re-query the protocol.
--- drivers/platform/chrome/cros_ec.c | 24 +++++++++++++++++++++ include/linux/platform_data/cros_ec_proto.h | 3 +++ 2 files changed, 27 insertions(+)
drivers/platform/chrome/cros_ec.c +24 -0
@@ -104,6 +104,23 @@ static int cros_ec_sleep_event(struct cros_ec_device *ec_dev, u8 sleep_event)return ret; } +static int cros_ec_ready_event (struct notifier_block *nb, +unsigned long queued_during_suspend,void *_notify) +{ + struct cros_ec_device *ec_dev = container_of(nb, struct cros_ec_device, + notifier_ready); +u32 host_event =cros_ec_get_host_event (ec_dev); + +if (host_event &EC_HOST_EVENT_MASK (EC_HOST_EVENT_INTERFACE_READY )) { +mutex_lock (&ec_dev->lock); +cros_ec_query_all (ec_dev); +mutex_unlock (&ec_dev->lock); +return NOTIFY_OK ; + } + +return NOTIFY_DONE ; +} +/** * cros_ec_register() - Register a new ChromeOS EC, using the provided info. * @ec_dev: Device to register.
@@ -201,6 +218,13 @@ int cros_ec_register(struct cros_ec_device *ec_dev)dev_dbg (ec_dev->dev,"Error %d clearing sleep event to ec" , err); +/* Register the notifier for EC_HOST_EVENT_INTERFACE_READY event. */ + ec_dev->notifier_ready.notifier_call = cros_ec_ready_event; + err =blocking_notifier_chain_register (&ec_dev->event_notifier, + &ec_dev->notifier_ready); +if (err) +return err; +dev_info (dev,"Chrome EC device registered\n" );return 0 ;
include/linux/platform_data/cros_ec_proto.h +3 -0
@@ -121,6 +121,8 @@ struct cros_ec_command {* @event_data: Raw payload transferred with the MKBP event. * @event_size: Size in bytes of the event data. * @host_event_wake_mask: Mask of host events that cause wake from suspend. +* @notifier_ready: The notifier_block to let the kernel re-query EC +* communication protocol when the EC sends EC_HOST_EVENT_INTERFACE_READY. * @ec: The platform_device used by the mfd driver to interface with the * main EC. * @pd: The platform_device used by the mfd driver to interface with the
@@ -161,6 +163,7 @@ struct cros_ec_device {int event_size;u32 host_event_wake_mask;u32 last_resume_result; +struct notifier_block notifier_ready;/* The platform devices used by the mfd driver */ struct platform_device *ec;
Signature · 1 line
2.21.0
PATCH v4 1/1 mfd / platform: cros_ec: Query EC protocol version if EC transitions between RO/RW
In reply to Enric Balletbo i SerraRO and RW of EC may have different EC protocol version. If EC transitions between RO and RW, but AP does not reboot (this is true for fingerprint microcontroller / cros_fp, but not true for main ec / cros_ec), the AP still uses the protocol version queried before transition, which can cause problems. In the case of fingerprint microcontroller, this causes AP to send the wrong version of EC_CMD_GET_NEXT_EVENT to RO in the interrupt handler, which in turn prevents RO to clear the interrupt line to AP, in an infinite loop.
Once an EC_HOST_EVENT_INTERFACE_READY is received, we know that there might have been a transition between RO and RW, so re-query the protocol.
--- drivers/platform/chrome/cros_ec.c | 24 +++++++++++++++++++++ include/linux/platform_data/cros_ec_proto.h | 3 +++ 2 files changed, 27 insertions(+)
drivers/platform/chrome/cros_ec.c +24 -0
@@ -104,6 +104,23 @@ static int cros_ec_sleep_event(struct cros_ec_device *ec_dev, u8 sleep_event)return ret; } +static int cros_ec_ready_event (struct notifier_block *nb, +unsigned long queued_during_suspend,void *_notify) +{ + struct cros_ec_device *ec_dev = container_of(nb, struct cros_ec_device, + notifier_ready); +u32 host_event =cros_ec_get_host_event (ec_dev); + +if (host_event &EC_HOST_EVENT_MASK (EC_HOST_EVENT_INTERFACE_READY )) { +mutex_lock (&ec_dev->lock); +cros_ec_query_all (ec_dev); +mutex_unlock (&ec_dev->lock); +return NOTIFY_OK ; + } + +return NOTIFY_DONE ; +} +/** * cros_ec_register() - Register a new ChromeOS EC, using the provided info. * @ec_dev: Device to register.
@@ -201,6 +218,13 @@ int cros_ec_register(struct cros_ec_device *ec_dev)dev_dbg (ec_dev->dev,"Error %d clearing sleep event to ec" , err); +/* Register the notifier for EC_HOST_EVENT_INTERFACE_READY event. */ + ec_dev->notifier_ready.notifier_call = cros_ec_ready_event; + err =blocking_notifier_chain_register (&ec_dev->event_notifier, + &ec_dev->notifier_ready); +if (err) +return err; +dev_info (dev,"Chrome EC device registered\n" );return 0 ;
include/linux/platform_data/cros_ec_proto.h +3 -0
@@ -121,6 +121,8 @@ struct cros_ec_command {* @event_data: Raw payload transferred with the MKBP event. * @event_size: Size in bytes of the event data. * @host_event_wake_mask: Mask of host events that cause wake from suspend. +* @notifier_ready: The notifier_block to let the kernel re-query EC +* communication protocol when the EC sends EC_HOST_EVENT_INTERFACE_READY. * @ec: The platform_device used by the mfd driver to interface with the * main EC. * @pd: The platform_device used by the mfd driver to interface with the
@@ -161,6 +163,7 @@ struct cros_ec_device {int event_size;u32 host_event_wake_mask;u32 last_resume_result; +struct notifier_block notifier_ready;/* The platform devices used by the mfd driver */ struct platform_device *ec;
Signature · 1 line
2.21.0
Hi Yicheng,
I looked at this patch deeply and I have a question.
Quoted 26 lines · Yicheng Li
RO and RW of EC may have different EC protocol version. If EC transitions between RO and RW, but AP does not reboot (this is true for fingerprint microcontroller /
cros_fp, but not true for main ec /cros_ec), the AP still uses the protocol version queried before transition, which can cause problems. In the case of fingerprint microcontroller, this causes AP to send the wrong version ofEC_CMD_GET_NEXT_EVENTto RO in the interrupt handler, which in turn prevents RO to clear the interrupt line to AP, in an infinite loop.Once an
EC_HOST_EVENT_INTERFACE_READYis received, we know that there might have been a transition between RO and RW, so re-query the protocol.Signed-off-by Yicheng Li <[email protected]>--- drivers/platform/chrome/cros_ec.c | 24 +++++++++++++++++++++ include/linux/platform_data/cros_ec_proto.h | 3 +++ 2 files changed, 27 insertions(+)drivers/platform/chrome/cros_ec.c +0
-0@@ -104,6 +104,23 @@ static int cros_ec_sleep_event(struct cros_ec_device *ec_dev, u8 sleep_event)return ret; }
drivers/platform/chrome/cros_ec.c static int cros_ec_sleep_event(struct cros_ec_device *ec_dev, u8 sleep_event) · line 116
Quoted 10 lines
drivers/platform/chrome/cros_ec.c +10
-0+static int cros_ec_ready_event (struct notifier_block *nb, +unsigned long queued_during_suspend,void *_notify) +{ + struct cros_ec_device *ec_dev = container_of(nb, struct cros_ec_device, + notifier_ready); +u32 host_event =cros_ec_get_host_event (ec_dev); + +if (host_event &EC_HOST_EVENT_MASK (EC_HOST_EVENT_INTERFACE_READY )) { +mutex_lock (&ec_dev->lock); +cros_ec_query_all (ec_dev);
I am wondering if instead of calling cros_ec_query_all we can just set the proto version to unknown:
ec_dev->proto_version == EC_PROTO_VERSION_UNKNOWN
and let the cros_ec_cmd_xfer function do its magic.
Should that work?
Thanks,
Enric
Quoted 46 lines
drivers/platform/chrome/cros_ec.c +14
-0+mutex_unlock (&ec_dev->lock); +return NOTIFY_OK ; + } + +return NOTIFY_DONE ; +} +/** * cros_ec_register() - Register a new ChromeOS EC, using the provided info. * @ec_dev: Device to register. @@ -201,6 +218,13 @@ int cros_ec_register(struct cros_ec_device *ec_dev)dev_dbg (ec_dev->dev,"Error %d clearing sleep event to ec" , err); +/* Register the notifier for EC_HOST_EVENT_INTERFACE_READY event. */ + ec_dev->notifier_ready.notifier_call = cros_ec_ready_event; + err =blocking_notifier_chain_register (&ec_dev->event_notifier, + &ec_dev->notifier_ready); +if (err) +return err; +dev_info (dev,"Chrome EC device registered\n" );return 0 ;include/linux/platform_data/cros_ec_proto.h +3
-0@@ -121,6 +121,8 @@ struct cros_ec_command {* @event_data: Raw payload transferred with the MKBP event. * @event_size: Size in bytes of the event data. * @host_event_wake_mask: Mask of host events that cause wake from suspend. +* @notifier_ready: The notifier_block to let the kernel re-query EC +* communication protocol when the EC sends EC_HOST_EVENT_INTERFACE_READY. * @ec: The platform_device used by the mfd driver to interface with the * main EC. * @pd: The platform_device used by the mfd driver to interface with the @@ -161,6 +163,7 @@ struct cros_ec_device {int event_size;u32 host_event_wake_mask;u32 last_resume_result; +struct notifier_block notifier_ready;/* The platform devices used by the mfd driver */ struct platform_device *ec;
Quoted 46 lines · Enric Balletbo i Serra
Hi Yicheng,
I looked at this patch deeply and I have a question.
Quoted 26 lines · Yicheng Li
RO and RW of EC may have different EC protocol version. If EC transitions between RO and RW, but AP does not reboot (this is true for fingerprint microcontroller /
cros_fp, but not true for main ec /cros_ec), the AP still uses the protocol version queried before transition, which can cause problems. In the case of fingerprint microcontroller, this causes AP to send the wrong version ofEC_CMD_GET_NEXT_EVENTto RO in the interrupt handler, which in turn prevents RO to clear the interrupt line to AP, in an infinite loop.Once an
EC_HOST_EVENT_INTERFACE_READYis received, we know that there might have been a transition between RO and RW, so re-query the protocol.Signed-off-by Yicheng Li <[email protected]>--- drivers/platform/chrome/cros_ec.c | 24 +++++++++++++++++++++ include/linux/platform_data/cros_ec_proto.h | 3 +++ 2 files changed, 27 insertions(+)drivers/platform/chrome/cros_ec.c +0
-0@@ -104,6 +104,23 @@ static int cros_ec_sleep_event(struct cros_ec_device *ec_dev, u8 sleep_event)return ret; }drivers/platform/chrome/cros_ec.c static int cros_ec_sleep_event(struct cros_ec_device *ec_dev, u8 sleep_event) · line 116
Quoted 10 lines
drivers/platform/chrome/cros_ec.c +10
-0+static int cros_ec_ready_event (struct notifier_block *nb, +unsigned long queued_during_suspend,void *_notify) +{ + struct cros_ec_device *ec_dev = container_of(nb, struct cros_ec_device, + notifier_ready); +u32 host_event =cros_ec_get_host_event (ec_dev); + +if (host_event &EC_HOST_EVENT_MASK (EC_HOST_EVENT_INTERFACE_READY )) { +mutex_lock (&ec_dev->lock); +cros_ec_query_all (ec_dev);I am wondering if instead of calling
cros_ec_query_allwe can just set the proto version to unknown:
Quoted 3 lines
ec_dev->proto_version == EC_PROTO_VERSION_UNKNOWNand let the
cros_ec_cmd_xferfunction do its magic.
This has actually been used in cros_ec_query_all itself, when the EC is not responding: when cros_ec_cmd_xfer is called, cros_ec_query_all() is called again. This is used when cros_ec_query_all() is called cros_ec_register(), but this is not working properly anymore, because the irq and device driver will not be registered anymore. See in cros_ec_register when cros_ec_query_all is called and set _UNKNOWN, ret is not 0 and cros_ec_register() will bail. I will work on it later. (crbug.com/1030373 for reference).
For our case at hand, we can not wait for a command coming from user space to unlock us. Internal commands could use send_command directly, if a new interrupt comes up for instance). Let's put all the check code from cros_ec_cmd_xfer() in send_command() and indeed reset the proto_version.
Gwendal.
Quoted 52 lines
Should that work?
Thanks,
EnricQuoted 46 lines
drivers/platform/chrome/cros_ec.c +14
-0+mutex_unlock (&ec_dev->lock); +return NOTIFY_OK ; + } + +return NOTIFY_DONE ; +} +/** * cros_ec_register() - Register a new ChromeOS EC, using the provided info. * @ec_dev: Device to register. @@ -201,6 +218,13 @@ int cros_ec_register(struct cros_ec_device *ec_dev)dev_dbg (ec_dev->dev,"Error %d clearing sleep event to ec" , err); +/* Register the notifier for EC_HOST_EVENT_INTERFACE_READY event. */ + ec_dev->notifier_ready.notifier_call = cros_ec_ready_event; + err =blocking_notifier_chain_register (&ec_dev->event_notifier, + &ec_dev->notifier_ready); +if (err) +return err; +dev_info (dev,"Chrome EC device registered\n" );return 0 ;include/linux/platform_data/cros_ec_proto.h +3
-0@@ -121,6 +121,8 @@ struct cros_ec_command {* @event_data: Raw payload transferred with the MKBP event. * @event_size: Size in bytes of the event data. * @host_event_wake_mask: Mask of host events that cause wake from suspend. +* @notifier_ready: The notifier_block to let the kernel re-query EC +* communication protocol when the EC sends EC_HOST_EVENT_INTERFACE_READY. * @ec: The platform_device used by the mfd driver to interface with the * main EC. * @pd: The platform_device used by the mfd driver to interface with the @@ -161,6 +163,7 @@ struct cros_ec_device {int event_size;u32 host_event_wake_mask;u32 last_resume_result; +struct notifier_block notifier_ready;/* The platform devices used by the mfd driver */ struct platform_device *ec;
Quoted 9 lines · Yicheng Li
RO and RW of EC may have different EC protocol version. If EC transitions between RO and RW, but AP does not reboot (this is true for fingerprint microcontroller /
cros_fp, but not true for main ec /cros_ec), the AP still uses the protocol version queried before transition, which can cause problems. In the case of fingerprint microcontroller, this causes AP to send the wrong version ofEC_CMD_GET_NEXT_EVENTto RO in the interrupt handler, which in turn prevents RO to clear the interrupt line to AP, in an infinite loop.
Quoted 8 lines
Once an
EC_HOST_EVENT_INTERFACE_READYis received, we know that there might have been a transition between RO and RW, so re-query the protocol.Signed-off-by Yicheng Li <[email protected]>--- drivers/platform/chrome/cros_ec.c | 24 +++++++++++++++++++++ include/linux/platform_data/cros_ec_proto.h | 3 +++ 2 files changed, 27 insertions(+)
This is not an MFD patch. Please drop it from the subject line.
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog