Blame SOURCES/0099-Documentation-Enhance-libcxl-memdev-API-documentatio.patch

26ccd9
From 7b9ed7e065c6de029385d40de1f7cb0aed3a9108 Mon Sep 17 00:00:00 2001
26ccd9
From: Dan Williams <dan.j.williams@intel.com>
26ccd9
Date: Sun, 23 Jan 2022 16:52:57 -0800
26ccd9
Subject: [PATCH 099/217] Documentation: Enhance libcxl memdev API
26ccd9
 documentation
26ccd9
26ccd9
In preparation for adding documentation for more objects, organize the
26ccd9
current into subsections and flesh out descriptions for the current APIs.
26ccd9
26ccd9
Link: https://lore.kernel.org/r/164298557771.3021641.14904324834528700206.stgit@dwillia2-desk3.amr.corp.intel.com
26ccd9
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
26ccd9
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
26ccd9
---
26ccd9
 Documentation/copyright.txt      |   2 +-
26ccd9
 Documentation/cxl/lib/libcxl.txt | 111 +++++++++++++++++++++++++++----
26ccd9
 2 files changed, 99 insertions(+), 14 deletions(-)
26ccd9
26ccd9
diff --git a/Documentation/copyright.txt b/Documentation/copyright.txt
26ccd9
index a9380e1..af9caf7 100644
26ccd9
--- a/Documentation/copyright.txt
26ccd9
+++ b/Documentation/copyright.txt
26ccd9
@@ -2,7 +2,7 @@
26ccd9
 
26ccd9
 COPYRIGHT
26ccd9
 ---------
26ccd9
-Copyright (C) 2016 - 2020, Intel Corporation. License GPLv2: GNU GPL
26ccd9
+Copyright (C) 2016 - 2022, Intel Corporation. License GPLv2: GNU GPL
26ccd9
 version 2 <http://gnu.org/licenses/gpl.html>.  This is free software:
26ccd9
 you are free to change and redistribute it.  There is NO WARRANTY, to
26ccd9
 the extent permitted by law.
26ccd9
diff --git a/Documentation/cxl/lib/libcxl.txt b/Documentation/cxl/lib/libcxl.txt
26ccd9
index 2539369..c127326 100644
26ccd9
--- a/Documentation/cxl/lib/libcxl.txt
26ccd9
+++ b/Documentation/cxl/lib/libcxl.txt
26ccd9
@@ -20,27 +20,100 @@ libcxl provides interfaces to interact with CXL devices in Linux, using sysfs
26ccd9
 interfaces for most kernel interactions, and the ioctl() interface for command
26ccd9
 submission.
26ccd9
 
26ccd9
-The starting point for all library interfaces is a 'cxl_ctx' object, returned
26ccd9
-by linklibcxl:cxl_new[3]. CXL 'Type 3' memory devices are children of the
26ccd9
-cxl_ctx object, and can be iterated through using an iterator API.
26ccd9
+The starting point for all library interfaces is a 'cxl_ctx' object,
26ccd9
+returned by linklibcxl:cxl_new[3]. CXL 'Type 3' memory devices and other
26ccd9
+CXL device objects are descendants of the cxl_ctx object, and can be
26ccd9
+iterated via an object an iterator API of the form
26ccd9
+cxl_<object>_foreach(<parent object>, <object iterator>).
26ccd9
 
26ccd9
-Library level interfaces that are agnostic to any device, or a specific
26ccd9
-subclass of operations have the prefix 'cxl_'
26ccd9
+MEMDEVS
26ccd9
+-------
26ccd9
+The object representing a CXL memory expander (Type 3 device) is 'struct
26ccd9
+cxl_memdev'. Library interfaces related to these devices have the prefix
26ccd9
+'cxl_memdev_'. These interfaces are mostly associated with sysfs
26ccd9
+interactions (unless otherwise noted in their respective documentation
26ccd9
+sections). They are typically used to retrieve data published by the
26ccd9
+kernel, or to send data or trigger kernel operations for a given device.
26ccd9
 
26ccd9
-The object representing a CXL Type 3 device is 'cxl_memdev'. Library interfaces
26ccd9
-related to these devices have the prefix 'cxl_memdev_'. These interfaces are
26ccd9
-mostly associated with sysfs interactions (unless otherwise noted in their
26ccd9
-respective documentation pages). They are typically used to retrieve data
26ccd9
-published by the kernel, or to send data or trigger kernel operations for a
26ccd9
-given device.
26ccd9
+=== MEMDEV: Enumeration
26ccd9
+----
26ccd9
+struct cxl_memdev *cxl_memdev_get_first(struct cxl_ctx *ctx);
26ccd9
+struct cxl_memdev *cxl_memdev_get_next(struct cxl_memdev *memdev);
26ccd9
+struct cxl_ctx *cxl_memdev_get_ctx(struct cxl_memdev *memdev);
26ccd9
+
26ccd9
+#define cxl_memdev_foreach(ctx, memdev) \
26ccd9
+        for (memdev = cxl_memdev_get_first(ctx); \
26ccd9
+             memdev != NULL; \
26ccd9
+             memdev = cxl_memdev_get_next(memdev))
26ccd9
+
26ccd9
+----
26ccd9
+
26ccd9
+CXL memdev instances are enumerated from the global library context
26ccd9
+'struct cxl_ctx'. By default a memdev only offers a portal to submit
26ccd9
+memory device commands, see the port, decoder, and endpoint APIs to
26ccd9
+determine what if any CXL Memory Resources are reachable given a
26ccd9
+specific memdev.
26ccd9
+
26ccd9
+=== MEMDEV: Attributes
26ccd9
+----
26ccd9
+int cxl_memdev_get_id(struct cxl_memdev *memdev);
26ccd9
+unsigned long long cxl_memdev_get_serial(struct cxl_memdev *memdev);
26ccd9
+const char *cxl_memdev_get_devname(struct cxl_memdev *memdev);
26ccd9
+int cxl_memdev_get_major(struct cxl_memdev *memdev);
26ccd9
+int cxl_memdev_get_minor(struct cxl_memdev *memdev);
26ccd9
+unsigned long long cxl_memdev_get_pmem_size(struct cxl_memdev *memdev);
26ccd9
+unsigned long long cxl_memdev_get_ram_size(struct cxl_memdev *memdev);
26ccd9
+const char *cxl_memdev_get_firmware_verison(struct cxl_memdev *memdev);
26ccd9
+size_t cxl_memdev_get_label_size(struct cxl_memdev *memdev);
26ccd9
+int cxl_memdev_nvdimm_bridge_active(struct cxl_memdev *memdev);
26ccd9
+----
26ccd9
+
26ccd9
+A memdev is given a kernel device name of the form "mem%d" where an id
26ccd9
+(cxl_memdev_get_id()) is dynamically allocated as devices are
26ccd9
+discovered. Note that there are no guarantees that ids / kernel device
26ccd9
+names for memdevs are stable from one boot to the next, devices are
26ccd9
+enumerated asynchronously. If a stable identifier is use
26ccd9
+cxl_memdev_get_serial() which returns a value according to the 'Device
26ccd9
+Serial Number Extended Capability' in the PCIe 5.0 Base Specification.
26ccd9
+
26ccd9
+The character device node for command submission can be found by default
26ccd9
+at /dev/cxl/mem%d, or created with a major / minor returned from
26ccd9
+cxl_memdev_get_{major,minor}().
26ccd9
+
26ccd9
+The 'pmem_size' and 'ram_size' attributes return the current
26ccd9
+provisioning of DPA (Device Physical Address / local capacity) in the
26ccd9
+device.
26ccd9
+
26ccd9
+=== MEMDEV: Commands
26ccd9
+----
26ccd9
+struct cxl_cmd *cxl_cmd_new_raw(struct cxl_memdev *memdev, int opcode);
26ccd9
+struct cxl_cmd *cxl_cmd_new_identify(struct cxl_memdev *memdev);
26ccd9
+struct cxl_cmd *cxl_cmd_new_get_health_info(struct cxl_memdev *memdev);
26ccd9
+struct cxl_cmd *cxl_cmd_new_read_label(struct cxl_memdev *memdev,
26ccd9
+					unsigned int offset, unsigned int length);
26ccd9
+struct cxl_cmd *cxl_cmd_new_write_label(struct cxl_memdev *memdev, void *buf,
26ccd9
+					unsigned int offset, unsigned int length);
26ccd9
+int cxl_memdev_zero_label(struct cxl_memdev *memdev, size_t length,
26ccd9
+			  size_t offset);
26ccd9
+int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, size_t length,
26ccd9
+			  size_t offset);
26ccd9
+int cxl_memdev_write_label(struct cxl_memdev *memdev, void *buf, size_t length,
26ccd9
+			   size_t offset);
26ccd9
+
26ccd9
+----
26ccd9
 
26ccd9
 A 'cxl_cmd' is a reference counted object which is used to perform 'Mailbox'
26ccd9
 commands as described in the CXL Specification. A 'cxl_cmd' object is tied to a
26ccd9
 'cxl_memdev'. Associated library interfaces have the prefix 'cxl_cmd_'. Within
26ccd9
 this sub-class of interfaces, there are:
26ccd9
 
26ccd9
- * 'cxl_cmd_new_*' interfaces that allocate a new cxl_cmd object for a given
26ccd9
-   command type.
26ccd9
+ * 'cxl_cmd_new_*()' interfaces that allocate a new cxl_cmd object for a given
26ccd9
+   command type targeted at a given memdev. As part of the command
26ccd9
+   instantiation process the library validates that the command is
26ccd9
+   supported by the memory device, otherwise it returns NULL to indicate
26ccd9
+   'no support'. The libcxl command id is translated by the kernel into
26ccd9
+   a CXL standard opcode. See the potential command ids in
26ccd9
+   /usr/include/linux/cxl_mem.h.
26ccd9
 
26ccd9
  * 'cxl_cmd_submit' which submits the command via ioctl()
26ccd9
 
26ccd9
@@ -49,6 +122,18 @@ this sub-class of interfaces, there are:
26ccd9
 
26ccd9
  * 'cxl_cmd_get_*' interfaces to get general command related information.
26ccd9
 
26ccd9
+cxl_cmd_new_raw() supports so called 'RAW' commands where the command id
26ccd9
+is 'RAW' and it carries an unmodified CXL memory device command payload
26ccd9
+associated with the 'opcode' argument. Given the kernel does minimal
26ccd9
+input validation on these commands typically raw commands are not
26ccd9
+supported by the kernel outside debug build scenarios. libcxl is limited
26ccd9
+to supporting commands that appear in the CXL standard / public
26ccd9
+specifications.
26ccd9
+
26ccd9
+cxl_memdev{read,write,zero}_label() are helpers for marshaling multiple
26ccd9
+label access commands over an arbitrary extent of the device's label
26ccd9
+area.
26ccd9
+
26ccd9
 include::../../copyright.txt[]
26ccd9
 
26ccd9
 SEE ALSO
26ccd9
-- 
26ccd9
2.27.0
26ccd9