2016-07-19 16:08:57 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2020-02-05 17:10:05 +00:00
|
|
|
#include "accel_engine_ioat.h"
|
2018-06-12 23:31:20 +00:00
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2016-07-19 16:08:57 +00:00
|
|
|
|
2020-02-05 17:10:05 +00:00
|
|
|
#include "spdk_internal/accel_engine.h"
|
2020-10-06 16:16:26 +00:00
|
|
|
#include "spdk/log.h"
|
2016-11-16 21:20:30 +00:00
|
|
|
|
2016-08-10 17:21:45 +00:00
|
|
|
#include "spdk/env.h"
|
2016-07-19 16:08:57 +00:00
|
|
|
#include "spdk/event.h"
|
2018-06-11 20:32:15 +00:00
|
|
|
#include "spdk/thread.h"
|
2016-07-19 16:08:57 +00:00
|
|
|
#include "spdk/ioat.h"
|
|
|
|
|
2018-06-05 23:33:20 +00:00
|
|
|
static bool g_ioat_enable = false;
|
2019-12-26 13:35:39 +00:00
|
|
|
static bool g_ioat_initialized = false;
|
2018-04-02 09:31:28 +00:00
|
|
|
|
2016-07-19 16:08:57 +00:00
|
|
|
struct ioat_device {
|
|
|
|
struct spdk_ioat_chan *ioat;
|
2016-09-20 22:42:08 +00:00
|
|
|
bool is_allocated;
|
2016-07-19 16:08:57 +00:00
|
|
|
/** linked list pointer for device list */
|
|
|
|
TAILQ_ENTRY(ioat_device) tailq;
|
|
|
|
};
|
|
|
|
|
2020-02-13 00:38:11 +00:00
|
|
|
struct pci_device {
|
|
|
|
struct spdk_pci_device *pci_dev;
|
|
|
|
TAILQ_ENTRY(pci_device) tailq;
|
|
|
|
};
|
|
|
|
|
2016-07-19 16:08:57 +00:00
|
|
|
static TAILQ_HEAD(, ioat_device) g_devices = TAILQ_HEAD_INITIALIZER(g_devices);
|
2016-09-20 22:42:08 +00:00
|
|
|
static pthread_mutex_t g_ioat_mutex = PTHREAD_MUTEX_INITIALIZER;
|
2016-07-19 16:08:57 +00:00
|
|
|
|
2020-02-13 00:38:11 +00:00
|
|
|
static TAILQ_HEAD(, pci_device) g_pci_devices = TAILQ_HEAD_INITIALIZER(g_pci_devices);
|
|
|
|
|
2016-09-20 20:13:38 +00:00
|
|
|
struct ioat_io_channel {
|
2020-07-01 18:50:01 +00:00
|
|
|
struct spdk_ioat_chan *ioat_ch;
|
|
|
|
struct ioat_device *ioat_dev;
|
|
|
|
struct spdk_poller *poller;
|
2016-09-20 20:13:38 +00:00
|
|
|
};
|
|
|
|
|
2016-09-20 22:42:08 +00:00
|
|
|
static struct ioat_device *
|
|
|
|
ioat_allocate_device(void)
|
|
|
|
{
|
|
|
|
struct ioat_device *dev;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&g_ioat_mutex);
|
|
|
|
TAILQ_FOREACH(dev, &g_devices, tailq) {
|
|
|
|
if (!dev->is_allocated) {
|
|
|
|
dev->is_allocated = true;
|
|
|
|
pthread_mutex_unlock(&g_ioat_mutex);
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&g_ioat_mutex);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ioat_free_device(struct ioat_device *dev)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&g_ioat_mutex);
|
|
|
|
dev->is_allocated = false;
|
|
|
|
pthread_mutex_unlock(&g_ioat_mutex);
|
|
|
|
}
|
2016-07-19 16:08:57 +00:00
|
|
|
|
2020-02-05 17:10:05 +00:00
|
|
|
static int accel_engine_ioat_init(void);
|
|
|
|
static void accel_engine_ioat_exit(void *ctx);
|
2016-07-19 16:08:57 +00:00
|
|
|
|
2016-11-16 21:23:57 +00:00
|
|
|
static size_t
|
2020-02-05 17:10:05 +00:00
|
|
|
accel_engine_ioat_get_ctx_size(void)
|
2016-07-19 16:08:57 +00:00
|
|
|
{
|
2020-07-28 17:51:20 +00:00
|
|
|
return 0;
|
2016-07-19 16:08:57 +00:00
|
|
|
}
|
|
|
|
|
2020-02-05 17:10:05 +00:00
|
|
|
SPDK_ACCEL_MODULE_REGISTER(accel_engine_ioat_init, accel_engine_ioat_exit,
|
2020-10-13 10:42:24 +00:00
|
|
|
NULL, accel_engine_ioat_get_ctx_size)
|
2016-07-19 16:08:57 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
ioat_done(void *cb_arg)
|
|
|
|
{
|
2020-07-28 17:51:20 +00:00
|
|
|
struct spdk_accel_task *accel_task = cb_arg;
|
2016-08-26 23:09:49 +00:00
|
|
|
|
2020-07-28 17:51:20 +00:00
|
|
|
spdk_accel_task_complete(accel_task, 0);
|
2016-08-26 23:09:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-13 00:16:47 +00:00
|
|
|
static int
|
2016-09-20 22:42:08 +00:00
|
|
|
ioat_poll(void *arg)
|
|
|
|
{
|
|
|
|
struct spdk_ioat_chan *chan = arg;
|
|
|
|
|
2020-05-04 09:51:27 +00:00
|
|
|
return spdk_ioat_process_events(chan) != 0 ? SPDK_POLLER_BUSY :
|
|
|
|
SPDK_POLLER_IDLE;
|
2016-09-20 22:42:08 +00:00
|
|
|
}
|
2016-08-26 23:09:49 +00:00
|
|
|
|
2017-05-18 17:48:04 +00:00
|
|
|
static struct spdk_io_channel *ioat_get_io_channel(void);
|
2016-09-20 20:13:38 +00:00
|
|
|
|
2020-04-24 16:47:55 +00:00
|
|
|
static uint64_t
|
|
|
|
ioat_get_capabilities(void)
|
|
|
|
{
|
2020-07-28 17:51:20 +00:00
|
|
|
return ACCEL_COPY | ACCEL_FILL;
|
2020-07-01 18:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-07-28 17:51:20 +00:00
|
|
|
ioat_submit_tasks(struct spdk_io_channel *ch, struct spdk_accel_task *accel_task)
|
2020-07-01 18:50:01 +00:00
|
|
|
{
|
2020-07-01 19:24:49 +00:00
|
|
|
struct ioat_io_channel *ioat_ch = spdk_io_channel_get_ctx(ch);
|
2020-07-28 17:51:20 +00:00
|
|
|
struct spdk_accel_task *tmp;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
switch (accel_task->op_code) {
|
|
|
|
case ACCEL_OPCODE_MEMFILL:
|
|
|
|
rc = spdk_ioat_build_fill(ioat_ch->ioat_ch, accel_task, ioat_done,
|
|
|
|
accel_task->dst, accel_task->fill_pattern, accel_task->nbytes);
|
2020-07-01 18:50:01 +00:00
|
|
|
break;
|
2020-07-28 17:51:20 +00:00
|
|
|
case ACCEL_OPCODE_MEMMOVE:
|
|
|
|
rc = spdk_ioat_build_copy(ioat_ch->ioat_ch, accel_task, ioat_done,
|
|
|
|
accel_task->dst, accel_task->src, accel_task->nbytes);
|
2020-07-01 18:50:01 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-28 17:51:20 +00:00
|
|
|
tmp = TAILQ_NEXT(accel_task, link);
|
|
|
|
|
|
|
|
/* Report any build errors via the callback now. */
|
|
|
|
if (rc) {
|
|
|
|
spdk_accel_task_complete(accel_task, rc);
|
|
|
|
}
|
2020-07-01 18:50:01 +00:00
|
|
|
|
2020-07-28 17:51:20 +00:00
|
|
|
accel_task = tmp;
|
|
|
|
} while (accel_task);
|
|
|
|
|
|
|
|
spdk_ioat_flush(ioat_ch->ioat_ch);
|
2020-07-01 18:50:01 +00:00
|
|
|
|
|
|
|
return 0;
|
2020-04-24 16:47:55 +00:00
|
|
|
}
|
|
|
|
|
2020-02-05 17:10:05 +00:00
|
|
|
static struct spdk_accel_engine ioat_accel_engine = {
|
2020-04-24 16:47:55 +00:00
|
|
|
.get_capabilities = ioat_get_capabilities,
|
|
|
|
.get_io_channel = ioat_get_io_channel,
|
2020-07-28 17:51:20 +00:00
|
|
|
.submit_tasks = ioat_submit_tasks,
|
2016-07-19 16:08:57 +00:00
|
|
|
};
|
|
|
|
|
2016-09-20 20:13:38 +00:00
|
|
|
static int
|
2017-05-18 17:48:04 +00:00
|
|
|
ioat_create_cb(void *io_device, void *ctx_buf)
|
2016-09-20 20:13:38 +00:00
|
|
|
{
|
|
|
|
struct ioat_io_channel *ch = ctx_buf;
|
|
|
|
struct ioat_device *ioat_dev;
|
|
|
|
|
|
|
|
ioat_dev = ioat_allocate_device();
|
|
|
|
if (ioat_dev == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ch->ioat_dev = ioat_dev;
|
|
|
|
ch->ioat_ch = ioat_dev->ioat;
|
2020-04-14 06:49:46 +00:00
|
|
|
ch->poller = SPDK_POLLER_REGISTER(ioat_poll, ch->ioat_ch, 0);
|
2020-07-28 17:51:20 +00:00
|
|
|
|
2016-09-20 20:13:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ioat_destroy_cb(void *io_device, void *ctx_buf)
|
|
|
|
{
|
|
|
|
struct ioat_io_channel *ch = ctx_buf;
|
|
|
|
|
|
|
|
ioat_free_device(ch->ioat_dev);
|
2017-11-15 22:09:40 +00:00
|
|
|
spdk_poller_unregister(&ch->poller);
|
2016-09-20 20:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct spdk_io_channel *
|
2017-05-18 17:48:04 +00:00
|
|
|
ioat_get_io_channel(void)
|
2016-09-20 20:13:38 +00:00
|
|
|
{
|
2020-02-05 17:10:05 +00:00
|
|
|
return spdk_get_io_channel(&ioat_accel_engine);
|
2016-09-20 20:13:38 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 16:08:57 +00:00
|
|
|
static bool
|
|
|
|
probe_cb(void *cb_ctx, struct spdk_pci_device *pci_dev)
|
|
|
|
{
|
2016-10-31 23:01:52 +00:00
|
|
|
struct spdk_pci_addr pci_addr = spdk_pci_device_get_addr(pci_dev);
|
2020-02-13 00:38:11 +00:00
|
|
|
struct pci_device *pdev;
|
2016-07-19 16:08:57 +00:00
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(accel_ioat,
|
2018-04-05 17:29:32 +00:00
|
|
|
" Found matching device at %04x:%02x:%02x.%x vendor:0x%04x device:0x%04x\n",
|
|
|
|
pci_addr.domain,
|
|
|
|
pci_addr.bus,
|
|
|
|
pci_addr.dev,
|
|
|
|
pci_addr.func,
|
|
|
|
spdk_pci_device_get_vendor_id(pci_dev),
|
|
|
|
spdk_pci_device_get_device_id(pci_dev));
|
2016-07-19 16:08:57 +00:00
|
|
|
|
2020-02-13 00:38:11 +00:00
|
|
|
pdev = calloc(1, sizeof(*pdev));
|
|
|
|
if (pdev == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
pdev->pci_dev = pci_dev;
|
|
|
|
TAILQ_INSERT_TAIL(&g_pci_devices, pdev, tailq);
|
|
|
|
|
2016-07-19 16:08:57 +00:00
|
|
|
/* Claim the device in case conflict with other process */
|
2019-09-02 09:35:33 +00:00
|
|
|
if (spdk_pci_device_claim(pci_dev) < 0) {
|
2016-07-19 16:08:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_ioat_chan *ioat)
|
|
|
|
{
|
|
|
|
struct ioat_device *dev;
|
|
|
|
|
2019-04-05 09:02:14 +00:00
|
|
|
dev = calloc(1, sizeof(*dev));
|
2016-07-19 16:08:57 +00:00
|
|
|
if (dev == NULL) {
|
|
|
|
SPDK_ERRLOG("Failed to allocate device struct\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->ioat = ioat;
|
|
|
|
TAILQ_INSERT_TAIL(&g_devices, dev, tailq);
|
|
|
|
}
|
|
|
|
|
2018-06-12 23:31:20 +00:00
|
|
|
void
|
2020-02-05 17:10:05 +00:00
|
|
|
accel_engine_ioat_enable_probe(void)
|
2018-06-12 23:31:20 +00:00
|
|
|
{
|
|
|
|
g_ioat_enable = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-02-05 17:10:05 +00:00
|
|
|
accel_engine_ioat_init(void)
|
2018-06-12 23:31:20 +00:00
|
|
|
{
|
2018-06-05 23:33:20 +00:00
|
|
|
if (!g_ioat_enable) {
|
2018-04-02 09:31:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-25 18:37:40 +00:00
|
|
|
if (spdk_ioat_probe(NULL, probe_cb, attach_cb) != 0) {
|
2016-07-19 16:08:57 +00:00
|
|
|
SPDK_ERRLOG("spdk_ioat_probe() failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-05-11 13:14:33 +00:00
|
|
|
if (TAILQ_EMPTY(&g_devices)) {
|
|
|
|
SPDK_NOTICELOG("No available ioat devices\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-12-26 13:35:39 +00:00
|
|
|
g_ioat_initialized = true;
|
2020-04-24 18:33:12 +00:00
|
|
|
SPDK_NOTICELOG("Accel engine updated to use IOAT engine.\n");
|
2020-02-05 21:31:16 +00:00
|
|
|
spdk_accel_hw_engine_register(&ioat_accel_engine);
|
2020-02-05 17:10:05 +00:00
|
|
|
spdk_io_device_register(&ioat_accel_engine, ioat_create_cb, ioat_destroy_cb,
|
|
|
|
sizeof(struct ioat_io_channel), "ioat_accel_engine");
|
2016-07-19 16:08:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-04-02 09:33:10 +00:00
|
|
|
|
2019-12-26 13:35:39 +00:00
|
|
|
static void
|
2020-02-05 17:10:05 +00:00
|
|
|
accel_engine_ioat_exit(void *ctx)
|
2019-12-26 13:35:39 +00:00
|
|
|
{
|
|
|
|
struct ioat_device *dev;
|
2020-02-13 00:38:11 +00:00
|
|
|
struct pci_device *pci_dev;
|
2019-12-26 13:35:39 +00:00
|
|
|
|
|
|
|
if (g_ioat_initialized) {
|
2020-02-05 17:10:05 +00:00
|
|
|
spdk_io_device_unregister(&ioat_accel_engine, NULL);
|
2019-12-26 13:35:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (!TAILQ_EMPTY(&g_devices)) {
|
|
|
|
dev = TAILQ_FIRST(&g_devices);
|
|
|
|
TAILQ_REMOVE(&g_devices, dev, tailq);
|
|
|
|
spdk_ioat_detach(dev->ioat);
|
|
|
|
ioat_free_device(dev);
|
|
|
|
free(dev);
|
|
|
|
}
|
2020-02-13 00:38:11 +00:00
|
|
|
|
|
|
|
while (!TAILQ_EMPTY(&g_pci_devices)) {
|
|
|
|
pci_dev = TAILQ_FIRST(&g_pci_devices);
|
|
|
|
TAILQ_REMOVE(&g_pci_devices, pci_dev, tailq);
|
|
|
|
spdk_pci_device_detach(pci_dev->pci_dev);
|
|
|
|
free(pci_dev);
|
|
|
|
}
|
|
|
|
|
2020-02-05 17:10:05 +00:00
|
|
|
spdk_accel_engine_module_finish();
|
2019-12-26 13:35:39 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_LOG_REGISTER_COMPONENT(accel_ioat)
|