xref: /OK3568_Linux_fs/kernel/include/uapi/scsi/cxlflash_ioctl.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * CXL Flash Device Driver
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
6*4882a593Smuzhiyun  *             Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * Copyright (C) 2015 IBM Corporation
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or
11*4882a593Smuzhiyun  * modify it under the terms of the GNU General Public License
12*4882a593Smuzhiyun  * as published by the Free Software Foundation; either version
13*4882a593Smuzhiyun  * 2 of the License, or (at your option) any later version.
14*4882a593Smuzhiyun  */
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #ifndef _CXLFLASH_IOCTL_H
17*4882a593Smuzhiyun #define _CXLFLASH_IOCTL_H
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #include <linux/types.h>
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun /*
22*4882a593Smuzhiyun  * Structure and definitions for all CXL Flash ioctls
23*4882a593Smuzhiyun  */
24*4882a593Smuzhiyun #define CXLFLASH_WWID_LEN		16
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun /*
27*4882a593Smuzhiyun  * Structure and flag definitions CXL Flash superpipe ioctls
28*4882a593Smuzhiyun  */
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #define DK_CXLFLASH_VERSION_0	0
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun struct dk_cxlflash_hdr {
33*4882a593Smuzhiyun 	__u16 version;			/* Version data */
34*4882a593Smuzhiyun 	__u16 rsvd[3];			/* Reserved for future use */
35*4882a593Smuzhiyun 	__u64 flags;			/* Input flags */
36*4882a593Smuzhiyun 	__u64 return_flags;		/* Returned flags */
37*4882a593Smuzhiyun };
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun /*
40*4882a593Smuzhiyun  * Return flag definitions available to all superpipe ioctls
41*4882a593Smuzhiyun  *
42*4882a593Smuzhiyun  * Similar to the input flags, these are grown from the bottom-up with the
43*4882a593Smuzhiyun  * intention that ioctl-specific return flag definitions would grow from the
44*4882a593Smuzhiyun  * top-down, allowing the two sets to co-exist. While not required/enforced
45*4882a593Smuzhiyun  * at this time, this provides future flexibility.
46*4882a593Smuzhiyun  */
47*4882a593Smuzhiyun #define DK_CXLFLASH_ALL_PORTS_ACTIVE	0x0000000000000001ULL
48*4882a593Smuzhiyun #define DK_CXLFLASH_APP_CLOSE_ADAP_FD	0x0000000000000002ULL
49*4882a593Smuzhiyun #define DK_CXLFLASH_CONTEXT_SQ_CMD_MODE	0x0000000000000004ULL
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun /*
52*4882a593Smuzhiyun  * General Notes:
53*4882a593Smuzhiyun  * -------------
54*4882a593Smuzhiyun  * The 'context_id' field of all ioctl structures contains the context
55*4882a593Smuzhiyun  * identifier for a context in the lower 32-bits (upper 32-bits are not
56*4882a593Smuzhiyun  * to be used when identifying a context to the AFU). That said, the value
57*4882a593Smuzhiyun  * in its entirety (all 64-bits) is to be treated as an opaque cookie and
58*4882a593Smuzhiyun  * should be presented as such when issuing ioctls.
59*4882a593Smuzhiyun  */
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun /*
62*4882a593Smuzhiyun  * DK_CXLFLASH_ATTACH Notes:
63*4882a593Smuzhiyun  * ------------------------
64*4882a593Smuzhiyun  * Read/write access permissions are specified via the O_RDONLY, O_WRONLY,
65*4882a593Smuzhiyun  * and O_RDWR flags defined in the fcntl.h header file.
66*4882a593Smuzhiyun  *
67*4882a593Smuzhiyun  * A valid adapter file descriptor (fd >= 0) is only returned on the initial
68*4882a593Smuzhiyun  * attach (successful) of a context. When a context is shared(reused), the user
69*4882a593Smuzhiyun  * is expected to already 'know' the adapter file descriptor associated with the
70*4882a593Smuzhiyun  * context.
71*4882a593Smuzhiyun  */
72*4882a593Smuzhiyun #define DK_CXLFLASH_ATTACH_REUSE_CONTEXT	0x8000000000000000ULL
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun struct dk_cxlflash_attach {
75*4882a593Smuzhiyun 	struct dk_cxlflash_hdr hdr;	/* Common fields */
76*4882a593Smuzhiyun 	__u64 num_interrupts;		/* Requested number of interrupts */
77*4882a593Smuzhiyun 	__u64 context_id;		/* Returned context */
78*4882a593Smuzhiyun 	__u64 mmio_size;		/* Returned size of MMIO area */
79*4882a593Smuzhiyun 	__u64 block_size;		/* Returned block size, in bytes */
80*4882a593Smuzhiyun 	__u64 adap_fd;			/* Returned adapter file descriptor */
81*4882a593Smuzhiyun 	__u64 last_lba;			/* Returned last LBA on the device */
82*4882a593Smuzhiyun 	__u64 max_xfer;			/* Returned max transfer size, blocks */
83*4882a593Smuzhiyun 	__u64 reserved[8];		/* Reserved for future use */
84*4882a593Smuzhiyun };
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun struct dk_cxlflash_detach {
87*4882a593Smuzhiyun 	struct dk_cxlflash_hdr hdr;	/* Common fields */
88*4882a593Smuzhiyun 	__u64 context_id;		/* Context to detach */
89*4882a593Smuzhiyun 	__u64 reserved[8];		/* Reserved for future use */
90*4882a593Smuzhiyun };
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun struct dk_cxlflash_udirect {
93*4882a593Smuzhiyun 	struct dk_cxlflash_hdr hdr;	/* Common fields */
94*4882a593Smuzhiyun 	__u64 context_id;		/* Context to own physical resources */
95*4882a593Smuzhiyun 	__u64 rsrc_handle;		/* Returned resource handle */
96*4882a593Smuzhiyun 	__u64 last_lba;			/* Returned last LBA on the device */
97*4882a593Smuzhiyun 	__u64 reserved[8];		/* Reserved for future use */
98*4882a593Smuzhiyun };
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun #define DK_CXLFLASH_UVIRTUAL_NEED_WRITE_SAME	0x8000000000000000ULL
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun struct dk_cxlflash_uvirtual {
103*4882a593Smuzhiyun 	struct dk_cxlflash_hdr hdr;	/* Common fields */
104*4882a593Smuzhiyun 	__u64 context_id;		/* Context to own virtual resources */
105*4882a593Smuzhiyun 	__u64 lun_size;			/* Requested size, in 4K blocks */
106*4882a593Smuzhiyun 	__u64 rsrc_handle;		/* Returned resource handle */
107*4882a593Smuzhiyun 	__u64 last_lba;			/* Returned last LBA of LUN */
108*4882a593Smuzhiyun 	__u64 reserved[8];		/* Reserved for future use */
109*4882a593Smuzhiyun };
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun struct dk_cxlflash_release {
112*4882a593Smuzhiyun 	struct dk_cxlflash_hdr hdr;	/* Common fields */
113*4882a593Smuzhiyun 	__u64 context_id;		/* Context owning resources */
114*4882a593Smuzhiyun 	__u64 rsrc_handle;		/* Resource handle to release */
115*4882a593Smuzhiyun 	__u64 reserved[8];		/* Reserved for future use */
116*4882a593Smuzhiyun };
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun struct dk_cxlflash_resize {
119*4882a593Smuzhiyun 	struct dk_cxlflash_hdr hdr;	/* Common fields */
120*4882a593Smuzhiyun 	__u64 context_id;		/* Context owning resources */
121*4882a593Smuzhiyun 	__u64 rsrc_handle;		/* Resource handle of LUN to resize */
122*4882a593Smuzhiyun 	__u64 req_size;			/* New requested size, in 4K blocks */
123*4882a593Smuzhiyun 	__u64 last_lba;			/* Returned last LBA of LUN */
124*4882a593Smuzhiyun 	__u64 reserved[8];		/* Reserved for future use */
125*4882a593Smuzhiyun };
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun struct dk_cxlflash_clone {
128*4882a593Smuzhiyun 	struct dk_cxlflash_hdr hdr;	/* Common fields */
129*4882a593Smuzhiyun 	__u64 context_id_src;		/* Context to clone from */
130*4882a593Smuzhiyun 	__u64 context_id_dst;		/* Context to clone to */
131*4882a593Smuzhiyun 	__u64 adap_fd_src;		/* Source context adapter fd */
132*4882a593Smuzhiyun 	__u64 reserved[8];		/* Reserved for future use */
133*4882a593Smuzhiyun };
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun #define DK_CXLFLASH_VERIFY_SENSE_LEN	18
136*4882a593Smuzhiyun #define DK_CXLFLASH_VERIFY_HINT_SENSE	0x8000000000000000ULL
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun struct dk_cxlflash_verify {
139*4882a593Smuzhiyun 	struct dk_cxlflash_hdr hdr;	/* Common fields */
140*4882a593Smuzhiyun 	__u64 context_id;		/* Context owning resources to verify */
141*4882a593Smuzhiyun 	__u64 rsrc_handle;		/* Resource handle of LUN */
142*4882a593Smuzhiyun 	__u64 hint;			/* Reasons for verify */
143*4882a593Smuzhiyun 	__u64 last_lba;			/* Returned last LBA of device */
144*4882a593Smuzhiyun 	__u8 sense_data[DK_CXLFLASH_VERIFY_SENSE_LEN]; /* SCSI sense data */
145*4882a593Smuzhiyun 	__u8 pad[6];			/* Pad to next 8-byte boundary */
146*4882a593Smuzhiyun 	__u64 reserved[8];		/* Reserved for future use */
147*4882a593Smuzhiyun };
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun #define DK_CXLFLASH_RECOVER_AFU_CONTEXT_RESET	0x8000000000000000ULL
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun struct dk_cxlflash_recover_afu {
152*4882a593Smuzhiyun 	struct dk_cxlflash_hdr hdr;	/* Common fields */
153*4882a593Smuzhiyun 	__u64 reason;			/* Reason for recovery request */
154*4882a593Smuzhiyun 	__u64 context_id;		/* Context to recover / updated ID */
155*4882a593Smuzhiyun 	__u64 mmio_size;		/* Returned size of MMIO area */
156*4882a593Smuzhiyun 	__u64 adap_fd;			/* Returned adapter file descriptor */
157*4882a593Smuzhiyun 	__u64 reserved[8];		/* Reserved for future use */
158*4882a593Smuzhiyun };
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun #define DK_CXLFLASH_MANAGE_LUN_WWID_LEN			CXLFLASH_WWID_LEN
161*4882a593Smuzhiyun #define DK_CXLFLASH_MANAGE_LUN_ENABLE_SUPERPIPE		0x8000000000000000ULL
162*4882a593Smuzhiyun #define DK_CXLFLASH_MANAGE_LUN_DISABLE_SUPERPIPE	0x4000000000000000ULL
163*4882a593Smuzhiyun #define DK_CXLFLASH_MANAGE_LUN_ALL_PORTS_ACCESSIBLE	0x2000000000000000ULL
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun struct dk_cxlflash_manage_lun {
166*4882a593Smuzhiyun 	struct dk_cxlflash_hdr hdr;			/* Common fields */
167*4882a593Smuzhiyun 	__u8 wwid[DK_CXLFLASH_MANAGE_LUN_WWID_LEN];	/* Page83 WWID, NAA-6 */
168*4882a593Smuzhiyun 	__u64 reserved[8];				/* Rsvd, future use */
169*4882a593Smuzhiyun };
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun union cxlflash_ioctls {
172*4882a593Smuzhiyun 	struct dk_cxlflash_attach attach;
173*4882a593Smuzhiyun 	struct dk_cxlflash_detach detach;
174*4882a593Smuzhiyun 	struct dk_cxlflash_udirect udirect;
175*4882a593Smuzhiyun 	struct dk_cxlflash_uvirtual uvirtual;
176*4882a593Smuzhiyun 	struct dk_cxlflash_release release;
177*4882a593Smuzhiyun 	struct dk_cxlflash_resize resize;
178*4882a593Smuzhiyun 	struct dk_cxlflash_clone clone;
179*4882a593Smuzhiyun 	struct dk_cxlflash_verify verify;
180*4882a593Smuzhiyun 	struct dk_cxlflash_recover_afu recover_afu;
181*4882a593Smuzhiyun 	struct dk_cxlflash_manage_lun manage_lun;
182*4882a593Smuzhiyun };
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun #define MAX_CXLFLASH_IOCTL_SZ	(sizeof(union cxlflash_ioctls))
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun #define CXL_MAGIC 0xCA
187*4882a593Smuzhiyun #define CXL_IOWR(_n, _s)	_IOWR(CXL_MAGIC, _n, struct _s)
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun /*
190*4882a593Smuzhiyun  * CXL Flash superpipe ioctls start at base of the reserved CXL_MAGIC
191*4882a593Smuzhiyun  * region (0x80) and grow upwards.
192*4882a593Smuzhiyun  */
193*4882a593Smuzhiyun #define DK_CXLFLASH_ATTACH		CXL_IOWR(0x80, dk_cxlflash_attach)
194*4882a593Smuzhiyun #define DK_CXLFLASH_USER_DIRECT		CXL_IOWR(0x81, dk_cxlflash_udirect)
195*4882a593Smuzhiyun #define DK_CXLFLASH_RELEASE		CXL_IOWR(0x82, dk_cxlflash_release)
196*4882a593Smuzhiyun #define DK_CXLFLASH_DETACH		CXL_IOWR(0x83, dk_cxlflash_detach)
197*4882a593Smuzhiyun #define DK_CXLFLASH_VERIFY		CXL_IOWR(0x84, dk_cxlflash_verify)
198*4882a593Smuzhiyun #define DK_CXLFLASH_RECOVER_AFU		CXL_IOWR(0x85, dk_cxlflash_recover_afu)
199*4882a593Smuzhiyun #define DK_CXLFLASH_MANAGE_LUN		CXL_IOWR(0x86, dk_cxlflash_manage_lun)
200*4882a593Smuzhiyun #define DK_CXLFLASH_USER_VIRTUAL	CXL_IOWR(0x87, dk_cxlflash_uvirtual)
201*4882a593Smuzhiyun #define DK_CXLFLASH_VLUN_RESIZE		CXL_IOWR(0x88, dk_cxlflash_resize)
202*4882a593Smuzhiyun #define DK_CXLFLASH_VLUN_CLONE		CXL_IOWR(0x89, dk_cxlflash_clone)
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun /*
205*4882a593Smuzhiyun  * Structure and flag definitions CXL Flash host ioctls
206*4882a593Smuzhiyun  */
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun #define HT_CXLFLASH_VERSION_0  0
209*4882a593Smuzhiyun 
210*4882a593Smuzhiyun struct ht_cxlflash_hdr {
211*4882a593Smuzhiyun 	__u16 version;		/* Version data */
212*4882a593Smuzhiyun 	__u16 subcmd;		/* Sub-command */
213*4882a593Smuzhiyun 	__u16 rsvd[2];		/* Reserved for future use */
214*4882a593Smuzhiyun 	__u64 flags;		/* Input flags */
215*4882a593Smuzhiyun 	__u64 return_flags;	/* Returned flags */
216*4882a593Smuzhiyun };
217*4882a593Smuzhiyun 
218*4882a593Smuzhiyun /*
219*4882a593Smuzhiyun  * Input flag definitions available to all host ioctls
220*4882a593Smuzhiyun  *
221*4882a593Smuzhiyun  * These are grown from the bottom-up with the intention that ioctl-specific
222*4882a593Smuzhiyun  * input flag definitions would grow from the top-down, allowing the two sets
223*4882a593Smuzhiyun  * to co-exist. While not required/enforced at this time, this provides future
224*4882a593Smuzhiyun  * flexibility.
225*4882a593Smuzhiyun  */
226*4882a593Smuzhiyun #define HT_CXLFLASH_HOST_READ				0x0000000000000000ULL
227*4882a593Smuzhiyun #define HT_CXLFLASH_HOST_WRITE				0x0000000000000001ULL
228*4882a593Smuzhiyun 
229*4882a593Smuzhiyun #define HT_CXLFLASH_LUN_PROVISION_SUBCMD_CREATE_LUN	0x0001
230*4882a593Smuzhiyun #define HT_CXLFLASH_LUN_PROVISION_SUBCMD_DELETE_LUN	0x0002
231*4882a593Smuzhiyun #define HT_CXLFLASH_LUN_PROVISION_SUBCMD_QUERY_PORT	0x0003
232*4882a593Smuzhiyun 
233*4882a593Smuzhiyun struct ht_cxlflash_lun_provision {
234*4882a593Smuzhiyun 	struct ht_cxlflash_hdr hdr; /* Common fields */
235*4882a593Smuzhiyun 	__u16 port;		    /* Target port for provision request */
236*4882a593Smuzhiyun 	__u16 reserved16[3];	    /* Reserved for future use */
237*4882a593Smuzhiyun 	__u64 size;		    /* Size of LUN (4K blocks) */
238*4882a593Smuzhiyun 	__u64 lun_id;		    /* SCSI LUN ID */
239*4882a593Smuzhiyun 	__u8 wwid[CXLFLASH_WWID_LEN];/* Page83 WWID, NAA-6 */
240*4882a593Smuzhiyun 	__u64 max_num_luns;	    /* Maximum number of LUNs provisioned */
241*4882a593Smuzhiyun 	__u64 cur_num_luns;	    /* Current number of LUNs provisioned */
242*4882a593Smuzhiyun 	__u64 max_cap_port;	    /* Total capacity for port (4K blocks) */
243*4882a593Smuzhiyun 	__u64 cur_cap_port;	    /* Current capacity for port (4K blocks) */
244*4882a593Smuzhiyun 	__u64 reserved[8];	    /* Reserved for future use */
245*4882a593Smuzhiyun };
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun #define	HT_CXLFLASH_AFU_DEBUG_MAX_DATA_LEN		262144	/* 256K */
248*4882a593Smuzhiyun #define HT_CXLFLASH_AFU_DEBUG_SUBCMD_LEN		12
249*4882a593Smuzhiyun struct ht_cxlflash_afu_debug {
250*4882a593Smuzhiyun 	struct ht_cxlflash_hdr hdr; /* Common fields */
251*4882a593Smuzhiyun 	__u8 reserved8[4];	    /* Reserved for future use */
252*4882a593Smuzhiyun 	__u8 afu_subcmd[HT_CXLFLASH_AFU_DEBUG_SUBCMD_LEN]; /* AFU subcommand,
253*4882a593Smuzhiyun 							    * (pass through)
254*4882a593Smuzhiyun 							    */
255*4882a593Smuzhiyun 	__u64 data_ea;		    /* Data buffer effective address */
256*4882a593Smuzhiyun 	__u32 data_len;		    /* Data buffer length */
257*4882a593Smuzhiyun 	__u32 reserved32;	    /* Reserved for future use */
258*4882a593Smuzhiyun 	__u64 reserved[8];	    /* Reserved for future use */
259*4882a593Smuzhiyun };
260*4882a593Smuzhiyun 
261*4882a593Smuzhiyun union cxlflash_ht_ioctls {
262*4882a593Smuzhiyun 	struct ht_cxlflash_lun_provision lun_provision;
263*4882a593Smuzhiyun 	struct ht_cxlflash_afu_debug afu_debug;
264*4882a593Smuzhiyun };
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun #define MAX_HT_CXLFLASH_IOCTL_SZ	(sizeof(union cxlflash_ht_ioctls))
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun /*
269*4882a593Smuzhiyun  * CXL Flash host ioctls start at the top of the reserved CXL_MAGIC
270*4882a593Smuzhiyun  * region (0xBF) and grow downwards.
271*4882a593Smuzhiyun  */
272*4882a593Smuzhiyun #define HT_CXLFLASH_LUN_PROVISION CXL_IOWR(0xBF, ht_cxlflash_lun_provision)
273*4882a593Smuzhiyun #define HT_CXLFLASH_AFU_DEBUG	  CXL_IOWR(0xBE, ht_cxlflash_afu_debug)
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun 
276*4882a593Smuzhiyun #endif /* ifndef _CXLFLASH_IOCTL_H */
277