History

habanalabs: use enum for CB allocation options

In the future there will be situations where queues can accept either kernel allocated CBs or user allocated CBs, depending on different states. Therefore, instead of using a boolean variable of kernel/user allocated CB, we need to use a bitmask to indicate that, which will allow to combine the two options. Add a flag to the uapi so the user will be able to indicate whether the CB was allocated by kernel or by user. Of course the driver validates that.

Tal Cohen committed 6 years ago

Commit 4bb1f2f1 parent 3c681575 files · +73 −12Browse files

Unified · Split

5 files
  1. drivers/misc/habanalabs/common/command_submission.c +29 −2
  2. drivers/misc/habanalabs/common/habanalabs.h +16 −3
  3. drivers/misc/habanalabs/gaudi/gaudi.c +9 −4
  4. drivers/misc/habanalabs/goya/goya.c +3 −3
  5. include/uapi/misc/habanalabs.h +16 −0
drivers/misc/habanalabs/common/command_submission.c+29−2
@@ -568,9 +568,36 @@ static int validate_queue_index(struct hl_device *hdev, · 567 unmodified lines
568568 return -EINVAL;
569569 }
570570
571− *queue_type = hw_queue_prop->type;
572− *is_kernel_allocated_cb = !!hw_queue_prop->requires_kernel_cb;
571+ /* When hw queue type isn't QUEUE_TYPE_HW,
572+ * USER_ALLOC_CB flag shall be referred as "don't care".
573+ */
574+ if (hw_queue_prop->type == QUEUE_TYPE_HW) {
575+ if (chunk->cs_chunk_flags & HL_CS_CHUNK_FLAGS_USER_ALLOC_CB) {
576+ if (!(hw_queue_prop->cb_alloc_flags & CB_ALLOC_USER)) {
577+ dev_err(hdev->dev,
578+ "Queue index %d doesn't support user CB\n",
579+ chunk->queue_index);
580+ return -EINVAL;
581+ }
573582
583+ *is_kernel_allocated_cb = false;
584+ } else {
585+ if (!(hw_queue_prop->cb_alloc_flags &
586+ CB_ALLOC_KERNEL)) {
587+ dev_err(hdev->dev,
588+ "Queue index %d doesn't support kernel CB\n",
589+ chunk->queue_index);
590+ return -EINVAL;
591+ }
592+
593+ *is_kernel_allocated_cb = true;
594+ }
595+ } else {
596+ *is_kernel_allocated_cb = !!(hw_queue_prop->cb_alloc_flags
597+ & CB_ALLOC_KERNEL);
598+ }
599+
600+ *queue_type = hw_queue_prop->type;
574601 return 0;
575602 }
576603
drivers/misc/habanalabs/common/habanalabs.h+16−3
@@ -206,6 +206,17 @@ struct hl_outbound_pci_region { · 205 unmodified lines
206206 u64 size;
207207 };
208208
209+/*
210+ * enum queue_cb_alloc_flags - Indicates queue support for CBs that
211+ * allocated by Kernel or by User
212+ * @CB_ALLOC_KERNEL: support only CBs that allocated by Kernel
213+ * @CB_ALLOC_USER: support only CBs that allocated by User
214+ */
215+enum queue_cb_alloc_flags {
216+ CB_ALLOC_KERNEL = 0x1,
217+ CB_ALLOC_USER = 0x2
218+};
219+
209220 /*
210221 * struct hl_hw_sob - H/W SOB info.
211222 * @hdev: habanalabs device structure.
@@ -223,16 +234,18 @@ struct hl_hw_sob { · 11 unmodified lines
223234 /**
224235 * struct hw_queue_properties - queue information.
225236 * @type: queue type.
237+ * @queue_cb_alloc_flags: bitmap which indicates if the hw queue supports CB
238+ * that allocated by the Kernel driver and therefore,
239+ * a CB handle can be provided for jobs on this queue.
240+ * Otherwise, a CB address must be provided.
226241 * @driver_only: true if only the driver is allowed to send a job to this queue,
227242 * false otherwise.
228− * @requires_kernel_cb: true if a CB handle must be provided for jobs on this
229− * queue, false otherwise (a CB address must be provided).
230243 * @supports_sync_stream: True if queue supports sync stream
231244 */
232245 struct hw_queue_properties {
233246 enum hl_queue_type type;
247+ enum queue_cb_alloc_flags cb_alloc_flags;
234248 u8 driver_only;
235− u8 requires_kernel_cb;
236249 u8 supports_sync_stream;
237250 };
238251
drivers/misc/habanalabs/gaudi/gaudi.c+9−4
@@ -381,23 +381,28 @@ static int gaudi_get_fixed_properties(struct hl_device *hdev) · 380 unmodified lines
381381 if (gaudi_queue_type[i] == QUEUE_TYPE_EXT) {
382382 prop->hw_queues_props[i].type = QUEUE_TYPE_EXT;
383383 prop->hw_queues_props[i].driver_only = 0;
384− prop->hw_queues_props[i].requires_kernel_cb = 1;
385384 prop->hw_queues_props[i].supports_sync_stream = 1;
385+ prop->hw_queues_props[i].cb_alloc_flags =
386+ CB_ALLOC_KERNEL;
386387 num_sync_stream_queues++;
387388 } else if (gaudi_queue_type[i] == QUEUE_TYPE_CPU) {
388389 prop->hw_queues_props[i].type = QUEUE_TYPE_CPU;
389390 prop->hw_queues_props[i].driver_only = 1;
390− prop->hw_queues_props[i].requires_kernel_cb = 0;
391391 prop->hw_queues_props[i].supports_sync_stream = 0;
392+ prop->hw_queues_props[i].cb_alloc_flags =
393+ CB_ALLOC_KERNEL;
392394 } else if (gaudi_queue_type[i] == QUEUE_TYPE_INT) {
393395 prop->hw_queues_props[i].type = QUEUE_TYPE_INT;
394396 prop->hw_queues_props[i].driver_only = 0;
395− prop->hw_queues_props[i].requires_kernel_cb = 0;
397+ prop->hw_queues_props[i].supports_sync_stream = 0;
398+ prop->hw_queues_props[i].cb_alloc_flags =
399+ CB_ALLOC_USER;
396400 } else if (gaudi_queue_type[i] == QUEUE_TYPE_NA) {
397401 prop->hw_queues_props[i].type = QUEUE_TYPE_NA;
398402 prop->hw_queues_props[i].driver_only = 0;
399− prop->hw_queues_props[i].requires_kernel_cb = 0;
400403 prop->hw_queues_props[i].supports_sync_stream = 0;
404+ prop->hw_queues_props[i].cb_alloc_flags =
405+ CB_ALLOC_USER;
401406 }
402407 }
403408
drivers/misc/habanalabs/goya/goya.c+3−3
@@ -373,20 +373,20 @@ int goya_get_fixed_properties(struct hl_device *hdev) · 372 unmodified lines
373373 for (i = 0 ; i < NUMBER_OF_EXT_HW_QUEUES ; i++) {
374374 prop->hw_queues_props[i].type = QUEUE_TYPE_EXT;
375375 prop->hw_queues_props[i].driver_only = 0;
376− prop->hw_queues_props[i].requires_kernel_cb = 1;
376+ prop->hw_queues_props[i].cb_alloc_flags = CB_ALLOC_KERNEL;
377377 }
378378
379379 for (; i < NUMBER_OF_EXT_HW_QUEUES + NUMBER_OF_CPU_HW_QUEUES ; i++) {
380380 prop->hw_queues_props[i].type = QUEUE_TYPE_CPU;
381381 prop->hw_queues_props[i].driver_only = 1;
382− prop->hw_queues_props[i].requires_kernel_cb = 0;
382+ prop->hw_queues_props[i].cb_alloc_flags = CB_ALLOC_KERNEL;
383383 }
384384
385385 for (; i < NUMBER_OF_EXT_HW_QUEUES + NUMBER_OF_CPU_HW_QUEUES +
386386 NUMBER_OF_INT_HW_QUEUES; i++) {
387387 prop->hw_queues_props[i].type = QUEUE_TYPE_INT;
388388 prop->hw_queues_props[i].driver_only = 0;
389− prop->hw_queues_props[i].requires_kernel_cb = 0;
389+ prop->hw_queues_props[i].cb_alloc_flags = CB_ALLOC_USER;
390390 }
391391
392392 prop->completion_queues_count = NUMBER_OF_CMPLT_QUEUES;
include/uapi/misc/habanalabs.h+16−0
@@ -490,6 +490,22 @@ union hl_cb_args { · 489 unmodified lines
490490 struct hl_cb_out out;
491491 };
492492
493+/* HL_CS_CHUNK_FLAGS_ values
494+ *
495+ * HL_CS_CHUNK_FLAGS_USER_ALLOC_CB:
496+ * Indicates if the CB was allocated and mapped by userspace.
497+ * User allocated CB is a command buffer allocated by the user, via malloc
498+ * (or similar). After allocating the CB, the user invokes “memory ioctl”
499+ * to map the user memory into a device virtual address. The user provides
500+ * this address via the cb_handle field. The interface provides the
501+ * ability to create a large CBs, Which aren’t limited to
502+ * “HL_MAX_CB_SIZE”. Therefore, it increases the PCI-DMA queues
503+ * throughput. This CB allocation method also reduces the use of Linux
504+ * DMA-able memory pool. Which are limited and used by other Linux
505+ * sub-systems.
506+ */
507+#define HL_CS_CHUNK_FLAGS_USER_ALLOC_CB 0x1
508+
493509 /*
494510 * This structure size must always be fixed to 64-bytes for backward
495511 * compatibility

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t