habanalabs: change wait for interrupt timeout to 64 bit
authorDani Liberman <dliberman@habana.ai>
Thu, 14 Oct 2021 19:38:41 +0000 (22:38 +0300)
committerOded Gabbay <ogabbay@kernel.org>
Sun, 26 Dec 2021 06:59:05 +0000 (08:59 +0200)
In order to increase maximum wait-for-interrupt timeout, change it
to 64 bit variable. This wait is used only by newer ASICs, so no
problem in changing this interface at this time.

Signed-off-by: Dani Liberman <dliberman@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
drivers/misc/habanalabs/common/command_submission.c
include/uapi/misc/habanalabs.h

index 9ebcd98..54a5425 100644 (file)
@@ -2765,8 +2765,23 @@ static int hl_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data)
        return 0;
 }
 
+static inline unsigned long hl_usecs64_to_jiffies(const u64 usecs)
+{
+       if (usecs <= U32_MAX)
+               return usecs_to_jiffies(usecs);
+
+       /*
+        * If the value in nanoseconds is larger than 64 bit, use the largest
+        * 64 bit value.
+        */
+       if (usecs >= ((u64)(U64_MAX / NSEC_PER_USEC)))
+               return nsecs_to_jiffies(U64_MAX);
+
+       return nsecs_to_jiffies(usecs * NSEC_PER_USEC);
+}
+
 static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx,
-                               u32 timeout_us, u64 user_address,
+                               u64 timeout_us, u64 user_address,
                                u64 target_value, u16 interrupt_offset,
                                u32 *status,
                                u64 *timestamp)
@@ -2778,10 +2793,7 @@ static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx,
        long completion_rc;
        int rc = 0;
 
-       if (timeout_us == U32_MAX)
-               timeout = timeout_us;
-       else
-               timeout = usecs_to_jiffies(timeout_us);
+       timeout = hl_usecs64_to_jiffies(timeout_us);
 
        hl_ctx_get(hdev, ctx);
 
index 00b3095..c5760ac 100644 (file)
@@ -911,14 +911,18 @@ struct hl_wait_cs_in {
         */
        __u32 flags;
 
-       /* Multi CS API info- valid entries in multi-CS array */
-       __u8 seq_arr_len;
-       __u8 pad[3];
+       union {
+               struct {
+                       /* Multi CS API info- valid entries in multi-CS array */
+                       __u8 seq_arr_len;
+                       __u8 pad[7];
+               };
 
-       /* Absolute timeout to wait for an interrupt in microseconds.
-        * Relevant only when HL_WAIT_CS_FLAGS_INTERRUPT is set
-        */
-       __u32 interrupt_timeout_us;
+               /* Absolute timeout to wait for an interrupt in microseconds.
+                * Relevant only when HL_WAIT_CS_FLAGS_INTERRUPT is set
+                */
+               __u64 interrupt_timeout_us;
+       };
 };
 
 #define HL_WAIT_CS_STATUS_COMPLETED    0