habanalabs: improve communication protocol with cpucp
PATCH 1/4 habanalabs: improve communication protocol with cpucp
From: Ofir Bitton <[email protected]>
Current messaging communictaion protocol with cpucp can get out of sync due to coherency issues. In order to improve the protocol reliability, we modify the protocol to expect a different acknowledgment for every packet sent to cpucp.
--- drivers/misc/habanalabs/common/firmware_if.c | 17 +++++++++++++++-- drivers/misc/habanalabs/common/habanalabs.h | 3 +++ drivers/misc/habanalabs/gaudi/gaudi.c | 6 +++++- drivers/misc/habanalabs/goya/goya.c | 6 +++++- .../misc/habanalabs/include/common/hl_boot_if.h | 5 +++++ 5 files changed, 33 insertions(+), 4 deletions(-)
drivers/misc/habanalabs/common/firmware_if.c +15 -2
@@ -90,9 +90,10 @@ int hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode)int hl_fw_send_cpu_message (struct hl_device *hdev,u32 hw_queue_id,u32 *msg,u16 len,u32 timeout,u64 *result) { +struct hl_hw_queue *queue = &hdev->kernel_queues[hw_queue_id];struct cpucp_packet *pkt;dma_addr_t pkt_dma_addr; -u32 tmp; +u32 tmp, expected_ack_val;int rc =0 ; pkt = hdev->asic_funcs->cpu_accessible_dma_pool_alloc(hdev, len,
@@ -115,14 +116,22 @@ int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg, goto out; } +/* set fence to a non valid value */ + pkt->fence =UINT_MAX ; + rc =hl_hw_queue_send_cb_no_cmpl (hdev, hw_queue_id, len, pkt_dma_addr);if (rc) {dev_err (hdev->dev,"Failed to send CB on CPU PQ (%d)\n" , rc); goto out; } +if (hdev->asic_prop.fw_cpucp_ack_with_pi) + expected_ack_val = queue->pi; +else + expected_ack_val =CPUCP_PACKET_FENCE_VAL ; + rc =hl_poll_timeout_memory (hdev, &pkt->fence, tmp, - (tmp ==CPUCP_PACKET_FENCE_VAL ),1000 , + (tmp == expected_ack_val),1000 , timeout, true);hl_hw_queue_inc_ci_kernel (hdev, hw_queue_id);
@@ -777,6 +786,10 @@ int hl_fw_init_cpu(struct hl_device *hdev, u32 cpu_boot_status_reg, CPU_BOOT_DEV_STS0_FW_HARD_RST_EN) prop->hard_reset_done_by_fw = true; +if (prop->fw_boot_cpu_security_map & +CPU_BOOT_DEV_STS0_PKT_PI_ACK_EN ) + prop->fw_cpucp_ack_with_pi = true; +dev_dbg (hdev->dev,"Firmware boot CPU security status %#x\n" , prop->fw_boot_cpu_security_map);
drivers/misc/habanalabs/common/habanalabs.h +3 -0
@@ -419,6 +419,8 @@ struct hl_mmu_properties {* from BOOT_DEV_STS0 * @dram_supports_virtual_memory: is there an MMU towards the DRAM * @hard_reset_done_by_fw: true if firmware is handling hard reset flow +* @fw_cpucp_ack_with_pi: true if cpucp is acking messages with the PQ PI +* instead of a magic number * @num_functional_hbms: number of functional HBMs in each DCORE. */ struct asic_fixed_properties {
@@ -479,6 +481,7 @@ struct asic_fixed_properties {u8 fw_security_status_valid;u8 dram_supports_virtual_memory;u8 hard_reset_done_by_fw; +u8 fw_cpucp_ack_with_pi;u8 num_functional_hbms; };
drivers/misc/habanalabs/gaudi/gaudi.c +5 -1
@@ -533,6 +533,7 @@ static int gaudi_get_fixed_properties(struct hl_device *hdev) prop->fw_security_disabled = true; prop->fw_security_status_valid = false; prop->hard_reset_done_by_fw = false; + prop->fw_cpucp_ack_with_pi = false;return 0 ; }
@@ -4438,9 +4439,12 @@ static void gaudi_ring_doorbell(struct hl_device *hdev, u32 hw_queue_id, u32 pi)/* ring the doorbell */ WREG32 (db_reg_offset, db_value); -if (hw_queue_id ==GAUDI_QUEUE_ID_CPU_PQ ) +if (hw_queue_id ==GAUDI_QUEUE_ID_CPU_PQ ) { +/* make sure device CPU will read latest data from host */ +mb ();WREG32 (mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR,GAUDI_EVENT_PI_UPDATE ); + } } static void gaudi_pqe_write(struct hl_device *hdev, __le64 *pqe,
drivers/misc/habanalabs/goya/goya.c +5 -1
@@ -461,6 +461,7 @@ int goya_get_fixed_properties(struct hl_device *hdev) prop->fw_security_disabled = true; prop->fw_security_status_valid = false; prop->hard_reset_done_by_fw = false; + prop->fw_cpucp_ack_with_pi = false;return 0 ; }
@@ -2806,9 +2807,12 @@ void goya_ring_doorbell(struct hl_device *hdev, u32 hw_queue_id, u32 pi)/* ring the doorbell */ WREG32 (db_reg_offset, db_value); -if (hw_queue_id ==GOYA_QUEUE_ID_CPU_PQ ) +if (hw_queue_id ==GOYA_QUEUE_ID_CPU_PQ ) { +/* make sure device CPU will read latest data from host */ +mb ();WREG32 (mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR,GOYA_ASYNC_EVENT_ID_PI_UPDATE ); + } }void goya_pqe_write (struct hl_device *hdev,__le64 *pqe,struct hl_bd *bd)
drivers/misc/habanalabs/include/common/hl_boot_if.h +5 -0
@@ -166,6 +166,10 @@* FW handles HBM ECC indications. * Initialized in: linux * +* CPU_BOOT_DEV_STS0_PKT_PI_ACK_EN Packets ack value used in the armcpd +* is set to the PI counter. +* Initialized in: linux +* * CPU_BOOT_DEV_STS0_ENABLED Device status register enabled. * This is a main indication that the * running FW populates the device status
@@ -190,6 +194,7 @@#define CPU_BOOT_DEV_STS0_SP_SRAM_EN (1 << 12)#define CPU_BOOT_DEV_STS0_CLK_GATE_EN (1 << 13)#define CPU_BOOT_DEV_STS0_HBM_ECC_EN (1 << 14) +#define CPU_BOOT_DEV_STS0_PKT_PI_ACK_EN (1 << 15)#define CPU_BOOT_DEV_STS0_ENABLED (1 << 31)enum cpu_boot_status {
Signature · 1 line
2.25.1
PATCH 2/4 habanalabs: support fetching first available user CQ
From: Ofir Bitton <[email protected]>
User must be aware of the available CQs when it needs to use them.
--- drivers/misc/habanalabs/common/habanalabs.h | 2 ++ drivers/misc/habanalabs/common/habanalabs_ioctl.c | 3 ++- drivers/misc/habanalabs/gaudi/gaudi.c | 3 +++ drivers/misc/habanalabs/goya/goya.c | 3 +++ include/uapi/misc/habanalabs.h | 3 +++ 5 files changed, 13 insertions(+), 1 deletion(-)
drivers/misc/habanalabs/common/habanalabs.h +2 -0
@@ -411,6 +411,7 @@ struct hl_mmu_properties {* @first_available_user_mon: first monitor available for the user * @first_available_user_msix_interrupt: first available msix interrupt * reserved for the user +* @first_available_cq: first available CQ for the user. * @tpc_enabled_mask: which TPCs are enabled. * @completion_queues_count: number of completion queues. * @fw_security_disabled: true if security measures are disabled in firmware,
@@ -475,6 +476,7 @@ struct asic_fixed_properties {u16 first_available_user_sob[HL_MAX_DCORES ];u16 first_available_user_mon[HL_MAX_DCORES ];u16 first_available_user_msix_interrupt; +u16 first_available_cq[HL_MAX_DCORES ];u8 tpc_enabled_mask;u8 completion_queues_count;u8 fw_security_disabled;
drivers/misc/habanalabs/common/habanalabs_ioctl.c +2 -1
@@ -397,7 +397,8 @@ static int sync_manager_info(struct hl_fpriv *hpriv, struct hl_info_args *args) prop->first_available_user_sob[args->dcore_id]; sm_info.first_available_monitor = prop->first_available_user_mon[args->dcore_id]; - + sm_info.first_available_cq = + prop->first_available_cq[args->dcore_id];return copy_to_user (out, &sm_info,min_t (size_t, (size_t ) max_size,sizeof (sm_info))) ? -EFAULT :0 ;
drivers/misc/habanalabs/gaudi/gaudi.c +3 -0
@@ -529,6 +529,9 @@ static int gaudi_get_fixed_properties(struct hl_device *hdev) prop->first_available_user_msix_interrupt =USHRT_MAX ; +for (i =0 ; i <HL_MAX_DCORES ; i++) + prop->first_available_cq[i] =USHRT_MAX ; +/* disable fw security for now, set it in a later stage */ prop->fw_security_disabled = true; prop->fw_security_status_valid = false;
drivers/misc/habanalabs/goya/goya.c +3 -0
@@ -457,6 +457,9 @@ int goya_get_fixed_properties(struct hl_device *hdev) prop->first_available_user_msix_interrupt =USHRT_MAX ; +for (i =0 ; i <HL_MAX_DCORES ; i++) + prop->first_available_cq[i] =USHRT_MAX ; +/* disable fw security for now, set it in a later stage */ prop->fw_security_disabled = true; prop->fw_security_status_valid = false;
include/uapi/misc/habanalabs.h +3 -0
@@ -414,10 +414,13 @@ struct hl_pll_frequency_info {* struct hl_info_sync_manager - sync manager information * @first_available_sync_object: first available sob * @first_available_monitor: first available monitor +* @first_available_cq: first available cq */ struct hl_info_sync_manager {__u32 first_available_sync_object;__u32 first_available_monitor; +__u32 first_available_cq; +__u32 reserved; };/**
Signature · 1 line
2.25.1
PATCH 3/4 habanalabs/gaudi: use HBM_ECC_EN bit for ECC ERR
In reply to Oded GabbayFrom: Ohad Sharabi <[email protected]>
driver should use ECC info from FW only if HBM ECC CAP is set. otherwise, try to fetch the data from MC regs only if security is disabled.
--- drivers/misc/habanalabs/gaudi/gaudi.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/misc/habanalabs/gaudi/gaudi.c +15 -3
@@ -7105,7 +7105,9 @@ static int gaudi_hbm_read_interrupts(struct hl_device *hdev, int device,u32 base, val, val2, wr_par, rd_par, ca_par, derr, serr, type, ch;int err =0 ; -if (!hdev->asic_prop.fw_security_disabled) { +if (hdev->asic_prop.fw_security_status_valid && + (hdev->asic_prop.fw_app_security_map & +CPU_BOOT_DEV_STS0_HBM_ECC_EN )) {if (!hbm_ecc_data) {dev_err (hdev->dev,"No FW ECC data" );return 0 ;
@@ -7127,14 +7129,24 @@ static int gaudi_hbm_read_interrupts(struct hl_device *hdev, int device, le32_to_cpu(hbm_ecc_data->hbm_ecc_info));dev_err (hdev->dev, -"HBM%d pc%d ECC: TYPE=%d, WR_PAR=%d, RD_PAR=%d, CA_PAR=%d, SERR=%d, DERR=%d\n" , - device, ch, type, wr_par, rd_par, ca_par, serr, derr); +"HBM%d pc%d interrupts info: WR_PAR=%d, RD_PAR=%d, CA_PAR=%d, SERR=%d, DERR=%d\n" , + device, ch, wr_par, rd_par, ca_par, serr, derr); +dev_err (hdev->dev, +"HBM%d pc%d ECC info: 1ST_ERR_ADDR=0x%x, 1ST_ERR_TYPE=%d, SEC_CONT_CNT=%u, SEC_CNT=%d, DEC_CNT=%d\n" , + device, ch, hbm_ecc_data->first_addr, type, + hbm_ecc_data->sec_cont_cnt, hbm_ecc_data->sec_cnt, + hbm_ecc_data->dec_cnt); err =1 ;return 0 ; } +if (!hdev->asic_prop.fw_security_disabled) { +dev_info (hdev->dev,"Cannot access MC regs for ECC data while security is enabled\n" ); +return 0 ; + } + base =GAUDI_HBM_CFG_BASE + device *GAUDI_HBM_CFG_OFFSET ;for (ch =0 ; ch <GAUDI_HBM_CHANNELS ; ch++) { val =RREG32_MASK (base + ch *0x1000 +0x06C ,0x0000FFFF );
Signature · 1 line
2.25.1
PATCH 4/4 habanalabs: enable F/W events after init done
In reply to Oded GabbayOnly after the initialization of the device is done, the driver is ready to receive events from the F/W. The driver can't handle events before that because of races so it will ignore events. In case of a fatal event, the driver won't know about it and the device will be operational although it shouldn't be.
Same logic should be applied after hard-reset.
--- drivers/misc/habanalabs/common/device.c | 23 +++++++++++++++++---- drivers/misc/habanalabs/common/habanalabs.h | 9 ++++++-- drivers/misc/habanalabs/gaudi/gaudi.c | 10 ++++++--- drivers/misc/habanalabs/goya/goya.c | 12 +++++++---- 4 files changed, 41 insertions(+), 13 deletions(-)
drivers/misc/habanalabs/common/device.c +19 -4
@@ -1159,12 +1159,20 @@ int hl_device_reset(struct hl_device *hdev, bool hard_reset,atomic_set (&hdev->in_reset,0 ); hdev->needs_reset = false; -if (hard_reset) +dev_notice (hdev->dev,"Successfully finished resetting the device\n" ); + +if (hard_reset) { hdev->hard_reset_cnt++; -else - hdev->soft_reset_cnt++; -dev_warn (hdev->dev,"Successfully finished resetting the device\n" ); +/* After reset 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 be operational although it shouldn't be +*/ + hdev->asic_funcs->enable_events_from_fw (hdev); + }else { + hdev->soft_reset_cnt++; + }return 0 ;
@@ -1415,6 +1423,13 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass) 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 +* be operational although it shouldn't be +*/ + hdev->asic_funcs->enable_events_from_fw (hdev); +return 0 ; release_ctx:
drivers/misc/habanalabs/common/habanalabs.h +7 -2
@@ -860,12 +860,16 @@ enum div_select_defs {* and place them in the relevant cs jobs * @collective_wait_create_jobs: allocate collective wait cs jobs * @scramble_addr: Routine to scramble the address prior of mapping it -* in the MMU. +* in the MMU. * @descramble_addr: Routine to de-scramble the address prior of -* showing it to users. +* showing it to users. * @ack_protection_bits_errors: ack and dump all security violations * @get_hw_block_id: retrieve a HW block id to be used by the user to mmap it. * @hw_block_mmap: mmap a HW block with a given id. +* @enable_events_from_fw: send interrupt to firmware to notify them the +* driver is ready to receive asynchronous events. This +* function should be called during the first init and +* after every hard-reset of the device */ struct hl_asic_funcs {int (*early_init)(struct hl_device *hdev);
@@ -982,6 +986,7 @@ struct hl_asic_funcs { u32 *block_id);int (*hw_block_mmap)(struct hl_device *hdev,struct vm_area_struct *vma,u32 block_id,u32 block_size); +void (*enable_events_from_fw)(struct hl_device *hdev); };
drivers/misc/habanalabs/gaudi/gaudi.c +7 -3
@@ -1383,8 +1383,6 @@ static int gaudi_late_init(struct hl_device *hdev)return rc; } -WREG32 (mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR,GAUDI_EVENT_INTS_REGISTER ); - rc =gaudi_fetch_psoc_frequency (hdev);if (rc) {dev_err (hdev->dev,"Failed to fetch psoc frequency\n" );
@@ -8500,6 +8498,11 @@ static int gaudi_block_mmap(struct hl_device *hdev,return -EPERM ; } +static void gaudi_enable_events_from_fw (struct hl_device *hdev) +{ +WREG32 (mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR,GAUDI_EVENT_INTS_REGISTER ); +} +static const struct hl_asic_funcs gaudi_funcs = { .early_init = gaudi_early_init, .early_fini = gaudi_early_fini,
@@ -8581,7 +8584,8 @@ static const struct hl_asic_funcs gaudi_funcs = { .descramble_addr = hl_mmu_descramble_addr, .ack_protection_bits_errors = gaudi_ack_protection_bits_errors, .get_hw_block_id = gaudi_get_hw_block_id, - .hw_block_mmap = gaudi_block_mmap + .hw_block_mmap = gaudi_block_mmap, + .enable_events_from_fw = gaudi_enable_events_from_fw };/**
drivers/misc/habanalabs/goya/goya.c +8 -4
@@ -798,9 +798,6 @@ int goya_late_init(struct hl_device *hdev)return rc; } -WREG32 (mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR, -GOYA_ASYNC_EVENT_ID_INTS_REGISTER ); -return 0 ; }
@@ -5400,6 +5397,12 @@ static int goya_block_mmap(struct hl_device *hdev, struct vm_area_struct *vma,return -EPERM ; } +static void goya_enable_events_from_fw (struct hl_device *hdev) +{ +WREG32 (mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR, +GOYA_ASYNC_EVENT_ID_INTS_REGISTER ); +} +static const struct hl_asic_funcs goya_funcs = { .early_init = goya_early_init, .early_fini = goya_early_fini,
@@ -5481,7 +5484,8 @@ static const struct hl_asic_funcs goya_funcs = { .descramble_addr = hl_mmu_descramble_addr, .ack_protection_bits_errors = goya_ack_protection_bits_errors, .get_hw_block_id = goya_get_hw_block_id, - .hw_block_mmap = goya_block_mmap + .hw_block_mmap = goya_block_mmap, + .enable_events_from_fw = goya_enable_events_from_fw };/*
Signature · 1 line
2.25.1