1*e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ 265be2c79SMatthew R. Ochs /* 365be2c79SMatthew R. Ochs * CXL Flash Device Driver 465be2c79SMatthew R. Ochs * 565be2c79SMatthew R. Ochs * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation 665be2c79SMatthew R. Ochs * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation 765be2c79SMatthew R. Ochs * 865be2c79SMatthew R. Ochs * Copyright (C) 2015 IBM Corporation 965be2c79SMatthew R. Ochs * 1065be2c79SMatthew R. Ochs * This program is free software; you can redistribute it and/or 1165be2c79SMatthew R. Ochs * modify it under the terms of the GNU General Public License 1265be2c79SMatthew R. Ochs * as published by the Free Software Foundation; either version 1365be2c79SMatthew R. Ochs * 2 of the License, or (at your option) any later version. 1465be2c79SMatthew R. Ochs */ 1565be2c79SMatthew R. Ochs 1665be2c79SMatthew R. Ochs #ifndef _CXLFLASH_IOCTL_H 1765be2c79SMatthew R. Ochs #define _CXLFLASH_IOCTL_H 1865be2c79SMatthew R. Ochs 1965be2c79SMatthew R. Ochs #include <linux/types.h> 2065be2c79SMatthew R. Ochs 2165be2c79SMatthew R. Ochs /* 22bc88ac47SMatthew R. Ochs * Structure and definitions for all CXL Flash ioctls 23bc88ac47SMatthew R. Ochs */ 24bc88ac47SMatthew R. Ochs #define CXLFLASH_WWID_LEN 16 25bc88ac47SMatthew R. Ochs 26bc88ac47SMatthew R. Ochs /* 2765be2c79SMatthew R. Ochs * Structure and flag definitions CXL Flash superpipe ioctls 2865be2c79SMatthew R. Ochs */ 2965be2c79SMatthew R. Ochs 3065be2c79SMatthew R. Ochs #define DK_CXLFLASH_VERSION_0 0 3165be2c79SMatthew R. Ochs 3265be2c79SMatthew R. Ochs struct dk_cxlflash_hdr { 3365be2c79SMatthew R. Ochs __u16 version; /* Version data */ 3465be2c79SMatthew R. Ochs __u16 rsvd[3]; /* Reserved for future use */ 3565be2c79SMatthew R. Ochs __u64 flags; /* Input flags */ 3665be2c79SMatthew R. Ochs __u64 return_flags; /* Returned flags */ 3765be2c79SMatthew R. Ochs }; 3865be2c79SMatthew R. Ochs 3965be2c79SMatthew R. Ochs /* 40d6e32f53SMatthew R. Ochs * Return flag definitions available to all superpipe ioctls 41d5e26bb1SMatthew R. Ochs * 42d5e26bb1SMatthew R. Ochs * Similar to the input flags, these are grown from the bottom-up with the 43d5e26bb1SMatthew R. Ochs * intention that ioctl-specific return flag definitions would grow from the 44d5e26bb1SMatthew R. Ochs * top-down, allowing the two sets to co-exist. While not required/enforced 45d5e26bb1SMatthew R. Ochs * at this time, this provides future flexibility. 46d5e26bb1SMatthew R. Ochs */ 47d5e26bb1SMatthew R. Ochs #define DK_CXLFLASH_ALL_PORTS_ACTIVE 0x0000000000000001ULL 48cd34af40SMatthew R. Ochs #define DK_CXLFLASH_APP_CLOSE_ADAP_FD 0x0000000000000002ULL 49696d0b0cSMatthew R. Ochs #define DK_CXLFLASH_CONTEXT_SQ_CMD_MODE 0x0000000000000004ULL 50d5e26bb1SMatthew R. Ochs 51d5e26bb1SMatthew R. Ochs /* 52cd34af40SMatthew R. Ochs * General Notes: 53cd34af40SMatthew R. Ochs * ------------- 5465be2c79SMatthew R. Ochs * The 'context_id' field of all ioctl structures contains the context 5565be2c79SMatthew R. Ochs * identifier for a context in the lower 32-bits (upper 32-bits are not 5665be2c79SMatthew R. Ochs * to be used when identifying a context to the AFU). That said, the value 5765be2c79SMatthew R. Ochs * in its entirety (all 64-bits) is to be treated as an opaque cookie and 5865be2c79SMatthew R. Ochs * should be presented as such when issuing ioctls. 59cd34af40SMatthew R. Ochs */ 60cd34af40SMatthew R. Ochs 61cd34af40SMatthew R. Ochs /* 62cd34af40SMatthew R. Ochs * DK_CXLFLASH_ATTACH Notes: 63cd34af40SMatthew R. Ochs * ------------------------ 64cd34af40SMatthew R. Ochs * Read/write access permissions are specified via the O_RDONLY, O_WRONLY, 65cd34af40SMatthew R. Ochs * and O_RDWR flags defined in the fcntl.h header file. 6665be2c79SMatthew R. Ochs * 67cd34af40SMatthew R. Ochs * A valid adapter file descriptor (fd >= 0) is only returned on the initial 68cd34af40SMatthew R. Ochs * attach (successful) of a context. When a context is shared(reused), the user 69cd34af40SMatthew R. Ochs * is expected to already 'know' the adapter file descriptor associated with the 70cd34af40SMatthew R. Ochs * context. 7165be2c79SMatthew R. Ochs */ 7265be2c79SMatthew R. Ochs #define DK_CXLFLASH_ATTACH_REUSE_CONTEXT 0x8000000000000000ULL 7365be2c79SMatthew R. Ochs 7465be2c79SMatthew R. Ochs struct dk_cxlflash_attach { 7565be2c79SMatthew R. Ochs struct dk_cxlflash_hdr hdr; /* Common fields */ 7665be2c79SMatthew R. Ochs __u64 num_interrupts; /* Requested number of interrupts */ 7765be2c79SMatthew R. Ochs __u64 context_id; /* Returned context */ 7865be2c79SMatthew R. Ochs __u64 mmio_size; /* Returned size of MMIO area */ 7965be2c79SMatthew R. Ochs __u64 block_size; /* Returned block size, in bytes */ 8065be2c79SMatthew R. Ochs __u64 adap_fd; /* Returned adapter file descriptor */ 8165be2c79SMatthew R. Ochs __u64 last_lba; /* Returned last LBA on the device */ 8265be2c79SMatthew R. Ochs __u64 max_xfer; /* Returned max transfer size, blocks */ 8365be2c79SMatthew R. Ochs __u64 reserved[8]; /* Reserved for future use */ 8465be2c79SMatthew R. Ochs }; 8565be2c79SMatthew R. Ochs 8665be2c79SMatthew R. Ochs struct dk_cxlflash_detach { 8765be2c79SMatthew R. Ochs struct dk_cxlflash_hdr hdr; /* Common fields */ 8865be2c79SMatthew R. Ochs __u64 context_id; /* Context to detach */ 8965be2c79SMatthew R. Ochs __u64 reserved[8]; /* Reserved for future use */ 9065be2c79SMatthew R. Ochs }; 9165be2c79SMatthew R. Ochs 9265be2c79SMatthew R. Ochs struct dk_cxlflash_udirect { 9365be2c79SMatthew R. Ochs struct dk_cxlflash_hdr hdr; /* Common fields */ 9465be2c79SMatthew R. Ochs __u64 context_id; /* Context to own physical resources */ 9565be2c79SMatthew R. Ochs __u64 rsrc_handle; /* Returned resource handle */ 9665be2c79SMatthew R. Ochs __u64 last_lba; /* Returned last LBA on the device */ 9765be2c79SMatthew R. Ochs __u64 reserved[8]; /* Reserved for future use */ 9865be2c79SMatthew R. Ochs }; 9965be2c79SMatthew R. Ochs 1002cb79266SMatthew R. Ochs #define DK_CXLFLASH_UVIRTUAL_NEED_WRITE_SAME 0x8000000000000000ULL 1012cb79266SMatthew R. Ochs 1022cb79266SMatthew R. Ochs struct dk_cxlflash_uvirtual { 1032cb79266SMatthew R. Ochs struct dk_cxlflash_hdr hdr; /* Common fields */ 1042cb79266SMatthew R. Ochs __u64 context_id; /* Context to own virtual resources */ 1052cb79266SMatthew R. Ochs __u64 lun_size; /* Requested size, in 4K blocks */ 1062cb79266SMatthew R. Ochs __u64 rsrc_handle; /* Returned resource handle */ 1072cb79266SMatthew R. Ochs __u64 last_lba; /* Returned last LBA of LUN */ 1082cb79266SMatthew R. Ochs __u64 reserved[8]; /* Reserved for future use */ 1092cb79266SMatthew R. Ochs }; 1102cb79266SMatthew R. Ochs 11165be2c79SMatthew R. Ochs struct dk_cxlflash_release { 11265be2c79SMatthew R. Ochs struct dk_cxlflash_hdr hdr; /* Common fields */ 11365be2c79SMatthew R. Ochs __u64 context_id; /* Context owning resources */ 11465be2c79SMatthew R. Ochs __u64 rsrc_handle; /* Resource handle to release */ 11565be2c79SMatthew R. Ochs __u64 reserved[8]; /* Reserved for future use */ 11665be2c79SMatthew R. Ochs }; 11765be2c79SMatthew R. Ochs 1182cb79266SMatthew R. Ochs struct dk_cxlflash_resize { 1192cb79266SMatthew R. Ochs struct dk_cxlflash_hdr hdr; /* Common fields */ 1202cb79266SMatthew R. Ochs __u64 context_id; /* Context owning resources */ 1212cb79266SMatthew R. Ochs __u64 rsrc_handle; /* Resource handle of LUN to resize */ 1222cb79266SMatthew R. Ochs __u64 req_size; /* New requested size, in 4K blocks */ 1232cb79266SMatthew R. Ochs __u64 last_lba; /* Returned last LBA of LUN */ 1242cb79266SMatthew R. Ochs __u64 reserved[8]; /* Reserved for future use */ 1252cb79266SMatthew R. Ochs }; 1262cb79266SMatthew R. Ochs 1272cb79266SMatthew R. Ochs struct dk_cxlflash_clone { 1282cb79266SMatthew R. Ochs struct dk_cxlflash_hdr hdr; /* Common fields */ 1292cb79266SMatthew R. Ochs __u64 context_id_src; /* Context to clone from */ 1302cb79266SMatthew R. Ochs __u64 context_id_dst; /* Context to clone to */ 1312cb79266SMatthew R. Ochs __u64 adap_fd_src; /* Source context adapter fd */ 1322cb79266SMatthew R. Ochs __u64 reserved[8]; /* Reserved for future use */ 1332cb79266SMatthew R. Ochs }; 1342cb79266SMatthew R. Ochs 13565be2c79SMatthew R. Ochs #define DK_CXLFLASH_VERIFY_SENSE_LEN 18 13665be2c79SMatthew R. Ochs #define DK_CXLFLASH_VERIFY_HINT_SENSE 0x8000000000000000ULL 13765be2c79SMatthew R. Ochs 13865be2c79SMatthew R. Ochs struct dk_cxlflash_verify { 13965be2c79SMatthew R. Ochs struct dk_cxlflash_hdr hdr; /* Common fields */ 14065be2c79SMatthew R. Ochs __u64 context_id; /* Context owning resources to verify */ 14165be2c79SMatthew R. Ochs __u64 rsrc_handle; /* Resource handle of LUN */ 14265be2c79SMatthew R. Ochs __u64 hint; /* Reasons for verify */ 14365be2c79SMatthew R. Ochs __u64 last_lba; /* Returned last LBA of device */ 14465be2c79SMatthew R. Ochs __u8 sense_data[DK_CXLFLASH_VERIFY_SENSE_LEN]; /* SCSI sense data */ 14565be2c79SMatthew R. Ochs __u8 pad[6]; /* Pad to next 8-byte boundary */ 14665be2c79SMatthew R. Ochs __u64 reserved[8]; /* Reserved for future use */ 14765be2c79SMatthew R. Ochs }; 14865be2c79SMatthew R. Ochs 14965be2c79SMatthew R. Ochs #define DK_CXLFLASH_RECOVER_AFU_CONTEXT_RESET 0x8000000000000000ULL 15065be2c79SMatthew R. Ochs 15165be2c79SMatthew R. Ochs struct dk_cxlflash_recover_afu { 15265be2c79SMatthew R. Ochs struct dk_cxlflash_hdr hdr; /* Common fields */ 15365be2c79SMatthew R. Ochs __u64 reason; /* Reason for recovery request */ 15465be2c79SMatthew R. Ochs __u64 context_id; /* Context to recover / updated ID */ 15565be2c79SMatthew R. Ochs __u64 mmio_size; /* Returned size of MMIO area */ 15665be2c79SMatthew R. Ochs __u64 adap_fd; /* Returned adapter file descriptor */ 15765be2c79SMatthew R. Ochs __u64 reserved[8]; /* Reserved for future use */ 15865be2c79SMatthew R. Ochs }; 15965be2c79SMatthew R. Ochs 160bc88ac47SMatthew R. Ochs #define DK_CXLFLASH_MANAGE_LUN_WWID_LEN CXLFLASH_WWID_LEN 16165be2c79SMatthew R. Ochs #define DK_CXLFLASH_MANAGE_LUN_ENABLE_SUPERPIPE 0x8000000000000000ULL 16265be2c79SMatthew R. Ochs #define DK_CXLFLASH_MANAGE_LUN_DISABLE_SUPERPIPE 0x4000000000000000ULL 16365be2c79SMatthew R. Ochs #define DK_CXLFLASH_MANAGE_LUN_ALL_PORTS_ACCESSIBLE 0x2000000000000000ULL 16465be2c79SMatthew R. Ochs 16565be2c79SMatthew R. Ochs struct dk_cxlflash_manage_lun { 16665be2c79SMatthew R. Ochs struct dk_cxlflash_hdr hdr; /* Common fields */ 16765be2c79SMatthew R. Ochs __u8 wwid[DK_CXLFLASH_MANAGE_LUN_WWID_LEN]; /* Page83 WWID, NAA-6 */ 16865be2c79SMatthew R. Ochs __u64 reserved[8]; /* Rsvd, future use */ 16965be2c79SMatthew R. Ochs }; 17065be2c79SMatthew R. Ochs 17165be2c79SMatthew R. Ochs union cxlflash_ioctls { 17265be2c79SMatthew R. Ochs struct dk_cxlflash_attach attach; 17365be2c79SMatthew R. Ochs struct dk_cxlflash_detach detach; 17465be2c79SMatthew R. Ochs struct dk_cxlflash_udirect udirect; 1752cb79266SMatthew R. Ochs struct dk_cxlflash_uvirtual uvirtual; 17665be2c79SMatthew R. Ochs struct dk_cxlflash_release release; 1772cb79266SMatthew R. Ochs struct dk_cxlflash_resize resize; 1782cb79266SMatthew R. Ochs struct dk_cxlflash_clone clone; 17965be2c79SMatthew R. Ochs struct dk_cxlflash_verify verify; 18065be2c79SMatthew R. Ochs struct dk_cxlflash_recover_afu recover_afu; 18165be2c79SMatthew R. Ochs struct dk_cxlflash_manage_lun manage_lun; 18265be2c79SMatthew R. Ochs }; 18365be2c79SMatthew R. Ochs 18465be2c79SMatthew R. Ochs #define MAX_CXLFLASH_IOCTL_SZ (sizeof(union cxlflash_ioctls)) 18565be2c79SMatthew R. Ochs 18665be2c79SMatthew R. Ochs #define CXL_MAGIC 0xCA 18765be2c79SMatthew R. Ochs #define CXL_IOWR(_n, _s) _IOWR(CXL_MAGIC, _n, struct _s) 18865be2c79SMatthew R. Ochs 189d6e32f53SMatthew R. Ochs /* 190d6e32f53SMatthew R. Ochs * CXL Flash superpipe ioctls start at base of the reserved CXL_MAGIC 191d6e32f53SMatthew R. Ochs * region (0x80) and grow upwards. 192d6e32f53SMatthew R. Ochs */ 19365be2c79SMatthew R. Ochs #define DK_CXLFLASH_ATTACH CXL_IOWR(0x80, dk_cxlflash_attach) 19465be2c79SMatthew R. Ochs #define DK_CXLFLASH_USER_DIRECT CXL_IOWR(0x81, dk_cxlflash_udirect) 19565be2c79SMatthew R. Ochs #define DK_CXLFLASH_RELEASE CXL_IOWR(0x82, dk_cxlflash_release) 19665be2c79SMatthew R. Ochs #define DK_CXLFLASH_DETACH CXL_IOWR(0x83, dk_cxlflash_detach) 19765be2c79SMatthew R. Ochs #define DK_CXLFLASH_VERIFY CXL_IOWR(0x84, dk_cxlflash_verify) 19865be2c79SMatthew R. Ochs #define DK_CXLFLASH_RECOVER_AFU CXL_IOWR(0x85, dk_cxlflash_recover_afu) 19965be2c79SMatthew R. Ochs #define DK_CXLFLASH_MANAGE_LUN CXL_IOWR(0x86, dk_cxlflash_manage_lun) 2002cb79266SMatthew R. Ochs #define DK_CXLFLASH_USER_VIRTUAL CXL_IOWR(0x87, dk_cxlflash_uvirtual) 2012cb79266SMatthew R. Ochs #define DK_CXLFLASH_VLUN_RESIZE CXL_IOWR(0x88, dk_cxlflash_resize) 2022cb79266SMatthew R. Ochs #define DK_CXLFLASH_VLUN_CLONE CXL_IOWR(0x89, dk_cxlflash_clone) 20365be2c79SMatthew R. Ochs 204d6e32f53SMatthew R. Ochs /* 205d6e32f53SMatthew R. Ochs * Structure and flag definitions CXL Flash host ioctls 206d6e32f53SMatthew R. Ochs */ 207d6e32f53SMatthew R. Ochs 208d6e32f53SMatthew R. Ochs #define HT_CXLFLASH_VERSION_0 0 209d6e32f53SMatthew R. Ochs 210d6e32f53SMatthew R. Ochs struct ht_cxlflash_hdr { 211d6e32f53SMatthew R. Ochs __u16 version; /* Version data */ 212d6e32f53SMatthew R. Ochs __u16 subcmd; /* Sub-command */ 213d6e32f53SMatthew R. Ochs __u16 rsvd[2]; /* Reserved for future use */ 214d6e32f53SMatthew R. Ochs __u64 flags; /* Input flags */ 215d6e32f53SMatthew R. Ochs __u64 return_flags; /* Returned flags */ 216d6e32f53SMatthew R. Ochs }; 217d6e32f53SMatthew R. Ochs 218bc88ac47SMatthew R. Ochs /* 219bc88ac47SMatthew R. Ochs * Input flag definitions available to all host ioctls 220bc88ac47SMatthew R. Ochs * 221bc88ac47SMatthew R. Ochs * These are grown from the bottom-up with the intention that ioctl-specific 222bc88ac47SMatthew R. Ochs * input flag definitions would grow from the top-down, allowing the two sets 223bc88ac47SMatthew R. Ochs * to co-exist. While not required/enforced at this time, this provides future 224bc88ac47SMatthew R. Ochs * flexibility. 225bc88ac47SMatthew R. Ochs */ 226bc88ac47SMatthew R. Ochs #define HT_CXLFLASH_HOST_READ 0x0000000000000000ULL 227bc88ac47SMatthew R. Ochs #define HT_CXLFLASH_HOST_WRITE 0x0000000000000001ULL 228bc88ac47SMatthew R. Ochs 2299cf43a36SMatthew R. Ochs #define HT_CXLFLASH_LUN_PROVISION_SUBCMD_CREATE_LUN 0x0001 2309cf43a36SMatthew R. Ochs #define HT_CXLFLASH_LUN_PROVISION_SUBCMD_DELETE_LUN 0x0002 2319cf43a36SMatthew R. Ochs #define HT_CXLFLASH_LUN_PROVISION_SUBCMD_QUERY_PORT 0x0003 2329cf43a36SMatthew R. Ochs 2339cf43a36SMatthew R. Ochs struct ht_cxlflash_lun_provision { 2349cf43a36SMatthew R. Ochs struct ht_cxlflash_hdr hdr; /* Common fields */ 2359cf43a36SMatthew R. Ochs __u16 port; /* Target port for provision request */ 2369cf43a36SMatthew R. Ochs __u16 reserved16[3]; /* Reserved for future use */ 2379cf43a36SMatthew R. Ochs __u64 size; /* Size of LUN (4K blocks) */ 2389cf43a36SMatthew R. Ochs __u64 lun_id; /* SCSI LUN ID */ 239bc88ac47SMatthew R. Ochs __u8 wwid[CXLFLASH_WWID_LEN];/* Page83 WWID, NAA-6 */ 2409cf43a36SMatthew R. Ochs __u64 max_num_luns; /* Maximum number of LUNs provisioned */ 2419cf43a36SMatthew R. Ochs __u64 cur_num_luns; /* Current number of LUNs provisioned */ 2429cf43a36SMatthew R. Ochs __u64 max_cap_port; /* Total capacity for port (4K blocks) */ 2439cf43a36SMatthew R. Ochs __u64 cur_cap_port; /* Current capacity for port (4K blocks) */ 2449cf43a36SMatthew R. Ochs __u64 reserved[8]; /* Reserved for future use */ 2459cf43a36SMatthew R. Ochs }; 2469cf43a36SMatthew R. Ochs 247bc88ac47SMatthew R. Ochs #define HT_CXLFLASH_AFU_DEBUG_MAX_DATA_LEN 262144 /* 256K */ 248bc88ac47SMatthew R. Ochs #define HT_CXLFLASH_AFU_DEBUG_SUBCMD_LEN 12 249bc88ac47SMatthew R. Ochs struct ht_cxlflash_afu_debug { 250bc88ac47SMatthew R. Ochs struct ht_cxlflash_hdr hdr; /* Common fields */ 251bc88ac47SMatthew R. Ochs __u8 reserved8[4]; /* Reserved for future use */ 252bc88ac47SMatthew R. Ochs __u8 afu_subcmd[HT_CXLFLASH_AFU_DEBUG_SUBCMD_LEN]; /* AFU subcommand, 253bc88ac47SMatthew R. Ochs * (pass through) 254bc88ac47SMatthew R. Ochs */ 255bc88ac47SMatthew R. Ochs __u64 data_ea; /* Data buffer effective address */ 256bc88ac47SMatthew R. Ochs __u32 data_len; /* Data buffer length */ 257bc88ac47SMatthew R. Ochs __u32 reserved32; /* Reserved for future use */ 258bc88ac47SMatthew R. Ochs __u64 reserved[8]; /* Reserved for future use */ 259bc88ac47SMatthew R. Ochs }; 260bc88ac47SMatthew R. Ochs 261d6e32f53SMatthew R. Ochs union cxlflash_ht_ioctls { 2629cf43a36SMatthew R. Ochs struct ht_cxlflash_lun_provision lun_provision; 263bc88ac47SMatthew R. Ochs struct ht_cxlflash_afu_debug afu_debug; 264d6e32f53SMatthew R. Ochs }; 265d6e32f53SMatthew R. Ochs 266d6e32f53SMatthew R. Ochs #define MAX_HT_CXLFLASH_IOCTL_SZ (sizeof(union cxlflash_ht_ioctls)) 267d6e32f53SMatthew R. Ochs 268d6e32f53SMatthew R. Ochs /* 269d6e32f53SMatthew R. Ochs * CXL Flash host ioctls start at the top of the reserved CXL_MAGIC 270d6e32f53SMatthew R. Ochs * region (0xBF) and grow downwards. 271d6e32f53SMatthew R. Ochs */ 2729cf43a36SMatthew R. Ochs #define HT_CXLFLASH_LUN_PROVISION CXL_IOWR(0xBF, ht_cxlflash_lun_provision) 273bc88ac47SMatthew R. Ochs #define HT_CXLFLASH_AFU_DEBUG CXL_IOWR(0xBE, ht_cxlflash_afu_debug) 274d6e32f53SMatthew R. Ochs 275d6e32f53SMatthew R. Ochs 27665be2c79SMatthew R. Ochs #endif /* ifndef _CXLFLASH_IOCTL_H */ 277