habanalabs: build ASICs from new to old
PATCH 1/4 habanalabs: build ASICs from new to old
From: Ohad Sharabi <[email protected]>
Newer ASICs code changes more often, has more chance to fail compilation. So, let's compile them first so errors in those files will fail compilation sooner.
--- drivers/misc/habanalabs/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/misc/habanalabs/Makefile +4 -4
@@ -8,13 +8,13 @@ obj-$(CONFIG_HABANA_AI) := habanalabs.o include $(src)/common/Makefile habanalabs-y += $(HL_COMMON_FILES) -include $(src)/goya/Makefile -habanalabs-y += $(HL_GOYA_FILES) +include $(src)/gaudi2/Makefile +habanalabs-y += $(HL_GAUDI2_FILES) include $(src)/gaudi/Makefile habanalabs-y += $(HL_GAUDI_FILES) -include $(src)/gaudi2/Makefile -habanalabs-y += $(HL_GAUDI2_FILES) +include $(src)/goya/Makefile +habanalabs-y += $(HL_GOYA_FILES) habanalabs-$(CONFIG_DEBUG_FS) += common/debugfs.o
Signature · 1 line
2.25.1
PATCH 3/4 habanalabs/gaudi: use 8KB aligned address for TPC kernels
From: Tomer Tayar <[email protected]>
I$ prefetch is enabled when sending a TPC kernel to initialize the TPC memory, and it has a restriction that the base address will be aligned to 8KB.
Currently the base address is 128 bytes from the start address of the device SRAM, so prefetching will start 128 bytes before the actual kernel memory.
Modify the kernel address to be 8KB aligned.
--- drivers/misc/habanalabs/gaudi/gaudi.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/misc/habanalabs/gaudi/gaudi.c +4 -3
@@ -984,9 +984,10 @@ static int _gaudi_init_tpc_mem(struct hl_device *hdev, init_tpc_mem_pkt->ctl =cpu_to_le32 (ctl); init_tpc_mem_pkt->src_addr =cpu_to_le64 (tpc_kernel_src_addr); - dst_addr = (prop->sram_user_base_address & -GAUDI_PKT_LIN_DMA_DST_ADDR_MASK ) >> -GAUDI_PKT_LIN_DMA_DST_ADDR_SHIFT ; + +/* TPC_CMD is configured with I$ prefetch enabled, so address should be aligned to 8KB */ + dst_addr =FIELD_PREP (GAUDI_PKT_LIN_DMA_DST_ADDR_MASK , +round_up (prop->sram_user_base_address,SZ_8K )); init_tpc_mem_pkt->dst_addr |=cpu_to_le64 (dst_addr); job =hl_cs_allocate_job (hdev,QUEUE_TYPE_EXT , true);
Signature · 1 line
2.25.1
PATCH 2/4 habanalabs: remove some f/w descriptor validations
In reply to Oded GabbayFrom: farah kassabri <[email protected]>
To be forward-backward compatible with the firmware in the initial communication during preboot, we need to remove the validation of the header size. This will allow us to add more fields to the lkd_fw_comms_desc structure.
Instead of the validation of the header size, we just print warning when some mismatch in descriptor has been revealed, and we calculate the CRC base on descriptor size reported by the firmware instead of calculating it ourselves.
--- drivers/misc/habanalabs/common/firmware_if.c | 43 +++++++------------- 1 file changed, 14 insertions(+), 29 deletions(-)
drivers/misc/habanalabs/common/firmware_if.c +14 -29
@@ -1900,50 +1900,36 @@ static int hl_fw_dynamic_validate_descriptor(struct hl_device *hdev,u64 addr;int rc; -if (le32_to_cpu (fw_desc->header.magic) !=HL_COMMS_DESC_MAGIC ) { -dev_err (hdev->dev,"Invalid magic for dynamic FW descriptor (%x)\n" , +if (le32_to_cpu (fw_desc->header.magic) !=HL_COMMS_DESC_MAGIC ) +dev_warn (hdev->dev,"Invalid magic for dynamic FW descriptor (%x)\n" , fw_desc->header.magic); -return -EIO ; - } -if (fw_desc->header.version !=HL_COMMS_DESC_VER ) { -dev_err (hdev->dev,"Invalid version for dynamic FW descriptor (%x)\n" , +if (fw_desc->header.version !=HL_COMMS_DESC_VER ) +dev_warn (hdev->dev,"Invalid version for dynamic FW descriptor (%x)\n" , fw_desc->header.version); -return -EIO ; - }/* -* calc CRC32 of data without header. +* Calc CRC32 of data without header. use the size of the descriptor +* reported by firmware, without calculating it ourself, to allow adding +* more fields to the lkd_fw_comms_desc structure. * note that no alignment/stride address issues here as all structures -* are 64 bit padded +* are 64 bit padded. */ - data_size =sizeof (struct lkd_fw_comms_desc ) - -sizeof (struct comms_desc_header ); data_ptr = (u8 *)fw_desc +sizeof (struct comms_desc_header ); - -if (le16_to_cpu (fw_desc->header.size) != data_size) { -dev_err (hdev->dev, -"Invalid descriptor size 0x%x, expected size 0x%zx\n" , -le16_to_cpu (fw_desc->header.size), data_size); -return -EIO ; - } + data_size =le16_to_cpu (fw_desc->header.size); data_crc32 =hl_fw_compat_crc32 (data_ptr, data_size); -if (data_crc32 !=le32_to_cpu (fw_desc->header.crc32)) { -dev_err (hdev->dev, -"CRC32 mismatch for dynamic FW descriptor (%x:%x)\n" , - data_crc32, fw_desc->header.crc32); +dev_err (hdev->dev,"CRC32 mismatch for dynamic FW descriptor (%x:%x)\n" , + data_crc32, fw_desc->header.crc32);return -EIO ; }/* find memory region to which to copy the image */ addr =le64_to_cpu (fw_desc->img_addr); region_id =hl_get_pci_memory_region (hdev, addr); -if ((region_id !=PCI_REGION_SRAM ) && - ((region_id !=PCI_REGION_DRAM ))) { -dev_err (hdev->dev, -"Invalid region to copy FW image address=%llx\n" , addr); +if ((region_id !=PCI_REGION_SRAM ) && ((region_id !=PCI_REGION_DRAM ))) { +dev_err (hdev->dev,"Invalid region to copy FW image address=%llx\n" , addr);return -EIO ; }
@@ -1960,8 +1946,7 @@ static int hl_fw_dynamic_validate_descriptor(struct hl_device *hdev, fw_loader->dynamic_loader.fw_image_size, region);if (rc) { -dev_err (hdev->dev, -"invalid mem transfer request for FW image\n" ); +dev_err (hdev->dev,"invalid mem transfer request for FW image\n" );return rc; }
Signature · 1 line
2.25.1
PATCH 4/4 habanalabs: eliminate aggregate use warning
In reply to Oded GabbayWhen doing sizeof() and giving as argument a dereference of a pointer-to-a-pointer object, clang will issue a warning.
Eliminate the warning by passing struct <name>*
--- drivers/misc/habanalabs/common/command_submission.c | 4 ++-- drivers/misc/habanalabs/common/device.c | 4 ++-- drivers/misc/habanalabs/common/hw_queue.c | 4 +--- drivers/misc/habanalabs/common/hwmon.c | 3 ++- drivers/misc/habanalabs/common/memory.c | 3 +-- 5 files changed, 8 insertions(+), 10 deletions(-)
drivers/misc/habanalabs/common/command_submission.c +2 -2
@@ -2571,7 +2571,7 @@ static int hl_cs_poll_fences(struct multi_cs_data *mcs_data, struct multi_cs_comktime_t max_ktime, first_cs_time;enum hl_cs_wait_status status; -memset (fence_ptr,0 , arr_len *sizeof (*fence_ptr)); +memset (fence_ptr,0 , arr_len *sizeof (struct hl_fence *));/* get all fences under the same lock */ rc =hl_ctx_get_fences (mcs_data->ctx, seq_arr, fence_ptr, arr_len);
@@ -2873,7 +2873,7 @@ static int hl_multi_cs_wait_ioctl(struct hl_fpriv *hpriv, void *data) }/* allocate array for the fences */ - fence_arr =kmalloc_array (seq_arr_len,sizeof (*fence_arr),GFP_KERNEL ); + fence_arr =kmalloc_array (seq_arr_len,sizeof (struct hl_fence *),GFP_KERNEL );if (!fence_arr) { rc = -ENOMEM ; goto free_seq_arr;
drivers/misc/habanalabs/common/device.c +2 -2
@@ -719,7 +719,7 @@ static int device_early_init(struct hl_device *hdev)if (hdev->asic_prop.completion_queues_count) { hdev->cq_wq =kcalloc (hdev->asic_prop.completion_queues_count, -sizeof (*hdev->cq_wq), +sizeof (struct workqueue_struct *),GFP_KERNEL );if (!hdev->cq_wq) { rc = -ENOMEM ;
@@ -1863,7 +1863,7 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass) } hdev->shadow_cs_queue =kcalloc (hdev->asic_prop.max_pending_cs, -sizeof (*hdev->shadow_cs_queue),GFP_KERNEL ); +sizeof (struct hl_cs *),GFP_KERNEL );if (!hdev->shadow_cs_queue) { rc = -ENOMEM ; goto cq_fini;
drivers/misc/habanalabs/common/hw_queue.c +1 -3
@@ -826,9 +826,7 @@ static int ext_and_cpu_queue_init(struct hl_device *hdev, struct hl_hw_queue *q, q->kernel_address = p; - q->shadow_queue =kmalloc_array (HL_QUEUE_LENGTH , -sizeof (*q->shadow_queue), -GFP_KERNEL ); + q->shadow_queue =kmalloc_array (HL_QUEUE_LENGTH ,sizeof (struct hl_cs_job *),GFP_KERNEL );if (!q->shadow_queue) { dev_err(hdev->dev, "Failed to allocate shadow queue for H/W queue %d\n",
drivers/misc/habanalabs/common/hwmon.c +2 -1
@@ -194,7 +194,8 @@ int hl_build_hwmon_channel_info(struct hl_device *hdev, struct cpucp_sensor *sen curr_arr[sensors_by_type_next_index[type]++] = flags; } - channels_info =kcalloc (num_active_sensor_types +1 ,sizeof (*channels_info),GFP_KERNEL ); + channels_info =kcalloc (num_active_sensor_types +1 ,sizeof (struct hwmon_channel_info *), +GFP_KERNEL );if (!channels_info) { rc = -ENOMEM ; goto channels_info_array_err;
drivers/misc/habanalabs/common/memory.c +1 -2
@@ -2308,8 +2308,7 @@ static int get_user_memory(struct hl_device *hdev, u64 addr, u64 size,return -EFAULT ; } - userptr->pages =kvmalloc_array (npages,sizeof (*userptr->pages), -GFP_KERNEL ); + userptr->pages =kvmalloc_array (npages,sizeof (struct page *),GFP_KERNEL );if (!userptr->pages)return -ENOMEM ;
Signature · 1 line
2.25.1