2019-03-04 08:22:09 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2016-2019 HabanaLabs, Ltd.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "habanalabs.h"
|
2020-07-28 17:18:51 +00:00
|
|
|
#include "../include/common/hl_boot_if.h"
|
2019-03-04 08:22:09 +00:00
|
|
|
|
|
|
|
#include <linux/firmware.h>
|
2020-05-10 10:41:28 +00:00
|
|
|
#include <linux/slab.h>
|
2019-03-04 08:22:09 +00:00
|
|
|
|
2020-08-11 06:19:53 +00:00
|
|
|
#define FW_FILE_MAX_SIZE 0x1400000 /* maximum size of 20MB */
|
2019-03-04 08:22:09 +00:00
|
|
|
/**
|
2020-03-26 10:32:56 +00:00
|
|
|
* hl_fw_load_fw_to_device() - Load F/W code to device's memory.
|
2020-07-01 08:58:36 +00:00
|
|
|
*
|
2019-03-04 08:22:09 +00:00
|
|
|
* @hdev: pointer to hl_device structure.
|
2020-07-01 08:58:36 +00:00
|
|
|
* @fw_name: the firmware image name
|
|
|
|
* @dst: IO memory mapped address space to copy firmware to
|
2020-10-20 07:45:37 +00:00
|
|
|
* @src_offset: offset in src FW to copy from
|
|
|
|
* @size: amount of bytes to copy (0 to copy the whole binary)
|
2019-03-04 08:22:09 +00:00
|
|
|
*
|
|
|
|
* Copy fw code from firmware file to device memory.
|
|
|
|
*
|
|
|
|
* Return: 0 on success, non-zero for failure.
|
|
|
|
*/
|
2020-03-26 10:32:56 +00:00
|
|
|
int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,
|
2020-10-20 07:45:37 +00:00
|
|
|
void __iomem *dst, u32 src_offset, u32 size)
|
2019-03-04 08:22:09 +00:00
|
|
|
{
|
|
|
|
const struct firmware *fw;
|
2020-10-20 07:45:37 +00:00
|
|
|
const void *fw_data;
|
2019-07-23 08:22:42 +00:00
|
|
|
size_t fw_size;
|
2019-03-04 08:22:09 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = request_firmware(&fw, fw_name, hdev->dev);
|
|
|
|
if (rc) {
|
2019-05-04 13:43:20 +00:00
|
|
|
dev_err(hdev->dev, "Firmware file %s is not found!\n", fw_name);
|
2019-03-04 08:22:09 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
fw_size = fw->size;
|
|
|
|
if ((fw_size % 4) != 0) {
|
2019-05-04 13:43:20 +00:00
|
|
|
dev_err(hdev->dev, "Illegal %s firmware size %zu\n",
|
2019-03-04 08:22:09 +00:00
|
|
|
fw_name, fw_size);
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(hdev->dev, "%s firmware size == %zu\n", fw_name, fw_size);
|
|
|
|
|
2020-08-11 06:19:53 +00:00
|
|
|
if (fw_size > FW_FILE_MAX_SIZE) {
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"FW file size %zu exceeds maximum of %u bytes\n",
|
|
|
|
fw_size, FW_FILE_MAX_SIZE);
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2020-10-20 07:45:37 +00:00
|
|
|
if (size - src_offset > fw_size) {
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"size to copy(%u) and offset(%u) are invalid\n",
|
|
|
|
size, src_offset);
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size)
|
|
|
|
fw_size = size;
|
|
|
|
|
|
|
|
fw_data = (const void *) fw->data;
|
2019-03-04 08:22:09 +00:00
|
|
|
|
2020-10-20 07:45:37 +00:00
|
|
|
memcpy_toio(dst, fw_data + src_offset, fw_size);
|
2019-03-04 08:22:09 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
release_firmware(fw);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode)
|
|
|
|
{
|
2020-08-15 13:28:10 +00:00
|
|
|
struct cpucp_packet pkt = {};
|
2019-03-04 08:22:09 +00:00
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
pkt.ctl = cpu_to_le32(opcode << CPUCP_PKT_CTL_OPCODE_SHIFT);
|
2019-03-04 08:22:09 +00:00
|
|
|
|
|
|
|
return hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt,
|
2020-07-07 14:30:13 +00:00
|
|
|
sizeof(pkt), 0, NULL);
|
2019-03-04 08:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,
|
2020-11-10 11:49:10 +00:00
|
|
|
u16 len, u32 timeout, u64 *result)
|
2019-03-04 08:22:09 +00:00
|
|
|
{
|
2020-08-15 13:28:10 +00:00
|
|
|
struct cpucp_packet *pkt;
|
2019-03-04 08:22:09 +00:00
|
|
|
dma_addr_t pkt_dma_addr;
|
|
|
|
u32 tmp;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
pkt = hdev->asic_funcs->cpu_accessible_dma_pool_alloc(hdev, len,
|
|
|
|
&pkt_dma_addr);
|
|
|
|
if (!pkt) {
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Failed to allocate DMA memory for packet to CPU\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(pkt, msg, len);
|
|
|
|
|
|
|
|
mutex_lock(&hdev->send_cpu_message_lock);
|
|
|
|
|
|
|
|
if (hdev->disabled)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (hdev->device_cpu_disabled) {
|
|
|
|
rc = -EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = hl_hw_queue_send_cb_no_cmpl(hdev, hw_queue_id, len, pkt_dma_addr);
|
|
|
|
if (rc) {
|
|
|
|
dev_err(hdev->dev, "Failed to send CB on CPU PQ (%d)\n", rc);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-05-08 22:48:23 +00:00
|
|
|
rc = hl_poll_timeout_memory(hdev, &pkt->fence, tmp,
|
2020-08-15 13:28:10 +00:00
|
|
|
(tmp == CPUCP_PACKET_FENCE_VAL), 1000,
|
2019-07-18 12:27:00 +00:00
|
|
|
timeout, true);
|
2019-03-04 08:22:09 +00:00
|
|
|
|
|
|
|
hl_hw_queue_inc_ci_kernel(hdev, hw_queue_id);
|
|
|
|
|
|
|
|
if (rc == -ETIMEDOUT) {
|
2019-05-08 22:48:23 +00:00
|
|
|
dev_err(hdev->dev, "Device CPU packet timeout (0x%x)\n", tmp);
|
2019-03-04 08:22:09 +00:00
|
|
|
hdev->device_cpu_disabled = true;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-05-08 22:48:23 +00:00
|
|
|
tmp = le32_to_cpu(pkt->ctl);
|
2019-03-04 08:22:09 +00:00
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
rc = (tmp & CPUCP_PKT_CTL_RC_MASK) >> CPUCP_PKT_CTL_RC_SHIFT;
|
2019-05-08 22:48:23 +00:00
|
|
|
if (rc) {
|
|
|
|
dev_err(hdev->dev, "F/W ERROR %d for CPU packet %d\n",
|
|
|
|
rc,
|
2020-08-15 13:28:10 +00:00
|
|
|
(tmp & CPUCP_PKT_CTL_OPCODE_MASK)
|
|
|
|
>> CPUCP_PKT_CTL_OPCODE_SHIFT);
|
2019-05-08 22:48:23 +00:00
|
|
|
rc = -EIO;
|
|
|
|
} else if (result) {
|
2020-11-10 11:49:10 +00:00
|
|
|
*result = le64_to_cpu(pkt->result);
|
2019-03-04 08:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_unlock(&hdev->send_cpu_message_lock);
|
|
|
|
|
|
|
|
hdev->asic_funcs->cpu_accessible_dma_pool_free(hdev, len, pkt);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2020-05-10 10:41:28 +00:00
|
|
|
int hl_fw_unmask_irq(struct hl_device *hdev, u16 event_type)
|
|
|
|
{
|
2020-08-15 13:28:10 +00:00
|
|
|
struct cpucp_packet pkt;
|
2020-11-10 11:49:10 +00:00
|
|
|
u64 result;
|
2020-05-10 10:41:28 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
memset(&pkt, 0, sizeof(pkt));
|
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
pkt.ctl = cpu_to_le32(CPUCP_PACKET_UNMASK_RAZWI_IRQ <<
|
|
|
|
CPUCP_PKT_CTL_OPCODE_SHIFT);
|
2020-05-10 10:41:28 +00:00
|
|
|
pkt.value = cpu_to_le64(event_type);
|
|
|
|
|
|
|
|
rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
|
2020-07-07 14:30:13 +00:00
|
|
|
0, &result);
|
2020-05-10 10:41:28 +00:00
|
|
|
|
|
|
|
if (rc)
|
|
|
|
dev_err(hdev->dev, "failed to unmask RAZWI IRQ %d", event_type);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int hl_fw_unmask_irq_arr(struct hl_device *hdev, const u32 *irq_arr,
|
|
|
|
size_t irq_arr_size)
|
|
|
|
{
|
2020-08-15 13:28:10 +00:00
|
|
|
struct cpucp_unmask_irq_arr_packet *pkt;
|
2020-05-10 10:41:28 +00:00
|
|
|
size_t total_pkt_size;
|
2020-11-10 11:49:10 +00:00
|
|
|
u64 result;
|
2020-05-10 10:41:28 +00:00
|
|
|
int rc;
|
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
total_pkt_size = sizeof(struct cpucp_unmask_irq_arr_packet) +
|
2020-05-10 10:41:28 +00:00
|
|
|
irq_arr_size;
|
|
|
|
|
2020-09-04 17:18:16 +00:00
|
|
|
/* data should be aligned to 8 bytes in order to CPU-CP to copy it */
|
2020-05-10 10:41:28 +00:00
|
|
|
total_pkt_size = (total_pkt_size + 0x7) & ~0x7;
|
|
|
|
|
|
|
|
/* total_pkt_size is casted to u16 later on */
|
|
|
|
if (total_pkt_size > USHRT_MAX) {
|
|
|
|
dev_err(hdev->dev, "too many elements in IRQ array\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pkt = kzalloc(total_pkt_size, GFP_KERNEL);
|
|
|
|
if (!pkt)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pkt->length = cpu_to_le32(irq_arr_size / sizeof(irq_arr[0]));
|
|
|
|
memcpy(&pkt->irqs, irq_arr, irq_arr_size);
|
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
pkt->cpucp_pkt.ctl = cpu_to_le32(CPUCP_PACKET_UNMASK_RAZWI_IRQ_ARRAY <<
|
|
|
|
CPUCP_PKT_CTL_OPCODE_SHIFT);
|
2020-05-10 10:41:28 +00:00
|
|
|
|
|
|
|
rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) pkt,
|
2020-07-07 14:30:13 +00:00
|
|
|
total_pkt_size, 0, &result);
|
2020-05-10 10:41:28 +00:00
|
|
|
|
|
|
|
if (rc)
|
|
|
|
dev_err(hdev->dev, "failed to unmask IRQ array\n");
|
|
|
|
|
|
|
|
kfree(pkt);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2019-03-04 08:22:09 +00:00
|
|
|
int hl_fw_test_cpu_queue(struct hl_device *hdev)
|
|
|
|
{
|
2020-08-15 13:28:10 +00:00
|
|
|
struct cpucp_packet test_pkt = {};
|
2020-11-10 11:49:10 +00:00
|
|
|
u64 result;
|
2019-03-04 08:22:09 +00:00
|
|
|
int rc;
|
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
test_pkt.ctl = cpu_to_le32(CPUCP_PACKET_TEST <<
|
|
|
|
CPUCP_PKT_CTL_OPCODE_SHIFT);
|
|
|
|
test_pkt.value = cpu_to_le64(CPUCP_PACKET_FENCE_VAL);
|
2019-03-04 08:22:09 +00:00
|
|
|
|
|
|
|
rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &test_pkt,
|
2020-07-07 14:30:13 +00:00
|
|
|
sizeof(test_pkt), 0, &result);
|
2019-03-04 08:22:09 +00:00
|
|
|
|
|
|
|
if (!rc) {
|
2020-08-15 13:28:10 +00:00
|
|
|
if (result != CPUCP_PACKET_FENCE_VAL)
|
2019-03-04 08:22:09 +00:00
|
|
|
dev_err(hdev->dev,
|
2020-11-10 11:49:10 +00:00
|
|
|
"CPU queue test failed (%#08llx)\n", result);
|
2019-03-04 08:22:09 +00:00
|
|
|
} else {
|
|
|
|
dev_err(hdev->dev, "CPU queue test failed, error %d\n", rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *hl_fw_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size,
|
|
|
|
dma_addr_t *dma_handle)
|
|
|
|
{
|
|
|
|
u64 kernel_addr;
|
|
|
|
|
|
|
|
kernel_addr = gen_pool_alloc(hdev->cpu_accessible_dma_pool, size);
|
|
|
|
|
|
|
|
*dma_handle = hdev->cpu_accessible_dma_address +
|
|
|
|
(kernel_addr - (u64) (uintptr_t) hdev->cpu_accessible_dma_mem);
|
|
|
|
|
|
|
|
return (void *) (uintptr_t) kernel_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void hl_fw_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size,
|
|
|
|
void *vaddr)
|
|
|
|
{
|
|
|
|
gen_pool_free(hdev->cpu_accessible_dma_pool, (u64) (uintptr_t) vaddr,
|
|
|
|
size);
|
|
|
|
}
|
|
|
|
|
|
|
|
int hl_fw_send_heartbeat(struct hl_device *hdev)
|
|
|
|
{
|
2020-08-15 13:28:10 +00:00
|
|
|
struct cpucp_packet hb_pkt = {};
|
2020-11-10 11:49:10 +00:00
|
|
|
u64 result;
|
2019-03-04 08:22:09 +00:00
|
|
|
int rc;
|
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
hb_pkt.ctl = cpu_to_le32(CPUCP_PACKET_TEST <<
|
|
|
|
CPUCP_PKT_CTL_OPCODE_SHIFT);
|
|
|
|
hb_pkt.value = cpu_to_le64(CPUCP_PACKET_FENCE_VAL);
|
2019-03-04 08:22:09 +00:00
|
|
|
|
|
|
|
rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &hb_pkt,
|
2020-07-07 14:30:13 +00:00
|
|
|
sizeof(hb_pkt), 0, &result);
|
2019-03-04 08:22:09 +00:00
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
if ((rc) || (result != CPUCP_PACKET_FENCE_VAL))
|
2019-03-04 08:22:09 +00:00
|
|
|
rc = -EIO;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2020-11-17 12:25:14 +00:00
|
|
|
int hl_fw_cpucp_info_get(struct hl_device *hdev,
|
|
|
|
u32 cpu_security_boot_status_reg)
|
2019-03-04 08:22:09 +00:00
|
|
|
{
|
|
|
|
struct asic_fixed_properties *prop = &hdev->asic_prop;
|
2020-08-15 13:28:10 +00:00
|
|
|
struct cpucp_packet pkt = {};
|
|
|
|
void *cpucp_info_cpu_addr;
|
|
|
|
dma_addr_t cpucp_info_dma_addr;
|
2020-11-10 11:49:10 +00:00
|
|
|
u64 result;
|
2019-03-04 08:22:09 +00:00
|
|
|
int rc;
|
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
cpucp_info_cpu_addr =
|
2019-03-04 08:22:09 +00:00
|
|
|
hdev->asic_funcs->cpu_accessible_dma_pool_alloc(hdev,
|
2020-08-15 13:28:10 +00:00
|
|
|
sizeof(struct cpucp_info),
|
|
|
|
&cpucp_info_dma_addr);
|
|
|
|
if (!cpucp_info_cpu_addr) {
|
2019-03-04 08:22:09 +00:00
|
|
|
dev_err(hdev->dev,
|
2020-09-04 17:18:16 +00:00
|
|
|
"Failed to allocate DMA memory for CPU-CP info packet\n");
|
2019-03-04 08:22:09 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
memset(cpucp_info_cpu_addr, 0, sizeof(struct cpucp_info));
|
2019-03-04 08:22:09 +00:00
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
pkt.ctl = cpu_to_le32(CPUCP_PACKET_INFO_GET <<
|
|
|
|
CPUCP_PKT_CTL_OPCODE_SHIFT);
|
|
|
|
pkt.addr = cpu_to_le64(cpucp_info_dma_addr);
|
|
|
|
pkt.data_max_size = cpu_to_le32(sizeof(struct cpucp_info));
|
2019-03-04 08:22:09 +00:00
|
|
|
|
|
|
|
rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
|
2020-08-15 13:28:10 +00:00
|
|
|
HL_CPUCP_INFO_TIMEOUT_USEC, &result);
|
2019-03-04 08:22:09 +00:00
|
|
|
if (rc) {
|
|
|
|
dev_err(hdev->dev,
|
2020-09-04 17:18:16 +00:00
|
|
|
"Failed to handle CPU-CP info pkt, error %d\n", rc);
|
2019-03-04 08:22:09 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
memcpy(&prop->cpucp_info, cpucp_info_cpu_addr,
|
|
|
|
sizeof(prop->cpucp_info));
|
2019-03-04 08:22:09 +00:00
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
rc = hl_build_hwmon_channel_info(hdev, prop->cpucp_info.sensors);
|
2019-03-04 08:22:09 +00:00
|
|
|
if (rc) {
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Failed to build hwmon channel info, error %d\n", rc);
|
|
|
|
rc = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2020-11-17 12:25:14 +00:00
|
|
|
/* Read FW application security bits again */
|
|
|
|
if (hdev->asic_prop.fw_security_status_valid)
|
|
|
|
hdev->asic_prop.fw_app_security_map =
|
|
|
|
RREG32(cpu_security_boot_status_reg);
|
|
|
|
|
2019-03-04 08:22:09 +00:00
|
|
|
out:
|
|
|
|
hdev->asic_funcs->cpu_accessible_dma_pool_free(hdev,
|
2020-08-15 13:28:10 +00:00
|
|
|
sizeof(struct cpucp_info), cpucp_info_cpu_addr);
|
2019-03-04 08:22:09 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int hl_fw_get_eeprom_data(struct hl_device *hdev, void *data, size_t max_size)
|
|
|
|
{
|
2020-08-15 13:28:10 +00:00
|
|
|
struct cpucp_packet pkt = {};
|
2019-03-04 08:22:09 +00:00
|
|
|
void *eeprom_info_cpu_addr;
|
|
|
|
dma_addr_t eeprom_info_dma_addr;
|
2020-11-10 11:49:10 +00:00
|
|
|
u64 result;
|
2019-03-04 08:22:09 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
eeprom_info_cpu_addr =
|
|
|
|
hdev->asic_funcs->cpu_accessible_dma_pool_alloc(hdev,
|
|
|
|
max_size, &eeprom_info_dma_addr);
|
|
|
|
if (!eeprom_info_cpu_addr) {
|
|
|
|
dev_err(hdev->dev,
|
2020-09-04 17:18:16 +00:00
|
|
|
"Failed to allocate DMA memory for CPU-CP EEPROM packet\n");
|
2019-03-04 08:22:09 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(eeprom_info_cpu_addr, 0, max_size);
|
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
pkt.ctl = cpu_to_le32(CPUCP_PACKET_EEPROM_DATA_GET <<
|
|
|
|
CPUCP_PKT_CTL_OPCODE_SHIFT);
|
2019-05-01 08:28:15 +00:00
|
|
|
pkt.addr = cpu_to_le64(eeprom_info_dma_addr);
|
2019-03-04 08:22:09 +00:00
|
|
|
pkt.data_max_size = cpu_to_le32(max_size);
|
|
|
|
|
|
|
|
rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
|
2020-08-15 13:28:10 +00:00
|
|
|
HL_CPUCP_EEPROM_TIMEOUT_USEC, &result);
|
2019-03-04 08:22:09 +00:00
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
dev_err(hdev->dev,
|
2020-09-04 17:18:16 +00:00
|
|
|
"Failed to handle CPU-CP EEPROM packet, error %d\n",
|
|
|
|
rc);
|
2019-03-04 08:22:09 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* result contains the actual size */
|
|
|
|
memcpy(data, eeprom_info_cpu_addr, min((size_t)result, max_size));
|
|
|
|
|
|
|
|
out:
|
|
|
|
hdev->asic_funcs->cpu_accessible_dma_pool_free(hdev, max_size,
|
|
|
|
eeprom_info_cpu_addr);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2020-03-26 10:32:56 +00:00
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
int hl_fw_cpucp_pci_counters_get(struct hl_device *hdev,
|
2020-07-21 07:49:51 +00:00
|
|
|
struct hl_info_pci_counters *counters)
|
|
|
|
{
|
2020-08-15 13:28:10 +00:00
|
|
|
struct cpucp_packet pkt = {};
|
2020-11-10 11:49:10 +00:00
|
|
|
u64 result;
|
2020-07-21 07:49:51 +00:00
|
|
|
int rc;
|
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
pkt.ctl = cpu_to_le32(CPUCP_PACKET_PCIE_THROUGHPUT_GET <<
|
|
|
|
CPUCP_PKT_CTL_OPCODE_SHIFT);
|
2020-07-21 07:49:51 +00:00
|
|
|
|
|
|
|
/* Fetch PCI rx counter */
|
2020-08-15 13:28:10 +00:00
|
|
|
pkt.index = cpu_to_le32(cpucp_pcie_throughput_rx);
|
2020-07-21 07:49:51 +00:00
|
|
|
rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
|
2020-08-15 13:28:10 +00:00
|
|
|
HL_CPUCP_INFO_TIMEOUT_USEC, &result);
|
2020-07-21 07:49:51 +00:00
|
|
|
if (rc) {
|
|
|
|
dev_err(hdev->dev,
|
2020-09-04 17:18:16 +00:00
|
|
|
"Failed to handle CPU-CP PCI info pkt, error %d\n", rc);
|
2020-07-21 07:49:51 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
counters->rx_throughput = result;
|
|
|
|
|
|
|
|
/* Fetch PCI tx counter */
|
2020-08-15 13:28:10 +00:00
|
|
|
pkt.index = cpu_to_le32(cpucp_pcie_throughput_tx);
|
2020-07-21 07:49:51 +00:00
|
|
|
rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
|
2020-08-15 13:28:10 +00:00
|
|
|
HL_CPUCP_INFO_TIMEOUT_USEC, &result);
|
2020-07-21 07:49:51 +00:00
|
|
|
if (rc) {
|
|
|
|
dev_err(hdev->dev,
|
2020-09-04 17:18:16 +00:00
|
|
|
"Failed to handle CPU-CP PCI info pkt, error %d\n", rc);
|
2020-07-21 07:49:51 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
counters->tx_throughput = result;
|
|
|
|
|
|
|
|
/* Fetch PCI replay counter */
|
2020-08-15 13:28:10 +00:00
|
|
|
pkt.ctl = cpu_to_le32(CPUCP_PACKET_PCIE_REPLAY_CNT_GET <<
|
|
|
|
CPUCP_PKT_CTL_OPCODE_SHIFT);
|
2020-07-21 07:49:51 +00:00
|
|
|
|
|
|
|
rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
|
2020-08-15 13:28:10 +00:00
|
|
|
HL_CPUCP_INFO_TIMEOUT_USEC, &result);
|
2020-07-21 07:49:51 +00:00
|
|
|
if (rc) {
|
|
|
|
dev_err(hdev->dev,
|
2020-09-04 17:18:16 +00:00
|
|
|
"Failed to handle CPU-CP PCI info pkt, error %d\n", rc);
|
2020-07-21 07:49:51 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
counters->replay_cnt = (u32) result;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
int hl_fw_cpucp_total_energy_get(struct hl_device *hdev, u64 *total_energy)
|
2020-08-09 13:25:53 +00:00
|
|
|
{
|
2020-08-15 13:28:10 +00:00
|
|
|
struct cpucp_packet pkt = {};
|
2020-11-10 11:49:10 +00:00
|
|
|
u64 result;
|
2020-08-09 13:25:53 +00:00
|
|
|
int rc;
|
|
|
|
|
2020-08-15 13:28:10 +00:00
|
|
|
pkt.ctl = cpu_to_le32(CPUCP_PACKET_TOTAL_ENERGY_GET <<
|
|
|
|
CPUCP_PKT_CTL_OPCODE_SHIFT);
|
2020-08-09 13:25:53 +00:00
|
|
|
|
|
|
|
rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
|
2020-08-15 13:28:10 +00:00
|
|
|
HL_CPUCP_INFO_TIMEOUT_USEC, &result);
|
2020-08-09 13:25:53 +00:00
|
|
|
if (rc) {
|
|
|
|
dev_err(hdev->dev,
|
2020-08-15 13:28:10 +00:00
|
|
|
"Failed to handle CpuCP total energy pkt, error %d\n",
|
2020-08-09 13:25:53 +00:00
|
|
|
rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
*total_energy = result;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2020-11-17 12:25:14 +00:00
|
|
|
int hl_fw_cpucp_pll_info_get(struct hl_device *hdev, u16 pll_index,
|
|
|
|
u16 *pll_freq_arr)
|
2020-10-05 08:36:00 +00:00
|
|
|
{
|
|
|
|
struct cpucp_packet pkt;
|
2020-11-10 11:49:10 +00:00
|
|
|
u64 result;
|
2020-10-05 08:36:00 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
memset(&pkt, 0, sizeof(pkt));
|
|
|
|
|
2020-11-17 12:25:14 +00:00
|
|
|
pkt.ctl = cpu_to_le32(CPUCP_PACKET_PLL_INFO_GET <<
|
2020-10-05 08:36:00 +00:00
|
|
|
CPUCP_PKT_CTL_OPCODE_SHIFT);
|
2020-11-17 12:25:14 +00:00
|
|
|
pkt.pll_type = __cpu_to_le16(pll_index);
|
2020-10-05 08:36:00 +00:00
|
|
|
|
|
|
|
rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
|
|
|
|
HL_CPUCP_INFO_TIMEOUT_USEC, &result);
|
|
|
|
if (rc)
|
|
|
|
dev_err(hdev->dev, "Failed to read PLL info, error %d\n", rc);
|
|
|
|
|
2020-11-17 12:25:14 +00:00
|
|
|
pll_freq_arr[0] = FIELD_GET(CPUCP_PKT_RES_PLL_OUT0_MASK, result);
|
|
|
|
pll_freq_arr[1] = FIELD_GET(CPUCP_PKT_RES_PLL_OUT1_MASK, result);
|
|
|
|
pll_freq_arr[2] = FIELD_GET(CPUCP_PKT_RES_PLL_OUT2_MASK, result);
|
|
|
|
pll_freq_arr[3] = FIELD_GET(CPUCP_PKT_RES_PLL_OUT3_MASK, result);
|
2020-10-05 08:36:00 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2020-10-04 06:09:19 +00:00
|
|
|
static void fw_read_errors(struct hl_device *hdev, u32 boot_err0_reg,
|
|
|
|
u32 cpu_security_boot_status_reg)
|
2020-03-26 10:32:56 +00:00
|
|
|
{
|
2020-10-04 06:09:19 +00:00
|
|
|
u32 err_val, security_val;
|
2020-03-26 10:32:56 +00:00
|
|
|
|
|
|
|
/* Some of the firmware status codes are deprecated in newer f/w
|
|
|
|
* versions. In those versions, the errors are reported
|
|
|
|
* in different registers. Therefore, we need to check those
|
|
|
|
* registers and print the exact errors. Moreover, there
|
|
|
|
* may be multiple errors, so we need to report on each error
|
|
|
|
* separately. Some of the error codes might indicate a state
|
|
|
|
* that is not an error per-se, but it is an error in production
|
|
|
|
* environment
|
|
|
|
*/
|
|
|
|
err_val = RREG32(boot_err0_reg);
|
|
|
|
if (!(err_val & CPU_BOOT_ERR0_ENABLED))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (err_val & CPU_BOOT_ERR0_DRAM_INIT_FAIL)
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Device boot error - DRAM initialization failed\n");
|
|
|
|
if (err_val & CPU_BOOT_ERR0_FIT_CORRUPTED)
|
|
|
|
dev_err(hdev->dev, "Device boot error - FIT image corrupted\n");
|
|
|
|
if (err_val & CPU_BOOT_ERR0_TS_INIT_FAIL)
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Device boot error - Thermal Sensor initialization failed\n");
|
|
|
|
if (err_val & CPU_BOOT_ERR0_DRAM_SKIPPED)
|
|
|
|
dev_warn(hdev->dev,
|
|
|
|
"Device boot warning - Skipped DRAM initialization\n");
|
|
|
|
if (err_val & CPU_BOOT_ERR0_BMC_WAIT_SKIPPED)
|
|
|
|
dev_warn(hdev->dev,
|
|
|
|
"Device boot error - Skipped waiting for BMC\n");
|
|
|
|
if (err_val & CPU_BOOT_ERR0_NIC_DATA_NOT_RDY)
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Device boot error - Serdes data from BMC not available\n");
|
|
|
|
if (err_val & CPU_BOOT_ERR0_NIC_FW_FAIL)
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Device boot error - NIC F/W initialization failed\n");
|
2020-11-12 15:52:52 +00:00
|
|
|
if (err_val & CPU_BOOT_ERR0_SECURITY_NOT_RDY)
|
|
|
|
dev_warn(hdev->dev,
|
|
|
|
"Device boot warning - security not ready\n");
|
|
|
|
if (err_val & CPU_BOOT_ERR0_SECURITY_FAIL)
|
|
|
|
dev_err(hdev->dev, "Device boot error - security failure\n");
|
|
|
|
if (err_val & CPU_BOOT_ERR0_EFUSE_FAIL)
|
|
|
|
dev_err(hdev->dev, "Device boot error - eFuse failure\n");
|
2020-10-04 06:09:19 +00:00
|
|
|
|
|
|
|
security_val = RREG32(cpu_security_boot_status_reg);
|
|
|
|
if (security_val & CPU_BOOT_DEV_STS0_ENABLED)
|
2020-11-27 16:10:20 +00:00
|
|
|
dev_dbg(hdev->dev, "Device security status %#x\n",
|
2020-10-04 06:09:19 +00:00
|
|
|
security_val);
|
2020-03-26 10:32:56 +00:00
|
|
|
}
|
|
|
|
|
2020-09-13 12:51:28 +00:00
|
|
|
static void detect_cpu_boot_status(struct hl_device *hdev, u32 status)
|
2020-06-23 16:21:22 +00:00
|
|
|
{
|
2020-09-13 12:51:28 +00:00
|
|
|
/* Some of the status codes below are deprecated in newer f/w
|
|
|
|
* versions but we keep them here for backward compatibility
|
|
|
|
*/
|
2020-06-23 16:21:22 +00:00
|
|
|
switch (status) {
|
|
|
|
case CPU_BOOT_STATUS_NA:
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Device boot error - BTL did NOT run\n");
|
|
|
|
break;
|
|
|
|
case CPU_BOOT_STATUS_IN_WFE:
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Device boot error - Stuck inside WFE loop\n");
|
|
|
|
break;
|
|
|
|
case CPU_BOOT_STATUS_IN_BTL:
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Device boot error - Stuck in BTL\n");
|
|
|
|
break;
|
|
|
|
case CPU_BOOT_STATUS_IN_PREBOOT:
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Device boot error - Stuck in Preboot\n");
|
|
|
|
break;
|
|
|
|
case CPU_BOOT_STATUS_IN_SPL:
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Device boot error - Stuck in SPL\n");
|
|
|
|
break;
|
|
|
|
case CPU_BOOT_STATUS_IN_UBOOT:
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Device boot error - Stuck in u-boot\n");
|
|
|
|
break;
|
|
|
|
case CPU_BOOT_STATUS_DRAM_INIT_FAIL:
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Device boot error - DRAM initialization failed\n");
|
|
|
|
break;
|
|
|
|
case CPU_BOOT_STATUS_UBOOT_NOT_READY:
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Device boot error - u-boot stopped by user\n");
|
|
|
|
break;
|
|
|
|
case CPU_BOOT_STATUS_TS_INIT_FAIL:
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Device boot error - Thermal Sensor initialization failed\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Device boot error - Invalid status code %d\n",
|
|
|
|
status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-04 06:09:19 +00:00
|
|
|
int hl_fw_read_preboot_status(struct hl_device *hdev, u32 cpu_boot_status_reg,
|
|
|
|
u32 cpu_security_boot_status_reg, u32 boot_err0_reg,
|
|
|
|
u32 timeout)
|
2020-09-13 12:51:28 +00:00
|
|
|
{
|
2020-10-04 06:09:19 +00:00
|
|
|
struct asic_fixed_properties *prop = &hdev->asic_prop;
|
|
|
|
u32 status, security_status;
|
2020-09-13 12:51:28 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (!hdev->cpu_enable)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Need to check two possible scenarios:
|
|
|
|
*
|
|
|
|
* CPU_BOOT_STATUS_WAITING_FOR_BOOT_FIT - for newer firmwares where
|
|
|
|
* the preboot is waiting for the boot fit
|
|
|
|
*
|
|
|
|
* All other status values - for older firmwares where the uboot was
|
|
|
|
* loaded from the FLASH
|
|
|
|
*/
|
|
|
|
rc = hl_poll_timeout(
|
|
|
|
hdev,
|
|
|
|
cpu_boot_status_reg,
|
|
|
|
status,
|
|
|
|
(status == CPU_BOOT_STATUS_IN_UBOOT) ||
|
|
|
|
(status == CPU_BOOT_STATUS_DRAM_RDY) ||
|
|
|
|
(status == CPU_BOOT_STATUS_NIC_FW_RDY) ||
|
|
|
|
(status == CPU_BOOT_STATUS_READY_TO_BOOT) ||
|
|
|
|
(status == CPU_BOOT_STATUS_SRAM_AVAIL) ||
|
|
|
|
(status == CPU_BOOT_STATUS_WAITING_FOR_BOOT_FIT),
|
|
|
|
10000,
|
|
|
|
timeout);
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
dev_err(hdev->dev, "Failed to read preboot version\n");
|
|
|
|
detect_cpu_boot_status(hdev, status);
|
2020-10-04 06:09:19 +00:00
|
|
|
fw_read_errors(hdev, boot_err0_reg,
|
|
|
|
cpu_security_boot_status_reg);
|
2020-09-13 12:51:28 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2020-10-14 12:17:36 +00:00
|
|
|
rc = hdev->asic_funcs->read_device_fw_version(hdev, FW_COMP_PREBOOT);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2020-09-13 12:51:28 +00:00
|
|
|
|
2020-10-04 06:09:19 +00:00
|
|
|
security_status = RREG32(cpu_security_boot_status_reg);
|
|
|
|
|
|
|
|
/* We read security status multiple times during boot:
|
2020-12-01 08:39:54 +00:00
|
|
|
* 1. preboot - a. Check whether the security status bits are valid
|
|
|
|
* b. Check whether fw security is enabled
|
2020-12-06 12:00:35 +00:00
|
|
|
* c. Check whether hard reset is done by preboot
|
|
|
|
* 2. boot cpu - a. Fetch boot cpu security status
|
|
|
|
* b. Check whether hard reset is done by boot cpu
|
|
|
|
* 3. FW application - a. Fetch fw application security status
|
|
|
|
* b. Check whether hard reset is done by fw app
|
2020-10-04 06:09:19 +00:00
|
|
|
*
|
|
|
|
* Preboot:
|
|
|
|
* Check security status bit (CPU_BOOT_DEV_STS0_ENABLED), if it is set
|
|
|
|
* check security enabled bit (CPU_BOOT_DEV_STS0_SECURITY_EN)
|
|
|
|
*/
|
|
|
|
if (security_status & CPU_BOOT_DEV_STS0_ENABLED) {
|
2020-12-06 12:00:35 +00:00
|
|
|
prop->fw_security_status_valid = 1;
|
2020-12-01 08:39:54 +00:00
|
|
|
|
2020-12-06 12:00:35 +00:00
|
|
|
if (security_status & CPU_BOOT_DEV_STS0_SECURITY_EN)
|
|
|
|
prop->fw_security_disabled = false;
|
|
|
|
else
|
2020-12-01 08:39:54 +00:00
|
|
|
prop->fw_security_disabled = true;
|
|
|
|
|
|
|
|
if (security_status & CPU_BOOT_DEV_STS0_FW_HARD_RST_EN)
|
2020-12-06 12:00:35 +00:00
|
|
|
prop->hard_reset_done_by_fw = true;
|
2020-10-04 06:09:19 +00:00
|
|
|
} else {
|
2020-12-06 12:00:35 +00:00
|
|
|
prop->fw_security_status_valid = 0;
|
2020-10-04 06:09:19 +00:00
|
|
|
prop->fw_security_disabled = true;
|
|
|
|
}
|
|
|
|
|
2020-12-06 12:00:35 +00:00
|
|
|
dev_dbg(hdev->dev, "Firmware preboot hard-reset is %s\n",
|
|
|
|
prop->hard_reset_done_by_fw ? "enabled" : "disabled");
|
2020-12-01 08:39:54 +00:00
|
|
|
|
2020-10-04 06:09:19 +00:00
|
|
|
dev_info(hdev->dev, "firmware-level security is %s\n",
|
2020-12-06 12:00:35 +00:00
|
|
|
prop->fw_security_disabled ? "disabled" : "enabled");
|
2020-10-04 06:09:19 +00:00
|
|
|
|
2020-09-13 12:51:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-26 10:32:56 +00:00
|
|
|
int hl_fw_init_cpu(struct hl_device *hdev, u32 cpu_boot_status_reg,
|
2020-04-16 10:47:15 +00:00
|
|
|
u32 msg_to_cpu_reg, u32 cpu_msg_status_reg,
|
2020-10-04 06:09:19 +00:00
|
|
|
u32 cpu_security_boot_status_reg, u32 boot_err0_reg,
|
|
|
|
bool skip_bmc, u32 cpu_timeout, u32 boot_fit_timeout)
|
2020-03-26 10:32:56 +00:00
|
|
|
{
|
2020-12-06 12:00:35 +00:00
|
|
|
struct asic_fixed_properties *prop = &hdev->asic_prop;
|
2020-03-26 10:32:56 +00:00
|
|
|
u32 status;
|
|
|
|
int rc;
|
|
|
|
|
2020-10-01 10:46:37 +00:00
|
|
|
if (!(hdev->fw_loading & FW_TYPE_BOOT_CPU))
|
|
|
|
return 0;
|
|
|
|
|
2020-03-26 10:32:56 +00:00
|
|
|
dev_info(hdev->dev, "Going to wait for device boot (up to %lds)\n",
|
|
|
|
cpu_timeout / USEC_PER_SEC);
|
|
|
|
|
2020-04-16 10:47:15 +00:00
|
|
|
/* Wait for boot FIT request */
|
|
|
|
rc = hl_poll_timeout(
|
|
|
|
hdev,
|
|
|
|
cpu_boot_status_reg,
|
|
|
|
status,
|
|
|
|
status == CPU_BOOT_STATUS_WAITING_FOR_BOOT_FIT,
|
|
|
|
10000,
|
|
|
|
boot_fit_timeout);
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
dev_dbg(hdev->dev,
|
|
|
|
"No boot fit request received, resuming boot\n");
|
|
|
|
} else {
|
|
|
|
rc = hdev->asic_funcs->load_boot_fit_to_device(hdev);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Clear device CPU message status */
|
|
|
|
WREG32(cpu_msg_status_reg, CPU_MSG_CLR);
|
|
|
|
|
|
|
|
/* Signal device CPU that boot loader is ready */
|
|
|
|
WREG32(msg_to_cpu_reg, KMD_MSG_FIT_RDY);
|
|
|
|
|
|
|
|
/* Poll for CPU device ack */
|
|
|
|
rc = hl_poll_timeout(
|
|
|
|
hdev,
|
|
|
|
cpu_msg_status_reg,
|
|
|
|
status,
|
|
|
|
status == CPU_MSG_OK,
|
|
|
|
10000,
|
|
|
|
boot_fit_timeout);
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Timeout waiting for boot fit load ack\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear message */
|
|
|
|
WREG32(msg_to_cpu_reg, KMD_MSG_NA);
|
|
|
|
}
|
|
|
|
|
2020-03-26 10:32:56 +00:00
|
|
|
/* Make sure CPU boot-loader is running */
|
|
|
|
rc = hl_poll_timeout(
|
|
|
|
hdev,
|
|
|
|
cpu_boot_status_reg,
|
|
|
|
status,
|
|
|
|
(status == CPU_BOOT_STATUS_DRAM_RDY) ||
|
|
|
|
(status == CPU_BOOT_STATUS_NIC_FW_RDY) ||
|
|
|
|
(status == CPU_BOOT_STATUS_READY_TO_BOOT) ||
|
|
|
|
(status == CPU_BOOT_STATUS_SRAM_AVAIL),
|
|
|
|
10000,
|
|
|
|
cpu_timeout);
|
|
|
|
|
2020-10-01 10:46:37 +00:00
|
|
|
dev_dbg(hdev->dev, "uboot status = %d\n", status);
|
|
|
|
|
2020-09-13 12:51:28 +00:00
|
|
|
/* Read U-Boot version now in case we will later fail */
|
2020-03-26 10:32:56 +00:00
|
|
|
hdev->asic_funcs->read_device_fw_version(hdev, FW_COMP_UBOOT);
|
|
|
|
|
2020-12-06 12:00:35 +00:00
|
|
|
/* Clear reset status since we need to read it again from boot CPU */
|
|
|
|
prop->hard_reset_done_by_fw = false;
|
|
|
|
|
2020-10-04 06:09:19 +00:00
|
|
|
/* Read boot_cpu security bits */
|
2020-12-06 12:00:35 +00:00
|
|
|
if (prop->fw_security_status_valid) {
|
|
|
|
prop->fw_boot_cpu_security_map =
|
2020-10-04 06:09:19 +00:00
|
|
|
RREG32(cpu_security_boot_status_reg);
|
|
|
|
|
2020-12-06 12:00:35 +00:00
|
|
|
if (prop->fw_boot_cpu_security_map &
|
|
|
|
CPU_BOOT_DEV_STS0_FW_HARD_RST_EN)
|
|
|
|
prop->hard_reset_done_by_fw = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(hdev->dev, "Firmware boot CPU hard-reset is %s\n",
|
|
|
|
prop->hard_reset_done_by_fw ? "enabled" : "disabled");
|
|
|
|
|
2020-03-26 10:32:56 +00:00
|
|
|
if (rc) {
|
2020-09-13 12:51:28 +00:00
|
|
|
detect_cpu_boot_status(hdev, status);
|
2020-03-26 10:32:56 +00:00
|
|
|
rc = -EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2020-10-01 10:46:37 +00:00
|
|
|
if (!(hdev->fw_loading & FW_TYPE_LINUX)) {
|
|
|
|
dev_info(hdev->dev, "Skip loading Linux F/W\n");
|
2020-03-26 10:32:56 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status == CPU_BOOT_STATUS_SRAM_AVAIL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
dev_info(hdev->dev,
|
|
|
|
"Loading firmware to device, may take some time...\n");
|
|
|
|
|
|
|
|
rc = hdev->asic_funcs->load_firmware_to_device(hdev);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (skip_bmc) {
|
|
|
|
WREG32(msg_to_cpu_reg, KMD_MSG_SKIP_BMC);
|
|
|
|
|
|
|
|
rc = hl_poll_timeout(
|
|
|
|
hdev,
|
|
|
|
cpu_boot_status_reg,
|
|
|
|
status,
|
|
|
|
(status == CPU_BOOT_STATUS_BMC_WAITING_SKIPPED),
|
|
|
|
10000,
|
|
|
|
cpu_timeout);
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Failed to get ACK on skipping BMC, %d\n",
|
|
|
|
status);
|
|
|
|
WREG32(msg_to_cpu_reg, KMD_MSG_NA);
|
|
|
|
rc = -EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WREG32(msg_to_cpu_reg, KMD_MSG_FIT_RDY);
|
|
|
|
|
|
|
|
rc = hl_poll_timeout(
|
|
|
|
hdev,
|
|
|
|
cpu_boot_status_reg,
|
|
|
|
status,
|
|
|
|
(status == CPU_BOOT_STATUS_SRAM_AVAIL),
|
|
|
|
10000,
|
|
|
|
cpu_timeout);
|
|
|
|
|
2020-04-16 10:47:15 +00:00
|
|
|
/* Clear message */
|
|
|
|
WREG32(msg_to_cpu_reg, KMD_MSG_NA);
|
|
|
|
|
2020-03-26 10:32:56 +00:00
|
|
|
if (rc) {
|
|
|
|
if (status == CPU_BOOT_STATUS_FIT_CORRUPTED)
|
|
|
|
dev_err(hdev->dev,
|
|
|
|
"Device reports FIT image is corrupted\n");
|
|
|
|
else
|
|
|
|
dev_err(hdev->dev,
|
2020-07-04 19:51:16 +00:00
|
|
|
"Failed to load firmware to device, %d\n",
|
|
|
|
status);
|
2020-03-26 10:32:56 +00:00
|
|
|
|
|
|
|
rc = -EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2020-12-06 12:00:35 +00:00
|
|
|
/* Clear reset status since we need to read again from app */
|
|
|
|
prop->hard_reset_done_by_fw = false;
|
|
|
|
|
2020-10-04 06:09:19 +00:00
|
|
|
/* Read FW application security bits */
|
2020-12-06 12:00:35 +00:00
|
|
|
if (prop->fw_security_status_valid) {
|
|
|
|
prop->fw_app_security_map =
|
2020-10-04 06:09:19 +00:00
|
|
|
RREG32(cpu_security_boot_status_reg);
|
|
|
|
|
2020-12-06 12:00:35 +00:00
|
|
|
if (prop->fw_app_security_map &
|
|
|
|
CPU_BOOT_DEV_STS0_FW_HARD_RST_EN)
|
|
|
|
prop->hard_reset_done_by_fw = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(hdev->dev, "Firmware application CPU hard-reset is %s\n",
|
|
|
|
prop->hard_reset_done_by_fw ? "enabled" : "disabled");
|
|
|
|
|
2020-03-26 10:32:56 +00:00
|
|
|
dev_info(hdev->dev, "Successfully loaded firmware to device\n");
|
|
|
|
|
|
|
|
out:
|
2020-10-04 06:09:19 +00:00
|
|
|
fw_read_errors(hdev, boot_err0_reg, cpu_security_boot_status_reg);
|
2020-03-26 10:32:56 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|