xref: /linux/drivers/dma/idxd/idxd.h (revision 0dcfe41e9a4ca759ccc87a48e3bb9cc3b08ff1e8)
1bfe1d560SDave Jiang /* SPDX-License-Identifier: GPL-2.0 */
2bfe1d560SDave Jiang /* Copyright(c) 2019 Intel Corporation. All rights rsvd. */
3bfe1d560SDave Jiang #ifndef _IDXD_H_
4bfe1d560SDave Jiang #define _IDXD_H_
5bfe1d560SDave Jiang 
6bfe1d560SDave Jiang #include <linux/sbitmap.h>
78f47d1a5SDave Jiang #include <linux/dmaengine.h>
8bfe1d560SDave Jiang #include <linux/percpu-rwsem.h>
9bfe1d560SDave Jiang #include <linux/wait.h>
1042d279f9SDave Jiang #include <linux/cdev.h>
1147c16ac2SDave Jiang #include <linux/idr.h>
1281dd4d4dSTom Zanussi #include <linux/pci.h>
1381dd4d4dSTom Zanussi #include <linux/perf_event.h>
14bfe1d560SDave Jiang #include "registers.h"
15bfe1d560SDave Jiang 
16bfe1d560SDave Jiang #define IDXD_DRIVER_VERSION	"1.00"
17bfe1d560SDave Jiang 
18bfe1d560SDave Jiang extern struct kmem_cache *idxd_desc_pool;
19bfe1d560SDave Jiang 
2039786285SDave Jiang struct idxd_device;
2139786285SDave Jiang struct idxd_wq;
2239786285SDave Jiang 
23bfe1d560SDave Jiang #define IDXD_REG_TIMEOUT	50
24bfe1d560SDave Jiang #define IDXD_DRAIN_TIMEOUT	5000
25bfe1d560SDave Jiang 
26bfe1d560SDave Jiang enum idxd_type {
27bfe1d560SDave Jiang 	IDXD_TYPE_UNKNOWN = -1,
28bfe1d560SDave Jiang 	IDXD_TYPE_DSA = 0,
29f25b4638SDave Jiang 	IDXD_TYPE_IAX,
30f25b4638SDave Jiang 	IDXD_TYPE_MAX,
31bfe1d560SDave Jiang };
32bfe1d560SDave Jiang 
33bfe1d560SDave Jiang #define IDXD_NAME_SIZE		128
3481dd4d4dSTom Zanussi #define IDXD_PMU_EVENT_MAX	64
35bfe1d560SDave Jiang 
36bfe1d560SDave Jiang struct idxd_device_driver {
37bfe1d560SDave Jiang 	struct device_driver drv;
38bfe1d560SDave Jiang };
39bfe1d560SDave Jiang 
40bfe1d560SDave Jiang struct idxd_irq_entry {
41bfe1d560SDave Jiang 	struct idxd_device *idxd;
42bfe1d560SDave Jiang 	int id;
435fc8e85fSDave Jiang 	int vector;
44bfe1d560SDave Jiang 	struct llist_head pending_llist;
45bfe1d560SDave Jiang 	struct list_head work_list;
46e4f4d8cdSDave Jiang 	/*
47e4f4d8cdSDave Jiang 	 * Lock to protect access between irq thread process descriptor
48e4f4d8cdSDave Jiang 	 * and irq thread processing error descriptor.
49e4f4d8cdSDave Jiang 	 */
50e4f4d8cdSDave Jiang 	spinlock_t list_lock;
51bfe1d560SDave Jiang };
52bfe1d560SDave Jiang 
53bfe1d560SDave Jiang struct idxd_group {
54bfe1d560SDave Jiang 	struct device conf_dev;
55bfe1d560SDave Jiang 	struct idxd_device *idxd;
56bfe1d560SDave Jiang 	struct grpcfg grpcfg;
57bfe1d560SDave Jiang 	int id;
58bfe1d560SDave Jiang 	int num_engines;
59bfe1d560SDave Jiang 	int num_wqs;
60bfe1d560SDave Jiang 	bool use_token_limit;
61bfe1d560SDave Jiang 	u8 tokens_allowed;
62bfe1d560SDave Jiang 	u8 tokens_reserved;
63bfe1d560SDave Jiang 	int tc_a;
64bfe1d560SDave Jiang 	int tc_b;
65bfe1d560SDave Jiang };
66bfe1d560SDave Jiang 
6781dd4d4dSTom Zanussi struct idxd_pmu {
6881dd4d4dSTom Zanussi 	struct idxd_device *idxd;
6981dd4d4dSTom Zanussi 
7081dd4d4dSTom Zanussi 	struct perf_event *event_list[IDXD_PMU_EVENT_MAX];
7181dd4d4dSTom Zanussi 	int n_events;
7281dd4d4dSTom Zanussi 
7381dd4d4dSTom Zanussi 	DECLARE_BITMAP(used_mask, IDXD_PMU_EVENT_MAX);
7481dd4d4dSTom Zanussi 
7581dd4d4dSTom Zanussi 	struct pmu pmu;
7681dd4d4dSTom Zanussi 	char name[IDXD_NAME_SIZE];
7781dd4d4dSTom Zanussi 	int cpu;
7881dd4d4dSTom Zanussi 
7981dd4d4dSTom Zanussi 	int n_counters;
8081dd4d4dSTom Zanussi 	int counter_width;
8181dd4d4dSTom Zanussi 	int n_event_categories;
8281dd4d4dSTom Zanussi 
8381dd4d4dSTom Zanussi 	bool per_counter_caps_supported;
8481dd4d4dSTom Zanussi 	unsigned long supported_event_categories;
8581dd4d4dSTom Zanussi 
8681dd4d4dSTom Zanussi 	unsigned long supported_filters;
8781dd4d4dSTom Zanussi 	int n_filters;
8881dd4d4dSTom Zanussi 
8981dd4d4dSTom Zanussi 	struct hlist_node cpuhp_node;
9081dd4d4dSTom Zanussi };
9181dd4d4dSTom Zanussi 
92bfe1d560SDave Jiang #define IDXD_MAX_PRIORITY	0xf
93bfe1d560SDave Jiang 
94bfe1d560SDave Jiang enum idxd_wq_state {
95bfe1d560SDave Jiang 	IDXD_WQ_DISABLED = 0,
96bfe1d560SDave Jiang 	IDXD_WQ_ENABLED,
97bfe1d560SDave Jiang };
98bfe1d560SDave Jiang 
99bfe1d560SDave Jiang enum idxd_wq_flag {
100bfe1d560SDave Jiang 	WQ_FLAG_DEDICATED = 0,
1018e50d392SDave Jiang 	WQ_FLAG_BLOCK_ON_FAULT,
102bfe1d560SDave Jiang };
103bfe1d560SDave Jiang 
104bfe1d560SDave Jiang enum idxd_wq_type {
105bfe1d560SDave Jiang 	IDXD_WQT_NONE = 0,
106bfe1d560SDave Jiang 	IDXD_WQT_KERNEL,
10742d279f9SDave Jiang 	IDXD_WQT_USER,
10842d279f9SDave Jiang };
10942d279f9SDave Jiang 
11042d279f9SDave Jiang struct idxd_cdev {
11104922b74SDave Jiang 	struct idxd_wq *wq;
11242d279f9SDave Jiang 	struct cdev cdev;
11304922b74SDave Jiang 	struct device dev;
11442d279f9SDave Jiang 	int minor;
115bfe1d560SDave Jiang };
116bfe1d560SDave Jiang 
117bfe1d560SDave Jiang #define IDXD_ALLOCATED_BATCH_SIZE	128U
118bfe1d560SDave Jiang #define WQ_NAME_SIZE   1024
119bfe1d560SDave Jiang #define WQ_TYPE_SIZE   10
120bfe1d560SDave Jiang 
121d1dfe5b8SDave Jiang enum idxd_op_type {
122d1dfe5b8SDave Jiang 	IDXD_OP_BLOCK = 0,
123d1dfe5b8SDave Jiang 	IDXD_OP_NONBLOCK = 1,
124d1dfe5b8SDave Jiang };
125d1dfe5b8SDave Jiang 
1268f47d1a5SDave Jiang enum idxd_complete_type {
1278f47d1a5SDave Jiang 	IDXD_COMPLETE_NORMAL = 0,
1288f47d1a5SDave Jiang 	IDXD_COMPLETE_ABORT,
1298e50d392SDave Jiang 	IDXD_COMPLETE_DEV_FAIL,
1308f47d1a5SDave Jiang };
1318f47d1a5SDave Jiang 
13239786285SDave Jiang struct idxd_dma_chan {
13339786285SDave Jiang 	struct dma_chan chan;
13439786285SDave Jiang 	struct idxd_wq *wq;
13539786285SDave Jiang };
13639786285SDave Jiang 
137bfe1d560SDave Jiang struct idxd_wq {
1388e50d392SDave Jiang 	void __iomem *portal;
13993a40a6dSDave Jiang 	struct percpu_ref wq_active;
14093a40a6dSDave Jiang 	struct completion wq_dead;
141bfe1d560SDave Jiang 	struct device conf_dev;
14204922b74SDave Jiang 	struct idxd_cdev *idxd_cdev;
14304922b74SDave Jiang 	struct wait_queue_head err_queue;
144bfe1d560SDave Jiang 	struct idxd_device *idxd;
145bfe1d560SDave Jiang 	int id;
146bfe1d560SDave Jiang 	enum idxd_wq_type type;
147bfe1d560SDave Jiang 	struct idxd_group *group;
148bfe1d560SDave Jiang 	int client_count;
149bfe1d560SDave Jiang 	struct mutex wq_lock;	/* mutex for workqueue */
150bfe1d560SDave Jiang 	u32 size;
151bfe1d560SDave Jiang 	u32 threshold;
152bfe1d560SDave Jiang 	u32 priority;
153bfe1d560SDave Jiang 	enum idxd_wq_state state;
154bfe1d560SDave Jiang 	unsigned long flags;
155d98793b5SDave Jiang 	union wqcfg *wqcfg;
156bfe1d560SDave Jiang 	u32 vec_ptr;		/* interrupt steering */
157bfe1d560SDave Jiang 	struct dsa_hw_desc **hw_descs;
158bfe1d560SDave Jiang 	int num_descs;
159f25b4638SDave Jiang 	union {
160bfe1d560SDave Jiang 		struct dsa_completion_record *compls;
161f25b4638SDave Jiang 		struct iax_completion_record *iax_compls;
162f25b4638SDave Jiang 	};
163f25b4638SDave Jiang 	void *compls_raw;
164bfe1d560SDave Jiang 	dma_addr_t compls_addr;
165f25b4638SDave Jiang 	dma_addr_t compls_addr_raw;
166bfe1d560SDave Jiang 	int compls_size;
167bfe1d560SDave Jiang 	struct idxd_desc **descs;
1680705107fSDave Jiang 	struct sbitmap_queue sbq;
16939786285SDave Jiang 	struct idxd_dma_chan *idxd_chan;
170bfe1d560SDave Jiang 	char name[WQ_NAME_SIZE + 1];
171d7aad555SDave Jiang 	u64 max_xfer_bytes;
172e7184b15SDave Jiang 	u32 max_batch_size;
17392de5fa2SDave Jiang 	bool ats_dis;
174bfe1d560SDave Jiang };
175bfe1d560SDave Jiang 
176bfe1d560SDave Jiang struct idxd_engine {
177bfe1d560SDave Jiang 	struct device conf_dev;
178bfe1d560SDave Jiang 	int id;
179bfe1d560SDave Jiang 	struct idxd_group *group;
180bfe1d560SDave Jiang 	struct idxd_device *idxd;
181bfe1d560SDave Jiang };
182bfe1d560SDave Jiang 
183bfe1d560SDave Jiang /* shadow registers */
184bfe1d560SDave Jiang struct idxd_hw {
185bfe1d560SDave Jiang 	u32 version;
186bfe1d560SDave Jiang 	union gen_cap_reg gen_cap;
187bfe1d560SDave Jiang 	union wq_cap_reg wq_cap;
188bfe1d560SDave Jiang 	union group_cap_reg group_cap;
189bfe1d560SDave Jiang 	union engine_cap_reg engine_cap;
190bfe1d560SDave Jiang 	struct opcap opcap;
191eb15e715SDave Jiang 	u32 cmd_cap;
192bfe1d560SDave Jiang };
193bfe1d560SDave Jiang 
194bfe1d560SDave Jiang enum idxd_device_state {
195bfe1d560SDave Jiang 	IDXD_DEV_HALTED = -1,
196bfe1d560SDave Jiang 	IDXD_DEV_DISABLED = 0,
197bfe1d560SDave Jiang 	IDXD_DEV_CONF_READY,
198bfe1d560SDave Jiang 	IDXD_DEV_ENABLED,
199bfe1d560SDave Jiang };
200bfe1d560SDave Jiang 
201bfe1d560SDave Jiang enum idxd_device_flag {
202bfe1d560SDave Jiang 	IDXD_FLAG_CONFIGURABLE = 0,
2030d5c10b4SDave Jiang 	IDXD_FLAG_CMD_RUNNING,
2048e50d392SDave Jiang 	IDXD_FLAG_PASID_ENABLED,
205bfe1d560SDave Jiang };
206bfe1d560SDave Jiang 
20739786285SDave Jiang struct idxd_dma_dev {
20839786285SDave Jiang 	struct idxd_device *idxd;
20939786285SDave Jiang 	struct dma_device dma;
21039786285SDave Jiang };
21139786285SDave Jiang 
212435b512dSDave Jiang struct idxd_driver_data {
213435b512dSDave Jiang 	const char *name_prefix;
214bfe1d560SDave Jiang 	enum idxd_type type;
215435b512dSDave Jiang 	struct device_type *dev_type;
216435b512dSDave Jiang 	int compl_size;
217435b512dSDave Jiang 	int align;
218435b512dSDave Jiang };
219435b512dSDave Jiang 
220435b512dSDave Jiang struct idxd_device {
221bfe1d560SDave Jiang 	struct device conf_dev;
222435b512dSDave Jiang 	struct idxd_driver_data *data;
223bfe1d560SDave Jiang 	struct list_head list;
224bfe1d560SDave Jiang 	struct idxd_hw hw;
225bfe1d560SDave Jiang 	enum idxd_device_state state;
226bfe1d560SDave Jiang 	unsigned long flags;
227bfe1d560SDave Jiang 	int id;
22842d279f9SDave Jiang 	int major;
229ff18de55SDave Jiang 	u8 cmd_status;
230bfe1d560SDave Jiang 
231bfe1d560SDave Jiang 	struct pci_dev *pdev;
232bfe1d560SDave Jiang 	void __iomem *reg_base;
233bfe1d560SDave Jiang 
234bfe1d560SDave Jiang 	spinlock_t dev_lock;	/* spinlock for device */
23553b2ee7fSDave Jiang 	spinlock_t cmd_lock;	/* spinlock for device commands */
2360d5c10b4SDave Jiang 	struct completion *cmd_done;
237defe49f9SDave Jiang 	struct idxd_group **groups;
2387c5dd23eSDave Jiang 	struct idxd_wq **wqs;
23975b91130SDave Jiang 	struct idxd_engine **engines;
240bfe1d560SDave Jiang 
2418e50d392SDave Jiang 	struct iommu_sva *sva;
2428e50d392SDave Jiang 	unsigned int pasid;
2438e50d392SDave Jiang 
244bfe1d560SDave Jiang 	int num_groups;
245bfe1d560SDave Jiang 
246bfe1d560SDave Jiang 	u32 msix_perm_offset;
247bfe1d560SDave Jiang 	u32 wqcfg_offset;
248bfe1d560SDave Jiang 	u32 grpcfg_offset;
249bfe1d560SDave Jiang 	u32 perfmon_offset;
250bfe1d560SDave Jiang 
251bfe1d560SDave Jiang 	u64 max_xfer_bytes;
252bfe1d560SDave Jiang 	u32 max_batch_size;
253bfe1d560SDave Jiang 	int max_groups;
254bfe1d560SDave Jiang 	int max_engines;
255bfe1d560SDave Jiang 	int max_tokens;
256bfe1d560SDave Jiang 	int max_wqs;
257bfe1d560SDave Jiang 	int max_wq_size;
258bfe1d560SDave Jiang 	int token_limit;
259c52ca478SDave Jiang 	int nr_tokens;		/* non-reserved tokens */
260d98793b5SDave Jiang 	unsigned int wqcfg_size;
261bfe1d560SDave Jiang 
262bfe1d560SDave Jiang 	union sw_err_reg sw_err;
2630d5c10b4SDave Jiang 	wait_queue_head_t cmd_waitq;
264bfe1d560SDave Jiang 	int num_wq_irqs;
265bfe1d560SDave Jiang 	struct idxd_irq_entry *irq_entries;
2668f47d1a5SDave Jiang 
26739786285SDave Jiang 	struct idxd_dma_dev *idxd_dma;
2680d5c10b4SDave Jiang 	struct workqueue_struct *wq;
2690d5c10b4SDave Jiang 	struct work_struct work;
270eb15e715SDave Jiang 
271eb15e715SDave Jiang 	int *int_handles;
27281dd4d4dSTom Zanussi 
27381dd4d4dSTom Zanussi 	struct idxd_pmu *idxd_pmu;
274bfe1d560SDave Jiang };
275bfe1d560SDave Jiang 
276bfe1d560SDave Jiang /* IDXD software descriptor */
277bfe1d560SDave Jiang struct idxd_desc {
278f25b4638SDave Jiang 	union {
279bfe1d560SDave Jiang 		struct dsa_hw_desc *hw;
280f25b4638SDave Jiang 		struct iax_hw_desc *iax_hw;
281f25b4638SDave Jiang 	};
282bfe1d560SDave Jiang 	dma_addr_t desc_dma;
283f25b4638SDave Jiang 	union {
284bfe1d560SDave Jiang 		struct dsa_completion_record *completion;
285f25b4638SDave Jiang 		struct iax_completion_record *iax_completion;
286f25b4638SDave Jiang 	};
287bfe1d560SDave Jiang 	dma_addr_t compl_dma;
2888f47d1a5SDave Jiang 	struct dma_async_tx_descriptor txd;
289bfe1d560SDave Jiang 	struct llist_node llnode;
290bfe1d560SDave Jiang 	struct list_head list;
291bfe1d560SDave Jiang 	int id;
2920705107fSDave Jiang 	int cpu;
293eb15e715SDave Jiang 	unsigned int vector;
294bfe1d560SDave Jiang 	struct idxd_wq *wq;
295bfe1d560SDave Jiang };
296bfe1d560SDave Jiang 
297bfe1d560SDave Jiang #define confdev_to_idxd(dev) container_of(dev, struct idxd_device, conf_dev)
298bfe1d560SDave Jiang #define confdev_to_wq(dev) container_of(dev, struct idxd_wq, conf_dev)
299bfe1d560SDave Jiang 
30042d279f9SDave Jiang extern struct bus_type dsa_bus_type;
301f25b4638SDave Jiang extern struct bus_type iax_bus_type;
30242d279f9SDave Jiang 
3038e50d392SDave Jiang extern bool support_enqcmd;
3044b73e4ebSDave Jiang extern struct ida idxd_ida;
30547c16ac2SDave Jiang extern struct device_type dsa_device_type;
30647c16ac2SDave Jiang extern struct device_type iax_device_type;
3077c5dd23eSDave Jiang extern struct device_type idxd_wq_device_type;
30875b91130SDave Jiang extern struct device_type idxd_engine_device_type;
309defe49f9SDave Jiang extern struct device_type idxd_group_device_type;
31047c16ac2SDave Jiang 
31147c16ac2SDave Jiang static inline bool is_dsa_dev(struct device *dev)
31247c16ac2SDave Jiang {
31347c16ac2SDave Jiang 	return dev->type == &dsa_device_type;
31447c16ac2SDave Jiang }
31547c16ac2SDave Jiang 
31647c16ac2SDave Jiang static inline bool is_iax_dev(struct device *dev)
31747c16ac2SDave Jiang {
31847c16ac2SDave Jiang 	return dev->type == &iax_device_type;
31947c16ac2SDave Jiang }
32047c16ac2SDave Jiang 
32147c16ac2SDave Jiang static inline bool is_idxd_dev(struct device *dev)
32247c16ac2SDave Jiang {
32347c16ac2SDave Jiang 	return is_dsa_dev(dev) || is_iax_dev(dev);
32447c16ac2SDave Jiang }
3258e50d392SDave Jiang 
3267c5dd23eSDave Jiang static inline bool is_idxd_wq_dev(struct device *dev)
3277c5dd23eSDave Jiang {
3287c5dd23eSDave Jiang 	return dev->type == &idxd_wq_device_type;
3297c5dd23eSDave Jiang }
3307c5dd23eSDave Jiang 
3317c5dd23eSDave Jiang static inline bool is_idxd_wq_dmaengine(struct idxd_wq *wq)
3327c5dd23eSDave Jiang {
3337c5dd23eSDave Jiang 	if (wq->type == IDXD_WQT_KERNEL && strcmp(wq->name, "dmaengine") == 0)
3347c5dd23eSDave Jiang 		return true;
3357c5dd23eSDave Jiang 	return false;
3367c5dd23eSDave Jiang }
3377c5dd23eSDave Jiang 
3387c5dd23eSDave Jiang static inline bool is_idxd_wq_cdev(struct idxd_wq *wq)
3397c5dd23eSDave Jiang {
3407c5dd23eSDave Jiang 	return wq->type == IDXD_WQT_USER;
3417c5dd23eSDave Jiang }
3427c5dd23eSDave Jiang 
343bfe1d560SDave Jiang static inline bool wq_dedicated(struct idxd_wq *wq)
344bfe1d560SDave Jiang {
345bfe1d560SDave Jiang 	return test_bit(WQ_FLAG_DEDICATED, &wq->flags);
346bfe1d560SDave Jiang }
347bfe1d560SDave Jiang 
3488e50d392SDave Jiang static inline bool wq_shared(struct idxd_wq *wq)
3498e50d392SDave Jiang {
3508e50d392SDave Jiang 	return !test_bit(WQ_FLAG_DEDICATED, &wq->flags);
3518e50d392SDave Jiang }
3528e50d392SDave Jiang 
3538e50d392SDave Jiang static inline bool device_pasid_enabled(struct idxd_device *idxd)
3548e50d392SDave Jiang {
3558e50d392SDave Jiang 	return test_bit(IDXD_FLAG_PASID_ENABLED, &idxd->flags);
3568e50d392SDave Jiang }
3578e50d392SDave Jiang 
3588e50d392SDave Jiang static inline bool device_swq_supported(struct idxd_device *idxd)
3598e50d392SDave Jiang {
3608e50d392SDave Jiang 	return (support_enqcmd && device_pasid_enabled(idxd));
3618e50d392SDave Jiang }
3628e50d392SDave Jiang 
36342d279f9SDave Jiang enum idxd_portal_prot {
36442d279f9SDave Jiang 	IDXD_PORTAL_UNLIMITED = 0,
36542d279f9SDave Jiang 	IDXD_PORTAL_LIMITED,
36642d279f9SDave Jiang };
36742d279f9SDave Jiang 
368eb15e715SDave Jiang enum idxd_interrupt_type {
369eb15e715SDave Jiang 	IDXD_IRQ_MSIX = 0,
370eb15e715SDave Jiang 	IDXD_IRQ_IMS,
371eb15e715SDave Jiang };
372eb15e715SDave Jiang 
37342d279f9SDave Jiang static inline int idxd_get_wq_portal_offset(enum idxd_portal_prot prot)
37442d279f9SDave Jiang {
37542d279f9SDave Jiang 	return prot * 0x1000;
37642d279f9SDave Jiang }
37742d279f9SDave Jiang 
37842d279f9SDave Jiang static inline int idxd_get_wq_portal_full_offset(int wq_id,
37942d279f9SDave Jiang 						 enum idxd_portal_prot prot)
38042d279f9SDave Jiang {
38142d279f9SDave Jiang 	return ((wq_id * 4) << PAGE_SHIFT) + idxd_get_wq_portal_offset(prot);
38242d279f9SDave Jiang }
38342d279f9SDave Jiang 
384c52ca478SDave Jiang static inline void idxd_wq_get(struct idxd_wq *wq)
385c52ca478SDave Jiang {
386c52ca478SDave Jiang 	wq->client_count++;
387c52ca478SDave Jiang }
388c52ca478SDave Jiang 
389c52ca478SDave Jiang static inline void idxd_wq_put(struct idxd_wq *wq)
390c52ca478SDave Jiang {
391c52ca478SDave Jiang 	wq->client_count--;
392c52ca478SDave Jiang }
393c52ca478SDave Jiang 
394c52ca478SDave Jiang static inline int idxd_wq_refcount(struct idxd_wq *wq)
395c52ca478SDave Jiang {
396c52ca478SDave Jiang 	return wq->client_count;
397c52ca478SDave Jiang };
398c52ca478SDave Jiang 
399c52ca478SDave Jiang int idxd_register_bus_type(void);
400c52ca478SDave Jiang void idxd_unregister_bus_type(void);
40147c16ac2SDave Jiang int idxd_register_devices(struct idxd_device *idxd);
40247c16ac2SDave Jiang void idxd_unregister_devices(struct idxd_device *idxd);
403c52ca478SDave Jiang int idxd_register_driver(void);
404c52ca478SDave Jiang void idxd_unregister_driver(void);
4055b0c68c4SDave Jiang void idxd_wqs_quiesce(struct idxd_device *idxd);
406bfe1d560SDave Jiang 
407bfe1d560SDave Jiang /* device interrupt control */
4086df0e6c5SDave Jiang void idxd_msix_perm_setup(struct idxd_device *idxd);
4096df0e6c5SDave Jiang void idxd_msix_perm_clear(struct idxd_device *idxd);
410bfe1d560SDave Jiang irqreturn_t idxd_misc_thread(int vec, void *data);
411bfe1d560SDave Jiang irqreturn_t idxd_wq_thread(int irq, void *data);
412bfe1d560SDave Jiang void idxd_mask_error_interrupts(struct idxd_device *idxd);
413bfe1d560SDave Jiang void idxd_unmask_error_interrupts(struct idxd_device *idxd);
414bfe1d560SDave Jiang void idxd_mask_msix_vectors(struct idxd_device *idxd);
4154548a6adSDave Jiang void idxd_mask_msix_vector(struct idxd_device *idxd, int vec_id);
4164548a6adSDave Jiang void idxd_unmask_msix_vector(struct idxd_device *idxd, int vec_id);
417bfe1d560SDave Jiang 
418bfe1d560SDave Jiang /* device control */
41989e3becdSDave Jiang int idxd_device_init_reset(struct idxd_device *idxd);
420bfe1d560SDave Jiang int idxd_device_enable(struct idxd_device *idxd);
421bfe1d560SDave Jiang int idxd_device_disable(struct idxd_device *idxd);
4220d5c10b4SDave Jiang void idxd_device_reset(struct idxd_device *idxd);
423*0dcfe41eSDave Jiang void idxd_device_clear_state(struct idxd_device *idxd);
424bfe1d560SDave Jiang int idxd_device_config(struct idxd_device *idxd);
4258e50d392SDave Jiang void idxd_device_drain_pasid(struct idxd_device *idxd, int pasid);
4268c66bbdcSDave Jiang int idxd_device_load_config(struct idxd_device *idxd);
427eb15e715SDave Jiang int idxd_device_request_int_handle(struct idxd_device *idxd, int idx, int *handle,
428eb15e715SDave Jiang 				   enum idxd_interrupt_type irq_type);
429eb15e715SDave Jiang int idxd_device_release_int_handle(struct idxd_device *idxd, int handle,
430eb15e715SDave Jiang 				   enum idxd_interrupt_type irq_type);
431bfe1d560SDave Jiang 
432bfe1d560SDave Jiang /* work queue control */
4335b0c68c4SDave Jiang void idxd_wqs_unmap_portal(struct idxd_device *idxd);
434bfe1d560SDave Jiang int idxd_wq_alloc_resources(struct idxd_wq *wq);
435bfe1d560SDave Jiang void idxd_wq_free_resources(struct idxd_wq *wq);
436bfe1d560SDave Jiang int idxd_wq_enable(struct idxd_wq *wq);
437*0dcfe41eSDave Jiang int idxd_wq_disable(struct idxd_wq *wq, bool reset_config);
4380d5c10b4SDave Jiang void idxd_wq_drain(struct idxd_wq *wq);
439ea9aadc0SDave Jiang void idxd_wq_reset(struct idxd_wq *wq);
440c52ca478SDave Jiang int idxd_wq_map_portal(struct idxd_wq *wq);
441c52ca478SDave Jiang void idxd_wq_unmap_portal(struct idxd_wq *wq);
4428e50d392SDave Jiang int idxd_wq_set_pasid(struct idxd_wq *wq, int pasid);
4438e50d392SDave Jiang int idxd_wq_disable_pasid(struct idxd_wq *wq);
44493a40a6dSDave Jiang void idxd_wq_quiesce(struct idxd_wq *wq);
44593a40a6dSDave Jiang int idxd_wq_init_percpu_ref(struct idxd_wq *wq);
446bfe1d560SDave Jiang 
447d1dfe5b8SDave Jiang /* submission */
448d1dfe5b8SDave Jiang int idxd_submit_desc(struct idxd_wq *wq, struct idxd_desc *desc);
449d1dfe5b8SDave Jiang struct idxd_desc *idxd_alloc_desc(struct idxd_wq *wq, enum idxd_op_type optype);
450d1dfe5b8SDave Jiang void idxd_free_desc(struct idxd_wq *wq, struct idxd_desc *desc);
451d1dfe5b8SDave Jiang 
4528f47d1a5SDave Jiang /* dmaengine */
4538f47d1a5SDave Jiang int idxd_register_dma_device(struct idxd_device *idxd);
4548f47d1a5SDave Jiang void idxd_unregister_dma_device(struct idxd_device *idxd);
4558f47d1a5SDave Jiang int idxd_register_dma_channel(struct idxd_wq *wq);
4568f47d1a5SDave Jiang void idxd_unregister_dma_channel(struct idxd_wq *wq);
4578f47d1a5SDave Jiang void idxd_parse_completion_status(u8 status, enum dmaengine_tx_result *res);
4588f47d1a5SDave Jiang void idxd_dma_complete_txd(struct idxd_desc *desc,
4598f47d1a5SDave Jiang 			   enum idxd_complete_type comp_type);
4608f47d1a5SDave Jiang 
46142d279f9SDave Jiang /* cdev */
46242d279f9SDave Jiang int idxd_cdev_register(void);
46342d279f9SDave Jiang void idxd_cdev_remove(void);
46442d279f9SDave Jiang int idxd_cdev_get_major(struct idxd_device *idxd);
46542d279f9SDave Jiang int idxd_wq_add_cdev(struct idxd_wq *wq);
46642d279f9SDave Jiang void idxd_wq_del_cdev(struct idxd_wq *wq);
46742d279f9SDave Jiang 
46881dd4d4dSTom Zanussi /* perfmon */
46981dd4d4dSTom Zanussi #if IS_ENABLED(CONFIG_INTEL_IDXD_PERFMON)
47081dd4d4dSTom Zanussi int perfmon_pmu_init(struct idxd_device *idxd);
47181dd4d4dSTom Zanussi void perfmon_pmu_remove(struct idxd_device *idxd);
47281dd4d4dSTom Zanussi void perfmon_counter_overflow(struct idxd_device *idxd);
47381dd4d4dSTom Zanussi void perfmon_init(void);
47481dd4d4dSTom Zanussi void perfmon_exit(void);
47581dd4d4dSTom Zanussi #else
47681dd4d4dSTom Zanussi static inline int perfmon_pmu_init(struct idxd_device *idxd) { return 0; }
47781dd4d4dSTom Zanussi static inline void perfmon_pmu_remove(struct idxd_device *idxd) {}
47881dd4d4dSTom Zanussi static inline void perfmon_counter_overflow(struct idxd_device *idxd) {}
47981dd4d4dSTom Zanussi static inline void perfmon_init(void) {}
48081dd4d4dSTom Zanussi static inline void perfmon_exit(void) {}
48181dd4d4dSTom Zanussi #endif
48281dd4d4dSTom Zanussi 
483bfe1d560SDave Jiang #endif
484