Skip to content

Commit 860e73b

Browse files
committed
Merge tag 'misc-habanalabs-next-2020-07-24' of git://people.freedesktop.org/~gabbayo/linux into char-misc-next
Oded writes: This tag contains the following changes for kernel 5.9-rc1: - Remove rate limiters from GAUDI configuration (no longer needed). - Set maximum amount of in-flight CS per ASIC type and increase the maximum amount for GAUDI. - Refactor signal/wait command submissions code - Calculate trace frequency from PLLs to show accurate profiling data - Rephrase error messages to make them more clear to the common user - Add statistics of dropped CS (counter per possible reason for drop) - Get ECC information from firmware - Remove support for partial SoC reset in Gaudi - Halt device CPU only when reset is certain to happen. Sometimes we abort the reset procedure and in that case we can't leave device CPU in halt mode. - set each CQ to its own work queue to prevent a race between completions on different CQs. - Use queue pi/ci in order to determine queue occupancy. This is done to make the code reusable between current and future ASICs. - Add more validations for user inputs. - Refactor PCIe controller configuration to make the code reusable between current and future ASICs. - Update firmware interface headers to latest version - Move all common code to a dedicated common sub-folder * tag 'misc-habanalabs-next-2020-07-24' of git://people.freedesktop.org/~gabbayo/linux: (28 commits) habanalabs: Fix memory leak in error flow of context initialization habanalabs: use no flags on MMU cache invalidation habanalabs: enable device before hw_init() habanalabs: create internal CB pool habanalabs: update hl_boot_if.h from firmware habanalabs: create common folder habanalabs: check for DMA errors when clearing memory habanalabs: verify queue can contain all cs jobs habanalabs: Assign each CQ with its own work queue habanalabs: halt device CPU only upon certain reset habanalabs: remove unused hash habanalabs: use queue pi/ci in order to determine queue occupancy habanalabs: configure maximum queues per asic habanalabs: remove soft-reset support from GAUDI habanalabs: PCIe iATU refactoring habanalabs: Extract ECC information from FW habanalabs: Add dropped cs statistics info struct habanalabs: extract cpu boot status lookup habanalabs: rephrase error messages habanalabs: Increase queues depth ...
2 parents 54918b8 + 94f8be9 commit 860e73b

34 files changed

+1260
-992
lines changed

drivers/misc/habanalabs/Makefile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
# Makefile for HabanaLabs AI accelerators driver
44
#
55

6-
obj-m := habanalabs.o
6+
obj-$(CONFIG_HABANA_AI) := habanalabs.o
77

8-
habanalabs-y := habanalabs_drv.o device.o context.o asid.o habanalabs_ioctl.o \
9-
command_buffer.o hw_queue.o irq.o sysfs.o hwmon.o memory.o \
10-
command_submission.o mmu.o firmware_if.o pci.o
11-
12-
habanalabs-$(CONFIG_DEBUG_FS) += debugfs.o
8+
include $(src)/common/Makefile
9+
habanalabs-y += $(HL_COMMON_FILES)
1310

1411
include $(src)/goya/Makefile
1512
habanalabs-y += $(HL_GOYA_FILES)
1613

1714
include $(src)/gaudi/Makefile
1815
habanalabs-y += $(HL_GAUDI_FILES)
16+
17+
habanalabs-$(CONFIG_DEBUG_FS) += common/debugfs.o
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
subdir-ccflags-y += -I$(src)/common
3+
4+
HL_COMMON_FILES := common/habanalabs_drv.o common/device.o common/context.o \
5+
common/asid.o common/habanalabs_ioctl.o \
6+
common/command_buffer.o common/hw_queue.o common/irq.o \
7+
common/sysfs.o common/hwmon.o common/memory.o \
8+
common/command_submission.o common/mmu.o common/firmware_if.o \
9+
common/pci.o

drivers/misc/habanalabs/command_buffer.c renamed to drivers/misc/habanalabs/common/command_buffer.c

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@
1010

1111
#include <linux/mm.h>
1212
#include <linux/slab.h>
13+
#include <linux/genalloc.h>
1314

1415
static void cb_fini(struct hl_device *hdev, struct hl_cb *cb)
1516
{
16-
hdev->asic_funcs->asic_dma_free_coherent(hdev, cb->size,
17-
(void *) (uintptr_t) cb->kernel_address,
18-
cb->bus_address);
17+
if (cb->is_internal)
18+
gen_pool_free(hdev->internal_cb_pool,
19+
cb->kernel_address, cb->size);
20+
else
21+
hdev->asic_funcs->asic_dma_free_coherent(hdev, cb->size,
22+
(void *) (uintptr_t) cb->kernel_address,
23+
cb->bus_address);
24+
1925
kfree(cb);
2026
}
2127

@@ -44,9 +50,10 @@ static void cb_release(struct kref *ref)
4450
}
4551

4652
static struct hl_cb *hl_cb_alloc(struct hl_device *hdev, u32 cb_size,
47-
int ctx_id)
53+
int ctx_id, bool internal_cb)
4854
{
4955
struct hl_cb *cb;
56+
u32 cb_offset;
5057
void *p;
5158

5259
/*
@@ -65,13 +72,25 @@ static struct hl_cb *hl_cb_alloc(struct hl_device *hdev, u32 cb_size,
6572
if (!cb)
6673
return NULL;
6774

68-
if (ctx_id == HL_KERNEL_ASID_ID)
75+
if (internal_cb) {
76+
p = (void *) gen_pool_alloc(hdev->internal_cb_pool, cb_size);
77+
if (!p) {
78+
kfree(cb);
79+
return NULL;
80+
}
81+
82+
cb_offset = p - hdev->internal_cb_pool_virt_addr;
83+
cb->is_internal = true;
84+
cb->bus_address = hdev->internal_cb_va_base + cb_offset;
85+
} else if (ctx_id == HL_KERNEL_ASID_ID) {
6986
p = hdev->asic_funcs->asic_dma_alloc_coherent(hdev, cb_size,
7087
&cb->bus_address, GFP_ATOMIC);
71-
else
88+
} else {
7289
p = hdev->asic_funcs->asic_dma_alloc_coherent(hdev, cb_size,
7390
&cb->bus_address,
7491
GFP_USER | __GFP_ZERO);
92+
}
93+
7594
if (!p) {
7695
dev_err(hdev->dev,
7796
"failed to allocate %d of dma memory for CB\n",
@@ -87,7 +106,7 @@ static struct hl_cb *hl_cb_alloc(struct hl_device *hdev, u32 cb_size,
87106
}
88107

89108
int hl_cb_create(struct hl_device *hdev, struct hl_cb_mgr *mgr,
90-
u32 cb_size, u64 *handle, int ctx_id)
109+
u32 cb_size, u64 *handle, int ctx_id, bool internal_cb)
91110
{
92111
struct hl_cb *cb;
93112
bool alloc_new_cb = true;
@@ -112,28 +131,30 @@ int hl_cb_create(struct hl_device *hdev, struct hl_cb_mgr *mgr,
112131
goto out_err;
113132
}
114133

115-
/* Minimum allocation must be PAGE SIZE */
116-
if (cb_size < PAGE_SIZE)
117-
cb_size = PAGE_SIZE;
118-
119-
if (ctx_id == HL_KERNEL_ASID_ID &&
120-
cb_size <= hdev->asic_prop.cb_pool_cb_size) {
121-
122-
spin_lock(&hdev->cb_pool_lock);
123-
if (!list_empty(&hdev->cb_pool)) {
124-
cb = list_first_entry(&hdev->cb_pool, typeof(*cb),
125-
pool_list);
126-
list_del(&cb->pool_list);
127-
spin_unlock(&hdev->cb_pool_lock);
128-
alloc_new_cb = false;
129-
} else {
130-
spin_unlock(&hdev->cb_pool_lock);
131-
dev_dbg(hdev->dev, "CB pool is empty\n");
134+
if (!internal_cb) {
135+
/* Minimum allocation must be PAGE SIZE */
136+
if (cb_size < PAGE_SIZE)
137+
cb_size = PAGE_SIZE;
138+
139+
if (ctx_id == HL_KERNEL_ASID_ID &&
140+
cb_size <= hdev->asic_prop.cb_pool_cb_size) {
141+
142+
spin_lock(&hdev->cb_pool_lock);
143+
if (!list_empty(&hdev->cb_pool)) {
144+
cb = list_first_entry(&hdev->cb_pool,
145+
typeof(*cb), pool_list);
146+
list_del(&cb->pool_list);
147+
spin_unlock(&hdev->cb_pool_lock);
148+
alloc_new_cb = false;
149+
} else {
150+
spin_unlock(&hdev->cb_pool_lock);
151+
dev_dbg(hdev->dev, "CB pool is empty\n");
152+
}
132153
}
133154
}
134155

135156
if (alloc_new_cb) {
136-
cb = hl_cb_alloc(hdev, cb_size, ctx_id);
157+
cb = hl_cb_alloc(hdev, cb_size, ctx_id, internal_cb);
137158
if (!cb) {
138159
rc = -ENOMEM;
139160
goto out_err;
@@ -229,8 +250,8 @@ int hl_cb_ioctl(struct hl_fpriv *hpriv, void *data)
229250
rc = -EINVAL;
230251
} else {
231252
rc = hl_cb_create(hdev, &hpriv->cb_mgr,
232-
args->in.cb_size, &handle,
233-
hpriv->ctx->asid);
253+
args->in.cb_size, &handle,
254+
hpriv->ctx->asid, false);
234255
}
235256

236257
memset(args, 0, sizeof(*args));
@@ -398,14 +419,15 @@ void hl_cb_mgr_fini(struct hl_device *hdev, struct hl_cb_mgr *mgr)
398419
idr_destroy(&mgr->cb_handles);
399420
}
400421

401-
struct hl_cb *hl_cb_kernel_create(struct hl_device *hdev, u32 cb_size)
422+
struct hl_cb *hl_cb_kernel_create(struct hl_device *hdev, u32 cb_size,
423+
bool internal_cb)
402424
{
403425
u64 cb_handle;
404426
struct hl_cb *cb;
405427
int rc;
406428

407429
rc = hl_cb_create(hdev, &hdev->kernel_cb_mgr, cb_size, &cb_handle,
408-
HL_KERNEL_ASID_ID);
430+
HL_KERNEL_ASID_ID, internal_cb);
409431
if (rc) {
410432
dev_err(hdev->dev,
411433
"Failed to allocate CB for the kernel driver %d\n", rc);
@@ -437,7 +459,7 @@ int hl_cb_pool_init(struct hl_device *hdev)
437459

438460
for (i = 0 ; i < hdev->asic_prop.cb_pool_cb_cnt ; i++) {
439461
cb = hl_cb_alloc(hdev, hdev->asic_prop.cb_pool_cb_size,
440-
HL_KERNEL_ASID_ID);
462+
HL_KERNEL_ASID_ID, false);
441463
if (cb) {
442464
cb->is_pool = true;
443465
list_add(&cb->pool_list, &hdev->cb_pool);

0 commit comments

Comments
 (0)