From: "Alastair D'Silva" <alastair@au1.ibm.com>
To: alastair@d-silva.org
Cc: "Madhavan Srinivasan" <maddy@linux.vnet.ibm.com>,
"Andrew Donnellan" <ajd@linux.ibm.com>,
"Arnd Bergmann" <arnd@arndb.de>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Alexey Kardashevskiy" <aik@ozlabs.ru>,
linux-kernel@vger.kernel.org,
"Nicholas Piggin" <npiggin@gmail.com>,
"Mahesh Salgaonkar" <mahesh@linux.vnet.ibm.com>,
"Masahiro Yamada" <yamada.masahiro@socionext.com>,
"Anju T Sudhakar" <anju@linux.vnet.ibm.com>,
"Paul Mackerras" <paulus@samba.org>,
"Cédric Le Goater" <clg@kaod.org>,
"Frederic Barrat" <fbarrat@linux.ibm.com>,
"Vaibhav Jain" <vaibhav@linux.ibm.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
linuxppc-dev@lists.ozlabs.org,
"David Gibson" <david@gibson.dropbear.id.au>
Subject: [PATCH 5/5] ocxl: Provide additional metadata to userspace
Date: Tue, 17 Sep 2019 11:43:01 +1000 [thread overview]
Message-ID: <20190917014307.30485-6-alastair@au1.ibm.com> (raw)
In-Reply-To: <20190917014307.30485-1-alastair@au1.ibm.com>
From: Alastair D'Silva <alastair@d-silva.org>
This patch exposes the OpenCAPI device serial number to
userspace.
It also includes placeholders for the LPC & special purpose
memory information (which will be populated in a subsequent patch)
to avoid creating excessive versions of the IOCTL.
Signed-off-by: Alastair D'Silva <alastair@d-silva.org>
---
drivers/misc/ocxl/config.c | 46 ++++++++++++++++++++++++++++++++++++++
drivers/misc/ocxl/file.c | 3 ++-
include/misc/ocxl.h | 1 +
include/uapi/misc/ocxl.h | 9 +++++++-
4 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/drivers/misc/ocxl/config.c b/drivers/misc/ocxl/config.c
index fb0c3b6f8312..a9203c309365 100644
--- a/drivers/misc/ocxl/config.c
+++ b/drivers/misc/ocxl/config.c
@@ -71,6 +71,51 @@ static int find_dvsec_afu_ctrl(struct pci_dev *dev, u8 afu_idx)
return 0;
}
+/**
+ * Find a related PCI device (function 0)
+ * @device: PCI device to match
+ *
+ * Returns a pointer to the related device, or null if not found
+ */
+static struct pci_dev *get_function_0(struct pci_dev *dev)
+{
+ unsigned int devfn = PCI_DEVFN(PCI_SLOT(dev->devfn), 0); // Look for function 0
+
+ return pci_get_domain_bus_and_slot(pci_domain_nr(dev->bus),
+ dev->bus->number, devfn);
+}
+
+static void read_serial(struct pci_dev *dev, struct ocxl_fn_config *fn)
+{
+ u32 low, high;
+ int pos;
+
+ pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DSN);
+ if (pos) {
+ pci_read_config_dword(dev, pos + 0x04, &low);
+ pci_read_config_dword(dev, pos + 0x08, &high);
+
+ fn->serial = low | ((u64)high) << 32;
+
+ return;
+ }
+
+ if (PCI_FUNC(dev->devfn) != 0) {
+ struct pci_dev *related = get_function_0(dev);
+
+ if (!related) {
+ fn->serial = 0;
+ return;
+ }
+
+ read_serial(related, fn);
+ pci_dev_put(related);
+ return;
+ }
+
+ fn->serial = 0;
+}
+
static void read_pasid(struct pci_dev *dev, struct ocxl_fn_config *fn)
{
u16 val;
@@ -208,6 +253,7 @@ int ocxl_config_read_function(struct pci_dev *dev, struct ocxl_fn_config *fn)
int rc;
read_pasid(dev, fn);
+ read_serial(dev, fn);
rc = read_dvsec_tl(dev, fn);
if (rc) {
diff --git a/drivers/misc/ocxl/file.c b/drivers/misc/ocxl/file.c
index 2870c25da166..08f6f594a11d 100644
--- a/drivers/misc/ocxl/file.c
+++ b/drivers/misc/ocxl/file.c
@@ -98,13 +98,14 @@ static long afu_ioctl_get_metadata(struct ocxl_context *ctx,
memset(&arg, 0, sizeof(arg));
- arg.version = 0;
+ arg.version = 1;
arg.afu_version_major = ctx->afu->config.version_major;
arg.afu_version_minor = ctx->afu->config.version_minor;
arg.pasid = ctx->pasid;
arg.pp_mmio_size = ctx->afu->config.pp_mmio_stride;
arg.global_mmio_size = ctx->afu->config.global_mmio_size;
+ arg.serial = ctx->afu->fn->config.serial;
if (copy_to_user(uarg, &arg, sizeof(arg)))
return -EFAULT;
diff --git a/include/misc/ocxl.h b/include/misc/ocxl.h
index a1897737908d..da75db149e6c 100644
--- a/include/misc/ocxl.h
+++ b/include/misc/ocxl.h
@@ -46,6 +46,7 @@ struct ocxl_fn_config {
int dvsec_afu_info_pos; /* offset of the AFU information DVSEC */
s8 max_pasid_log;
s8 max_afu_index;
+ u64 serial;
};
enum ocxl_endian {
diff --git a/include/uapi/misc/ocxl.h b/include/uapi/misc/ocxl.h
index 6d29a60a896a..d4c6bf10580c 100644
--- a/include/uapi/misc/ocxl.h
+++ b/include/uapi/misc/ocxl.h
@@ -45,7 +45,14 @@ struct ocxl_ioctl_metadata {
/* End version 0 fields */
- __u64 reserved[13]; /* Total of 16*u64 */
+ // Version 1 fields
+ __u64 lpc_mem_size;
+ __u64 special_purpose_mem_size;
+ __u64 serial; // Device serial number
+
+ // End version 1 fields
+
+ __u64 reserved[10]; // Total of 16*u64
};
struct ocxl_ioctl_p9_wait {
--
2.21.0
next prev parent reply other threads:[~2019-09-17 2:00 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-17 1:42 [PATCH 0/5] ocxl: Allow external drivers to access LPC memory Alastair D'Silva
2019-09-17 1:42 ` [PATCH 1/5] powerpc: Add OPAL calls for LPC memory alloc/release Alastair D'Silva
2019-09-25 11:41 ` Andrew Donnellan
2019-09-17 1:42 ` [PATCH 2/5] powerpc: Map & release OpenCAPI LPC memory Alastair D'Silva
2019-09-17 4:22 ` kbuild test robot
2019-09-18 14:03 ` Frederic Barrat
2019-09-19 0:58 ` Alastair D'Silva
2019-09-19 8:38 ` Frederic Barrat
2019-09-17 1:42 ` [PATCH 3/5] ocxl: Tally up the LPC memory on a link & allow it to be mapped Alastair D'Silva
2019-09-18 14:02 ` Frederic Barrat
2019-09-19 4:55 ` Alastair D'Silva
2019-09-19 8:41 ` Frederic Barrat
2019-09-17 1:43 ` [PATCH 4/5] ocxl: Add functions to map/unmap LPC memory Alastair D'Silva
2019-09-17 7:36 ` Christoph Hellwig
2019-09-18 14:03 ` Frederic Barrat
2019-09-19 1:19 ` Alastair D'Silva
2019-09-19 1:24 ` Alastair D'Silva
2019-09-23 11:39 ` Frederic Barrat
2019-09-26 2:59 ` Alastair D'Silva
2019-09-17 1:43 ` Alastair D'Silva [this message]
2019-09-17 6:35 ` [PATCH 5/5] ocxl: Provide additional metadata to userspace Alastair D'Silva
2019-09-17 11:30 ` kbuild test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190917014307.30485-6-alastair@au1.ibm.com \
--to=alastair@au1.ibm.com \
--cc=aik@ozlabs.ru \
--cc=ajd@linux.ibm.com \
--cc=alastair@d-silva.org \
--cc=anju@linux.vnet.ibm.com \
--cc=arnd@arndb.de \
--cc=clg@kaod.org \
--cc=david@gibson.dropbear.id.au \
--cc=fbarrat@linux.ibm.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.vnet.ibm.com \
--cc=mahesh@linux.vnet.ibm.com \
--cc=npiggin@gmail.com \
--cc=paulus@samba.org \
--cc=tglx@linutronix.de \
--cc=vaibhav@linux.ibm.com \
--cc=yamada.masahiro@socionext.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).