habanalabs: block WREG_BULK packet on PDMA
Subsystems (2)
PATCH 1/2 habanalabs: block WREG_BULK packet on PDMA
WREG_BULK is a special packet that has a variable length. Therefore, we can't parse it when validating CBs that go to the PCI DMA queue. In case the user needs to use it, it can put multiple WREG32 packets instead.
--- drivers/misc/habanalabs/gaudi/gaudi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/misc/habanalabs/gaudi/gaudi.c +6 -1
@@ -3865,6 +3865,12 @@ static int gaudi_validate_cb(struct hl_device *hdev, rc = -EPERM ;break ; +case PACKET_WREG_BULK : +dev_err (hdev->dev, +"User not allowed to use WREG_BULK\n" ); + rc = -EPERM ; +break ; +case PACKET_LOAD_AND_EXE : rc =gaudi_validate_load_and_exe_pkt (hdev, parser, (struct packet_load_and_exe *) user_pkt);
@@ -3880,7 +3886,6 @@ static int gaudi_validate_cb(struct hl_device *hdev,break ;case PACKET_WREG_32 : -case PACKET_WREG_BULK :case PACKET_MSG_LONG :case PACKET_MSG_SHORT :case PACKET_REPEAT :
Signature · 1 line
2.17.1
PATCH 2/2 habanalabs: set clock gating per engine
For debugging purposes, we need to allow the root user better control of the clock gating feature of the DMA and compute engines. Therefore, change the clock gating debugfs interface to be bitmask instead of true/false. Each bit represents a different engine, according to gaudi_engine_id enum.
See debugfs documentation for more details.
--- .../ABI/testing/debugfs-driver-habanalabs | 11 +- drivers/misc/habanalabs/debugfs.c | 17 +-- drivers/misc/habanalabs/device.c | 2 +- drivers/misc/habanalabs/gaudi/gaudi.c | 112 ++++++++++++------ drivers/misc/habanalabs/goya/goya.c | 8 +- drivers/misc/habanalabs/habanalabs.h | 13 +- drivers/misc/habanalabs/habanalabs_drv.c | 2 +- 7 files changed, 103 insertions(+), 62 deletions(-)
Documentation/ABI/testing/debugfs-driver-habanalabs +10 -1
@@ -16,7 +16,16 @@ Description: Allow the root user to disable/enable in runtime the clock gating mechanism in Gaudi. Due to how Gaudi is built, the clock gating needs to be disabled in order to access the registers of the TPC and MME engines. This is sometimes needed - during debug by the user and hence the user needs this option + during debug by the user and hence the user needs this option. + The user can supply a bitmask value, each bit represents + a different engine to disable/enable its clock gating feature. + The bitmask is composed of 20 bits: + 0 - 7 : DMA channels + 8 - 11 : MME engines + 12 - 19 : TPC engines + The bit's location of a specific engine can be determined + using (1 << GAUDI_ENGINE_ID_*). GAUDI_ENGINE_ID_* values + are defined in uapi habanalabs.h file in enum gaudi_engine_id What: /sys/kernel/debug/habanalabs/hl<n>/command_buffers Date: Jan 2019
drivers/misc/habanalabs/debugfs.c +5 -12
@@ -981,7 +981,7 @@ static ssize_t hl_clk_gate_read(struct file *f, char __user *buf,if (*ppos)return 0 ; -sprintf (tmp_buf,"%d\n" , hdev->clock_gating); +sprintf (tmp_buf,"0x%llx\n" , hdev->clock_gating_mask); rc =simple_read_from_buffer (buf,strlen (tmp_buf) +1 , ppos, tmp_buf,strlen (tmp_buf) +1 );
@@ -993,7 +993,7 @@ static ssize_t hl_clk_gate_write(struct file *f, const char __user *buf, {struct hl_dbg_device_entry *entry =file_inode (f)->i_private;struct hl_device *hdev = entry->hdev; -u32 value; +u64 value;ssize_t rc;if (atomic_read (&hdev->in_reset)) {
@@ -1002,19 +1002,12 @@ static ssize_t hl_clk_gate_write(struct file *f, const char __user *buf,return 0 ; } - rc =kstrtouint_from_user (buf, count,10 , &value); + rc =kstrtoull_from_user (buf, count,16 , &value);if (rc)return rc; -if (value) { - hdev->clock_gating =1 ; -if (hdev->asic_funcs->enable_clock_gating) - hdev->asic_funcs->enable_clock_gating (hdev); - }else { -if (hdev->asic_funcs->disable_clock_gating) - hdev->asic_funcs->disable_clock_gating (hdev); - hdev->clock_gating =0 ; - } + hdev->clock_gating_mask = value; + hdev->asic_funcs->set_clock_gating (hdev);return count; }
drivers/misc/habanalabs/device.c +1 -1
@@ -608,7 +608,7 @@ int hl_device_set_debug_mode(struct hl_device *hdev, bool enable) hdev->in_debug =0 ;if (!hdev->hard_reset_pending) - hdev->asic_funcs->enable_clock_gating (hdev); + hdev->asic_funcs->set_clock_gating (hdev); goto out; }
drivers/misc/habanalabs/gaudi/gaudi.c +74 -38
269 lines not on this page · raw message
drivers/misc/habanalabs/goya/goya.c +4 -4
@@ -5028,14 +5028,14 @@ int goya_armcp_info_get(struct hl_device *hdev)return 0 ; } -static void goya_enable_clock_gating (struct hl_device *hdev) +static void goya_set_clock_gating (struct hl_device *hdev) { - +/* clock gating not supported in Goya */ }static void goya_disable_clock_gating (struct hl_device *hdev) { - +/* clock gating not supported in Goya */ } static bool goya_is_device_idle(struct hl_device *hdev, u32 *mask,
@@ -5259,7 +5259,7 @@ static const struct hl_asic_funcs goya_funcs = { .mmu_invalidate_cache = goya_mmu_invalidate_cache, .mmu_invalidate_cache_range = goya_mmu_invalidate_cache_range, .send_heartbeat = goya_send_heartbeat, - .enable_clock_gating = goya_enable_clock_gating, + .set_clock_gating = goya_set_clock_gating, .disable_clock_gating = goya_disable_clock_gating, .debug_coresight = goya_debug_coresight, .is_device_idle = goya_is_device_idle,
drivers/misc/habanalabs/habanalabs.h +8 -5
@@ -578,8 +578,9 @@ enum hl_pll_frequency {* @mmu_invalidate_cache_range: flush specific MMU STLB cache lines with * ASID-VA-size mask. * @send_heartbeat: send is-alive packet to ArmCP and verify response. -* @enable_clock_gating: enable clock gating for reducing power consumption. -* @disable_clock_gating: disable clock for accessing registers on HBW. +* @set_clock_gating: enable/disable clock gating per engine according to +* clock gating mask in hdev +* @disable_clock_gating: disable clock gating completely * @debug_coresight: perform certain actions on Coresight for debugging. * @is_device_idle: return true if device is idle, false otherwise. * @soft_reset_late_init: perform certain actions needed after soft reset.
@@ -680,7 +681,7 @@ struct hl_asic_funcs {int (*mmu_invalidate_cache_range)(struct hl_device *hdev,bool is_hard,u32 asid,u64 va,u64 size);int (*send_heartbeat)(struct hl_device *hdev); -void (*enable_clock_gating)(struct hl_device *hdev); +void (*set_clock_gating)(struct hl_device *hdev);void (*disable_clock_gating)(struct hl_device *hdev);int (*debug_coresight)(struct hl_device *hdev,void *data); bool (*is_device_idle)(struct hl_device *hdev, u32 *mask,
@@ -1398,6 +1399,9 @@ struct hl_device_idle_busy_ts {* @max_power: the max power of the device, as configured by the sysadmin. This * value is saved so in case of hard-reset, the driver will restore * this value and update the F/W after the re-initialization +* @clock_gating_mask: is clock gating enabled. bitmask that represents the +* different engines. See debugfs-driver-habanalabs for +* details. * @in_reset: is device in reset flow. * @curr_pll_profile: current PLL profile. * @cs_active_cnt: number of active command submissions on this device (active
@@ -1425,7 +1429,6 @@ struct hl_device_idle_busy_ts {* @init_done: is the initialization of the device done. * @mmu_enable: is MMU enabled. * @mmu_huge_page_opt: is MMU huge pages optimization enabled. -* @clock_gating: is clock gating enabled. * @device_cpu_disabled: is the device CPU disabled (due to timeouts) * @dma_mask: the dma mask that was set for this device * @in_debug: is device under debug. This, together with fpriv_list, enforces
@@ -1493,6 +1496,7 @@ struct hl_device {atomic64_t dram_used_mem;u64 timeout_jiffies;u64 max_power; +u64 clock_gating_mask;atomic_t in_reset;enum hl_pll_frequency curr_pll_profile;int cs_active_cnt;
@@ -1514,7 +1518,6 @@ struct hl_device {u8 dram_default_page_mapping;u8 pmmu_huge_range;u8 init_done; -u8 clock_gating;u8 device_cpu_disabled;u8 dma_mask;u8 in_debug;
drivers/misc/habanalabs/habanalabs_drv.c +1 -1
@@ -232,7 +232,7 @@ static void set_driver_behavior_per_device(struct hl_device *hdev) hdev->fw_loading =1 ; hdev->cpu_queues_enable =1 ; hdev->heartbeat =1 ; - hdev->clock_gating =1 ; + hdev->clock_gating_mask =ULONG_MAX ; hdev->reset_pcilink =0 ; hdev->axi_drain =0 ;
Signature · 1 line
2.17.1
Quoted 5 lines · Oded Gabbay
WREG_BULKis a special packet that has a variable length. Therefore, we can't parse it when validating CBs that go to the PCI DMA queue. In case the user needs to use it, it can put multiple WREG32 packets instead.Signed-off-by Oded Gabbay <[email protected]>
RE: [PATCH 2/2] habanalabs: set clock gating per engine
In reply to Oded GabbayQuoted 8 lines · Oded Gabbay
For debugging purposes, we need to allow the root user better control of the clock gating feature of the DMA and compute engines. Therefore, change the clock gating debugfs interface to be bitmask instead of true/false. Each bit represents a different engine, according to
gaudi_engine_idenum.See debugfs documentation for more details.
Signed-off-by Oded Gabbay <[email protected]>