From patchwork Mon Sep 18 09:13: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: 13389267 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 1A097C46CA1 for ; Mon, 18 Sep 2023 09:13:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 518C310E231; Mon, 18 Sep 2023 09:13:34 +0000 (UTC) Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id F40D410E22E for ; Mon, 18 Sep 2023 09:13:31 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 76E76CE0A0B; Mon, 18 Sep 2023 09:13:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5475C433C8; Mon, 18 Sep 2023 09:13:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695028407; bh=4/VVM9XorWdiX2PYPKT9KPOPQ6XGUkwmOlEV21QKXRE=; h=From:To:Cc:Subject:Date:From; b=HrhjxHXVAnfudU7iLw3Pb7N1bKFtSBxEH91cS8gs54t7qYGMGrEr/kbElzMHQcOsH K5pFoaBsxF2jJX7SedvmjUL+1i28zewOgbCnUAt0qlYsOcyvX3tiaAhlHqVPHwx3QD hLtDlZGd3oizheUpHl9NNYAkEWVyGvt8BYaXDZyrx43GjxqtHZcoy9ge9gThbeZkzn xbVvPL8Q+EcuixZnOd0ptUE4sYKFwM4NwZvjNB32SN1Tf9iBVzxl/TEUhnauFkfBID PCCASGzDZ2GdwtE3LsA27cjfUPjKD28Ig9kpPAefNCtrUrfviBjnWc5w7P8tG348Gy rDQs6T4mdmXXA== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 01/14] accel/habanalabs: improve etf configuration Date: Mon, 18 Sep 2023 12:13:08 +0300 Message-Id: <20230918091321.855943-1-ogabbay@kernel.org> X-Mailer: git-send-email 2.34.1 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: Benjamin Dotan Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Benjamin Dotan coresight ETF blocks have different size. As a result, sync packets need to be aligned based on fifo size. Signed-off-by: Benjamin Dotan Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/gaudi2/gaudi2_coresight.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2_coresight.c b/drivers/accel/habanalabs/gaudi2/gaudi2_coresight.c index 32e0f1a85b35..14a855cdc96b 100644 --- a/drivers/accel/habanalabs/gaudi2/gaudi2_coresight.c +++ b/drivers/accel/habanalabs/gaudi2/gaudi2_coresight.c @@ -2125,10 +2125,17 @@ static int gaudi2_config_etf(struct hl_device *hdev, struct hl_debug_params *par if (!input) return -EINVAL; + val = RREG32(base_reg + mmETF_RSZ_OFFSET) << 2; + if (val) { + val = ffs(val); + WREG32(base_reg + mmETF_PSCR_OFFSET, val); + } else { + WREG32(base_reg + mmETF_PSCR_OFFSET, 0x10); + } + WREG32(base_reg + mmETF_BUFWM_OFFSET, 0x3FFC); WREG32(base_reg + mmETF_MODE_OFFSET, input->sink_mode); WREG32(base_reg + mmETF_FFCR_OFFSET, 0x4001); - WREG32(base_reg + mmETF_PSCR_OFFSET, 0x10); WREG32(base_reg + mmETF_CTL_OFFSET, 1); } else { WREG32(base_reg + mmETF_BUFWM_OFFSET, 0); From patchwork Mon Sep 18 09:13: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: 13389266 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 422F8C46CA1 for ; Mon, 18 Sep 2023 09:13:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1D8F810E22E; Mon, 18 Sep 2023 09:13:34 +0000 (UTC) Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id F24CD10E22D for ; Mon, 18 Sep 2023 09:13:31 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8C349B80C02; Mon, 18 Sep 2023 09:13:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A35CC433C9; Mon, 18 Sep 2023 09:13:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695028409; bh=9cdXrTw+/xKd2cIdxIiF2QqBtcopA1xELWmurmcutPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZAik4hO06gLlycr2aB+5sQ+GdcyuEFGNCy3wXx3ayf6iiH3AFxIJ4E8VmYUhRDnYf 0mjjcdj3zD3H4MBiRjCpljUKKU5Q54qVFzIuMym5zWVFOkUtObaj/ZTNWeoKVn+3g5 n1kapv04rq+IlPFOXjvTGdFNfH4SoeuK/cgX5mapQjJb7NZayXeHgssbgVQMw0uPDU xAHCX/YXSvVXZHfd5cO/j+OsmpFoPe0yE/sF5dcgCUMDLKRni/JpsAHFARWgjJtHuS ruULQNi+9uXJ+vpvMbFktyrKUWORlYH6kNQNsZJ8xuG552IH279YI9UYkzee5M73th 3s6XfIlP3PWjg== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 02/14] accel/habanalabs/gaudi2: include block id in ECC error reporting Date: Mon, 18 Sep 2023 12:13:09 +0300 Message-Id: <20230918091321.855943-2-ogabbay@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918091321.855943-1-ogabbay@kernel.org> References: <20230918091321.855943-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 During ECC event handling, Memory wrapper id was mistakenly printed as block id. Fix the print and in addition fetch the actual block-id from firmware. Signed-off-by: Ofir Bitton Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/gaudi2/gaudi2.c | 23 +++++++++++++++---- .../habanalabs/include/common/cpucp_if.h | 3 ++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2.c b/drivers/accel/habanalabs/gaudi2/gaudi2.c index d60389b6700f..dca19be42d5f 100644 --- a/drivers/accel/habanalabs/gaudi2/gaudi2.c +++ b/drivers/accel/habanalabs/gaudi2/gaudi2.c @@ -7834,16 +7834,29 @@ static void gaudi2_print_event(struct hl_device *hdev, u16 event_type, static bool gaudi2_handle_ecc_event(struct hl_device *hdev, u16 event_type, struct hl_eq_ecc_data *ecc_data) { - u64 ecc_address = 0, ecc_syndrom = 0; + u64 ecc_address = 0, ecc_syndrome = 0; u8 memory_wrapper_idx = 0; + bool has_block_id = false; + u16 block_id; + + if (!hl_is_fw_sw_ver_below(hdev, 1, 12)) + has_block_id = true; ecc_address = le64_to_cpu(ecc_data->ecc_address); - ecc_syndrom = le64_to_cpu(ecc_data->ecc_syndrom); + ecc_syndrome = le64_to_cpu(ecc_data->ecc_syndrom); memory_wrapper_idx = ecc_data->memory_wrapper_idx; - gaudi2_print_event(hdev, event_type, !ecc_data->is_critical, - "ECC error detected. address: %#llx. Syndrom: %#llx. block id %u. critical %u.", - ecc_address, ecc_syndrom, memory_wrapper_idx, ecc_data->is_critical); + if (has_block_id) { + block_id = le16_to_cpu(ecc_data->block_id); + gaudi2_print_event(hdev, event_type, !ecc_data->is_critical, + "ECC error detected. address: %#llx. Syndrome: %#llx. wrapper id %u. block id %#x. critical %u.", + ecc_address, ecc_syndrome, memory_wrapper_idx, block_id, + ecc_data->is_critical); + } else { + gaudi2_print_event(hdev, event_type, !ecc_data->is_critical, + "ECC error detected. address: %#llx. Syndrome: %#llx. wrapper id %u. critical %u.", + ecc_address, ecc_syndrome, memory_wrapper_idx, ecc_data->is_critical); + } return !!ecc_data->is_critical; } diff --git a/drivers/accel/habanalabs/include/common/cpucp_if.h b/drivers/accel/habanalabs/include/common/cpucp_if.h index 33807b839c37..ef7d32224066 100644 --- a/drivers/accel/habanalabs/include/common/cpucp_if.h +++ b/drivers/accel/habanalabs/include/common/cpucp_if.h @@ -69,7 +69,8 @@ struct hl_eq_ecc_data { __le64 ecc_syndrom; __u8 memory_wrapper_idx; __u8 is_critical; - __u8 pad[6]; + __le16 block_id; + __u8 pad[4]; }; enum hl_sm_sei_cause { From patchwork Mon Sep 18 09:13: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: 13389275 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 5FCBBCD37B0 for ; Mon, 18 Sep 2023 09:13:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A151C10E238; Mon, 18 Sep 2023 09:13:48 +0000 (UTC) Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9CB4410E22D for ; Mon, 18 Sep 2023 09:13:33 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 114FCB80CA2; Mon, 18 Sep 2023 09:13:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D08D8C433C8; Mon, 18 Sep 2023 09:13:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695028410; bh=DKlCHJ1BfrgX6X6/lxRyiL9q1TBqxd84Oj8p7ZwR7Zk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BBqeOuJGJdSu44etL3D+aEFE2n+DhAdUcsiWdveIL4AKde8n8iMnti19zRE3IZme3 8/vg/OQk4mrm8hKsfCin7SOlJsBnx0wCJOQDd345OYtKHG2gB08bpMkbY1QUuFMeWA B6bGvrhXn0R6sy1UL+fwyBcC54r/HuNSigQwObUz2zHoW7cKNiT9QfLmBSOeK6oBei GYoj/acNIbBBXsAW8Emk3JLz42L70uLLopNo0FegRD3jfk/ZO2xvPQBIug9Au9FucJ Z1RtKm4ksg70Kn19XjwJrBDiwKynmHrSi22EMIrhTAGTNHcTf3XrjvKtuz0crWSeHy TYToFCFXpUNBA== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 03/14] accel/habanalabs: move cpucp interface to linux/habanalabs Date: Mon, 18 Sep 2023 12:13:10 +0300 Message-Id: <20230918091321.855943-3-ogabbay@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918091321.855943-1-ogabbay@kernel.org> References: <20230918091321.855943-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: David Meriin Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: David Meriin The CPUCP interface is moved to a shared folder outside of accel as a pre-requisite to upstream the NIC drivers that will also include this file. Signed-off-by: David Meriin Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- MAINTAINERS | 1 + drivers/accel/habanalabs/common/firmware_if.c | 2 +- drivers/accel/habanalabs/common/habanalabs.h | 2 +- drivers/accel/habanalabs/gaudi/gaudiP.h | 2 +- drivers/accel/habanalabs/gaudi2/gaudi2P.h | 2 +- drivers/accel/habanalabs/goya/goyaP.h | 2 +- .../common => include/linux/habanalabs}/cpucp_if.h | 13 +++++++++---- .../linux/habanalabs}/hl_boot_if.h | 0 8 files changed, 15 insertions(+), 9 deletions(-) rename {drivers/accel/habanalabs/include/common => include/linux/habanalabs}/cpucp_if.h (99%) rename {drivers/accel/habanalabs/include/common => include/linux/habanalabs}/hl_boot_if.h (100%) diff --git a/MAINTAINERS b/MAINTAINERS index 90f13281d297..a9dad911add9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9067,6 +9067,7 @@ T: git https://git.kernel.org/pub/scm/linux/kernel/git/ogabbay/linux.git F: Documentation/ABI/testing/debugfs-driver-habanalabs F: Documentation/ABI/testing/sysfs-driver-habanalabs F: drivers/accel/habanalabs/ +F: include/linux/habanalabs/ F: include/trace/events/habanalabs.h F: include/uapi/drm/habanalabs_accel.h diff --git a/drivers/accel/habanalabs/common/firmware_if.c b/drivers/accel/habanalabs/common/firmware_if.c index 2bc775d29854..2a6dfea3d27d 100644 --- a/drivers/accel/habanalabs/common/firmware_if.c +++ b/drivers/accel/habanalabs/common/firmware_if.c @@ -6,7 +6,7 @@ */ #include "habanalabs.h" -#include "../include/common/hl_boot_if.h" +#include #include #include diff --git a/drivers/accel/habanalabs/common/habanalabs.h b/drivers/accel/habanalabs/common/habanalabs.h index efb046370f2e..8b5fd2b92676 100644 --- a/drivers/accel/habanalabs/common/habanalabs.h +++ b/drivers/accel/habanalabs/common/habanalabs.h @@ -8,7 +8,7 @@ #ifndef HABANALABSP_H_ #define HABANALABSP_H_ -#include "../include/common/cpucp_if.h" +#include #include "../include/common/qman_if.h" #include "../include/hw_ip/mmu/mmu_general.h" #include diff --git a/drivers/accel/habanalabs/gaudi/gaudiP.h b/drivers/accel/habanalabs/gaudi/gaudiP.h index b8fa724be5a1..831be53bb9d7 100644 --- a/drivers/accel/habanalabs/gaudi/gaudiP.h +++ b/drivers/accel/habanalabs/gaudi/gaudiP.h @@ -10,7 +10,7 @@ #include #include "../common/habanalabs.h" -#include "../include/common/hl_boot_if.h" +#include #include "../include/gaudi/gaudi_packets.h" #include "../include/gaudi/gaudi.h" #include "../include/gaudi/gaudi_async_events.h" diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2P.h b/drivers/accel/habanalabs/gaudi2/gaudi2P.h index 5f3ce086928e..4535aa5ab561 100644 --- a/drivers/accel/habanalabs/gaudi2/gaudi2P.h +++ b/drivers/accel/habanalabs/gaudi2/gaudi2P.h @@ -10,7 +10,7 @@ #include #include "../common/habanalabs.h" -#include "../include/common/hl_boot_if.h" +#include #include "../include/gaudi2/gaudi2.h" #include "../include/gaudi2/gaudi2_packets.h" #include "../include/gaudi2/gaudi2_fw_if.h" diff --git a/drivers/accel/habanalabs/goya/goyaP.h b/drivers/accel/habanalabs/goya/goyaP.h index 5df3d30b91fd..194c2ae157cd 100644 --- a/drivers/accel/habanalabs/goya/goyaP.h +++ b/drivers/accel/habanalabs/goya/goyaP.h @@ -9,8 +9,8 @@ #define GOYAP_H_ #include +#include #include "../common/habanalabs.h" -#include "../include/common/hl_boot_if.h" #include "../include/goya/goya_packets.h" #include "../include/goya/goya.h" #include "../include/goya/goya_async_events.h" diff --git a/drivers/accel/habanalabs/include/common/cpucp_if.h b/include/linux/habanalabs/cpucp_if.h similarity index 99% rename from drivers/accel/habanalabs/include/common/cpucp_if.h rename to include/linux/habanalabs/cpucp_if.h index ef7d32224066..4cdedb603ecb 100644 --- a/drivers/accel/habanalabs/include/common/cpucp_if.h +++ b/include/linux/habanalabs/cpucp_if.h @@ -668,7 +668,11 @@ enum pq_init_status { * Packet to register interrupts indicating LKD is ready to receive events from FW. * * CPUCP_PACKET_SOFT_RESET - - * Packet to perform soft-reset. + * Packet to perform soft-reset. + * + * CPUCP_PACKET_INTS_REGISTER - + * Packet to inform FW that queues have been established and LKD is ready to receive + * EQ events. */ enum cpucp_packet_id { @@ -734,9 +738,10 @@ enum cpucp_packet_id { CPUCP_PACKET_RESERVED10, /* not used */ 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 */ + CPUCP_PACKET_RESERVED13, /* internal */ + CPUCP_PACKET_SOFT_RESET, /* internal */ + CPUCP_PACKET_INTS_REGISTER, /* internal */ + CPUCP_PACKET_ID_MAX /* must be last */ }; #define CPUCP_PACKET_FENCE_VAL 0xFE8CE7A5 diff --git a/drivers/accel/habanalabs/include/common/hl_boot_if.h b/include/linux/habanalabs/hl_boot_if.h similarity index 100% rename from drivers/accel/habanalabs/include/common/hl_boot_if.h rename to include/linux/habanalabs/hl_boot_if.h From patchwork Mon Sep 18 09:13: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: 13389268 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 3B444C46CA1 for ; Mon, 18 Sep 2023 09:13:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AD94110E22D; Mon, 18 Sep 2023 09:13:38 +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 AE19D10E22E for ; Mon, 18 Sep 2023 09:13:33 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 04E6260B32; Mon, 18 Sep 2023 09:13:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53616C433C7; Mon, 18 Sep 2023 09:13:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695028412; bh=Lajnt7mV35ksl0/tTunQMF5VIdd1qJ8xz+Rqy63owcI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nm5W3YwaVhlJNL+T0XmAIhqO+kqpxD/Z4pPl0TpQ+R7OkDSJIkY/KLyglWPGZUL0m Q9JhaTzMQVpfvJTfJeEM/LnqMhR8VYrzaWwnCImVSoarabeEgyk+WVhrotR38HH8dK mLbIa2ZZY9XskHZSzAyGockL+3buJTVKqztS1zyTrcflFz79OCi8YmZpxFu9KS9MjX vQ8Sow5lVvbufESx8a9cbo7sGsJfYUzoDBiI+vq3/pzB2Fr9maslnIOmiTignoW7XV WukUgoM9tYCoP66t/Ys09KxRbMpXgfC4rc4XnBWP7z45ql0kuD5Fy+MtDfYUMzottj ZGq1NZnGT6rvg== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 04/14] accel/habanalabs: disable events ioctls on control device Date: Mon, 18 Sep 2023 12:13:11 +0300 Message-Id: <20230918091321.855943-4-ogabbay@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918091321.855943-1-ogabbay@kernel.org> References: <20230918091321.855943-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 Because it is not used and also, for graceful reset to work those ioctls should run on the compute device. Signed-off-by: Dafna Hirschfeld Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/common/device.c | 13 ------------- drivers/accel/habanalabs/common/habanalabs_drv.c | 1 - drivers/accel/habanalabs/common/habanalabs_ioctl.c | 11 +++++++++++ 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/drivers/accel/habanalabs/common/device.c b/drivers/accel/habanalabs/common/device.c index 5293ac3c7988..2d12c197e165 100644 --- a/drivers/accel/habanalabs/common/device.c +++ b/drivers/accel/habanalabs/common/device.c @@ -572,11 +572,6 @@ static int hl_device_release_ctrl(struct inode *inode, struct file *filp) list_del(&hpriv->dev_node); mutex_unlock(&hdev->fpriv_ctrl_list_lock); out: - /* release the eventfd */ - if (hpriv->notifier_event.eventfd) - eventfd_ctx_put(hpriv->notifier_event.eventfd); - - mutex_destroy(&hpriv->notifier_event.lock); put_pid(hpriv->taskpid); kfree(hpriv); @@ -1995,14 +1990,6 @@ void hl_notifier_event_send_all(struct hl_device *hdev, u64 event_mask) hl_notifier_event_send(&hpriv->notifier_event, event_mask); mutex_unlock(&hdev->fpriv_list_lock); - - /* control device */ - mutex_lock(&hdev->fpriv_ctrl_list_lock); - - list_for_each_entry(hpriv, &hdev->fpriv_ctrl_list, dev_node) - hl_notifier_event_send(&hpriv->notifier_event, event_mask); - - mutex_unlock(&hdev->fpriv_ctrl_list_lock); } /* diff --git a/drivers/accel/habanalabs/common/habanalabs_drv.c b/drivers/accel/habanalabs/common/habanalabs_drv.c index 5db9af7e2daf..306a5bc9bf89 100644 --- a/drivers/accel/habanalabs/common/habanalabs_drv.c +++ b/drivers/accel/habanalabs/common/habanalabs_drv.c @@ -296,7 +296,6 @@ int hl_device_open_ctrl(struct inode *inode, struct file *filp) hpriv->hdev = hdev; filp->private_data = hpriv; - mutex_init(&hpriv->notifier_event.lock); nonseekable_open(inode, filp); hpriv->taskpid = get_task_pid(current, PIDTYPE_PID); diff --git a/drivers/accel/habanalabs/common/habanalabs_ioctl.c b/drivers/accel/habanalabs/common/habanalabs_ioctl.c index 87a6a0c0c48a..8c3f1e2de2fe 100644 --- a/drivers/accel/habanalabs/common/habanalabs_ioctl.c +++ b/drivers/accel/habanalabs/common/habanalabs_ioctl.c @@ -1104,6 +1104,17 @@ int hl_info_ioctl(struct drm_device *ddev, void *data, struct drm_file *file_pri static int hl_info_ioctl_control(struct hl_fpriv *hpriv, void *data) { + struct hl_info_args *args = data; + + switch (args->op) { + case HL_INFO_GET_EVENTS: + case HL_INFO_UNREGISTER_EVENTFD: + case HL_INFO_REGISTER_EVENTFD: + return -EOPNOTSUPP; + default: + break; + } + return _hl_info_ioctl(hpriv, data, hpriv->hdev->dev_ctrl); } From patchwork Mon Sep 18 09:13: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: 13389269 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 BE8AEC46CA1 for ; Mon, 18 Sep 2023 09:13:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D929610E232; Mon, 18 Sep 2023 09:13:38 +0000 (UTC) Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9EF3810E232 for ; Mon, 18 Sep 2023 09:13:36 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 150D7B80C02; Mon, 18 Sep 2023 09:13:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCA33C433C9; Mon, 18 Sep 2023 09:13:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695028413; bh=lK2kx7GPrJAjrDexWAuQkKEQ9GbU6QhgtAq8zq9Ines=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WqzYqPI9jEmU1cKZvlV69MehXk/dP22UXckVvQNKna2Ysj4Lr43B6dLuq0J6k7Z7d cjQ6c/glne+0xzpzpWyfDK+wl7pcmd0HivwuDsoCK3D1N9q+JUk3js8TByNbOfNPcV v1rsFwR5brA97Iua51XDcfXCh1O7JbH5kfewIS6+MmHzpeCldlGjp5vnLODJLhIr1V eGoEWSv9aE2p51f/5bYgd5GcnlcsP5gyg7BBpAJRLUhgAwBPIjbAvXEunVRBvprXFh ZdS4HMNgvjViRaMK1hBDntlTbl5TfN2iXlN7Ro2TpNOPTzj6Cc3eOhdF094eYSv4hl 59PC0Ty7rd2Mg== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 05/14] accel/habanalabs: fix inline doc typos Date: Mon, 18 Sep 2023 12:13:12 +0300 Message-Id: <20230918091321.855943-5-ogabbay@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918091321.855943-1-ogabbay@kernel.org> References: <20230918091321.855943-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 Fix two typos Signed-off-by: Dafna Hirschfeld Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/common/device.c | 2 +- drivers/accel/habanalabs/common/habanalabs.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/accel/habanalabs/common/device.c b/drivers/accel/habanalabs/common/device.c index 2d12c197e165..bf1b53f7fce9 100644 --- a/drivers/accel/habanalabs/common/device.c +++ b/drivers/accel/habanalabs/common/device.c @@ -639,7 +639,7 @@ static void device_release_func(struct device *dev) * @hdev: pointer to habanalabs device structure * @class: pointer to the class object of the device * @minor: minor number of the specific device - * @fpos: file operations to install for this device + * @fops: file operations to install for this device * @name: name of the device as it will appear in the filesystem * @cdev: pointer to the char device object that will be initialized * @dev: pointer to the device object that will be initialized diff --git a/drivers/accel/habanalabs/common/habanalabs.h b/drivers/accel/habanalabs/common/habanalabs.h index 8b5fd2b92676..f8c597903cac 100644 --- a/drivers/accel/habanalabs/common/habanalabs.h +++ b/drivers/accel/habanalabs/common/habanalabs.h @@ -2261,7 +2261,7 @@ struct hl_notifier_event { /** * struct hl_fpriv - process information stored in FD private data. * @hdev: habanalabs device structure. - * @filp: pointer to the DRM file private data structure. + * @file_priv: pointer to the DRM file private data structure. * @taskpid: current process ID. * @ctx: current executing context. TODO: remove for multiple ctx per process * @ctx_mgr: context manager to handle multiple context for this FD. From patchwork Mon Sep 18 09:13: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: 13389270 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 153F5CD13D1 for ; Mon, 18 Sep 2023 09:13:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 367FF10E230; Mon, 18 Sep 2023 09:13:39 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9C67610E22D for ; Mon, 18 Sep 2023 09:13:36 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 024EA60B32; Mon, 18 Sep 2023 09:13:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DDF5C433C8; Mon, 18 Sep 2023 09:13:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695028415; bh=Q1Nlo5rS4kA9jhgQTGt3jiSP5WfvGZ4EYSbJ1TkoS9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QSNKO3DBRY2YR1m0zZHnJ+2tkA6aSoq7ZhU/daQ14p4YyrVOEpGdWlcKzCVA7BLwh JOrugAzfQw6DGq1Hwmu6IvvME1/6Sm9lN+M6rDeIyGBA4yniU9jp/fH8P+tZloq5Pn 4S2PYt3gHtWHXuP4ds1TI0J/sgxefy8u3OaHIBZ/u5fmoF61qV1zAWO5DgQQ30ZJeP YAzW5GG/7s3MdCedWFpRjYEJrEUB1xCw/jXyJSgdmTpdWIwyFo+hm9pS06g+zL/ONX T3wHXRyU9+7FyDihx/kO2jYRgkeTR/++5iW90scszqmuz+IgkSQ4vda2T3jIY52Ouc Pgf7+QTzDub/w== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 06/14] accel/habanalabs: add tsc clock sampling to clock sync info Date: Mon, 18 Sep 2023 12:13:13 +0300 Message-Id: <20230918091321.855943-6-ogabbay@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918091321.855943-1-ogabbay@kernel.org> References: <20230918091321.855943-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: Hen Alon Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Hen Alon Add tsc clock to clock sync info, to enable using this clock for sampling and sync it with device time. Signed-off-by: Hen Alon Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/common/habanalabs_ioctl.c | 1 + include/uapi/drm/habanalabs_accel.h | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/accel/habanalabs/common/habanalabs_ioctl.c b/drivers/accel/habanalabs/common/habanalabs_ioctl.c index 8c3f1e2de2fe..a428226a0425 100644 --- a/drivers/accel/habanalabs/common/habanalabs_ioctl.c +++ b/drivers/accel/habanalabs/common/habanalabs_ioctl.c @@ -320,6 +320,7 @@ static int time_sync_info(struct hl_device *hdev, struct hl_info_args *args) time_sync.device_time = hdev->asic_funcs->get_device_time(hdev); time_sync.host_time = ktime_get_raw_ns(); + time_sync.tsc_time = rdtsc(); return copy_to_user(out, &time_sync, min((size_t) max_size, sizeof(time_sync))) ? -EFAULT : 0; diff --git a/include/uapi/drm/habanalabs_accel.h b/include/uapi/drm/habanalabs_accel.h index e7893b082bf8..dfe47db24ae6 100644 --- a/include/uapi/drm/habanalabs_accel.h +++ b/include/uapi/drm/habanalabs_accel.h @@ -991,6 +991,7 @@ struct hl_info_reset_count { struct hl_info_time_sync { __u64 device_time; __u64 host_time; + __u64 tsc_time; }; /** From patchwork Mon Sep 18 09:13: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: 13389273 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 128ACC46CA1 for ; Mon, 18 Sep 2023 09:13:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8A76010E234; Mon, 18 Sep 2023 09:13:47 +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 2451410E22D for ; Mon, 18 Sep 2023 09:13:38 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 920C560F80; Mon, 18 Sep 2023 09:13:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDDE9C433C9; Mon, 18 Sep 2023 09:13:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695028416; bh=rm/2o0Yzt0/LI9xoFfNtzYLF1kipUM2YHJa2kQoVsiM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h2F9tMm7wn7mi4gCp6ENOiLCITvs7zMF0dkGdi/EeUAaWvJd+cAAszmiGxLMNz1ao vSdmnRxD5t0WoQNT4XqL50Usp8NcjPPSpSMnM9ybFpE7iPqa4EOjNKNPPpY2mVdoDh Cd2LmhJaozcHmWTYUSuMMTlx4wfchbPopa56Vq7awJs9YyduG3yOO+oCCDmnmznkXU BWT4kw91ULoHRGM+026BjsRdKhmRdD/Dt6R+GzYw9i3QNqcat8hC94WfN6kG63LqB+ t3a8XLvCDZSRYKk6r8xFNUItiw/S0JBroKR3M7jWAfF12tngCCLDJZCqXehxoR2lwX O7mCLfPa3PKxQ== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 07/14] accel/habanalabs/gaudi2: print power-mode changes Date: Mon, 18 Sep 2023 12:13:14 +0300 Message-Id: <20230918091321.855943-7-ogabbay@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918091321.855943-1-ogabbay@kernel.org> References: <20230918091321.855943-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 Print to kernel log any device power mode changes events reported by the FW. Signed-off-by: Moti Haimovski Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/gaudi2/gaudi2.c | 12 ++++++++++++ .../habanalabs/include/gaudi2/gaudi2_async_events.h | 7 +++++++ .../include/gaudi2/gaudi2_async_ids_map_extended.h | 12 ++++++++++++ 3 files changed, 31 insertions(+) diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2.c b/drivers/accel/habanalabs/gaudi2/gaudi2.c index dca19be42d5f..677900e18519 100644 --- a/drivers/accel/habanalabs/gaudi2/gaudi2.c +++ b/drivers/accel/habanalabs/gaudi2/gaudi2.c @@ -7798,6 +7798,7 @@ static inline bool is_info_event(u32 event) switch (event) { case GAUDI2_EVENT_CPU_CPLD_SHUTDOWN_CAUSE: case GAUDI2_EVENT_CPU_FIX_POWER_ENV_S ... GAUDI2_EVENT_CPU_FIX_THERMAL_ENV_E: + case GAUDI2_EVENT_ARC_PWR_BRK_ENTRY ... GAUDI2_EVENT_ARC_PWR_RD_MODE3: /* return in case of NIC status event - these events are received periodically and not as * an indication to an error. @@ -10178,6 +10179,17 @@ static void gaudi2_handle_eqe(struct hl_device *hdev, struct hl_eq_entry *eq_ent is_critical = true; break; + case GAUDI2_EVENT_ARC_PWR_BRK_ENTRY: + case GAUDI2_EVENT_ARC_PWR_BRK_EXT: + case GAUDI2_EVENT_ARC_PWR_RD_MODE0: + case GAUDI2_EVENT_ARC_PWR_RD_MODE1: + case GAUDI2_EVENT_ARC_PWR_RD_MODE2: + case GAUDI2_EVENT_ARC_PWR_RD_MODE3: + error_count = GAUDI2_NA_EVENT_CAUSE; + dev_info_ratelimited(hdev->dev, "%s event received\n", + gaudi2_irq_map_table[event_type].name); + break; + default: if (gaudi2_irq_map_table[event_type].valid) { dev_err_ratelimited(hdev->dev, "Cannot find handler for event %d\n", diff --git a/drivers/accel/habanalabs/include/gaudi2/gaudi2_async_events.h b/drivers/accel/habanalabs/include/gaudi2/gaudi2_async_events.h index f661068d0c5f..a426410139af 100644 --- a/drivers/accel/habanalabs/include/gaudi2/gaudi2_async_events.h +++ b/drivers/accel/habanalabs/include/gaudi2/gaudi2_async_events.h @@ -959,6 +959,13 @@ enum gaudi2_async_event_id { GAUDI2_EVENT_ARC_DCCM_FULL = 1319, GAUDI2_EVENT_CPU_FP32_NOT_SUPPORTED = 1320, GAUDI2_EVENT_CPU_DEV_RESET_REQ = 1321, + GAUDI2_EVENT_ARC_PWR_BRK_ENTRY = 1322, + GAUDI2_EVENT_ARC_PWR_BRK_EXT = 1323, + GAUDI2_EVENT_ARC_PWR_RD_MODE0 = 1324, + GAUDI2_EVENT_ARC_PWR_RD_MODE1 = 1325, + GAUDI2_EVENT_ARC_PWR_RD_MODE2 = 1326, + GAUDI2_EVENT_ARC_PWR_RD_MODE3 = 1327, + GAUDI2_EVENT_ARC_EQ_HEARTBEAT = 1328, GAUDI2_EVENT_SIZE, }; diff --git a/drivers/accel/habanalabs/include/gaudi2/gaudi2_async_ids_map_extended.h b/drivers/accel/habanalabs/include/gaudi2/gaudi2_async_ids_map_extended.h index ad01fc4e9940..6cb0f615fc3e 100644 --- a/drivers/accel/habanalabs/include/gaudi2/gaudi2_async_ids_map_extended.h +++ b/drivers/accel/habanalabs/include/gaudi2/gaudi2_async_ids_map_extended.h @@ -2673,6 +2673,18 @@ static struct gaudi2_async_events_ids_map gaudi2_irq_map_table[] = { .name = "FP32_NOT_SUPPORTED" }, { .fc_id = 1321, .cpu_id = 627, .valid = 1, .msg = 1, .reset = EVENT_RESET_TYPE_HARD, .name = "DEV_RESET_REQ" }, + { .fc_id = 1322, .cpu_id = 628, .valid = 1, .msg = 1, .reset = EVENT_RESET_TYPE_NONE, + .name = "PWR_BRK_ENTRY" }, + { .fc_id = 1323, .cpu_id = 629, .valid = 1, .msg = 1, .reset = EVENT_RESET_TYPE_NONE, + .name = "PWR_BRK_EXT" }, + { .fc_id = 1324, .cpu_id = 630, .valid = 1, .msg = 1, .reset = EVENT_RESET_TYPE_NONE, + .name = "PWR_RD_MODE0" }, + { .fc_id = 1325, .cpu_id = 631, .valid = 1, .msg = 1, .reset = EVENT_RESET_TYPE_NONE, + .name = "PWR_RD_MODE1" }, + { .fc_id = 1326, .cpu_id = 632, .valid = 1, .msg = 1, .reset = EVENT_RESET_TYPE_NONE, + .name = "PWR_RD_MODE2" }, + { .fc_id = 1327, .cpu_id = 633, .valid = 1, .msg = 1, .reset = EVENT_RESET_TYPE_NONE, + .name = "PWR_RD_MODE3" }, }; #endif /* __GAUDI2_ASYNC_IDS_MAP_EVENTS_EXT_H_ */ From patchwork Mon Sep 18 09:13: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: 13389278 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 E7B60CD37B0 for ; Mon, 18 Sep 2023 09:14:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 31F8010E23F; Mon, 18 Sep 2023 09:14:05 +0000 (UTC) Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1B64810E233 for ; Mon, 18 Sep 2023 09:13:41 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 89DE8B80CA2; Mon, 18 Sep 2023 09:13:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57419C433C7; Mon, 18 Sep 2023 09:13:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695028418; bh=IOe4pvYHZifdZAT1ElJWSs1UKoCsNyEBNwCY0FpORoo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fxTK3E7e+gz3U3z3h9/AjIrEtHjCMqDcZYxPSaXNoi5MliA3UdtJqyxN/nHgLBWx/ d2eeQYRQrN2mPJSlP9W95EYGF9qNjZ1sJw6u72VCR/OshM2OUrfDi50KPuSp/u+k9r +9G1WS7Se/uRnKs7vb1pNWdkuxCPi5OuYEW/hzik3GDklZwH/v57cJaxmK4EhjBdKG IUt28Nm/0DB4A7lzD9TSIBPQ3hy6IkE3QdHkm7mvZnvLbygG7DPWh2iWuwX41spBvG IJhFY2/tV2FtFc+kRLZ1aZ9tvmzkDokFLev+BvuXODME+U1tODNm280z+c6ikscAwn PpL4kikpIh8MA== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 08/14] accel/habanalabs/gaudi2: handle eq health heartbeat check Date: Mon, 18 Sep 2023 12:13:15 +0300 Message-Id: <20230918091321.855943-8-ogabbay@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918091321.855943-1-ogabbay@kernel.org> References: <20230918091321.855943-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 mechanism for fw eq health check. this will be done using two flows: using the heartbeat mechanism and raising a dedicated interrupt to indicate an eq failure like EQ full. This patch will add implementation for the eq heartbeat for gaudi2 asic. More info about the heartbeat mechanism: Expand the heartbeat mechanism to monitor a new event that will be sent from FW upon receiving heartbeat message. that way driver can know that the eq is working or not. Signed-off-by: farah kassabri Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/common/device.c | 37 ++++++++++++++++++- drivers/accel/habanalabs/common/habanalabs.h | 2 + drivers/accel/habanalabs/gaudi2/gaudi2.c | 10 +++++ .../gaudi2/gaudi2_async_ids_map_extended.h | 14 ++++--- include/linux/habanalabs/cpucp_if.h | 14 ++++++- 5 files changed, 68 insertions(+), 9 deletions(-) diff --git a/drivers/accel/habanalabs/common/device.c b/drivers/accel/habanalabs/common/device.c index bf1b53f7fce9..1d68d2233171 100644 --- a/drivers/accel/habanalabs/common/device.c +++ b/drivers/accel/habanalabs/common/device.c @@ -989,6 +989,25 @@ static bool is_pci_link_healthy(struct hl_device *hdev) return (vendor_id == PCI_VENDOR_ID_HABANALABS); } +static void hl_device_eq_heartbeat(struct hl_device *hdev) +{ + u64 event_mask = HL_NOTIFIER_EVENT_DEVICE_RESET | HL_NOTIFIER_EVENT_DEVICE_UNAVAILABLE; + struct asic_fixed_properties *prop = &hdev->asic_prop; + + /* + * This feature supported in FW version 1.12.0 45.2.0 and above, + * only on those FW versions eq_health_check_supported will be set. + * Start checking eq health only after driver has enabled events from FW. + */ + if (!prop->cpucp_info.eq_health_check_supported || !hdev->init_done) + return; + + if (hdev->eq_heartbeat_received) + hdev->eq_heartbeat_received = false; + else + hl_device_cond_reset(hdev, HL_DRV_RESET_HARD, event_mask); +} + static void hl_device_heartbeat(struct work_struct *work) { struct hl_device *hdev = container_of(work, struct hl_device, @@ -999,6 +1018,12 @@ static void hl_device_heartbeat(struct work_struct *work) if (!hl_device_operational(hdev, NULL)) goto reschedule; + /* + * For EQ health check need to check if driver received the heartbeat eq event + * in order to validate the eq is working. + */ + hl_device_eq_heartbeat(hdev); + if (!hdev->asic_funcs->send_heartbeat(hdev)) goto reschedule; @@ -1055,7 +1080,15 @@ static int device_late_init(struct hl_device *hdev) hdev->high_pll = hdev->asic_prop.high_pll; if (hdev->heartbeat) { + /* + * Before scheduling the heartbeat driver will check if eq event has received. + * for the first schedule we need to set the indication as true then for the next + * one this indication will be true only if eq event was sent by FW. + */ + hdev->eq_heartbeat_received = true; + INIT_DELAYED_WORK(&hdev->work_heartbeat, hl_device_heartbeat); + schedule_delayed_work(&hdev->work_heartbeat, usecs_to_jiffies(HL_HEARTBEAT_PER_USEC)); } @@ -2235,8 +2268,6 @@ int hl_device_init(struct hl_device *hdev) "Successfully added device %s to habanalabs driver\n", dev_name(&(hdev)->pdev->dev)); - hdev->init_done = true; - /* After initialization is done, we are ready to receive events from * the F/W. We can't do it before because we will ignore events and if * those events are fatal, we won't know about it and the device will @@ -2244,6 +2275,8 @@ int hl_device_init(struct hl_device *hdev) */ hdev->asic_funcs->enable_events_from_fw(hdev); + hdev->init_done = true; + return 0; cb_pool_fini: diff --git a/drivers/accel/habanalabs/common/habanalabs.h b/drivers/accel/habanalabs/common/habanalabs.h index f8c597903cac..e5b416852996 100644 --- a/drivers/accel/habanalabs/common/habanalabs.h +++ b/drivers/accel/habanalabs/common/habanalabs.h @@ -3314,6 +3314,7 @@ struct hl_reset_info { * device. * @supports_ctx_switch: true if a ctx switch is required upon first submission. * @support_preboot_binning: true if we support read binning info from preboot. + * @eq_heartbeat_received: indication that eq heartbeat event has received from FW. * @nic_ports_mask: Controls which NIC ports are enabled. Used only for testing. * @fw_components: Controls which f/w components to load to the device. There are multiple f/w * stages and sometimes we want to stop at a certain stage. Used only for testing. @@ -3474,6 +3475,7 @@ struct hl_device { u8 reset_upon_device_release; u8 supports_ctx_switch; u8 support_preboot_binning; + u8 eq_heartbeat_received; /* Parameters for bring-up to be upstreamed */ u64 nic_ports_mask; diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2.c b/drivers/accel/habanalabs/gaudi2/gaudi2.c index 677900e18519..e507847bf460 100644 --- a/drivers/accel/habanalabs/gaudi2/gaudi2.c +++ b/drivers/accel/habanalabs/gaudi2/gaudi2.c @@ -7804,6 +7804,7 @@ static inline bool is_info_event(u32 event) * an indication to an error. */ case GAUDI2_EVENT_CPU0_STATUS_NIC0_ENG0 ... GAUDI2_EVENT_CPU11_STATUS_NIC11_ENG1: + case GAUDI2_EVENT_ARC_EQ_HEARTBEAT: return true; default: return false; @@ -9765,6 +9766,11 @@ static u16 event_id_to_engine_id(struct hl_device *hdev, u16 event_type) return U16_MAX; } +static void hl_eq_heartbeat_event_handle(struct hl_device *hdev) +{ + hdev->eq_heartbeat_received = true; +} + static void gaudi2_handle_eqe(struct hl_device *hdev, struct hl_eq_entry *eq_entry) { struct gaudi2_device *gaudi2 = hdev->asic_specific; @@ -10190,6 +10196,10 @@ static void gaudi2_handle_eqe(struct hl_device *hdev, struct hl_eq_entry *eq_ent gaudi2_irq_map_table[event_type].name); break; + case GAUDI2_EVENT_ARC_EQ_HEARTBEAT: + hl_eq_heartbeat_event_handle(hdev); + error_count = GAUDI2_NA_EVENT_CAUSE; + break; default: if (gaudi2_irq_map_table[event_type].valid) { dev_err_ratelimited(hdev->dev, "Cannot find handler for event %d\n", diff --git a/drivers/accel/habanalabs/include/gaudi2/gaudi2_async_ids_map_extended.h b/drivers/accel/habanalabs/include/gaudi2/gaudi2_async_ids_map_extended.h index 6cb0f615fc3e..57e661771b6c 100644 --- a/drivers/accel/habanalabs/include/gaudi2/gaudi2_async_ids_map_extended.h +++ b/drivers/accel/habanalabs/include/gaudi2/gaudi2_async_ids_map_extended.h @@ -2674,17 +2674,19 @@ static struct gaudi2_async_events_ids_map gaudi2_irq_map_table[] = { { .fc_id = 1321, .cpu_id = 627, .valid = 1, .msg = 1, .reset = EVENT_RESET_TYPE_HARD, .name = "DEV_RESET_REQ" }, { .fc_id = 1322, .cpu_id = 628, .valid = 1, .msg = 1, .reset = EVENT_RESET_TYPE_NONE, - .name = "PWR_BRK_ENTRY" }, + .name = "ARC_PWR_BRK_ENTRY" }, { .fc_id = 1323, .cpu_id = 629, .valid = 1, .msg = 1, .reset = EVENT_RESET_TYPE_NONE, - .name = "PWR_BRK_EXT" }, + .name = "ARC_PWR_BRK_EXT" }, { .fc_id = 1324, .cpu_id = 630, .valid = 1, .msg = 1, .reset = EVENT_RESET_TYPE_NONE, - .name = "PWR_RD_MODE0" }, + .name = "ARC_PWR_RD_MODE0" }, { .fc_id = 1325, .cpu_id = 631, .valid = 1, .msg = 1, .reset = EVENT_RESET_TYPE_NONE, - .name = "PWR_RD_MODE1" }, + .name = "ARC_PWR_RD_MODE1" }, { .fc_id = 1326, .cpu_id = 632, .valid = 1, .msg = 1, .reset = EVENT_RESET_TYPE_NONE, - .name = "PWR_RD_MODE2" }, + .name = "ARC_PWR_RD_MODE2" }, { .fc_id = 1327, .cpu_id = 633, .valid = 1, .msg = 1, .reset = EVENT_RESET_TYPE_NONE, - .name = "PWR_RD_MODE3" }, + .name = "ARC_PWR_RD_MODE3" }, + { .fc_id = 1328, .cpu_id = 634, .valid = 1, .msg = 1, .reset = EVENT_RESET_TYPE_NONE, + .name = "ARC_EQ_HEARTBEAT" }, }; #endif /* __GAUDI2_ASYNC_IDS_MAP_EVENTS_EXT_H_ */ diff --git a/include/linux/habanalabs/cpucp_if.h b/include/linux/habanalabs/cpucp_if.h index 4cdedb603ecb..a18fa81aad1f 100644 --- a/include/linux/habanalabs/cpucp_if.h +++ b/include/linux/habanalabs/cpucp_if.h @@ -33,6 +33,17 @@ #define PLL_MAP_MAX_BITS 128 #define PLL_MAP_LEN (PLL_MAP_MAX_BITS / 8) +enum eq_event_id { + EQ_EVENT_NIC_STS_REQUEST = 0, + EQ_EVENT_PWR_MODE_0, + EQ_EVENT_PWR_MODE_1, + EQ_EVENT_PWR_MODE_2, + EQ_EVENT_PWR_MODE_3, + EQ_EVENT_PWR_BRK_ENTRY, + EQ_EVENT_PWR_BRK_EXIT, + EQ_EVENT_HEARTBEAT, +}; + /* * info of the pkt queue pointers in the first async occurrence */ @@ -1143,6 +1154,7 @@ struct cpucp_security_info { * (0 = functional 1 = binned) * @interposer_version: Interposer version programmed in eFuse * @substrate_version: Substrate version programmed in eFuse + * @eq_health_check_supported: eq health check feature supported in FW. * @fw_hbm_region_size: Size in bytes of FW reserved region in HBM. * @fw_os_version: Firmware OS Version */ @@ -1169,7 +1181,7 @@ struct cpucp_info { __u8 xbar_binning_mask; __u8 interposer_version; __u8 substrate_version; - __u8 reserved2; + __u8 eq_health_check_supported; struct cpucp_security_info sec_info; __le32 fw_hbm_region_size; __u8 pll_map[PLL_MAP_LEN]; From patchwork Mon Sep 18 09:13: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: 13389276 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 EAC5EC46CA1 for ; Mon, 18 Sep 2023 09:13:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DE15E10E23A; Mon, 18 Sep 2023 09:13:48 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3E48D10E234 for ; Mon, 18 Sep 2023 09:13:41 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 863DB60F0C; Mon, 18 Sep 2023 09:13:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF119C433CC; Mon, 18 Sep 2023 09:13:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695028419; bh=jZzubz+wsAcVV1N05/YAGUJdAXiGGqIY6UuWeo0Tcgk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MhBcCBskLilP1NkOm/lbjBhp/rbVw2FzZnl+eczpom7qmeAVnJJ7IzdGU+eZkC90g gbVkYzjiP46mabs4w3Gd5pl/Iagzbw5JT0V8YEM0PdC8JQt+BnG3WirVYW8ciSZ21a nMgctOgGd7JH6zReoqaF9aF2RKbWTsfQjkQlUvV0d/vBBkhPpqxFiYEKstjnxTokFJ 4rxYGwbGlZOGk2jvHXUcz96GUFIDsPBRwx35dEz88ykBRCu7PvIpCx8v3S35yl77O0 fb6M8OzEZgrBUOwk7mxx0ccoWw9+gYKg5Pc45EoeTJhTNmx2l6Z6toGVLp/X0M/O6R Emd6cRSoq6JSg== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 09/14] accel/habanalabs/gaudi2: add eq health check using irq Date: Mon, 18 Sep 2023 12:13:16 +0300 Message-Id: <20230918091321.855943-9-ogabbay@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918091321.855943-1-ogabbay@kernel.org> References: <20230918091321.855943-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 This is the second patch for applying the eq health check mechanism which will add support for the interrupt flow for gaudi2 asic. More info about the interrupt mechanism: set a dedicated msix for the eq error interrupt, and add interrupt handler for it. when FW detects some issue with EQ like EQ_FULL, it'll raise that interrupt and driver should reset the device. Driver will inform the FW which msix index to use through the already existing handshake mechanism which will send msix info message to fw. Signed-off-by: farah kassabri Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/common/habanalabs.h | 1 + drivers/accel/habanalabs/common/irq.c | 12 ++++++++++++ drivers/accel/habanalabs/gaudi2/gaudi2.c | 16 ++++++++++++++++ drivers/accel/habanalabs/gaudi2/gaudi2P.h | 1 + include/linux/habanalabs/cpucp_if.h | 1 + 5 files changed, 31 insertions(+) diff --git a/drivers/accel/habanalabs/common/habanalabs.h b/drivers/accel/habanalabs/common/habanalabs.h index e5b416852996..6f2cbd3c2e95 100644 --- a/drivers/accel/habanalabs/common/habanalabs.h +++ b/drivers/accel/habanalabs/common/habanalabs.h @@ -3689,6 +3689,7 @@ irqreturn_t hl_irq_handler_eq(int irq, void *arg); irqreturn_t hl_irq_handler_dec_abnrm(int irq, void *arg); irqreturn_t hl_irq_handler_user_interrupt(int irq, void *arg); irqreturn_t hl_irq_user_interrupt_thread_handler(int irq, void *arg); +irqreturn_t hl_irq_eq_error_interrupt_thread_handler(int irq, void *arg); u32 hl_cq_inc_ptr(u32 ptr); int hl_asid_init(struct hl_device *hdev); diff --git a/drivers/accel/habanalabs/common/irq.c b/drivers/accel/habanalabs/common/irq.c index 10ac100bf9e2..f6b6c54bc868 100644 --- a/drivers/accel/habanalabs/common/irq.c +++ b/drivers/accel/habanalabs/common/irq.c @@ -401,6 +401,18 @@ irqreturn_t hl_irq_user_interrupt_thread_handler(int irq, void *arg) return IRQ_HANDLED; } +irqreturn_t hl_irq_eq_error_interrupt_thread_handler(int irq, void *arg) +{ + u64 event_mask = HL_NOTIFIER_EVENT_DEVICE_RESET | HL_NOTIFIER_EVENT_DEVICE_UNAVAILABLE; + struct hl_device *hdev = arg; + + dev_err(hdev->dev, "EQ error interrupt received\n"); + + hl_device_cond_reset(hdev, HL_DRV_RESET_HARD, event_mask); + + return IRQ_HANDLED; +} + /** * hl_irq_handler_eq - irq handler for event queue * diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2.c b/drivers/accel/habanalabs/gaudi2/gaudi2.c index e507847bf460..b0ba62b691ec 100644 --- a/drivers/accel/habanalabs/gaudi2/gaudi2.c +++ b/drivers/accel/habanalabs/gaudi2/gaudi2.c @@ -4175,6 +4175,8 @@ static const char *gaudi2_irq_name(u16 irq_number) return "gaudi2 unexpected error"; case GAUDI2_IRQ_NUM_USER_FIRST ... GAUDI2_IRQ_NUM_USER_LAST: return "gaudi2 user completion"; + case GAUDI2_IRQ_NUM_EQ_ERROR: + return "gaudi2 eq error"; default: return "invalid"; } @@ -4317,6 +4319,15 @@ static int gaudi2_enable_msix(struct hl_device *hdev) } } + irq = pci_irq_vector(hdev->pdev, GAUDI2_IRQ_NUM_EQ_ERROR); + rc = request_threaded_irq(irq, NULL, hl_irq_eq_error_interrupt_thread_handler, + IRQF_ONESHOT, gaudi2_irq_name(GAUDI2_IRQ_NUM_EQ_ERROR), + hdev); + if (rc) { + dev_err(hdev->dev, "Failed to request IRQ %d", irq); + goto free_user_irq; + } + gaudi2->hw_cap_initialized |= HW_CAP_MSIX; return 0; @@ -4376,6 +4387,7 @@ static void gaudi2_sync_irqs(struct hl_device *hdev) } synchronize_irq(pci_irq_vector(hdev->pdev, GAUDI2_IRQ_NUM_EVENT_QUEUE)); + synchronize_irq(pci_irq_vector(hdev->pdev, GAUDI2_IRQ_NUM_EQ_ERROR)); } static void gaudi2_disable_msix(struct hl_device *hdev) @@ -4412,6 +4424,9 @@ static void gaudi2_disable_msix(struct hl_device *hdev) cq = &hdev->completion_queue[GAUDI2_RESERVED_CQ_CS_COMPLETION]; free_irq(irq, cq); + irq = pci_irq_vector(hdev->pdev, GAUDI2_IRQ_NUM_EQ_ERROR); + free_irq(irq, hdev); + pci_free_irq_vectors(hdev->pdev); gaudi2->hw_cap_initialized &= ~HW_CAP_MSIX; @@ -11345,6 +11360,7 @@ static int gaudi2_ack_mmu_page_fault_or_access_error(struct hl_device *hdev, u64 static void gaudi2_get_msi_info(__le32 *table) { table[CPUCP_EVENT_QUEUE_MSI_TYPE] = cpu_to_le32(GAUDI2_EVENT_QUEUE_MSIX_IDX); + table[CPUCP_EVENT_QUEUE_ERR_MSI_TYPE] = cpu_to_le32(GAUDI2_IRQ_NUM_EQ_ERROR); } static int gaudi2_map_pll_idx_to_fw_idx(u32 pll_idx) diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2P.h b/drivers/accel/habanalabs/gaudi2/gaudi2P.h index 4535aa5ab561..14e281fd9895 100644 --- a/drivers/accel/habanalabs/gaudi2/gaudi2P.h +++ b/drivers/accel/habanalabs/gaudi2/gaudi2P.h @@ -419,6 +419,7 @@ enum gaudi2_irq_num { GAUDI2_IRQ_NUM_NIC_PORT_FIRST, GAUDI2_IRQ_NUM_NIC_PORT_LAST = (GAUDI2_IRQ_NUM_NIC_PORT_FIRST + NIC_NUMBER_OF_PORTS - 1), GAUDI2_IRQ_NUM_TPC_ASSERT, + GAUDI2_IRQ_NUM_EQ_ERROR, GAUDI2_IRQ_NUM_RESERVED_FIRST, GAUDI2_IRQ_NUM_RESERVED_LAST = (GAUDI2_MSIX_ENTRIES - GAUDI2_TOTAL_USER_INTERRUPTS - 1), GAUDI2_IRQ_NUM_UNEXPECTED_ERROR = RESERVED_MSIX_UNEXPECTED_USER_ERROR_INTERRUPT, diff --git a/include/linux/habanalabs/cpucp_if.h b/include/linux/habanalabs/cpucp_if.h index a18fa81aad1f..84d74c4ee4d3 100644 --- a/include/linux/habanalabs/cpucp_if.h +++ b/include/linux/habanalabs/cpucp_if.h @@ -1004,6 +1004,7 @@ enum cpucp_msi_type { CPUCP_NIC_PORT5_MSI_TYPE, CPUCP_NIC_PORT7_MSI_TYPE, CPUCP_NIC_PORT9_MSI_TYPE, + CPUCP_EVENT_QUEUE_ERR_MSI_TYPE, CPUCP_NUM_OF_MSI_TYPES }; From patchwork Mon Sep 18 09:13:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 13389272 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 44CD1CD37B0 for ; Mon, 18 Sep 2023 09:13:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8C0CE10E235; Mon, 18 Sep 2023 09:13:47 +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 172F410E233 for ; Mon, 18 Sep 2023 09:13:42 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 85EDB61042; Mon, 18 Sep 2023 09:13:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B28AC433C7; Mon, 18 Sep 2023 09:13:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695028421; bh=lB6DUE9RYbedQxq7J1xTWUcAEDFQGvi1RKnye/w7h6Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=diVAqMwrXubwleg0KTQguCywIqmTpS6B61ykr4B+gN9AIPoO0mxV9ypba5c+otJ34 MoDJDN0uVA8LDnBTONKSbMjMPCIVh+EcNZkrkKH8Vur9TcP4eP1IzxOPo1dWx9XfCz 1uuEDBBuoX4gTdrtejkmpIxxNDLzWO19Csk1Lb0EpmGx87vBPx7yzXr9D9TY6gW2hg +r5CR6DmvMTDfOeWKy+Cfzy4iRmFZDzCX7N4J4PCCYx3LZPbY1JrJQ/3PbQQm+LAa/ lU2fDCp8ZfzDk5FecbNl+k3FfJg6iKbFoiLr4uNwJNAe1cB5bawybduTdoo24rGTHg Z7Vp4wNY6vseQ== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 10/14] accel/habanalabs: prevent sending heartbeat before events are enabled Date: Mon, 18 Sep 2023 12:13:17 +0300 Message-Id: <20230918091321.855943-10-ogabbay@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918091321.855943-1-ogabbay@kernel.org> References: <20230918091321.855943-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 After the heartbeat mechanism is now expanded to be used also for EQ health check, we shouldn't send heartbeat messages to FW before driver allow events to be received from FW. Because if the driver will send two heartbeats before it enables events to be received from FW, then the EQ health check will fail and reset the device. Signed-off-by: farah kassabri Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/common/device.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/accel/habanalabs/common/device.c b/drivers/accel/habanalabs/common/device.c index 1d68d2233171..13f14b80a7d4 100644 --- a/drivers/accel/habanalabs/common/device.c +++ b/drivers/accel/habanalabs/common/device.c @@ -994,12 +994,7 @@ static void hl_device_eq_heartbeat(struct hl_device *hdev) u64 event_mask = HL_NOTIFIER_EVENT_DEVICE_RESET | HL_NOTIFIER_EVENT_DEVICE_UNAVAILABLE; struct asic_fixed_properties *prop = &hdev->asic_prop; - /* - * This feature supported in FW version 1.12.0 45.2.0 and above, - * only on those FW versions eq_health_check_supported will be set. - * Start checking eq health only after driver has enabled events from FW. - */ - if (!prop->cpucp_info.eq_health_check_supported || !hdev->init_done) + if (!prop->cpucp_info.eq_health_check_supported) return; if (hdev->eq_heartbeat_received) @@ -1015,7 +1010,8 @@ static void hl_device_heartbeat(struct work_struct *work) struct hl_info_fw_err_info info = {0}; u64 event_mask = HL_NOTIFIER_EVENT_DEVICE_RESET | HL_NOTIFIER_EVENT_DEVICE_UNAVAILABLE; - if (!hl_device_operational(hdev, NULL)) + /* Start heartbeat checks only after driver has enabled events from FW */ + if (!hl_device_operational(hdev, NULL) || !hdev->init_done) goto reschedule; /* From patchwork Mon Sep 18 09:13:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 13389271 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 3EDDBC46CA1 for ; Mon, 18 Sep 2023 09:13:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 21E7710E233; Mon, 18 Sep 2023 09:13:47 +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 A36EE10E233 for ; Mon, 18 Sep 2023 09:13:43 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2046960CF7; Mon, 18 Sep 2023 09:13:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF777C433C8; Mon, 18 Sep 2023 09:13:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695028422; bh=MrXAGxLM0yf+s4ztq/FX0QDPjaO6/6qXmGK6LW3YNu0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O+Uv0MwKBeGgpna5V2xY8x+WVVUVnUqsAmVn0UPHtUZEJEj7zLHH1hxFrQtv5slec Yv1wGfGqnmyJDm/srOc17k/kgj2z8qKwYMeVr9SWVDbhz6CWCmV0JwwxxexpK3i1m2 Ixv9g4Zg0FCaF+DzQ6yyXi0oYpHyGXEiysJMg0VM6+OIlvYh1OcCFYpcuAegHMT07x 3D/JBa4wihKScUQWK6vfb1Is9pfLehuXF35sQhPAmxnsH59k9figSPnHarcPbz12cR VIDQ40EXi/catzNu1D2h4bWj4oV4ih8P2l1wVEu2XevNDl6RO1N3DYIPF8vg4Q7quI lPqV6s4J72d8w== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 11/14] accel/habanalabs: always pass exported size to alloc_sgt_from_device_pages() Date: Mon, 18 Sep 2023 12:13:18 +0300 Message-Id: <20230918091321.855943-11-ogabbay@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918091321.855943-1-ogabbay@kernel.org> References: <20230918091321.855943-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: Tomer Tayar Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Tomer Tayar For Gaudi1 the exported dma-buf is always composed of a single page, and therefore the exported size is equal to this page's size. When calling alloc_sgt_from_device_pages(), we pass 0 as the exported size and internally calculate it as "number of pages * page size". This makes alloc_sgt_from_device_pages() less clear, because the exported size parameter is not understood as a restriction on the pages' size. Modify to always pass the exported size explicitly. Signed-off-by: Tomer Tayar Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/common/memory.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/accel/habanalabs/common/memory.c b/drivers/accel/habanalabs/common/memory.c index 1b1b4256b011..c7e49cb383cf 100644 --- a/drivers/accel/habanalabs/common/memory.c +++ b/drivers/accel/habanalabs/common/memory.c @@ -1561,8 +1561,7 @@ static struct sg_table *alloc_sgt_from_device_pages(struct hl_device *hdev, u64 if (!sgt) return ERR_PTR(-ENOMEM); - /* remove export size restrictions in case not explicitly defined */ - cur_size_to_export = exported_size ? exported_size : (npages * page_size); + cur_size_to_export = exported_size; /* If the size of each page is larger than the dma max segment size, * then we can't combine pages and the number of entries in the SGL @@ -1728,7 +1727,7 @@ static struct sg_table *hl_map_dmabuf(struct dma_buf_attachment *attachment, &hl_dmabuf->device_address, 1, hl_dmabuf->dmabuf->size, - 0, + hl_dmabuf->dmabuf->size, attachment->dev, dir); From patchwork Mon Sep 18 09:13:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 13389274 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 B6D1DCD13D1 for ; Mon, 18 Sep 2023 09:13:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A80CF10E236; Mon, 18 Sep 2023 09:13:47 +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 AAB0E10E233 for ; Mon, 18 Sep 2023 09:13:45 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2679660CF7; Mon, 18 Sep 2023 09:13:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73E53C433C7; Mon, 18 Sep 2023 09:13:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695028424; bh=81TY+X/zYD3utV7chAR+whOPap4/nbU57ppgHVQ9bsA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H1u/iAMyRLCR0NaNS2Hlg+56JHMUGHejrEjkdvUNlbnuwqLmUI5tmcQhxlv6Gj2j1 W4OaPJ7lB3q3gcYmoOtnv+qn6xz1AVBop1IAex6pGELvyYHGxkc3LxUfVzb+U985go ySGnT6YMM+bR+Maa0T38i1khnMCFrAnnXoiuFMn2WX2rrJri7HkkwXaIibNd+CB/4I WRFCpMEnJW/GQ94dODwiDC92BQyfuqVidOH33CsvNwSRKSY9+jKiIvAvwDzRKKSnFk 3wr0g9cR5v3zPfobThDY7vM2a7iXnqtyW4rhq1VPiS6vF37vJ9he/95i6OQdOfRmdZ j/zpBKPPHStvg== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 12/14] accel/habanalabs: use exported size from dma_buf and not from phys_pg_pack Date: Mon, 18 Sep 2023 12:13:19 +0300 Message-Id: <20230918091321.855943-12-ogabbay@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918091321.855943-1-ogabbay@kernel.org> References: <20230918091321.855943-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: Tomer Tayar Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Tomer Tayar The 'exported_size' member in 'struct hl_vm_phys_pg_pack' is used to keep the exported dma-buf size, to be later used when the buffer is mapped. However it is possible that the same phys_pg_pack will be exported more than once, and independently of when the mapping takes place. Remove this member from the phys_pg_pack structure, and simply use the size in the dma-buf object as the exported size when mapping. Signed-off-by: Tomer Tayar Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/common/habanalabs.h | 2 -- drivers/accel/habanalabs/common/memory.c | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/accel/habanalabs/common/habanalabs.h b/drivers/accel/habanalabs/common/habanalabs.h index 6f2cbd3c2e95..4c5d55c9109d 100644 --- a/drivers/accel/habanalabs/common/habanalabs.h +++ b/drivers/accel/habanalabs/common/habanalabs.h @@ -2159,7 +2159,6 @@ struct hl_vm_hw_block_list_node { * @pages: the physical page array. * @npages: num physical pages in the pack. * @total_size: total size of all the pages in this list. - * @exported_size: buffer exported size. * @node: used to attach to deletion list that is used when all the allocations are cleared * at the teardown of the context. * @mapping_cnt: number of shared mappings. @@ -2176,7 +2175,6 @@ struct hl_vm_phys_pg_pack { u64 *pages; u64 npages; u64 total_size; - u64 exported_size; struct list_head node; atomic_t mapping_cnt; u32 asid; diff --git a/drivers/accel/habanalabs/common/memory.c b/drivers/accel/habanalabs/common/memory.c index c7e49cb383cf..27ab176c55c1 100644 --- a/drivers/accel/habanalabs/common/memory.c +++ b/drivers/accel/habanalabs/common/memory.c @@ -1719,7 +1719,7 @@ static struct sg_table *hl_map_dmabuf(struct dma_buf_attachment *attachment, phys_pg_pack->pages, phys_pg_pack->npages, phys_pg_pack->page_size, - phys_pg_pack->exported_size, + hl_dmabuf->dmabuf->size, attachment->dev, dir); else @@ -2044,7 +2044,6 @@ static int export_dmabuf_from_addr(struct hl_ctx *ctx, u64 addr, u64 size, u64 o if (rc) goto dec_memhash_export_cnt; - phys_pg_pack->exported_size = size; hl_dmabuf->phys_pg_pack = phys_pg_pack; hl_dmabuf->memhash_hnode = hnode; } else { From patchwork Mon Sep 18 09:13:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 13389279 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 75F11C46CA1 for ; Mon, 18 Sep 2023 09:14:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CEA9210E241; Mon, 18 Sep 2023 09:14:16 +0000 (UTC) Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by gabe.freedesktop.org (Postfix) with ESMTPS id CE8F210E237 for ; Mon, 18 Sep 2023 09:13:50 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 826EBCE0A0B; Mon, 18 Sep 2023 09:13:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04474C433CA; Mon, 18 Sep 2023 09:13:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695028426; bh=zodNnixLrbstuOswbxN+fWiJxkLR9+sM5/mxmqhTVXQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EME/oURXieCa1sfLmE3YlZhm+wtm8PZ145+lR/Vy4z1husDiDrTjlljZKBKoyrIM4 pb5Jaoy5cpgSEzauA4QbDzPKgCVphCQtCSgSh7dcvB+Myaasqc8e733J1T3wDLPHZo pjs0RdGGRSCAd4bH3we68nMwXkeheL2UGID2yvZ+maR5A9W4Z2rR0qABPwlY2kezSi LwkKykDsWqhd1PfLX9+jpq2+NdBT9hdGHP3V3S677lCyoQFTnE0I+AQ/3vv0hpCkXq Z8lmRRGNg0w5+ot/z0kFcJl6bWu8J9FlfL0TmWia1BM3imDBGJxhWBZnpsVoUlTnB0 loAo9r5pJc8Pg== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 13/14] accel/habanalabs: export dma-buf only if size/offset multiples of PAGE_SIZE Date: Mon, 18 Sep 2023 12:13:20 +0300 Message-Id: <20230918091321.855943-13-ogabbay@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918091321.855943-1-ogabbay@kernel.org> References: <20230918091321.855943-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: Tomer Tayar Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Tomer Tayar It is currently allowed for a user to export dma-buf with size and offset that are not multiples of PAGE_SIZE. The exported memory is mapped for the importer device, and there it will be rounded to PAGE_SIZE, leading to actually exporting more than the user intended to. To make the user be aware of it, accept only size and offset which are multiple of PAGE_SIZE. Signed-off-by: Tomer Tayar Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/common/memory.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/accel/habanalabs/common/memory.c b/drivers/accel/habanalabs/common/memory.c index 27ab176c55c1..b4a9ff692ebc 100644 --- a/drivers/accel/habanalabs/common/memory.c +++ b/drivers/accel/habanalabs/common/memory.c @@ -1877,16 +1877,16 @@ static int export_dmabuf(struct hl_ctx *ctx, static int validate_export_params_common(struct hl_device *hdev, u64 device_addr, u64 size) { - if (!IS_ALIGNED(device_addr, PAGE_SIZE)) { + if (!PAGE_ALIGNED(device_addr)) { dev_dbg(hdev->dev, - "exported device memory address 0x%llx should be aligned to 0x%lx\n", + "exported device memory address 0x%llx should be aligned to PAGE_SIZE 0x%lx\n", device_addr, PAGE_SIZE); return -EINVAL; } - if (size < PAGE_SIZE) { + if (!size || !PAGE_ALIGNED(size)) { dev_dbg(hdev->dev, - "exported device memory size %llu should be equal to or greater than %lu\n", + "exported device memory size %llu should be a multiple of PAGE_SIZE %lu\n", size, PAGE_SIZE); return -EINVAL; } @@ -1937,6 +1937,13 @@ static int validate_export_params(struct hl_device *hdev, u64 device_addr, u64 s if (rc) return rc; + if (!PAGE_ALIGNED(offset)) { + dev_dbg(hdev->dev, + "exported device memory offset %llu should be a multiple of PAGE_SIZE %lu\n", + offset, PAGE_SIZE); + return -EINVAL; + } + if ((offset + size) > phys_pg_pack->total_size) { dev_dbg(hdev->dev, "offset %#llx and size %#llx exceed total map size %#llx\n", offset, size, phys_pg_pack->total_size); From patchwork Mon Sep 18 09:13:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oded Gabbay X-Patchwork-Id: 13389277 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 3D803CD13D1 for ; Mon, 18 Sep 2023 09:14:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 221FA10E23E; Mon, 18 Sep 2023 09:14:05 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by gabe.freedesktop.org (Postfix) with ESMTPS id 47C0810E237 for ; Mon, 18 Sep 2023 09:13:48 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BB9D960F80; Mon, 18 Sep 2023 09:13:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D405C433C9; Mon, 18 Sep 2023 09:13:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695028427; bh=I/0HpoqHM0BJ4a7JhF8jIdMYbLNVn3owEdWgsmxxvlA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OJRm9sXt0nfeRIFPJNODErjaUMLqsMyBEEJtfSLa46nhxEiuJtXL0KSZ7S29jOEWX MF1Qk0FV7jX25U3+Lc3kWLYxnrZ92KglOupmSuI8l0YYKzWDi0LnBdLgdDQglxrzXt mKPKlKWWpBmyC3ACVqevUudK+gT2Cvmt38JblFx2MctfUdpJFrhQyQv+jSkgLcVzU2 1zPwWJhTwaA6Cvsz95aQsoLfUEceZpjxuyr7blq2kHZlasc3iDka4YxYZ7HXcHbaxe 0FeVl6HACKxUO8z/zGp6kXHh447waVaCgVtoggzUxVQ0v1iuPyGPExReb9oZRMXw1K Q0NlikoevpFEQ== From: Oded Gabbay To: dri-devel@lists.freedesktop.org Subject: [PATCH 14/14] accel/habanalabs: tiny refactor of hl_map_dmabuf() Date: Mon, 18 Sep 2023 12:13:21 +0300 Message-Id: <20230918091321.855943-14-ogabbay@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230918091321.855943-1-ogabbay@kernel.org> References: <20230918091321.855943-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: Tomer Tayar Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Tomer Tayar alloc_sgt_from_device_pages() includes relatively many parameters, and in a subsequent change another offset parameter is going to be added. Using structure fields directly when calling this function, and in hl_map_dmabuf() it is done twice, makes it a little bit difficult to understand the meaning of the parameters. To make it clearer, assign the required values into local variables with explicit names, and use the variables when calling the function. Signed-off-by: Tomer Tayar Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay --- drivers/accel/habanalabs/common/memory.c | 37 +++++++++++------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/drivers/accel/habanalabs/common/memory.c b/drivers/accel/habanalabs/common/memory.c index b4a9ff692ebc..d0edbe4b4210 100644 --- a/drivers/accel/habanalabs/common/memory.c +++ b/drivers/accel/habanalabs/common/memory.c @@ -1699,38 +1699,35 @@ static int hl_dmabuf_attach(struct dma_buf *dmabuf, static struct sg_table *hl_map_dmabuf(struct dma_buf_attachment *attachment, enum dma_data_direction dir) { + u64 *pages, npages, page_size, exported_size; struct dma_buf *dma_buf = attachment->dmabuf; struct hl_vm_phys_pg_pack *phys_pg_pack; struct hl_dmabuf_priv *hl_dmabuf; struct hl_device *hdev; struct sg_table *sgt; - hl_dmabuf = dma_buf->priv; - hdev = hl_dmabuf->ctx->hdev; - phys_pg_pack = hl_dmabuf->phys_pg_pack; - if (!attachment->peer2peer) { dev_dbg(hdev->dev, "Failed to map dmabuf because p2p is disabled\n"); return ERR_PTR(-EPERM); } - if (phys_pg_pack) - sgt = alloc_sgt_from_device_pages(hdev, - phys_pg_pack->pages, - phys_pg_pack->npages, - phys_pg_pack->page_size, - hl_dmabuf->dmabuf->size, - attachment->dev, - dir); - else - sgt = alloc_sgt_from_device_pages(hdev, - &hl_dmabuf->device_address, - 1, - hl_dmabuf->dmabuf->size, - hl_dmabuf->dmabuf->size, - attachment->dev, - dir); + hl_dmabuf = dma_buf->priv; + hdev = hl_dmabuf->ctx->hdev; + exported_size = hl_dmabuf->dmabuf->size; + phys_pg_pack = hl_dmabuf->phys_pg_pack; + + if (phys_pg_pack) { + pages = phys_pg_pack->pages; + npages = phys_pg_pack->npages; + page_size = phys_pg_pack->page_size; + } else { + pages = &hl_dmabuf->device_address; + npages = 1; + page_size = hl_dmabuf->dmabuf->size; + } + sgt = alloc_sgt_from_device_pages(hdev, pages, npages, page_size, exported_size, + attachment->dev, dir); if (IS_ERR(sgt)) dev_err(hdev->dev, "failed (%ld) to initialize sgt for dmabuf\n", PTR_ERR(sgt));