Commit 1242e9f0 authored by Oded Gabbay's avatar Oded Gabbay

habanalabs: check running index in eqe control

To harden the event queue mechanism, we add a running index to the
control header of the entry.

The firmware writes the index in each entry and the driver verifies
that the index of the current entry is larger by 1 of the index of
the previous entry.

In case it isn't, the driver will treat the entry as if it wasn't
valid (it won't process it but won't skip it).
Signed-off-by: default avatarOded Gabbay <ogabbay@kernel.org>
parent 7fb2a1f5
...@@ -617,10 +617,17 @@ int hl_fw_cpucp_info_get(struct hl_device *hdev, ...@@ -617,10 +617,17 @@ int hl_fw_cpucp_info_get(struct hl_device *hdev,
goto out; goto out;
} }
/* assume EQ code doesn't need to check eqe index */
hdev->event_queue.check_eqe_index = false;
/* Read FW application security bits again */ /* Read FW application security bits again */
if (hdev->asic_prop.fw_cpu_boot_dev_sts0_valid) if (hdev->asic_prop.fw_cpu_boot_dev_sts0_valid) {
hdev->asic_prop.fw_app_cpu_boot_dev_sts0 = hdev->asic_prop.fw_app_cpu_boot_dev_sts0 =
RREG32(sts_boot_dev_sts0_reg); RREG32(sts_boot_dev_sts0_reg);
if (hdev->asic_prop.fw_app_cpu_boot_dev_sts0 &
CPU_BOOT_DEV_STS0_EQ_INDEX_EN)
hdev->event_queue.check_eqe_index = true;
}
if (hdev->asic_prop.fw_cpu_boot_dev_sts1_valid) if (hdev->asic_prop.fw_cpu_boot_dev_sts1_valid)
hdev->asic_prop.fw_app_cpu_boot_dev_sts1 = hdev->asic_prop.fw_app_cpu_boot_dev_sts1 =
......
...@@ -780,12 +780,19 @@ struct hl_user_pending_interrupt { ...@@ -780,12 +780,19 @@ struct hl_user_pending_interrupt {
* @kernel_address: holds the queue's kernel virtual address * @kernel_address: holds the queue's kernel virtual address
* @bus_address: holds the queue's DMA address * @bus_address: holds the queue's DMA address
* @ci: ci inside the queue * @ci: ci inside the queue
* @prev_eqe_index: the index of the previous event queue entry. The index of
* the current entry's index must be +1 of the previous one.
* @check_eqe_index: do we need to check the index of the current entry vs. the
* previous one. This is for backward compatibility with older
* firmwares
*/ */
struct hl_eq { struct hl_eq {
struct hl_device *hdev; struct hl_device *hdev;
void *kernel_address; void *kernel_address;
dma_addr_t bus_address; dma_addr_t bus_address;
u32 ci; u32 ci;
u32 prev_eqe_index;
bool check_eqe_index;
}; };
......
...@@ -207,17 +207,33 @@ irqreturn_t hl_irq_handler_eq(int irq, void *arg) ...@@ -207,17 +207,33 @@ irqreturn_t hl_irq_handler_eq(int irq, void *arg)
struct hl_eq_entry *eq_entry; struct hl_eq_entry *eq_entry;
struct hl_eq_entry *eq_base; struct hl_eq_entry *eq_base;
struct hl_eqe_work *handle_eqe_work; struct hl_eqe_work *handle_eqe_work;
bool entry_ready;
u32 cur_eqe;
u16 cur_eqe_index;
eq_base = eq->kernel_address; eq_base = eq->kernel_address;
while (1) { while (1) {
bool entry_ready = cur_eqe = le32_to_cpu(eq_base[eq->ci].hdr.ctl);
((le32_to_cpu(eq_base[eq->ci].hdr.ctl) & entry_ready = !!FIELD_GET(EQ_CTL_READY_MASK, cur_eqe);
EQ_CTL_READY_MASK) >> EQ_CTL_READY_SHIFT);
if (!entry_ready) if (!entry_ready)
break; break;
cur_eqe_index = FIELD_GET(EQ_CTL_INDEX_MASK, cur_eqe);
if ((hdev->event_queue.check_eqe_index) &&
(((eq->prev_eqe_index + 1) & EQ_CTL_INDEX_MASK)
!= cur_eqe_index)) {
dev_dbg(hdev->dev,
"EQE 0x%x in queue is ready but index does not match %d!=%d",
eq_base[eq->ci].hdr.ctl,
((eq->prev_eqe_index + 1) & EQ_CTL_INDEX_MASK),
cur_eqe_index);
break;
}
eq->prev_eqe_index++;
eq_entry = &eq_base[eq->ci]; eq_entry = &eq_base[eq->ci];
/* /*
...@@ -341,6 +357,7 @@ int hl_eq_init(struct hl_device *hdev, struct hl_eq *q) ...@@ -341,6 +357,7 @@ int hl_eq_init(struct hl_device *hdev, struct hl_eq *q)
q->hdev = hdev; q->hdev = hdev;
q->kernel_address = p; q->kernel_address = p;
q->ci = 0; q->ci = 0;
q->prev_eqe_index = 0;
return 0; return 0;
} }
...@@ -365,6 +382,7 @@ void hl_eq_fini(struct hl_device *hdev, struct hl_eq *q) ...@@ -365,6 +382,7 @@ void hl_eq_fini(struct hl_device *hdev, struct hl_eq *q)
void hl_eq_reset(struct hl_device *hdev, struct hl_eq *q) void hl_eq_reset(struct hl_device *hdev, struct hl_eq *q)
{ {
q->ci = 0; q->ci = 0;
q->prev_eqe_index = 0;
/* /*
* It's not enough to just reset the PI/CI because the H/W may have * It's not enough to just reset the PI/CI because the H/W may have
......
...@@ -103,6 +103,9 @@ struct hl_eq_entry { ...@@ -103,6 +103,9 @@ struct hl_eq_entry {
#define EQ_CTL_EVENT_TYPE_SHIFT 16 #define EQ_CTL_EVENT_TYPE_SHIFT 16
#define EQ_CTL_EVENT_TYPE_MASK 0x03FF0000 #define EQ_CTL_EVENT_TYPE_MASK 0x03FF0000
#define EQ_CTL_INDEX_SHIFT 0
#define EQ_CTL_INDEX_MASK 0x0000FFFF
enum pq_init_status { enum pq_init_status {
PQ_INIT_STATUS_NA = 0, PQ_INIT_STATUS_NA = 0,
PQ_INIT_STATUS_READY_FOR_CP, PQ_INIT_STATUS_READY_FOR_CP,
......
...@@ -195,7 +195,15 @@ ...@@ -195,7 +195,15 @@
* previleged entity. FW sets this status * previleged entity. FW sets this status
* bit for host. If this bit is set then * bit for host. If this bit is set then
* GIC can not be accessed from host. * GIC can not be accessed from host.
* Initialized in: armcpd * Initialized in: linux
*
* CPU_BOOT_DEV_STS0_EQ_INDEX_EN Event Queue (EQ) index is a running
* index for each new event sent to host.
* This is used as a method in host to
* identify that the waiting event in
* queue is actually a new event which
* was not served before.
* Initialized in: linux
* *
* CPU_BOOT_DEV_STS0_ENABLED Device status register enabled. * CPU_BOOT_DEV_STS0_ENABLED Device status register enabled.
* This is a main indication that the * This is a main indication that the
...@@ -226,6 +234,7 @@ ...@@ -226,6 +234,7 @@
#define CPU_BOOT_DEV_STS0_FW_IATU_CONF_EN (1 << 17) #define CPU_BOOT_DEV_STS0_FW_IATU_CONF_EN (1 << 17)
#define CPU_BOOT_DEV_STS0_DYN_PLL_EN (1 << 19) #define CPU_BOOT_DEV_STS0_DYN_PLL_EN (1 << 19)
#define CPU_BOOT_DEV_STS0_GIC_PRIVILEGED_EN (1 << 20) #define CPU_BOOT_DEV_STS0_GIC_PRIVILEGED_EN (1 << 20)
#define CPU_BOOT_DEV_STS0_EQ_INDEX_EN (1 << 21)
#define CPU_BOOT_DEV_STS0_ENABLED (1 << 31) #define CPU_BOOT_DEV_STS0_ENABLED (1 << 31)
#define CPU_BOOT_DEV_STS1_ENABLED (1 << 31) #define CPU_BOOT_DEV_STS1_ENABLED (1 << 31)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment