1 /* 2 * CXL Flash Device Driver 3 * 4 * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation 5 * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation 6 * 7 * Copyright (C) 2015 IBM Corporation 8 * 9 * This program is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU General Public License 11 * as published by the Free Software Foundation; either version 12 * 2 of the License, or (at your option) any later version. 13 */ 14 15 #ifndef _CXLFLASH_IOCTL_H 16 #define _CXLFLASH_IOCTL_H 17 18 #include <linux/types.h> 19 20 /* 21 * Structure and flag definitions CXL Flash superpipe ioctls 22 */ 23 24 #define DK_CXLFLASH_VERSION_0 0 25 26 struct dk_cxlflash_hdr { 27 __u16 version; /* Version data */ 28 __u16 rsvd[3]; /* Reserved for future use */ 29 __u64 flags; /* Input flags */ 30 __u64 return_flags; /* Returned flags */ 31 }; 32 33 /* 34 * Return flag definitions available to all ioctls 35 * 36 * Similar to the input flags, these are grown from the bottom-up with the 37 * intention that ioctl-specific return flag definitions would grow from the 38 * top-down, allowing the two sets to co-exist. While not required/enforced 39 * at this time, this provides future flexibility. 40 */ 41 #define DK_CXLFLASH_ALL_PORTS_ACTIVE 0x0000000000000001ULL 42 #define DK_CXLFLASH_APP_CLOSE_ADAP_FD 0x0000000000000002ULL 43 #define DK_CXLFLASH_CONTEXT_SQ_CMD_MODE 0x0000000000000004ULL 44 45 /* 46 * General Notes: 47 * ------------- 48 * The 'context_id' field of all ioctl structures contains the context 49 * identifier for a context in the lower 32-bits (upper 32-bits are not 50 * to be used when identifying a context to the AFU). That said, the value 51 * in its entirety (all 64-bits) is to be treated as an opaque cookie and 52 * should be presented as such when issuing ioctls. 53 */ 54 55 /* 56 * DK_CXLFLASH_ATTACH Notes: 57 * ------------------------ 58 * Read/write access permissions are specified via the O_RDONLY, O_WRONLY, 59 * and O_RDWR flags defined in the fcntl.h header file. 60 * 61 * A valid adapter file descriptor (fd >= 0) is only returned on the initial 62 * attach (successful) of a context. When a context is shared(reused), the user 63 * is expected to already 'know' the adapter file descriptor associated with the 64 * context. 65 */ 66 #define DK_CXLFLASH_ATTACH_REUSE_CONTEXT 0x8000000000000000ULL 67 68 struct dk_cxlflash_attach { 69 struct dk_cxlflash_hdr hdr; /* Common fields */ 70 __u64 num_interrupts; /* Requested number of interrupts */ 71 __u64 context_id; /* Returned context */ 72 __u64 mmio_size; /* Returned size of MMIO area */ 73 __u64 block_size; /* Returned block size, in bytes */ 74 __u64 adap_fd; /* Returned adapter file descriptor */ 75 __u64 last_lba; /* Returned last LBA on the device */ 76 __u64 max_xfer; /* Returned max transfer size, blocks */ 77 __u64 reserved[8]; /* Reserved for future use */ 78 }; 79 80 struct dk_cxlflash_detach { 81 struct dk_cxlflash_hdr hdr; /* Common fields */ 82 __u64 context_id; /* Context to detach */ 83 __u64 reserved[8]; /* Reserved for future use */ 84 }; 85 86 struct dk_cxlflash_udirect { 87 struct dk_cxlflash_hdr hdr; /* Common fields */ 88 __u64 context_id; /* Context to own physical resources */ 89 __u64 rsrc_handle; /* Returned resource handle */ 90 __u64 last_lba; /* Returned last LBA on the device */ 91 __u64 reserved[8]; /* Reserved for future use */ 92 }; 93 94 #define DK_CXLFLASH_UVIRTUAL_NEED_WRITE_SAME 0x8000000000000000ULL 95 96 struct dk_cxlflash_uvirtual { 97 struct dk_cxlflash_hdr hdr; /* Common fields */ 98 __u64 context_id; /* Context to own virtual resources */ 99 __u64 lun_size; /* Requested size, in 4K blocks */ 100 __u64 rsrc_handle; /* Returned resource handle */ 101 __u64 last_lba; /* Returned last LBA of LUN */ 102 __u64 reserved[8]; /* Reserved for future use */ 103 }; 104 105 struct dk_cxlflash_release { 106 struct dk_cxlflash_hdr hdr; /* Common fields */ 107 __u64 context_id; /* Context owning resources */ 108 __u64 rsrc_handle; /* Resource handle to release */ 109 __u64 reserved[8]; /* Reserved for future use */ 110 }; 111 112 struct dk_cxlflash_resize { 113 struct dk_cxlflash_hdr hdr; /* Common fields */ 114 __u64 context_id; /* Context owning resources */ 115 __u64 rsrc_handle; /* Resource handle of LUN to resize */ 116 __u64 req_size; /* New requested size, in 4K blocks */ 117 __u64 last_lba; /* Returned last LBA of LUN */ 118 __u64 reserved[8]; /* Reserved for future use */ 119 }; 120 121 struct dk_cxlflash_clone { 122 struct dk_cxlflash_hdr hdr; /* Common fields */ 123 __u64 context_id_src; /* Context to clone from */ 124 __u64 context_id_dst; /* Context to clone to */ 125 __u64 adap_fd_src; /* Source context adapter fd */ 126 __u64 reserved[8]; /* Reserved for future use */ 127 }; 128 129 #define DK_CXLFLASH_VERIFY_SENSE_LEN 18 130 #define DK_CXLFLASH_VERIFY_HINT_SENSE 0x8000000000000000ULL 131 132 struct dk_cxlflash_verify { 133 struct dk_cxlflash_hdr hdr; /* Common fields */ 134 __u64 context_id; /* Context owning resources to verify */ 135 __u64 rsrc_handle; /* Resource handle of LUN */ 136 __u64 hint; /* Reasons for verify */ 137 __u64 last_lba; /* Returned last LBA of device */ 138 __u8 sense_data[DK_CXLFLASH_VERIFY_SENSE_LEN]; /* SCSI sense data */ 139 __u8 pad[6]; /* Pad to next 8-byte boundary */ 140 __u64 reserved[8]; /* Reserved for future use */ 141 }; 142 143 #define DK_CXLFLASH_RECOVER_AFU_CONTEXT_RESET 0x8000000000000000ULL 144 145 struct dk_cxlflash_recover_afu { 146 struct dk_cxlflash_hdr hdr; /* Common fields */ 147 __u64 reason; /* Reason for recovery request */ 148 __u64 context_id; /* Context to recover / updated ID */ 149 __u64 mmio_size; /* Returned size of MMIO area */ 150 __u64 adap_fd; /* Returned adapter file descriptor */ 151 __u64 reserved[8]; /* Reserved for future use */ 152 }; 153 154 #define DK_CXLFLASH_MANAGE_LUN_WWID_LEN 16 155 #define DK_CXLFLASH_MANAGE_LUN_ENABLE_SUPERPIPE 0x8000000000000000ULL 156 #define DK_CXLFLASH_MANAGE_LUN_DISABLE_SUPERPIPE 0x4000000000000000ULL 157 #define DK_CXLFLASH_MANAGE_LUN_ALL_PORTS_ACCESSIBLE 0x2000000000000000ULL 158 159 struct dk_cxlflash_manage_lun { 160 struct dk_cxlflash_hdr hdr; /* Common fields */ 161 __u8 wwid[DK_CXLFLASH_MANAGE_LUN_WWID_LEN]; /* Page83 WWID, NAA-6 */ 162 __u64 reserved[8]; /* Rsvd, future use */ 163 }; 164 165 union cxlflash_ioctls { 166 struct dk_cxlflash_attach attach; 167 struct dk_cxlflash_detach detach; 168 struct dk_cxlflash_udirect udirect; 169 struct dk_cxlflash_uvirtual uvirtual; 170 struct dk_cxlflash_release release; 171 struct dk_cxlflash_resize resize; 172 struct dk_cxlflash_clone clone; 173 struct dk_cxlflash_verify verify; 174 struct dk_cxlflash_recover_afu recover_afu; 175 struct dk_cxlflash_manage_lun manage_lun; 176 }; 177 178 #define MAX_CXLFLASH_IOCTL_SZ (sizeof(union cxlflash_ioctls)) 179 180 #define CXL_MAGIC 0xCA 181 #define CXL_IOWR(_n, _s) _IOWR(CXL_MAGIC, _n, struct _s) 182 183 #define DK_CXLFLASH_ATTACH CXL_IOWR(0x80, dk_cxlflash_attach) 184 #define DK_CXLFLASH_USER_DIRECT CXL_IOWR(0x81, dk_cxlflash_udirect) 185 #define DK_CXLFLASH_RELEASE CXL_IOWR(0x82, dk_cxlflash_release) 186 #define DK_CXLFLASH_DETACH CXL_IOWR(0x83, dk_cxlflash_detach) 187 #define DK_CXLFLASH_VERIFY CXL_IOWR(0x84, dk_cxlflash_verify) 188 #define DK_CXLFLASH_RECOVER_AFU CXL_IOWR(0x85, dk_cxlflash_recover_afu) 189 #define DK_CXLFLASH_MANAGE_LUN CXL_IOWR(0x86, dk_cxlflash_manage_lun) 190 #define DK_CXLFLASH_USER_VIRTUAL CXL_IOWR(0x87, dk_cxlflash_uvirtual) 191 #define DK_CXLFLASH_VLUN_RESIZE CXL_IOWR(0x88, dk_cxlflash_resize) 192 #define DK_CXLFLASH_VLUN_CLONE CXL_IOWR(0x89, dk_cxlflash_clone) 193 194 #endif /* ifndef _CXLFLASH_IOCTL_H */ 195