1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright 2016-2019 HabanaLabs, Ltd.
8 #include "habanalabs.h"
9 #include "../include/common/hl_boot_if.h"
11 #include <linux/firmware.h>
12 #include <linux/slab.h>
14 #define FW_FILE_MAX_SIZE 0x1400000 /* maximum size of 20MB */
16 * hl_fw_load_fw_to_device() - Load F/W code to device's memory.
18 * @hdev: pointer to hl_device structure.
19 * @fw_name: the firmware image name
20 * @dst: IO memory mapped address space to copy firmware to
21 * @src_offset: offset in src FW to copy from
22 * @size: amount of bytes to copy (0 to copy the whole binary)
24 * Copy fw code from firmware file to device memory.
26 * Return: 0 on success, non-zero for failure.
28 int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,
29 void __iomem *dst, u32 src_offset, u32 size)
31 const struct firmware *fw;
36 rc = request_firmware(&fw, fw_name, hdev->dev);
38 dev_err(hdev->dev, "Firmware file %s is not found!\n", fw_name);
43 if ((fw_size % 4) != 0) {
44 dev_err(hdev->dev, "Illegal %s firmware size %zu\n",
50 dev_dbg(hdev->dev, "%s firmware size == %zu\n", fw_name, fw_size);
52 if (fw_size > FW_FILE_MAX_SIZE) {
54 "FW file size %zu exceeds maximum of %u bytes\n",
55 fw_size, FW_FILE_MAX_SIZE);
60 if (size - src_offset > fw_size) {
62 "size to copy(%u) and offset(%u) are invalid\n",
71 fw_data = (const void *) fw->data;
73 memcpy_toio(dst, fw_data + src_offset, fw_size);
80 int hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode)
82 struct cpucp_packet pkt = {};
84 pkt.ctl = cpu_to_le32(opcode << CPUCP_PKT_CTL_OPCODE_SHIFT);
86 return hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt,
87 sizeof(pkt), 0, NULL);
90 int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,
91 u16 len, u32 timeout, u64 *result)
93 struct hl_hw_queue *queue = &hdev->kernel_queues[hw_queue_id];
94 struct cpucp_packet *pkt;
95 dma_addr_t pkt_dma_addr;
96 u32 tmp, expected_ack_val;
99 pkt = hdev->asic_funcs->cpu_accessible_dma_pool_alloc(hdev, len,
103 "Failed to allocate DMA memory for packet to CPU\n");
107 memcpy(pkt, msg, len);
109 mutex_lock(&hdev->send_cpu_message_lock);
114 if (hdev->device_cpu_disabled) {
119 /* set fence to a non valid value */
120 pkt->fence = UINT_MAX;
122 rc = hl_hw_queue_send_cb_no_cmpl(hdev, hw_queue_id, len, pkt_dma_addr);
124 dev_err(hdev->dev, "Failed to send CB on CPU PQ (%d)\n", rc);
128 if (hdev->asic_prop.fw_app_security_map &
129 CPU_BOOT_DEV_STS0_PKT_PI_ACK_EN)
130 expected_ack_val = queue->pi;
132 expected_ack_val = CPUCP_PACKET_FENCE_VAL;
134 rc = hl_poll_timeout_memory(hdev, &pkt->fence, tmp,
135 (tmp == expected_ack_val), 1000,
138 hl_hw_queue_inc_ci_kernel(hdev, hw_queue_id);
140 if (rc == -ETIMEDOUT) {
141 dev_err(hdev->dev, "Device CPU packet timeout (0x%x)\n", tmp);
142 hdev->device_cpu_disabled = true;
146 tmp = le32_to_cpu(pkt->ctl);
148 rc = (tmp & CPUCP_PKT_CTL_RC_MASK) >> CPUCP_PKT_CTL_RC_SHIFT;
150 dev_err(hdev->dev, "F/W ERROR %d for CPU packet %d\n",
152 (tmp & CPUCP_PKT_CTL_OPCODE_MASK)
153 >> CPUCP_PKT_CTL_OPCODE_SHIFT);
156 *result = le64_to_cpu(pkt->result);
160 mutex_unlock(&hdev->send_cpu_message_lock);
162 hdev->asic_funcs->cpu_accessible_dma_pool_free(hdev, len, pkt);
167 int hl_fw_unmask_irq(struct hl_device *hdev, u16 event_type)
169 struct cpucp_packet pkt;
173 memset(&pkt, 0, sizeof(pkt));
175 pkt.ctl = cpu_to_le32(CPUCP_PACKET_UNMASK_RAZWI_IRQ <<
176 CPUCP_PKT_CTL_OPCODE_SHIFT);
177 pkt.value = cpu_to_le64(event_type);
179 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
183 dev_err(hdev->dev, "failed to unmask RAZWI IRQ %d", event_type);
188 int hl_fw_unmask_irq_arr(struct hl_device *hdev, const u32 *irq_arr,
191 struct cpucp_unmask_irq_arr_packet *pkt;
192 size_t total_pkt_size;
196 total_pkt_size = sizeof(struct cpucp_unmask_irq_arr_packet) +
199 /* data should be aligned to 8 bytes in order to CPU-CP to copy it */
200 total_pkt_size = (total_pkt_size + 0x7) & ~0x7;
202 /* total_pkt_size is casted to u16 later on */
203 if (total_pkt_size > USHRT_MAX) {
204 dev_err(hdev->dev, "too many elements in IRQ array\n");
208 pkt = kzalloc(total_pkt_size, GFP_KERNEL);
212 pkt->length = cpu_to_le32(irq_arr_size / sizeof(irq_arr[0]));
213 memcpy(&pkt->irqs, irq_arr, irq_arr_size);
215 pkt->cpucp_pkt.ctl = cpu_to_le32(CPUCP_PACKET_UNMASK_RAZWI_IRQ_ARRAY <<
216 CPUCP_PKT_CTL_OPCODE_SHIFT);
218 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) pkt,
219 total_pkt_size, 0, &result);
222 dev_err(hdev->dev, "failed to unmask IRQ array\n");
229 int hl_fw_test_cpu_queue(struct hl_device *hdev)
231 struct cpucp_packet test_pkt = {};
235 test_pkt.ctl = cpu_to_le32(CPUCP_PACKET_TEST <<
236 CPUCP_PKT_CTL_OPCODE_SHIFT);
237 test_pkt.value = cpu_to_le64(CPUCP_PACKET_FENCE_VAL);
239 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &test_pkt,
240 sizeof(test_pkt), 0, &result);
243 if (result != CPUCP_PACKET_FENCE_VAL)
245 "CPU queue test failed (%#08llx)\n", result);
247 dev_err(hdev->dev, "CPU queue test failed, error %d\n", rc);
253 void *hl_fw_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size,
254 dma_addr_t *dma_handle)
258 kernel_addr = gen_pool_alloc(hdev->cpu_accessible_dma_pool, size);
260 *dma_handle = hdev->cpu_accessible_dma_address +
261 (kernel_addr - (u64) (uintptr_t) hdev->cpu_accessible_dma_mem);
263 return (void *) (uintptr_t) kernel_addr;
266 void hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size,
269 gen_pool_free(hdev->cpu_accessible_dma_pool, (u64) (uintptr_t) vaddr,
273 int hl_fw_send_heartbeat(struct hl_device *hdev)
275 struct cpucp_packet hb_pkt = {};
279 hb_pkt.ctl = cpu_to_le32(CPUCP_PACKET_TEST <<
280 CPUCP_PKT_CTL_OPCODE_SHIFT);
281 hb_pkt.value = cpu_to_le64(CPUCP_PACKET_FENCE_VAL);
283 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &hb_pkt,
284 sizeof(hb_pkt), 0, &result);
286 if ((rc) || (result != CPUCP_PACKET_FENCE_VAL))
292 static int fw_read_errors(struct hl_device *hdev, u32 boot_err0_reg,
293 u32 cpu_security_boot_status_reg)
295 u32 err_val, security_val;
297 /* Some of the firmware status codes are deprecated in newer f/w
298 * versions. In those versions, the errors are reported
299 * in different registers. Therefore, we need to check those
300 * registers and print the exact errors. Moreover, there
301 * may be multiple errors, so we need to report on each error
302 * separately. Some of the error codes might indicate a state
303 * that is not an error per-se, but it is an error in production
306 err_val = RREG32(boot_err0_reg);
307 if (!(err_val & CPU_BOOT_ERR0_ENABLED))
310 if (err_val & CPU_BOOT_ERR0_DRAM_INIT_FAIL)
312 "Device boot error - DRAM initialization failed\n");
313 if (err_val & CPU_BOOT_ERR0_FIT_CORRUPTED)
314 dev_err(hdev->dev, "Device boot error - FIT image corrupted\n");
315 if (err_val & CPU_BOOT_ERR0_TS_INIT_FAIL)
317 "Device boot error - Thermal Sensor initialization failed\n");
318 if (err_val & CPU_BOOT_ERR0_DRAM_SKIPPED)
320 "Device boot warning - Skipped DRAM initialization\n");
322 if (err_val & CPU_BOOT_ERR0_BMC_WAIT_SKIPPED) {
323 if (hdev->bmc_enable)
325 "Device boot error - Skipped waiting for BMC\n");
327 err_val &= ~CPU_BOOT_ERR0_BMC_WAIT_SKIPPED;
330 if (err_val & CPU_BOOT_ERR0_NIC_DATA_NOT_RDY)
332 "Device boot error - Serdes data from BMC not available\n");
333 if (err_val & CPU_BOOT_ERR0_NIC_FW_FAIL)
335 "Device boot error - NIC F/W initialization failed\n");
336 if (err_val & CPU_BOOT_ERR0_SECURITY_NOT_RDY)
338 "Device boot warning - security not ready\n");
339 if (err_val & CPU_BOOT_ERR0_SECURITY_FAIL)
340 dev_err(hdev->dev, "Device boot error - security failure\n");
341 if (err_val & CPU_BOOT_ERR0_EFUSE_FAIL)
342 dev_err(hdev->dev, "Device boot error - eFuse failure\n");
343 if (err_val & CPU_BOOT_ERR0_PLL_FAIL)
344 dev_err(hdev->dev, "Device boot error - PLL failure\n");
346 security_val = RREG32(cpu_security_boot_status_reg);
347 if (security_val & CPU_BOOT_DEV_STS0_ENABLED)
348 dev_dbg(hdev->dev, "Device security status %#x\n",
351 if (err_val & ~CPU_BOOT_ERR0_ENABLED)
357 int hl_fw_cpucp_info_get(struct hl_device *hdev,
358 u32 cpu_security_boot_status_reg,
361 struct asic_fixed_properties *prop = &hdev->asic_prop;
362 struct cpucp_packet pkt = {};
363 void *cpucp_info_cpu_addr;
364 dma_addr_t cpucp_info_dma_addr;
368 cpucp_info_cpu_addr =
369 hdev->asic_funcs->cpu_accessible_dma_pool_alloc(hdev,
370 sizeof(struct cpucp_info),
371 &cpucp_info_dma_addr);
372 if (!cpucp_info_cpu_addr) {
374 "Failed to allocate DMA memory for CPU-CP info packet\n");
378 memset(cpucp_info_cpu_addr, 0, sizeof(struct cpucp_info));
380 pkt.ctl = cpu_to_le32(CPUCP_PACKET_INFO_GET <<
381 CPUCP_PKT_CTL_OPCODE_SHIFT);
382 pkt.addr = cpu_to_le64(cpucp_info_dma_addr);
383 pkt.data_max_size = cpu_to_le32(sizeof(struct cpucp_info));
385 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
386 HL_CPUCP_INFO_TIMEOUT_USEC, &result);
389 "Failed to handle CPU-CP info pkt, error %d\n", rc);
393 rc = fw_read_errors(hdev, boot_err0_reg, cpu_security_boot_status_reg);
395 dev_err(hdev->dev, "Errors in device boot\n");
399 memcpy(&prop->cpucp_info, cpucp_info_cpu_addr,
400 sizeof(prop->cpucp_info));
402 rc = hl_build_hwmon_channel_info(hdev, prop->cpucp_info.sensors);
405 "Failed to build hwmon channel info, error %d\n", rc);
410 /* Read FW application security bits again */
411 if (hdev->asic_prop.fw_security_status_valid)
412 hdev->asic_prop.fw_app_security_map =
413 RREG32(cpu_security_boot_status_reg);
416 hdev->asic_funcs->cpu_accessible_dma_pool_free(hdev,
417 sizeof(struct cpucp_info), cpucp_info_cpu_addr);
422 int hl_fw_get_eeprom_data(struct hl_device *hdev, void *data, size_t max_size)
424 struct cpucp_packet pkt = {};
425 void *eeprom_info_cpu_addr;
426 dma_addr_t eeprom_info_dma_addr;
430 eeprom_info_cpu_addr =
431 hdev->asic_funcs->cpu_accessible_dma_pool_alloc(hdev,
432 max_size, &eeprom_info_dma_addr);
433 if (!eeprom_info_cpu_addr) {
435 "Failed to allocate DMA memory for CPU-CP EEPROM packet\n");
439 memset(eeprom_info_cpu_addr, 0, max_size);
441 pkt.ctl = cpu_to_le32(CPUCP_PACKET_EEPROM_DATA_GET <<
442 CPUCP_PKT_CTL_OPCODE_SHIFT);
443 pkt.addr = cpu_to_le64(eeprom_info_dma_addr);
444 pkt.data_max_size = cpu_to_le32(max_size);
446 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
447 HL_CPUCP_EEPROM_TIMEOUT_USEC, &result);
451 "Failed to handle CPU-CP EEPROM packet, error %d\n",
456 /* result contains the actual size */
457 memcpy(data, eeprom_info_cpu_addr, min((size_t)result, max_size));
460 hdev->asic_funcs->cpu_accessible_dma_pool_free(hdev, max_size,
461 eeprom_info_cpu_addr);
466 int hl_fw_cpucp_pci_counters_get(struct hl_device *hdev,
467 struct hl_info_pci_counters *counters)
469 struct cpucp_packet pkt = {};
473 pkt.ctl = cpu_to_le32(CPUCP_PACKET_PCIE_THROUGHPUT_GET <<
474 CPUCP_PKT_CTL_OPCODE_SHIFT);
476 /* Fetch PCI rx counter */
477 pkt.index = cpu_to_le32(cpucp_pcie_throughput_rx);
478 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
479 HL_CPUCP_INFO_TIMEOUT_USEC, &result);
482 "Failed to handle CPU-CP PCI info pkt, error %d\n", rc);
485 counters->rx_throughput = result;
487 memset(&pkt, 0, sizeof(pkt));
488 pkt.ctl = cpu_to_le32(CPUCP_PACKET_PCIE_THROUGHPUT_GET <<
489 CPUCP_PKT_CTL_OPCODE_SHIFT);
491 /* Fetch PCI tx counter */
492 pkt.index = cpu_to_le32(cpucp_pcie_throughput_tx);
493 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
494 HL_CPUCP_INFO_TIMEOUT_USEC, &result);
497 "Failed to handle CPU-CP PCI info pkt, error %d\n", rc);
500 counters->tx_throughput = result;
502 /* Fetch PCI replay counter */
503 memset(&pkt, 0, sizeof(pkt));
504 pkt.ctl = cpu_to_le32(CPUCP_PACKET_PCIE_REPLAY_CNT_GET <<
505 CPUCP_PKT_CTL_OPCODE_SHIFT);
507 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
508 HL_CPUCP_INFO_TIMEOUT_USEC, &result);
511 "Failed to handle CPU-CP PCI info pkt, error %d\n", rc);
514 counters->replay_cnt = (u32) result;
519 int hl_fw_cpucp_total_energy_get(struct hl_device *hdev, u64 *total_energy)
521 struct cpucp_packet pkt = {};
525 pkt.ctl = cpu_to_le32(CPUCP_PACKET_TOTAL_ENERGY_GET <<
526 CPUCP_PKT_CTL_OPCODE_SHIFT);
528 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
529 HL_CPUCP_INFO_TIMEOUT_USEC, &result);
532 "Failed to handle CpuCP total energy pkt, error %d\n",
537 *total_energy = result;
542 int hl_fw_cpucp_pll_info_get(struct hl_device *hdev, u16 pll_index,
545 struct cpucp_packet pkt;
549 memset(&pkt, 0, sizeof(pkt));
551 pkt.ctl = cpu_to_le32(CPUCP_PACKET_PLL_INFO_GET <<
552 CPUCP_PKT_CTL_OPCODE_SHIFT);
553 pkt.pll_type = __cpu_to_le16(pll_index);
555 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
556 HL_CPUCP_INFO_TIMEOUT_USEC, &result);
558 dev_err(hdev->dev, "Failed to read PLL info, error %d\n", rc);
560 pll_freq_arr[0] = FIELD_GET(CPUCP_PKT_RES_PLL_OUT0_MASK, result);
561 pll_freq_arr[1] = FIELD_GET(CPUCP_PKT_RES_PLL_OUT1_MASK, result);
562 pll_freq_arr[2] = FIELD_GET(CPUCP_PKT_RES_PLL_OUT2_MASK, result);
563 pll_freq_arr[3] = FIELD_GET(CPUCP_PKT_RES_PLL_OUT3_MASK, result);
568 static void detect_cpu_boot_status(struct hl_device *hdev, u32 status)
570 /* Some of the status codes below are deprecated in newer f/w
571 * versions but we keep them here for backward compatibility
574 case CPU_BOOT_STATUS_NA:
576 "Device boot error - BTL did NOT run\n");
578 case CPU_BOOT_STATUS_IN_WFE:
580 "Device boot error - Stuck inside WFE loop\n");
582 case CPU_BOOT_STATUS_IN_BTL:
584 "Device boot error - Stuck in BTL\n");
586 case CPU_BOOT_STATUS_IN_PREBOOT:
588 "Device boot error - Stuck in Preboot\n");
590 case CPU_BOOT_STATUS_IN_SPL:
592 "Device boot error - Stuck in SPL\n");
594 case CPU_BOOT_STATUS_IN_UBOOT:
596 "Device boot error - Stuck in u-boot\n");
598 case CPU_BOOT_STATUS_DRAM_INIT_FAIL:
600 "Device boot error - DRAM initialization failed\n");
602 case CPU_BOOT_STATUS_UBOOT_NOT_READY:
604 "Device boot error - u-boot stopped by user\n");
606 case CPU_BOOT_STATUS_TS_INIT_FAIL:
608 "Device boot error - Thermal Sensor initialization failed\n");
612 "Device boot error - Invalid status code %d\n",
618 int hl_fw_read_preboot_status(struct hl_device *hdev, u32 cpu_boot_status_reg,
619 u32 cpu_security_boot_status_reg, u32 boot_err0_reg,
622 struct asic_fixed_properties *prop = &hdev->asic_prop;
623 u32 status, security_status;
626 if (!hdev->cpu_enable)
629 /* Need to check two possible scenarios:
631 * CPU_BOOT_STATUS_WAITING_FOR_BOOT_FIT - for newer firmwares where
632 * the preboot is waiting for the boot fit
634 * All other status values - for older firmwares where the uboot was
635 * loaded from the FLASH
637 rc = hl_poll_timeout(
641 (status == CPU_BOOT_STATUS_IN_UBOOT) ||
642 (status == CPU_BOOT_STATUS_DRAM_RDY) ||
643 (status == CPU_BOOT_STATUS_NIC_FW_RDY) ||
644 (status == CPU_BOOT_STATUS_READY_TO_BOOT) ||
645 (status == CPU_BOOT_STATUS_SRAM_AVAIL) ||
646 (status == CPU_BOOT_STATUS_WAITING_FOR_BOOT_FIT),
651 dev_err(hdev->dev, "Failed to read preboot version\n");
652 detect_cpu_boot_status(hdev, status);
653 fw_read_errors(hdev, boot_err0_reg,
654 cpu_security_boot_status_reg);
658 rc = hdev->asic_funcs->read_device_fw_version(hdev, FW_COMP_PREBOOT);
662 security_status = RREG32(cpu_security_boot_status_reg);
664 /* We read security status multiple times during boot:
665 * 1. preboot - a. Check whether the security status bits are valid
666 * b. Check whether fw security is enabled
667 * c. Check whether hard reset is done by preboot
668 * 2. boot cpu - a. Fetch boot cpu security status
669 * b. Check whether hard reset is done by boot cpu
670 * 3. FW application - a. Fetch fw application security status
671 * b. Check whether hard reset is done by fw app
674 * Check security status bit (CPU_BOOT_DEV_STS0_ENABLED), if it is set
675 * check security enabled bit (CPU_BOOT_DEV_STS0_SECURITY_EN)
677 if (security_status & CPU_BOOT_DEV_STS0_ENABLED) {
678 prop->fw_security_status_valid = 1;
680 if (security_status & CPU_BOOT_DEV_STS0_SECURITY_EN)
681 prop->fw_security_disabled = false;
683 prop->fw_security_disabled = true;
685 if (security_status & CPU_BOOT_DEV_STS0_FW_HARD_RST_EN)
686 prop->hard_reset_done_by_fw = true;
688 prop->fw_security_status_valid = 0;
689 prop->fw_security_disabled = true;
692 dev_dbg(hdev->dev, "Firmware preboot security status %#x\n",
695 dev_dbg(hdev->dev, "Firmware preboot hard-reset is %s\n",
696 prop->hard_reset_done_by_fw ? "enabled" : "disabled");
698 dev_info(hdev->dev, "firmware-level security is %s\n",
699 prop->fw_security_disabled ? "disabled" : "enabled");
704 int hl_fw_init_cpu(struct hl_device *hdev, u32 cpu_boot_status_reg,
705 u32 msg_to_cpu_reg, u32 cpu_msg_status_reg,
706 u32 cpu_security_boot_status_reg, u32 boot_err0_reg,
707 bool skip_bmc, u32 cpu_timeout, u32 boot_fit_timeout)
709 struct asic_fixed_properties *prop = &hdev->asic_prop;
713 if (!(hdev->fw_loading & FW_TYPE_BOOT_CPU))
716 dev_info(hdev->dev, "Going to wait for device boot (up to %lds)\n",
717 cpu_timeout / USEC_PER_SEC);
719 /* Wait for boot FIT request */
720 rc = hl_poll_timeout(
724 status == CPU_BOOT_STATUS_WAITING_FOR_BOOT_FIT,
730 "No boot fit request received, resuming boot\n");
732 rc = hdev->asic_funcs->load_boot_fit_to_device(hdev);
736 /* Clear device CPU message status */
737 WREG32(cpu_msg_status_reg, CPU_MSG_CLR);
739 /* Signal device CPU that boot loader is ready */
740 WREG32(msg_to_cpu_reg, KMD_MSG_FIT_RDY);
742 /* Poll for CPU device ack */
743 rc = hl_poll_timeout(
747 status == CPU_MSG_OK,
753 "Timeout waiting for boot fit load ack\n");
758 WREG32(msg_to_cpu_reg, KMD_MSG_NA);
761 /* Make sure CPU boot-loader is running */
762 rc = hl_poll_timeout(
766 (status == CPU_BOOT_STATUS_DRAM_RDY) ||
767 (status == CPU_BOOT_STATUS_NIC_FW_RDY) ||
768 (status == CPU_BOOT_STATUS_READY_TO_BOOT) ||
769 (status == CPU_BOOT_STATUS_SRAM_AVAIL),
773 dev_dbg(hdev->dev, "uboot status = %d\n", status);
775 /* Read U-Boot version now in case we will later fail */
776 hdev->asic_funcs->read_device_fw_version(hdev, FW_COMP_UBOOT);
778 /* Clear reset status since we need to read it again from boot CPU */
779 prop->hard_reset_done_by_fw = false;
781 /* Read boot_cpu security bits */
782 if (prop->fw_security_status_valid) {
783 prop->fw_boot_cpu_security_map =
784 RREG32(cpu_security_boot_status_reg);
786 if (prop->fw_boot_cpu_security_map &
787 CPU_BOOT_DEV_STS0_FW_HARD_RST_EN)
788 prop->hard_reset_done_by_fw = true;
791 "Firmware boot CPU security status %#x\n",
792 prop->fw_boot_cpu_security_map);
795 dev_dbg(hdev->dev, "Firmware boot CPU hard-reset is %s\n",
796 prop->hard_reset_done_by_fw ? "enabled" : "disabled");
799 detect_cpu_boot_status(hdev, status);
804 if (!(hdev->fw_loading & FW_TYPE_LINUX)) {
805 dev_info(hdev->dev, "Skip loading Linux F/W\n");
809 if (status == CPU_BOOT_STATUS_SRAM_AVAIL)
813 "Loading firmware to device, may take some time...\n");
815 rc = hdev->asic_funcs->load_firmware_to_device(hdev);
820 WREG32(msg_to_cpu_reg, KMD_MSG_SKIP_BMC);
822 rc = hl_poll_timeout(
826 (status == CPU_BOOT_STATUS_BMC_WAITING_SKIPPED),
832 "Failed to get ACK on skipping BMC, %d\n",
834 WREG32(msg_to_cpu_reg, KMD_MSG_NA);
840 WREG32(msg_to_cpu_reg, KMD_MSG_FIT_RDY);
842 rc = hl_poll_timeout(
846 (status == CPU_BOOT_STATUS_SRAM_AVAIL),
851 WREG32(msg_to_cpu_reg, KMD_MSG_NA);
854 if (status == CPU_BOOT_STATUS_FIT_CORRUPTED)
856 "Device reports FIT image is corrupted\n");
859 "Failed to load firmware to device, %d\n",
866 rc = fw_read_errors(hdev, boot_err0_reg, cpu_security_boot_status_reg);
870 /* Clear reset status since we need to read again from app */
871 prop->hard_reset_done_by_fw = false;
873 /* Read FW application security bits */
874 if (prop->fw_security_status_valid) {
875 prop->fw_app_security_map =
876 RREG32(cpu_security_boot_status_reg);
878 if (prop->fw_app_security_map &
879 CPU_BOOT_DEV_STS0_FW_HARD_RST_EN)
880 prop->hard_reset_done_by_fw = true;
883 "Firmware application CPU security status %#x\n",
884 prop->fw_app_security_map);
887 dev_dbg(hdev->dev, "Firmware application CPU hard-reset is %s\n",
888 prop->hard_reset_done_by_fw ? "enabled" : "disabled");
890 dev_info(hdev->dev, "Successfully loaded firmware to device\n");
895 fw_read_errors(hdev, boot_err0_reg, cpu_security_boot_status_reg);