165be2c79SMatthew R. Ochs /*
265be2c79SMatthew R. Ochs  * CXL Flash Device Driver
365be2c79SMatthew R. Ochs  *
465be2c79SMatthew R. Ochs  * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
565be2c79SMatthew R. Ochs  *             Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
665be2c79SMatthew R. Ochs  *
765be2c79SMatthew R. Ochs  * Copyright (C) 2015 IBM Corporation
865be2c79SMatthew R. Ochs  *
965be2c79SMatthew R. Ochs  * This program is free software; you can redistribute it and/or
1065be2c79SMatthew R. Ochs  * modify it under the terms of the GNU General Public License
1165be2c79SMatthew R. Ochs  * as published by the Free Software Foundation; either version
1265be2c79SMatthew R. Ochs  * 2 of the License, or (at your option) any later version.
1365be2c79SMatthew R. Ochs  */
1465be2c79SMatthew R. Ochs 
1565be2c79SMatthew R. Ochs #ifndef _CXLFLASH_IOCTL_H
1665be2c79SMatthew R. Ochs #define _CXLFLASH_IOCTL_H
1765be2c79SMatthew R. Ochs 
1865be2c79SMatthew R. Ochs #include <linux/types.h>
1965be2c79SMatthew R. Ochs 
2065be2c79SMatthew R. Ochs /*
2165be2c79SMatthew R. Ochs  * Structure and flag definitions CXL Flash superpipe ioctls
2265be2c79SMatthew R. Ochs  */
2365be2c79SMatthew R. Ochs 
2465be2c79SMatthew R. Ochs #define DK_CXLFLASH_VERSION_0	0
2565be2c79SMatthew R. Ochs 
2665be2c79SMatthew R. Ochs struct dk_cxlflash_hdr {
2765be2c79SMatthew R. Ochs 	__u16 version;			/* Version data */
2865be2c79SMatthew R. Ochs 	__u16 rsvd[3];			/* Reserved for future use */
2965be2c79SMatthew R. Ochs 	__u64 flags;			/* Input flags */
3065be2c79SMatthew R. Ochs 	__u64 return_flags;		/* Returned flags */
3165be2c79SMatthew R. Ochs };
3265be2c79SMatthew R. Ochs 
3365be2c79SMatthew R. Ochs /*
3465be2c79SMatthew R. Ochs  * Notes:
3565be2c79SMatthew R. Ochs  * -----
3665be2c79SMatthew R. Ochs  * The 'context_id' field of all ioctl structures contains the context
3765be2c79SMatthew R. Ochs  * identifier for a context in the lower 32-bits (upper 32-bits are not
3865be2c79SMatthew R. Ochs  * to be used when identifying a context to the AFU). That said, the value
3965be2c79SMatthew R. Ochs  * in its entirety (all 64-bits) is to be treated as an opaque cookie and
4065be2c79SMatthew R. Ochs  * should be presented as such when issuing ioctls.
4165be2c79SMatthew R. Ochs  *
4265be2c79SMatthew R. Ochs  * For DK_CXLFLASH_ATTACH ioctl, user specifies read/write access
4365be2c79SMatthew R. Ochs  * permissions via the O_RDONLY, O_WRONLY, and O_RDWR flags defined in
4465be2c79SMatthew R. Ochs  * the fcntl.h header file.
4565be2c79SMatthew R. Ochs  */
4665be2c79SMatthew R. Ochs #define DK_CXLFLASH_ATTACH_REUSE_CONTEXT	0x8000000000000000ULL
4765be2c79SMatthew R. Ochs 
4865be2c79SMatthew R. Ochs struct dk_cxlflash_attach {
4965be2c79SMatthew R. Ochs 	struct dk_cxlflash_hdr hdr;	/* Common fields */
5065be2c79SMatthew R. Ochs 	__u64 num_interrupts;		/* Requested number of interrupts */
5165be2c79SMatthew R. Ochs 	__u64 context_id;		/* Returned context */
5265be2c79SMatthew R. Ochs 	__u64 mmio_size;		/* Returned size of MMIO area */
5365be2c79SMatthew R. Ochs 	__u64 block_size;		/* Returned block size, in bytes */
5465be2c79SMatthew R. Ochs 	__u64 adap_fd;			/* Returned adapter file descriptor */
5565be2c79SMatthew R. Ochs 	__u64 last_lba;			/* Returned last LBA on the device */
5665be2c79SMatthew R. Ochs 	__u64 max_xfer;			/* Returned max transfer size, blocks */
5765be2c79SMatthew R. Ochs 	__u64 reserved[8];		/* Reserved for future use */
5865be2c79SMatthew R. Ochs };
5965be2c79SMatthew R. Ochs 
6065be2c79SMatthew R. Ochs struct dk_cxlflash_detach {
6165be2c79SMatthew R. Ochs 	struct dk_cxlflash_hdr hdr;	/* Common fields */
6265be2c79SMatthew R. Ochs 	__u64 context_id;		/* Context to detach */
6365be2c79SMatthew R. Ochs 	__u64 reserved[8];		/* Reserved for future use */
6465be2c79SMatthew R. Ochs };
6565be2c79SMatthew R. Ochs 
6665be2c79SMatthew R. Ochs struct dk_cxlflash_udirect {
6765be2c79SMatthew R. Ochs 	struct dk_cxlflash_hdr hdr;	/* Common fields */
6865be2c79SMatthew R. Ochs 	__u64 context_id;		/* Context to own physical resources */
6965be2c79SMatthew R. Ochs 	__u64 rsrc_handle;		/* Returned resource handle */
7065be2c79SMatthew R. Ochs 	__u64 last_lba;			/* Returned last LBA on the device */
7165be2c79SMatthew R. Ochs 	__u64 reserved[8];		/* Reserved for future use */
7265be2c79SMatthew R. Ochs };
7365be2c79SMatthew R. Ochs 
742cb79266SMatthew R. Ochs #define DK_CXLFLASH_UVIRTUAL_NEED_WRITE_SAME	0x8000000000000000ULL
752cb79266SMatthew R. Ochs 
762cb79266SMatthew R. Ochs struct dk_cxlflash_uvirtual {
772cb79266SMatthew R. Ochs 	struct dk_cxlflash_hdr hdr;	/* Common fields */
782cb79266SMatthew R. Ochs 	__u64 context_id;		/* Context to own virtual resources */
792cb79266SMatthew R. Ochs 	__u64 lun_size;			/* Requested size, in 4K blocks */
802cb79266SMatthew R. Ochs 	__u64 rsrc_handle;		/* Returned resource handle */
812cb79266SMatthew R. Ochs 	__u64 last_lba;			/* Returned last LBA of LUN */
822cb79266SMatthew R. Ochs 	__u64 reserved[8];		/* Reserved for future use */
832cb79266SMatthew R. Ochs };
842cb79266SMatthew R. Ochs 
8565be2c79SMatthew R. Ochs struct dk_cxlflash_release {
8665be2c79SMatthew R. Ochs 	struct dk_cxlflash_hdr hdr;	/* Common fields */
8765be2c79SMatthew R. Ochs 	__u64 context_id;		/* Context owning resources */
8865be2c79SMatthew R. Ochs 	__u64 rsrc_handle;		/* Resource handle to release */
8965be2c79SMatthew R. Ochs 	__u64 reserved[8];		/* Reserved for future use */
9065be2c79SMatthew R. Ochs };
9165be2c79SMatthew R. Ochs 
922cb79266SMatthew R. Ochs struct dk_cxlflash_resize {
932cb79266SMatthew R. Ochs 	struct dk_cxlflash_hdr hdr;	/* Common fields */
942cb79266SMatthew R. Ochs 	__u64 context_id;		/* Context owning resources */
952cb79266SMatthew R. Ochs 	__u64 rsrc_handle;		/* Resource handle of LUN to resize */
962cb79266SMatthew R. Ochs 	__u64 req_size;			/* New requested size, in 4K blocks */
972cb79266SMatthew R. Ochs 	__u64 last_lba;			/* Returned last LBA of LUN */
982cb79266SMatthew R. Ochs 	__u64 reserved[8];		/* Reserved for future use */
992cb79266SMatthew R. Ochs };
1002cb79266SMatthew R. Ochs 
1012cb79266SMatthew R. Ochs struct dk_cxlflash_clone {
1022cb79266SMatthew R. Ochs 	struct dk_cxlflash_hdr hdr;	/* Common fields */
1032cb79266SMatthew R. Ochs 	__u64 context_id_src;		/* Context to clone from */
1042cb79266SMatthew R. Ochs 	__u64 context_id_dst;		/* Context to clone to */
1052cb79266SMatthew R. Ochs 	__u64 adap_fd_src;		/* Source context adapter fd */
1062cb79266SMatthew R. Ochs 	__u64 reserved[8];		/* Reserved for future use */
1072cb79266SMatthew R. Ochs };
1082cb79266SMatthew R. Ochs 
10965be2c79SMatthew R. Ochs #define DK_CXLFLASH_VERIFY_SENSE_LEN	18
11065be2c79SMatthew R. Ochs #define DK_CXLFLASH_VERIFY_HINT_SENSE	0x8000000000000000ULL
11165be2c79SMatthew R. Ochs 
11265be2c79SMatthew R. Ochs struct dk_cxlflash_verify {
11365be2c79SMatthew R. Ochs 	struct dk_cxlflash_hdr hdr;	/* Common fields */
11465be2c79SMatthew R. Ochs 	__u64 context_id;		/* Context owning resources to verify */
11565be2c79SMatthew R. Ochs 	__u64 rsrc_handle;		/* Resource handle of LUN */
11665be2c79SMatthew R. Ochs 	__u64 hint;			/* Reasons for verify */
11765be2c79SMatthew R. Ochs 	__u64 last_lba;			/* Returned last LBA of device */
11865be2c79SMatthew R. Ochs 	__u8 sense_data[DK_CXLFLASH_VERIFY_SENSE_LEN]; /* SCSI sense data */
11965be2c79SMatthew R. Ochs 	__u8 pad[6];			/* Pad to next 8-byte boundary */
12065be2c79SMatthew R. Ochs 	__u64 reserved[8];		/* Reserved for future use */
12165be2c79SMatthew R. Ochs };
12265be2c79SMatthew R. Ochs 
12365be2c79SMatthew R. Ochs #define DK_CXLFLASH_RECOVER_AFU_CONTEXT_RESET	0x8000000000000000ULL
12465be2c79SMatthew R. Ochs 
12565be2c79SMatthew R. Ochs struct dk_cxlflash_recover_afu {
12665be2c79SMatthew R. Ochs 	struct dk_cxlflash_hdr hdr;	/* Common fields */
12765be2c79SMatthew R. Ochs 	__u64 reason;			/* Reason for recovery request */
12865be2c79SMatthew R. Ochs 	__u64 context_id;		/* Context to recover / updated ID */
12965be2c79SMatthew R. Ochs 	__u64 mmio_size;		/* Returned size of MMIO area */
13065be2c79SMatthew R. Ochs 	__u64 adap_fd;			/* Returned adapter file descriptor */
13165be2c79SMatthew R. Ochs 	__u64 reserved[8];		/* Reserved for future use */
13265be2c79SMatthew R. Ochs };
13365be2c79SMatthew R. Ochs 
13465be2c79SMatthew R. Ochs #define DK_CXLFLASH_MANAGE_LUN_WWID_LEN			16
13565be2c79SMatthew R. Ochs #define DK_CXLFLASH_MANAGE_LUN_ENABLE_SUPERPIPE		0x8000000000000000ULL
13665be2c79SMatthew R. Ochs #define DK_CXLFLASH_MANAGE_LUN_DISABLE_SUPERPIPE	0x4000000000000000ULL
13765be2c79SMatthew R. Ochs #define DK_CXLFLASH_MANAGE_LUN_ALL_PORTS_ACCESSIBLE	0x2000000000000000ULL
13865be2c79SMatthew R. Ochs 
13965be2c79SMatthew R. Ochs struct dk_cxlflash_manage_lun {
14065be2c79SMatthew R. Ochs 	struct dk_cxlflash_hdr hdr;			/* Common fields */
14165be2c79SMatthew R. Ochs 	__u8 wwid[DK_CXLFLASH_MANAGE_LUN_WWID_LEN];	/* Page83 WWID, NAA-6 */
14265be2c79SMatthew R. Ochs 	__u64 reserved[8];				/* Rsvd, future use */
14365be2c79SMatthew R. Ochs };
14465be2c79SMatthew R. Ochs 
14565be2c79SMatthew R. Ochs union cxlflash_ioctls {
14665be2c79SMatthew R. Ochs 	struct dk_cxlflash_attach attach;
14765be2c79SMatthew R. Ochs 	struct dk_cxlflash_detach detach;
14865be2c79SMatthew R. Ochs 	struct dk_cxlflash_udirect udirect;
1492cb79266SMatthew R. Ochs 	struct dk_cxlflash_uvirtual uvirtual;
15065be2c79SMatthew R. Ochs 	struct dk_cxlflash_release release;
1512cb79266SMatthew R. Ochs 	struct dk_cxlflash_resize resize;
1522cb79266SMatthew R. Ochs 	struct dk_cxlflash_clone clone;
15365be2c79SMatthew R. Ochs 	struct dk_cxlflash_verify verify;
15465be2c79SMatthew R. Ochs 	struct dk_cxlflash_recover_afu recover_afu;
15565be2c79SMatthew R. Ochs 	struct dk_cxlflash_manage_lun manage_lun;
15665be2c79SMatthew R. Ochs };
15765be2c79SMatthew R. Ochs 
15865be2c79SMatthew R. Ochs #define MAX_CXLFLASH_IOCTL_SZ	(sizeof(union cxlflash_ioctls))
15965be2c79SMatthew R. Ochs 
16065be2c79SMatthew R. Ochs #define CXL_MAGIC 0xCA
16165be2c79SMatthew R. Ochs #define CXL_IOWR(_n, _s)	_IOWR(CXL_MAGIC, _n, struct _s)
16265be2c79SMatthew R. Ochs 
16365be2c79SMatthew R. Ochs #define DK_CXLFLASH_ATTACH		CXL_IOWR(0x80, dk_cxlflash_attach)
16465be2c79SMatthew R. Ochs #define DK_CXLFLASH_USER_DIRECT		CXL_IOWR(0x81, dk_cxlflash_udirect)
16565be2c79SMatthew R. Ochs #define DK_CXLFLASH_RELEASE		CXL_IOWR(0x82, dk_cxlflash_release)
16665be2c79SMatthew R. Ochs #define DK_CXLFLASH_DETACH		CXL_IOWR(0x83, dk_cxlflash_detach)
16765be2c79SMatthew R. Ochs #define DK_CXLFLASH_VERIFY		CXL_IOWR(0x84, dk_cxlflash_verify)
16865be2c79SMatthew R. Ochs #define DK_CXLFLASH_RECOVER_AFU		CXL_IOWR(0x85, dk_cxlflash_recover_afu)
16965be2c79SMatthew R. Ochs #define DK_CXLFLASH_MANAGE_LUN		CXL_IOWR(0x86, dk_cxlflash_manage_lun)
1702cb79266SMatthew R. Ochs #define DK_CXLFLASH_USER_VIRTUAL	CXL_IOWR(0x87, dk_cxlflash_uvirtual)
1712cb79266SMatthew R. Ochs #define DK_CXLFLASH_VLUN_RESIZE		CXL_IOWR(0x88, dk_cxlflash_resize)
1722cb79266SMatthew R. Ochs #define DK_CXLFLASH_VLUN_CLONE		CXL_IOWR(0x89, dk_cxlflash_clone)
17365be2c79SMatthew R. Ochs 
17465be2c79SMatthew R. Ochs #endif /* ifndef _CXLFLASH_IOCTL_H */
175