1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2023 Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #include "spdk/accel.h" 7 #include "spdk/accel_module.h" 8 #include "spdk/thread.h" 9 10 static struct spdk_accel_driver g_ex_driver; 11 12 static int 13 ex_accel_fill(struct iovec *iovs, uint32_t iovcnt, uint8_t fill) 14 { 15 void *dst; 16 size_t nbytes; 17 18 if (spdk_unlikely(iovcnt != 1)) { 19 fprintf(stderr, "Unexpected number of iovs: %" PRIu32 "\n", iovcnt); 20 return -EINVAL; 21 } 22 23 dst = iovs[0].iov_base; 24 nbytes = iovs[0].iov_len; 25 26 memset(dst, fill, nbytes); 27 28 return 0; 29 } 30 31 static int 32 ex_driver_create_cb(void *io_device, void *ctx_buf) 33 { 34 return 0; 35 } 36 37 static void 38 ex_driver_destroy_cb(void *io_device, void *ctx_buf) 39 { 40 } 41 42 static int 43 ex_driver_execute_sequence(struct spdk_io_channel *ch, struct spdk_accel_sequence *seq) 44 { 45 struct spdk_accel_task *task; 46 int rc; 47 48 while ((task = spdk_accel_sequence_first_task(seq)) != NULL) { 49 printf("Running on accel driver task with code: %" PRIu8 "\n", task->op_code); 50 if (task->op_code == SPDK_ACCEL_OPC_FILL) { 51 rc = ex_accel_fill(task->d.iovs, task->d.iovcnt, task->fill_pattern); 52 if (rc != 0) { 53 fprintf(stderr, "Error during filling buffer: %d\n", rc); 54 } 55 } else { 56 break; 57 } 58 59 spdk_accel_task_complete(task, rc); 60 if (rc != 0) { 61 break; 62 } 63 } 64 65 spdk_accel_sequence_continue(seq); 66 67 return 0; 68 } 69 70 static struct spdk_io_channel * 71 ex_driver_get_io_channel(void) 72 { 73 return spdk_get_io_channel(&g_ex_driver); 74 } 75 76 static int 77 ex_accel_driver_init(void) 78 { 79 spdk_io_device_register(&g_ex_driver, ex_driver_create_cb, ex_driver_destroy_cb, 80 0, "external_accel_driver"); 81 82 return 0; 83 } 84 85 static void 86 ex_accel_driver_fini(void) 87 { 88 spdk_io_device_unregister(&g_ex_driver, NULL); 89 } 90 91 static struct spdk_accel_driver g_ex_driver = { 92 .name = "external", 93 .execute_sequence = ex_driver_execute_sequence, 94 .get_io_channel = ex_driver_get_io_channel, 95 .init = ex_accel_driver_init, 96 .fini = ex_accel_driver_fini 97 }; 98 99 SPDK_ACCEL_DRIVER_REGISTER(external, &g_ex_driver); 100