From 1716f5a7942fcc0068512b2d2807b674d877feaa Mon Sep 17 00:00:00 2001
From: Alexey Timofeyev <alexey.timofeyev@sk.com>
Date: Thu, 28 Jun 2018 17:33:05 +0000
Subject: nvme-cli: add support of RAE

Git-commit: 97ca8c0d1008aa640e848d7606e85e0828c1cf2d
References: bsc#1076004

Currently telemetry-log cannot retain content of corresponding log page as RAE is not set.
This patch adds RAE bit support into routines to retrieve log pages.

Signed-off-by: Alexey Timofeyev <alexey.timofeyev@sk.com>
---
 Documentation/nvme-get-log.1    | 26 +++++++++++++++++----
 Documentation/nvme-get-log.html | 50 +++++++++++++++++++++++++++++++++++++----
 Documentation/nvme-get-log.txt  | 16 +++++++++++++
 nvme-ioctl.c                    |  8 +++----
 nvme-ioctl.h                    |  2 +-
 nvme.c                          |  8 +++++--
 6 files changed, 95 insertions(+), 15 deletions(-)

diff --git a/Documentation/nvme-get-log.1 b/Documentation/nvme-get-log.1
index eb36bd8..ce7f928 100644
--- a/Documentation/nvme-get-log.1
+++ b/Documentation/nvme-get-log.1
@@ -1,13 +1,13 @@
 '\" t
 .\"     Title: nvme-get-log
-.\"    Author: [FIXME: author] [see http://docbook.sf.net/el/author]
-.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
-.\"      Date: 02/02/2017
+.\"    Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
+.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
+.\"      Date: 06/28/2018
 .\"    Manual: NVMe Manual
 .\"    Source: NVMe
 .\"  Language: English
 .\"
-.TH "NVME\-GET\-LOG" "1" "02/02/2017" "NVMe" "NVMe Manual"
+.TH "NVME\-GET\-LOG" "1" "06/28/2018" "NVMe" "NVMe Manual"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
@@ -36,6 +36,9 @@ nvme-get-log \- Retrieves a log page from an NVMe device
                       [\-\-log\-len=<log\-len> | \-l <log\-len>]
                       [\-\-namespace\-id=<nsid> | \-n <nsid>]
                       [\-\-raw\-binary | \-b]
+                      [\-\-lpo=<offset> | \-o <offset>]
+                      [\-\-lsp=<field> | \-s <field>]
+                      [\-\-rae | \-r]
 .fi
 .SH "DESCRIPTION"
 .sp
@@ -65,6 +68,21 @@ Sets the command\(cqs nsid value to the given nsid\&. Defaults to 0xffffffff if
 .RS 4
 Print the raw log buffer to stdout\&.
 .RE
+.PP
+\-o <offset>, \-\-lpo=<offset>
+.RS 4
+The log page offset specifies the location within a log page to start returning data from\&. It\(cqs Dword\-aligned and 64\-bits\&.
+.RE
+.PP
+\-s <field>, \-\-lsp=<field>
+.RS 4
+The log specified field of LID\&.
+.RE
+.PP
+\-r, \-\-rae
+.RS 4
+Retain an Asynchronous Event\&.
+.RE
 .SH "EXAMPLES"
 .sp
 .RS 4
diff --git a/Documentation/nvme-get-log.html b/Documentation/nvme-get-log.html
index f139f0c..e2dcf00 100644
--- a/Documentation/nvme-get-log.html
+++ b/Documentation/nvme-get-log.html
@@ -1,9 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 <head>
 <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
-<meta name="generator" content="AsciiDoc 8.6.7" />
+<meta name="generator" content="AsciiDoc 8.6.10" />
 <title>nvme-get-log(1)</title>
 <style type="text/css">
 /* Shared CSS for AsciiDoc xhtml11 and html5 backends */
@@ -91,6 +92,9 @@ pre {
   padding: 0;
   margin: 0;
 }
+pre {
+  white-space: pre-wrap;
+}
 
 #author {
   color: #527bbd;
@@ -219,7 +223,7 @@ div.exampleblock > div.content {
 }
 
 div.imageblock div.content { padding-left: 0; }
-span.image img { border-style: none; }
+span.image img { border-style: none; vertical-align: text-bottom; }
 a.image:visited { color: white; }
 
 dl {
@@ -755,7 +759,10 @@ nvme-get-log(1) Manual Page
 <pre class="content"><em>nvme get-log</em> &lt;device&gt; [--log-id=&lt;log-id&gt; | -i &lt;log-id&gt;]
                       [--log-len=&lt;log-len&gt; | -l &lt;log-len&gt;]
                       [--namespace-id=&lt;nsid&gt; | -n &lt;nsid&gt;]
-                      [--raw-binary | -b]</pre>
+                      [--raw-binary | -b]
+                      [--lpo=&lt;offset&gt; | -o &lt;offset&gt;]
+                      [--lsp=&lt;field&gt; | -s &lt;field&gt;]
+                      [--rae | -r]</pre>
 <div class="attribution">
 </div></div>
 </div>
@@ -826,6 +833,40 @@ program to parse.</p></div>
         Print the raw log buffer to stdout.
 </p>
 </dd>
+<dt class="hdlist1">
+-o &lt;offset&gt;
+</dt>
+<dt class="hdlist1">
+--lpo=&lt;offset&gt;
+</dt>
+<dd>
+<p>
+        The log page offset specifies the location within a log page to start
+        returning data from. It&#8217;s Dword-aligned and 64-bits.
+</p>
+</dd>
+<dt class="hdlist1">
+-s &lt;field&gt;
+</dt>
+<dt class="hdlist1">
+--lsp=&lt;field&gt;
+</dt>
+<dd>
+<p>
+        The log specified field of LID.
+</p>
+</dd>
+<dt class="hdlist1">
+-r
+</dt>
+<dt class="hdlist1">
+--rae
+</dt>
+<dd>
+<p>
+        Retain an Asynchronous Event.
+</p>
+</dd>
 </dl></div>
 </div>
 </div>
@@ -869,7 +910,8 @@ Have the program return the raw log page in binary:
 <div id="footnotes"><hr /></div>
 <div id="footer">
 <div id="footer-text">
-Last updated 2015-05-11 13:55:59 MDT
+Last updated
+ 2018-06-28 16:56:55 UTC
 </div>
 </div>
 </body>
diff --git a/Documentation/nvme-get-log.txt b/Documentation/nvme-get-log.txt
index 1a496f7..b054c2e 100644
--- a/Documentation/nvme-get-log.txt
+++ b/Documentation/nvme-get-log.txt
@@ -12,6 +12,9 @@ SYNOPSIS
 		      [--log-len=<log-len> | -l <log-len>]
 		      [--namespace-id=<nsid> | -n <nsid>]
 		      [--raw-binary | -b]
+		      [--lpo=<offset> | -o <offset>]
+		      [--lsp=<field> | -s <field>]
+		      [--rae | -r]
 
 DESCRIPTION
 -----------
@@ -49,6 +52,19 @@ OPTIONS
 --raw-binary::
 	Print the raw log buffer to stdout.
 
+-o <offset>::
+--lpo=<offset>::
+	The log page offset specifies the location within a log page to start
+	returning data from. It's Dword-aligned and 64-bits.
+
+-s <field>::
+--lsp=<field>::
+	The log specified field of LID.
+
+-r::
+--rae::
+	Retain an Asynchronous Event.
+
 EXAMPLES
 --------
 * Get 512 bytes from log page 2
diff --git a/nvme-ioctl.c b/nvme-ioctl.c
index bf86c23..f267227 100644
--- a/nvme-ioctl.c
+++ b/nvme-ioctl.c
@@ -371,7 +371,7 @@ int nvme_identify_ns_descs(int fd, __u32 nsid, void *data)
 }
 
 int nvme_get_log13(int fd, __u32 nsid, __u8 log_id, __u8 lsp, __u64 lpo,
-                 __u32 data_len, void *data)
+		__u16 lsi, bool rae, __u32 data_len, void *data)
 {
 	struct nvme_admin_cmd cmd = {
 		.opcode		= nvme_admin_get_log_page,
@@ -382,7 +382,7 @@ int nvme_get_log13(int fd, __u32 nsid, __u8 log_id, __u8 lsp, __u64 lpo,
 	__u32 numd = (data_len >> 2) - 1;
 	__u16 numdu = numd >> 16, numdl = numd & 0xffff;
 
-	cmd.cdw10 = log_id | (numdl << 16);
+	cmd.cdw10 = log_id | (numdl << 16) | (rae ? 1 << 15 : 0);
 	if (lsp)
                 cmd.cdw10 |= lsp << 8;
 
@@ -397,7 +397,7 @@ int nvme_get_log13(int fd, __u32 nsid, __u8 log_id, __u8 lsp, __u64 lpo,
 int nvme_get_log(int fd, __u32 nsid, __u8 log_id, __u32 data_len, void *data)
 {
 	return nvme_get_log13(fd, nsid, log_id, NVME_NO_LOG_LSP, NVME_NO_LOG_LPO,
-			      data_len, data);
+			      0, 0, data_len, data);
 }
 
 int nvme_fw_log(int fd, struct nvme_firmware_log_page *fw_log)
@@ -407,7 +407,7 @@ int nvme_fw_log(int fd, struct nvme_firmware_log_page *fw_log)
 
 int nvme_error_log(int fd, int entries, struct nvme_error_log_page *err_log)
 {
-	return nvme_get_log(fd, 0, NVME_LOG_ERROR, entries * sizeof(*err_log), err_log);
+	return nvme_get_log(fd, NVME_NSID_ALL, NVME_LOG_ERROR, entries * sizeof(*err_log), err_log);
 }
 
 int nvme_smart_log(int fd, __u32 nsid, struct nvme_smart_log *smart_log)
diff --git a/nvme-ioctl.h b/nvme-ioctl.h
index 1758c4f..e86a577 100644
--- a/nvme-ioctl.h
+++ b/nvme-ioctl.h
@@ -79,7 +79,7 @@ int nvme_identify_ns_list(int fd, __u32 nsid, bool all, void *data);
 int nvme_identify_ctrl_list(int fd, __u32 nsid, __u16 cntid, void *data);
 int nvme_identify_ns_descs(int fd, __u32 nsid, void *data);
 int nvme_get_log13(int fd, __u32 nsid, __u8 log_id, __u8 lsp, __u64 lpo,
-		   __u32 data_len, void *data);
+		   __u16 group_id, bool rae, __u32 data_len, void *data);
 int nvme_get_log(int fd, __u32 nsid, __u8 log_id, __u32 data_len, void *data);
 
 
diff --git a/nvme.c b/nvme.c
index 7513947..386def4 100644
--- a/nvme.c
+++ b/nvme.c
@@ -363,6 +363,7 @@ static int get_log(int argc, char **argv, struct command *cmd, struct plugin *pl
 	const char *log_len = "how many bytes to retrieve";
 	const char *lsp = "log specific field";
 	const char *lpo = "log page offset specifies the location within a log page from where to start returning data";
+	const char *rae = "retain an asynchronous event";
 	const char *raw_binary = "output in raw format";
 	int err, fd;
 
@@ -372,6 +373,7 @@ static int get_log(int argc, char **argv, struct command *cmd, struct plugin *pl
 		__u32 log_len;
 		__u64 lpo;
 		__u8  lsp;
+		int   rae;
 		int   raw_binary;
 	};
 
@@ -381,6 +383,7 @@ static int get_log(int argc, char **argv, struct command *cmd, struct plugin *pl
 		.log_len      = 0,
 		.lpo          = NVME_NO_LOG_LPO,
 		.lsp          = NVME_NO_LOG_LSP,
+		.rae          = 0,
 	};
 
 	const struct argconfig_commandline_options command_line_options[] = {
@@ -390,6 +393,7 @@ static int get_log(int argc, char **argv, struct command *cmd, struct plugin *pl
 		{"raw-binary",   'b', "",    CFG_NONE,     &cfg.raw_binary,   no_argument,       raw_binary},
 		{"lpo",          'o', "NUM", CFG_LONG,     &cfg.lpo,          required_argument, lpo},
 		{"lsp",          's', "NUM", CFG_BYTE,     &cfg.lsp,          required_argument, lsp},
+		{"rae",          'r', "",    CFG_NONE,     &cfg.rae,          no_argument,       rae},
 		{NULL}
 	};
 
@@ -410,7 +414,7 @@ static int get_log(int argc, char **argv, struct command *cmd, struct plugin *pl
 		}
 
 		err = nvme_get_log13(fd, cfg.namespace_id, cfg.log_id,
-				     cfg.lsp, cfg.lpo,
+				     cfg.lsp, cfg.lpo, 0, cfg.rae,
 				     cfg.log_len, log);
 		if (!err) {
 			if (!cfg.raw_binary) {
@@ -1611,7 +1615,7 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin
 		{"value",        'v', "NUM",  CFG_POSITIVE, &cfg.value,        required_argument, value},
 		{"data-len",     'l', "NUM",  CFG_POSITIVE, &cfg.data_len,     required_argument, data_len},
 		{"data",         'd', "FILE", CFG_STRING,   &cfg.file,         required_argument, data},
-		{"save",         's', "",     CFG_NONE,     &cfg.save,         no_argument, save},
+		{"save",         's', "",     CFG_NONE,     &cfg.save,         no_argument,       save},
 		{NULL}
 	};
 
-- 
2.13.7

