162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * CXL Flash Device Driver 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation 662306a36Sopenharmony_ci * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Copyright (C) 2015 IBM Corporation 962306a36Sopenharmony_ci * 1062306a36Sopenharmony_ci * This program is free software; you can redistribute it and/or 1162306a36Sopenharmony_ci * modify it under the terms of the GNU General Public License 1262306a36Sopenharmony_ci * as published by the Free Software Foundation; either version 1362306a36Sopenharmony_ci * 2 of the License, or (at your option) any later version. 1462306a36Sopenharmony_ci */ 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#ifndef _CXLFLASH_IOCTL_H 1762306a36Sopenharmony_ci#define _CXLFLASH_IOCTL_H 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci#include <linux/types.h> 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci/* 2262306a36Sopenharmony_ci * Structure and definitions for all CXL Flash ioctls 2362306a36Sopenharmony_ci */ 2462306a36Sopenharmony_ci#define CXLFLASH_WWID_LEN 16 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci/* 2762306a36Sopenharmony_ci * Structure and flag definitions CXL Flash superpipe ioctls 2862306a36Sopenharmony_ci */ 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci#define DK_CXLFLASH_VERSION_0 0 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_cistruct dk_cxlflash_hdr { 3362306a36Sopenharmony_ci __u16 version; /* Version data */ 3462306a36Sopenharmony_ci __u16 rsvd[3]; /* Reserved for future use */ 3562306a36Sopenharmony_ci __u64 flags; /* Input flags */ 3662306a36Sopenharmony_ci __u64 return_flags; /* Returned flags */ 3762306a36Sopenharmony_ci}; 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci/* 4062306a36Sopenharmony_ci * Return flag definitions available to all superpipe ioctls 4162306a36Sopenharmony_ci * 4262306a36Sopenharmony_ci * Similar to the input flags, these are grown from the bottom-up with the 4362306a36Sopenharmony_ci * intention that ioctl-specific return flag definitions would grow from the 4462306a36Sopenharmony_ci * top-down, allowing the two sets to co-exist. While not required/enforced 4562306a36Sopenharmony_ci * at this time, this provides future flexibility. 4662306a36Sopenharmony_ci */ 4762306a36Sopenharmony_ci#define DK_CXLFLASH_ALL_PORTS_ACTIVE 0x0000000000000001ULL 4862306a36Sopenharmony_ci#define DK_CXLFLASH_APP_CLOSE_ADAP_FD 0x0000000000000002ULL 4962306a36Sopenharmony_ci#define DK_CXLFLASH_CONTEXT_SQ_CMD_MODE 0x0000000000000004ULL 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci/* 5262306a36Sopenharmony_ci * General Notes: 5362306a36Sopenharmony_ci * ------------- 5462306a36Sopenharmony_ci * The 'context_id' field of all ioctl structures contains the context 5562306a36Sopenharmony_ci * identifier for a context in the lower 32-bits (upper 32-bits are not 5662306a36Sopenharmony_ci * to be used when identifying a context to the AFU). That said, the value 5762306a36Sopenharmony_ci * in its entirety (all 64-bits) is to be treated as an opaque cookie and 5862306a36Sopenharmony_ci * should be presented as such when issuing ioctls. 5962306a36Sopenharmony_ci */ 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci/* 6262306a36Sopenharmony_ci * DK_CXLFLASH_ATTACH Notes: 6362306a36Sopenharmony_ci * ------------------------ 6462306a36Sopenharmony_ci * Read/write access permissions are specified via the O_RDONLY, O_WRONLY, 6562306a36Sopenharmony_ci * and O_RDWR flags defined in the fcntl.h header file. 6662306a36Sopenharmony_ci * 6762306a36Sopenharmony_ci * A valid adapter file descriptor (fd >= 0) is only returned on the initial 6862306a36Sopenharmony_ci * attach (successful) of a context. When a context is shared(reused), the user 6962306a36Sopenharmony_ci * is expected to already 'know' the adapter file descriptor associated with the 7062306a36Sopenharmony_ci * context. 7162306a36Sopenharmony_ci */ 7262306a36Sopenharmony_ci#define DK_CXLFLASH_ATTACH_REUSE_CONTEXT 0x8000000000000000ULL 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_cistruct dk_cxlflash_attach { 7562306a36Sopenharmony_ci struct dk_cxlflash_hdr hdr; /* Common fields */ 7662306a36Sopenharmony_ci __u64 num_interrupts; /* Requested number of interrupts */ 7762306a36Sopenharmony_ci __u64 context_id; /* Returned context */ 7862306a36Sopenharmony_ci __u64 mmio_size; /* Returned size of MMIO area */ 7962306a36Sopenharmony_ci __u64 block_size; /* Returned block size, in bytes */ 8062306a36Sopenharmony_ci __u64 adap_fd; /* Returned adapter file descriptor */ 8162306a36Sopenharmony_ci __u64 last_lba; /* Returned last LBA on the device */ 8262306a36Sopenharmony_ci __u64 max_xfer; /* Returned max transfer size, blocks */ 8362306a36Sopenharmony_ci __u64 reserved[8]; /* Reserved for future use */ 8462306a36Sopenharmony_ci}; 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_cistruct dk_cxlflash_detach { 8762306a36Sopenharmony_ci struct dk_cxlflash_hdr hdr; /* Common fields */ 8862306a36Sopenharmony_ci __u64 context_id; /* Context to detach */ 8962306a36Sopenharmony_ci __u64 reserved[8]; /* Reserved for future use */ 9062306a36Sopenharmony_ci}; 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_cistruct dk_cxlflash_udirect { 9362306a36Sopenharmony_ci struct dk_cxlflash_hdr hdr; /* Common fields */ 9462306a36Sopenharmony_ci __u64 context_id; /* Context to own physical resources */ 9562306a36Sopenharmony_ci __u64 rsrc_handle; /* Returned resource handle */ 9662306a36Sopenharmony_ci __u64 last_lba; /* Returned last LBA on the device */ 9762306a36Sopenharmony_ci __u64 reserved[8]; /* Reserved for future use */ 9862306a36Sopenharmony_ci}; 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci#define DK_CXLFLASH_UVIRTUAL_NEED_WRITE_SAME 0x8000000000000000ULL 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_cistruct dk_cxlflash_uvirtual { 10362306a36Sopenharmony_ci struct dk_cxlflash_hdr hdr; /* Common fields */ 10462306a36Sopenharmony_ci __u64 context_id; /* Context to own virtual resources */ 10562306a36Sopenharmony_ci __u64 lun_size; /* Requested size, in 4K blocks */ 10662306a36Sopenharmony_ci __u64 rsrc_handle; /* Returned resource handle */ 10762306a36Sopenharmony_ci __u64 last_lba; /* Returned last LBA of LUN */ 10862306a36Sopenharmony_ci __u64 reserved[8]; /* Reserved for future use */ 10962306a36Sopenharmony_ci}; 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_cistruct dk_cxlflash_release { 11262306a36Sopenharmony_ci struct dk_cxlflash_hdr hdr; /* Common fields */ 11362306a36Sopenharmony_ci __u64 context_id; /* Context owning resources */ 11462306a36Sopenharmony_ci __u64 rsrc_handle; /* Resource handle to release */ 11562306a36Sopenharmony_ci __u64 reserved[8]; /* Reserved for future use */ 11662306a36Sopenharmony_ci}; 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_cistruct dk_cxlflash_resize { 11962306a36Sopenharmony_ci struct dk_cxlflash_hdr hdr; /* Common fields */ 12062306a36Sopenharmony_ci __u64 context_id; /* Context owning resources */ 12162306a36Sopenharmony_ci __u64 rsrc_handle; /* Resource handle of LUN to resize */ 12262306a36Sopenharmony_ci __u64 req_size; /* New requested size, in 4K blocks */ 12362306a36Sopenharmony_ci __u64 last_lba; /* Returned last LBA of LUN */ 12462306a36Sopenharmony_ci __u64 reserved[8]; /* Reserved for future use */ 12562306a36Sopenharmony_ci}; 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_cistruct dk_cxlflash_clone { 12862306a36Sopenharmony_ci struct dk_cxlflash_hdr hdr; /* Common fields */ 12962306a36Sopenharmony_ci __u64 context_id_src; /* Context to clone from */ 13062306a36Sopenharmony_ci __u64 context_id_dst; /* Context to clone to */ 13162306a36Sopenharmony_ci __u64 adap_fd_src; /* Source context adapter fd */ 13262306a36Sopenharmony_ci __u64 reserved[8]; /* Reserved for future use */ 13362306a36Sopenharmony_ci}; 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ci#define DK_CXLFLASH_VERIFY_SENSE_LEN 18 13662306a36Sopenharmony_ci#define DK_CXLFLASH_VERIFY_HINT_SENSE 0x8000000000000000ULL 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_cistruct dk_cxlflash_verify { 13962306a36Sopenharmony_ci struct dk_cxlflash_hdr hdr; /* Common fields */ 14062306a36Sopenharmony_ci __u64 context_id; /* Context owning resources to verify */ 14162306a36Sopenharmony_ci __u64 rsrc_handle; /* Resource handle of LUN */ 14262306a36Sopenharmony_ci __u64 hint; /* Reasons for verify */ 14362306a36Sopenharmony_ci __u64 last_lba; /* Returned last LBA of device */ 14462306a36Sopenharmony_ci __u8 sense_data[DK_CXLFLASH_VERIFY_SENSE_LEN]; /* SCSI sense data */ 14562306a36Sopenharmony_ci __u8 pad[6]; /* Pad to next 8-byte boundary */ 14662306a36Sopenharmony_ci __u64 reserved[8]; /* Reserved for future use */ 14762306a36Sopenharmony_ci}; 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci#define DK_CXLFLASH_RECOVER_AFU_CONTEXT_RESET 0x8000000000000000ULL 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_cistruct dk_cxlflash_recover_afu { 15262306a36Sopenharmony_ci struct dk_cxlflash_hdr hdr; /* Common fields */ 15362306a36Sopenharmony_ci __u64 reason; /* Reason for recovery request */ 15462306a36Sopenharmony_ci __u64 context_id; /* Context to recover / updated ID */ 15562306a36Sopenharmony_ci __u64 mmio_size; /* Returned size of MMIO area */ 15662306a36Sopenharmony_ci __u64 adap_fd; /* Returned adapter file descriptor */ 15762306a36Sopenharmony_ci __u64 reserved[8]; /* Reserved for future use */ 15862306a36Sopenharmony_ci}; 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci#define DK_CXLFLASH_MANAGE_LUN_WWID_LEN CXLFLASH_WWID_LEN 16162306a36Sopenharmony_ci#define DK_CXLFLASH_MANAGE_LUN_ENABLE_SUPERPIPE 0x8000000000000000ULL 16262306a36Sopenharmony_ci#define DK_CXLFLASH_MANAGE_LUN_DISABLE_SUPERPIPE 0x4000000000000000ULL 16362306a36Sopenharmony_ci#define DK_CXLFLASH_MANAGE_LUN_ALL_PORTS_ACCESSIBLE 0x2000000000000000ULL 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_cistruct dk_cxlflash_manage_lun { 16662306a36Sopenharmony_ci struct dk_cxlflash_hdr hdr; /* Common fields */ 16762306a36Sopenharmony_ci __u8 wwid[DK_CXLFLASH_MANAGE_LUN_WWID_LEN]; /* Page83 WWID, NAA-6 */ 16862306a36Sopenharmony_ci __u64 reserved[8]; /* Rsvd, future use */ 16962306a36Sopenharmony_ci}; 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ciunion cxlflash_ioctls { 17262306a36Sopenharmony_ci struct dk_cxlflash_attach attach; 17362306a36Sopenharmony_ci struct dk_cxlflash_detach detach; 17462306a36Sopenharmony_ci struct dk_cxlflash_udirect udirect; 17562306a36Sopenharmony_ci struct dk_cxlflash_uvirtual uvirtual; 17662306a36Sopenharmony_ci struct dk_cxlflash_release release; 17762306a36Sopenharmony_ci struct dk_cxlflash_resize resize; 17862306a36Sopenharmony_ci struct dk_cxlflash_clone clone; 17962306a36Sopenharmony_ci struct dk_cxlflash_verify verify; 18062306a36Sopenharmony_ci struct dk_cxlflash_recover_afu recover_afu; 18162306a36Sopenharmony_ci struct dk_cxlflash_manage_lun manage_lun; 18262306a36Sopenharmony_ci}; 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_ci#define MAX_CXLFLASH_IOCTL_SZ (sizeof(union cxlflash_ioctls)) 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_ci#define CXL_MAGIC 0xCA 18762306a36Sopenharmony_ci#define CXL_IOWR(_n, _s) _IOWR(CXL_MAGIC, _n, struct _s) 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci/* 19062306a36Sopenharmony_ci * CXL Flash superpipe ioctls start at base of the reserved CXL_MAGIC 19162306a36Sopenharmony_ci * region (0x80) and grow upwards. 19262306a36Sopenharmony_ci */ 19362306a36Sopenharmony_ci#define DK_CXLFLASH_ATTACH CXL_IOWR(0x80, dk_cxlflash_attach) 19462306a36Sopenharmony_ci#define DK_CXLFLASH_USER_DIRECT CXL_IOWR(0x81, dk_cxlflash_udirect) 19562306a36Sopenharmony_ci#define DK_CXLFLASH_RELEASE CXL_IOWR(0x82, dk_cxlflash_release) 19662306a36Sopenharmony_ci#define DK_CXLFLASH_DETACH CXL_IOWR(0x83, dk_cxlflash_detach) 19762306a36Sopenharmony_ci#define DK_CXLFLASH_VERIFY CXL_IOWR(0x84, dk_cxlflash_verify) 19862306a36Sopenharmony_ci#define DK_CXLFLASH_RECOVER_AFU CXL_IOWR(0x85, dk_cxlflash_recover_afu) 19962306a36Sopenharmony_ci#define DK_CXLFLASH_MANAGE_LUN CXL_IOWR(0x86, dk_cxlflash_manage_lun) 20062306a36Sopenharmony_ci#define DK_CXLFLASH_USER_VIRTUAL CXL_IOWR(0x87, dk_cxlflash_uvirtual) 20162306a36Sopenharmony_ci#define DK_CXLFLASH_VLUN_RESIZE CXL_IOWR(0x88, dk_cxlflash_resize) 20262306a36Sopenharmony_ci#define DK_CXLFLASH_VLUN_CLONE CXL_IOWR(0x89, dk_cxlflash_clone) 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_ci/* 20562306a36Sopenharmony_ci * Structure and flag definitions CXL Flash host ioctls 20662306a36Sopenharmony_ci */ 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci#define HT_CXLFLASH_VERSION_0 0 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_cistruct ht_cxlflash_hdr { 21162306a36Sopenharmony_ci __u16 version; /* Version data */ 21262306a36Sopenharmony_ci __u16 subcmd; /* Sub-command */ 21362306a36Sopenharmony_ci __u16 rsvd[2]; /* Reserved for future use */ 21462306a36Sopenharmony_ci __u64 flags; /* Input flags */ 21562306a36Sopenharmony_ci __u64 return_flags; /* Returned flags */ 21662306a36Sopenharmony_ci}; 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_ci/* 21962306a36Sopenharmony_ci * Input flag definitions available to all host ioctls 22062306a36Sopenharmony_ci * 22162306a36Sopenharmony_ci * These are grown from the bottom-up with the intention that ioctl-specific 22262306a36Sopenharmony_ci * input flag definitions would grow from the top-down, allowing the two sets 22362306a36Sopenharmony_ci * to co-exist. While not required/enforced at this time, this provides future 22462306a36Sopenharmony_ci * flexibility. 22562306a36Sopenharmony_ci */ 22662306a36Sopenharmony_ci#define HT_CXLFLASH_HOST_READ 0x0000000000000000ULL 22762306a36Sopenharmony_ci#define HT_CXLFLASH_HOST_WRITE 0x0000000000000001ULL 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ci#define HT_CXLFLASH_LUN_PROVISION_SUBCMD_CREATE_LUN 0x0001 23062306a36Sopenharmony_ci#define HT_CXLFLASH_LUN_PROVISION_SUBCMD_DELETE_LUN 0x0002 23162306a36Sopenharmony_ci#define HT_CXLFLASH_LUN_PROVISION_SUBCMD_QUERY_PORT 0x0003 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_cistruct ht_cxlflash_lun_provision { 23462306a36Sopenharmony_ci struct ht_cxlflash_hdr hdr; /* Common fields */ 23562306a36Sopenharmony_ci __u16 port; /* Target port for provision request */ 23662306a36Sopenharmony_ci __u16 reserved16[3]; /* Reserved for future use */ 23762306a36Sopenharmony_ci __u64 size; /* Size of LUN (4K blocks) */ 23862306a36Sopenharmony_ci __u64 lun_id; /* SCSI LUN ID */ 23962306a36Sopenharmony_ci __u8 wwid[CXLFLASH_WWID_LEN];/* Page83 WWID, NAA-6 */ 24062306a36Sopenharmony_ci __u64 max_num_luns; /* Maximum number of LUNs provisioned */ 24162306a36Sopenharmony_ci __u64 cur_num_luns; /* Current number of LUNs provisioned */ 24262306a36Sopenharmony_ci __u64 max_cap_port; /* Total capacity for port (4K blocks) */ 24362306a36Sopenharmony_ci __u64 cur_cap_port; /* Current capacity for port (4K blocks) */ 24462306a36Sopenharmony_ci __u64 reserved[8]; /* Reserved for future use */ 24562306a36Sopenharmony_ci}; 24662306a36Sopenharmony_ci 24762306a36Sopenharmony_ci#define HT_CXLFLASH_AFU_DEBUG_MAX_DATA_LEN 262144 /* 256K */ 24862306a36Sopenharmony_ci#define HT_CXLFLASH_AFU_DEBUG_SUBCMD_LEN 12 24962306a36Sopenharmony_cistruct ht_cxlflash_afu_debug { 25062306a36Sopenharmony_ci struct ht_cxlflash_hdr hdr; /* Common fields */ 25162306a36Sopenharmony_ci __u8 reserved8[4]; /* Reserved for future use */ 25262306a36Sopenharmony_ci __u8 afu_subcmd[HT_CXLFLASH_AFU_DEBUG_SUBCMD_LEN]; /* AFU subcommand, 25362306a36Sopenharmony_ci * (pass through) 25462306a36Sopenharmony_ci */ 25562306a36Sopenharmony_ci __u64 data_ea; /* Data buffer effective address */ 25662306a36Sopenharmony_ci __u32 data_len; /* Data buffer length */ 25762306a36Sopenharmony_ci __u32 reserved32; /* Reserved for future use */ 25862306a36Sopenharmony_ci __u64 reserved[8]; /* Reserved for future use */ 25962306a36Sopenharmony_ci}; 26062306a36Sopenharmony_ci 26162306a36Sopenharmony_ciunion cxlflash_ht_ioctls { 26262306a36Sopenharmony_ci struct ht_cxlflash_lun_provision lun_provision; 26362306a36Sopenharmony_ci struct ht_cxlflash_afu_debug afu_debug; 26462306a36Sopenharmony_ci}; 26562306a36Sopenharmony_ci 26662306a36Sopenharmony_ci#define MAX_HT_CXLFLASH_IOCTL_SZ (sizeof(union cxlflash_ht_ioctls)) 26762306a36Sopenharmony_ci 26862306a36Sopenharmony_ci/* 26962306a36Sopenharmony_ci * CXL Flash host ioctls start at the top of the reserved CXL_MAGIC 27062306a36Sopenharmony_ci * region (0xBF) and grow downwards. 27162306a36Sopenharmony_ci */ 27262306a36Sopenharmony_ci#define HT_CXLFLASH_LUN_PROVISION CXL_IOWR(0xBF, ht_cxlflash_lun_provision) 27362306a36Sopenharmony_ci#define HT_CXLFLASH_AFU_DEBUG CXL_IOWR(0xBE, ht_cxlflash_afu_debug) 27462306a36Sopenharmony_ci 27562306a36Sopenharmony_ci 27662306a36Sopenharmony_ci#endif /* ifndef _CXLFLASH_IOCTL_H */ 277