mei: update mei-pxp's component interface with timeouts
authorAlan Previn <alan.previn.teres.alexis@intel.com>
Wed, 11 Oct 2023 11:01:57 +0000 (14:01 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Oct 2023 08:01:33 +0000 (10:01 +0200)
In debugging platform or firmware related MEI-PXP connection
issues, having a timeout when clients (such as i915) calling
into mei-pxp's send/receive functions have proven useful as opposed to
blocking forever until the kernel triggers a watchdog panic (when
platform issues are experienced).

Update the mei-pxp component interface send and receive functions
to take in timeouts.

Signed-off-by: Alan Previn <alan.previn.teres.alexis@intel.com>
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Link: https://lore.kernel.org/r/20231011110157.247552-5-tomas.winkler@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/gpu/drm/i915/pxp/intel_pxp_tee.c
drivers/misc/mei/pxp/mei_pxp.c
include/drm/i915_pxp_tee_interface.h

index 80bb0018986525f16d410e565ff4db98d470a9f9..dfc2878426fc2226ccb552700a7212dd7fe6621c 100644 (file)
@@ -20,6 +20,8 @@
 #include "intel_pxp_tee.h"
 #include "intel_pxp_types.h"
 
+#define PXP_TRANSPORT_TIMEOUT_MS 5000 /* 5 sec */
+
 static bool
 is_fw_err_platform_config(u32 type)
 {
@@ -71,13 +73,15 @@ static int intel_pxp_tee_io_message(struct intel_pxp *pxp,
                goto unlock;
        }
 
-       ret = pxp_component->ops->send(pxp_component->tee_dev, msg_in, msg_in_size);
+       ret = pxp_component->ops->send(pxp_component->tee_dev, msg_in, msg_in_size,
+                                      PXP_TRANSPORT_TIMEOUT_MS);
        if (ret) {
                drm_err(&i915->drm, "Failed to send PXP TEE message\n");
                goto unlock;
        }
 
-       ret = pxp_component->ops->recv(pxp_component->tee_dev, msg_out, msg_out_max_size);
+       ret = pxp_component->ops->recv(pxp_component->tee_dev, msg_out, msg_out_max_size,
+                                      PXP_TRANSPORT_TIMEOUT_MS);
        if (ret < 0) {
                drm_err(&i915->drm, "Failed to receive PXP TEE message\n");
                goto unlock;
index 9875d16445bb03efcfb31cd94583fd8c49e588de..f77d78fa50549e69f0a0873b87bbc4711899b356 100644 (file)
@@ -46,10 +46,20 @@ static inline int mei_pxp_reenable(const struct device *dev, struct mei_cl_devic
  * @dev: device corresponding to the mei_cl_device
  * @message: a message buffer to send
  * @size: size of the message
- * Return: 0 on Success, <0 on Failure
+ * @timeout_ms: timeout in milliseconds, zero means wait indefinitely.
+ *
+ * Returns: 0 on Success, <0 on Failure with the following defined failures.
+ *         -ENODEV: Client was not connected.
+ *                  Caller may attempt to try again immediately.
+ *         -ENOMEM: Internal memory allocation failure experienced.
+ *                  Caller may sleep to allow kernel reclaim before retrying.
+ *         -EINTR : Calling thread received a signal. Caller may choose
+ *                  to abandon with the same thread id.
+ *         -ETIME : Request is timed out.
+ *                  Caller may attempt to try again immediately.
  */
 static int
-mei_pxp_send_message(struct device *dev, const void *message, size_t size)
+mei_pxp_send_message(struct device *dev, const void *message, size_t size, unsigned long timeout_ms)
 {
        struct mei_cl_device *cldev;
        ssize_t byte;
@@ -60,7 +70,7 @@ mei_pxp_send_message(struct device *dev, const void *message, size_t size)
 
        cldev = to_mei_cl_device(dev);
 
-       byte = mei_cldev_send(cldev, message, size);
+       byte = mei_cldev_send_timeout(cldev, message, size, timeout_ms);
        if (byte < 0) {
                dev_dbg(dev, "mei_cldev_send failed. %zd\n", byte);
                switch (byte) {
@@ -84,10 +94,21 @@ mei_pxp_send_message(struct device *dev, const void *message, size_t size)
  * @dev: device corresponding to the mei_cl_device
  * @buffer: a message buffer to contain the received message
  * @size: size of the buffer
- * Return: bytes sent on Success, <0 on Failure
+ * @timeout_ms: timeout in milliseconds, zero means wait indefinitely.
+ *
+ * Returns: number of bytes send on Success, <0 on Failure with the following defined failures.
+ *         -ENODEV: Client was not connected.
+ *                  Caller may attempt to try again from send immediately.
+ *         -ENOMEM: Internal memory allocation failure experienced.
+ *                  Caller may sleep to allow kernel reclaim before retrying.
+ *         -EINTR : Calling thread received a signal. Caller will need to repeat calling
+ *                  (with a different owning thread) to retrieve existing unclaimed response
+ *                  (and may discard it).
+ *         -ETIME : Request is timed out.
+ *                  Caller may attempt to try again from send immediately.
  */
 static int
-mei_pxp_receive_message(struct device *dev, void *buffer, size_t size)
+mei_pxp_receive_message(struct device *dev, void *buffer, size_t size, unsigned long timeout_ms)
 {
        struct mei_cl_device *cldev;
        ssize_t byte;
@@ -100,7 +121,7 @@ mei_pxp_receive_message(struct device *dev, void *buffer, size_t size)
        cldev = to_mei_cl_device(dev);
 
 retry:
-       byte = mei_cldev_recv(cldev, buffer, size);
+       byte = mei_cldev_recv_timeout(cldev, buffer, size, timeout_ms);
        if (byte < 0) {
                dev_dbg(dev, "mei_cldev_recv failed. %zd\n", byte);
                switch (byte) {
index a702b6ec17f7ca95eda7d225ba1936ae1e15a298..7d96985f2d05327151b0dfc1d633be9dd2d58694 100644 (file)
@@ -22,8 +22,10 @@ struct i915_pxp_component_ops {
         */
        struct module *owner;
 
-       int (*send)(struct device *dev, const void *message, size_t size);
-       int (*recv)(struct device *dev, void *buffer, size_t size);
+       int (*send)(struct device *dev, const void *message, size_t size,
+                   unsigned long timeout_ms);
+       int (*recv)(struct device *dev, void *buffer, size_t size,
+                   unsigned long timeout_ms);
        ssize_t (*gsc_command)(struct device *dev, u8 client_id, u32 fence_id,
                               struct scatterlist *sg_in, size_t total_in_len,
                               struct scatterlist *sg_out);