anitazha / rpms / ndctl

Forked from rpms/ndctl a year ago
Clone

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

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