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

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