cxlflash_ioctl.h 9.9 KB

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