2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2020-04-10 15:29:01 +00:00
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __IDXD_H__
|
|
|
|
#define __IDXD_H__
|
|
|
|
|
|
|
|
#include "spdk/stdinc.h"
|
|
|
|
|
|
|
|
#include "spdk/idxd.h"
|
|
|
|
#include "spdk/queue.h"
|
|
|
|
#include "spdk/mmio.h"
|
2021-09-08 16:04:07 +00:00
|
|
|
#include "spdk/idxd_spec.h"
|
2020-04-10 15:29:01 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* TODO: get the gcc intrinsic to work. */
|
|
|
|
#define nop() asm volatile ("nop")
|
|
|
|
static inline void movdir64b(void *dst, const void *src)
|
|
|
|
{
|
|
|
|
asm volatile(".byte 0x66, 0x0f, 0x38, 0xf8, 0x02"
|
|
|
|
: "=m"(*(char *)dst)
|
|
|
|
: "d"(src), "a"(dst));
|
|
|
|
}
|
|
|
|
|
|
|
|
#define IDXD_REGISTER_TIMEOUT_US 50
|
2020-05-07 18:45:15 +00:00
|
|
|
#define IDXD_DRAIN_TIMEOUT_US 500000
|
2020-04-10 15:29:01 +00:00
|
|
|
|
|
|
|
#define WQ_MODE_DEDICATED 1
|
2020-08-03 15:54:55 +00:00
|
|
|
|
|
|
|
/* TODO: consider setting the max per batch limit via RPC. */
|
|
|
|
|
2022-01-11 20:13:42 +00:00
|
|
|
/* The following sets up a max desc count per batch of 32 */
|
|
|
|
#define LOG2_WQ_MAX_BATCH 5 /* 2^5 = 32 */
|
2020-08-03 15:54:55 +00:00
|
|
|
#define DESC_PER_BATCH (1 << LOG2_WQ_MAX_BATCH)
|
|
|
|
|
2020-04-10 15:29:01 +00:00
|
|
|
#define LOG2_WQ_MAX_XFER 30 /* 2^30 = 1073741824 */
|
|
|
|
#define WQ_PRIORITY_1 1
|
|
|
|
#define IDXD_MAX_QUEUES 64
|
|
|
|
|
2022-05-20 16:40:25 +00:00
|
|
|
enum idxd_dev {
|
|
|
|
IDXD_DEV_TYPE_DSA = 0,
|
|
|
|
IDXD_DEV_TYPE_IAA = 1,
|
|
|
|
};
|
|
|
|
|
2020-08-03 15:54:55 +00:00
|
|
|
/* Each pre-allocated batch structure goes on a per channel list and
|
2020-10-21 18:04:02 +00:00
|
|
|
* contains the memory for both user descriptors.
|
2020-08-03 15:54:55 +00:00
|
|
|
*/
|
2020-05-07 18:45:15 +00:00
|
|
|
struct idxd_batch {
|
2020-08-03 15:54:55 +00:00
|
|
|
struct idxd_hw_desc *user_desc;
|
2021-07-23 20:44:47 +00:00
|
|
|
struct idxd_ops *user_ops;
|
2021-11-18 19:30:29 +00:00
|
|
|
uint64_t user_desc_addr;
|
2020-08-03 15:54:55 +00:00
|
|
|
uint8_t index;
|
2022-04-13 16:24:12 +00:00
|
|
|
uint8_t refcnt;
|
2021-08-11 05:05:08 +00:00
|
|
|
struct spdk_idxd_io_channel *chan;
|
2020-05-07 18:45:15 +00:00
|
|
|
TAILQ_ENTRY(idxd_batch) link;
|
|
|
|
};
|
2020-04-10 15:29:01 +00:00
|
|
|
|
|
|
|
struct device_config {
|
|
|
|
uint8_t config_num;
|
|
|
|
uint8_t num_groups;
|
|
|
|
uint16_t total_wqs;
|
|
|
|
uint16_t total_engines;
|
|
|
|
};
|
|
|
|
|
2021-07-23 20:44:47 +00:00
|
|
|
struct idxd_ops;
|
2020-04-10 15:29:01 +00:00
|
|
|
|
2020-08-03 15:54:55 +00:00
|
|
|
struct spdk_idxd_io_channel {
|
2021-06-17 00:31:00 +00:00
|
|
|
struct spdk_idxd_device *idxd;
|
2020-08-03 15:54:55 +00:00
|
|
|
/* The portal is the address that we write descriptors to for submission. */
|
2021-06-17 00:31:00 +00:00
|
|
|
void *portal;
|
|
|
|
uint32_t portal_offset;
|
2020-04-10 15:29:01 +00:00
|
|
|
|
2022-01-07 21:00:16 +00:00
|
|
|
/* The currently open batch */
|
|
|
|
struct idxd_batch *batch;
|
|
|
|
|
2020-04-10 15:29:01 +00:00
|
|
|
/*
|
2021-07-23 20:44:47 +00:00
|
|
|
* User descriptors (those included in a batch) are managed independently from
|
|
|
|
* data descriptors and are located in the batch structure.
|
2020-04-10 15:29:01 +00:00
|
|
|
*/
|
2021-07-23 20:44:47 +00:00
|
|
|
void *desc_base;
|
2022-04-12 21:12:12 +00:00
|
|
|
STAILQ_HEAD(, idxd_ops) ops_pool;
|
2021-11-25 01:40:58 +00:00
|
|
|
/* Current list of outstanding operations to poll. */
|
2022-04-12 21:12:12 +00:00
|
|
|
STAILQ_HEAD(op_head, idxd_ops) ops_outstanding;
|
2021-07-23 20:44:47 +00:00
|
|
|
void *ops_base;
|
2020-05-07 18:45:15 +00:00
|
|
|
|
2021-06-17 00:31:00 +00:00
|
|
|
TAILQ_HEAD(, idxd_batch) batch_pool;
|
|
|
|
void *batch_base;
|
2020-04-10 15:29:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pci_dev_id {
|
|
|
|
int vendor_id;
|
|
|
|
int device_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This struct wraps the hardware completion record which is 32 bytes in
|
|
|
|
* size and must be 32 byte aligned.
|
|
|
|
*/
|
2021-07-23 20:44:47 +00:00
|
|
|
struct idxd_ops {
|
2022-05-20 16:40:25 +00:00
|
|
|
union {
|
|
|
|
struct dsa_hw_comp_record hw;
|
|
|
|
struct iaa_hw_comp_record iaa_hw;
|
|
|
|
};
|
2020-05-06 14:21:00 +00:00
|
|
|
void *cb_arg;
|
2020-04-10 15:29:01 +00:00
|
|
|
spdk_idxd_req_cb cb_fn;
|
2020-05-07 18:45:15 +00:00
|
|
|
struct idxd_batch *batch;
|
2020-08-03 15:54:55 +00:00
|
|
|
struct idxd_hw_desc *desc;
|
2022-04-18 19:34:57 +00:00
|
|
|
union {
|
|
|
|
uint32_t *crc_dst;
|
|
|
|
uint32_t *output_size;
|
|
|
|
};
|
2022-04-11 18:12:59 +00:00
|
|
|
struct idxd_ops *parent;
|
|
|
|
uint32_t count;
|
2022-04-12 21:12:12 +00:00
|
|
|
STAILQ_ENTRY(idxd_ops) link;
|
2020-08-03 15:54:55 +00:00
|
|
|
};
|
2022-05-20 16:40:25 +00:00
|
|
|
SPDK_STATIC_ASSERT(sizeof(struct idxd_ops) == 128, "size mismatch");
|
2020-04-10 15:29:01 +00:00
|
|
|
|
2021-04-13 11:02:46 +00:00
|
|
|
struct spdk_idxd_impl {
|
|
|
|
const char *name;
|
2022-05-20 16:40:25 +00:00
|
|
|
int (*probe)(void *cb_ctx, spdk_idxd_attach_cb attach_cb,
|
|
|
|
spdk_idxd_probe_cb probe_cb);
|
2021-04-13 11:02:46 +00:00
|
|
|
void (*destruct)(struct spdk_idxd_device *idxd);
|
2021-07-08 10:29:27 +00:00
|
|
|
void (*dump_sw_error)(struct spdk_idxd_device *idxd, void *portal);
|
2021-04-13 11:02:46 +00:00
|
|
|
char *(*portal_get_addr)(struct spdk_idxd_device *idxd);
|
|
|
|
|
|
|
|
STAILQ_ENTRY(spdk_idxd_impl) link;
|
|
|
|
};
|
|
|
|
|
2020-04-10 15:29:01 +00:00
|
|
|
struct spdk_idxd_device {
|
2021-04-13 11:02:46 +00:00
|
|
|
struct spdk_idxd_impl *impl;
|
2022-01-21 19:50:31 +00:00
|
|
|
void *portal;
|
|
|
|
uint32_t socket_id;
|
2021-01-09 21:55:16 +00:00
|
|
|
uint32_t num_channels;
|
2021-06-03 17:29:01 +00:00
|
|
|
uint32_t total_wq_size;
|
2021-06-05 14:18:11 +00:00
|
|
|
uint32_t chan_per_device;
|
2021-01-09 21:55:16 +00:00
|
|
|
pthread_mutex_t num_channels_lock;
|
2022-05-20 16:40:25 +00:00
|
|
|
enum idxd_dev type;
|
2022-04-18 19:34:57 +00:00
|
|
|
struct iaa_aecs *aecs;
|
2022-07-06 21:28:52 +00:00
|
|
|
uint32_t version;
|
2020-04-10 15:29:01 +00:00
|
|
|
};
|
|
|
|
|
2021-04-13 11:02:46 +00:00
|
|
|
void idxd_impl_register(struct spdk_idxd_impl *impl);
|
|
|
|
|
|
|
|
#define SPDK_IDXD_IMPL_REGISTER(name, impl) \
|
|
|
|
static void __attribute__((constructor)) idxd_impl_register_##name(void) \
|
|
|
|
{ \
|
|
|
|
idxd_impl_register(impl); \
|
|
|
|
}
|
|
|
|
|
2020-04-10 15:29:01 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __IDXD_H__ */
|