1/*
2 * Copyright 2014 IBM Corp.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 */
9
10#ifndef _UAPI_MISC_CXL_H
11#define _UAPI_MISC_CXL_H
12
13#include <linux/types.h>
14#include <linux/ioctl.h>
15
16
17struct cxl_ioctl_start_work {
18	__u64 flags;
19	__u64 work_element_descriptor;
20	__u64 amr;
21	__s16 num_interrupts;
22	__s16 reserved1;
23	__s32 reserved2;
24	__u64 reserved3;
25	__u64 reserved4;
26	__u64 reserved5;
27	__u64 reserved6;
28};
29
30#define CXL_START_WORK_AMR		0x0000000000000001ULL
31#define CXL_START_WORK_NUM_IRQS		0x0000000000000002ULL
32#define CXL_START_WORK_ERR_FF		0x0000000000000004ULL
33#define CXL_START_WORK_ALL		(CXL_START_WORK_AMR |\
34					 CXL_START_WORK_NUM_IRQS |\
35					 CXL_START_WORK_ERR_FF)
36
37
38/* Possible modes that an afu can be in */
39#define CXL_MODE_DEDICATED   0x1
40#define CXL_MODE_DIRECTED    0x2
41
42/* possible flags for the cxl_afu_id flags field */
43#define CXL_AFUID_FLAG_SLAVE    0x1  /* In directed-mode afu is in slave mode */
44
45struct cxl_afu_id {
46	__u64 flags;     /* One of CXL_AFUID_FLAG_X */
47	__u32 card_id;
48	__u32 afu_offset;
49	__u32 afu_mode;  /* one of the CXL_MODE_X */
50	__u32 reserved1;
51	__u64 reserved2;
52	__u64 reserved3;
53	__u64 reserved4;
54	__u64 reserved5;
55	__u64 reserved6;
56};
57
58/* ioctl numbers */
59#define CXL_MAGIC 0xCA
60#define CXL_IOCTL_START_WORK		_IOW(CXL_MAGIC, 0x00, struct cxl_ioctl_start_work)
61#define CXL_IOCTL_GET_PROCESS_ELEMENT	_IOR(CXL_MAGIC, 0x01, __u32)
62#define CXL_IOCTL_GET_AFU_ID            _IOR(CXL_MAGIC, 0x02, struct cxl_afu_id)
63
64#define CXL_READ_MIN_SIZE 0x1000 /* 4K */
65
66/* Events from read() */
67enum cxl_event_type {
68	CXL_EVENT_RESERVED      = 0,
69	CXL_EVENT_AFU_INTERRUPT = 1,
70	CXL_EVENT_DATA_STORAGE  = 2,
71	CXL_EVENT_AFU_ERROR     = 3,
72};
73
74struct cxl_event_header {
75	__u16 type;
76	__u16 size;
77	__u16 process_element;
78	__u16 reserved1;
79};
80
81struct cxl_event_afu_interrupt {
82	__u16 flags;
83	__u16 irq; /* Raised AFU interrupt number */
84	__u32 reserved1;
85};
86
87struct cxl_event_data_storage {
88	__u16 flags;
89	__u16 reserved1;
90	__u32 reserved2;
91	__u64 addr;
92	__u64 dsisr;
93	__u64 reserved3;
94};
95
96struct cxl_event_afu_error {
97	__u16 flags;
98	__u16 reserved1;
99	__u32 reserved2;
100	__u64 error;
101};
102
103struct cxl_event {
104	struct cxl_event_header header;
105	union {
106		struct cxl_event_afu_interrupt irq;
107		struct cxl_event_data_storage fault;
108		struct cxl_event_afu_error afu_error;
109	};
110};
111
112#endif /* _UAPI_MISC_CXL_H */
113