From patchwork Tue Apr 18 09:39:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 13215326 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D7D3EC77B75 for ; Tue, 18 Apr 2023 09:39:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2C01810E12A; Tue, 18 Apr 2023 09:39:25 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id CBF4B10E12A for ; Tue, 18 Apr 2023 09:39:22 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E3C71623D5; Tue, 18 Apr 2023 09:39:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E2B9C433D2; Tue, 18 Apr 2023 09:39:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681810761; bh=xaI3K7MCLkZy3+e+eR2kUIl4q3HzkDongRje4wLA4cc=; h=From:To:Cc:Subject:Date:From; b=luvGJhGM+my6xXjjXwd0KmpLLyjxhK9IulUz5xhuSF4mCjdM45f28B0IiUmYyKFEG UR88LSRSptDFPwo3ursW3gf2Fz3qUYmuTMfPKjtg9+nfcuwfeAz16/COsUekRWz6gm j5tJdIjkvGIUK4u66lg3H+oorRAddnJIbA7NBJdzP3kloG31UtkHFT2YRKYnhjsUHx 4H6OZlWZrbPQ2tmfauRlQzXHapxNnK/BCmYpxNBs865IwSIt7A4LSm5/UCoF3TeYmt KUx3qN9T8LLD+JztfK3HzRM4B+gsVtqXYcrb9OJYXNVmqmUc70WNHFsbSHuIirjOK5 z0eeqHOXzeEiQ== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 01/10] accel/habanalabs: add helper to extract the FW major/minor Date: Tue, 18 Apr 2023 12:39:07 +0300 Message-Id: <20230418093916.2979728-1-ogabbay@kernel.org> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dafna Hirschfeld Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Dafna Hirschfeld the helper is extract_u32_until_given_char and can later be used to also get the major/minor of the sw version. Signed-off-by: Dafna Hirschfeld Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/common/firmware_if.c | 69 ++++++++++++------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/drivers/accel/habanalabs/common/firmware_if.c b/drivers/accel/habanalabs/common/firmware_if.c index 59f61ec66445..1400a4430045 100644 --- a/drivers/accel/habanalabs/common/firmware_if.c +++ b/drivers/accel/habanalabs/common/firmware_if.c @@ -71,38 +71,59 @@ static char *extract_fw_ver_from_str(const char *fw_str) return NULL; } -static int hl_get_preboot_major_minor(struct hl_device *hdev, char *preboot_ver) +/** + * extract_u32_until_given_char() - given a string of the format "*", extract the u32. + * @str: the given string + * @ver_num: the pointer to the extracted u32 to be returned to the caller. + * @given_char: the given char at the end of the u32 in the string + * + * Return: Upon success, return a pointer to the given_char in the string. Upon failure, return NULL + */ +static char *extract_u32_until_given_char(char *str, u32 *ver_num, char given_char) { - char major[8], minor[8], *first_dot, *second_dot; - int rc; + char num_str[8] = {}, *ch; - first_dot = strnstr(preboot_ver, ".", 10); - if (first_dot) { - strscpy(major, preboot_ver, first_dot - preboot_ver + 1); - rc = kstrtou32(major, 10, &hdev->fw_major_version); - } else { - rc = -EINVAL; - } + ch = strchrnul(str, given_char); + if (*ch == '\0' || ch == str || ch - str >= sizeof(num_str)) + return NULL; - if (rc) { - dev_err(hdev->dev, "Error %d parsing preboot major version\n", rc); - return rc; + memcpy(num_str, str, ch - str); + if (kstrtou32(num_str, 10, ver_num)) + return NULL; + return ch; +} + +/** + * hl_get_preboot_major_minor() - extract the FW's version major, minor from the version string. + * @hdev: pointer to the hl_device + * @preboot_ver: the FW's version string + * + * preboot_ver is expected to be the format of ..*, e.g: 42.0.1-sec-3 + * The extracted version is set in the hdev fields: fw_inner_{major/minor}_ver. + * + * Return: 0 on success, negative error code for failure. + */ +static int hl_get_preboot_major_minor(struct hl_device *hdev, char *preboot_ver) +{ + preboot_ver = extract_u32_until_given_char(preboot_ver, &hdev->fw_major_version, '.'); + if (!preboot_ver) { + dev_err(hdev->dev, "Error parsing preboot major version\n"); + goto err_zero_ver; } - /* skip the first dot */ - first_dot++; + preboot_ver++; - second_dot = strnstr(first_dot, ".", 10); - if (second_dot) { - strscpy(minor, first_dot, second_dot - first_dot + 1); - rc = kstrtou32(minor, 10, &hdev->fw_minor_version); - } else { - rc = -EINVAL; + preboot_ver = extract_u32_until_given_char(preboot_ver, &hdev->fw_minor_version, '.'); + if (!preboot_ver) { + dev_err(hdev->dev, "Error parsing preboot minor version\n"); + goto err_zero_ver; } + return 0; - if (rc) - dev_err(hdev->dev, "Error %d parsing preboot minor version\n", rc); - return rc; +err_zero_ver: + hdev->fw_major_version = 0; + hdev->fw_minor_version = 0; + return -EINVAL; } static int hl_request_fw(struct hl_device *hdev, From patchwork Tue Apr 18 09:39:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 13215330 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2C9E8C77B75 for ; Tue, 18 Apr 2023 09:39:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5861710E725; Tue, 18 Apr 2023 09:39:40 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id C6D3E10E12A for ; Tue, 18 Apr 2023 09:39:23 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 56C03625C0; Tue, 18 Apr 2023 09:39:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6AAEC4339B; Tue, 18 Apr 2023 09:39:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681810762; bh=BNb0jfAL1kXRfJrhkG9aaKJBzAVfZ2wABHHYL7NV1RU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F9AzIMTFdVcm7s4YS9nKqDpuXptzv/eBrB7BaTChQlpNe3d+i0HwUg2aqOfWd3LXQ 9rGe4h9q87UdksFcaOAGCbYjIhEit/LVqN9eakpX3HjOKlabM8Fn9Ke8f9IDedirlL eYRbNZcLDLjxp1aHVe5+zf+aqzNWcwEu11PpqwAPqYyA6K0XgHggWqdxM14MN/nybL GNyspjqC1swhxSDrYzqN92+j5XJc4qSBou9AcXST1jiQwa8sFPqC3zGqCAZ0EBwdTg rsAgPSxNfpcRXtMEmlQ0vFauk5TvF77pPNxAGK5QzghcECdA+mXG3FTB1e7e8nMAfM b8fxuZ4D+4jtA== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 02/10] accel/habanalabs: rename fw_{major/minor}_version to fw_inner_{major/minor}_ver Date: Tue, 18 Apr 2023 12:39:08 +0300 Message-Id: <20230418093916.2979728-2-ogabbay@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230418093916.2979728-1-ogabbay@kernel.org> References: <20230418093916.2979728-1-ogabbay@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dafna Hirschfeld Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Dafna Hirschfeld We later want to add fields for Firmware SW version. The current extracted FW version is the inner FW versioning so the new name is better and also better differentiate from the FW's SW version. Signed-off-by: Dafna Hirschfeld Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/common/firmware_if.c | 8 ++++---- drivers/accel/habanalabs/common/habanalabs.h | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/accel/habanalabs/common/firmware_if.c b/drivers/accel/habanalabs/common/firmware_if.c index 1400a4430045..6150ab6ba810 100644 --- a/drivers/accel/habanalabs/common/firmware_if.c +++ b/drivers/accel/habanalabs/common/firmware_if.c @@ -105,7 +105,7 @@ static char *extract_u32_until_given_char(char *str, u32 *ver_num, char given_ch */ static int hl_get_preboot_major_minor(struct hl_device *hdev, char *preboot_ver) { - preboot_ver = extract_u32_until_given_char(preboot_ver, &hdev->fw_major_version, '.'); + preboot_ver = extract_u32_until_given_char(preboot_ver, &hdev->fw_inner_major_ver, '.'); if (!preboot_ver) { dev_err(hdev->dev, "Error parsing preboot major version\n"); goto err_zero_ver; @@ -113,7 +113,7 @@ static int hl_get_preboot_major_minor(struct hl_device *hdev, char *preboot_ver) preboot_ver++; - preboot_ver = extract_u32_until_given_char(preboot_ver, &hdev->fw_minor_version, '.'); + preboot_ver = extract_u32_until_given_char(preboot_ver, &hdev->fw_inner_minor_ver, '.'); if (!preboot_ver) { dev_err(hdev->dev, "Error parsing preboot minor version\n"); goto err_zero_ver; @@ -121,8 +121,8 @@ static int hl_get_preboot_major_minor(struct hl_device *hdev, char *preboot_ver) return 0; err_zero_ver: - hdev->fw_major_version = 0; - hdev->fw_minor_version = 0; + hdev->fw_inner_major_ver = 0; + hdev->fw_inner_minor_ver = 0; return -EINVAL; } diff --git a/drivers/accel/habanalabs/common/habanalabs.h b/drivers/accel/habanalabs/common/habanalabs.h index eaae69a9f817..57661cb51621 100644 --- a/drivers/accel/habanalabs/common/habanalabs.h +++ b/drivers/accel/habanalabs/common/habanalabs.h @@ -3225,8 +3225,8 @@ struct hl_reset_info { * @captured_err_info: holds information about errors. * @reset_info: holds current device reset information. * @stream_master_qid_arr: pointer to array with QIDs of master streams. - * @fw_major_version: major version of current loaded preboot. - * @fw_minor_version: minor version of current loaded preboot. + * @fw_inner_major_ver: the major of current loaded preboot inner version. + * @fw_inner_minor_ver: the minor of current loaded preboot inner version. * @dram_used_mem: current DRAM memory consumption. * @memory_scrub_val: the value to which the dram will be scrubbed to using cb scrub_device_dram * @timeout_jiffies: device CS timeout value. @@ -3412,8 +3412,8 @@ struct hl_device { struct hl_reset_info reset_info; u32 *stream_master_qid_arr; - u32 fw_major_version; - u32 fw_minor_version; + u32 fw_inner_major_ver; + u32 fw_inner_minor_ver; atomic64_t dram_used_mem; u64 memory_scrub_val; u64 timeout_jiffies; @@ -3549,7 +3549,7 @@ struct hl_ioctl_desc { static inline bool hl_is_fw_ver_below_1_9(struct hl_device *hdev) { - return (hdev->fw_major_version < 42); + return (hdev->fw_inner_major_ver < 42); } /* From patchwork Tue Apr 18 09:39:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 13215331 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C599C77B76 for ; Tue, 18 Apr 2023 09:39:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B92CD10E726; Tue, 18 Apr 2023 09:39:40 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5402610E716 for ; Tue, 18 Apr 2023 09:39:25 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B847C623D5; Tue, 18 Apr 2023 09:39:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B4FCC433EF; Tue, 18 Apr 2023 09:39:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681810764; bh=iUFZfYhcdmFcqRCRra3sJ5S/JKaZ3csvf3NYNsgjISg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lMTPQvqke0kL1MOgKEp2189+nX83e9A3z7QW4bQ3kBX489mcWfyJ2U39uYr7fEjoF UoznGTEHOu4yf8+jwMxtNKywOUJQcQcgR26qB+mcbQxTLB3ukvAzscNU2nmb7lXgyV KJ+iItV6dLdMInv0KIVwatbOua0z2vrG8lmRGiuppsSnCOHfvYceufjQ1yAnLSf6Ac GdjF1tA1n9YUrqUCZ+1efsQbOty2XkNmgLRa/bdYWAVO/2ZqimDMsj8mYyJSb0k9XG OjHcVJuEyyCXEIz+ufmw3O5W8My8tUJdyN4CdIb3tZv7B9XKDtMgeIAw5jpIj2uXXl 5PoQT6ygfz75Q== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 03/10] accel/habanalabs: extract and save the FW's SW major/minor/sub-minor Date: Tue, 18 Apr 2023 12:39:09 +0300 Message-Id: <20230418093916.2979728-3-ogabbay@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230418093916.2979728-1-ogabbay@kernel.org> References: <20230418093916.2979728-1-ogabbay@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dafna Hirschfeld Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Dafna Hirschfeld It is not always possible to know the FW's SW version from the inner FW version. Therefore we should extract the general SW version in addition to the FW version and use it in functions like 'hl_is_fw_ver_below_1_9' etc. Signed-off-by: Dafna Hirschfeld Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/common/firmware_if.c | 78 +++++++++++++++++-- drivers/accel/habanalabs/common/habanalabs.h | 6 ++ 2 files changed, 78 insertions(+), 6 deletions(-) diff --git a/drivers/accel/habanalabs/common/firmware_if.c b/drivers/accel/habanalabs/common/firmware_if.c index 6150ab6ba810..62052cfe694f 100644 --- a/drivers/accel/habanalabs/common/firmware_if.c +++ b/drivers/accel/habanalabs/common/firmware_if.c @@ -93,6 +93,71 @@ static char *extract_u32_until_given_char(char *str, u32 *ver_num, char given_ch return ch; } +/** + * hl_get_sw_major_minor_subminor() - extract the FW's SW version major, minor, sub-minor + * from the version string + * @hdev: pointer to the hl_device + * @fw_str: the FW's version string + * + * The extracted version is set in the hdev fields: fw_sw_{major/minor/sub_minor}_ver. + * + * fw_str is expected to have one of two possible formats, examples: + * 1) 'Preboot version hl-gaudi2-1.9.0-fw-42.0.1-sec-3' + * 2) 'Preboot version hl-gaudi2-1.9.0-rc-fw-42.0.1-sec-3' + * In those examples, the SW major,minor,subminor are correspondingly: 1,9,0. + * + * Return: 0 for success or a negative error code for failure. + */ +static int hl_get_sw_major_minor_subminor(struct hl_device *hdev, const char *fw_str) +{ + char *end, *start; + + end = strnstr(fw_str, "-rc-", VERSION_MAX_LEN); + if (end == fw_str) + return -EINVAL; + + if (!end) + end = strnstr(fw_str, "-fw-", VERSION_MAX_LEN); + + if (end == fw_str) + return -EINVAL; + + if (!end) + return -EINVAL; + + for (start = end - 1; start != fw_str; start--) { + if (*start == '-') + break; + } + + if (start == fw_str) + return -EINVAL; + + /* start/end point each to the starting and ending hyphen of the sw version e.g. -1.9.0- */ + start++; + start = extract_u32_until_given_char(start, &hdev->fw_sw_major_ver, '.'); + if (!start) + goto err_zero_ver; + + start++; + start = extract_u32_until_given_char(start, &hdev->fw_sw_minor_ver, '.'); + if (!start) + goto err_zero_ver; + + start++; + start = extract_u32_until_given_char(start, &hdev->fw_sw_sub_minor_ver, '-'); + if (!start) + goto err_zero_ver; + + return 0; + +err_zero_ver: + hdev->fw_sw_major_ver = 0; + hdev->fw_sw_minor_ver = 0; + hdev->fw_sw_sub_minor_ver = 0; + return -EINVAL; +} + /** * hl_get_preboot_major_minor() - extract the FW's version major, minor from the version string. * @hdev: pointer to the hl_device @@ -2172,6 +2237,7 @@ static int hl_fw_dynamic_read_device_fw_version(struct hl_device *hdev, struct asic_fixed_properties *prop = &hdev->asic_prop; char *preboot_ver, *boot_ver; char btl_ver[32]; + int rc; switch (fwc) { case FW_COMP_BOOT_FIT: @@ -2185,20 +2251,20 @@ static int hl_fw_dynamic_read_device_fw_version(struct hl_device *hdev, break; case FW_COMP_PREBOOT: strscpy(prop->preboot_ver, fw_version, VERSION_MAX_LEN); - preboot_ver = strnstr(prop->preboot_ver, "Preboot", - VERSION_MAX_LEN); + preboot_ver = strnstr(prop->preboot_ver, "Preboot", VERSION_MAX_LEN); + dev_info(hdev->dev, "preboot full version: '%s'\n", preboot_ver); + if (preboot_ver && preboot_ver != prop->preboot_ver) { strscpy(btl_ver, prop->preboot_ver, min((int) (preboot_ver - prop->preboot_ver), 31)); dev_info(hdev->dev, "%s\n", btl_ver); } + rc = hl_get_sw_major_minor_subminor(hdev, preboot_ver); + if (rc) + return rc; preboot_ver = extract_fw_ver_from_str(prop->preboot_ver); if (preboot_ver) { - int rc; - - dev_info(hdev->dev, "preboot version %s\n", preboot_ver); - rc = hl_get_preboot_major_minor(hdev, preboot_ver); kfree(preboot_ver); if (rc) diff --git a/drivers/accel/habanalabs/common/habanalabs.h b/drivers/accel/habanalabs/common/habanalabs.h index 57661cb51621..d6f454b1cde4 100644 --- a/drivers/accel/habanalabs/common/habanalabs.h +++ b/drivers/accel/habanalabs/common/habanalabs.h @@ -3227,6 +3227,9 @@ struct hl_reset_info { * @stream_master_qid_arr: pointer to array with QIDs of master streams. * @fw_inner_major_ver: the major of current loaded preboot inner version. * @fw_inner_minor_ver: the minor of current loaded preboot inner version. + * @fw_sw_major_ver: the major of current loaded preboot SW version. + * @fw_sw_minor_ver: the minor of current loaded preboot SW version. + * @fw_sw_sub_minor_ver: the sub-minor of current loaded preboot SW version. * @dram_used_mem: current DRAM memory consumption. * @memory_scrub_val: the value to which the dram will be scrubbed to using cb scrub_device_dram * @timeout_jiffies: device CS timeout value. @@ -3414,6 +3417,9 @@ struct hl_device { u32 *stream_master_qid_arr; u32 fw_inner_major_ver; u32 fw_inner_minor_ver; + u32 fw_sw_major_ver; + u32 fw_sw_minor_ver; + u32 fw_sw_sub_minor_ver; atomic64_t dram_used_mem; u64 memory_scrub_val; u64 timeout_jiffies; From patchwork Tue Apr 18 09:39:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 13215327 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 61171C77B75 for ; Tue, 18 Apr 2023 09:39:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7F6A610E716; Tue, 18 Apr 2023 09:39:28 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id A270510E716 for ; Tue, 18 Apr 2023 09:39:26 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 33472625F0; Tue, 18 Apr 2023 09:39:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3CE9C4339B; Tue, 18 Apr 2023 09:39:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681810765; bh=hwfh9cx73kb1mUh5/2zCXg2tIqhGQnxf5/EQ/bzd8sc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VG/Uyrdu9qcnK2WqYt2+zs4bVi00qDAunXTcokG1WGbZQZ5d5tuuDrWsOdJ/7Br/N E2Bjo9zFRUh8fnQzoUZpnCTGMdkAT5f6hue+D8HbuO0PLnshaKejZs4RpO9TBsgTe4 /Z/8RvkPm+3Ymz5G18OgS53n8nI5Z4I2DmbfrLanKerRtEeuK5oCnuAO5Ap/m232IB hyDhvEQ81y8ScvgIO9v1ArQpXZBrYp0xi8xX4mpy067M/h/Ag7tIwBcMXQkGeCXhaq zvcmlp1P1bZhMVv31rKmQTWQwss1Tf46sCgErvvwB6vdl7ueiNmLc8VUSrQ+IhnNkx zNKyAyBWGtR4w== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 04/10] accel/habanalabs: check fw version using sw version Date: Tue, 18 Apr 2023 12:39:10 +0300 Message-Id: <20230418093916.2979728-4-ogabbay@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230418093916.2979728-1-ogabbay@kernel.org> References: <20230418093916.2979728-1-ogabbay@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dafna Hirschfeld Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Dafna Hirschfeld The fw inner version is less trustable, instead use the fw general sw release version. Signed-off-by: Dafna Hirschfeld Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/common/habanalabs.h | 10 ++++++++-- drivers/accel/habanalabs/gaudi2/gaudi2.c | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/accel/habanalabs/common/habanalabs.h b/drivers/accel/habanalabs/common/habanalabs.h index d6f454b1cde4..02620654ccdf 100644 --- a/drivers/accel/habanalabs/common/habanalabs.h +++ b/drivers/accel/habanalabs/common/habanalabs.h @@ -3553,9 +3553,15 @@ struct hl_ioctl_desc { hl_ioctl_t *func; }; -static inline bool hl_is_fw_ver_below_1_9(struct hl_device *hdev) +static inline bool hl_is_fw_sw_ver_below(struct hl_device *hdev, u32 fw_sw_major, u32 fw_sw_minor) { - return (hdev->fw_inner_major_ver < 42); + if (hdev->fw_sw_major_ver < fw_sw_major) + return true; + if (hdev->fw_sw_major_ver > fw_sw_major) + return false; + if (hdev->fw_sw_minor_ver < fw_sw_minor) + return true; + return false; } /* diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2.c b/drivers/accel/habanalabs/gaudi2/gaudi2.c index acc304ebca82..6e3aa89b19c2 100644 --- a/drivers/accel/habanalabs/gaudi2/gaudi2.c +++ b/drivers/accel/habanalabs/gaudi2/gaudi2.c @@ -8043,7 +8043,7 @@ static void gaudi2_ack_module_razwi_event_handler(struct hl_device *hdev, case RAZWI_TPC: hbw_rtr_id = gaudi2_tpc_initiator_hbw_rtr_id[module_idx]; - if (hl_is_fw_ver_below_1_9(hdev) && + if (hl_is_fw_sw_ver_below(hdev, 1, 9) && !hdev->asic_prop.fw_security_enabled && ((module_idx == 0) || (module_idx == 1))) lbw_rtr_id = DCORE0_RTR0; From patchwork Tue Apr 18 09:39:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 13215329 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B2CCDC77B76 for ; Tue, 18 Apr 2023 09:39:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8373010E724; Tue, 18 Apr 2023 09:39:33 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9717810E723 for ; Tue, 18 Apr 2023 09:39:28 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 277D2625F0; Tue, 18 Apr 2023 09:39:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29045C4339C; Tue, 18 Apr 2023 09:39:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681810767; bh=GbucswmlkFevsYu4Aa/VuRUww7vrdpB9R+VxnfOPSqI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eJMHePn0WZuCMPv2fIR95nLiU69iIZ/l+ZPKhEsWPzv3KMo3Qpok4bzd+nkMND6rI rWdSMFNXDRBMfKu9JBPxmtvW/dhYqGJYWJlXGE2fTt2GyxbwmBwWr0P4nGsTv1X5rK h+qjXL7YO/0W87w/G610uxqUx5pBqxfJAWmhZczrDVvfrhYcsEAqCJwJPlmT8+i971 oyCqdmCSTLF22tm0ujo9rhvk8Qk5VnixKO/P9Zr6AOAIcX5BgHnyGpesmKNHRk3hal XSM176z49yQmx/y16xmKOBcwklRO9KYLUCn/ePYTXAFFRoQnpeh7U1ahUhWwl46l5X 4W/7SQhtmlCgw== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 05/10] accel/habanalabs: do soft-reset using cpucp packet Date: Tue, 18 Apr 2023 12:39:11 +0300 Message-Id: <20230418093916.2979728-5-ogabbay@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230418093916.2979728-1-ogabbay@kernel.org> References: <20230418093916.2979728-1-ogabbay@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dafna Hirschfeld Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Dafna Hirschfeld This is done depending on the FW version. The cpucp method is preferable and saves scratchpads resource. Signed-off-by: Dafna Hirschfeld Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/common/firmware_if.c | 14 ++++++++++ drivers/accel/habanalabs/common/habanalabs.h | 1 + drivers/accel/habanalabs/gaudi2/gaudi2.c | 26 ++++++++++++------- .../habanalabs/include/common/cpucp_if.h | 4 +++ 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/drivers/accel/habanalabs/common/firmware_if.c b/drivers/accel/habanalabs/common/firmware_if.c index 62052cfe694f..e48f024d8649 100644 --- a/drivers/accel/habanalabs/common/firmware_if.c +++ b/drivers/accel/habanalabs/common/firmware_if.c @@ -591,6 +591,20 @@ void hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size, size); } +int hl_fw_send_soft_reset(struct hl_device *hdev) +{ + struct cpucp_packet pkt; + int rc; + + memset(&pkt, 0, sizeof(pkt)); + pkt.ctl = cpu_to_le32(CPUCP_PACKET_SOFT_RESET << CPUCP_PKT_CTL_OPCODE_SHIFT); + rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, NULL); + if (rc) + dev_err(hdev->dev, "failed to send soft-reset msg (err = %d)\n", rc); + + return rc; +} + int hl_fw_send_device_activity(struct hl_device *hdev, bool open) { struct cpucp_packet pkt; diff --git a/drivers/accel/habanalabs/common/habanalabs.h b/drivers/accel/habanalabs/common/habanalabs.h index 02620654ccdf..6b102947cb90 100644 --- a/drivers/accel/habanalabs/common/habanalabs.h +++ b/drivers/accel/habanalabs/common/habanalabs.h @@ -3884,6 +3884,7 @@ int hl_fw_dram_replaced_row_get(struct hl_device *hdev, int hl_fw_dram_pending_row_get(struct hl_device *hdev, u32 *pend_rows_num); int hl_fw_cpucp_engine_core_asid_set(struct hl_device *hdev, u32 asid); int hl_fw_send_device_activity(struct hl_device *hdev, bool open); +int hl_fw_send_soft_reset(struct hl_device *hdev); int hl_pci_bars_map(struct hl_device *hdev, const char * const name[3], bool is_wc[3]); int hl_pci_elbi_read(struct hl_device *hdev, u64 addr, u32 *data); diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2.c b/drivers/accel/habanalabs/gaudi2/gaudi2.c index 6e3aa89b19c2..5c80e7af5b78 100644 --- a/drivers/accel/habanalabs/gaudi2/gaudi2.c +++ b/drivers/accel/habanalabs/gaudi2/gaudi2.c @@ -6148,18 +6148,24 @@ static int gaudi2_execute_soft_reset(struct hl_device *hdev, bool driver_perform u32 poll_timeout_us) { struct cpu_dyn_regs *dyn_regs = &hdev->fw_loader.dynamic_loader.comm_desc.cpu_dyn_regs; + int rc = 0; if (!driver_performs_reset) { - /* set SP to indicate reset request sent to FW */ - if (dyn_regs->cpu_rst_status) - WREG32(le32_to_cpu(dyn_regs->cpu_rst_status), CPU_RST_STATUS_NA); - else - WREG32(mmCPU_RST_STATUS_TO_HOST, CPU_RST_STATUS_NA); - - WREG32(le32_to_cpu(dyn_regs->gic_host_soft_rst_irq), - gaudi2_irq_map_table[GAUDI2_EVENT_CPU_SOFT_RESET].cpu_id); - - return gaudi2_get_soft_rst_done_indication(hdev, poll_timeout_us); + if (hl_is_fw_sw_ver_below(hdev, 1, 10)) { + /* set SP to indicate reset request sent to FW */ + if (dyn_regs->cpu_rst_status) + WREG32(le32_to_cpu(dyn_regs->cpu_rst_status), CPU_RST_STATUS_NA); + else + WREG32(mmCPU_RST_STATUS_TO_HOST, CPU_RST_STATUS_NA); + WREG32(le32_to_cpu(dyn_regs->gic_host_soft_rst_irq), + gaudi2_irq_map_table[GAUDI2_EVENT_CPU_SOFT_RESET].cpu_id); + + /* wait for f/w response */ + rc = gaudi2_get_soft_rst_done_indication(hdev, poll_timeout_us); + } else { + rc = hl_fw_send_soft_reset(hdev); + } + return rc; } /* Block access to engines, QMANs and SM during reset, these diff --git a/drivers/accel/habanalabs/include/common/cpucp_if.h b/drivers/accel/habanalabs/include/common/cpucp_if.h index 8bbe685458c4..f68308cc2524 100644 --- a/drivers/accel/habanalabs/include/common/cpucp_if.h +++ b/drivers/accel/habanalabs/include/common/cpucp_if.h @@ -665,6 +665,9 @@ enum pq_init_status { * * CPUCP_PACKET_REGISTER_INTERRUPTS - * Packet to register interrupts indicating LKD is ready to receive events from FW. + * + * CPUCP_PACKET_SOFT_RESET - + * Packet to perform soft-reset. */ enum cpucp_packet_id { @@ -731,6 +734,7 @@ enum cpucp_packet_id { CPUCP_PACKET_RESERVED11, /* not used */ CPUCP_PACKET_RESERVED12, /* internal */ CPUCP_PACKET_REGISTER_INTERRUPTS, /* internal */ + CPUCP_PACKET_SOFT_RESET, /* internal */ CPUCP_PACKET_ID_MAX /* must be last */ }; From patchwork Tue Apr 18 09:39:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 13215328 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 12506C77B71 for ; Tue, 18 Apr 2023 09:39:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 27C3410E723; Tue, 18 Apr 2023 09:39:33 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by gabe.freedesktop.org (Postfix) with ESMTPS id 82A5410E724 for ; Tue, 18 Apr 2023 09:39:29 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0B2C262F3A; Tue, 18 Apr 2023 09:39:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 919F8C433AC; Tue, 18 Apr 2023 09:39:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681810768; bh=Kkm2B1ZfKpKomI0agT9Iz+r5j+6sxdjkGvmphFliIxY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YnPnmj/tQRiPwbnFIBugef88OrT1XwR1Jehq4qlSLNJQ7qy5fSLoMcjawu5d6KMi/ vOa2lbdmhJvXk0hnjkOMAC8Z4qOAJS12jVHNroz+mAzijmdgkvzWGWu5mG0PQ+L8M6 NZ3IP7Q7hUIT4Q9bnC0exkZW/RbedwtVWQoE6UgBes+StzwiIhvtUMgBZJdNmqPcNg oV02cHmpoNRaAlv7xce3/RNtoQtFuwpXnlNoNmUKNEFBghed9Ng3aiiBp8sonFGtwI QL9mtNgdhj851lQn3Z3OqZA3jJHHu5HraYprgT9dzDlRk7QH+OFc0ljBHRT/2gEYZz 2TFLTGoQFhR2w== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 06/10] accel/habanalabs: unsecure TPC bias registers Date: Tue, 18 Apr 2023 12:39:12 +0300 Message-Id: <20230418093916.2979728-6-ogabbay@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230418093916.2979728-1-ogabbay@kernel.org> References: <20230418093916.2979728-1-ogabbay@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ofir Bitton Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Ofir Bitton User needs to be able to perform downcast / upcast of fp8_143 dtype. Hence bias register needs to be accessed by the user. Signed-off-by: Ofir Bitton Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/gaudi2/gaudi2_security.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2_security.c b/drivers/accel/habanalabs/gaudi2/gaudi2_security.c index 52a12c2bb58e..fadb870ff4c0 100644 --- a/drivers/accel/habanalabs/gaudi2/gaudi2_security.c +++ b/drivers/accel/habanalabs/gaudi2/gaudi2_security.c @@ -1542,6 +1542,7 @@ static const u32 gaudi2_pb_dcr0_tpc0_unsecured_regs[] = { mmDCORE0_TPC0_CFG_LUT_FUNC128_BASE2_ADDR_HI, mmDCORE0_TPC0_CFG_LUT_FUNC256_BASE2_ADDR_LO, mmDCORE0_TPC0_CFG_LUT_FUNC256_BASE2_ADDR_HI, + mmDCORE0_TPC0_CFG_FP8_143_BIAS, mmDCORE0_TPC0_CFG_ROUND_CSR, mmDCORE0_TPC0_CFG_CONV_ROUND_CSR, mmDCORE0_TPC0_CFG_SEMAPHORE, From patchwork Tue Apr 18 09:39:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 13215335 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 53050C77B71 for ; Tue, 18 Apr 2023 09:39:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 74B6710E727; Tue, 18 Apr 2023 09:39:58 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by gabe.freedesktop.org (Postfix) with ESMTPS id F114A10E723 for ; Tue, 18 Apr 2023 09:39:30 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 79E9562EE2; Tue, 18 Apr 2023 09:39:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08649C433D2; Tue, 18 Apr 2023 09:39:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681810769; bh=PUiHiQI3VT7vjg61fsTlhga3kjv/W10ivkPyrIDs4Rc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eR5vEhEuRjLmXP+dmhRQ0zuHUxQZnGkF5e9sfVhYFroAQyAAetMWbmHPGddrBBoci jg1LyjZTv+0KlVKfD5LH/xfWW768K7c5ZibM0Jy2BPpMJ6HUG8kYKB/WtnGHDksZ4N ed1qurK4/4Sq3PQPxrlFyzmJIBfAGUc0XLfNpbxm63wmZxeHCC06Zy8Ae6/5X4bK2a Mes6+3PkEmFaJJcukHt6exMz5bV6bUdqse1Jn5ndlIyLxTXqpbtKGLrvb1QI2eEwWt k8MO3o3Pp4eFP0BVB5zgbq2l6schWn0kYrmCrOT1WK/oDH7YdoqjHblTmV41Vf6uYY QTXBx4SnhbQ5Q== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 07/10] accel/habanalabs: call to HW/FW err returns 0 when no events exist Date: Tue, 18 Apr 2023 12:39:13 +0300 Message-Id: <20230418093916.2979728-7-ogabbay@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230418093916.2979728-1-ogabbay@kernel.org> References: <20230418093916.2979728-1-ogabbay@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Moti Haimovski Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Moti Haimovski This commit modifies the call to retrieve HW or FW error events to return success when no events are pending, as done in the calls to other events. Signed-off-by: Moti Haimovski Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- .../habanalabs/common/habanalabs_ioctl.c | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/accel/habanalabs/common/habanalabs_ioctl.c b/drivers/accel/habanalabs/common/habanalabs_ioctl.c index 203ee857810c..4368e6c9a23a 100644 --- a/drivers/accel/habanalabs/common/habanalabs_ioctl.c +++ b/drivers/accel/habanalabs/common/habanalabs_ioctl.c @@ -842,15 +842,15 @@ static int hw_err_info(struct hl_fpriv *hpriv, struct hl_info_args *args) struct hw_err_info *info; int rc; - if ((!user_buf_size) || (!user_buf)) + if (!user_buf) return -EINVAL; - if (user_buf_size < sizeof(struct hl_info_hw_err_event)) - return -ENOMEM; - info = &hdev->captured_err_info.hw_err; if (!info->event_info_available) - return -ENOENT; + return 0; + + if (user_buf_size < sizeof(struct hl_info_hw_err_event)) + return -ENOMEM; rc = copy_to_user(user_buf, &info->event, sizeof(struct hl_info_hw_err_event)); return rc ? -EFAULT : 0; @@ -864,15 +864,15 @@ static int fw_err_info(struct hl_fpriv *hpriv, struct hl_info_args *args) struct fw_err_info *info; int rc; - if ((!user_buf_size) || (!user_buf)) + if (!user_buf) return -EINVAL; - if (user_buf_size < sizeof(struct hl_info_fw_err_event)) - return -ENOMEM; - info = &hdev->captured_err_info.fw_err; if (!info->event_info_available) - return -ENOENT; + return 0; + + if (user_buf_size < sizeof(struct hl_info_fw_err_event)) + return -ENOMEM; rc = copy_to_user(user_buf, &info->event, sizeof(struct hl_info_fw_err_event)); return rc ? -EFAULT : 0; From patchwork Tue Apr 18 09:39:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 13215332 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9876DC77B71 for ; Tue, 18 Apr 2023 09:39:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1C49610E72F; Tue, 18 Apr 2023 09:39:41 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by gabe.freedesktop.org (Postfix) with ESMTPS id B40BC10E723 for ; Tue, 18 Apr 2023 09:39:32 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2F66662665; Tue, 18 Apr 2023 09:39:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70DE5C4339B; Tue, 18 Apr 2023 09:39:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681810771; bh=DyzilZi3AvtuWDxbseJKiNEnesYmAdHHC9BBE7yWUK8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uMig/i2wD/OTonTQUBWI67HS/whD1kLB3Wp86qjTdj32G5R9izW53ueUo9PVhp2DA KkLcIScSEgJjIAM5MoSUoPSCImlP/R94A56evXqRyzQDiEVj3X0f4S5nAlHe6p15Ka lkkx6eBA2AUD7Q8nqeRZYDu147a7bqS0JN9MkmfOxiE4lmwtSqTOkGgg3kYv9S5rEn 9oow1mUIjzFlbKknZ7TgnNQ7FaRBp5bv9H+QhvsjM8BGIp+ZkixZo21jJ+DJn5Rl1V 43wph4ade5UWERsKLk2dkSbaQCNwQNch0v65EdxV4eV0N/Ml9ULiVV8lw482MG79OY AGFeE5GAlOKeg== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 08/10] accel/habanalabs: add unregister timestamp uapi Date: Tue, 18 Apr 2023 12:39:14 +0300 Message-Id: <20230418093916.2979728-8-ogabbay@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230418093916.2979728-1-ogabbay@kernel.org> References: <20230418093916.2979728-1-ogabbay@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: farah kassabri Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: farah kassabri Add uapi to allow user to unregister timestamp record. This is needed when the user wishes to re-use the same record with different interrupt id. For that, the user must first unregister it from the current interrupt id and then register it with the new id. Signed-off-by: farah kassabri Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- .../habanalabs/common/command_submission.c | 123 ++++++++++++++---- include/uapi/drm/habanalabs_accel.h | 1 + 2 files changed, 101 insertions(+), 23 deletions(-) diff --git a/drivers/accel/habanalabs/common/command_submission.c b/drivers/accel/habanalabs/common/command_submission.c index af9d2e22c6e7..977900866e8f 100644 --- a/drivers/accel/habanalabs/common/command_submission.c +++ b/drivers/accel/habanalabs/common/command_submission.c @@ -3196,34 +3196,57 @@ static int hl_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data) return 0; } +static inline void set_record_cq_info(struct hl_user_pending_interrupt *record, + struct hl_cb *cq_cb, u32 cq_offset, u32 target_value) +{ + record->ts_reg_info.cq_cb = cq_cb; + record->cq_kernel_addr = (u64 *) cq_cb->kernel_address + cq_offset; + record->cq_target_value = target_value; +} + +static int validate_and_get_ts_record(struct device *dev, + struct hl_ts_buff *ts_buff, u64 ts_offset, + struct hl_user_pending_interrupt **req_event_record) +{ + struct hl_user_pending_interrupt *ts_cb_last; + + *req_event_record = (struct hl_user_pending_interrupt *)ts_buff->kernel_buff_address + + ts_offset; + ts_cb_last = (struct hl_user_pending_interrupt *)ts_buff->kernel_buff_address + + (ts_buff->kernel_buff_size / sizeof(struct hl_user_pending_interrupt)); + + /* Validate ts_offset not exceeding last max */ + if (*req_event_record >= ts_cb_last) { + dev_err(dev, "Ts offset(%llx) exceeds max CB offset(0x%llx)\n", + ts_offset, (u64)(uintptr_t)ts_cb_last); + return -EINVAL; + } + + return 0; +} + static int ts_buff_get_kernel_ts_record(struct hl_mmap_mem_buf *buf, struct hl_cb *cq_cb, u64 ts_offset, u64 cq_offset, u64 target_value, spinlock_t *wait_list_lock, struct hl_user_pending_interrupt **pend) { + struct hl_user_pending_interrupt *requested_offset_record; struct hl_ts_buff *ts_buff = buf->private; - struct hl_user_pending_interrupt *requested_offset_record = - (struct hl_user_pending_interrupt *)ts_buff->kernel_buff_address + - ts_offset; - struct hl_user_pending_interrupt *cb_last = - (struct hl_user_pending_interrupt *)ts_buff->kernel_buff_address + - (ts_buff->kernel_buff_size / sizeof(struct hl_user_pending_interrupt)); - unsigned long iter_counter = 0; + unsigned long iter_counter = 0, flags; u64 current_cq_counter; ktime_t timestamp; + int rc; - /* Validate ts_offset not exceeding last max */ - if (requested_offset_record >= cb_last) { - dev_err(buf->mmg->dev, "Ts offset exceeds max CB offset(0x%llx)\n", - (u64)(uintptr_t)cb_last); - return -EINVAL; - } + rc = validate_and_get_ts_record(buf->mmg->dev, ts_buff, ts_offset, + &requested_offset_record); + if (rc) + return rc; timestamp = ktime_get(); start_over: - spin_lock(wait_list_lock); + spin_lock_irqsave(wait_list_lock, flags); /* Unregister only if we didn't reach the target value * since in this case there will be no handling in irq context @@ -3234,7 +3257,9 @@ static int ts_buff_get_kernel_ts_record(struct hl_mmap_mem_buf *buf, current_cq_counter = *requested_offset_record->cq_kernel_addr; if (current_cq_counter < requested_offset_record->cq_target_value) { list_del(&requested_offset_record->wait_list_node); - spin_unlock(wait_list_lock); + spin_unlock_irqrestore(wait_list_lock, flags); + + set_record_cq_info(requested_offset_record, cq_cb, cq_offset, target_value); hl_mmap_mem_buf_put(requested_offset_record->ts_reg_info.buf); hl_cb_put(requested_offset_record->ts_reg_info.cq_cb); @@ -3245,8 +3270,8 @@ static int ts_buff_get_kernel_ts_record(struct hl_mmap_mem_buf *buf, dev_dbg(buf->mmg->dev, "ts node in middle of irq handling\n"); - /* irq thread handling in the middle give it time to finish */ - spin_unlock(wait_list_lock); + /* irq handling in the middle give it time to finish */ + spin_unlock_irqrestore(wait_list_lock, flags); usleep_range(100, 1000); if (++iter_counter == MAX_TS_ITER_NUM) { dev_err(buf->mmg->dev, @@ -3260,14 +3285,11 @@ static int ts_buff_get_kernel_ts_record(struct hl_mmap_mem_buf *buf, } else { /* Fill up the new registration node info */ requested_offset_record->ts_reg_info.buf = buf; - requested_offset_record->ts_reg_info.cq_cb = cq_cb; requested_offset_record->ts_reg_info.timestamp_kernel_addr = (u64 *) ts_buff->user_buff_address + ts_offset; - requested_offset_record->cq_kernel_addr = - (u64 *) cq_cb->kernel_address + cq_offset; - requested_offset_record->cq_target_value = target_value; + set_record_cq_info(requested_offset_record, cq_cb, cq_offset, target_value); - spin_unlock(wait_list_lock); + spin_unlock_irqrestore(wait_list_lock, flags); } *pend = requested_offset_record; @@ -3277,6 +3299,58 @@ static int ts_buff_get_kernel_ts_record(struct hl_mmap_mem_buf *buf, return 0; } +static int unregister_timestamp_node_ioctl(struct hl_device *hdev, struct hl_mem_mgr *mmg, + u64 ts_handle, u64 ts_offset, struct hl_user_interrupt *interrupt) +{ + struct hl_user_pending_interrupt *req_event_record, *pend, *temp_pend; + struct hl_mmap_mem_buf *buff; + struct hl_ts_buff *ts_buff; + bool ts_rec_found = false; + int rc; + + buff = hl_mmap_mem_buf_get(mmg, ts_handle); + if (!buff) { + dev_err(hdev->dev, "invalid TS buff handle!\n"); + return -EINVAL; + } + + ts_buff = buff->private; + + rc = validate_and_get_ts_record(hdev->dev, ts_buff, ts_offset, &req_event_record); + if (rc) + goto out; + + /* + * Note: we don't use the ts in_use field here, but we rather scan the list + * because we cannot rely on the user to keep the order of register/unregister calls + * and since we might have races here all the time between the irq and register/unregister + * calls so it safer to lock the list and scan it to find the node. + * If the node found on the list we mark it as not in use and delete it from the list, + * if it's not here then the node was handled already in the irq before we get into + * this ioctl. + */ + spin_lock(&interrupt->wait_list_lock); + list_for_each_entry_safe(pend, temp_pend, &interrupt->wait_list_head, wait_list_node) { + if (pend == req_event_record) { + pend->ts_reg_info.in_use = 0; + list_del(&pend->wait_list_node); + ts_rec_found = true; + break; + } + } + spin_unlock(&interrupt->wait_list_lock); + + /* Put refcounts that were taken when we registered the event */ + if (ts_rec_found) { + hl_mmap_mem_buf_put(pend->ts_reg_info.buf); + hl_cb_put(pend->ts_reg_info.cq_cb); + } +out: + hl_mmap_mem_buf_put(buff); + + return rc; +} + static int _hl_interrupt_wait_ioctl(struct hl_device *hdev, struct hl_ctx *ctx, struct hl_mem_mgr *cb_mmg, struct hl_mem_mgr *mmg, u64 timeout_us, u64 cq_counters_handle, u64 cq_counters_offset, @@ -3610,7 +3684,10 @@ static int hl_interrupt_wait_ioctl(struct hl_fpriv *hpriv, void *data) return -EINVAL; } - if (args->in.flags & HL_WAIT_CS_FLAGS_INTERRUPT_KERNEL_CQ) + if (args->in.flags & HL_WAIT_CS_FLAGS_UNREGISTER_INTERRUPT) + rc = unregister_timestamp_node_ioctl(hdev, &hpriv->mem_mgr, + args->in.timestamp_handle, args->in.timestamp_offset, interrupt); + else if (args->in.flags & HL_WAIT_CS_FLAGS_INTERRUPT_KERNEL_CQ) rc = _hl_interrupt_wait_ioctl(hdev, hpriv->ctx, &hpriv->mem_mgr, &hpriv->mem_mgr, args->in.interrupt_timeout_us, args->in.cq_counters_handle, args->in.cq_counters_offset, diff --git a/include/uapi/drm/habanalabs_accel.h b/include/uapi/drm/habanalabs_accel.h index d9ef1b151d04..d45454b9a62e 100644 --- a/include/uapi/drm/habanalabs_accel.h +++ b/include/uapi/drm/habanalabs_accel.h @@ -1704,6 +1704,7 @@ union hl_cs_args { #define HL_WAIT_CS_FLAGS_MULTI_CS 0x4 #define HL_WAIT_CS_FLAGS_INTERRUPT_KERNEL_CQ 0x10 #define HL_WAIT_CS_FLAGS_REGISTER_INTERRUPT 0x20 +#define HL_WAIT_CS_FLAGS_UNREGISTER_INTERRUPT 0x40 #define HL_WAIT_MULTI_CS_LIST_MAX_LEN 32 From patchwork Tue Apr 18 09:39:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 13215333 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8F09EC77B75 for ; Tue, 18 Apr 2023 09:39:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D45DE10E731; Tue, 18 Apr 2023 09:39:41 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1E2C410E726 for ; Tue, 18 Apr 2023 09:39:34 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 981A0623D5; Tue, 18 Apr 2023 09:39:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26875C433D2; Tue, 18 Apr 2023 09:39:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681810773; bh=p9rbv1GioQA0SSdKIoOwp5qdaKDPXYiHe0ch00pyzM8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PFh7XdCU1ayRMYAxC04dcu0UMzAJqA8baFDxiAHe8eRnYtl+aOS2FOkKCMY82nrdb cj1gWDwMsB9Ic/M7XpkPIVDHAHKy8ntkLLD8xBJ5g5s7XJFi6mGY8VQp99R/ZUxBA0 H1LUQvgjG5m9s4ztvG/uxpoQLZd3V1iGKvWJB0UOXXKqqH6IMLNbsb2FqZ4oXAu+Bh jPDEb64RpgcHrjUsSK6ZSkByrxtNuxZQmrl0/fnVJvEQF9yHzQzKYSXoQEwSQ05zgJ jjH6n6TLTpAWF9CcozGDN/H392gYdyLcMl64vXZOlkOn+or5tv9oPA2fOxKHkYp1bp SjFuVN7BBfsTg== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 09/10] accel/habanalabs: minimize encapsulation signal mutex lock time Date: Tue, 18 Apr 2023 12:39:15 +0300 Message-Id: <20230418093916.2979728-9-ogabbay@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230418093916.2979728-1-ogabbay@kernel.org> References: <20230418093916.2979728-1-ogabbay@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Koby Elbaz Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Koby Elbaz Sync Stream Encapsulated Signal Handlers can be managed from different contexts, and as such they are protected via a spin_lock. However, spin_lock was unnecessarily protecting a larger code section than really needed, covering a sleepable code section as well. Since spin_lock disables preemption, it could lead to sleeping in atomic context. Signed-off-by: Koby Elbaz Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/common/command_submission.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/accel/habanalabs/common/command_submission.c b/drivers/accel/habanalabs/common/command_submission.c index 977900866e8f..56bc115e1b83 100644 --- a/drivers/accel/habanalabs/common/command_submission.c +++ b/drivers/accel/habanalabs/common/command_submission.c @@ -2152,7 +2152,7 @@ static int cs_ioctl_unreserve_signals(struct hl_fpriv *hpriv, u32 handle_id) hdev->asic_funcs->hw_queues_unlock(hdev); rc = -EINVAL; - goto out; + goto out_unlock; } /* @@ -2167,15 +2167,21 @@ static int cs_ioctl_unreserve_signals(struct hl_fpriv *hpriv, u32 handle_id) /* Release the id and free allocated memory of the handle */ idr_remove(&mgr->handles, handle_id); + + /* unlock before calling ctx_put, where we might sleep */ + spin_unlock(&mgr->lock); hl_ctx_put(encaps_sig_hdl->ctx); kfree(encaps_sig_hdl); + goto out; } else { rc = -EINVAL; dev_err(hdev->dev, "failed to unreserve signals, cannot find handler\n"); } -out: + +out_unlock: spin_unlock(&mgr->lock); +out: return rc; } From patchwork Tue Apr 18 09:39:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 13215334 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45D3AC77B76 for ; Tue, 18 Apr 2023 09:39:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 42FBA10E732; Tue, 18 Apr 2023 09:39:42 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7DB1F10E725 for ; Tue, 18 Apr 2023 09:39:35 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0DF0162661; Tue, 18 Apr 2023 09:39:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FDE1C433EF; Tue, 18 Apr 2023 09:39:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681810774; bh=RlAnk0HIEtpPzMhoDosalgTSMbhgAkI4oI3YyC2FN/U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NNDTIxRBJyRhdSIkm5m0kbqUZrl4CYMrcuOvbrM8Ty9LYD5uQ6YKsOZpqnkZ0O2sK 9SMubPUXPkAuTa8LqOObnD4aYy9e+0392lixkn+7mcv6WSyEWmRHlbr8iRRJfdAGL3 KnHZnalg2666Naq0Cnk8brYxLjh41R1NrXiItCEva0AbCM3cLlgDZd59c086WxEgJv fkus7eG0i3sTEwud9hX0IduCSAO6V1wgAwkxewYwpR6c0LbbN2Xcr0eGqDnr0V416W f1Vf2+/j6jLw47A7y8CmstzHrP+Sw2L16iitpLTt3YgsDR4nKKAXj3vRGJ/5nudDjS eAKt1hKb0qBUA== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 10/10] accel/habanalabs: refactor abort of completions and waits Date: Tue, 18 Apr 2023 12:39:16 +0300 Message-Id: <20230418093916.2979728-10-ogabbay@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230418093916.2979728-1-ogabbay@kernel.org> References: <20230418093916.2979728-1-ogabbay@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Koby Elbaz Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Koby Elbaz Aborting CS completions should be in command_submission.c but aborting waiting for user interrupts should be in device.c. This separation is also for adding more abort operations in the future. Signed-off-by: Koby Elbaz Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- .../habanalabs/common/command_submission.c | 3 +-- drivers/accel/habanalabs/common/device.c | 17 ++++++++++++----- drivers/accel/habanalabs/common/habanalabs.h | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/accel/habanalabs/common/command_submission.c b/drivers/accel/habanalabs/common/command_submission.c index 56bc115e1b83..ccf68f482948 100644 --- a/drivers/accel/habanalabs/common/command_submission.c +++ b/drivers/accel/habanalabs/common/command_submission.c @@ -1139,11 +1139,10 @@ static void force_complete_cs(struct hl_device *hdev) spin_unlock(&hdev->cs_mirror_lock); } -void hl_abort_waitings_for_completion(struct hl_device *hdev) +void hl_abort_waiting_for_cs_completions(struct hl_device *hdev) { force_complete_cs(hdev); force_complete_multi_cs(hdev); - hl_release_pending_user_interrupts(hdev); } static void job_wq_completion(struct work_struct *work) diff --git a/drivers/accel/habanalabs/common/device.c b/drivers/accel/habanalabs/common/device.c index fabfc501ef54..c8f4a34d2831 100644 --- a/drivers/accel/habanalabs/common/device.c +++ b/drivers/accel/habanalabs/common/device.c @@ -1157,6 +1157,16 @@ static void take_release_locks(struct hl_device *hdev) mutex_unlock(&hdev->fpriv_ctrl_list_lock); } +static void hl_abort_waiting_for_completions(struct hl_device *hdev) +{ + hl_abort_waiting_for_cs_completions(hdev); + + /* Release all pending user interrupts, each pending user interrupt + * holds a reference to a user context. + */ + hl_release_pending_user_interrupts(hdev); +} + static void cleanup_resources(struct hl_device *hdev, bool hard_reset, bool fw_reset, bool skip_wq_flush) { @@ -1176,10 +1186,7 @@ static void cleanup_resources(struct hl_device *hdev, bool hard_reset, bool fw_r /* flush the MMU prefetch workqueue */ flush_workqueue(hdev->prefetch_wq); - /* Release all pending user interrupts, each pending user interrupt - * holds a reference to user context - */ - hl_release_pending_user_interrupts(hdev); + hl_abort_waiting_for_completions(hdev); } /* @@ -1921,7 +1928,7 @@ int hl_device_cond_reset(struct hl_device *hdev, u32 flags, u64 event_mask) hl_ctx_put(ctx); - hl_abort_waitings_for_completion(hdev); + hl_abort_waiting_for_completions(hdev); return 0; diff --git a/drivers/accel/habanalabs/common/habanalabs.h b/drivers/accel/habanalabs/common/habanalabs.h index 6b102947cb90..f83ea96c6530 100644 --- a/drivers/accel/habanalabs/common/habanalabs.h +++ b/drivers/accel/habanalabs/common/habanalabs.h @@ -3934,7 +3934,7 @@ void hl_dec_fini(struct hl_device *hdev); void hl_dec_ctx_fini(struct hl_ctx *ctx); void hl_release_pending_user_interrupts(struct hl_device *hdev); -void hl_abort_waitings_for_completion(struct hl_device *hdev); +void hl_abort_waiting_for_cs_completions(struct hl_device *hdev); int hl_cs_signal_sob_wraparound_handler(struct hl_device *hdev, u32 q_idx, struct hl_hw_sob **hw_sob, u32 count, bool encaps_sig);