habanalabs: change CB's ID to be 64 bits
PATCH 6/9 habanalabs: remove redundant assignment to variable
In reply to Oded Gabbaynew_dma_pkt->ctl is assigned a value and then is reassigned a new value without the first value ever being used.
--- drivers/misc/habanalabs/gaudi/gaudi.c | 2 -- 1 file changed, 2 deletions(-)
drivers/misc/habanalabs/gaudi/gaudi.c +0 -2
@@ -3944,8 +3944,6 @@ static int gaudi_patch_dma_packet(struct hl_device *hdev, } } - new_dma_pkt->ctl = user_dma_pkt->ctl; - ctl =le32_to_cpu (user_dma_pkt->ctl);if (likely (dma_desc_cnt)) ctl &= ~GAUDI_PKT_CTL_EB_MASK ;
Signature · 1 line
2.17.1
PATCH 5/9 habanalabs: use FIELD_PREP() instead of <<
In reply to Oded GabbayUse the standard FIELD_PREP() macro instead of << operator to perform bitmask operations. This ensures type check safety and eliminate compiler warnings.
--- drivers/misc/habanalabs/common/hw_queue.c | 9 +- drivers/misc/habanalabs/gaudi/gaudi.c | 50 ++-- .../habanalabs/include/gaudi/gaudi_masks.h | 274 ++++++++---------- 3 files changed, 154 insertions(+), 179 deletions(-)
drivers/misc/habanalabs/common/hw_queue.c +5 -4
@@ -8,6 +8,7 @@#include "habanalabs.h" #include <linux/slab.h> +#include <linux/bitfield.h> /* * hl_queue_add_ptr - add to pi or ci and checks if it wraps around
@@ -288,10 +289,10 @@ static void ext_queue_schedule_job(struct hl_cs_job *job) ptr = cb->bus_address; cq_pkt.data =cpu_to_le32 ( - ((q->pi <<CQ_ENTRY_SHADOW_INDEX_SHIFT ) - &CQ_ENTRY_SHADOW_INDEX_MASK ) | - (1 <<CQ_ENTRY_SHADOW_INDEX_VALID_SHIFT ) | - (1 <<CQ_ENTRY_READY_SHIFT )); + ((q->pi <<CQ_ENTRY_SHADOW_INDEX_SHIFT ) + &CQ_ENTRY_SHADOW_INDEX_MASK ) | +FIELD_PREP (CQ_ENTRY_SHADOW_INDEX_VALID_MASK ,1 ) | +FIELD_PREP (CQ_ENTRY_READY_MASK ,1 ));/* * No need to protect pi_offset because scheduling to the
drivers/misc/habanalabs/gaudi/gaudi.c +27 -23
105 lines not on this page · raw message
drivers/misc/habanalabs/include/gaudi/gaudi_masks.h +122 -152
316 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 4/9 habanalabs: use standard BIT() and GENMASK()
In reply to Oded GabbayUse the standard macros to define bitmasks.
--- drivers/misc/habanalabs/gaudi/gaudiP.h | 44 +++++++++++++------------- 1 file changed, 22 insertions(+), 22 deletions(-)
drivers/misc/habanalabs/gaudi/gaudiP.h +22 -22
@@ -141,28 +141,28 @@#define VA_HOST_SPACE_SIZE (VA_HOST_SPACE_END - \ VA_HOST_SPACE_START)/* 767TB */ -#define HW_CAP_PLL 0x00000001 -#define HW_CAP_HBM 0x00000002 -#define HW_CAP_MMU 0x00000004 -#define HW_CAP_MME 0x00000008 -#define HW_CAP_CPU 0x00000010 -#define HW_CAP_PCI_DMA 0x00000020 -#define HW_CAP_MSI 0x00000040 -#define HW_CAP_CPU_Q 0x00000080 -#define HW_CAP_HBM_DMA 0x00000100 -#define HW_CAP_CLK_GATE 0x00000200 -#define HW_CAP_SRAM_SCRAMBLER 0x00000400 -#define HW_CAP_HBM_SCRAMBLER 0x00000800 - -#define HW_CAP_TPC0 0x01000000 -#define HW_CAP_TPC1 0x02000000 -#define HW_CAP_TPC2 0x04000000 -#define HW_CAP_TPC3 0x08000000 -#define HW_CAP_TPC4 0x10000000 -#define HW_CAP_TPC5 0x20000000 -#define HW_CAP_TPC6 0x40000000 -#define HW_CAP_TPC7 0x80000000 -#define HW_CAP_TPC_MASK 0xFF000000 +#define HW_CAP_PLL BIT(0) +#define HW_CAP_HBM BIT(1) +#define HW_CAP_MMU BIT(2) +#define HW_CAP_MME BIT(3) +#define HW_CAP_CPU BIT(4) +#define HW_CAP_PCI_DMA BIT(5) +#define HW_CAP_MSI BIT(6) +#define HW_CAP_CPU_Q BIT(7) +#define HW_CAP_HBM_DMA BIT(8) +#define HW_CAP_CLK_GATE BIT(9) +#define HW_CAP_SRAM_SCRAMBLER BIT(10) +#define HW_CAP_HBM_SCRAMBLER BIT(11) + +#define HW_CAP_TPC0 BIT(24) +#define HW_CAP_TPC1 BIT(25) +#define HW_CAP_TPC2 BIT(26) +#define HW_CAP_TPC3 BIT(27) +#define HW_CAP_TPC4 BIT(28) +#define HW_CAP_TPC5 BIT(29) +#define HW_CAP_TPC6 BIT(30) +#define HW_CAP_TPC7 BIT(31) +#define HW_CAP_TPC_MASK GENMASK(31, 24)#define HW_CAP_TPC_SHIFT 24#define GAUDI_CPU_PCI_MSB_ADDR (addr) (((addr) & GENMASK_ULL(49, 39)) >> 39)
Signature · 1 line
2.17.1
PATCH 2/9 habanalabs: cast int to u32 before printing it with %u
In reply to Oded Gabbay%u is used for unsigned so we need to cast the int variable to u32 to avoid compiler warning.
--- drivers/misc/habanalabs/common/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/habanalabs/common/device.c +1 -1
@@ -286,7 +286,7 @@ static int device_early_init(struct hl_device *hdev) }for (i =0 ; i < hdev->asic_prop.completion_queues_count ; i++) { -snprintf (workq_name,32 ,"hl-free-jobs-%u" , i); +snprintf (workq_name,32 ,"hl-free-jobs-%u" , (u32 ) i); hdev->cq_wq[i] =create_singlethread_workqueue (workq_name);if (hdev->cq_wq[i] ==NULL ) {dev_err (hdev->dev,"Failed to allocate CQ workqueue\n" );
Signature · 1 line
2.17.1
PATCH 3/9 habanalabs: eliminate redundant else condition
In reply to Oded GabbayIf both parts of if-else are goto statements, we can remove the else and put the else goto statement after the if statement.
--- drivers/misc/habanalabs/common/command_submission.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/habanalabs/common/command_submission.c +2 -2
@@ -686,8 +686,8 @@ static int cs_ioctl_default(struct hl_fpriv *hpriv, void __user *chunks, rc = -ENOMEM ;if (is_kernel_allocated_cb) goto release_cb; -else - goto free_cs_object; + + goto free_cs_object; } job->id = i +1 ;
Signature · 1 line
2.17.1
PATCH 1/9 habanalabs: change CB's ID to be 64 bits
Although the possible values for CB's ID are only 32 bits, there are a few places in the code where this field is shifted and passed into a function which expects 64 bits.
--- drivers/misc/habanalabs/common/command_buffer.c | 2 +- drivers/misc/habanalabs/common/debugfs.c | 2 +- drivers/misc/habanalabs/common/habanalabs.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/misc/habanalabs/common/command_buffer.c +1 -1
@@ -173,7 +173,7 @@ int hl_cb_create(struct hl_device *hdev, struct hl_cb_mgr *mgr, goto release_cb; } - cb->id = rc; + cb->id = (u64 ) rc;kref_init (&cb->refcount);spin_lock_init (&cb->lock);
drivers/misc/habanalabs/common/debugfs.c +1 -1
@@ -110,7 +110,7 @@ static int command_buffers_show(struct seq_file *s, void *data)seq_puts (s,"---------------------------------------------------------------\n" ); }seq_printf (s, -" %03d %d 0x%08x %d %d %d\n" , +" %03llu %d 0x%08x %d %d %d\n" , cb->id, cb->ctx_id, cb->size,kref_read (&cb->refcount), cb->mmap, cb->cs_cnt);
drivers/misc/habanalabs/common/habanalabs.h +2 -2
@@ -401,11 +401,11 @@ struct hl_cb_mgr {* @lock: spinlock to protect mmap/cs flows. * @debugfs_list: node in debugfs list of command buffers. * @pool_list: node in pool list of command buffers. +* @id: the CB's ID. * @kernel_address: Holds the CB's kernel virtual address. * @bus_address: Holds the CB's DMA address. * @mmap_size: Holds the CB's size that was mmaped. * @size: holds the CB's size. -* @id: the CB's ID. * @cs_cnt: holds number of CS that this CB participates in. * @ctx_id: holds the ID of the owner's context. * @mmap: true if the CB is currently mmaped to user.
@@ -418,11 +418,11 @@ struct hl_cb {spinlock_t lock;struct list_head debugfs_list;struct list_head pool_list; +u64 id;u64 kernel_address;dma_addr_t bus_address;u32 mmap_size;u32 size; -u32 id;u32 cs_cnt;u32 ctx_id;u8 mmap;
Signature · 1 line
2.17.1
PATCH 9/9 habanalabs: extend busy engines mask to 64 bits
From: farah kassabri <[email protected]>
change busy engines bitmask to 64 bits in order to represent more engines, needed for future ASIC support.
--- drivers/misc/habanalabs/common/habanalabs.h | 2 +- drivers/misc/habanalabs/common/habanalabs_ioctl.c | 2 +- drivers/misc/habanalabs/gaudi/gaudi.c | 2 +- drivers/misc/habanalabs/goya/goya.c | 2 +- include/uapi/misc/habanalabs.h | 6 ++++++ 5 files changed, 10 insertions(+), 4 deletions(-)
drivers/misc/habanalabs/common/habanalabs.h +1 -1
@@ -754,7 +754,7 @@ struct hl_asic_funcs {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, +bool (*is_device_idle)(struct hl_device *hdev,u64 *mask,struct seq_file *s);int (*soft_reset_late_init)(struct hl_device *hdev);void (*hw_queues_lock)(struct hl_device *hdev);
drivers/misc/habanalabs/common/habanalabs_ioctl.c +1 -1
@@ -132,7 +132,7 @@ static int hw_idle(struct hl_device *hdev, struct hl_info_args *args)return -EINVAL ; hw_idle.is_idle = hdev->asic_funcs->is_device_idle (hdev, - &hw_idle.busy_engines_mask,NULL ); + &hw_idle.busy_engines_mask_ext,NULL );return copy_to_user (out, &hw_idle,min ((size_t ) max_size,sizeof (hw_idle))) ? -EFAULT :0 ;
drivers/misc/habanalabs/gaudi/gaudi.c +1 -1
@@ -6041,7 +6041,7 @@ static int gaudi_armcp_info_get(struct hl_device *hdev)return 0 ; } -static bool gaudi_is_device_idle (struct hl_device *hdev,u32 *mask, +static bool gaudi_is_device_idle (struct hl_device *hdev,u64 *mask,struct seq_file *s) {struct gaudi_device *gaudi = hdev->asic_specific;
drivers/misc/habanalabs/goya/goya.c +1 -1
@@ -5117,7 +5117,7 @@ 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, +static bool goya_is_device_idle (struct hl_device *hdev,u64 *mask,struct seq_file *s) {const char *fmt ="%-5d%-9s%#-14x%#-16x%#x\n" ;
include/uapi/misc/habanalabs.h +6 -0
@@ -319,6 +319,12 @@ struct hl_info_hw_idle {* Bits definition is according to `enum <chip>_enging_id'. */ __u32 busy_engines_mask; + +/* +* Extended Bitmask of busy engines. +* Bits definition is according to `enum <chip>_enging_id'. +*/ +__u64 busy_engines_mask_ext; };struct hl_info_device_status {
Signature · 1 line
2.17.1
PATCH 7/9 habanalabs: check TPC vector pipe is empty
In reply to Oded GabbayThe driver waits for the TPC vector pipe to be empty before checking if the TPC kernel has finished executing, but the code doesn't validate that the pipe was indeed empty, it just wait for it without checking the return value.
--- drivers/misc/habanalabs/gaudi/gaudi.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/misc/habanalabs/gaudi/gaudi.c +9 -0
@@ -6262,6 +6262,15 @@ static int gaudi_run_tpc_kernel(struct hl_device *hdev, u64 tpc_kernel,1000 , kernel_timeout); +if (rc) { +dev_err (hdev->dev, +"Timeout while waiting for TPC%d vector pipe\n" , + tpc_id); + hdev->asic_funcs->set_clock_gating (hdev); +mutex_unlock (&gaudi->clk_gate_mutex); +return -EIO ; + } + rc = hl_poll_timeout( hdev, mmTPC0_CFG_WQ_INFLIGHT_CNTR + offset,
Signature · 1 line
2.17.1
Quoted 6 lines · On Sat, Aug 15, 2020 at 21:00 Oded Gabbay <[email protected]> wrote:
Although the possible values for CB's ID are only 32 bits, there are a few places in the code where this field is shifted and passed into a function which expects 64 bits.
Reported-by kernel test robot <[email protected]>Signed-off-by Oded Gabbay <[email protected]>
RE: [PATCH 2/9] habanalabs: cast int to u32 before printing it with %u
In reply to Oded GabbayQuoted 5 lines · On Sat, Aug 15, 2020 at 21:00 Oded Gabbay <[email protected]> wrote:
%u is used for unsigned so we need to cast the int variable to u32 to avoid compiler warning.
Reported-by kernel test robot <[email protected]>Signed-off-by Oded Gabbay <[email protected]>
RE: [PATCH 3/9] habanalabs: eliminate redundant else condition
In reply to Oded GabbayQuoted 5 lines · On Sat, Aug 15, 2020 at 21:00 Oded Gabbay <[email protected]> wrote:
If both parts of if-else are goto statements, we can remove the else and put the else goto statement after the if statement.
Reported-by kernel test robot <[email protected]>Signed-off-by Oded Gabbay <[email protected]>
RE: [PATCH 4/9] habanalabs: use standard BIT() and GENMASK()
In reply to Oded GabbayQuoted 4 lines · On Sat, Aug 15, 2020 at 21:00 Oded Gabbay <[email protected]> wrote:
Use the standard macros to define bitmasks.
Reported-by kernel test robot <[email protected]>Signed-off-by Oded Gabbay <[email protected]>
RE: [PATCH 6/9] habanalabs: remove redundant assignment to variable
In reply to Oded GabbayQuoted 5 lines · On Sat, Aug 15, 2020 at 21:00 Oded Gabbay <[email protected]> wrote:
new_dma_pkt->ctlis assigned a value and then is reassigned a new value without the first value ever being used.Reported-by kernel test robot <[email protected]>Signed-off-by Oded Gabbay <[email protected]>
RE: [PATCH 5/9] habanalabs: use FIELD_PREP() instead of <<
In reply to Oded GabbayQuoted 6 lines · On Sat, Aug 15, 2020 at 21:00 Oded Gabbay <[email protected]> wrote:
Use the standard
FIELD_PREP()macro instead of << operator to perform bitmask operations. This ensures type check safety and eliminate compiler warnings.Reported-by kernel test robot <[email protected]>Signed-off-by Oded Gabbay <[email protected]>
RE: [PATCH 7/9] habanalabs: check TPC vector pipe is empty
In reply to Oded GabbayQuoted 7 lines · On Sat, Aug 15, 2020 at 21:00 Oded Gabbay <[email protected]> wrote:
The driver waits for the TPC vector pipe to be empty before checking if the TPC kernel has finished executing, but the code doesn't validate that the pipe was indeed empty, it just wait for it without checking the return value.
Reported-by kernel test robot <[email protected]>Signed-off-by Oded Gabbay <[email protected]>
Tomer Tayar
Reviewed-byRE: [PATCH 8/9] habanalabs: use 1U when shifting bits
In reply to a message not in the archiveQuoted 5 lines · On Sat, Aug 15, 2020 at 21:00 Oded Gabbay <[email protected]> wrote:
Eliminate following warning:
warning: Shifting signed 32-bit value by 31 bits is undefined behaviorReported-by kernel test robot <[email protected]>Signed-off-by Oded Gabbay <[email protected]>