Lines Matching +full:u +full:- +full:boot +full:- +full:spl
1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright 2016-2022 HabanaLabs, Ltd.
27 str = strnstr(fw_str, "fw-", VERSION_MAX_LEN); in extract_fw_ver_from_str()
31 /* Skip the fw- part */ in extract_fw_ver_from_str()
33 ver_offset = str - fw_str; in extract_fw_ver_from_str()
36 whitespace = strnstr(str, " ", VERSION_MAX_LEN - ver_offset); in extract_fw_ver_from_str()
40 strscpy(fw_ver, str, whitespace - str + 1); in extract_fw_ver_from_str()
56 strscpy(major, preboot_ver, first_dot - preboot_ver + 1); in extract_fw_sub_versions()
57 rc = kstrtou32(major, 10, &hdev->fw_major_version); in extract_fw_sub_versions()
59 rc = -EINVAL; in extract_fw_sub_versions()
63 dev_err(hdev->dev, "Error %d parsing preboot major version\n", rc); in extract_fw_sub_versions()
72 strscpy(minor, first_dot, second_dot - first_dot + 1); in extract_fw_sub_versions()
73 rc = kstrtou32(minor, 10, &hdev->fw_minor_version); in extract_fw_sub_versions()
75 rc = -EINVAL; in extract_fw_sub_versions()
79 dev_err(hdev->dev, "Error %d parsing preboot minor version\n", rc); in extract_fw_sub_versions()
93 rc = request_firmware(firmware_p, fw_name, hdev->dev); in hl_request_fw()
95 dev_err(hdev->dev, "Firmware file %s is not found! (error %d)\n", in hl_request_fw()
100 fw_size = (*firmware_p)->size; in hl_request_fw()
102 dev_err(hdev->dev, "Illegal %s firmware size %zu\n", in hl_request_fw()
104 rc = -EINVAL; in hl_request_fw()
108 dev_dbg(hdev->dev, "%s firmware size == %zu\n", fw_name, fw_size); in hl_request_fw()
111 dev_err(hdev->dev, in hl_request_fw()
112 "FW file size %zu exceeds maximum of %u bytes\n", in hl_request_fw()
114 rc = -EINVAL; in hl_request_fw()
127 * hl_release_firmware() - release FW
140 * hl_fw_copy_fw_to_device() - copy FW to device
158 size = fw->size; in hl_fw_copy_fw_to_device()
160 if (src_offset + size > fw->size) { in hl_fw_copy_fw_to_device()
161 dev_err(hdev->dev, in hl_fw_copy_fw_to_device()
162 "size to copy(%u) and offset(%u) are invalid\n", in hl_fw_copy_fw_to_device()
164 return -EINVAL; in hl_fw_copy_fw_to_device()
167 fw_data = (const void *) fw->data; in hl_fw_copy_fw_to_device()
174 * hl_fw_copy_msg_to_device() - copy message to device
195 dev_err(hdev->dev, in hl_fw_copy_msg_to_device()
196 "size to copy(%u) and offset(%u) are invalid\n", in hl_fw_copy_msg_to_device()
198 return -EINVAL; in hl_fw_copy_msg_to_device()
209 * hl_fw_load_fw_to_device() - Load F/W code to device's memory.
219 * Return: 0 on success, non-zero for failure.
244 return hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, NULL); in hl_fw_send_pci_access_msg()
250 struct hl_hw_queue *queue = &hdev->kernel_queues[hw_queue_id]; in hl_fw_send_cpu_message()
251 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_fw_send_cpu_message()
260 dev_err(hdev->dev, in hl_fw_send_cpu_message()
262 return -ENOMEM; in hl_fw_send_cpu_message()
267 mutex_lock(&hdev->send_cpu_message_lock); in hl_fw_send_cpu_message()
269 /* CPU-CP messages can be sent during soft-reset */ in hl_fw_send_cpu_message()
270 if (hdev->disabled && !hdev->reset_info.in_compute_reset) { in hl_fw_send_cpu_message()
275 if (hdev->device_cpu_disabled) { in hl_fw_send_cpu_message()
276 rc = -EIO; in hl_fw_send_cpu_message()
281 pkt->fence = cpu_to_le32(UINT_MAX); in hl_fw_send_cpu_message()
282 pi = queue->pi; in hl_fw_send_cpu_message()
292 hl_hw_queue_submit_bd(hdev, queue, hl_queue_inc_ptr(queue->pi), len, pkt_dma_addr); in hl_fw_send_cpu_message()
294 if (prop->fw_app_cpu_boot_dev_sts0 & CPU_BOOT_DEV_STS0_PKT_PI_ACK_EN) in hl_fw_send_cpu_message()
295 expected_ack_val = queue->pi; in hl_fw_send_cpu_message()
299 rc = hl_poll_timeout_memory(hdev, &pkt->fence, tmp, in hl_fw_send_cpu_message()
305 if (rc == -ETIMEDOUT) { in hl_fw_send_cpu_message()
309 if (!hl_device_operational(hdev, NULL) && !hdev->reset_info.in_compute_reset) in hl_fw_send_cpu_message()
310 dev_dbg(hdev->dev, "Device CPU packet timeout (0x%x) due to FW reset\n", in hl_fw_send_cpu_message()
313 dev_err(hdev->dev, "Device CPU packet timeout (0x%x)\n", tmp); in hl_fw_send_cpu_message()
314 hdev->device_cpu_disabled = true; in hl_fw_send_cpu_message()
318 tmp = le32_to_cpu(pkt->ctl); in hl_fw_send_cpu_message()
324 if (!prop->supports_advanced_cpucp_rc) { in hl_fw_send_cpu_message()
325 dev_dbg(hdev->dev, "F/W ERROR %d for CPU packet %d\n", rc, opcode); in hl_fw_send_cpu_message()
331 dev_err(hdev->dev, in hl_fw_send_cpu_message()
335 dev_err(hdev->dev, in hl_fw_send_cpu_message()
339 dev_dbg(hdev->dev, in hl_fw_send_cpu_message()
343 dev_err(hdev->dev, in hl_fw_send_cpu_message()
348 dev_err(hdev->dev, in hl_fw_send_cpu_message()
356 rc = -EIO; in hl_fw_send_cpu_message()
359 *result = le64_to_cpu(pkt->result); in hl_fw_send_cpu_message()
367 sent_bd = queue->kernel_address; in hl_fw_send_cpu_message()
369 sent_bd->ctl = cpu_to_le32(UINT_MAX); in hl_fw_send_cpu_message()
372 mutex_unlock(&hdev->send_cpu_message_lock); in hl_fw_send_cpu_message()
391 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_fw_unmask_irq()
395 dev_err(hdev->dev, "failed to unmask RAZWI IRQ %d", event_type); in hl_fw_unmask_irq()
411 /* data should be aligned to 8 bytes in order to CPU-CP to copy it */ in hl_fw_unmask_irq_arr()
416 dev_err(hdev->dev, "too many elements in IRQ array\n"); in hl_fw_unmask_irq_arr()
417 return -EINVAL; in hl_fw_unmask_irq_arr()
422 return -ENOMEM; in hl_fw_unmask_irq_arr()
424 pkt->length = cpu_to_le32(irq_arr_size / sizeof(irq_arr[0])); in hl_fw_unmask_irq_arr()
425 memcpy(&pkt->irqs, irq_arr, irq_arr_size); in hl_fw_unmask_irq_arr()
427 pkt->cpucp_pkt.ctl = cpu_to_le32(CPUCP_PACKET_UNMASK_RAZWI_IRQ_ARRAY << in hl_fw_unmask_irq_arr()
430 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) pkt, in hl_fw_unmask_irq_arr()
434 dev_err(hdev->dev, "failed to unmask IRQ array\n"); in hl_fw_unmask_irq_arr()
451 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &test_pkt, in hl_fw_test_cpu_queue()
456 dev_err(hdev->dev, in hl_fw_test_cpu_queue()
459 dev_err(hdev->dev, "CPU queue test failed, error %d\n", rc); in hl_fw_test_cpu_queue()
470 kernel_addr = gen_pool_alloc(hdev->cpu_accessible_dma_pool, size); in hl_fw_cpu_accessible_dma_pool_alloc()
472 *dma_handle = hdev->cpu_accessible_dma_address + in hl_fw_cpu_accessible_dma_pool_alloc()
473 (kernel_addr - (u64) (uintptr_t) hdev->cpu_accessible_dma_mem); in hl_fw_cpu_accessible_dma_pool_alloc()
481 gen_pool_free(hdev->cpu_accessible_dma_pool, (u64) (uintptr_t) vaddr, in hl_fw_cpu_accessible_dma_pool_free()
493 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, NULL); in hl_fw_send_device_activity()
495 dev_err(hdev->dev, "failed to send device activity msg(%u)\n", open); in hl_fw_send_device_activity()
511 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &hb_pkt, in hl_fw_send_heartbeat()
515 return -EIO; in hl_fw_send_heartbeat()
519 dev_warn(hdev->dev, "FW reported EQ fault during heartbeat\n"); in hl_fw_send_heartbeat()
520 rc = -EIO; in hl_fw_send_heartbeat()
535 dev_err(hdev->dev, in fw_report_boot_dev0()
536 "Device boot error - DRAM initialization failed\n"); in fw_report_boot_dev0()
541 dev_err(hdev->dev, "Device boot error - FIT image corrupted\n"); in fw_report_boot_dev0()
546 dev_err(hdev->dev, in fw_report_boot_dev0()
547 "Device boot error - Thermal Sensor initialization failed\n"); in fw_report_boot_dev0()
552 if (hdev->bmc_enable) { in fw_report_boot_dev0()
553 dev_err(hdev->dev, in fw_report_boot_dev0()
554 "Device boot error - Skipped waiting for BMC\n"); in fw_report_boot_dev0()
557 dev_info(hdev->dev, in fw_report_boot_dev0()
558 "Device boot message - Skipped waiting for BMC\n"); in fw_report_boot_dev0()
567 dev_err(hdev->dev, in fw_report_boot_dev0()
568 "Device boot error - Serdes data from BMC not available\n"); in fw_report_boot_dev0()
573 dev_err(hdev->dev, in fw_report_boot_dev0()
574 "Device boot error - NIC F/W initialization failed\n"); in fw_report_boot_dev0()
579 dev_err(hdev->dev, in fw_report_boot_dev0()
580 "Device boot warning - security not ready\n"); in fw_report_boot_dev0()
585 dev_err(hdev->dev, "Device boot error - security failure\n"); in fw_report_boot_dev0()
590 dev_err(hdev->dev, "Device boot error - eFuse failure\n"); in fw_report_boot_dev0()
595 dev_err(hdev->dev, "Device boot error - Failed to load preboot secondary image\n"); in fw_report_boot_dev0()
600 dev_err(hdev->dev, "Device boot error - PLL failure\n"); in fw_report_boot_dev0()
606 dev_dbg(hdev->dev, "device unusable status is set\n"); in fw_report_boot_dev0()
611 dev_err(hdev->dev, "Device boot error - binning failure\n"); in fw_report_boot_dev0()
616 dev_dbg(hdev->dev, "Device status0 %#x\n", sts_val); in fw_report_boot_dev0()
620 dev_warn(hdev->dev, in fw_report_boot_dev0()
621 "Device boot warning - EEPROM failure detected, default settings applied\n"); in fw_report_boot_dev0()
629 dev_warn(hdev->dev, in fw_report_boot_dev0()
630 "Device boot warning - Skipped DRAM initialization\n"); in fw_report_boot_dev0()
638 dev_warn(hdev->dev, in fw_report_boot_dev0()
639 "Device boot warning - Failed to load preboot primary image\n"); in fw_report_boot_dev0()
647 dev_warn(hdev->dev, in fw_report_boot_dev0()
648 "Device boot warning - TPM failure\n"); in fw_report_boot_dev0()
656 dev_err(hdev->dev, in fw_report_boot_dev0()
657 "Device boot error - unknown ERR0 error 0x%08x\n", err_val); in fw_report_boot_dev0()
663 lower_32_bits(hdev->boot_error_status_mask))) in fw_report_boot_dev0()
684 dev_dbg(hdev->dev, "Device status1 %#x\n", sts_val); in fw_report_boot_dev1()
687 dev_err(hdev->dev, in fw_report_boot_dev1()
688 "Device boot error - unknown ERR1 error 0x%08x\n", in fw_report_boot_dev1()
695 upper_32_bits(hdev->boot_error_status_mask))) in fw_report_boot_dev1()
714 * that is not an error per-se, but it is an error in production in fw_read_errors()
726 return -EIO; in fw_read_errors()
736 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_fw_cpucp_info_get()
747 dev_err(hdev->dev, in hl_fw_cpucp_info_get()
748 "Failed to allocate DMA memory for CPU-CP info packet\n"); in hl_fw_cpucp_info_get()
749 return -ENOMEM; in hl_fw_cpucp_info_get()
759 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_fw_cpucp_info_get()
762 dev_err(hdev->dev, in hl_fw_cpucp_info_get()
763 "Failed to handle CPU-CP info pkt, error %d\n", rc); in hl_fw_cpucp_info_get()
770 dev_err(hdev->dev, "Errors in device boot\n"); in hl_fw_cpucp_info_get()
774 memcpy(&prop->cpucp_info, cpucp_info_cpu_addr, in hl_fw_cpucp_info_get()
775 sizeof(prop->cpucp_info)); in hl_fw_cpucp_info_get()
777 rc = hl_build_hwmon_channel_info(hdev, prop->cpucp_info.sensors); in hl_fw_cpucp_info_get()
779 dev_err(hdev->dev, in hl_fw_cpucp_info_get()
781 rc = -EFAULT; in hl_fw_cpucp_info_get()
785 kernel_ver = extract_fw_ver_from_str(prop->cpucp_info.kernel_version); in hl_fw_cpucp_info_get()
787 dev_info(hdev->dev, "Linux version %s", kernel_ver); in hl_fw_cpucp_info_get()
792 hdev->event_queue.check_eqe_index = false; in hl_fw_cpucp_info_get()
795 if (prop->fw_cpu_boot_dev_sts0_valid) { in hl_fw_cpucp_info_get()
796 prop->fw_app_cpu_boot_dev_sts0 = RREG32(sts_boot_dev_sts0_reg); in hl_fw_cpucp_info_get()
797 if (prop->fw_app_cpu_boot_dev_sts0 & in hl_fw_cpucp_info_get()
799 hdev->event_queue.check_eqe_index = true; in hl_fw_cpucp_info_get()
802 if (prop->fw_cpu_boot_dev_sts1_valid) in hl_fw_cpucp_info_get()
803 prop->fw_app_cpu_boot_dev_sts1 = RREG32(sts_boot_dev_sts1_reg); in hl_fw_cpucp_info_get()
819 if (!hdev->asic_funcs->get_msi_info) in hl_fw_send_msi_info_msg()
825 /* data should be aligned to 8 bytes in order to CPU-CP to copy it */ in hl_fw_send_msi_info_msg()
830 dev_err(hdev->dev, "CPUCP array data is too big\n"); in hl_fw_send_msi_info_msg()
831 return -EINVAL; in hl_fw_send_msi_info_msg()
836 return -ENOMEM; in hl_fw_send_msi_info_msg()
838 pkt->length = cpu_to_le32(CPUCP_NUM_OF_MSI_TYPES); in hl_fw_send_msi_info_msg()
840 memset((void *) &pkt->data, 0xFF, data_size); in hl_fw_send_msi_info_msg()
841 hdev->asic_funcs->get_msi_info(pkt->data); in hl_fw_send_msi_info_msg()
843 pkt->cpucp_pkt.ctl = cpu_to_le32(CPUCP_PACKET_MSI_INFO_SET << in hl_fw_send_msi_info_msg()
846 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *)pkt, in hl_fw_send_msi_info_msg()
852 * to stop the boot in hl_fw_send_msi_info_msg()
858 dev_err(hdev->dev, "failed to send CPUCP array data\n"); in hl_fw_send_msi_info_msg()
892 dev_err(hdev->dev, in hl_fw_get_eeprom_data()
893 "Failed to allocate DMA memory for CPU-CP EEPROM packet\n"); in hl_fw_get_eeprom_data()
894 return -ENOMEM; in hl_fw_get_eeprom_data()
904 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_fw_get_eeprom_data()
908 dev_err(hdev->dev, in hl_fw_get_eeprom_data()
909 "Failed to handle CPU-CP EEPROM packet, error %d\n", in hl_fw_get_eeprom_data()
937 dev_err(hdev->dev, in hl_fw_get_monitor_dump()
938 "Failed to allocate DMA memory for CPU-CP monitor-dump packet\n"); in hl_fw_get_monitor_dump()
939 return -ENOMEM; in hl_fw_get_monitor_dump()
948 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_fw_get_monitor_dump()
951 dev_err(hdev->dev, "Failed to handle CPU-CP monitor-dump packet, error %d\n", rc); in hl_fw_get_monitor_dump()
982 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_fw_cpucp_pci_counters_get()
985 dev_err(hdev->dev, in hl_fw_cpucp_pci_counters_get()
986 "Failed to handle CPU-CP PCI info pkt, error %d\n", rc); in hl_fw_cpucp_pci_counters_get()
989 counters->rx_throughput = result; in hl_fw_cpucp_pci_counters_get()
997 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_fw_cpucp_pci_counters_get()
1000 dev_err(hdev->dev, in hl_fw_cpucp_pci_counters_get()
1001 "Failed to handle CPU-CP PCI info pkt, error %d\n", rc); in hl_fw_cpucp_pci_counters_get()
1004 counters->tx_throughput = result; in hl_fw_cpucp_pci_counters_get()
1011 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_fw_cpucp_pci_counters_get()
1014 dev_err(hdev->dev, in hl_fw_cpucp_pci_counters_get()
1015 "Failed to handle CPU-CP PCI info pkt, error %d\n", rc); in hl_fw_cpucp_pci_counters_get()
1018 counters->replay_cnt = (u32) result; in hl_fw_cpucp_pci_counters_get()
1032 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_fw_cpucp_total_energy_get()
1035 dev_err(hdev->dev, in hl_fw_cpucp_total_energy_get()
1049 struct asic_fixed_properties *prop = &hdev->asic_prop; in get_used_pll_index()
1054 dynamic_pll = !!(prop->fw_app_cpu_boot_dev_sts0 & in get_used_pll_index()
1070 fw_pll_idx = hdev->asic_funcs->map_pll_idx_to_fw_idx(input_pll_index); in get_used_pll_index()
1072 dev_err(hdev->dev, "Invalid PLL index (%u) error %d\n", in get_used_pll_index()
1074 return -EINVAL; in get_used_pll_index()
1078 pll_byte = prop->cpucp_info.pll_map[fw_pll_idx >> 3]; in get_used_pll_index()
1082 dev_err(hdev->dev, "PLL index %d is not supported\n", in get_used_pll_index()
1084 return -EINVAL; in get_used_pll_index()
1110 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_fw_cpucp_pll_info_get()
1113 dev_err(hdev->dev, "Failed to read PLL info, error %d\n", rc); in hl_fw_cpucp_pll_info_get()
1137 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_fw_cpucp_power_get()
1140 dev_err(hdev->dev, "Failed to read power, error %d\n", rc); in hl_fw_cpucp_power_get()
1162 dev_err(hdev->dev, in hl_fw_dram_replaced_row_get()
1163 "Failed to allocate DMA memory for CPU-CP replaced rows info packet\n"); in hl_fw_dram_replaced_row_get()
1164 return -ENOMEM; in hl_fw_dram_replaced_row_get()
1174 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_fw_dram_replaced_row_get()
1177 dev_err(hdev->dev, in hl_fw_dram_replaced_row_get()
1178 "Failed to handle CPU-CP replaced rows info pkt, error %d\n", rc); in hl_fw_dram_replaced_row_get()
1201 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, &result); in hl_fw_dram_pending_row_get()
1203 dev_err(hdev->dev, in hl_fw_dram_pending_row_get()
1204 "Failed to handle CPU-CP pending rows info pkt, error %d\n", rc); in hl_fw_dram_pending_row_get()
1223 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_fw_cpucp_engine_core_asid_set()
1226 dev_err(hdev->dev, in hl_fw_cpucp_engine_core_asid_set()
1236 &hdev->fw_loader.static_loader; in hl_fw_ask_hard_reset_without_linux()
1239 if (hdev->asic_prop.dynamic_fw_load) { in hl_fw_ask_hard_reset_without_linux()
1240 rc = hl_fw_dynamic_send_protocol_cmd(hdev, &hdev->fw_loader, in hl_fw_ask_hard_reset_without_linux()
1242 hdev->fw_loader.cpu_timeout); in hl_fw_ask_hard_reset_without_linux()
1244 dev_warn(hdev->dev, "Failed sending COMMS_RST_DEV\n"); in hl_fw_ask_hard_reset_without_linux()
1246 WREG32(static_loader->kmd_msg_to_cpu_reg, KMD_MSG_RST_DEV); in hl_fw_ask_hard_reset_without_linux()
1253 &hdev->fw_loader.static_loader; in hl_fw_ask_halt_machine_without_linux()
1256 if (hdev->device_cpu_is_halted) in hl_fw_ask_halt_machine_without_linux()
1260 if (hdev->asic_prop.dynamic_fw_load) { in hl_fw_ask_halt_machine_without_linux()
1261 rc = hl_fw_dynamic_send_protocol_cmd(hdev, &hdev->fw_loader, in hl_fw_ask_halt_machine_without_linux()
1263 hdev->fw_loader.cpu_timeout); in hl_fw_ask_halt_machine_without_linux()
1265 dev_warn(hdev->dev, "Failed sending COMMS_GOTO_WFE\n"); in hl_fw_ask_halt_machine_without_linux()
1267 WREG32(static_loader->kmd_msg_to_cpu_reg, KMD_MSG_GOTO_WFE); in hl_fw_ask_halt_machine_without_linux()
1268 msleep(static_loader->cpu_reset_wait_msec); in hl_fw_ask_halt_machine_without_linux()
1273 WREG32(static_loader->kmd_msg_to_cpu_reg, KMD_MSG_NA); in hl_fw_ask_halt_machine_without_linux()
1276 hdev->device_cpu_is_halted = true; in hl_fw_ask_halt_machine_without_linux()
1286 dev_err(hdev->dev, in detect_cpu_boot_status()
1287 "Device boot progress - BTL/ROM did NOT run\n"); in detect_cpu_boot_status()
1290 dev_err(hdev->dev, in detect_cpu_boot_status()
1291 "Device boot progress - Stuck inside WFE loop\n"); in detect_cpu_boot_status()
1294 dev_err(hdev->dev, in detect_cpu_boot_status()
1295 "Device boot progress - Stuck in BTL\n"); in detect_cpu_boot_status()
1298 dev_err(hdev->dev, in detect_cpu_boot_status()
1299 "Device boot progress - Stuck in Preboot\n"); in detect_cpu_boot_status()
1302 dev_err(hdev->dev, in detect_cpu_boot_status()
1303 "Device boot progress - Stuck in SPL\n"); in detect_cpu_boot_status()
1306 dev_err(hdev->dev, in detect_cpu_boot_status()
1307 "Device boot progress - Stuck in u-boot\n"); in detect_cpu_boot_status()
1310 dev_err(hdev->dev, in detect_cpu_boot_status()
1311 "Device boot progress - DRAM initialization failed\n"); in detect_cpu_boot_status()
1314 dev_err(hdev->dev, in detect_cpu_boot_status()
1315 "Device boot progress - Cannot boot\n"); in detect_cpu_boot_status()
1318 dev_err(hdev->dev, in detect_cpu_boot_status()
1319 "Device boot progress - Thermal Sensor initialization failed\n"); in detect_cpu_boot_status()
1322 dev_err(hdev->dev, in detect_cpu_boot_status()
1323 "Device boot progress - Stuck in preboot after security initialization\n"); in detect_cpu_boot_status()
1326 dev_err(hdev->dev, in detect_cpu_boot_status()
1327 "Device boot progress - Invalid status code %d\n", in detect_cpu_boot_status()
1335 struct pre_fw_load_props *pre_fw_load = &hdev->fw_loader.pre_fw_load; in hl_fw_wait_preboot_ready()
1341 * CPU_BOOT_STATUS_WAITING_FOR_BOOT_FIT - for newer firmwares where in hl_fw_wait_preboot_ready()
1342 * the preboot is waiting for the boot fit in hl_fw_wait_preboot_ready()
1344 * All other status values - for older firmwares where the uboot was in hl_fw_wait_preboot_ready()
1349 pre_fw_load->cpu_boot_status_reg, in hl_fw_wait_preboot_ready()
1354 hdev->fw_poll_interval_usec, in hl_fw_wait_preboot_ready()
1355 pre_fw_load->wait_for_preboot_timeout); in hl_fw_wait_preboot_ready()
1358 dev_err(hdev->dev, "CPU boot ready status timeout\n"); in hl_fw_wait_preboot_ready()
1364 if (status != -1) in hl_fw_wait_preboot_ready()
1365 fw_read_errors(hdev, pre_fw_load->boot_err0_reg, in hl_fw_wait_preboot_ready()
1366 pre_fw_load->boot_err1_reg, in hl_fw_wait_preboot_ready()
1367 pre_fw_load->sts_boot_dev_sts0_reg, in hl_fw_wait_preboot_ready()
1368 pre_fw_load->sts_boot_dev_sts1_reg); in hl_fw_wait_preboot_ready()
1369 return -EIO; in hl_fw_wait_preboot_ready()
1372 hdev->fw_loader.fw_comp_loaded |= FW_TYPE_PREBOOT_CPU; in hl_fw_wait_preboot_ready()
1384 prop = &hdev->asic_prop; in hl_fw_read_preboot_caps()
1385 pre_fw_load = &hdev->fw_loader.pre_fw_load; in hl_fw_read_preboot_caps()
1398 * In case it is not enabled the stored value will be left 0- all in hl_fw_read_preboot_caps()
1401 reg_val = RREG32(pre_fw_load->sts_boot_dev_sts0_reg); in hl_fw_read_preboot_caps()
1403 prop->fw_cpu_boot_dev_sts0_valid = true; in hl_fw_read_preboot_caps()
1404 prop->fw_preboot_cpu_boot_dev_sts0 = reg_val; in hl_fw_read_preboot_caps()
1407 reg_val = RREG32(pre_fw_load->sts_boot_dev_sts1_reg); in hl_fw_read_preboot_caps()
1409 prop->fw_cpu_boot_dev_sts1_valid = true; in hl_fw_read_preboot_caps()
1410 prop->fw_preboot_cpu_boot_dev_sts1 = reg_val; in hl_fw_read_preboot_caps()
1413 prop->dynamic_fw_load = !!(prop->fw_preboot_cpu_boot_dev_sts0 & in hl_fw_read_preboot_caps()
1417 hdev->asic_funcs->init_firmware_loader(hdev); in hl_fw_read_preboot_caps()
1419 dev_dbg(hdev->dev, "Attempting %s FW load\n", in hl_fw_read_preboot_caps()
1420 prop->dynamic_fw_load ? "dynamic" : "legacy"); in hl_fw_read_preboot_caps()
1427 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_fw_static_read_device_fw_version()
1428 struct fw_load_mgr *fw_loader = &hdev->fw_loader; in hl_fw_static_read_device_fw_version()
1435 static_loader = &hdev->fw_loader.static_loader; in hl_fw_static_read_device_fw_version()
1439 ver_off = RREG32(static_loader->boot_fit_version_offset_reg); in hl_fw_static_read_device_fw_version()
1440 dest = prop->uboot_ver; in hl_fw_static_read_device_fw_version()
1441 name = "Boot-fit"; in hl_fw_static_read_device_fw_version()
1442 limit = static_loader->boot_fit_version_max_off; in hl_fw_static_read_device_fw_version()
1445 ver_off = RREG32(static_loader->preboot_version_offset_reg); in hl_fw_static_read_device_fw_version()
1446 dest = prop->preboot_ver; in hl_fw_static_read_device_fw_version()
1448 limit = static_loader->preboot_version_max_off; in hl_fw_static_read_device_fw_version()
1451 dev_warn(hdev->dev, "Undefined FW component: %d\n", fwc); in hl_fw_static_read_device_fw_version()
1452 return -EIO; in hl_fw_static_read_device_fw_version()
1455 ver_off &= static_loader->sram_offset_mask; in hl_fw_static_read_device_fw_version()
1459 hdev->pcie_bar[fw_loader->sram_bar_id] + ver_off, in hl_fw_static_read_device_fw_version()
1462 dev_err(hdev->dev, "%s version offset (0x%x) is above SRAM\n", in hl_fw_static_read_device_fw_version()
1465 return -EIO; in hl_fw_static_read_device_fw_version()
1469 boot_ver = extract_fw_ver_from_str(prop->uboot_ver); in hl_fw_static_read_device_fw_version()
1471 dev_info(hdev->dev, "boot-fit version %s\n", boot_ver); in hl_fw_static_read_device_fw_version()
1475 preboot_ver = strnstr(prop->preboot_ver, "Preboot", in hl_fw_static_read_device_fw_version()
1477 if (preboot_ver && preboot_ver != prop->preboot_ver) { in hl_fw_static_read_device_fw_version()
1478 strscpy(btl_ver, prop->preboot_ver, in hl_fw_static_read_device_fw_version()
1479 min((int) (preboot_ver - prop->preboot_ver), in hl_fw_static_read_device_fw_version()
1481 dev_info(hdev->dev, "%s\n", btl_ver); in hl_fw_static_read_device_fw_version()
1484 preboot_ver = extract_fw_ver_from_str(prop->preboot_ver); in hl_fw_static_read_device_fw_version()
1486 dev_info(hdev->dev, "preboot version %s\n", in hl_fw_static_read_device_fw_version()
1496 * hl_fw_preboot_update_state - update internal data structures during
1502 * @return 0 on success, otherwise non-zero error code
1506 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_fw_preboot_update_state()
1509 cpu_boot_dev_sts0 = prop->fw_preboot_cpu_boot_dev_sts0; in hl_fw_preboot_update_state()
1510 cpu_boot_dev_sts1 = prop->fw_preboot_cpu_boot_dev_sts1; in hl_fw_preboot_update_state()
1512 /* We read boot_dev_sts registers multiple times during boot: in hl_fw_preboot_update_state()
1513 * 1. preboot - a. Check whether the security status bits are valid in hl_fw_preboot_update_state()
1516 * 2. boot cpu - a. Fetch boot cpu security status in hl_fw_preboot_update_state()
1517 * b. Check whether hard reset is done by boot cpu in hl_fw_preboot_update_state()
1518 * 3. FW application - a. Fetch fw application security status in hl_fw_preboot_update_state()
1521 prop->hard_reset_done_by_fw = !!(cpu_boot_dev_sts0 & CPU_BOOT_DEV_STS0_FW_HARD_RST_EN); in hl_fw_preboot_update_state()
1523 prop->fw_security_enabled = !!(cpu_boot_dev_sts0 & CPU_BOOT_DEV_STS0_SECURITY_EN); in hl_fw_preboot_update_state()
1525 dev_dbg(hdev->dev, "Firmware preboot boot device status0 %#x\n", in hl_fw_preboot_update_state()
1528 dev_dbg(hdev->dev, "Firmware preboot boot device status1 %#x\n", in hl_fw_preboot_update_state()
1531 dev_dbg(hdev->dev, "Firmware preboot hard-reset is %s\n", in hl_fw_preboot_update_state()
1532 prop->hard_reset_done_by_fw ? "enabled" : "disabled"); in hl_fw_preboot_update_state()
1534 dev_dbg(hdev->dev, "firmware-level security is %s\n", in hl_fw_preboot_update_state()
1535 prop->fw_security_enabled ? "enabled" : "disabled"); in hl_fw_preboot_update_state()
1537 dev_dbg(hdev->dev, "GIC controller is %s\n", in hl_fw_preboot_update_state()
1538 prop->gic_interrupts_enable ? "enabled" : "disabled"); in hl_fw_preboot_update_state()
1556 if (!(hdev->fw_components & FW_TYPE_PREBOOT_CPU)) in hl_fw_read_preboot_status()
1559 /* get FW pre-load parameters */ in hl_fw_read_preboot_status()
1560 hdev->asic_funcs->init_firmware_preload_params(hdev); in hl_fw_read_preboot_status()
1563 * In order to determine boot method (static VS dynamic) we need to in hl_fw_read_preboot_status()
1564 * read the boot caps register in hl_fw_read_preboot_status()
1573 if (hdev->asic_prop.dynamic_fw_load) in hl_fw_read_preboot_status()
1590 * hl_fw_dynamic_report_error_status - report error status
1604 dev_err(hdev->dev, "Device status %s, expected status: %s\n", in hl_fw_dynamic_report_error_status()
1608 dev_err(hdev->dev, "Device status unknown %d, expected status: %s\n", in hl_fw_dynamic_report_error_status()
1614 * hl_fw_dynamic_send_cmd - send LKD to FW cmd
1625 * to be allocated by the FW to receive the next boot component.
1634 dyn_regs = &fw_loader->dynamic_loader.comm_desc.cpu_dyn_regs; in hl_fw_dynamic_send_cmd()
1639 WREG32(le32_to_cpu(dyn_regs->kmd_msg_to_cpu), val); in hl_fw_dynamic_send_cmd()
1643 * hl_fw_dynamic_extract_fw_response - update the FW response
1650 * @return 0 on success, otherwise non-zero error code
1657 response->status = FIELD_GET(COMMS_STATUS_STATUS_MASK, status); in hl_fw_dynamic_extract_fw_response()
1658 response->ram_offset = FIELD_GET(COMMS_STATUS_OFFSET_MASK, status) << in hl_fw_dynamic_extract_fw_response()
1660 response->ram_type = FIELD_GET(COMMS_STATUS_RAM_TYPE_MASK, status); in hl_fw_dynamic_extract_fw_response()
1662 if ((response->ram_type != COMMS_SRAM) && in hl_fw_dynamic_extract_fw_response()
1663 (response->ram_type != COMMS_DRAM)) { in hl_fw_dynamic_extract_fw_response()
1664 dev_err(hdev->dev, "FW status: invalid RAM type %u\n", in hl_fw_dynamic_extract_fw_response()
1665 response->ram_type); in hl_fw_dynamic_extract_fw_response()
1666 return -EIO; in hl_fw_dynamic_extract_fw_response()
1673 * hl_fw_dynamic_wait_for_status - wait for status in dynamic FW load
1680 * @return 0 on success, otherwise non-zero error code
1694 dyn_regs = &fw_loader->dynamic_loader.comm_desc.cpu_dyn_regs; in hl_fw_dynamic_wait_for_status()
1699 le32_to_cpu(dyn_regs->cpu_cmd_status_to_host), in hl_fw_dynamic_wait_for_status()
1702 hdev->fw_comms_poll_interval_usec, in hl_fw_dynamic_wait_for_status()
1708 return -EIO; in hl_fw_dynamic_wait_for_status()
1719 &fw_loader->dynamic_loader.response, in hl_fw_dynamic_wait_for_status()
1725 * hl_fw_dynamic_send_clear_cmd - send clear command to FW
1730 * @return 0 on success, otherwise non-zero error code
1744 fw_loader->cpu_timeout); in hl_fw_dynamic_send_clear_cmd()
1748 * hl_fw_dynamic_send_protocol_cmd - send LKD to FW cmd and wait for ACK
1757 * @return 0 on success, otherwise non-zero error code
1761 * - send clear (clear command and verify clear status register)
1762 * - send the actual protocol command
1763 * - wait for ACK on the protocol command
1764 * - send clear
1765 * - send NOOP
1767 * - wait for OK
1768 * - send clear
1769 * - send NOOP
1823 * hl_fw_compat_crc32 - CRC compatible with FW
1841 * hl_fw_dynamic_validate_memory_bound - validate memory bounds for memory
1850 * @return 0 on success, otherwise non-zero error code
1860 if (end_addr >= region->region_base + region->region_size) { in hl_fw_dynamic_validate_memory_bound()
1861 dev_err(hdev->dev, in hl_fw_dynamic_validate_memory_bound()
1864 return -EIO; in hl_fw_dynamic_validate_memory_bound()
1872 if (end_addr >= region->region_base - region->offset_in_bar + in hl_fw_dynamic_validate_memory_bound()
1873 region->bar_size) { in hl_fw_dynamic_validate_memory_bound()
1874 dev_err(hdev->dev, in hl_fw_dynamic_validate_memory_bound()
1876 return -EIO; in hl_fw_dynamic_validate_memory_bound()
1883 * hl_fw_dynamic_validate_descriptor - validate FW descriptor
1889 * @return 0 on success, otherwise non-zero error code
1903 if (le32_to_cpu(fw_desc->header.magic) != HL_COMMS_DESC_MAGIC) in hl_fw_dynamic_validate_descriptor()
1904 dev_warn(hdev->dev, "Invalid magic for dynamic FW descriptor (%x)\n", in hl_fw_dynamic_validate_descriptor()
1905 fw_desc->header.magic); in hl_fw_dynamic_validate_descriptor()
1907 if (fw_desc->header.version != HL_COMMS_DESC_VER) in hl_fw_dynamic_validate_descriptor()
1908 dev_warn(hdev->dev, "Invalid version for dynamic FW descriptor (%x)\n", in hl_fw_dynamic_validate_descriptor()
1909 fw_desc->header.version); in hl_fw_dynamic_validate_descriptor()
1919 data_size = le16_to_cpu(fw_desc->header.size); in hl_fw_dynamic_validate_descriptor()
1922 if (data_crc32 != le32_to_cpu(fw_desc->header.crc32)) { in hl_fw_dynamic_validate_descriptor()
1923 dev_err(hdev->dev, "CRC32 mismatch for dynamic FW descriptor (%x:%x)\n", in hl_fw_dynamic_validate_descriptor()
1924 data_crc32, fw_desc->header.crc32); in hl_fw_dynamic_validate_descriptor()
1925 return -EIO; in hl_fw_dynamic_validate_descriptor()
1929 addr = le64_to_cpu(fw_desc->img_addr); in hl_fw_dynamic_validate_descriptor()
1932 dev_err(hdev->dev, "Invalid region to copy FW image address=%llx\n", addr); in hl_fw_dynamic_validate_descriptor()
1933 return -EIO; in hl_fw_dynamic_validate_descriptor()
1936 region = &hdev->pci_mem_region[region_id]; in hl_fw_dynamic_validate_descriptor()
1939 fw_loader->dynamic_loader.image_region = region; in hl_fw_dynamic_validate_descriptor()
1946 fw_loader->dynamic_loader.fw_image_size, in hl_fw_dynamic_validate_descriptor()
1949 dev_err(hdev->dev, "invalid mem transfer request for FW image\n"); in hl_fw_dynamic_validate_descriptor()
1954 fw_loader->dynamic_loader.fw_desc_valid = true; in hl_fw_dynamic_validate_descriptor()
1966 device_addr = region->region_base + response->ram_offset; in hl_fw_dynamic_validate_response()
1971 * type- testing only the end address is enough in hl_fw_dynamic_validate_response()
1980 * hl_fw_dynamic_read_and_validate_descriptor - read and validate FW descriptor
1985 * @return 0 on success, otherwise non-zero error code
1997 fw_desc = &fw_loader->dynamic_loader.comm_desc; in hl_fw_dynamic_read_and_validate_descriptor()
1998 response = &fw_loader->dynamic_loader.response; in hl_fw_dynamic_read_and_validate_descriptor()
2000 region_id = (response->ram_type == COMMS_SRAM) ? in hl_fw_dynamic_read_and_validate_descriptor()
2003 region = &hdev->pci_mem_region[region_id]; in hl_fw_dynamic_read_and_validate_descriptor()
2007 dev_err(hdev->dev, in hl_fw_dynamic_read_and_validate_descriptor()
2014 * in addition, as the descriptor value is going to be over-ridden by new data- we mark it in hl_fw_dynamic_read_and_validate_descriptor()
2018 fw_loader->dynamic_loader.fw_desc_valid = false; in hl_fw_dynamic_read_and_validate_descriptor()
2019 src = hdev->pcie_bar[region->bar_id] + region->offset_in_bar + in hl_fw_dynamic_read_and_validate_descriptor()
2020 response->ram_offset; in hl_fw_dynamic_read_and_validate_descriptor()
2027 * hl_fw_dynamic_request_descriptor - handshake with CPU to get FW descriptor
2033 * @return 0 on success, otherwise non-zero error code
2043 fw_loader->cpu_timeout); in hl_fw_dynamic_request_descriptor()
2051 * hl_fw_dynamic_read_device_fw_version - read FW version to exposed properties
2061 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_fw_dynamic_read_device_fw_version()
2067 strscpy(prop->uboot_ver, fw_version, VERSION_MAX_LEN); in hl_fw_dynamic_read_device_fw_version()
2068 boot_ver = extract_fw_ver_from_str(prop->uboot_ver); in hl_fw_dynamic_read_device_fw_version()
2070 dev_info(hdev->dev, "boot-fit version %s\n", boot_ver); in hl_fw_dynamic_read_device_fw_version()
2076 strscpy(prop->preboot_ver, fw_version, VERSION_MAX_LEN); in hl_fw_dynamic_read_device_fw_version()
2077 preboot_ver = strnstr(prop->preboot_ver, "Preboot", in hl_fw_dynamic_read_device_fw_version()
2079 if (preboot_ver && preboot_ver != prop->preboot_ver) { in hl_fw_dynamic_read_device_fw_version()
2080 strscpy(btl_ver, prop->preboot_ver, in hl_fw_dynamic_read_device_fw_version()
2081 min((int) (preboot_ver - prop->preboot_ver), 31)); in hl_fw_dynamic_read_device_fw_version()
2082 dev_info(hdev->dev, "%s\n", btl_ver); in hl_fw_dynamic_read_device_fw_version()
2085 preboot_ver = extract_fw_ver_from_str(prop->preboot_ver); in hl_fw_dynamic_read_device_fw_version()
2089 dev_info(hdev->dev, "preboot version %s\n", preboot_ver); in hl_fw_dynamic_read_device_fw_version()
2099 dev_warn(hdev->dev, "Undefined FW component: %d\n", fwc); in hl_fw_dynamic_read_device_fw_version()
2100 return -EINVAL; in hl_fw_dynamic_read_device_fw_version()
2107 * hl_fw_dynamic_copy_image - copy image to memory allocated by the FW
2123 fw_desc = &fw_loader->dynamic_loader.comm_desc; in hl_fw_dynamic_copy_image()
2124 addr = le64_to_cpu(fw_desc->img_addr); in hl_fw_dynamic_copy_image()
2127 region = fw_loader->dynamic_loader.image_region; in hl_fw_dynamic_copy_image()
2129 dest = hdev->pcie_bar[region->bar_id] + region->offset_in_bar + in hl_fw_dynamic_copy_image()
2130 (addr - region->region_base); in hl_fw_dynamic_copy_image()
2133 fw_loader->boot_fit_img.src_off, in hl_fw_dynamic_copy_image()
2134 fw_loader->boot_fit_img.copy_size); in hl_fw_dynamic_copy_image()
2140 * hl_fw_dynamic_copy_msg - copy msg to memory allocated by the FW
2155 fw_desc = &fw_loader->dynamic_loader.comm_desc; in hl_fw_dynamic_copy_msg()
2156 addr = le64_to_cpu(fw_desc->img_addr); in hl_fw_dynamic_copy_msg()
2159 region = fw_loader->dynamic_loader.image_region; in hl_fw_dynamic_copy_msg()
2161 dest = hdev->pcie_bar[region->bar_id] + region->offset_in_bar + in hl_fw_dynamic_copy_msg()
2162 (addr - region->region_base); in hl_fw_dynamic_copy_msg()
2170 * hl_fw_boot_fit_update_state - update internal data structures after boot-fit
2174 * @cpu_boot_dev_sts0_reg: register holding CPU boot dev status 0
2175 * @cpu_boot_dev_sts1_reg: register holding CPU boot dev status 1
2177 * @return 0 on success, otherwise non-zero error code
2183 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_fw_boot_fit_update_state()
2185 hdev->fw_loader.fw_comp_loaded |= FW_TYPE_BOOT_CPU; in hl_fw_boot_fit_update_state()
2188 if (prop->fw_preboot_cpu_boot_dev_sts0 & CPU_BOOT_DEV_STS0_ENABLED) { in hl_fw_boot_fit_update_state()
2189 prop->fw_bootfit_cpu_boot_dev_sts0 = in hl_fw_boot_fit_update_state()
2192 prop->hard_reset_done_by_fw = !!(prop->fw_bootfit_cpu_boot_dev_sts0 & in hl_fw_boot_fit_update_state()
2195 dev_dbg(hdev->dev, "Firmware boot CPU status0 %#x\n", in hl_fw_boot_fit_update_state()
2196 prop->fw_bootfit_cpu_boot_dev_sts0); in hl_fw_boot_fit_update_state()
2199 if (prop->fw_cpu_boot_dev_sts1_valid) { in hl_fw_boot_fit_update_state()
2200 prop->fw_bootfit_cpu_boot_dev_sts1 = in hl_fw_boot_fit_update_state()
2203 dev_dbg(hdev->dev, "Firmware boot CPU status1 %#x\n", in hl_fw_boot_fit_update_state()
2204 prop->fw_bootfit_cpu_boot_dev_sts1); in hl_fw_boot_fit_update_state()
2207 dev_dbg(hdev->dev, "Firmware boot CPU hard-reset is %s\n", in hl_fw_boot_fit_update_state()
2208 prop->hard_reset_done_by_fw ? "enabled" : "disabled"); in hl_fw_boot_fit_update_state()
2214 &hdev->fw_loader.dynamic_loader.comm_desc.cpu_dyn_regs; in hl_fw_dynamic_update_linux_interrupt_if()
2219 if (!hdev->asic_prop.gic_interrupts_enable && in hl_fw_dynamic_update_linux_interrupt_if()
2220 !(hdev->asic_prop.fw_app_cpu_boot_dev_sts0 & in hl_fw_dynamic_update_linux_interrupt_if()
2222 dyn_regs->gic_host_halt_irq = dyn_regs->gic_host_pi_upd_irq; in hl_fw_dynamic_update_linux_interrupt_if()
2223 dyn_regs->gic_host_ints_irq = dyn_regs->gic_host_pi_upd_irq; in hl_fw_dynamic_update_linux_interrupt_if()
2225 dev_warn(hdev->dev, in hl_fw_dynamic_update_linux_interrupt_if()
2230 * hl_fw_dynamic_load_image - load FW image using dynamic protocol
2237 * @return 0 on success, otherwise non-zero error code
2251 * 1. current FW component is preboot and we want to load boot-fit in hl_fw_dynamic_load_image()
2252 * 2. current FW component is boot-fit and we want to load linux in hl_fw_dynamic_load_image()
2256 fw_name = fw_loader->boot_fit_img.image_name; in hl_fw_dynamic_load_image()
2259 fw_name = fw_loader->linux_img.image_name; in hl_fw_dynamic_load_image()
2268 fw_loader->dynamic_loader.fw_image_size = fw->size; in hl_fw_dynamic_load_image()
2270 rc = hl_fw_dynamic_request_descriptor(hdev, fw_loader, fw->size); in hl_fw_dynamic_load_image()
2276 fw_loader->dynamic_loader.comm_desc.cur_fw_ver); in hl_fw_dynamic_load_image()
2280 /* update state according to boot stage */ in hl_fw_dynamic_load_image()
2284 dyn_regs = &fw_loader->dynamic_loader.comm_desc.cpu_dyn_regs; in hl_fw_dynamic_load_image()
2286 le32_to_cpu(dyn_regs->cpu_boot_dev_sts0), in hl_fw_dynamic_load_image()
2287 le32_to_cpu(dyn_regs->cpu_boot_dev_sts1)); in hl_fw_dynamic_load_image()
2290 /* copy boot fit to space allocated by FW */ in hl_fw_dynamic_load_image()
2297 fw_loader->cpu_timeout); in hl_fw_dynamic_load_image()
2317 dyn_loader = &fw_loader->dynamic_loader; in hl_fw_dynamic_wait_for_boot_fit_active()
2320 * Make sure CPU boot-loader is running in hl_fw_dynamic_wait_for_boot_fit_active()
2329 le32_to_cpu(dyn_loader->comm_desc.cpu_dyn_regs.cpu_boot_status), in hl_fw_dynamic_wait_for_boot_fit_active()
2333 hdev->fw_poll_interval_usec, in hl_fw_dynamic_wait_for_boot_fit_active()
2334 dyn_loader->wait_for_bl_timeout); in hl_fw_dynamic_wait_for_boot_fit_active()
2336 dev_err(hdev->dev, "failed to wait for boot\n"); in hl_fw_dynamic_wait_for_boot_fit_active()
2340 dev_dbg(hdev->dev, "uboot status = %d\n", status); in hl_fw_dynamic_wait_for_boot_fit_active()
2351 dyn_loader = &fw_loader->dynamic_loader; in hl_fw_dynamic_wait_for_linux_active()
2357 le32_to_cpu(dyn_loader->comm_desc.cpu_dyn_regs.cpu_boot_status), in hl_fw_dynamic_wait_for_linux_active()
2360 hdev->fw_poll_interval_usec, in hl_fw_dynamic_wait_for_linux_active()
2361 fw_loader->cpu_timeout); in hl_fw_dynamic_wait_for_linux_active()
2363 dev_err(hdev->dev, "failed to wait for Linux\n"); in hl_fw_dynamic_wait_for_linux_active()
2367 dev_dbg(hdev->dev, "Boot status = %d\n", status); in hl_fw_dynamic_wait_for_linux_active()
2372 * hl_fw_linux_update_state - update internal data structures after Linux
2375 * of two stages - loading kernel (SRAM_AVAIL)
2377 * Therefore reading boot device status in any of
2381 * @cpu_boot_dev_sts0_reg: register holding CPU boot dev status 0
2382 * @cpu_boot_dev_sts1_reg: register holding CPU boot dev status 1
2384 * @return 0 on success, otherwise non-zero error code
2390 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_fw_linux_update_state()
2392 hdev->fw_loader.fw_comp_loaded |= FW_TYPE_LINUX; in hl_fw_linux_update_state()
2395 if (prop->fw_cpu_boot_dev_sts0_valid) { in hl_fw_linux_update_state()
2396 prop->fw_app_cpu_boot_dev_sts0 = RREG32(cpu_boot_dev_sts0_reg); in hl_fw_linux_update_state()
2398 prop->hard_reset_done_by_fw = !!(prop->fw_app_cpu_boot_dev_sts0 & in hl_fw_linux_update_state()
2401 if (prop->fw_app_cpu_boot_dev_sts0 & in hl_fw_linux_update_state()
2403 prop->gic_interrupts_enable = false; in hl_fw_linux_update_state()
2405 dev_dbg(hdev->dev, in hl_fw_linux_update_state()
2407 prop->fw_app_cpu_boot_dev_sts0); in hl_fw_linux_update_state()
2409 dev_dbg(hdev->dev, "GIC controller is %s\n", in hl_fw_linux_update_state()
2410 prop->gic_interrupts_enable ? in hl_fw_linux_update_state()
2414 if (prop->fw_cpu_boot_dev_sts1_valid) { in hl_fw_linux_update_state()
2415 prop->fw_app_cpu_boot_dev_sts1 = RREG32(cpu_boot_dev_sts1_reg); in hl_fw_linux_update_state()
2417 dev_dbg(hdev->dev, in hl_fw_linux_update_state()
2419 prop->fw_app_cpu_boot_dev_sts1); in hl_fw_linux_update_state()
2422 dev_dbg(hdev->dev, "Firmware application CPU hard-reset is %s\n", in hl_fw_linux_update_state()
2423 prop->hard_reset_done_by_fw ? "enabled" : "disabled"); in hl_fw_linux_update_state()
2425 dev_info(hdev->dev, "Successfully loaded firmware to device\n"); in hl_fw_linux_update_state()
2429 * hl_fw_dynamic_send_msg - send a COMMS message with attached data
2436 * @return 0 on success, otherwise non-zero error code
2457 dev_err(hdev->dev, in hl_fw_dynamic_send_msg()
2458 "Send COMMS message - invalid message type %u\n", in hl_fw_dynamic_send_msg()
2460 return -EINVAL; in hl_fw_dynamic_send_msg()
2475 fw_loader->cpu_timeout); in hl_fw_dynamic_send_msg()
2481 fw_loader->cpu_timeout); in hl_fw_dynamic_send_msg()
2489 * hl_fw_dynamic_init_cpu - initialize the device CPU using dynamic protocol
2494 * @return 0 on success, otherwise non-zero error code
2498 * - LKD command register
2499 * - FW status register
2503 * in case of timeout expiration without the desired status from FW- the
2504 * protocol (and hence the boot) will fail.
2512 dev_info(hdev->dev, in hl_fw_dynamic_init_cpu()
2514 hdev->asic_prop.fw_security_enabled ? "secured " : ""); in hl_fw_dynamic_init_cpu()
2517 fw_loader->dynamic_loader.fw_desc_valid = false; in hl_fw_dynamic_init_cpu()
2523 dyn_regs = &fw_loader->dynamic_loader.comm_desc.cpu_dyn_regs; in hl_fw_dynamic_init_cpu()
2527 fw_loader->cpu_timeout); in hl_fw_dynamic_init_cpu()
2531 if (hdev->reset_info.curr_reset_cause) { in hl_fw_dynamic_init_cpu()
2533 HL_COMMS_RESET_CAUSE_TYPE, &hdev->reset_info.curr_reset_cause); in hl_fw_dynamic_init_cpu()
2538 hdev->reset_info.curr_reset_cause = HL_RESET_CAUSE_UNKNOWN; in hl_fw_dynamic_init_cpu()
2541 if (!(hdev->fw_components & FW_TYPE_BOOT_CPU)) { in hl_fw_dynamic_init_cpu()
2548 fw_loader->dynamic_loader.comm_desc.cur_fw_ver); in hl_fw_dynamic_init_cpu()
2551 /* load boot fit to FW */ in hl_fw_dynamic_init_cpu()
2553 fw_loader->boot_fit_timeout); in hl_fw_dynamic_init_cpu()
2555 dev_err(hdev->dev, "failed to load boot fit\n"); in hl_fw_dynamic_init_cpu()
2561 * wait until boot fit is active as it may take several hours. in hl_fw_dynamic_init_cpu()
2565 if (hdev->pldm && !(hdev->fw_components & FW_TYPE_LINUX)) in hl_fw_dynamic_init_cpu()
2572 /* Enable DRAM scrambling before Linux boot and after successful in hl_fw_dynamic_init_cpu()
2575 hdev->asic_funcs->init_cpu_scrambler_dram(hdev); in hl_fw_dynamic_init_cpu()
2577 if (!(hdev->fw_components & FW_TYPE_LINUX)) { in hl_fw_dynamic_init_cpu()
2578 dev_info(hdev->dev, "Skip loading Linux F/W\n"); in hl_fw_dynamic_init_cpu()
2582 if (fw_loader->skip_bmc) { in hl_fw_dynamic_init_cpu()
2586 fw_loader->cpu_timeout); in hl_fw_dynamic_init_cpu()
2588 dev_err(hdev->dev, "failed to load boot fit\n"); in hl_fw_dynamic_init_cpu()
2595 fw_loader->cpu_timeout); in hl_fw_dynamic_init_cpu()
2597 dev_err(hdev->dev, "failed to load Linux\n"); in hl_fw_dynamic_init_cpu()
2605 hl_fw_linux_update_state(hdev, le32_to_cpu(dyn_regs->cpu_boot_dev_sts0), in hl_fw_dynamic_init_cpu()
2606 le32_to_cpu(dyn_regs->cpu_boot_dev_sts1)); in hl_fw_dynamic_init_cpu()
2613 if (fw_loader->dynamic_loader.fw_desc_valid) in hl_fw_dynamic_init_cpu()
2614 fw_read_errors(hdev, le32_to_cpu(dyn_regs->cpu_boot_err0), in hl_fw_dynamic_init_cpu()
2615 le32_to_cpu(dyn_regs->cpu_boot_err1), in hl_fw_dynamic_init_cpu()
2616 le32_to_cpu(dyn_regs->cpu_boot_dev_sts0), in hl_fw_dynamic_init_cpu()
2617 le32_to_cpu(dyn_regs->cpu_boot_dev_sts1)); in hl_fw_dynamic_init_cpu()
2622 * hl_fw_static_init_cpu - initialize the device CPU using static protocol
2627 * @return 0 on success, otherwise non-zero error code
2638 if (!(hdev->fw_components & FW_TYPE_BOOT_CPU)) in hl_fw_static_init_cpu()
2642 cpu_timeout = fw_loader->cpu_timeout; in hl_fw_static_init_cpu()
2645 static_loader = &fw_loader->static_loader; in hl_fw_static_init_cpu()
2646 cpu_msg_status_reg = static_loader->cpu_cmd_status_to_host_reg; in hl_fw_static_init_cpu()
2647 msg_to_cpu_reg = static_loader->kmd_msg_to_cpu_reg; in hl_fw_static_init_cpu()
2648 cpu_boot_dev_status0_reg = static_loader->cpu_boot_dev_status0_reg; in hl_fw_static_init_cpu()
2649 cpu_boot_dev_status1_reg = static_loader->cpu_boot_dev_status1_reg; in hl_fw_static_init_cpu()
2650 cpu_boot_status_reg = static_loader->cpu_boot_status_reg; in hl_fw_static_init_cpu()
2652 dev_info(hdev->dev, "Going to wait for device boot (up to %lds)\n", in hl_fw_static_init_cpu()
2655 /* Wait for boot FIT request */ in hl_fw_static_init_cpu()
2661 hdev->fw_poll_interval_usec, in hl_fw_static_init_cpu()
2662 fw_loader->boot_fit_timeout); in hl_fw_static_init_cpu()
2665 dev_dbg(hdev->dev, in hl_fw_static_init_cpu()
2666 "No boot fit request received, resuming boot\n"); in hl_fw_static_init_cpu()
2668 rc = hdev->asic_funcs->load_boot_fit_to_device(hdev); in hl_fw_static_init_cpu()
2675 /* Signal device CPU that boot loader is ready */ in hl_fw_static_init_cpu()
2684 hdev->fw_poll_interval_usec, in hl_fw_static_init_cpu()
2685 fw_loader->boot_fit_timeout); in hl_fw_static_init_cpu()
2688 dev_err(hdev->dev, in hl_fw_static_init_cpu()
2689 "Timeout waiting for boot fit load ack\n"); in hl_fw_static_init_cpu()
2698 * Make sure CPU boot-loader is running in hl_fw_static_init_cpu()
2713 hdev->fw_poll_interval_usec, in hl_fw_static_init_cpu()
2716 dev_dbg(hdev->dev, "uboot status = %d\n", status); in hl_fw_static_init_cpu()
2718 /* Read U-Boot version now in case we will later fail */ in hl_fw_static_init_cpu()
2721 /* update state according to boot stage */ in hl_fw_static_init_cpu()
2727 rc = -EIO; in hl_fw_static_init_cpu()
2731 /* Enable DRAM scrambling before Linux boot and after successful in hl_fw_static_init_cpu()
2734 hdev->asic_funcs->init_cpu_scrambler_dram(hdev); in hl_fw_static_init_cpu()
2736 if (!(hdev->fw_components & FW_TYPE_LINUX)) { in hl_fw_static_init_cpu()
2737 dev_info(hdev->dev, "Skip loading Linux F/W\n"); in hl_fw_static_init_cpu()
2747 dev_info(hdev->dev, in hl_fw_static_init_cpu()
2750 rc = hdev->asic_funcs->load_firmware_to_device(hdev); in hl_fw_static_init_cpu()
2754 if (fw_loader->skip_bmc) { in hl_fw_static_init_cpu()
2762 hdev->fw_poll_interval_usec, in hl_fw_static_init_cpu()
2766 dev_err(hdev->dev, in hl_fw_static_init_cpu()
2770 rc = -EIO; in hl_fw_static_init_cpu()
2782 hdev->fw_poll_interval_usec, in hl_fw_static_init_cpu()
2790 dev_err(hdev->dev, in hl_fw_static_init_cpu()
2793 dev_err(hdev->dev, in hl_fw_static_init_cpu()
2797 rc = -EIO; in hl_fw_static_init_cpu()
2801 rc = fw_read_errors(hdev, fw_loader->static_loader.boot_err0_reg, in hl_fw_static_init_cpu()
2802 fw_loader->static_loader.boot_err1_reg, in hl_fw_static_init_cpu()
2814 fw_read_errors(hdev, fw_loader->static_loader.boot_err0_reg, in hl_fw_static_init_cpu()
2815 fw_loader->static_loader.boot_err1_reg, in hl_fw_static_init_cpu()
2823 * hl_fw_init_cpu - initialize the device CPU
2827 * @return 0 on success, otherwise non-zero error code
2834 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_fw_init_cpu()
2835 struct fw_load_mgr *fw_loader = &hdev->fw_loader; in hl_fw_init_cpu()
2837 return prop->dynamic_fw_load ? in hl_fw_init_cpu()
2844 hl_fw_set_frequency(hdev, hdev->asic_prop.clk_pll_index, in hl_fw_set_pll_profile()
2845 hdev->asic_prop.max_freq_value); in hl_fw_set_pll_profile()
2853 return -ENODEV; in hl_fw_get_clk_rate()
2855 if (!hdev->pdev) { in hl_fw_get_clk_rate()
2861 value = hl_fw_get_frequency(hdev, hdev->asic_prop.clk_pll_index, false); in hl_fw_get_clk_rate()
2864 dev_err(hdev->dev, "Failed to retrieve device max clock %ld\n", value); in hl_fw_get_clk_rate()
2870 value = hl_fw_get_frequency(hdev, hdev->asic_prop.clk_pll_index, true); in hl_fw_get_clk_rate()
2873 dev_err(hdev->dev, "Failed to retrieve device current clock %ld\n", value); in hl_fw_get_clk_rate()
2903 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, &result); in hl_fw_get_frequency()
2906 dev_err(hdev->dev, "Failed to get frequency of PLL %d, error %d\n", in hl_fw_get_frequency()
2930 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, NULL); in hl_fw_set_frequency()
2933 dev_err(hdev->dev, "Failed to set frequency to PLL %d, error %d\n", in hl_fw_set_frequency()
2947 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, &result); in hl_fw_get_max_power()
2950 dev_err(hdev->dev, "Failed to get max power, error %d\n", rc); in hl_fw_get_max_power()
2963 if (!hdev->pdev) in hl_fw_set_max_power()
2969 pkt.value = cpu_to_le64(hdev->max_power); in hl_fw_set_max_power()
2971 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, NULL); in hl_fw_set_max_power()
2974 dev_err(hdev->dev, "Failed to set max power, error %d\n", rc); in hl_fw_set_max_power()
2987 dev_err(hdev->dev, in hl_fw_get_sec_attest_data()
2988 "Failed to allocate DMA memory for CPU-CP packet %u\n", packet_id); in hl_fw_get_sec_attest_data()
2989 return -ENOMEM; in hl_fw_get_sec_attest_data()
2999 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), in hl_fw_get_sec_attest_data()
3002 dev_err(hdev->dev, in hl_fw_get_sec_attest_data()
3003 "Failed to handle CPU-CP pkt %u, error %d\n", packet_id, rc); in hl_fw_get_sec_attest_data()