accel/habanalabs: remove Gaudi1 multi MSI code
Oded Gabbay
maintainerPATCH 1/4 accel/habanalabs: remove Gaudi1 multi MSI code
From: Ofir Bitton <[email protected]>
Multi MSI interrupts aren't working in Gaudi1 and because of that, we are only using a single MSI interrupt. Therefore, let's remove this dead code in order to avoid confusion.
--- drivers/accel/habanalabs/gaudi/gaudi.c | 83 ++----------------------- drivers/accel/habanalabs/gaudi/gaudiP.h | 15 ----- 2 files changed, 5 insertions(+), 93 deletions(-)
drivers/accel/habanalabs/gaudi/gaudi.c +5 -78
@@ -2020,38 +2020,6 @@ static int gaudi_enable_msi_single(struct hl_device *hdev)return rc; } -static int gaudi_enable_msi_multi (struct hl_device *hdev) -{ -int cq_cnt = hdev->asic_prop.completion_queues_count; -int rc, i, irq_cnt_init, irq; - -for (i =0 , irq_cnt_init =0 ; i < cq_cnt ; i++, irq_cnt_init++) { - irq =gaudi_pci_irq_vector (hdev, i, false); - rc =request_irq (irq, hl_irq_handler_cq,0 , gaudi_irq_name[i], - &hdev->completion_queue[i]); -if (rc) { -dev_err (hdev->dev,"Failed to request IRQ %d" , irq); - goto free_irqs; - } - } - - irq =gaudi_pci_irq_vector (hdev,GAUDI_EVENT_QUEUE_MSI_IDX , true); - rc =request_irq (irq, hl_irq_handler_eq,0 , gaudi_irq_name[cq_cnt], - &hdev->event_queue); -if (rc) { -dev_err (hdev->dev,"Failed to request IRQ %d" , irq); - goto free_irqs; - } - -return 0 ; - -free_irqs: -for (i =0 ; i < irq_cnt_init ; i++) -free_irq (gaudi_pci_irq_vector (hdev, i, false), - &hdev->completion_queue[i]); -return rc; -} -static int gaudi_enable_msi (struct hl_device *hdev) {struct gaudi_device *gaudi = hdev->asic_specific;
@@ -2066,14 +2034,7 @@ static int gaudi_enable_msi(struct hl_device *hdev)return rc; } -if (rc <NUMBER_OF_INTERRUPTS ) { - gaudi->multi_msi_mode = false; - rc =gaudi_enable_msi_single (hdev); - }else { - gaudi->multi_msi_mode = true; - rc =gaudi_enable_msi_multi (hdev); - } - + rc =gaudi_enable_msi_single (hdev);if (rc) goto free_pci_irq_vectors;
@@ -2089,47 +2050,23 @@ static int gaudi_enable_msi(struct hl_device *hdev)static void gaudi_sync_irqs (struct hl_device *hdev) {struct gaudi_device *gaudi = hdev->asic_specific; -int i, cq_cnt = hdev->asic_prop.completion_queues_count;if (!(gaudi->hw_cap_initialized &HW_CAP_MSI ))return ;/* Wait for all pending IRQs to be finished */ -if (gaudi->multi_msi_mode) { -for (i =0 ; i < cq_cnt ; i++) -synchronize_irq (gaudi_pci_irq_vector (hdev, i, false)); - -synchronize_irq (gaudi_pci_irq_vector (hdev, -GAUDI_EVENT_QUEUE_MSI_IDX , - true)); - }else { -synchronize_irq (gaudi_pci_irq_vector (hdev,0 , false)); - } +synchronize_irq (gaudi_pci_irq_vector (hdev,0 , false)); }static void gaudi_disable_msi (struct hl_device *hdev) {struct gaudi_device *gaudi = hdev->asic_specific; -int i, irq, cq_cnt = hdev->asic_prop.completion_queues_count;if (!(gaudi->hw_cap_initialized &HW_CAP_MSI ))return ;gaudi_sync_irqs (hdev); - -if (gaudi->multi_msi_mode) { - irq =gaudi_pci_irq_vector (hdev,GAUDI_EVENT_QUEUE_MSI_IDX , - true); -free_irq (irq, &hdev->event_queue); - -for (i =0 ; i < cq_cnt ; i++) { - irq =gaudi_pci_irq_vector (hdev, i, false); -free_irq (irq, &hdev->completion_queue[i]); - } - }else { -free_irq (gaudi_pci_irq_vector (hdev,0 , false), hdev); - } - +free_irq (gaudi_pci_irq_vector (hdev,0 , false), hdev);pci_free_irq_vectors (hdev->pdev); gaudi->hw_cap_initialized &= ~HW_CAP_MSI ;
@@ -3924,11 +3861,7 @@ static int gaudi_init_cpu_queues(struct hl_device *hdev, u32 cpu_timeout)WREG32 (mmCPU_IF_PF_PQ_PI,0 ); -if (gaudi->multi_msi_mode) -WREG32 (mmCPU_IF_QUEUE_INIT,PQ_INIT_STATUS_READY_FOR_CP ); -else -WREG32 (mmCPU_IF_QUEUE_INIT, -PQ_INIT_STATUS_READY_FOR_CP_SINGLE_MSI ); +WREG32 (mmCPU_IF_QUEUE_INIT,PQ_INIT_STATUS_READY_FOR_CP_SINGLE_MSI ); irq_handler_offset = prop->gic_interrupts_enable ? mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR :
@@ -5605,7 +5538,6 @@ static void gaudi_add_end_of_cb_packets(struct hl_device *hdev, void *kernel_add u32 len, u32 original_len, u64 cq_addr, u32 cq_val, u32 msi_vec, bool eb) { - struct gaudi_device *gaudi = hdev->asic_specific; struct packet_msg_prot *cq_pkt;struct packet_nop *cq_padding;u64 msi_addr;
@@ -5635,12 +5567,7 @@ static void gaudi_add_end_of_cb_packets(struct hl_device *hdev, void *kernel_add tmp |=FIELD_PREP (GAUDI_PKT_CTL_MB_MASK ,1 ); cq_pkt->ctl =cpu_to_le32 (tmp); cq_pkt->value =cpu_to_le32 (1 ); - -if (gaudi->multi_msi_mode) - msi_addr = mmPCIE_MSI_INTR_0 + msi_vec *4 ; -else - msi_addr = mmPCIE_CORE_MSI_REQ; - + msi_addr = hdev->pdev ? mmPCIE_CORE_MSI_REQ : mmPCIE_MSI_INTR_0 + msi_vec *4 ; cq_pkt->addr =cpu_to_le64 (CFG_BASE + msi_addr); }
drivers/accel/habanalabs/gaudi/gaudiP.h +0 -15
@@ -28,20 +28,8 @@#define NUMBER_OF_COLLECTIVE_QUEUES 12#define NUMBER_OF_SOBS_IN_GRP 11 -/* -* Number of MSI interrupts IDS: -* Each completion queue has 1 ID -* The event queue has 1 ID -*/ -#define NUMBER_OF_INTERRUPTS (NUMBER_OF_CMPLT_QUEUES + \ - NUMBER_OF_CPU_HW_QUEUES) -#define GAUDI_STREAM_MASTER_ARR_SIZE 8 -#if (NUMBER_OF_INTERRUPTS >GAUDI_MSI_ENTRIES ) -#error "Number of MSI interrupts must be smaller or equal to GAUDI_MSI_ENTRIES" -#endif -#define CORESIGHT_TIMEOUT_USEC 100000/* 100 ms */ #define GAUDI_MAX_CLK_FREQ 2200000000ull/* 2200 MHz */
@@ -324,8 +312,6 @@ struct gaudi_internal_qman_info {* signal we can use this engine in later code paths. * Each bit is cleared upon reset of its corresponding H/W * engine. -* @multi_msi_mode: whether we are working in multi MSI single MSI mode. -* Multi MSI is possible only with IOMMU enabled. * @mmu_cache_inv_pi: PI for MMU cache invalidation flow. The H/W expects an * 8-bit value so use u8. */
@@ -345,7 +331,6 @@ struct gaudi_device {u32 events_stat[GAUDI_EVENT_SIZE ];u32 events_stat_aggregate[GAUDI_EVENT_SIZE ];u32 hw_cap_initialized; -u8 multi_msi_mode;u8 mmu_cache_inv_pi; };
Signature · 1 line
2.40.0
Oded Gabbay
maintainerPATCH 2/4 accel/habanalabs: fix handling of arc farm sei event
From: Dani Liberman <[email protected]>
There is only single eq entry for arc farm sei event which aggregates events from the four arc farms.
Fix the code to handle this event according to this behavior.
--- drivers/accel/habanalabs/gaudi2/gaudi2.c | 25 +++++++++++-------- .../include/gaudi2/asic_reg/gaudi2_regs.h | 4 ++- 2 files changed, 18 insertions(+), 11 deletions(-)
drivers/accel/habanalabs/gaudi2/gaudi2.c +15 -10
@@ -8490,23 +8490,28 @@ static int gaudi2_handle_qman_err(struct hl_device *hdev, u16 event_type, u64 *estatic int gaudi2_handle_arc_farm_sei_err (struct hl_device *hdev,u16 event_type) { -u32 i, sts_val, sts_clr_val =0 , error_count =0 ; +u32 i, sts_val, sts_clr_val, error_count =0 , arc_farm; - sts_val =RREG32 (mmARC_FARM_ARC0_AUX_ARC_SEI_INTR_STS); +for (arc_farm =0 ; arc_farm <NUM_OF_ARC_FARMS_ARC ; arc_farm++) { + sts_clr_val =0 ; + sts_val =RREG32 (mmARC_FARM_ARC0_AUX_ARC_SEI_INTR_STS + + (arc_farm *ARC_FARM_OFFSET )); -for (i =0 ; i <GAUDI2_NUM_OF_ARC_SEI_ERR_CAUSE ; i++) { -if (sts_val &BIT (i)) { -gaudi2_print_event (hdev, event_type, true, -"err cause: %s" , gaudi2_arc_sei_error_cause[i]); - sts_clr_val |=BIT (i); - error_count++; +for (i =0 ; i <GAUDI2_NUM_OF_ARC_SEI_ERR_CAUSE ; i++) { +if (sts_val &BIT (i)) { +gaudi2_print_event (hdev, event_type, true, +"ARC FARM ARC %u err cause: %s" , + arc_farm, gaudi2_arc_sei_error_cause[i]); + sts_clr_val |=BIT (i); + error_count++; + } } +WREG32 (mmARC_FARM_ARC0_AUX_ARC_SEI_INTR_CLR + (arc_farm *ARC_FARM_OFFSET ), + sts_clr_val); }hl_check_for_glbl_errors (hdev); -WREG32 (mmARC_FARM_ARC0_AUX_ARC_SEI_INTR_CLR, sts_clr_val); -return error_count; }
drivers/accel/habanalabs/include/gaudi2/asic_reg/gaudi2_regs.h +3 -1
@@ -1,6 +1,6 @@/* SPDX-License-Identifier: GPL-2.0 * -* Copyright 2020-2022 HabanaLabs, Ltd. +* Copyright 2020-2023 HabanaLabs, Ltd. * All Rights Reserved. * */
@@ -543,6 +543,8 @@#define HBM_MC_SPI_IEEE1500_COMP_MASK BIT(3)#define HBM_MC_SPI_IEEE1500_PAUSED_MASK BIT(4) +#define ARC_FARM_OFFSET (mmARC_FARM_ARC1_AUX_BASE - mmARC_FARM_ARC0_AUX_BASE) +#include "nic0_qpc0_regs.h" #include "nic0_qm0_regs.h" #include "nic0_qm_arc_aux0_regs.h"
Signature · 1 line
2.40.0
Oded Gabbay
maintainerPATCH 4/4 accel/habanalabs: add missing error flow in hl_sysfs_init()
In reply to Oded GabbayFrom: Tomer Tayar <[email protected]>
hl_sysfs_fini() is called only if hl_sysfs_init() completes successfully. Therefore if hl_sysfs_init() fails, need to remove any sysfs group that was added until that point.
--- drivers/accel/habanalabs/common/sysfs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/accel/habanalabs/common/sysfs.c +5 -1
@@ -497,10 +497,14 @@ int hl_sysfs_init(struct hl_device *hdev)if (rc) {dev_err (hdev->dev,"Failed to add groups to device, error %d\n" , rc); -return rc; + goto remove_groups; }return 0 ; + +remove_groups: +device_remove_groups (hdev->dev, hl_dev_attr_groups); +return rc; }void hl_sysfs_fini (struct hl_device *hdev)
Signature · 1 line
2.40.0
Oded Gabbay
maintainerPATCH 3/4 accel/habanalabs: speedup h/w queues test in Gaudi2
In reply to Oded GabbayFrom: Moti Haimovski <[email protected]>
HW queues testing at driver load and after reset takes a substantial amount of time.
This commit reduces the queues test time in Gaudi2 devices by running all the tests in parallel instead of one after the other. Time measurements on tests duration shows that the new method is almost x100 faster than the serial approach.
--- drivers/accel/habanalabs/gaudi2/gaudi2.c | 152 ++++++++++++++++------ drivers/accel/habanalabs/gaudi2/gaudi2P.h | 17 +++ 2 files changed, 128 insertions(+), 41 deletions(-)
drivers/accel/habanalabs/gaudi2/gaudi2.c +111 -41
@@ -3480,6 +3480,48 @@ static int gaudi2_special_blocks_iterator_config(struct hl_device *hdev)return gaudi2_special_blocks_config (hdev); } +static void gaudi2_test_queues_msgs_free (struct hl_device *hdev) +{ +struct gaudi2_device *gaudi2 = hdev->asic_specific; +struct gaudi2_queues_test_info *msg_info = gaudi2->queues_test_info; +int i; + +for (i =0 ; i <GAUDI2_NUM_TESTED_QS ; i++) { +/* bail-out if this is an allocation failure point */ +if (!msg_info[i].kern_addr) +break ; + +hl_asic_dma_pool_free (hdev, msg_info[i].kern_addr, msg_info[i].dma_addr); + msg_info[i].kern_addr =NULL ; + } +} + +static int gaudi2_test_queues_msgs_alloc (struct hl_device *hdev) +{ +struct gaudi2_device *gaudi2 = hdev->asic_specific; +struct gaudi2_queues_test_info *msg_info = gaudi2->queues_test_info; +int i, rc; + +/* allocate a message-short buf for each Q we intend to test */ +for (i =0 ; i <GAUDI2_NUM_TESTED_QS ; i++) { + msg_info[i].kern_addr = + (void *)hl_asic_dma_pool_zalloc (hdev,sizeof (struct packet_msg_short ), +GFP_KERNEL , &msg_info[i].dma_addr); +if (!msg_info[i].kern_addr) { +dev_err (hdev->dev, +"Failed to allocate dma memory for H/W queue %d testing\n" , i); + rc = -ENOMEM ; + goto err_exit; + } + } + +return 0 ; + +err_exit: +gaudi2_test_queues_msgs_free (hdev); +return rc; +} +static int gaudi2_sw_init (struct hl_device *hdev) {struct asic_fixed_properties *prop = &hdev->asic_prop;
@@ -3579,8 +3621,14 @@ static int gaudi2_sw_init(struct hl_device *hdev)if (rc) goto free_scratchpad_mem; + rc =gaudi2_test_queues_msgs_alloc (hdev); +if (rc) + goto special_blocks_free; +return 0 ; +special_blocks_free: +gaudi2_special_blocks_iterator_free (hdev); free_scratchpad_mem:hl_asic_dma_pool_free (hdev, gaudi2->scratchpad_kernel_address, gaudi2->scratchpad_bus_address);
@@ -3603,6 +3651,8 @@ static int gaudi2_sw_fini(struct hl_device *hdev)struct asic_fixed_properties *prop = &hdev->asic_prop;struct gaudi2_device *gaudi2 = hdev->asic_specific; +gaudi2_test_queues_msgs_free (hdev); +gaudi2_special_blocks_iterator_free (hdev);hl_cpu_accessible_dma_pool_free (hdev, prop->pmmu.page_size, gaudi2->virt_msix_db_cpu_addr);
@@ -6797,28 +6847,29 @@ static void gaudi2_qman_set_test_mode(struct hl_device *hdev, u32 hw_queue_id, b } } -static int gaudi2_test_queue (struct hl_device *hdev,u32 hw_queue_id) +static inline u32 gaudi2_test_queue_hw_queue_id_to_sob_id (struct hl_device *hdev,u32 hw_queue_id) { -u32 sob_offset = hdev->asic_prop.first_available_user_sob[0 ] *4 ; +return hdev->asic_prop.first_available_user_sob[0 ] + + hw_queue_id -GAUDI2_QUEUE_ID_PDMA_0_0 ; +} + +static void gaudi2_test_queue_clear (struct hl_device *hdev,u32 hw_queue_id) +{ +u32 sob_offset =gaudi2_test_queue_hw_queue_id_to_sob_id (hdev, hw_queue_id) *4 ;u32 sob_addr = mmDCORE0_SYNC_MNGR_OBJS_SOB_OBJ_0 + sob_offset; -u32 timeout_usec, tmp, sob_base =1 , sob_val =0x5a5a ; -struct packet_msg_short *msg_short_pkt; -dma_addr_t pkt_dma_addr; -size_t pkt_size; -int rc; -if (hdev->pldm) - timeout_usec =GAUDI2_PLDM_TEST_QUEUE_WAIT_USEC ; -else - timeout_usec =GAUDI2_TEST_QUEUE_WAIT_USEC ; +/* Reset the SOB value */ +WREG32 (sob_addr,0 ); +} - pkt_size =sizeof (*msg_short_pkt); - msg_short_pkt =hl_asic_dma_pool_zalloc (hdev, pkt_size,GFP_KERNEL , &pkt_dma_addr); -if (!msg_short_pkt) { -dev_err (hdev->dev,"Failed to allocate packet for H/W queue %d testing\n" , - hw_queue_id); -return -ENOMEM ; - } +static int gaudi2_test_queue_send_msg_short (struct hl_device *hdev,u32 hw_queue_id,u32 sob_val, +struct gaudi2_queues_test_info *msg_info) +{ +u32 sob_offset =gaudi2_test_queue_hw_queue_id_to_sob_id (hdev, hw_queue_id) *4 ; +u32 tmp, sob_base =1 ; +struct packet_msg_short *msg_short_pkt = msg_info->kern_addr; +size_t pkt_size =sizeof (struct packet_msg_short ); +int rc; tmp = (PACKET_MSG_SHORT <<GAUDI2_PKT_CTL_OPCODE_SHIFT ) | (1 << GAUDI2_PKT_CTL_EB_SHIFT) |
@@ -6829,15 +6880,25 @@ static int gaudi2_test_queue(struct hl_device *hdev, u32 hw_queue_id) msg_short_pkt->value =cpu_to_le32 (sob_val); msg_short_pkt->ctl =cpu_to_le32 (tmp); -/* Reset the SOB value */ -WREG32 (sob_addr,0 ); + rc =hl_hw_queue_send_cb_no_cmpl (hdev, hw_queue_id, pkt_size, msg_info->dma_addr); +if (rc) +dev_err (hdev->dev, +"Failed to send msg_short packet to H/W queue %d\n" , hw_queue_id); - rc =hl_hw_queue_send_cb_no_cmpl (hdev, hw_queue_id, pkt_size, pkt_dma_addr); -if (rc) { -dev_err (hdev->dev,"Failed to send msg_short packet to H/W queue %d\n" , - hw_queue_id); - goto free_pkt; - } +return rc; +} + +static int gaudi2_test_queue_wait_completion (struct hl_device *hdev,u32 hw_queue_id,u32 sob_val) +{ +u32 sob_offset =gaudi2_test_queue_hw_queue_id_to_sob_id (hdev, hw_queue_id) *4 ; +u32 sob_addr = mmDCORE0_SYNC_MNGR_OBJS_SOB_OBJ_0 + sob_offset; +u32 timeout_usec, tmp; +int rc; + +if (hdev->pldm) + timeout_usec =GAUDI2_PLDM_TEST_QUEUE_WAIT_USEC ; +else + timeout_usec =GAUDI2_TEST_QUEUE_WAIT_USEC ; rc = hl_poll_timeout( hdev,
@@ -6853,11 +6914,6 @@ static int gaudi2_test_queue(struct hl_device *hdev, u32 hw_queue_id) rc = -EIO ; } -/* Reset the SOB value */ -WREG32 (sob_addr,0 ); - -free_pkt: -hl_asic_dma_pool_free (hdev, (void *) msg_short_pkt, pkt_dma_addr);return rc; }
@@ -6877,30 +6933,44 @@ static int gaudi2_test_cpu_queue(struct hl_device *hdev)static int gaudi2_test_queues (struct hl_device *hdev) { -int i, rc, ret_val =0 ; +struct gaudi2_device *gaudi2 = hdev->asic_specific; +struct gaudi2_queues_test_info *msg_info; +u32 sob_val =0x5a5a ; +int i, rc; +/* send test message on all enabled Qs */ for (i =GAUDI2_QUEUE_ID_PDMA_0_0 ; i <GAUDI2_QUEUE_ID_CPU_PQ ; i++) {if (!gaudi2_is_queue_enabled (hdev, i))continue ; + msg_info = &gaudi2->queues_test_info[i -GAUDI2_QUEUE_ID_PDMA_0_0 ];gaudi2_qman_set_test_mode (hdev, i, true); - rc =gaudi2_test_queue (hdev, i); -gaudi2_qman_set_test_mode (hdev, i, false); - -if (rc) { - ret_val = -EINVAL ; +gaudi2_test_queue_clear (hdev, i); + rc =gaudi2_test_queue_send_msg_short (hdev, i, sob_val, msg_info); +if (rc) goto done; - } } rc =gaudi2_test_cpu_queue (hdev); -if (rc) { - ret_val = -EINVAL ; +if (rc) goto done; + +/* verify that all messages were processed */ +for (i =GAUDI2_QUEUE_ID_PDMA_0_0 ; i <GAUDI2_QUEUE_ID_CPU_PQ ; i++) { +if (!gaudi2_is_queue_enabled (hdev, i)) +continue ; + + rc =gaudi2_test_queue_wait_completion (hdev, i, sob_val); +if (rc) +/* chip is not usable, no need for cleanups, just bail-out with error */ + goto done; + +gaudi2_test_queue_clear (hdev, i); +gaudi2_qman_set_test_mode (hdev, i, false); } done: -return ret_val; +return rc; }static int gaudi2_compute_reset_late_init (struct hl_device *hdev)
drivers/accel/habanalabs/gaudi2/gaudi2P.h +17 -0
@@ -240,6 +240,8 @@#define GAUDI2_SOB_INCREMENT_BY_ONE (FIELD_PREP(DCORE0_SYNC_MNGR_OBJS_SOB_OBJ_VAL_MASK, 1) | \ FIELD_PREP(DCORE0_SYNC_MNGR_OBJS_SOB_OBJ_INC_MASK, 1)) +#define GAUDI2_NUM_TESTED_QS (GAUDI2_QUEUE_ID_CPU_PQ - GAUDI2_QUEUE_ID_PDMA_0_0) +#define GAUDI2_NUM_OF_GLBL_ERR_CAUSE 8enum gaudi2_reserved_sob_id {
@@ -452,6 +454,17 @@ struct dup_block_ctx {unsigned int instances; }; +/** +* struct gaudi2_queues_test_info - Holds the address of a the messages used for testing the +* device queues. +* @dma_addr: the address used by the HW for accessing the message. +* @kern_addr: The address used by the driver for accessing the message. +*/ +struct gaudi2_queues_test_info { +dma_addr_t dma_addr; +void *kern_addr; +}; +/** * struct gaudi2_device - ASIC specific manage structure. * @cpucp_info_get: get information on device from CPU-CP
@@ -510,6 +523,7 @@ struct dup_block_ctx {* @flush_db_fifo: flag to force flush DB FIFO after a write. * @hbm_cfg: HBM subsystem settings * @hw_queues_lock_mutex: used by simulator instead of hw_queues_lock. +* @queues_test_info: information used by the driver when testing the HW queues. */ struct gaudi2_device {int (*cpucp_info_get)(struct hl_device *hdev);
@@ -537,6 +551,9 @@ struct gaudi2_device {u32 events_stat[GAUDI2_EVENT_SIZE ];u32 events_stat_aggregate[GAUDI2_EVENT_SIZE ];u32 num_of_valid_hw_events; + +/* Queue testing */ +struct gaudi2_queues_test_info queues_test_info[GAUDI2_NUM_TESTED_QS ]; };/*
Signature · 1 line
2.40.0