Lines Matching defs:hdev

99  * @hdev: pointer to the hl_device
102 * The extracted version is set in the hdev fields: fw_sw_{major/minor/sub_minor}_ver.
111 static int hl_get_sw_major_minor_subminor(struct hl_device *hdev, const char *fw_str)
138 start = extract_u32_until_given_char(start, &hdev->fw_sw_major_ver, '.');
143 start = extract_u32_until_given_char(start, &hdev->fw_sw_minor_ver, '.');
148 start = extract_u32_until_given_char(start, &hdev->fw_sw_sub_minor_ver, '-');
155 hdev->fw_sw_major_ver = 0;
156 hdev->fw_sw_minor_ver = 0;
157 hdev->fw_sw_sub_minor_ver = 0;
163 * @hdev: pointer to the hl_device
167 * The extracted version is set in the hdev fields: fw_inner_{major/minor}_ver.
171 static int hl_get_preboot_major_minor(struct hl_device *hdev, char *preboot_ver)
173 preboot_ver = extract_u32_until_given_char(preboot_ver, &hdev->fw_inner_major_ver, '.');
175 dev_err(hdev->dev, "Error parsing preboot major version\n");
181 preboot_ver = extract_u32_until_given_char(preboot_ver, &hdev->fw_inner_minor_ver, '.');
183 dev_err(hdev->dev, "Error parsing preboot minor version\n");
189 hdev->fw_inner_major_ver = 0;
190 hdev->fw_inner_minor_ver = 0;
194 static int hl_request_fw(struct hl_device *hdev,
201 rc = request_firmware(firmware_p, fw_name, hdev->dev);
203 dev_err(hdev->dev, "Firmware file %s is not found! (error %d)\n",
210 dev_err(hdev->dev, "Illegal %s firmware size %zu\n",
216 dev_dbg(hdev->dev, "%s firmware size == %zu\n", fw_name, fw_size);
219 dev_err(hdev->dev,
250 * @hdev: pointer to hl_device structure.
258 static int hl_fw_copy_fw_to_device(struct hl_device *hdev,
269 dev_err(hdev->dev,
284 * @hdev: pointer to hl_device structure.
292 static int hl_fw_copy_msg_to_device(struct hl_device *hdev,
303 dev_err(hdev->dev,
319 * @hdev: pointer to hl_device structure.
329 int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,
335 rc = hl_request_fw(hdev, &fw, fw_name);
339 rc = hl_fw_copy_fw_to_device(hdev, fw, dst, src_offset, size);
345 int hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode, u64 value)
352 return hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, NULL);
355 int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,
358 struct hl_hw_queue *queue = &hdev->kernel_queues[hw_queue_id];
359 struct asic_fixed_properties *prop = &hdev->asic_prop;
366 pkt = hl_cpu_accessible_dma_pool_alloc(hdev, len, &pkt_dma_addr);
368 dev_err(hdev->dev,
375 mutex_lock(&hdev->send_cpu_message_lock);
378 if (hdev->disabled && !hdev->reset_info.in_compute_reset) {
383 if (hdev->device_cpu_disabled) {
400 hl_hw_queue_submit_bd(hdev, queue, hl_queue_inc_ptr(queue->pi), len, pkt_dma_addr);
407 rc = hl_poll_timeout_memory(hdev, &pkt->fence, tmp,
411 hl_hw_queue_inc_ci_kernel(hdev, hw_queue_id);
417 if (!hl_device_operational(hdev, NULL) && !hdev->reset_info.in_compute_reset)
418 dev_dbg(hdev->dev, "Device CPU packet timeout (0x%x) due to FW reset\n",
421 dev_err(hdev->dev, "Device CPU packet timeout (status = 0x%x)\n", tmp);
422 hdev->device_cpu_disabled = true;
433 dev_dbg(hdev->dev, "F/W ERROR %d for CPU packet %d\n", rc, opcode);
440 dev_err(hdev->dev,
444 dev_err(hdev->dev,
448 dev_dbg(hdev->dev,
452 dev_err(hdev->dev,
457 dev_err(hdev->dev,
481 mutex_unlock(&hdev->send_cpu_message_lock);
483 hl_cpu_accessible_dma_pool_free(hdev, len, pkt);
488 int hl_fw_unmask_irq(struct hl_device *hdev, u16 event_type)
500 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
504 dev_err(hdev->dev, "failed to unmask RAZWI IRQ %d", event_type);
509 int hl_fw_unmask_irq_arr(struct hl_device *hdev, const u32 *irq_arr,
525 dev_err(hdev->dev, "too many elements in IRQ array\n");
539 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) pkt,
543 dev_err(hdev->dev, "failed to unmask IRQ array\n");
550 int hl_fw_test_cpu_queue(struct hl_device *hdev)
560 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &test_pkt,
565 dev_err(hdev->dev,
568 dev_err(hdev->dev, "CPU queue test failed, error %d\n", rc);
574 void *hl_fw_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size,
579 kernel_addr = gen_pool_alloc(hdev->cpu_accessible_dma_pool, size);
581 *dma_handle = hdev->cpu_accessible_dma_address +
582 (kernel_addr - (u64) (uintptr_t) hdev->cpu_accessible_dma_mem);
587 void hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size,
590 gen_pool_free(hdev->cpu_accessible_dma_pool, (u64) (uintptr_t) vaddr,
594 int hl_fw_send_soft_reset(struct hl_device *hdev)
601 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, NULL);
603 dev_err(hdev->dev, "failed to send soft-reset msg (err = %d)\n", rc);
608 int hl_fw_send_device_activity(struct hl_device *hdev, bool open)
616 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, NULL);
618 dev_err(hdev->dev, "failed to send device activity msg(%u)\n", open);
623 int hl_fw_send_heartbeat(struct hl_device *hdev)
634 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &hb_pkt,
642 dev_warn(hdev->dev, "FW reported EQ fault during heartbeat\n");
649 static bool fw_report_boot_dev0(struct hl_device *hdev, u32 err_val,
658 dev_err(hdev->dev,
664 dev_err(hdev->dev, "Device boot error - FIT image corrupted\n");
669 dev_err(hdev->dev,
675 if (hdev->bmc_enable) {
676 dev_err(hdev->dev,
680 dev_info(hdev->dev,
690 dev_err(hdev->dev,
696 dev_err(hdev->dev,
702 dev_err(hdev->dev,
708 dev_err(hdev->dev, "Device boot error - security failure\n");
713 dev_err(hdev->dev, "Device boot error - eFuse failure\n");
718 dev_err(hdev->dev, "Device boot error - Failed to load preboot secondary image\n");
723 dev_err(hdev->dev, "Device boot error - PLL failure\n");
729 dev_dbg(hdev->dev, "device unusable status is set\n");
734 dev_err(hdev->dev, "Device boot error - binning failure\n");
739 dev_dbg(hdev->dev, "Device status0 %#x\n", sts_val);
742 dev_err(hdev->dev, "Device boot error - EEPROM failure detected\n");
748 dev_warn(hdev->dev,
757 dev_warn(hdev->dev,
766 dev_warn(hdev->dev,
775 dev_err(hdev->dev,
782 lower_32_bits(hdev->boot_error_status_mask)))
789 static bool fw_report_boot_dev1(struct hl_device *hdev, u32 err_val,
803 dev_dbg(hdev->dev, "Device status1 %#x\n", sts_val);
806 dev_err(hdev->dev,
814 upper_32_bits(hdev->boot_error_status_mask)))
820 static int fw_read_errors(struct hl_device *hdev, u32 boot_err0_reg,
838 err_exists = fw_report_boot_dev0(hdev, err_val, status_val);
842 err_exists |= fw_report_boot_dev1(hdev, err_val, status_val);
850 int hl_fw_cpucp_info_get(struct hl_device *hdev,
855 struct asic_fixed_properties *prop = &hdev->asic_prop;
863 cpucp_info_cpu_addr = hl_cpu_accessible_dma_pool_alloc(hdev, sizeof(struct cpucp_info),
866 dev_err(hdev->dev,
878 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
881 dev_err(hdev->dev,
886 rc = fw_read_errors(hdev, boot_err0_reg, boot_err1_reg,
889 dev_err(hdev->dev, "Errors in device boot\n");
896 rc = hl_build_hwmon_channel_info(hdev, prop->cpucp_info.sensors);
898 dev_err(hdev->dev,
906 dev_info(hdev->dev, "Linux version %s", kernel_ver);
911 hdev->event_queue.check_eqe_index = false;
918 hdev->event_queue.check_eqe_index = true;
925 hl_cpu_accessible_dma_pool_free(hdev, sizeof(struct cpucp_info), cpucp_info_cpu_addr);
930 static int hl_fw_send_msi_info_msg(struct hl_device *hdev)
938 if (!hdev->asic_funcs->get_msi_info)
949 dev_err(hdev->dev, "CPUCP array data is too big\n");
960 hdev->asic_funcs->get_msi_info(pkt->data);
965 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *)pkt,
977 dev_err(hdev->dev, "failed to send CPUCP array data\n");
984 int hl_fw_cpucp_handshake(struct hl_device *hdev,
991 rc = hl_fw_cpucp_info_get(hdev, sts_boot_dev_sts0_reg,
997 return hl_fw_send_msi_info_msg(hdev);
1000 int hl_fw_get_eeprom_data(struct hl_device *hdev, void *data, size_t max_size)
1008 eeprom_info_cpu_addr = hl_cpu_accessible_dma_pool_alloc(hdev, max_size,
1011 dev_err(hdev->dev,
1023 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
1027 dev_err(hdev->dev,
1037 hl_cpu_accessible_dma_pool_free(hdev, max_size, eeprom_info_cpu_addr);
1042 int hl_fw_get_monitor_dump(struct hl_device *hdev, void *data)
1054 mon_dump_cpu_addr = hl_cpu_accessible_dma_pool_alloc(hdev, data_size, &mon_dump_dma_addr);
1056 dev_err(hdev->dev,
1067 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
1070 dev_err(hdev->dev, "Failed to handle CPU-CP monitor-dump packet, error %d\n", rc);
1084 hl_cpu_accessible_dma_pool_free(hdev, data_size, mon_dump_cpu_addr);
1089 int hl_fw_cpucp_pci_counters_get(struct hl_device *hdev,
1101 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
1104 dev_err(hdev->dev,
1116 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
1119 dev_err(hdev->dev,
1130 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
1133 dev_err(hdev->dev,
1142 int hl_fw_cpucp_total_energy_get(struct hl_device *hdev, u64 *total_energy)
1151 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
1154 dev_err(hdev->dev,
1165 int get_used_pll_index(struct hl_device *hdev, u32 input_pll_index,
1168 struct asic_fixed_properties *prop = &hdev->asic_prop;
1189 fw_pll_idx = hdev->asic_funcs->map_pll_idx_to_fw_idx(input_pll_index);
1191 dev_err(hdev->dev, "Invalid PLL index (%u) error %d\n",
1201 dev_err(hdev->dev, "PLL index %d is not supported\n",
1211 int hl_fw_cpucp_pll_info_get(struct hl_device *hdev, u32 pll_index,
1219 rc = get_used_pll_index(hdev, pll_index, &used_pll_idx);
1229 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
1232 dev_err(hdev->dev, "Failed to read PLL info, error %d\n", rc);
1244 int hl_fw_cpucp_power_get(struct hl_device *hdev, u64 *power)
1256 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
1259 dev_err(hdev->dev, "Failed to read power, error %d\n", rc);
1268 int hl_fw_dram_replaced_row_get(struct hl_device *hdev,
1277 cpucp_repl_rows_info_cpu_addr = hl_cpu_accessible_dma_pool_alloc(hdev,
1281 dev_err(hdev->dev,
1293 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
1296 dev_err(hdev->dev,
1304 hl_cpu_accessible_dma_pool_free(hdev, sizeof(struct cpucp_hbm_row_info),
1310 int hl_fw_dram_pending_row_get(struct hl_device *hdev, u32 *pend_rows_num)
1320 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, &result);
1322 dev_err(hdev->dev,
1332 int hl_fw_cpucp_engine_core_asid_set(struct hl_device *hdev, u32 asid)
1342 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
1345 dev_err(hdev->dev,
1352 void hl_fw_ask_hard_reset_without_linux(struct hl_device *hdev)
1355 &hdev->fw_loader.static_loader;
1358 if (hdev->asic_prop.dynamic_fw_load) {
1359 rc = hl_fw_dynamic_send_protocol_cmd(hdev, &hdev->fw_loader,
1361 hdev->fw_loader.cpu_timeout);
1363 dev_err(hdev->dev, "Failed sending COMMS_RST_DEV\n");
1369 void hl_fw_ask_halt_machine_without_linux(struct hl_device *hdev)
1371 struct fw_load_mgr *fw_loader = &hdev->fw_loader;
1377 if (hdev->device_cpu_is_halted)
1381 if (hdev->asic_prop.dynamic_fw_load) {
1386 rc = hl_fw_dynamic_send_protocol_cmd(hdev, &hdev->fw_loader,
1389 dev_err(hdev->dev, "Failed sending COMMS_GOTO_WFE\n");
1392 hdev,
1396 hdev->fw_poll_interval_usec,
1399 dev_err(hdev->dev, "Current status=%u. Timed-out updating to WFE\n",
1403 static_loader = &hdev->fw_loader.static_loader;
1413 hdev->device_cpu_is_halted = true;
1416 static void detect_cpu_boot_status(struct hl_device *hdev, u32 status)
1423 dev_err(hdev->dev,
1427 dev_err(hdev->dev,
1431 dev_err(hdev->dev,
1435 dev_err(hdev->dev,
1439 dev_err(hdev->dev,
1443 dev_err(hdev->dev,
1447 dev_err(hdev->dev,
1451 dev_err(hdev->dev,
1455 dev_err(hdev->dev,
1459 dev_err(hdev->dev,
1463 dev_err(hdev->dev,
1469 int hl_fw_wait_preboot_ready(struct hl_device *hdev)
1471 struct pre_fw_load_props *pre_fw_load = &hdev->fw_loader.pre_fw_load;
1484 hdev,
1490 hdev->fw_poll_interval_usec,
1494 detect_cpu_boot_status(hdev, status);
1495 dev_err(hdev->dev, "CPU boot ready timeout (status = %d)\n", status);
1501 fw_read_errors(hdev, pre_fw_load->boot_err0_reg,
1508 hdev->fw_loader.fw_comp_loaded |= FW_TYPE_PREBOOT_CPU;
1513 static int hl_fw_read_preboot_caps(struct hl_device *hdev)
1520 prop = &hdev->asic_prop;
1521 pre_fw_load = &hdev->fw_loader.pre_fw_load;
1523 rc = hl_fw_wait_preboot_ready(hdev);
1553 hdev->asic_funcs->init_firmware_loader(hdev);
1555 dev_dbg(hdev->dev, "Attempting %s FW load\n",
1560 static int hl_fw_static_read_device_fw_version(struct hl_device *hdev,
1563 struct asic_fixed_properties *prop = &hdev->asic_prop;
1564 struct fw_load_mgr *fw_loader = &hdev->fw_loader;
1571 static_loader = &hdev->fw_loader.static_loader;
1587 dev_warn(hdev->dev, "Undefined FW component: %d\n", fwc);
1595 hdev->pcie_bar[fw_loader->sram_bar_id] + ver_off,
1598 dev_err(hdev->dev, "%s version offset (0x%x) is above SRAM\n",
1607 dev_info(hdev->dev, "boot-fit version %s\n", boot_ver);
1617 dev_info(hdev->dev, "%s\n", btl_ver);
1622 dev_info(hdev->dev, "preboot version %s\n",
1636 * @hdev: pointer to the habanalabs device structure
1640 static void hl_fw_preboot_update_state(struct hl_device *hdev)
1642 struct asic_fixed_properties *prop = &hdev->asic_prop;
1661 dev_dbg(hdev->dev, "Firmware preboot boot device status0 %#x\n",
1664 dev_dbg(hdev->dev, "Firmware preboot boot device status1 %#x\n",
1667 dev_dbg(hdev->dev, "Firmware preboot hard-reset is %s\n",
1670 dev_dbg(hdev->dev, "firmware-level security is %s\n",
1673 dev_dbg(hdev->dev, "GIC controller is %s\n",
1677 static int hl_fw_static_read_preboot_status(struct hl_device *hdev)
1681 rc = hl_fw_static_read_device_fw_version(hdev, FW_COMP_PREBOOT);
1688 int hl_fw_read_preboot_status(struct hl_device *hdev)
1692 if (!(hdev->fw_components & FW_TYPE_PREBOOT_CPU))
1696 hdev->asic_funcs->init_firmware_preload_params(hdev);
1702 rc = hl_fw_read_preboot_caps(hdev);
1706 hl_fw_preboot_update_state(hdev);
1709 if (hdev->asic_prop.dynamic_fw_load)
1712 return hl_fw_static_read_preboot_status(hdev);
1728 * @hdev: pointer to the habanalabs device structure
1732 static void hl_fw_dynamic_report_error_status(struct hl_device *hdev,
1740 dev_err(hdev->dev, "Device status %s, expected status: %s\n",
1744 dev_err(hdev->dev, "Device status unknown %d, expected status: %s\n",
1752 * @hdev: pointer to the habanalabs device structure
1763 static void hl_fw_dynamic_send_cmd(struct hl_device *hdev,
1775 trace_habanalabs_comms_send_cmd(hdev->dev, comms_cmd_str_arr[cmd]);
1782 * @hdev: pointer to the habanalabs device structure
1789 static int hl_fw_dynamic_extract_fw_response(struct hl_device *hdev,
1801 dev_err(hdev->dev, "FW status: invalid RAM type %u\n",
1812 * @hdev: pointer to the habanalabs device structure
1822 static int hl_fw_dynamic_wait_for_status(struct hl_device *hdev,
1833 trace_habanalabs_comms_wait_status(hdev->dev, comms_sts_str_arr[expected_status]);
1837 hdev,
1841 hdev->fw_comms_poll_interval_usec,
1845 hl_fw_dynamic_report_error_status(hdev, status,
1850 trace_habanalabs_comms_wait_status_done(hdev->dev, comms_sts_str_arr[expected_status]);
1859 rc = hl_fw_dynamic_extract_fw_response(hdev, fw_loader,
1868 * @hdev: pointer to the habanalabs device structure
1879 static int hl_fw_dynamic_send_clear_cmd(struct hl_device *hdev,
1882 hl_fw_dynamic_send_cmd(hdev, fw_loader, COMMS_CLR_STS, 0);
1884 return hl_fw_dynamic_wait_for_status(hdev, fw_loader, COMMS_STS_NOOP,
1891 * @hdev: pointer to the habanalabs device structure
1917 int hl_fw_dynamic_send_protocol_cmd(struct hl_device *hdev,
1924 trace_habanalabs_comms_protocol_cmd(hdev->dev, comms_cmd_str_arr[cmd]);
1927 rc = hl_fw_dynamic_send_clear_cmd(hdev, fw_loader);
1932 hl_fw_dynamic_send_cmd(hdev, fw_loader, cmd, size);
1935 rc = hl_fw_dynamic_wait_for_status(hdev, fw_loader, COMMS_STS_ACK,
1941 rc = hl_fw_dynamic_send_clear_cmd(hdev, fw_loader);
1946 hl_fw_dynamic_send_cmd(hdev, fw_loader, COMMS_NOOP, 0);
1951 rc = hl_fw_dynamic_wait_for_status(hdev, fw_loader, COMMS_STS_OK,
1957 rc = hl_fw_dynamic_send_clear_cmd(hdev, fw_loader);
1962 hl_fw_dynamic_send_cmd(hdev, fw_loader, COMMS_NOOP, 0);
1990 * @hdev: pointer to the habanalabs device structure
1997 static int hl_fw_dynamic_validate_memory_bound(struct hl_device *hdev,
2006 dev_err(hdev->dev,
2019 dev_err(hdev->dev,
2030 * @hdev: pointer to the habanalabs device structure
2036 static int hl_fw_dynamic_validate_descriptor(struct hl_device *hdev,
2049 dev_dbg(hdev->dev, "Invalid magic for dynamic FW descriptor (%x)\n",
2053 dev_dbg(hdev->dev, "Invalid version for dynamic FW descriptor (%x)\n",
2068 dev_err(hdev->dev, "CRC32 mismatch for dynamic FW descriptor (%x:%x)\n",
2075 region_id = hl_get_pci_memory_region(hdev, addr);
2077 dev_err(hdev->dev, "Invalid region to copy FW image address=%llx\n", addr);
2081 region = &hdev->pci_mem_region[region_id];
2090 rc = hl_fw_dynamic_validate_memory_bound(hdev, addr,
2094 dev_err(hdev->dev, "invalid mem transfer request for FW image\n");
2104 static int hl_fw_dynamic_validate_response(struct hl_device *hdev,
2118 rc = hl_fw_dynamic_validate_memory_bound(hdev, device_addr,
2127 * @hdev: pointer to the habanalabs device structure
2130 static void hl_fw_dynamic_read_descriptor_msg(struct hl_device *hdev,
2146 dev_err(hdev->dev, "fw: %s", fw_desc->ascii_msg[i].msg);
2149 dev_warn(hdev->dev, "fw: %s", fw_desc->ascii_msg[i].msg);
2152 dev_info(hdev->dev, "fw: %s", fw_desc->ascii_msg[i].msg);
2155 dev_dbg(hdev->dev, "fw: %s", fw_desc->ascii_msg[i].msg);
2164 * @hdev: pointer to the habanalabs device structure
2169 static int hl_fw_dynamic_read_and_validate_descriptor(struct hl_device *hdev,
2187 region = &hdev->pci_mem_region[region_id];
2189 rc = hl_fw_dynamic_validate_response(hdev, response, region);
2191 dev_err(hdev->dev,
2203 src = hdev->pcie_bar[region->bar_id] + region->offset_in_bar +
2223 rc = hl_fw_dynamic_validate_descriptor(hdev, fw_loader,
2227 hl_fw_dynamic_read_descriptor_msg(hdev, temp_fw_desc);
2237 * @hdev: pointer to the habanalabs device structure
2243 static int hl_fw_dynamic_request_descriptor(struct hl_device *hdev,
2249 rc = hl_fw_dynamic_send_protocol_cmd(hdev, fw_loader, COMMS_PREP_DESC,
2255 return hl_fw_dynamic_read_and_validate_descriptor(hdev, fw_loader);
2261 * @hdev: pointer to the habanalabs device structure
2265 static int hl_fw_dynamic_read_device_fw_version(struct hl_device *hdev,
2269 struct asic_fixed_properties *prop = &hdev->asic_prop;
2279 dev_info(hdev->dev, "boot-fit version %s\n", boot_ver);
2287 dev_info(hdev->dev, "preboot full version: '%s'\n", preboot_ver);
2292 dev_info(hdev->dev, "%s\n", btl_ver);
2295 rc = hl_get_sw_major_minor_subminor(hdev, preboot_ver);
2300 rc = hl_get_preboot_major_minor(hdev, preboot_ver);
2308 dev_warn(hdev->dev, "Undefined FW component: %d\n", fwc);
2318 * @hdev: pointer to the habanalabs device structure
2322 static int hl_fw_dynamic_copy_image(struct hl_device *hdev,
2338 dest = hdev->pcie_bar[region->bar_id] + region->offset_in_bar +
2341 rc = hl_fw_copy_fw_to_device(hdev, fw, dest,
2351 * @hdev: pointer to the habanalabs device structure
2355 static int hl_fw_dynamic_copy_msg(struct hl_device *hdev,
2370 dest = hdev->pcie_bar[region->bar_id] + region->offset_in_bar +
2373 rc = hl_fw_copy_msg_to_device(hdev, msg, dest, 0, 0);
2382 * @hdev: pointer to the habanalabs device structure
2388 static void hl_fw_boot_fit_update_state(struct hl_device *hdev,
2392 struct asic_fixed_properties *prop = &hdev->asic_prop;
2394 hdev->fw_loader.fw_comp_loaded |= FW_TYPE_BOOT_CPU;
2404 dev_dbg(hdev->dev, "Firmware boot CPU status0 %#x\n",
2412 dev_dbg(hdev->dev, "Firmware boot CPU status1 %#x\n",
2416 dev_dbg(hdev->dev, "Firmware boot CPU hard-reset is %s\n",
2420 static void hl_fw_dynamic_update_linux_interrupt_if(struct hl_device *hdev)
2423 &hdev->fw_loader.dynamic_loader.comm_desc.cpu_dyn_regs;
2428 if (!hdev->asic_prop.gic_interrupts_enable &&
2429 !(hdev->asic_prop.fw_app_cpu_boot_dev_sts0 &
2434 dev_warn(hdev->dev,
2441 * @hdev: pointer to the habanalabs device structure
2448 static int hl_fw_dynamic_load_image(struct hl_device *hdev,
2472 rc = hl_request_fw(hdev, &fw, fw_name);
2479 rc = hl_fw_dynamic_request_descriptor(hdev, fw_loader, fw->size);
2484 rc = hl_fw_dynamic_read_device_fw_version(hdev, cur_fwc,
2490 rc = hl_fw_dynamic_copy_image(hdev, fw, fw_loader);
2494 rc = hl_fw_dynamic_send_protocol_cmd(hdev, fw_loader, COMMS_DATA_RDY,
2500 rc = hl_fw_dynamic_send_protocol_cmd(hdev, fw_loader, COMMS_EXEC,
2509 static int hl_fw_dynamic_wait_for_boot_fit_active(struct hl_device *hdev,
2527 hdev,
2532 hdev->fw_poll_interval_usec,
2535 dev_err(hdev->dev, "failed to wait for boot (status = %d)\n", status);
2539 dev_dbg(hdev->dev, "uboot status = %d\n", status);
2543 static int hl_fw_dynamic_wait_for_linux_active(struct hl_device *hdev,
2555 hdev,
2559 hdev->fw_poll_interval_usec,
2562 dev_err(hdev->dev, "failed to wait for Linux (status = %d)\n", status);
2566 dev_dbg(hdev->dev, "Boot status = %d\n", status);
2579 * @hdev: pointer to the habanalabs device structure
2585 static void hl_fw_linux_update_state(struct hl_device *hdev,
2589 struct asic_fixed_properties *prop = &hdev->asic_prop;
2591 hdev->fw_loader.fw_comp_loaded |= FW_TYPE_LINUX;
2604 dev_dbg(hdev->dev,
2608 dev_dbg(hdev->dev, "GIC controller is %s\n",
2616 dev_dbg(hdev->dev,
2621 dev_dbg(hdev->dev, "Firmware application CPU hard-reset is %s\n",
2624 dev_info(hdev->dev, "Successfully loaded firmware to device\n");
2630 * @hdev: pointer to the habanalabs device structure
2637 static int hl_fw_dynamic_send_msg(struct hl_device *hdev,
2658 dev_err(hdev->dev,
2665 rc = hl_fw_dynamic_request_descriptor(hdev, fw_loader,
2671 rc = hl_fw_dynamic_copy_msg(hdev, msg, fw_loader);
2675 rc = hl_fw_dynamic_send_protocol_cmd(hdev, fw_loader, COMMS_DATA_RDY,
2681 rc = hl_fw_dynamic_send_protocol_cmd(hdev, fw_loader, COMMS_EXEC,
2693 * @hdev: pointer to the habanalabs device structure
2708 static int hl_fw_dynamic_init_cpu(struct hl_device *hdev,
2714 dev_info(hdev->dev,
2716 hdev->asic_prop.fw_security_enabled ? "secured " : "");
2727 rc = hl_fw_dynamic_send_protocol_cmd(hdev, fw_loader, COMMS_RST_STATE,
2733 if (hdev->reset_info.curr_reset_cause) {
2734 rc = hl_fw_dynamic_send_msg(hdev, fw_loader,
2735 HL_COMMS_RESET_CAUSE_TYPE, &hdev->reset_info.curr_reset_cause);
2740 hdev->reset_info.curr_reset_cause = HL_RESET_CAUSE_UNKNOWN;
2743 if (!(hdev->fw_components & FW_TYPE_BOOT_CPU)) {
2746 rc = hl_fw_dynamic_request_descriptor(hdev, fw_loader, 0);
2751 rc = hl_fw_dynamic_read_device_fw_version(hdev, FW_COMP_PREBOOT,
2758 if (hdev->support_preboot_binning) {
2760 hdev->tpc_binning = le64_to_cpu(binning_info->tpc_mask_l);
2761 hdev->dram_binning = le32_to_cpu(binning_info->dram_mask);
2762 hdev->edma_binning = le32_to_cpu(binning_info->edma_mask);
2763 hdev->decoder_binning = le32_to_cpu(binning_info->dec_mask);
2764 hdev->rotator_binning = le32_to_cpu(binning_info->rot_mask);
2766 rc = hdev->asic_funcs->set_dram_properties(hdev);
2770 rc = hdev->asic_funcs->set_binning_masks(hdev);
2774 dev_dbg(hdev->dev,
2776 hdev->tpc_binning, hdev->dram_binning, hdev->edma_binning,
2777 hdev->decoder_binning, hdev->rotator_binning);
2784 rc = hl_fw_dynamic_load_image(hdev, fw_loader, FW_COMP_BOOT_FIT,
2787 dev_err(hdev->dev, "failed to load boot fit\n");
2791 rc = hl_fw_dynamic_wait_for_boot_fit_active(hdev, fw_loader);
2795 hl_fw_boot_fit_update_state(hdev,
2805 if (hdev->pldm && !(hdev->fw_components & FW_TYPE_LINUX))
2811 hdev->asic_funcs->init_cpu_scrambler_dram(hdev);
2813 if (!(hdev->fw_components & FW_TYPE_LINUX)) {
2814 dev_info(hdev->dev, "Skip loading Linux F/W\n");
2819 rc = hl_fw_dynamic_send_protocol_cmd(hdev, fw_loader,
2824 dev_err(hdev->dev, "failed to load boot fit\n");
2830 rc = hl_fw_dynamic_load_image(hdev, fw_loader, FW_COMP_LINUX,
2833 dev_err(hdev->dev, "failed to load Linux\n");
2837 rc = hl_fw_dynamic_wait_for_linux_active(hdev, fw_loader);
2841 hl_fw_linux_update_state(hdev,
2845 hl_fw_dynamic_update_linux_interrupt_if(hdev);
2849 fw_error_rc = fw_read_errors(hdev, le32_to_cpu(dyn_regs->cpu_boot_err0),
2864 * @hdev: pointer to the habanalabs device structure
2869 static int hl_fw_static_init_cpu(struct hl_device *hdev,
2878 if (!(hdev->fw_components & FW_TYPE_BOOT_CPU))
2892 dev_info(hdev->dev, "Going to wait for device boot (up to %lds)\n",
2897 hdev,
2901 hdev->fw_poll_interval_usec,
2905 dev_dbg(hdev->dev,
2908 rc = hdev->asic_funcs->load_boot_fit_to_device(hdev);
2920 hdev,
2924 hdev->fw_poll_interval_usec,
2928 dev_err(hdev->dev,
2946 hdev,
2953 hdev->fw_poll_interval_usec,
2956 dev_dbg(hdev->dev, "uboot status = %d\n", status);
2959 hl_fw_static_read_device_fw_version(hdev, FW_COMP_BOOT_FIT);
2962 hl_fw_boot_fit_update_state(hdev, cpu_boot_dev_status0_reg,
2966 detect_cpu_boot_status(hdev, status);
2974 hdev->asic_funcs->init_cpu_scrambler_dram(hdev);
2976 if (!(hdev->fw_components & FW_TYPE_LINUX)) {
2977 dev_info(hdev->dev, "Skip loading Linux F/W\n");
2987 dev_info(hdev->dev,
2990 rc = hdev->asic_funcs->load_firmware_to_device(hdev);
2998 hdev,
3002 hdev->fw_poll_interval_usec,
3006 dev_err(hdev->dev,
3018 hdev,
3022 hdev->fw_poll_interval_usec,
3030 dev_err(hdev->dev,
3033 dev_err(hdev->dev,
3041 rc = fw_read_errors(hdev, fw_loader->static_loader.boot_err0_reg,
3048 hl_fw_linux_update_state(hdev, cpu_boot_dev_status0_reg,
3054 fw_read_errors(hdev, fw_loader->static_loader.boot_err0_reg,
3065 * @hdev: pointer to the habanalabs device structure
3072 int hl_fw_init_cpu(struct hl_device *hdev)
3074 struct asic_fixed_properties *prop = &hdev->asic_prop;
3075 struct fw_load_mgr *fw_loader = &hdev->fw_loader;
3078 hl_fw_dynamic_init_cpu(hdev, fw_loader) :
3079 hl_fw_static_init_cpu(hdev, fw_loader);
3082 void hl_fw_set_pll_profile(struct hl_device *hdev)
3084 hl_fw_set_frequency(hdev, hdev->asic_prop.clk_pll_index,
3085 hdev->asic_prop.max_freq_value);
3088 int hl_fw_get_clk_rate(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk)
3092 if (!hl_device_operational(hdev, NULL))
3095 if (!hdev->pdev) {
3101 value = hl_fw_get_frequency(hdev, hdev->asic_prop.clk_pll_index, false);
3104 dev_err(hdev->dev, "Failed to retrieve device max clock %ld\n", value);
3110 value = hl_fw_get_frequency(hdev, hdev->asic_prop.clk_pll_index, true);
3113 dev_err(hdev->dev, "Failed to retrieve device current clock %ld\n", value);
3122 long hl_fw_get_frequency(struct hl_device *hdev, u32 pll_index, bool curr)
3129 rc = get_used_pll_index(hdev, pll_index, &used_pll_idx);
3143 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, &result);
3146 dev_err(hdev->dev, "Failed to get frequency of PLL %d, error %d\n",
3154 void hl_fw_set_frequency(struct hl_device *hdev, u32 pll_index, u64 freq)
3160 rc = get_used_pll_index(hdev, pll_index, &used_pll_idx);
3170 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, NULL);
3173 dev_err(hdev->dev, "Failed to set frequency to PLL %d, error %d\n",
3177 long hl_fw_get_max_power(struct hl_device *hdev)
3187 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, &result);
3190 dev_err(hdev->dev, "Failed to get max power, error %d\n", rc);
3197 void hl_fw_set_max_power(struct hl_device *hdev)
3203 if (!hdev->pdev)
3209 pkt.value = cpu_to_le64(hdev->max_power);
3211 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), 0, NULL);
3214 dev_err(hdev->dev, "Failed to set max power, error %d\n", rc);
3217 static int hl_fw_get_sec_attest_data(struct hl_device *hdev, u32 packet_id, void *data, u32 size,
3225 req_cpu_addr = hl_cpu_accessible_dma_pool_alloc(hdev, size, &req_dma_addr);
3227 dev_err(hdev->dev,
3239 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
3242 dev_err(hdev->dev,
3250 hl_cpu_accessible_dma_pool_free(hdev, size, req_cpu_addr);
3255 int hl_fw_get_sec_attest_info(struct hl_device *hdev, struct cpucp_sec_attest_info *sec_attest_info,
3258 return hl_fw_get_sec_attest_data(hdev, CPUCP_PACKET_SEC_ATTEST_GET, sec_attest_info,
3263 int hl_fw_send_generic_request(struct hl_device *hdev, enum hl_passthrough_type sub_opcode,
3275 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *)&pkt, sizeof(pkt),
3278 dev_err(hdev->dev, "failed to send CPUCP data of generic fw pkt\n");
3280 dev_dbg(hdev->dev, "generic pkt was successful, result: 0x%llx\n", result);