1*4882a593Smuzhiyun================================ 2*4882a593SmuzhiyunCoherent Accelerator (CXL) Flash 3*4882a593Smuzhiyun================================ 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunIntroduction 6*4882a593Smuzhiyun============ 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun The IBM Power architecture provides support for CAPI (Coherent 9*4882a593Smuzhiyun Accelerator Power Interface), which is available to certain PCIe slots 10*4882a593Smuzhiyun on Power 8 systems. CAPI can be thought of as a special tunneling 11*4882a593Smuzhiyun protocol through PCIe that allow PCIe adapters to look like special 12*4882a593Smuzhiyun purpose co-processors which can read or write an application's 13*4882a593Smuzhiyun memory and generate page faults. As a result, the host interface to 14*4882a593Smuzhiyun an adapter running in CAPI mode does not require the data buffers to 15*4882a593Smuzhiyun be mapped to the device's memory (IOMMU bypass) nor does it require 16*4882a593Smuzhiyun memory to be pinned. 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun On Linux, Coherent Accelerator (CXL) kernel services present CAPI 19*4882a593Smuzhiyun devices as a PCI device by implementing a virtual PCI host bridge. 20*4882a593Smuzhiyun This abstraction simplifies the infrastructure and programming 21*4882a593Smuzhiyun model, allowing for drivers to look similar to other native PCI 22*4882a593Smuzhiyun device drivers. 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun CXL provides a mechanism by which user space applications can 25*4882a593Smuzhiyun directly talk to a device (network or storage) bypassing the typical 26*4882a593Smuzhiyun kernel/device driver stack. The CXL Flash Adapter Driver enables a 27*4882a593Smuzhiyun user space application direct access to Flash storage. 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun The CXL Flash Adapter Driver is a kernel module that sits in the 30*4882a593Smuzhiyun SCSI stack as a low level device driver (below the SCSI disk and 31*4882a593Smuzhiyun protocol drivers) for the IBM CXL Flash Adapter. This driver is 32*4882a593Smuzhiyun responsible for the initialization of the adapter, setting up the 33*4882a593Smuzhiyun special path for user space access, and performing error recovery. It 34*4882a593Smuzhiyun communicates directly the Flash Accelerator Functional Unit (AFU) 35*4882a593Smuzhiyun as described in Documentation/powerpc/cxl.rst. 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun The cxlflash driver supports two, mutually exclusive, modes of 38*4882a593Smuzhiyun operation at the device (LUN) level: 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun - Any flash device (LUN) can be configured to be accessed as a 41*4882a593Smuzhiyun regular disk device (i.e.: /dev/sdc). This is the default mode. 42*4882a593Smuzhiyun 43*4882a593Smuzhiyun - Any flash device (LUN) can be configured to be accessed from 44*4882a593Smuzhiyun user space with a special block library. This mode further 45*4882a593Smuzhiyun specifies the means of accessing the device and provides for 46*4882a593Smuzhiyun either raw access to the entire LUN (referred to as direct 47*4882a593Smuzhiyun or physical LUN access) or access to a kernel/AFU-mediated 48*4882a593Smuzhiyun partition of the LUN (referred to as virtual LUN access). The 49*4882a593Smuzhiyun segmentation of a disk device into virtual LUNs is assisted 50*4882a593Smuzhiyun by special translation services provided by the Flash AFU. 51*4882a593Smuzhiyun 52*4882a593SmuzhiyunOverview 53*4882a593Smuzhiyun======== 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun The Coherent Accelerator Interface Architecture (CAIA) introduces a 56*4882a593Smuzhiyun concept of a master context. A master typically has special privileges 57*4882a593Smuzhiyun granted to it by the kernel or hypervisor allowing it to perform AFU 58*4882a593Smuzhiyun wide management and control. The master may or may not be involved 59*4882a593Smuzhiyun directly in each user I/O, but at the minimum is involved in the 60*4882a593Smuzhiyun initial setup before the user application is allowed to send requests 61*4882a593Smuzhiyun directly to the AFU. 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun The CXL Flash Adapter Driver establishes a master context with the 64*4882a593Smuzhiyun AFU. It uses memory mapped I/O (MMIO) for this control and setup. The 65*4882a593Smuzhiyun Adapter Problem Space Memory Map looks like this:: 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun +-------------------------------+ 68*4882a593Smuzhiyun | 512 * 64 KB User MMIO | 69*4882a593Smuzhiyun | (per context) | 70*4882a593Smuzhiyun | User Accessible | 71*4882a593Smuzhiyun +-------------------------------+ 72*4882a593Smuzhiyun | 512 * 128 B per context | 73*4882a593Smuzhiyun | Provisioning and Control | 74*4882a593Smuzhiyun | Trusted Process accessible | 75*4882a593Smuzhiyun +-------------------------------+ 76*4882a593Smuzhiyun | 64 KB Global | 77*4882a593Smuzhiyun | Trusted Process accessible | 78*4882a593Smuzhiyun +-------------------------------+ 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun This driver configures itself into the SCSI software stack as an 81*4882a593Smuzhiyun adapter driver. The driver is the only entity that is considered a 82*4882a593Smuzhiyun Trusted Process to program the Provisioning and Control and Global 83*4882a593Smuzhiyun areas in the MMIO Space shown above. The master context driver 84*4882a593Smuzhiyun discovers all LUNs attached to the CXL Flash adapter and instantiates 85*4882a593Smuzhiyun scsi block devices (/dev/sdb, /dev/sdc etc.) for each unique LUN 86*4882a593Smuzhiyun seen from each path. 87*4882a593Smuzhiyun 88*4882a593Smuzhiyun Once these scsi block devices are instantiated, an application 89*4882a593Smuzhiyun written to a specification provided by the block library may get 90*4882a593Smuzhiyun access to the Flash from user space (without requiring a system call). 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun This master context driver also provides a series of ioctls for this 93*4882a593Smuzhiyun block library to enable this user space access. The driver supports 94*4882a593Smuzhiyun two modes for accessing the block device. 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun The first mode is called a virtual mode. In this mode a single scsi 97*4882a593Smuzhiyun block device (/dev/sdb) may be carved up into any number of distinct 98*4882a593Smuzhiyun virtual LUNs. The virtual LUNs may be resized as long as the sum of 99*4882a593Smuzhiyun the sizes of all the virtual LUNs, along with the meta-data associated 100*4882a593Smuzhiyun with it does not exceed the physical capacity. 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun The second mode is called the physical mode. In this mode a single 103*4882a593Smuzhiyun block device (/dev/sdb) may be opened directly by the block library 104*4882a593Smuzhiyun and the entire space for the LUN is available to the application. 105*4882a593Smuzhiyun 106*4882a593Smuzhiyun Only the physical mode provides persistence of the data. i.e. The 107*4882a593Smuzhiyun data written to the block device will survive application exit and 108*4882a593Smuzhiyun restart and also reboot. The virtual LUNs do not persist (i.e. do 109*4882a593Smuzhiyun not survive after the application terminates or the system reboots). 110*4882a593Smuzhiyun 111*4882a593Smuzhiyun 112*4882a593SmuzhiyunBlock library API 113*4882a593Smuzhiyun================= 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun Applications intending to get access to the CXL Flash from user 116*4882a593Smuzhiyun space should use the block library, as it abstracts the details of 117*4882a593Smuzhiyun interfacing directly with the cxlflash driver that are necessary for 118*4882a593Smuzhiyun performing administrative actions (i.e.: setup, tear down, resize). 119*4882a593Smuzhiyun The block library can be thought of as a 'user' of services, 120*4882a593Smuzhiyun implemented as IOCTLs, that are provided by the cxlflash driver 121*4882a593Smuzhiyun specifically for devices (LUNs) operating in user space access 122*4882a593Smuzhiyun mode. While it is not a requirement that applications understand 123*4882a593Smuzhiyun the interface between the block library and the cxlflash driver, 124*4882a593Smuzhiyun a high-level overview of each supported service (IOCTL) is provided 125*4882a593Smuzhiyun below. 126*4882a593Smuzhiyun 127*4882a593Smuzhiyun The block library can be found on GitHub: 128*4882a593Smuzhiyun http://github.com/open-power/capiflash 129*4882a593Smuzhiyun 130*4882a593Smuzhiyun 131*4882a593SmuzhiyunCXL Flash Driver LUN IOCTLs 132*4882a593Smuzhiyun=========================== 133*4882a593Smuzhiyun 134*4882a593Smuzhiyun Users, such as the block library, that wish to interface with a flash 135*4882a593Smuzhiyun device (LUN) via user space access need to use the services provided 136*4882a593Smuzhiyun by the cxlflash driver. As these services are implemented as ioctls, 137*4882a593Smuzhiyun a file descriptor handle must first be obtained in order to establish 138*4882a593Smuzhiyun the communication channel between a user and the kernel. This file 139*4882a593Smuzhiyun descriptor is obtained by opening the device special file associated 140*4882a593Smuzhiyun with the scsi disk device (/dev/sdb) that was created during LUN 141*4882a593Smuzhiyun discovery. As per the location of the cxlflash driver within the 142*4882a593Smuzhiyun SCSI protocol stack, this open is actually not seen by the cxlflash 143*4882a593Smuzhiyun driver. Upon successful open, the user receives a file descriptor 144*4882a593Smuzhiyun (herein referred to as fd1) that should be used for issuing the 145*4882a593Smuzhiyun subsequent ioctls listed below. 146*4882a593Smuzhiyun 147*4882a593Smuzhiyun The structure definitions for these IOCTLs are available in: 148*4882a593Smuzhiyun uapi/scsi/cxlflash_ioctl.h 149*4882a593Smuzhiyun 150*4882a593SmuzhiyunDK_CXLFLASH_ATTACH 151*4882a593Smuzhiyun------------------ 152*4882a593Smuzhiyun 153*4882a593Smuzhiyun This ioctl obtains, initializes, and starts a context using the CXL 154*4882a593Smuzhiyun kernel services. These services specify a context id (u16) by which 155*4882a593Smuzhiyun to uniquely identify the context and its allocated resources. The 156*4882a593Smuzhiyun services additionally provide a second file descriptor (herein 157*4882a593Smuzhiyun referred to as fd2) that is used by the block library to initiate 158*4882a593Smuzhiyun memory mapped I/O (via mmap()) to the CXL flash device and poll for 159*4882a593Smuzhiyun completion events. This file descriptor is intentionally installed by 160*4882a593Smuzhiyun this driver and not the CXL kernel services to allow for intermediary 161*4882a593Smuzhiyun notification and access in the event of a non-user-initiated close(), 162*4882a593Smuzhiyun such as a killed process. This design point is described in further 163*4882a593Smuzhiyun detail in the description for the DK_CXLFLASH_DETACH ioctl. 164*4882a593Smuzhiyun 165*4882a593Smuzhiyun There are a few important aspects regarding the "tokens" (context id 166*4882a593Smuzhiyun and fd2) that are provided back to the user: 167*4882a593Smuzhiyun 168*4882a593Smuzhiyun - These tokens are only valid for the process under which they 169*4882a593Smuzhiyun were created. The child of a forked process cannot continue 170*4882a593Smuzhiyun to use the context id or file descriptor created by its parent 171*4882a593Smuzhiyun (see DK_CXLFLASH_VLUN_CLONE for further details). 172*4882a593Smuzhiyun 173*4882a593Smuzhiyun - These tokens are only valid for the lifetime of the context and 174*4882a593Smuzhiyun the process under which they were created. Once either is 175*4882a593Smuzhiyun destroyed, the tokens are to be considered stale and subsequent 176*4882a593Smuzhiyun usage will result in errors. 177*4882a593Smuzhiyun 178*4882a593Smuzhiyun - A valid adapter file descriptor (fd2 >= 0) is only returned on 179*4882a593Smuzhiyun the initial attach for a context. Subsequent attaches to an 180*4882a593Smuzhiyun existing context (DK_CXLFLASH_ATTACH_REUSE_CONTEXT flag present) 181*4882a593Smuzhiyun do not provide the adapter file descriptor as it was previously 182*4882a593Smuzhiyun made known to the application. 183*4882a593Smuzhiyun 184*4882a593Smuzhiyun - When a context is no longer needed, the user shall detach from 185*4882a593Smuzhiyun the context via the DK_CXLFLASH_DETACH ioctl. When this ioctl 186*4882a593Smuzhiyun returns with a valid adapter file descriptor and the return flag 187*4882a593Smuzhiyun DK_CXLFLASH_APP_CLOSE_ADAP_FD is present, the application _must_ 188*4882a593Smuzhiyun close the adapter file descriptor following a successful detach. 189*4882a593Smuzhiyun 190*4882a593Smuzhiyun - When this ioctl returns with a valid fd2 and the return flag 191*4882a593Smuzhiyun DK_CXLFLASH_APP_CLOSE_ADAP_FD is present, the application _must_ 192*4882a593Smuzhiyun close fd2 in the following circumstances: 193*4882a593Smuzhiyun 194*4882a593Smuzhiyun + Following a successful detach of the last user of the context 195*4882a593Smuzhiyun + Following a successful recovery on the context's original fd2 196*4882a593Smuzhiyun + In the child process of a fork(), following a clone ioctl, 197*4882a593Smuzhiyun on the fd2 associated with the source context 198*4882a593Smuzhiyun 199*4882a593Smuzhiyun - At any time, a close on fd2 will invalidate the tokens. Applications 200*4882a593Smuzhiyun should exercise caution to only close fd2 when appropriate (outlined 201*4882a593Smuzhiyun in the previous bullet) to avoid premature loss of I/O. 202*4882a593Smuzhiyun 203*4882a593SmuzhiyunDK_CXLFLASH_USER_DIRECT 204*4882a593Smuzhiyun----------------------- 205*4882a593Smuzhiyun This ioctl is responsible for transitioning the LUN to direct 206*4882a593Smuzhiyun (physical) mode access and configuring the AFU for direct access from 207*4882a593Smuzhiyun user space on a per-context basis. Additionally, the block size and 208*4882a593Smuzhiyun last logical block address (LBA) are returned to the user. 209*4882a593Smuzhiyun 210*4882a593Smuzhiyun As mentioned previously, when operating in user space access mode, 211*4882a593Smuzhiyun LUNs may be accessed in whole or in part. Only one mode is allowed 212*4882a593Smuzhiyun at a time and if one mode is active (outstanding references exist), 213*4882a593Smuzhiyun requests to use the LUN in a different mode are denied. 214*4882a593Smuzhiyun 215*4882a593Smuzhiyun The AFU is configured for direct access from user space by adding an 216*4882a593Smuzhiyun entry to the AFU's resource handle table. The index of the entry is 217*4882a593Smuzhiyun treated as a resource handle that is returned to the user. The user 218*4882a593Smuzhiyun is then able to use the handle to reference the LUN during I/O. 219*4882a593Smuzhiyun 220*4882a593SmuzhiyunDK_CXLFLASH_USER_VIRTUAL 221*4882a593Smuzhiyun------------------------ 222*4882a593Smuzhiyun This ioctl is responsible for transitioning the LUN to virtual mode 223*4882a593Smuzhiyun of access and configuring the AFU for virtual access from user space 224*4882a593Smuzhiyun on a per-context basis. Additionally, the block size and last logical 225*4882a593Smuzhiyun block address (LBA) are returned to the user. 226*4882a593Smuzhiyun 227*4882a593Smuzhiyun As mentioned previously, when operating in user space access mode, 228*4882a593Smuzhiyun LUNs may be accessed in whole or in part. Only one mode is allowed 229*4882a593Smuzhiyun at a time and if one mode is active (outstanding references exist), 230*4882a593Smuzhiyun requests to use the LUN in a different mode are denied. 231*4882a593Smuzhiyun 232*4882a593Smuzhiyun The AFU is configured for virtual access from user space by adding 233*4882a593Smuzhiyun an entry to the AFU's resource handle table. The index of the entry 234*4882a593Smuzhiyun is treated as a resource handle that is returned to the user. The 235*4882a593Smuzhiyun user is then able to use the handle to reference the LUN during I/O. 236*4882a593Smuzhiyun 237*4882a593Smuzhiyun By default, the virtual LUN is created with a size of 0. The user 238*4882a593Smuzhiyun would need to use the DK_CXLFLASH_VLUN_RESIZE ioctl to adjust the grow 239*4882a593Smuzhiyun the virtual LUN to a desired size. To avoid having to perform this 240*4882a593Smuzhiyun resize for the initial creation of the virtual LUN, the user has the 241*4882a593Smuzhiyun option of specifying a size as part of the DK_CXLFLASH_USER_VIRTUAL 242*4882a593Smuzhiyun ioctl, such that when success is returned to the user, the 243*4882a593Smuzhiyun resource handle that is provided is already referencing provisioned 244*4882a593Smuzhiyun storage. This is reflected by the last LBA being a non-zero value. 245*4882a593Smuzhiyun 246*4882a593Smuzhiyun When a LUN is accessible from more than one port, this ioctl will 247*4882a593Smuzhiyun return with the DK_CXLFLASH_ALL_PORTS_ACTIVE return flag set. This 248*4882a593Smuzhiyun provides the user with a hint that I/O can be retried in the event 249*4882a593Smuzhiyun of an I/O error as the LUN can be reached over multiple paths. 250*4882a593Smuzhiyun 251*4882a593SmuzhiyunDK_CXLFLASH_VLUN_RESIZE 252*4882a593Smuzhiyun----------------------- 253*4882a593Smuzhiyun This ioctl is responsible for resizing a previously created virtual 254*4882a593Smuzhiyun LUN and will fail if invoked upon a LUN that is not in virtual 255*4882a593Smuzhiyun mode. Upon success, an updated last LBA is returned to the user 256*4882a593Smuzhiyun indicating the new size of the virtual LUN associated with the 257*4882a593Smuzhiyun resource handle. 258*4882a593Smuzhiyun 259*4882a593Smuzhiyun The partitioning of virtual LUNs is jointly mediated by the cxlflash 260*4882a593Smuzhiyun driver and the AFU. An allocation table is kept for each LUN that is 261*4882a593Smuzhiyun operating in the virtual mode and used to program a LUN translation 262*4882a593Smuzhiyun table that the AFU references when provided with a resource handle. 263*4882a593Smuzhiyun 264*4882a593Smuzhiyun This ioctl can return -EAGAIN if an AFU sync operation takes too long. 265*4882a593Smuzhiyun In addition to returning a failure to user, cxlflash will also schedule 266*4882a593Smuzhiyun an asynchronous AFU reset. Should the user choose to retry the operation, 267*4882a593Smuzhiyun it is expected to succeed. If this ioctl fails with -EAGAIN, the user 268*4882a593Smuzhiyun can either retry the operation or treat it as a failure. 269*4882a593Smuzhiyun 270*4882a593SmuzhiyunDK_CXLFLASH_RELEASE 271*4882a593Smuzhiyun------------------- 272*4882a593Smuzhiyun This ioctl is responsible for releasing a previously obtained 273*4882a593Smuzhiyun reference to either a physical or virtual LUN. This can be 274*4882a593Smuzhiyun thought of as the inverse of the DK_CXLFLASH_USER_DIRECT or 275*4882a593Smuzhiyun DK_CXLFLASH_USER_VIRTUAL ioctls. Upon success, the resource handle 276*4882a593Smuzhiyun is no longer valid and the entry in the resource handle table is 277*4882a593Smuzhiyun made available to be used again. 278*4882a593Smuzhiyun 279*4882a593Smuzhiyun As part of the release process for virtual LUNs, the virtual LUN 280*4882a593Smuzhiyun is first resized to 0 to clear out and free the translation tables 281*4882a593Smuzhiyun associated with the virtual LUN reference. 282*4882a593Smuzhiyun 283*4882a593SmuzhiyunDK_CXLFLASH_DETACH 284*4882a593Smuzhiyun------------------ 285*4882a593Smuzhiyun This ioctl is responsible for unregistering a context with the 286*4882a593Smuzhiyun cxlflash driver and release outstanding resources that were 287*4882a593Smuzhiyun not explicitly released via the DK_CXLFLASH_RELEASE ioctl. Upon 288*4882a593Smuzhiyun success, all "tokens" which had been provided to the user from the 289*4882a593Smuzhiyun DK_CXLFLASH_ATTACH onward are no longer valid. 290*4882a593Smuzhiyun 291*4882a593Smuzhiyun When the DK_CXLFLASH_APP_CLOSE_ADAP_FD flag was returned on a successful 292*4882a593Smuzhiyun attach, the application _must_ close the fd2 associated with the context 293*4882a593Smuzhiyun following the detach of the final user of the context. 294*4882a593Smuzhiyun 295*4882a593SmuzhiyunDK_CXLFLASH_VLUN_CLONE 296*4882a593Smuzhiyun---------------------- 297*4882a593Smuzhiyun This ioctl is responsible for cloning a previously created 298*4882a593Smuzhiyun context to a more recently created context. It exists solely to 299*4882a593Smuzhiyun support maintaining user space access to storage after a process 300*4882a593Smuzhiyun forks. Upon success, the child process (which invoked the ioctl) 301*4882a593Smuzhiyun will have access to the same LUNs via the same resource handle(s) 302*4882a593Smuzhiyun as the parent, but under a different context. 303*4882a593Smuzhiyun 304*4882a593Smuzhiyun Context sharing across processes is not supported with CXL and 305*4882a593Smuzhiyun therefore each fork must be met with establishing a new context 306*4882a593Smuzhiyun for the child process. This ioctl simplifies the state management 307*4882a593Smuzhiyun and playback required by a user in such a scenario. When a process 308*4882a593Smuzhiyun forks, child process can clone the parents context by first creating 309*4882a593Smuzhiyun a context (via DK_CXLFLASH_ATTACH) and then using this ioctl to 310*4882a593Smuzhiyun perform the clone from the parent to the child. 311*4882a593Smuzhiyun 312*4882a593Smuzhiyun The clone itself is fairly simple. The resource handle and lun 313*4882a593Smuzhiyun translation tables are copied from the parent context to the child's 314*4882a593Smuzhiyun and then synced with the AFU. 315*4882a593Smuzhiyun 316*4882a593Smuzhiyun When the DK_CXLFLASH_APP_CLOSE_ADAP_FD flag was returned on a successful 317*4882a593Smuzhiyun attach, the application _must_ close the fd2 associated with the source 318*4882a593Smuzhiyun context (still resident/accessible in the parent process) following the 319*4882a593Smuzhiyun clone. This is to avoid a stale entry in the file descriptor table of the 320*4882a593Smuzhiyun child process. 321*4882a593Smuzhiyun 322*4882a593Smuzhiyun This ioctl can return -EAGAIN if an AFU sync operation takes too long. 323*4882a593Smuzhiyun In addition to returning a failure to user, cxlflash will also schedule 324*4882a593Smuzhiyun an asynchronous AFU reset. Should the user choose to retry the operation, 325*4882a593Smuzhiyun it is expected to succeed. If this ioctl fails with -EAGAIN, the user 326*4882a593Smuzhiyun can either retry the operation or treat it as a failure. 327*4882a593Smuzhiyun 328*4882a593SmuzhiyunDK_CXLFLASH_VERIFY 329*4882a593Smuzhiyun------------------ 330*4882a593Smuzhiyun This ioctl is used to detect various changes such as the capacity of 331*4882a593Smuzhiyun the disk changing, the number of LUNs visible changing, etc. In cases 332*4882a593Smuzhiyun where the changes affect the application (such as a LUN resize), the 333*4882a593Smuzhiyun cxlflash driver will report the changed state to the application. 334*4882a593Smuzhiyun 335*4882a593Smuzhiyun The user calls in when they want to validate that a LUN hasn't been 336*4882a593Smuzhiyun changed in response to a check condition. As the user is operating out 337*4882a593Smuzhiyun of band from the kernel, they will see these types of events without 338*4882a593Smuzhiyun the kernel's knowledge. When encountered, the user's architected 339*4882a593Smuzhiyun behavior is to call in to this ioctl, indicating what they want to 340*4882a593Smuzhiyun verify and passing along any appropriate information. For now, only 341*4882a593Smuzhiyun verifying a LUN change (ie: size different) with sense data is 342*4882a593Smuzhiyun supported. 343*4882a593Smuzhiyun 344*4882a593SmuzhiyunDK_CXLFLASH_RECOVER_AFU 345*4882a593Smuzhiyun----------------------- 346*4882a593Smuzhiyun This ioctl is used to drive recovery (if such an action is warranted) 347*4882a593Smuzhiyun of a specified user context. Any state associated with the user context 348*4882a593Smuzhiyun is re-established upon successful recovery. 349*4882a593Smuzhiyun 350*4882a593Smuzhiyun User contexts are put into an error condition when the device needs to 351*4882a593Smuzhiyun be reset or is terminating. Users are notified of this error condition 352*4882a593Smuzhiyun by seeing all 0xF's on an MMIO read. Upon encountering this, the 353*4882a593Smuzhiyun architected behavior for a user is to call into this ioctl to recover 354*4882a593Smuzhiyun their context. A user may also call into this ioctl at any time to 355*4882a593Smuzhiyun check if the device is operating normally. If a failure is returned 356*4882a593Smuzhiyun from this ioctl, the user is expected to gracefully clean up their 357*4882a593Smuzhiyun context via release/detach ioctls. Until they do, the context they 358*4882a593Smuzhiyun hold is not relinquished. The user may also optionally exit the process 359*4882a593Smuzhiyun at which time the context/resources they held will be freed as part of 360*4882a593Smuzhiyun the release fop. 361*4882a593Smuzhiyun 362*4882a593Smuzhiyun When the DK_CXLFLASH_APP_CLOSE_ADAP_FD flag was returned on a successful 363*4882a593Smuzhiyun attach, the application _must_ unmap and close the fd2 associated with the 364*4882a593Smuzhiyun original context following this ioctl returning success and indicating that 365*4882a593Smuzhiyun the context was recovered (DK_CXLFLASH_RECOVER_AFU_CONTEXT_RESET). 366*4882a593Smuzhiyun 367*4882a593SmuzhiyunDK_CXLFLASH_MANAGE_LUN 368*4882a593Smuzhiyun---------------------- 369*4882a593Smuzhiyun This ioctl is used to switch a LUN from a mode where it is available 370*4882a593Smuzhiyun for file-system access (legacy), to a mode where it is set aside for 371*4882a593Smuzhiyun exclusive user space access (superpipe). In case a LUN is visible 372*4882a593Smuzhiyun across multiple ports and adapters, this ioctl is used to uniquely 373*4882a593Smuzhiyun identify each LUN by its World Wide Node Name (WWNN). 374*4882a593Smuzhiyun 375*4882a593Smuzhiyun 376*4882a593SmuzhiyunCXL Flash Driver Host IOCTLs 377*4882a593Smuzhiyun============================ 378*4882a593Smuzhiyun 379*4882a593Smuzhiyun Each host adapter instance that is supported by the cxlflash driver 380*4882a593Smuzhiyun has a special character device associated with it to enable a set of 381*4882a593Smuzhiyun host management function. These character devices are hosted in a 382*4882a593Smuzhiyun class dedicated for cxlflash and can be accessed via `/dev/cxlflash/*`. 383*4882a593Smuzhiyun 384*4882a593Smuzhiyun Applications can be written to perform various functions using the 385*4882a593Smuzhiyun host ioctl APIs below. 386*4882a593Smuzhiyun 387*4882a593Smuzhiyun The structure definitions for these IOCTLs are available in: 388*4882a593Smuzhiyun uapi/scsi/cxlflash_ioctl.h 389*4882a593Smuzhiyun 390*4882a593SmuzhiyunHT_CXLFLASH_LUN_PROVISION 391*4882a593Smuzhiyun------------------------- 392*4882a593Smuzhiyun This ioctl is used to create and delete persistent LUNs on cxlflash 393*4882a593Smuzhiyun devices that lack an external LUN management interface. It is only 394*4882a593Smuzhiyun valid when used with AFUs that support the LUN provision capability. 395*4882a593Smuzhiyun 396*4882a593Smuzhiyun When sufficient space is available, LUNs can be created by specifying 397*4882a593Smuzhiyun the target port to host the LUN and a desired size in 4K blocks. Upon 398*4882a593Smuzhiyun success, the LUN ID and WWID of the created LUN will be returned and 399*4882a593Smuzhiyun the SCSI bus can be scanned to detect the change in LUN topology. Note 400*4882a593Smuzhiyun that partial allocations are not supported. Should a creation fail due 401*4882a593Smuzhiyun to a space issue, the target port can be queried for its current LUN 402*4882a593Smuzhiyun geometry. 403*4882a593Smuzhiyun 404*4882a593Smuzhiyun To remove a LUN, the device must first be disassociated from the Linux 405*4882a593Smuzhiyun SCSI subsystem. The LUN deletion can then be initiated by specifying a 406*4882a593Smuzhiyun target port and LUN ID. Upon success, the LUN geometry associated with 407*4882a593Smuzhiyun the port will be updated to reflect new number of provisioned LUNs and 408*4882a593Smuzhiyun available capacity. 409*4882a593Smuzhiyun 410*4882a593Smuzhiyun To query the LUN geometry of a port, the target port is specified and 411*4882a593Smuzhiyun upon success, the following information is presented: 412*4882a593Smuzhiyun 413*4882a593Smuzhiyun - Maximum number of provisioned LUNs allowed for the port 414*4882a593Smuzhiyun - Current number of provisioned LUNs for the port 415*4882a593Smuzhiyun - Maximum total capacity of provisioned LUNs for the port (4K blocks) 416*4882a593Smuzhiyun - Current total capacity of provisioned LUNs for the port (4K blocks) 417*4882a593Smuzhiyun 418*4882a593Smuzhiyun With this information, the number of available LUNs and capacity can be 419*4882a593Smuzhiyun can be calculated. 420*4882a593Smuzhiyun 421*4882a593SmuzhiyunHT_CXLFLASH_AFU_DEBUG 422*4882a593Smuzhiyun--------------------- 423*4882a593Smuzhiyun This ioctl is used to debug AFUs by supporting a command pass-through 424*4882a593Smuzhiyun interface. It is only valid when used with AFUs that support the AFU 425*4882a593Smuzhiyun debug capability. 426*4882a593Smuzhiyun 427*4882a593Smuzhiyun With exception of buffer management, AFU debug commands are opaque to 428*4882a593Smuzhiyun cxlflash and treated as pass-through. For debug commands that do require 429*4882a593Smuzhiyun data transfer, the user supplies an adequately sized data buffer and must 430*4882a593Smuzhiyun specify the data transfer direction with respect to the host. There is a 431*4882a593Smuzhiyun maximum transfer size of 256K imposed. Note that partial read completions 432*4882a593Smuzhiyun are not supported - when errors are experienced with a host read data 433*4882a593Smuzhiyun transfer, the data buffer is not copied back to the user. 434