cxlflash: Base support for IBM CXL Flash Adapter
Subsystems (2)
RFC PATCH 1/2 cxlflash: Base support for IBM CXL Flash Adapter
SCSI device driver to support filesystem access on the IBM CXL Flash adapter.
--- Documentation/powerpc/cxlflash.txt | 275 +++++ drivers/scsi/Kconfig | 1 + drivers/scsi/Makefile | 1 + drivers/scsi/cxlflash/Kconfig | 11 + drivers/scsi/cxlflash/Makefile | 4 + drivers/scsi/cxlflash/common.h | 287 +++++ drivers/scsi/cxlflash/main.c | 2081 ++++++++++++++++++++++++++++++++++++ drivers/scsi/cxlflash/main.h | 124 +++ drivers/scsi/cxlflash/sislite.h | 407 +++++++ 9 files changed, 3191 insertions(+) create mode 100644 Documentation/powerpc/cxlflash.txt create mode 100644 drivers/scsi/cxlflash/Kconfig create mode 100644 drivers/scsi/cxlflash/Makefile create mode 100644 drivers/scsi/cxlflash/common.h create mode 100644 drivers/scsi/cxlflash/main.c create mode 100644 drivers/scsi/cxlflash/main.h create mode 100755 drivers/scsi/cxlflash/sislite.h
Documentation/powerpc/cxlflash.txt new file +275 -0
@@ -0,0 +1,275 @@ +Introduction +============ + + The IBM Power architecture provides support for CAPI (Coherent + Accelerator Power Interface), which is available to certain PCIe + slots on Power 8 systems. CAPI can be thought of as a special + tunneling protocol through PCIe that allow PCIe adapters to look + like special purpose co-processors which can read or write an + application's memory and generate page faults. As a result, the + host interface to an adapter running in CAPI mode do not require + the data buffers to be mapped to the device's memory (IOMMU bypass) + nor does it require memory to be pinned. + + On Linux, Coherent Accelerator (CXL) kernel services present CAPI + devices as a PCI device by implementing a virtual PCI host bridge. + This abstraction simplifies the infrastructure and programming model, + allowing for drivers to look similar to other native PCI device drivers. + + CXL provides a mechanism by which user space applications can + directly talk to a device (network or storage) bypassing the + typical kernel/device driver stack. The CXL Flash Adapter Driver + enables a user space application direct access to Flash storage. + + The CXL Flash Adapter Driver is a kernel module that sits in + the SCSI stack as a low level device driver (below the SCSI disk + and protocol drivers) for the IBM CXL Flash Adapter. This driver + is responsible for the initialization of the adapter, setting up + the special path for user space access, and performing error + recovery. It communicates directly the Flash Accelerator Functional + Unit (AFU) as described in Documentation/powerpc/cxl.txt. + + The cxlflash driver supports two, mutually exclusive, modes of + operation at the device (LUN) level: + + - Any flash device (LUN) can be configured to be accessed as a + regular disk device (ie: /dev/sdc). This is the default mode. + + - Any flash device (LUN) can be configured to be accessed from + user space with a special block library. This mode further + specifies the means of accessing the device and provides for + either raw access to the entire LUN (referred to as direct or + physical LUN access) or access to a kernel/AFU-mediated partition + of the LUN (referred to as virtual LUN access). The segmentation + of a disk device into virtual LUNs is assisted by special + translation services provided by the Flash AFU. + +Overview +======== + + The Coherent Accelerator Interface Architecture (CAIA) introduces + a concept of a master context. A master typically has special + privileges granted to it by the kernel or hypervisor allowing + it to perform AFU wide management and control. The master may or + may not be involved directly in each user I/O, but at the minimum + is involved in the initial setup before the user application is + allowed to send requests directly to the AFU. + + The CXL Flash Adapter Driver establishes a master context with + the AFU. It uses memory mapped I/O (MMIO) for this control and + setup. The Adapter Problem Space Memory Map looks like this: + + +-------------------------------+ + | 512 * 64 KB User MMIO | + | (per context) | + | User Accessible | + +-------------------------------+ + | 512 * 128 B per context | + | Provisioning and Control | + | Trusted Process accessible | + +-------------------------------+ + | 64 KB Global | + | Trusted Process accessible | + +-------------------------------+ + + This driver configures itself into the SCSI software stack + as an adapter driver. The driver is the only entity that + is considered a Trusted Process to program the Provisioning and + Control and Global areas in the MMIO Space shown above. + The master context driver discovers all LUNs attached to the + CXL Flash adapter and instantiates scsi block devices + (/dev/sdb, /dev/sdc etc.) for each unique LUN seen from each path. + + Once these scsi block devices are instantiated, an application + written to a specification provided by the block library may + get access to the Flash from user space (without requiring + a system call). + + This master context driver also provides a series of ioctls + for this block library to enable this user space access. + The driver supports two modes for accessing the block device. + + The first mode is called a virtual mode. In this mode a single + scsi block device (/dev/sdb) may be carved up into any number + of distinct virtual LUNs. The virtual LUNs may be resized as long + as the sum of the sizes of all the virtual LUNs, along with + the meta-data associated with it does not exceed the physical + capacity. + + The second mode is called the physical mode. IN this mode a + single block device (/dev/sdb) may be opened directly by + the block library and the entire space for the LUN is available + to the application. + + Only the physical mode provides persistence of the data. + i.e. The data written to the block device will survive application + exit and restart and also reboot. The virtual LUNs do not + persist (i.e. do not survive after the application terminates or + the system reboots). + + +Block library API +================= + + Applications intending to get access to the CXL Flash from user + space should use the block library, as it abstracts the details + of interfacing directly with the cxlflash driver that are necessary + for performing administrative actions (i.e.: setup, tear down, resize). + The block library can be thought of as a 'user' of services, implemented + as IOCTLs, that are provided by the cxlflash driver specifically for + devices (LUNs) operating in user space access mode. While it is not + a requirement that applications understand the interface between the + block library and the cxlflash driver, a high-level overview of each + supported service (IOCTL) is provided below. + + The block library can be found on GitHub: + http://www.github.com/mikehollinger/ibmcapikv + + +CXL Flash Driver IOCTLs +======================= + + Users, such as the block library, that wish to interface with a + flash device (LUN) via user space access need to use the services + provided by the cxlflash driver. As these services are implemented + as ioctls, a file descriptor handle must first be obtained in order + to establish the communication channel between a user and the kernel. + This file descriptor is obtained by opening the device special file + associated with the scsi disk device (/dev/sdb) that was created + during LUN discovery. As per the location of the cxlflash driver within + the SCSI protocol stack, this open is actually not seen by the cxlflash + driver. Upon successful open, the user receives a file descriptor + (herein referred to as fd1) that should be used for issuing the + subsequent ioctls listed below. + + The structure definitions for these IOCTLs are available in: + uapi/scsi/cxlflash_ioctl.h + +DK_CXLFLASH_ATTACH +------------------ + + This ioctl obtains, initializes, and starts a context using the CXL + kernel services. These services specify a context id (u16) by which + to uniquely identify the context and its allocated resources. The + services additionally provide a second file descriptor (herein + referred to as fd2) that is used by the block library to initiate + memory mapped I/O (via mmap()) to the CXL flash device and poll for + completion events. This file descriptor is intentionally installed by + this driver and not the CXL kernel services to allow for intermediary + notification and access in the event of a non-user-initiated close(), + such as a killed process. This design point is described in further + detail in the description for the DK_CXLFLASH_DETACH ioctl. + + There are a few important aspects regarding the "tokens" (context id + and fd2) that are provided back to the user: + + - These tokens are only valid for the process under which they + were created. The child of a forked process cannot continue + to use the context id or file descriptor created by its parent + (see DK_CXLFLASH_CLONE for further details). + + - These tokens are only valid for the lifetime of the context and + the process under which they were created. Once either is destroyed, + the tokens are to be considered stale and subsequent usage will + result in errors. + + - When a context is no longer needed, the user shall detach from + the context via the DK_CXLFLASH_DETACH ioctl. + + - A close on fd2 will invalidate the tokens. This operation is not + required by the user. + +DK_CXLFLASH_USER_DIRECT +----------------------- + This ioctl is responsible for transitioning the LUN to direct (physical) + mode access and configuring the AFU for direct access from user space on + a per-context basis. Additionally, the block size and last logical block + address (LBA) are returned to the user. + + As mentioned previously, when operating in user space access mode, LUNs + may be accessed in whole or in part. Only one mode is allowed at a time + and if one mode is active (outstanding references exist), requests to use + the LUN in a different mode are denied. + + The AFU is configured for direct access from user space by adding an entry + to the AFU's resource handle table. The index of the entry is treated as a + resource handle that is returned to the user. The user is then able to use + the handle to reference the LUN during I/O. + +DK_CXLFLASH_USER_VIRTUAL +------------------------ + This ioctl is responsible for transitioning the LUN to virtual mode of + access and configuring the AFU for virtual access from user space on a + per-context basis. Additionally, the block size and last logical block + address (LBA) are returned to the user. + + As mentioned previously, when operating in user space access mode, LUNs + may be accessed in whole or in part. Only one mode is allowed at a time + and if one mode is active (outstanding references exist), requests to use + the LUN in a different mode are denied. + + The AFU is configured for virtual access from user space by adding an entry + to the AFU's resource handle table. The index of the entry is treated as a + resource handle that is returned to the user. The user is then able to use + the handle to reference the LUN during I/O. + + By default, the virtual LUN is created with a size of 0. The user would + need to use the DK_CXLFLASH_VLUN_RESIZE ioctl to adjust the grow the virtual + LUN to a desired size. To avoid having to perform this resize for the + initial creation of the virtual LUN, the user has the option of specifying + a size as part of the DK_CXLFLASH_USER_VIRTUAL ioctl, such that when success + is returned to the user, the resource handle that is provided is already + referencing provisioned storage. This is reflected by the last LBA being + a non-zero value. + +DK_CXLFLASH_VLUN_RESIZE +----------------------- + This ioctl is responsible for resizing a previously created virtual LUN + and will fail if invoked upon a LUN that is not in virtual mode. Upon + success, an updated last LBA is returned to the user indicating the new + size of the virtual LUN associated with the resource handle. + + The partitioning of virtual LUNs is jointly mediated by the cxlflash driver + and the AFU. An allocation table is kept for each LUN that is operating + in the virtual mode and used to program a LUN translation table that the + AFU references when provided with a resource handle. + +DK_CXLFLASH_RELEASE +------------------- + This ioctl is responsible for releasing a previously obtained reference + to either a physical or virtual LUN. This can be thought of as the inverse + of the DK_CXLFLASH_USER_DIRECT or DK_CXLFLASH_USER_VIRTUAL ioctls. Upon + success, the resource handle is no longer valid and the entry in the + resource handle table is made available to be used again. + + As part of the release process for virtual LUNs, the virtual LUN is first + resized to 0 to clear out and free the translation tables associated with + the virtual LUN reference. + +DK_CXLFLASH_DETACH +------------------ + This ioctl is responsible for unregistering a context with the cxlflash + driver and release outstanding resources that were not explicitly released + via the DK_CXLFLASH_RELEASE ioctl. Upon success, all "tokens" which had been + provided to the user from the DK_CXLFLASH_ATTACH onward are no longer valid. + +DK_CXLFLASH_CLONE +----------------- + This ioctl is responsible for cloning a previously created context to a more + recently created context. It exists solely to support maintaining user space + access to storage after a process forks. Upon success, the child process + (which invoked the ioctl) will have access to the same LUNs via the same + resource handle(s) and fd2 as the parent, but under a different context. + + Context sharing across processes is not supported with CXL and + therefore each fork must be met with establishing a new context for the + child process. This ioctl simplifies the state management and playback + required by a user in such a scenario. When a process forks, child + process can clone the parents context by first creating a context + (via DK_CXLFLASH_ATTACH) and then using this ioctl to perform the clone + from the parent to the child. + + The clone itself is fairly simple. The resource handle and lun + translation tables are copied from the parent context to the child's + and then synced with the AFU. +
drivers/scsi/Kconfig +1 -0
@@ -345,6 +345,7 @@ source "drivers/scsi/cxgbi/Kconfig" source "drivers/scsi/bnx2i/Kconfig" source "drivers/scsi/bnx2fc/Kconfig" source "drivers/scsi/be2iscsi/Kconfig" +source "drivers/scsi/cxlflash/Kconfig" config SGIWD93_SCSI tristate "SGI WD93C93 SCSI Driver"
drivers/scsi/Makefile +1 -0
@@ -101,6 +101,7 @@ obj-$(CONFIG_SCSI_7000FASST) += wd7000.o obj-$(CONFIG_SCSI_EATA) += eata.o obj-$(CONFIG_SCSI_DC395x) += dc395x.o obj-$(CONFIG_SCSI_AM53C974) += esp_scsi.o am53c974.o +obj-$(CONFIG_CXLFLASH) += cxlflash/ obj-$(CONFIG_MEGARAID_LEGACY) += megaraid.o obj-$(CONFIG_MEGARAID_NEWGEN) += megaraid/ obj-$(CONFIG_MEGARAID_SAS) += megaraid/
drivers/scsi/cxlflash/Kconfig new file +11 -0
@@ -0,0 +1,11 @@ +# +# IBM CXL-attached Flash Accelerator SCSI Driver +# + +config CXLFLASH + tristate "Support for IBM CAPI Flash" + depends on CXL + default m + help + Allows CAPI Accelerated IO to Flash + If unsure, say N.
drivers/scsi/cxlflash/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +obj-$(CONFIG_CXLFLASH) += cxlflash.o +cxlflash-y += main.o + +ccflags-y += -DCONFIG_PRINTK
drivers/scsi/cxlflash/common.h new file +287 -0
287 lines not on this page · raw message
drivers/scsi/cxlflash/main.c new file +2081 -0
2,081 lines not on this page · raw message
drivers/scsi/cxlflash/main.h new file +124 -0
124 lines not on this page · raw message
drivers/scsi/cxlflash/sislite.h new file +407 -0
204 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.1.0
Part of the diff is not shown here. View the raw message.
Quoted 1 line · Matthew R. Ochs
SCSI device driver to support filesystem access on the IBM CXL Flash adapter.
Please drop all the code related to your weird direct access ioctls from this patch. Without that it looks mostly mergeable.
Hi Christoph,
Thank you for looking at this RFC.
Quoted 6 lines · Christoph Hellwig
Quoted 1 line · Matthew R. Ochs
SCSI device driver to support filesystem access on the IBM CXL Flash adapter.
Please drop all the code related to your weird direct access ioctls from this patch. Without that it looks mostly mergeable.
Could you expand more on your objection <to the second patch>? Are you generally opposed to a kernel bypass or is there something specific regarding our implementation to solving the problem (ioctls)?
One of the key features we were hoping to provide with this driver is a kernel bypass. This device has a very unique MMU interface that allows user applications and hardware to share memory directly. The problem we ran into is how to configure and manage that access. The device is very SCSI-like and since we were implementing a SCSI adapter driver to support filesystem access for traditional use cases, the ioctls seemed to be a reasonable solution.
-matt
Quoted 8 lines · Matthew R. Ochs
Quoted 4 lines · Christoph Hellwig
Please drop all the code related to your weird direct access ioctls from this patch. Without that it looks mostly mergeable.
Could you expand more on your objection <to the second patch>? Are you generally opposed to a kernel bypass or is there something specific regarding our implementation to solving the problem (ioctls)?
One of the key features we were hoping to provide with this driver is a kernel bypass. This device has a very unique MMU interface that allows user applications and hardware to share memory directly. The problem we ran into is how to configure and manage that access. The device is very SCSI-like and since we were implementing a SCSI adapter driver to support filesystem access for traditional use cases, the ioctls seemed to be a reasonable solution.
We're going to proceed with submitting the first patch that contains filesystem access while the discussion continues regarding how best to implement the kernel bypass feature.
-matt
Christoph,
Quoted 5 lines · Matthew R. Ochs
Quoted 1 line
SCSI device driver to support filesystem access on the IBM CXL Flash adapter.
Please drop all the code related to your weird direct access ioctls from this patch. Without that it looks mostly mergeable.
What's your issue with this? Do you just not like direct access at all, or the way it's been done?
The CAPI hardware allows devices to have direct access to userspace memory via an MMU. What this driver is doing is enabling this direct access so the flash controller can share memory (like queues) directly with userspace without the kernel overhead.
Mikey
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Matthew R. Ochs
Sent: Monday, April 27, 2015 2:50 PM
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Manoj N. Kumar
Subject: [PATCH RFC 1/2] cxlflash: Base support for IBM CXL Flash Adapter
Quoted 20 lines
drivers/scsi/cxlflash/main.c new file +20
-0+static ssize_t cxlflash_show_port_status (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct Scsi_Host *shost =class_to_shost (dev); +struct cxlflash *cxlflash = (struct cxlflash *)shost->hostdata; +struct afu *afu = cxlflash->afu; + +char *disp_status; +int rc; +u32 port; +u64 status; +volatile u64 *fc_regs; + + rc =kstrtouint ((attr->attr.name +4 ),10 , &port); +if (rc || (port >NUM_FC_PORTS )) +return 0 ; + + fc_regs = &afu->afu_map->global.fc_regs[port][0 ]; + status =
drivers/scsi/cxlflash/main.c line 538
Quoted 10 lines
drivers/scsi/cxlflash/main.c new file +10
-0+ (readq_be (&fc_regs[FC_MTIP_STATUS /8 ]) &FC_MTIP_STATUS_MASK ); + +if (status ==FC_MTIP_STATUS_ONLINE ) + disp_status ="online" ; +else if (status ==FC_MTIP_STATUS_OFFLINE ) + disp_status ="offline" ; +else + disp_status ="unknown" ; + +return snprintf (buf,PAGE_SIZE ,"%s\n" , disp_status);
You need to use scnprintf() instead of snprintf() here
drivers/scsi/cxlflash/main.c line 548
Quoted 8 lines
drivers/scsi/cxlflash/main.c new file +8
-0+static ssize_t cxlflash_show_lun_mode (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct Scsi_Host *shost =class_to_shost (dev); +struct cxlflash *cxlflash = (struct cxlflash *)shost->hostdata; +struct afu *afu = cxlflash->afu; + +return snprintf (buf,PAGE_SIZE ,"%u\n" , afu->internal_lun);
See above about snprintf()
+static DEVICE_ATTR(port0, S_IRUGO, cxlflash_show_port_status, NULL); +static DEVICE_ATTR(port1, S_IRUGO, cxlflash_show_port_status, NULL); +static DEVICE_ATTR(lun_mode, S_IRUGO | S_IWUSR, cxlflash_show_lun_mode,
+ cxlflash_store_lun_mode);
Please use DEVICE_ATTR_RO and DEVICE_ATTR_RW as appropriate if you can, you will need to change the show/store function names. The main reason I know for doing this is (using DEVICE_ATTR_RO as an example) if someone sees a sysfs attribute called port0 or port1 they should be able to search the kernel source to find a function called port0_show or port1_show without having to spend any extra time searching to find out what the driver is and then look at the driver source to find that they need to look at cxlflash_show_port_status. Using DEVICE_ATTR_RO for port0 and port1 would probably change the code to looking something like this:
static ssize_t cxlflash_show_port_status(u32 port,
struct afu *afu, char *buf)
{
char *disp_status;
u64 status;
volatile u64 *fc_regs;
fc_regs = &afu->afu_map->global.fc_regs[port][0];
/* I split this line into two because I had to really look at where
* the brackets were and this made it more obvious to me
* what it was doing but that could just be me. */
status = readq_be(&fc_regs[FC_MTIP_STATUS / 8]);
status &= FC_MTIP_STATUS_MASK;
if (status == FC_MTIP_STATUS_ONLINE)
disp_status = "online";
else if (status == FC_MTIP_STATUS_OFFLINE)
disp_status = "offline";
else
disp_status = "unknown";
return scnprintf(buf, PAGE_SIZE, "%s\n", disp_status);
}Since you have fixed values you could use also sprintf here (although the documentation currently says to only use scnprintf) and that would make port0_show and port1_show to be:
static ssize_t port0_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct Scsi_Host *shost = class_to_shost(dev);
struct cxlflash *cxlflash = (struct cxlflash *)shost->hostdata;
struct afu *afu = cxlflash->afu;
return cxlflash_show_port_status(0, afu, buf);
}static ssize_t port1_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct Scsi_Host *shost = class_to_shost(dev);
struct cxlflash *cxlflash = (struct cxlflash *)shost->hostdata;
struct afu *afu = cxlflash->afu;
return cxlflash_show_port_status(1, afu, buf);
}I'm assuming that 0 and 1 are always valid for port number and don't need to be checked against NUM_FC_PORTS. That's just a suggestion and I haven't attempted to compile the above example and you'd need to test it to make sure that they still work as expected.
Shane
Shane,
All great suggestions.
I've gone ahead and implemented these and also applied your comments to our other attributes as well. Will include in our next push of fixes.
-matt
Quoted 110 lines · Shane M
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Matthew R. Ochs
Sent: Monday, April 27, 2015 2:50 PM
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Manoj N. Kumar
Subject: [PATCH RFC 1/2] cxlflash: Base support for IBM CXL Flash AdapterQuoted 20 lines
drivers/scsi/cxlflash/main.c new file +20
-0+static ssize_t cxlflash_show_port_status (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct Scsi_Host *shost =class_to_shost (dev); +struct cxlflash *cxlflash = (struct cxlflash *)shost->hostdata; +struct afu *afu = cxlflash->afu; + +char *disp_status; +int rc; +u32 port; +u64 status; +volatile u64 *fc_regs; + + rc =kstrtouint ((attr->attr.name +4 ),10 , &port); +if (rc || (port >NUM_FC_PORTS )) +return 0 ; + + fc_regs = &afu->afu_map->global.fc_regs[port][0 ]; + status =drivers/scsi/cxlflash/main.c line 538
Quoted 10 lines
drivers/scsi/cxlflash/main.c new file +10
-0+ (readq_be (&fc_regs[FC_MTIP_STATUS /8 ]) &FC_MTIP_STATUS_MASK ); + +if (status ==FC_MTIP_STATUS_ONLINE ) + disp_status ="online" ; +else if (status ==FC_MTIP_STATUS_OFFLINE ) + disp_status ="offline" ; +else + disp_status ="unknown" ; + +return snprintf (buf,PAGE_SIZE ,"%s\n" , disp_status);You need to use
scnprintf()instead ofsnprintf()heredrivers/scsi/cxlflash/main.c line 548
Quoted 8 lines
drivers/scsi/cxlflash/main.c new file +8
-0+static ssize_t cxlflash_show_lun_mode (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct Scsi_Host *shost =class_to_shost (dev); +struct cxlflash *cxlflash = (struct cxlflash *)shost->hostdata; +struct afu *afu = cxlflash->afu; + +return snprintf (buf,PAGE_SIZE ,"%u\n" , afu->internal_lun);See above about
snprintf()drivers/scsi/cxlflash/main.c new file +4
-0+static DEVICE_ATTR(port0, S_IRUGO, cxlflash_show_port_status, NULL); +static DEVICE_ATTR(port1, S_IRUGO, cxlflash_show_port_status, NULL); +static DEVICE_ATTR(lun_mode, S_IRUGO | S_IWUSR, cxlflash_show_lun_mode, + cxlflash_store_lun_mode);Please use
DEVICE_ATTR_ROandDEVICE_ATTR_RWas appropriate if you can, you will need to change the show/store function names. The main reason I know for doing this is (usingDEVICE_ATTR_ROas an example) if someone sees a sysfs attribute called port0 or port1 they should be able to search the kernel source to find a function calledport0_showorport1_showwithout having to spend any extra time searching to find out what the driver is and then look at the driver source to find that they need to look atcxlflash_show_port_status. UsingDEVICE_ATTR_ROfor port0 and port1 would probably change the code to looking something like this:static
ssize_tcxlflash_show_port_status(u32 port,
struct afu *afu, char *buf){ char *disp_status; u64 status; volatile u64 *fc_regs; fc_regs = &afu->afu_map->global.fc_regs[port][0]; /* I split this line into two because I had to really look at where * the brackets were and this made it more obvious to me * what it was doing but that could just be me. */ status = readq_be(&fc_regs[FC_MTIP_STATUS / 8]); status &= FC_MTIP_STATUS_MASK; if (status == FC_MTIP_STATUS_ONLINE) disp_status = "online"; else if (status == FC_MTIP_STATUS_OFFLINE) disp_status = "offline"; else disp_status = "unknown"; return scnprintf(buf, PAGE_SIZE, "%s\n", disp_status); }Since you have fixed values you could use also sprintf here (although the documentation currently says to only use scnprintf) and that would make
port0_showandport1_showto be:static
ssize_tport0_show(struct device *dev,
structdevice_attribute*attr,
char *buf){ struct Scsi_Host *shost = class_to_shost(dev); struct cxlflash *cxlflash = (struct cxlflash *)shost->hostdata; struct afu *afu = cxlflash->afu; return cxlflash_show_port_status(0, afu, buf); }static
ssize_tport1_show(struct device *dev,
structdevice_attribute*attr,
char *buf){ struct Scsi_Host *shost = class_to_shost(dev); struct cxlflash *cxlflash = (struct cxlflash *)shost->hostdata; struct afu *afu = cxlflash->afu; return cxlflash_show_port_status(1, afu, buf); }I'm assuming that 0 and 1 are always valid for port number and don't need to be checked against
NUM_FC_PORTS. That's just a suggestion and I haven't attempted to compile the above example and you'd need to test it to make sure that they still work as expected.Shane