habanalabs: various improvements and updates
cover habanalabs: various improvements and updates
This patch-set contains various improvements to existing code and some updates from our internal tree at habanalabs.
None of the patches here is critical fix for the 5.1 kernel release, and they will be queued in the main pull request for the 5.2 merge window.
Thanks,
Oded
Dotan Barak (1):
habanalabs: remove implicit include from header files
Igor Grinberg (1):
habanalabs: add new device CPU boot status
Oded Gabbay (7):
habanalabs: rename goya_non_fatal_events array to all events
habanalabs: use EQ MSI/X ID per chip
habanalabs: remove unused defines
habanalabs: ratelimit warnings at start of IOCTLs uapi/habanalabs: add some comments in habanalabs.h
habanalabs: keep track of the device's dma mask
habanalabs: never fail hard reset of device
Omer Shpigelman (1):
habanalabs: add MMU shadow mapping
Tomer Tayar (5):
habanalabs: Move device CPU code into common file
habanalabs: Move PCI code into common file
habanalabs: Remove unneeded function pointers
habanalabs: Add a printout with the name of a busy engine
habanalabs: Allow accessing DRAM virtual addresses via debugfs
drivers/misc/habanalabs/Makefile | 2 +- drivers/misc/habanalabs/command_submission.c | 2 +- drivers/misc/habanalabs/debugfs.c | 96 ++- drivers/misc/habanalabs/device.c | 19 +- drivers/misc/habanalabs/firmware_if.c | 324 ++++++++ drivers/misc/habanalabs/goya/goya.c | 719 +++--------------- drivers/misc/habanalabs/goya/goyaP.h | 29 +- drivers/misc/habanalabs/goya/goya_security.c | 1 + drivers/misc/habanalabs/habanalabs.h | 72 +- drivers/misc/habanalabs/habanalabs_drv.c | 3 + drivers/misc/habanalabs/habanalabs_ioctl.c | 4 +- drivers/misc/habanalabs/include/armcp_if.h | 10 +- .../include/goya/asic_reg/goya_masks.h | 12 - drivers/misc/habanalabs/include/goya/goya.h | 4 - .../include/goya/goya_async_events.h | 9 + .../misc/habanalabs/include/goya/goya_fw_if.h | 2 + drivers/misc/habanalabs/include/hl_boot_if.h | 3 +- .../include/hw_ip/mmu/mmu_general.h | 16 +- .../include/hw_ip/pci/pci_general.h | 23 + drivers/misc/habanalabs/mmu.c | 597 ++++++++------- drivers/misc/habanalabs/pci.c | 402 ++++++++++ include/uapi/misc/habanalabs.h | 7 +- 22 files changed, 1404 insertions(+), 952 deletions(-) create mode 100644 drivers/misc/habanalabs/firmware_if.c create mode 100644 drivers/misc/habanalabs/include/hw_ip/pci/pci_general.h create mode 100644 drivers/misc/habanalabs/pci.c
Signature · 1 line
2.17.1
PATCH 1/15 habanalabs: add new device CPU boot status
From: Igor Grinberg <[email protected]>
This patch adds a definition of a new status in the device CPU boot stages and add the handling of the new status.
--- drivers/misc/habanalabs/goya/goya.c | 5 +++++ drivers/misc/habanalabs/include/hl_boot_if.h | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-)
drivers/misc/habanalabs/goya/goya.c +5 -0
@@ -2550,6 +2550,11 @@ static int goya_init_cpu(struct hl_device *hdev, u32 cpu_timeout)"ARM status %d - DDR initialization failed\n" , status);break ; +case CPU_BOOT_STATUS_UBOOT_NOT_READY : +dev_err (hdev->dev, +"ARM status %d - u-boot stopped by user\n" , + status); +break ;default : dev_err(hdev->dev, "ARM status %d - Invalid status code\n",
drivers/misc/habanalabs/include/hl_boot_if.h +2 -1
@@ -18,7 +18,8 @@ enum cpu_boot_status {CPU_BOOT_STATUS_IN_SPL ,CPU_BOOT_STATUS_IN_UBOOT ,CPU_BOOT_STATUS_DRAM_INIT_FAIL , -CPU_BOOT_STATUS_FIT_CORRUPTED +CPU_BOOT_STATUS_FIT_CORRUPTED , + CPU_BOOT_STATUS_UBOOT_NOT_READY, }; enum kmd_msg {
Signature · 1 line
2.17.1
PATCH 2/15 habanalabs: rename goya_non_fatal_events array to all events
In reply to Oded GabbayThe goya_non_fatal_events array actually contains all the possible events the driver can receive from the F/W. Therefore, use a proper name for the array.
The patch also adds missing event Ids to the goya_async_event_id enum.
--- drivers/misc/habanalabs/goya/goya.c | 8 +++----- drivers/misc/habanalabs/include/goya/goya_async_events.h | 9 +++++++++ 2 files changed, 12 insertions(+), 5 deletions(-)
drivers/misc/habanalabs/goya/goya.c +3 -5
@@ -176,9 +176,7 @@ static u64 goya_mmu_regs[GOYA_MMU_REGS_NUM] = {mmMME_WBC_CONTROL_DATA }; -#define GOYA_ASYC_EVENT_GROUP_NON_FATAL_SIZE 121 - -static u32 goya_non_fatal_events[GOYA_ASYC_EVENT_GROUP_NON_FATAL_SIZE ] = { +static u32 goya_all_events[] = {GOYA_ASYNC_EVENT_ID_PCIE_IF ,GOYA_ASYNC_EVENT_ID_TPC0_ECC ,GOYA_ASYNC_EVENT_ID_TPC1_ECC ,
@@ -4627,8 +4625,8 @@ static int goya_soft_reset_late_init(struct hl_device *hdev)* Unmask all IRQs since some could have been received * during the soft reset */ -return goya_unmask_irq_arr (hdev, goya_non_fatal_events, -sizeof (goya_non_fatal_events)); +return goya_unmask_irq_arr (hdev, goya_all_events, +sizeof (goya_all_events)); }static int goya_unmask_irq (struct hl_device *hdev,u16 event_type)
drivers/misc/habanalabs/include/goya/goya_async_events.h +9 -0
@@ -9,7 +9,9 @@#define __GOYA_ASYNC_EVENTS_H_enum goya_async_event_id { +GOYA_ASYNC_EVENT_ID_PCIE_CORE =32 ,GOYA_ASYNC_EVENT_ID_PCIE_IF =33 , +GOYA_ASYNC_EVENT_ID_PCIE_PHY =34 ,GOYA_ASYNC_EVENT_ID_TPC0_ECC =36 ,GOYA_ASYNC_EVENT_ID_TPC1_ECC =39 ,GOYA_ASYNC_EVENT_ID_TPC2_ECC =42 ,
@@ -23,6 +25,8 @@ enum goya_async_event_id {GOYA_ASYNC_EVENT_ID_MMU_ECC =63 ,GOYA_ASYNC_EVENT_ID_DMA_MACRO =64 ,GOYA_ASYNC_EVENT_ID_DMA_ECC =66 , +GOYA_ASYNC_EVENT_ID_DDR0_PARITY =69 , +GOYA_ASYNC_EVENT_ID_DDR1_PARITY =72 ,GOYA_ASYNC_EVENT_ID_CPU_IF_ECC =75 ,GOYA_ASYNC_EVENT_ID_PSOC_MEM =78 , GOYA_ASYNC_EVENT_ID_PSOC_CORESIGHT = 79,
@@ -72,6 +76,7 @@ enum goya_async_event_id {GOYA_ASYNC_EVENT_ID_MME_WACSD =142 ,GOYA_ASYNC_EVENT_ID_PLL0 =143 ,GOYA_ASYNC_EVENT_ID_PLL1 =144 , +GOYA_ASYNC_EVENT_ID_PLL2 =145 ,GOYA_ASYNC_EVENT_ID_PLL3 =146 ,GOYA_ASYNC_EVENT_ID_PLL4 =147 , GOYA_ASYNC_EVENT_ID_PLL5 = 148,
@@ -81,6 +86,7 @@ enum goya_async_event_id {GOYA_ASYNC_EVENT_ID_PSOC =160 ,GOYA_ASYNC_EVENT_ID_PCIE_FLR =171 ,GOYA_ASYNC_EVENT_ID_PCIE_HOT_RESET =172 , +GOYA_ASYNC_EVENT_ID_PCIE_PERST =173 ,GOYA_ASYNC_EVENT_ID_PCIE_QID0_ENG0 =174 ,GOYA_ASYNC_EVENT_ID_PCIE_QID0_ENG1 =175 , GOYA_ASYNC_EVENT_ID_PCIE_QID0_ENG2 = 176,
@@ -144,8 +150,11 @@ enum goya_async_event_id {GOYA_ASYNC_EVENT_ID_PSOC_GPIO_U16_0 =330 ,GOYA_ASYNC_EVENT_ID_PSOC_GPIO_U16_1 =331 ,GOYA_ASYNC_EVENT_ID_PSOC_GPIO_U16_2 =332 , +GOYA_ASYNC_EVENT_ID_PSOC_GPIO_U16_3 =333 , +GOYA_ASYNC_EVENT_ID_PSOC_GPIO_U16_4 =334 ,GOYA_ASYNC_EVENT_ID_PSOC_GPIO_05_SW_RESET =356 ,GOYA_ASYNC_EVENT_ID_PSOC_GPIO_10_VRHOT_ICRIT =361 , +GOYA_ASYNC_EVENT_ID_FAN =425 ,GOYA_ASYNC_EVENT_ID_TPC0_CMDQ =430 ,GOYA_ASYNC_EVENT_ID_TPC1_CMDQ =431 , GOYA_ASYNC_EVENT_ID_TPC2_CMDQ = 432,
Signature · 1 line
2.17.1
PATCH 3/15 habanalabs: remove implicit include from header files
In reply to Oded GabbayFrom: Dotan Barak <[email protected]>
This will prevent unneeded include of header files, which may increase compilation time.
--- drivers/misc/habanalabs/goya/goya_security.c | 1 + drivers/misc/habanalabs/include/goya/goya.h | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-)
drivers/misc/habanalabs/goya/goya_security.c +1 -0
@@ -6,6 +6,7 @@*/ #include "goyaP.h" +#include "include/goya/asic_reg/goya_regs.h" /* * goya_set_block_as_protected - set the given block as protected
drivers/misc/habanalabs/include/goya/goya.h +0 -4
@@ -8,10 +8,6 @@#ifndef GOYA_H #define GOYA_H -#include "asic_reg/goya_regs.h" - -#include <linux/types.h> -#define SRAM_CFG_BAR_ID 0#define MSIX_BAR_ID 2#define DDR_BAR_ID 4
Signature · 1 line
2.17.1
PATCH 4/15 habanalabs: Move device CPU code into common file
In reply to Oded GabbayFrom: Tomer Tayar <[email protected]>
This patch moves the code that is responsible of the communication vs. the F/W to a dedicated file. This will allow us to share the code between different ASICs.
--- drivers/misc/habanalabs/Makefile | 2 +- drivers/misc/habanalabs/firmware_if.c | 324 +++++++++++++++++++ drivers/misc/habanalabs/goya/goya.c | 360 ++++----------------- drivers/misc/habanalabs/goya/goyaP.h | 11 - drivers/misc/habanalabs/habanalabs.h | 17 + drivers/misc/habanalabs/include/armcp_if.h | 8 + 6 files changed, 407 insertions(+), 315 deletions(-) create mode 100644 drivers/misc/habanalabs/firmware_if.c
drivers/misc/habanalabs/Makefile +1 -1
@@ -6,7 +6,7 @@ obj-m := habanalabs.o habanalabs-y := habanalabs_drv.o device.o context.o asid.o habanalabs_ioctl.o \ command_buffer.o hw_queue.o irq.o sysfs.o hwmon.o memory.o \ - command_submission.o mmu.o + command_submission.o mmu.o firmware_if.o habanalabs-$(CONFIG_DEBUG_FS) += debugfs.o
drivers/misc/habanalabs/firmware_if.c new file +324 -0
324 lines not on this page · raw message
drivers/misc/habanalabs/goya/goya.c +57 -303
543 lines not on this page · raw message
drivers/misc/habanalabs/goya/goyaP.h +0 -11
@@ -49,9 +49,6 @@#define MAX_POWER_DEFAULT 200000/* 200W */ -#define GOYA_ARMCP_INFO_TIMEOUT 10000000/* 10s */ -#define GOYA_ARMCP_EEPROM_TIMEOUT 10000000/* 10s */ -#define DRAM_PHYS_DEFAULT_SIZE 0x100000000ull/* 4GB */ /* DRAM Memory Map */
@@ -142,13 +139,6 @@#define HW_CAP_GOLDEN 0x00000400#define HW_CAP_TPC 0x00000800 -#define CPU_PKT_SHIFT 5 -#define CPU_PKT_SIZE (1 << CPU_PKT_SHIFT) -#define CPU_PKT_MASK (~((1 << CPU_PKT_SHIFT) - 1)) -#define CPU_MAX_PKTS_IN_CB 32 -#define CPU_CB_SIZE (CPU_PKT_SIZE * CPU_MAX_PKTS_IN_CB) -#define CPU_ACCESSIBLE_MEM_SIZE (HL_QUEUE_LENGTH * CPU_CB_SIZE) -enum goya_fw_component {FW_COMP_UBOOT ,FW_COMP_PREBOOT
@@ -192,7 +182,6 @@ void goya_init_security(struct hl_device *hdev);u64 goya_get_max_power (struct hl_device *hdev);void goya_set_max_power (struct hl_device *hdev,u64 value); -int goya_send_pci_access_msg (struct hl_device *hdev,u32 opcode);void goya_late_fini (struct hl_device *hdev);int goya_suspend (struct hl_device *hdev);int goya_resume (struct hl_device *hdev);
drivers/misc/habanalabs/habanalabs.h +17 -0
@@ -33,6 +33,9 @@#define HL_PLL_LOW_JOB_FREQ_USEC 5000000/* 5 s */ +#define HL_ARMCP_INFO_TIMEOUT_USEC 10000000/* 10s */ +#define HL_ARMCP_EEPROM_TIMEOUT_USEC 10000000/* 10s */ +#define HL_MAX_QUEUES 128#define HL_MAX_JOBS_PER_CS 64
@@ -1351,6 +1354,20 @@ int hl_mmu_unmap(struct hl_ctx *ctx, u64 virt_addr, u32 page_size);void hl_mmu_swap_out (struct hl_ctx *ctx);void hl_mmu_swap_in (struct hl_ctx *ctx); +int hl_fw_push_fw_to_device (struct hl_device *hdev,const char *fw_name, +void __iomem *dst); +int hl_fw_send_pci_access_msg (struct hl_device *hdev,u32 opcode); +int hl_fw_send_cpu_message (struct hl_device *hdev,u32 hw_queue_id,u32 *msg, +u16 len,u32 timeout,long *result); +int hl_fw_test_cpu_queue (struct hl_device *hdev); +void *hl_fw_cpu_accessible_dma_pool_alloc (struct hl_device *hdev,size_t size, +dma_addr_t *dma_handle); +void hl_fw_cpu_accessible_dma_pool_free (struct hl_device *hdev,size_t size, +void *vaddr); +int hl_fw_send_heartbeat (struct hl_device *hdev); +int hl_fw_armcp_info_get (struct hl_device *hdev); +int hl_fw_get_eeprom_data (struct hl_device *hdev,void *data,size_t max_size); +long hl_get_frequency (struct hl_device *hdev,u32 pll_index,bool curr);void hl_set_frequency (struct hl_device *hdev,u32 pll_index,u64 freq);long hl_get_temperature (struct hl_device *hdev,int sensor_index,u32 attr);
drivers/misc/habanalabs/include/armcp_if.h +8 -0
@@ -302,6 +302,14 @@ enum armcp_pwm_attributes {armcp_pwm_enable }; +#define HL_CPU_PKT_SHIFT 5 +#define HL_CPU_PKT_SIZE (1 << HL_CPU_PKT_SHIFT) +#define HL_CPU_PKT_MASK (~((1 << HL_CPU_PKT_SHIFT) - 1)) +#define HL_CPU_MAX_PKTS_IN_CB 32 +#define HL_CPU_CB_SIZE (HL_CPU_PKT_SIZE * \ + HL_CPU_MAX_PKTS_IN_CB) +#define HL_CPU_ACCESSIBLE_MEM_SIZE (HL_QUEUE_LENGTH * HL_CPU_CB_SIZE) +/* Event Queue Packets */ struct eq_generic_event {
Signature · 1 line
2.17.1
PATCH 9/15 habanalabs: Remove unneeded function pointers
In reply to Oded GabbayFrom: Tomer Tayar <[email protected]>
Remove pointers to ASIC-specific functions and instead call the functions explicitly as they are not accessed from outside the ASIC-specific files.
--- drivers/misc/habanalabs/goya/goya.c | 12 +++--------- drivers/misc/habanalabs/goya/goyaP.h | 4 +--- 2 files changed, 4 insertions(+), 12 deletions(-)
drivers/misc/habanalabs/goya/goya.c +3 -9
@@ -299,7 +299,6 @@ static u32 goya_all_events[] = { GOYA_ASYNC_EVENT_ID_DMA_BM_CH4 }; -static int goya_armcp_info_get (struct hl_device *hdev);static void goya_mmu_prepare (struct hl_device *hdev,u32 asid);static int goya_mmu_clear_pgt_range (struct hl_device *hdev);static int goya_mmu_set_dram_default_page (struct hl_device *hdev);
@@ -539,10 +538,9 @@ static void goya_fetch_psoc_frequency(struct hl_device *hdev)static int goya_late_init (struct hl_device *hdev) {struct asic_fixed_properties *prop = &hdev->asic_prop; -struct goya_device *goya = hdev->asic_specific;int rc; - rc = goya->armcp_info_get (hdev); + rc =goya_armcp_info_get (hdev);if (rc) {dev_err (hdev->dev,"Failed to get armcp info\n" );return rc;
@@ -629,9 +627,6 @@ static int goya_sw_init(struct hl_device *hdev)if (!goya)return -ENOMEM ; - goya->test_cpu_queue = goya_test_cpu_queue; - goya->armcp_info_get = goya_armcp_info_get; -/* according to goya_init_iatu */ goya->ddr_bar_cur_addr =DRAM_PHYS_BASE ;
@@ -2969,7 +2964,6 @@ int goya_test_cpu_queue(struct hl_device *hdev)static int goya_test_queues (struct hl_device *hdev) { -struct goya_device *goya = hdev->asic_specific;int i, rc, ret_val =0 ;for (i =0 ; i <NUMBER_OF_EXT_HW_QUEUES ; i++) {
@@ -2979,7 +2973,7 @@ static int goya_test_queues(struct hl_device *hdev) }if (hdev->cpu_queues_enable) { - rc = goya->test_cpu_queue (hdev); + rc =goya_test_cpu_queue (hdev);if (rc) ret_val = -EINVAL ; }
@@ -4657,7 +4651,7 @@ int goya_send_heartbeat(struct hl_device *hdev)return hl_fw_send_heartbeat (hdev); } -static int goya_armcp_info_get (struct hl_device *hdev) +int goya_armcp_info_get (struct hl_device *hdev) {struct goya_device *goya = hdev->asic_specific;struct asic_fixed_properties *prop = &hdev->asic_prop;
drivers/misc/habanalabs/goya/goyaP.h +1 -3
@@ -143,9 +143,6 @@ enum goya_fw_component { };struct goya_device { -int (*test_cpu_queue)(struct hl_device *hdev); -int (*armcp_info_get)(struct hl_device *hdev); -/* TODO: remove hw_queues_lock after moving to scheduler code */ spinlock_t hw_queues_lock;
@@ -176,6 +173,7 @@ void goya_debugfs_led_set(struct hl_device *hdev, u8 led, u8 state);void goya_set_pll_profile (struct hl_device *hdev,enum hl_pll_frequency freq);void goya_add_device_attr (struct hl_device *hdev,struct attribute_group *dev_attr_grp); +int goya_armcp_info_get (struct hl_device *hdev);void goya_init_security (struct hl_device *hdev);u64 goya_get_max_power (struct hl_device *hdev);void goya_set_max_power (struct hl_device *hdev,u64 value);
Signature · 1 line
2.17.1
PATCH 10/15 uapi/habanalabs: add some comments in habanalabs.h
In reply to Oded GabbayThis patch adds two comments in uapi/habanalabs.h:
- From which queue id the internal queues begin
- Invalid values that can be returned in the seq field from the CS IOCTL
--- include/uapi/misc/habanalabs.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
include/uapi/misc/habanalabs.h +5 -2
@@ -33,7 +33,7 @@ enum goya_queue_id {GOYA_QUEUE_ID_DMA_3 ,GOYA_QUEUE_ID_DMA_4 ,GOYA_QUEUE_ID_CPU_PQ , -GOYA_QUEUE_ID_MME , +GOYA_QUEUE_ID_MME ,/* Internal queues start here */ GOYA_QUEUE_ID_TPC0 ,GOYA_QUEUE_ID_TPC1 , GOYA_QUEUE_ID_TPC2,
@@ -181,7 +181,10 @@ struct hl_cs_in { };struct hl_cs_out { -/* this holds the sequence number of the CS to pass to wait ioctl */ +/* +* seq holds the sequence number of the CS to pass to wait ioctl. All +* values are valid except for 0 and ULLONG_MAX +*/ __u64 seq;/* HL_CS_STATUS_* */ __u32 status;
Signature · 1 line
2.17.1
PATCH 12/15 habanalabs: Allow accessing DRAM virtual addresses via debugfs
In reply to Oded GabbayFrom: Tomer Tayar <[email protected]>
The addr/data32 debugfs nodes currently permit the access to only physical addresses of a device. This patch extends it and allows accessing also device's DRAM virtual addresses.
--- drivers/misc/habanalabs/debugfs.c | 96 +++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 5 deletions(-)
drivers/misc/habanalabs/debugfs.c +91 -5
@@ -505,22 +505,97 @@ static ssize_t mmu_write(struct file *file, const char __user *buf,return -EINVAL ; } +static int device_va_to_pa (struct hl_device *hdev,u64 virt_addr, +u64 *phys_addr) +{ +struct hl_ctx *ctx = hdev->user_ctx; +u64 hop_addr, hop_pte_addr, hop_pte; +int rc =0 ; + +if (!ctx) { +dev_err (hdev->dev,"no ctx available\n" ); +return -EINVAL ; + } + +mutex_lock (&ctx->mmu_lock); + +/* hop 0 */ + hop_addr =get_hop0_addr (ctx); + hop_pte_addr =get_hop0_pte_addr (ctx, hop_addr, virt_addr); + hop_pte = hdev->asic_funcs->read_pte (hdev, hop_pte_addr); + +/* hop 1 */ + hop_addr =get_next_hop_addr (hop_pte); +if (hop_addr ==ULLONG_MAX ) + goto not_mapped; + hop_pte_addr =get_hop1_pte_addr (ctx, hop_addr, virt_addr); + hop_pte = hdev->asic_funcs->read_pte (hdev, hop_pte_addr); + +/* hop 2 */ + hop_addr =get_next_hop_addr (hop_pte); +if (hop_addr ==ULLONG_MAX ) + goto not_mapped; + hop_pte_addr =get_hop2_pte_addr (ctx, hop_addr, virt_addr); + hop_pte = hdev->asic_funcs->read_pte (hdev, hop_pte_addr); + +/* hop 3 */ + hop_addr =get_next_hop_addr (hop_pte); +if (hop_addr ==ULLONG_MAX ) + goto not_mapped; + hop_pte_addr =get_hop3_pte_addr (ctx, hop_addr, virt_addr); + hop_pte = hdev->asic_funcs->read_pte (hdev, hop_pte_addr); + +if (!(hop_pte &LAST_MASK )) { +/* hop 4 */ + hop_addr =get_next_hop_addr (hop_pte); +if (hop_addr ==ULLONG_MAX ) + goto not_mapped; + hop_pte_addr =get_hop4_pte_addr (ctx, hop_addr, virt_addr); + hop_pte = hdev->asic_funcs->read_pte (hdev, hop_pte_addr); + } + +if (!(hop_pte &PAGE_PRESENT_MASK )) + goto not_mapped; + + *phys_addr = (hop_pte &PTE_PHYS_ADDR_MASK ) | (virt_addr &OFFSET_MASK ); + + goto out; + +not_mapped: +dev_err (hdev->dev,"virt addr 0x%llx is not mapped to phys addr\n" , + virt_addr); + rc = -EINVAL ; +out: +mutex_unlock (&ctx->mmu_lock); +return rc; +} +static ssize_t hl_data_read32 (struct file *f,char __user *buf,size_t count,loff_t *ppos) {struct hl_dbg_device_entry *entry =file_inode (f)->i_private;struct hl_device *hdev = entry->hdev; +struct asic_fixed_properties *prop = &hdev->asic_prop;char tmp_buf[32 ]; +u64 addr = entry->addr;u32 val;ssize_t rc;if (*ppos)return 0 ; - rc = hdev->asic_funcs->debugfs_read32 (hdev, entry->addr, &val); +if (addr >= prop->va_space_dram_start_address && + addr < prop->va_space_dram_end_address && + hdev->mmu_enable && + hdev->dram_supports_virtual_memory) { + rc =device_va_to_pa (hdev, entry->addr, &addr); +if (rc) +return rc; + } + + rc = hdev->asic_funcs->debugfs_read32 (hdev, addr, &val);if (rc) { -dev_err (hdev->dev,"Failed to read from 0x%010llx\n" , - entry->addr); +dev_err (hdev->dev,"Failed to read from 0x%010llx\n" , addr);return rc; }
@@ -536,6 +611,8 @@ static ssize_t hl_data_write32(struct file *f, const char __user *buf, {struct hl_dbg_device_entry *entry =file_inode (f)->i_private;struct hl_device *hdev = entry->hdev; +struct asic_fixed_properties *prop = &hdev->asic_prop; +u64 addr = entry->addr;u32 value;ssize_t rc;
@@ -543,10 +620,19 @@ static ssize_t hl_data_write32(struct file *f, const char __user *buf,if (rc)return rc; - rc = hdev->asic_funcs->debugfs_write32 (hdev, entry->addr, value); +if (addr >= prop->va_space_dram_start_address && + addr < prop->va_space_dram_end_address && + hdev->mmu_enable && + hdev->dram_supports_virtual_memory) { + rc =device_va_to_pa (hdev, entry->addr, &addr); +if (rc) +return rc; + } + + rc = hdev->asic_funcs->debugfs_write32 (hdev, addr, value);if (rc) {dev_err (hdev->dev,"Failed to write 0x%08x to 0x%010llx\n" , - value, entry->addr); + value, addr);return rc; }
Signature · 1 line
2.17.1
PATCH 15/15 habanalabs: never fail hard reset of device
In reply to Oded GabbayHard-reset of our device should never fail, due to dangers of permanent damage to the H/W.
This patch removes the last place in the reset path where the driver might exit before doing the actual reset.
--- drivers/misc/habanalabs/device.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/misc/habanalabs/device.c +9 -10
@@ -663,17 +663,9 @@ int hl_device_reset(struct hl_device *hdev, bool hard_reset,/* Go over all the queues, release all CS and their jobs */ hl_cs_rollback_all (hdev); -if (hard_reset) { -/* Release kernel context */ -if (hl_ctx_put (hdev->kernel_ctx) !=1 ) { -dev_err (hdev->dev, -"kernel ctx is alive during hard reset\n" ); - rc = -EBUSY ; - goto out_err; - } - +/* Release kernel context */ +if ((hard_reset) && (hl_ctx_put (hdev->kernel_ctx) ==1 )) hdev->kernel_ctx =NULL ; - }/* Reset the H/W. It will be in idle state after this returns */ hdev->asic_funcs->hw_fini (hdev, hard_reset);
@@ -699,6 +691,13 @@ int hl_device_reset(struct hl_device *hdev, bool hard_reset,if (hard_reset) { hdev->device_cpu_disabled = false; +if (hdev->kernel_ctx) { +dev_crit (hdev->dev, +"kernel ctx was alive during hard reset, something is terribly wrong\n" ); + rc = -EBUSY ; + goto out_err; + } +/* Allocate the kernel context */ hdev->kernel_ctx =kzalloc (sizeof (*hdev->kernel_ctx),GFP_KERNEL );
Signature · 1 line
2.17.1
PATCH 14/15 habanalabs: keep track of the device's dma mask
In reply to Oded GabbayThis patch refactors the code that is responsible to set the DMA mask for the device.
Upon each change of the dma mask, the driver will save the new value that was set. This is needed in order to make sure we don't try to increase the mask a second time, in case we failed in the first time. This is especially relevant for Power machines, as that may cause a change in configuration of the TVT which will break the device.
Goya will first try to set the device's dma mask to 39 bits, so that the memory that is allocated on the host machine for communication with the device's cpu will be in a bus address which is lower then 39 bits. Later, Goya will try to increase that mask to 48 bits, but only if setting the mask to 39 bits was successful.
--- drivers/misc/habanalabs/goya/goya.c | 32 ++++-------- drivers/misc/habanalabs/habanalabs.h | 5 +- drivers/misc/habanalabs/habanalabs_drv.c | 3 ++ drivers/misc/habanalabs/pci.c | 64 ++++++++++++++++++------ 4 files changed, 65 insertions(+), 39 deletions(-)
drivers/misc/habanalabs/goya/goya.c +10 -22
@@ -483,7 +483,7 @@ static int goya_early_init(struct hl_device *hdev) prop->dram_pci_bar_size =pci_resource_len (pdev,DDR_BAR_ID ); - rc =hl_pci_init (hdev); + rc =hl_pci_init (hdev,39 );if (rc)return rc;
@@ -2446,28 +2446,16 @@ static int goya_hw_init(struct hl_device *hdev) goto disable_msix; } -/* CPU initialization is finished, we can now move to 48 bit DMA mask */ - rc =pci_set_dma_mask (hdev->pdev,DMA_BIT_MASK (48 )); -if (rc) { -dev_warn (hdev->dev,"Unable to set pci dma mask to 48 bits\n" ); - rc =pci_set_dma_mask (hdev->pdev,DMA_BIT_MASK (32 )); -if (rc) { -dev_err (hdev->dev, -"Unable to set pci dma mask to 32 bits\n" ); - goto disable_pci_access; - } - } - - rc =pci_set_consistent_dma_mask (hdev->pdev,DMA_BIT_MASK (48 )); -if (rc) { -dev_warn (hdev->dev, -"Unable to set pci consistent dma mask to 48 bits\n" ); - rc =pci_set_consistent_dma_mask (hdev->pdev,DMA_BIT_MASK (32 )); -if (rc) { -dev_err (hdev->dev, -"Unable to set pci consistent dma mask to 32 bits\n" ); +/* +* Check if we managed to set the DMA mask to more then 32 bits. If so, +* let's try to increase it again because in Goya we set the initial +* dma mask to less then 39 bits so that the allocation of the memory +* area for the device's cpu will be under 39 bits +*/ +if (hdev->dma_mask >32 ) { + rc =hl_pci_set_dma_mask (hdev,48 ); +if (rc) goto disable_pci_access; - } }/* Perform read from the device to flush all MSI-X configuration */
drivers/misc/habanalabs/habanalabs.h +4 -1
@@ -1106,6 +1106,7 @@ struct hl_device_reset_work {* @init_done: is the initialization of the device done. * @mmu_enable: is MMU enabled. * @device_cpu_disabled: is the device CPU disabled (due to timeouts) +* @dma_mask: the dma mask that was set for this device */ struct hl_device {struct pci_dev *pdev;
@@ -1176,6 +1177,7 @@ struct hl_device {u8 dram_default_page_mapping;u8 init_done;u8 device_cpu_disabled; +u8 dma_mask;/* Parameters for bring-up */ u8 mmu_enable;
@@ -1397,8 +1399,9 @@ int hl_pci_set_dram_bar_base(struct hl_device *hdev, u8 inbound_region, u8 bar, u64 addr);int hl_pci_init_iatu (struct hl_device *hdev,u64 sram_base_address,u64 dram_base_address,u64 host_phys_size); -int hl_pci_init (struct hl_device *hdev); +int hl_pci_init (struct hl_device *hdev,u8 dma_mask);void hl_pci_fini (struct hl_device *hdev); +int hl_pci_set_dma_mask (struct hl_device *hdev,u8 dma_mask);long hl_get_frequency (struct hl_device *hdev,u32 pll_index,bool curr);void hl_set_frequency (struct hl_device *hdev,u32 pll_index,u64 freq);
drivers/misc/habanalabs/habanalabs_drv.c +3 -0
@@ -229,6 +229,9 @@ int create_hdev(struct hl_device **dev, struct pci_dev *pdev, hdev->asic_type = asic_type; } +/* Set default DMA mask to 32 bits */ + hdev->dma_mask =32 ; +mutex_lock (&hl_devs_idr_lock);if (minor ==-1 ) {
drivers/misc/habanalabs/pci.c +48 -16
90 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 13/15 habanalabs: add MMU shadow mapping
In reply to Oded GabbayFrom: Omer Shpigelman <[email protected]>
This patch adds shadow mapping to the MMU module. The shadow mapping allows traversing the page table in host memory rather reading each PTE from the device memory.
It brings better performance and avoids reading from invalid device address upon PCI errors.
Only at the end of map/unmap flow, writings to the device are performed in order to sync the H/W page tables with the shadow ones.
--- drivers/misc/habanalabs/habanalabs.h | 24 +- .../include/hw_ip/mmu/mmu_general.h | 16 +- drivers/misc/habanalabs/mmu.c | 597 ++++++++++-------- 3 files changed, 353 insertions(+), 284 deletions(-)
drivers/misc/habanalabs/habanalabs.h +15 -9
@@ -51,8 +51,9 @@/** * struct pgt_info - MMU hop page info. -* @node: hash linked-list node for the pgts hash of pgts. -* @addr: physical address of the pgt. +* @node: hash linked-list node for the pgts shadow hash of pgts. +* @phys_addr: physical address of the pgt. +* @shadow_addr: shadow hop in the host. * @ctx: pointer to the owner ctx. * @num_of_ptes: indicates how many ptes are used in the pgt. *
@@ -62,10 +63,11 @@* page, it is freed with its pgt_info structure. */ struct pgt_info { -struct hlist_node node; -u64 addr; -struct hl_ctx *ctx; -int num_of_ptes; +struct hlist_node node; +u64 phys_addr; +u64 shadow_addr; +struct hl_ctx *ctx; +int num_of_ptes; };struct hl_device ;
@@ -595,7 +597,8 @@ struct hl_va_range {* struct hl_ctx - user/kernel context. * @mem_hash: holds mapping from virtual address to virtual memory area * descriptor (hl_vm_phys_pg_list or hl_userptr). -* @mmu_hash: holds a mapping from virtual address to pgt_info structure. +* @mmu_phys_hash: holds a mapping from physical address to pgt_info structure. +* @mmu_shadow_hash: holds a mapping from shadow address to pgt_info structure. * @hpriv: pointer to the private (KMD) data of the process (fd). * @hdev: pointer to the device structure. * @refcount: reference counter for the context. Context is released only when
@@ -624,7 +627,8 @@ struct hl_va_range {*/ struct hl_ctx { DECLARE_HASHTABLE(mem_hash, MEM_HASH_TABLE_BITS); - DECLARE_HASHTABLE(mmu_hash, MMU_HASH_TABLE_BITS); + DECLARE_HASHTABLE(mmu_phys_hash, MMU_HASH_TABLE_BITS); + DECLARE_HASHTABLE(mmu_shadow_hash, MMU_HASH_TABLE_BITS);struct hl_fpriv *hpriv;struct hl_device *hdev;struct kref refcount;
@@ -1066,7 +1070,8 @@ struct hl_device_reset_work {* @asic_specific: ASIC specific information to use only from ASIC files. * @mmu_pgt_pool: pool of available MMU hops. * @vm: virtual memory manager for MMU. -* @mmu_cache_lock: protects MMU cache invalidation as it can serve one context +* @mmu_cache_lock: protects MMU cache invalidation as it can serve one context. +* @mmu_shadow_hop0: shadow mapping of the MMU hop 0 zone. * @hwmon_dev: H/W monitor device. * @pm_mng_profile: current power management profile. * @hl_chip_info: ASIC's sensors information.
@@ -1136,6 +1141,7 @@ struct hl_device {struct gen_pool *mmu_pgt_pool;struct hl_vm vm;struct mutex mmu_cache_lock; +void *mmu_shadow_hop0;struct device *hwmon_dev;enum hl_pm_mng_profile pm_mng_profile;struct hwmon_chip_info *hl_chip_info;
drivers/misc/habanalabs/include/hw_ip/mmu/mmu_general.h +8 -8
@@ -14,16 +14,16 @@#define PAGE_SIZE_4KB (_AC(1, UL) << PAGE_SHIFT_4KB)#define PAGE_MASK_2MB (~(PAGE_SIZE_2MB - 1)) -#define PAGE_PRESENT_MASK 0x0000000000001 -#define SWAP_OUT_MASK 0x0000000000004 -#define LAST_MASK 0x0000000000800 -#define PHYS_ADDR_MASK 0x3FFFFFFFFF000ull +#define PAGE_PRESENT_MASK 0x0000000000001ull +#define SWAP_OUT_MASK 0x0000000000004ull +#define LAST_MASK 0x0000000000800ull +#define PHYS_ADDR_MASK 0xFFFFFFFFFFFFF000ull#define HOP0_MASK 0x3000000000000ull#define HOP1_MASK 0x0FF8000000000ull#define HOP2_MASK 0x0007FC0000000ull -#define HOP3_MASK 0x000003FE00000 -#define HOP4_MASK 0x00000001FF000 -#define OFFSET_MASK 0x0000000000FFF +#define HOP3_MASK 0x000003FE00000ull +#define HOP4_MASK 0x00000001FF000ull +#define OFFSET_MASK 0x0000000000FFFull#define HOP0_SHIFT 48#define HOP1_SHIFT 39
@@ -32,7 +32,7 @@#define HOP4_SHIFT 12#define PTE_PHYS_ADDR_SHIFT 12 -#define PTE_PHYS_ADDR_MASK ~0xFFF +#define PTE_PHYS_ADDR_MASK ~OFFSET_MASK#define HL_PTE_SIZE sizeof(u64)#define HOP_TABLE_SIZE PAGE_SIZE_4KB
drivers/misc/habanalabs/mmu.c +330 -267
896 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 8/15 habanalabs: Move PCI code into common file
In reply to Oded GabbayFrom: Tomer Tayar <[email protected]>
Move duplicated PCI-related code from ASIC-specific files into the common pci.c file.
--- drivers/misc/habanalabs/Makefile | 2 +- drivers/misc/habanalabs/goya/goya.c | 272 +------------ drivers/misc/habanalabs/habanalabs.h | 20 + .../include/goya/asic_reg/goya_masks.h | 12 - .../include/hw_ip/pci/pci_general.h | 23 ++ drivers/misc/habanalabs/pci.c | 370 ++++++++++++++++++ 6 files changed, 434 insertions(+), 265 deletions(-) create mode 100644 drivers/misc/habanalabs/include/hw_ip/pci/pci_general.h create mode 100644 drivers/misc/habanalabs/pci.c
drivers/misc/habanalabs/Makefile +1 -1
@@ -6,7 +6,7 @@ obj-m := habanalabs.o habanalabs-y := habanalabs_drv.o device.o context.o asid.o habanalabs_ioctl.o \ command_buffer.o hw_queue.o irq.o sysfs.o hwmon.o memory.o \ - command_submission.o mmu.o firmware_if.o + command_submission.o mmu.o firmware_if.o pci.o habanalabs-$(CONFIG_DEBUG_FS) += debugfs.o
drivers/misc/habanalabs/goya/goya.c +20 -252
334 lines not on this page · raw message
drivers/misc/habanalabs/habanalabs.h +20 -0
@@ -148,6 +148,8 @@ enum hl_device_hw_state {* mapping DRAM memory. * @dram_size_for_default_page_mapping: DRAM size needed to map to avoid page * fault. +* @pcie_dbi_base_address: Base address of the PCIE_DBI block. +* @pcie_aux_dbi_reg_addr: Address of the PCIE_AUX DBI register. * @mmu_pgt_addr: base physical address in DRAM of MMU page tables. * @mmu_dram_default_page_addr: DRAM default page physical address. * @mmu_pgt_size: MMU page tables total size.
@@ -189,6 +191,8 @@ struct asic_fixed_properties {u64 va_space_dram_start_address;u64 va_space_dram_end_address;u64 dram_size_for_default_page_mapping; +u64 pcie_dbi_base_address; +u64 pcie_aux_dbi_reg_addr;u64 mmu_pgt_addr;u64 mmu_dram_default_page_addr;u32 mmu_pgt_size;
@@ -485,6 +489,9 @@ enum hl_pll_frequency {* @get_eeprom_data: retrieve EEPROM data from F/W. * @send_cpu_message: send buffer to ArmCP. * @get_hw_state: retrieve the H/W state +* @pci_bars_map: Map PCI BARs. +* @set_dram_bar_base: Set DRAM BAR to map specific device address. +* @init_iatu: Initialize the iATU unit inside the PCI controller. */ struct hl_asic_funcs {int (*early_init)(struct hl_device *hdev);
@@ -558,6 +565,9 @@ struct hl_asic_funcs {int (*send_cpu_message)(struct hl_device *hdev,u32 *msg,u16 len,u32 timeout,long *result);enum hl_device_hw_state (*get_hw_state)(struct hl_device *hdev); +int (*pci_bars_map)(struct hl_device *hdev); +int (*set_dram_bar_base)(struct hl_device *hdev,u64 addr); +int (*init_iatu)(struct hl_device *hdev); };
@@ -1368,6 +1378,16 @@ int hl_fw_send_heartbeat(struct hl_device *hdev);int hl_fw_armcp_info_get (struct hl_device *hdev);int hl_fw_get_eeprom_data (struct hl_device *hdev,void *data,size_t max_size); +int hl_pci_bars_map (struct hl_device *hdev,const char *const name[3 ], +bool is_wc[3 ]); +int hl_pci_iatu_write (struct hl_device *hdev,u32 addr,u32 data); +int hl_pci_set_dram_bar_base (struct hl_device *hdev,u8 inbound_region,u8 bar, +u64 addr); +int hl_pci_init_iatu (struct hl_device *hdev,u64 sram_base_address, +u64 dram_base_address,u64 host_phys_size); +int hl_pci_init (struct hl_device *hdev); +void hl_pci_fini (struct hl_device *hdev); +long hl_get_frequency (struct hl_device *hdev,u32 pll_index,bool curr);void hl_set_frequency (struct hl_device *hdev,u32 pll_index,u64 freq);long hl_get_temperature (struct hl_device *hdev,int sensor_index,u32 attr);
drivers/misc/habanalabs/include/goya/asic_reg/goya_masks.h +0 -12
@@ -189,18 +189,6 @@ 1 << CPU_CA53_CFG_ARM_RST_CONTROL_NL2RESET_SHIFT |\ 1 << CPU_CA53_CFG_ARM_RST_CONTROL_NMBISTRESET_SHIFT) -/* PCI CONFIGURATION SPACE */ -#define mmPCI_CONFIG_ELBI_ADDR 0xFF0 -#define mmPCI_CONFIG_ELBI_DATA 0xFF4 -#define mmPCI_CONFIG_ELBI_CTRL 0xFF8 -#define PCI_CONFIG_ELBI_CTRL_WRITE (1 << 31) - -#define mmPCI_CONFIG_ELBI_STS 0xFFC -#define PCI_CONFIG_ELBI_STS_ERR (1 << 30) -#define PCI_CONFIG_ELBI_STS_DONE (1 << 31) -#define PCI_CONFIG_ELBI_STS_MASK (PCI_CONFIG_ELBI_STS_ERR | \ - PCI_CONFIG_ELBI_STS_DONE) -#define GOYA_IRQ_HBW_ID_MASK 0x1FFF#define GOYA_IRQ_HBW_ID_SHIFT 0#define GOYA_IRQ_HBW_INTERNAL_ID_MASK 0xE000
drivers/misc/habanalabs/include/hw_ip/pci/pci_general.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright 2016-2019 HabanaLabs, Ltd. +* All Rights Reserved. +* +*/ + +#ifndef INCLUDE_PCI_GENERAL_H_ +#define INCLUDE_PCI_GENERAL_H_ + +/* PCI CONFIGURATION SPACE */ +#define mmPCI_CONFIG_ELBI_ADDR 0xFF0 +#define mmPCI_CONFIG_ELBI_DATA 0xFF4 +#define mmPCI_CONFIG_ELBI_CTRL 0xFF8 +#define PCI_CONFIG_ELBI_CTRL_WRITE (1 << 31) + +#define mmPCI_CONFIG_ELBI_STS 0xFFC +#define PCI_CONFIG_ELBI_STS_ERR (1 << 30) +#define PCI_CONFIG_ELBI_STS_DONE (1 << 31) +#define PCI_CONFIG_ELBI_STS_MASK (PCI_CONFIG_ELBI_STS_ERR | \ + PCI_CONFIG_ELBI_STS_DONE) + +#endif /* INCLUDE_PCI_GENERAL_H_ */
drivers/misc/habanalabs/pci.c new file +370 -0
370 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 11/15 habanalabs: Add a printout with the name of a busy engine
In reply to Oded GabbayFrom: Tomer Tayar <[email protected]>
Print the name of a busy engine when checking if a device is idle. The change is done mainly to help a user to pinpoint problems in his topology's recipe.
--- drivers/misc/habanalabs/goya/goya.c | 24 ++++++++++++---------- drivers/misc/habanalabs/habanalabs.h | 8 +++++++- drivers/misc/habanalabs/habanalabs_ioctl.c | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-)
drivers/misc/habanalabs/goya/goya.c +13 -11
@@ -2784,6 +2784,7 @@ static int goya_send_job_on_qman0(struct hl_device *hdev, struct hl_cs_job *job)dma_addr_t fence_dma_addr;struct hl_cb *cb;u32 tmp, timeout; +char buf[16 ] = {};int rc;if (hdev->pldm)
@@ -2791,9 +2792,10 @@ static int goya_send_job_on_qman0(struct hl_device *hdev, struct hl_cs_job *job)else timeout =HL_DEVICE_TIMEOUT_USEC ; -if (!hdev->asic_funcs->is_device_idle (hdev)) { +if (!hdev->asic_funcs->is_device_idle (hdev, buf,sizeof (buf))) {dev_err_ratelimited (hdev->dev, -"Can't send KMD job on QMAN0 if device is not idle\n" ); +"Can't send KMD job on QMAN0 because %s is busy\n" , + buf);return -EBUSY ; }
@@ -4692,7 +4694,7 @@ static void goya_disable_clock_gating(struct hl_device *hdev) } -static bool goya_is_device_idle (struct hl_device *hdev) +static bool goya_is_device_idle (struct hl_device *hdev,char *buf,size_t size) {u64 offset, dma_qm_reg, tpc_qm_reg, tpc_cmdq_reg, tpc_cfg_reg;int i;
@@ -4704,7 +4706,7 @@ static bool goya_is_device_idle(struct hl_device *hdev)if ((RREG32 (dma_qm_reg) &DMA_QM_IDLE_MASK ) !=DMA_QM_IDLE_MASK ) -return false; +return HL_ENG_BUSY (buf, size,"DMA%d_QM" , i); } offset = mmTPC1_QM_GLBL_STS0 - mmTPC0_QM_GLBL_STS0;
@@ -4716,31 +4718,31 @@ static bool goya_is_device_idle(struct hl_device *hdev)if ((RREG32 (tpc_qm_reg) &TPC_QM_IDLE_MASK ) !=TPC_QM_IDLE_MASK ) -return false; +return HL_ENG_BUSY (buf, size,"TPC%d_QM" , i);if ((RREG32 (tpc_cmdq_reg) &TPC_CMDQ_IDLE_MASK ) !=TPC_CMDQ_IDLE_MASK ) -return false; +return HL_ENG_BUSY (buf, size,"TPC%d_CMDQ" , i);if ((RREG32 (tpc_cfg_reg) &TPC_CFG_IDLE_MASK ) !=TPC_CFG_IDLE_MASK ) -return false; +return HL_ENG_BUSY (buf, size,"TPC%d_CFG" , i); }if ((RREG32 (mmMME_QM_GLBL_STS0) &MME_QM_IDLE_MASK ) !=MME_QM_IDLE_MASK ) -return false; +return HL_ENG_BUSY (buf, size,"MME_QM" );if ((RREG32 (mmMME_CMDQ_GLBL_STS0) &MME_CMDQ_IDLE_MASK ) !=MME_CMDQ_IDLE_MASK ) -return false; +return HL_ENG_BUSY (buf, size,"MME_CMDQ" );if ((RREG32 (mmMME_ARCH_STATUS) &MME_ARCH_IDLE_MASK ) !=MME_ARCH_IDLE_MASK ) -return false; +return HL_ENG_BUSY (buf, size,"MME_ARCH" );if (RREG32 (mmMME_SHADOW_0_STATUS) &MME_SHADOW_IDLE_MASK ) -return false; +return HL_ENG_BUSY (buf, size,"MME" );return true; }
drivers/misc/habanalabs/habanalabs.h +7 -1
@@ -555,7 +555,7 @@ struct hl_asic_funcs {int (*send_heartbeat)(struct hl_device *hdev);void (*enable_clock_gating)(struct hl_device *hdev);void (*disable_clock_gating)(struct hl_device *hdev); -bool (*is_device_idle)(struct hl_device *hdev); +bool (*is_device_idle)(struct hl_device *hdev,char *buf,size_t size);int (*soft_reset_late_init)(struct hl_device *hdev);void (*hw_queues_lock)(struct hl_device *hdev);void (*hw_queues_unlock)(struct hl_device *hdev);
@@ -1010,6 +1010,12 @@ void hl_wreg(struct hl_device *hdev, u32 reg, u32 val); WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | \ (val) << REG_FIELD_SHIFT(reg, field)) +#define HL_ENG_BUSY (buf, size, fmt, ...) ({ \ + if (buf) \ + snprintf(buf, size, fmt, ##__VA_ARGS__); \ + false; \ + }) +struct hwmon_chip_info ;/**
drivers/misc/habanalabs/habanalabs_ioctl.c +1 -1
@@ -93,7 +93,7 @@ static int hw_idle(struct hl_device *hdev, struct hl_info_args *args)if ((!max_size) || (!out))return -EINVAL ; - hw_idle.is_idle = hdev->asic_funcs->is_device_idle (hdev); + hw_idle.is_idle = hdev->asic_funcs->is_device_idle (hdev,NULL ,0 );return copy_to_user (out, &hw_idle,min ((size_t ) max_size,sizeof (hw_idle))) ? -EFAULT :0 ;
Signature · 1 line
2.17.1
PATCH 5/15 habanalabs: use EQ MSI/X ID per chip
In reply to Oded GabbayThe Event Queue MSI/X ID is different per ASIC. This patch renames the current define to have the GOYA_ prefix to mark it only for Goya. It also moves it from the common armcp_if.h file to the ASIC specific goya_fw_if.h file.
--- drivers/misc/habanalabs/goya/goya.c | 8 ++++---- drivers/misc/habanalabs/include/armcp_if.h | 2 -- drivers/misc/habanalabs/include/goya/goya_fw_if.h | 2 ++ 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/misc/habanalabs/goya/goya.c +4 -4
@@ -2205,10 +2205,10 @@ static int goya_enable_msix(struct hl_device *hdev) } } - irq =pci_irq_vector (hdev->pdev,EVENT_QUEUE_MSIX_IDX ); + irq =pci_irq_vector (hdev->pdev,GOYA_EVENT_QUEUE_MSIX_IDX ); rc =request_irq (irq, hl_irq_handler_eq,0 , - goya_irq_name[EVENT_QUEUE_MSIX_IDX ], + goya_irq_name[GOYA_EVENT_QUEUE_MSIX_IDX ], &hdev->event_queue);if (rc) {dev_err (hdev->dev,"Failed to request IRQ %d" , irq);
@@ -2239,7 +2239,7 @@ static void goya_sync_irqs(struct hl_device *hdev)for (i =0 ; i < hdev->asic_prop.completion_queues_count ; i++)synchronize_irq (pci_irq_vector (hdev->pdev, i)); -synchronize_irq (pci_irq_vector (hdev->pdev,EVENT_QUEUE_MSIX_IDX )); +synchronize_irq (pci_irq_vector (hdev->pdev,GOYA_EVENT_QUEUE_MSIX_IDX )); }static void goya_disable_msix (struct hl_device *hdev)
@@ -2252,7 +2252,7 @@ static void goya_disable_msix(struct hl_device *hdev)goya_sync_irqs (hdev); - irq =pci_irq_vector (hdev->pdev,EVENT_QUEUE_MSIX_IDX ); + irq =pci_irq_vector (hdev->pdev,GOYA_EVENT_QUEUE_MSIX_IDX );free_irq (irq, &hdev->event_queue);for (i =0 ; i < hdev->asic_prop.completion_queues_count ; i++) {
drivers/misc/habanalabs/include/armcp_if.h +0 -2
@@ -32,8 +32,6 @@ struct hl_eq_entry {#define EQ_CTL_EVENT_TYPE_SHIFT 16#define EQ_CTL_EVENT_TYPE_MASK 0x03FF0000 -#define EVENT_QUEUE_MSIX_IDX 5 -enum pq_init_status {PQ_INIT_STATUS_NA =0 ,PQ_INIT_STATUS_READY_FOR_CP ,
drivers/misc/habanalabs/include/goya/goya_fw_if.h +2 -0
@@ -8,6 +8,8 @@#ifndef GOYA_FW_IF_H #define GOYA_FW_IF_H +#define GOYA_EVENT_QUEUE_MSIX_IDX 5 +#define CPU_BOOT_ADDR 0x7FF8040000ull#define UBOOT_FW_OFFSET 0x100000/* 1MB in SRAM */
Signature · 1 line
2.17.1
PATCH 6/15 habanalabs: remove unused defines
In reply to Oded GabbayThis patch removes some old defines which are not in use anymore.
--- drivers/misc/habanalabs/goya/goyaP.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/misc/habanalabs/goya/goyaP.h +6 -8
@@ -54,11 +54,9 @@/* DRAM Memory Map */ #define CPU_FW_IMAGE_SIZE 0x10000000/* 256MB */ -#define MMU_PAGE_TABLES_SIZE 0x0DE00000/* 222MB */ +#define MMU_PAGE_TABLES_SIZE 0x0FC00000/* 252MB */ #define MMU_DRAM_DEFAULT_PAGE_SIZE 0x00200000/* 2MB */ #define MMU_CACHE_MNG_SIZE 0x00001000/* 4KB */ -#define CPU_PQ_PKT_SIZE 0x00001000/* 4KB */ -#define CPU_PQ_DATA_SIZE 0x01FFE000/* 32MB - 8KB */ #define CPU_FW_IMAGE_ADDR DRAM_PHYS_BASE#define MMU_PAGE_TABLES_ADDR (CPU_FW_IMAGE_ADDR + CPU_FW_IMAGE_SIZE)
@@ -66,13 +64,13 @@ MMU_PAGE_TABLES_SIZE)#define MMU_CACHE_MNG_ADDR (MMU_DRAM_DEFAULT_PAGE_ADDR + \ MMU_DRAM_DEFAULT_PAGE_SIZE) -#define CPU_PQ_PKT_ADDR (MMU_CACHE_MNG_ADDR + \ +#define DRAM_KMD_END_ADDR (MMU_CACHE_MNG_ADDR + \ MMU_CACHE_MNG_SIZE) -#define CPU_PQ_DATA_ADDR (CPU_PQ_PKT_ADDR + CPU_PQ_PKT_SIZE) -#define DRAM_BASE_ADDR_USER (CPU_PQ_DATA_ADDR + CPU_PQ_DATA_SIZE) -#if (DRAM_BASE_ADDR_USER !=0x20000000 ) -#error "KMD must reserve 512MB" +#define DRAM_BASE_ADDR_USER 0x20000000 + +#if (DRAM_KMD_END_ADDR >DRAM_BASE_ADDR_USER ) +#error "KMD must reserve no more than 512MB"#endif /*
Signature · 1 line
2.17.1
PATCH 7/15 habanalabs: ratelimit warnings at start of IOCTLs
In reply to Oded GabbayAt the start of some IOCTLs we check if the device is disabled or in reset. If it is, we return -EBUSY and print a message to kernel log.
Because these IOCTLs can be called at very high frequency, use ratelimit to avoid spamming the kernel log. Also use the same type of message - dev_warn - in all the relevant IOCTLs.
--- drivers/misc/habanalabs/command_submission.c | 2 +- drivers/misc/habanalabs/habanalabs_ioctl.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/misc/habanalabs/command_submission.c +1 -1
@@ -604,7 +604,7 @@ int hl_cs_ioctl(struct hl_fpriv *hpriv, void *data)bool need_soft_reset = false;if (hl_device_disabled_or_in_reset (hdev)) { -dev_warn (hdev->dev, +dev_warn_ratelimited (hdev->dev,"Device is %s. Can't submit new CS\n" ,atomic_read (&hdev->in_reset) ?"in_reset" :"disabled" ); rc = -EBUSY ;
drivers/misc/habanalabs/habanalabs_ioctl.c +1 -1
@@ -106,7 +106,7 @@ static int hl_info_ioctl(struct hl_fpriv *hpriv, void *data)int rc;if (hl_device_disabled_or_in_reset (hdev)) { -dev_err (hdev->dev, +dev_warn_ratelimited (hdev->dev,"Device is disabled or in reset. Can't execute INFO IOCTL\n" );return -EBUSY ; }
Signature · 1 line
2.17.1