Skip to contentSkip to conversation

drivers: fsi: Add SBEFIFO and OCC drivers

PATCH Superseded Eddie James 3 participants 10 messages Sep 22, 2017 – Oct 4, 2017

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover drivers: fsi: Add SBEFIFO and OCC drivers

From: "Edward A. James" <[email protected]>

This series adds two FSI-based device drivers. The OCC driver is dependent on the SBEFIFO driver, as a user of it's in-kernel API. The in-kernel API provided by the OCC driver will be used by a hwmon driver (on the lkml as "Add On-Chip Controller (OCC) hwmon driver").

Changes since v2:
* Rename occ.c and occ.h to fsi-occ.c and fsi-occ.h
* Improved remove() ordering in both drivers.
* Added cancel functionality to OCC driver to make sure no xfrs started during remove().
* Fix spin_unlock with spin_unlock_irq in OCC driver.
* Fix list_first_entry with list_first_entry_or_null in OCC worker function.
* Add OCC response definitions to OCC include file.
* Handle probe() failures better.

Changes since v1:
* Split bindings into separate patch and added SBEFIFO device binding
* Fixed #includes
* Fix SBEFIFO race condition between write() and poll_timer().
* Followed Rob's suggestion to just create one platform device for hwmon driver, instead of using the device tree.
* Also check for "command in progress" response from OCC and try a while

Edward A. James (6):
dt-bindings: fsi: Add SBEFIFO documentation
drivers: fsi: Add SBEFIFO FSI client device driver
drivers: fsi: sbefifo: Add in-kernel API
dt-bindings: fsi: Add OCC documentation
drivers: fsi: Add On-Chip Controller (OCC) driver
drivers: fsi: occ: Add in-kernel API

 .../devicetree/bindings/fsi/ibm,p9-occ.txt         |  15 +
 .../devicetree/bindings/fsi/ibm,p9-sbefifo.txt     |  20 +
 drivers/fsi/Kconfig                                |  17 +
 drivers/fsi/Makefile                               |   2 +
 drivers/fsi/fsi-occ.c                              | 851 ++++++++++++++++++
 drivers/fsi/fsi-sbefifo.c                          | 956 +++++++++++++++++++++
 include/linux/fsi-occ.h                            |  41 +
 include/linux/fsi-sbefifo.h                        |  30 +
 8 files changed, 1932 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/fsi/ibm,p9-occ.txt
 create mode 100644 Documentation/devicetree/bindings/fsi/ibm,p9-sbefifo.txt
 create mode 100644 drivers/fsi/fsi-occ.c
 create mode 100644 drivers/fsi/fsi-sbefifo.c
 create mode 100644 include/linux/fsi-occ.h
 create mode 100644 include/linux/fsi-sbefifo.h
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v3 1/6 dt-bindings: fsi: Add SBEFIFO documentation

From: "Edward A. James" <[email protected]>

Document the bindings for the SBE CFAM device. SBE devices are located on a CFAM off an FSI bus.

---
 .../devicetree/bindings/fsi/ibm,p9-sbefifo.txt       | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/fsi/ibm,p9-sbefifo.txt
Documentation/devicetree/bindings/fsi/ibm,p9-sbefifo.txt new file +20 -0
new file mode 100644
index 0000000..07fbf29
@@ -0,0 +1,20 @@
+Device-tree bindings for P9 SBEFIFO CFAM device
+-----------------------------------------------
+
+Required properties:
+ - reg = < address size >		: FSI CFAM address for the SBE engine
+					  and address space size.
+
+Optional properties:
+ - <child nodes>			: Devices that are accessible through
+					  the SBEFIFO.
+
+Examples:
+
+    sbefifo@2400 {
+        reg = < 0x2400 0x400 >;
+
+        occ@1 {
+            ...
+        };
+    };
Signature · 1 line
1.8.3.1
maintainer
#2 lore raw

Re: [PATCH v3 1/6] dt-bindings: fsi: Add SBEFIFO documentation

Quoted 17 lines · Eddie James

From: "Edward A. James" <eajames-r/[email protected]>

Document the bindings for the SBE CFAM device. SBE devices are located on a CFAM off an FSI bus.

---
 .../devicetree/bindings/fsi/ibm,p9-sbefifo.txt       | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/fsi/ibm,p9-sbefifo.txt
Documentation/devicetree/bindings/fsi/ibm,p9-sbefifo.txt new file +0 -0
new file mode 100644
index 0000000..07fbf29

Documentation/devicetree/bindings/fsi/ibm,p9-sbefifo.txt line 6

Quoted 6 lines
Documentation/devicetree/bindings/fsi/ibm,p9-sbefifo.txt new file +6 -0
@@ -0,0 +1,20 @@
+Device-tree bindings for P9 SBEFIFO CFAM device
+-----------------------------------------------
+
+Required properties:
+ - reg = < address size >		: FSI CFAM address for the SBE engine
+					  and address space size.

compatible?

Documentation/devicetree/bindings/fsi/ibm,p9-sbefifo.txt line 10

Quoted 4 lines
Documentation/devicetree/bindings/fsi/ibm,p9-sbefifo.txt new file +4 -0
+
+Optional properties:
+ - <child nodes>			: Devices that are accessible through
+					  the SBEFIFO.

You need some sort of definition what's in the child nodes.

Documentation/devicetree/bindings/fsi/ibm,p9-sbefifo.txt line 15

Quoted 5 lines
Documentation/devicetree/bindings/fsi/ibm,p9-sbefifo.txt new file +5 -0
+
+Examples:
+
+    sbefifo@2400 {
+        reg = < 0x2400 0x400 >;

Need #{address,size}-cells here.

Documentation/devicetree/bindings/fsi/ibm,p9-sbefifo.txt line 17

Quoted 2 lines
Documentation/devicetree/bindings/fsi/ibm,p9-sbefifo.txt new file +2 -0
+
+        occ@1 {

Need a reg property here and you need to define what reg represents.

Quoted 6 lines
Documentation/devicetree/bindings/fsi/ibm,p9-sbefifo.txt new file +3 -0
+            ...
+        };
+    };
Signature · 1 line
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

PATCH v3 2/6 drivers: fsi: Add SBEFIFO FSI client device driver

In reply to Eddie James

From: "Edward A. James" <[email protected]>

IBM POWER9 processors contain some embedded hardware and software bits collectively referred to as the self boot engine (SBE). One role of the SBE is to act as a proxy that provides access to the registers of the POWER chip from other (embedded) systems.

The POWER9 chip contains a hardware frontend for communicating with the SBE from remote systems called the SBEFIFO. The SBEFIFO logic is contained within an FSI CFAM and as such the driver implements an FSI bus device.

The SBE expects to communicate using a defined wire protocol; however, the driver knows nothing of the protocol and only provides raw access to the fifo device to userspace applications wishing to communicate with the SBE using the wire protocol.

The SBEFIFO consists of two hardware fifos. The upstream fifo is used by the driver to transfer data to the SBE on the POWER chip, from the system hosting the driver. The downstream fifo is used by the driver to transfer data from the SBE on the power chip to the system hosting the driver.

---
 drivers/fsi/Kconfig       |   7 +
 drivers/fsi/Makefile      |   1 +
 drivers/fsi/fsi-sbefifo.c | 861 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 869 insertions(+)
 create mode 100644 drivers/fsi/fsi-sbefifo.c
drivers/fsi/Kconfig +7 -0
index 6821ed0..8c4d903 100644
@@ -33,6 +33,13 @@ config FSI_SCOM
 	---help---
 	This option enables an FSI based SCOM device driver.
 
+config FSI_SBEFIFO
+	tristate "SBEFIFO FSI client device driver"
+	---help---
+	This option enables an FSI based SBEFIFO device driver. The SBEFIFO is
+	a pipe-like FSI device for communicating with the self boot engine
+	(SBE) on POWER processors.
+
 endif
 
 endmenu
drivers/fsi/Makefile +1 -0
index 65eb99d..851182e 100644
@@ -3,3 +3,4 @@ obj-$(CONFIG_FSI) += fsi-core.o
 obj-$(CONFIG_FSI_MASTER_HUB) += fsi-master-hub.o
 obj-$(CONFIG_FSI_MASTER_GPIO) += fsi-master-gpio.o
 obj-$(CONFIG_FSI_SCOM) += fsi-scom.o
+obj-$(CONFIG_FSI_SBEFIFO) += fsi-sbefifo.o
drivers/fsi/fsi-sbefifo.c new file +861 -0

861 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#4 lore raw

Re: [PATCH v3 2/6] drivers: fsi: Add SBEFIFO FSI client device driver

Hi Eddie,

Quoted 25 lines · Eddie James

From: "Edward A. James" <eajames-r/[email protected]>

IBM POWER9 processors contain some embedded hardware and software bits collectively referred to as the self boot engine (SBE). One role of the SBE is to act as a proxy that provides access to the registers of the POWER chip from other (embedded) systems.

The POWER9 chip contains a hardware frontend for communicating with the SBE from remote systems called the SBEFIFO. The SBEFIFO logic is contained within an FSI CFAM and as such the driver implements an FSI bus device.

The SBE expects to communicate using a defined wire protocol; however, the driver knows nothing of the protocol and only provides raw access to the fifo device to userspace applications wishing to communicate with the SBE using the wire protocol.

The SBEFIFO consists of two hardware fifos. The upstream fifo is used by the driver to transfer data to the SBE on the POWER chip, from the system hosting the driver. The downstream fifo is used by the driver to transfer data from the SBE on the power chip to the system hosting the driver.

Quoted 7 lines
---
 drivers/fsi/Kconfig       |   7 +
 drivers/fsi/Makefile      |   1 +
 drivers/fsi/fsi-sbefifo.c | 861
 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 869 insertions(+)
 create mode 100644 drivers/fsi/fsi-sbefifo.c

My general feeling is the implementation is too complex by half for what is required. I may be wrong and the solution genuinely needs the complexity, but to test that I'll cook up a counter-proposal patch and we can debate that. I'm away for the next few days, but I hope to send something by the end of next week.

Cheers,

Andrew
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

PATCH v3 3/6 drivers: fsi: sbefifo: Add in-kernel API

In reply to Eddie James

From: "Edward A. James" <[email protected]>

Refactor the user interface of the SBEFIFO driver to allow for an in-kernel read/write API. Add exported functions for other drivers to call, and add an include file with those functions. Also parse the device tree for child nodes and create child platform devices accordingly.

---
 drivers/fsi/fsi-sbefifo.c   | 137 +++++++++++++++++++++++++++++++++++++-------
 include/linux/fsi-sbefifo.h |  30 ++++++++++
 2 files changed, 146 insertions(+), 21 deletions(-)
 create mode 100644 include/linux/fsi-sbefifo.h
drivers/fsi/fsi-sbefifo.c +116 -21
index 24d9bd5..5d25ade 100644
@@ -15,12 +15,16 @@
 #include <linux/errno.h>
 #include <linux/fs.h>
 #include <linux/fsi.h>
+#include <linux/fsi-sbefifo.h>
 #include <linux/idr.h>
 #include <linux/kernel.h>
 #include <linux/kref.h>
 #include <linux/list.h>
 #include <linux/miscdevice.h>
 #include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_platform.h>
 #include <linux/poll.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
@@ -88,6 +92,7 @@ struct sbefifo_client {
 	struct list_head xfrs;
 	struct sbefifo *dev;
 	struct kref kref;
+	unsigned long f_flags;
 };
 
 static DEFINE_IDA(sbefifo_ida);
@@ -508,6 +513,7 @@ static int sbefifo_open(struct inode *inode, struct file *file)
 		return -ENOMEM;
 
 	file->private_data = client;
+	client->f_flags = file->f_flags;
 
 	return 0;
 }
@@ -545,19 +551,18 @@ static bool sbefifo_read_ready(struct sbefifo *sbefifo,
 		(xfr && test_bit(SBEFIFO_XFR_COMPLETE, &xfr->flags));
 }
 
-static ssize_t sbefifo_read(struct file *file, char __user *buf, size_t len,
-			    loff_t *offset)
+static ssize_t sbefifo_read_common(struct sbefifo_client *client,
+				   char __user *ubuf, char *kbuf, size_t len)
 {
-	struct sbefifo_client *client = file->private_data;
 	struct sbefifo *sbefifo = client->dev;
 	struct sbefifo_xfr *xfr;
-	ssize_t ret = 0;
 	size_t n;
+	ssize_t ret = 0;
 
 	if ((len >> 2) << 2 != len)
 		return -EINVAL;
 
-	if ((file->f_flags & O_NONBLOCK) && !sbefifo_xfr_rsp_pending(client))
+	if ((client->f_flags & O_NONBLOCK) && !sbefifo_xfr_rsp_pending(client))
 		return -EAGAIN;
 
 	sbefifo_get_client(client);
@@ -576,9 +581,13 @@ static ssize_t sbefifo_read(struct file *file, char __user *buf, size_t len,
 
 	n = min_t(size_t, n, len);
 
-	if (copy_to_user(buf, READ_ONCE(client->rbuf.rpos), n)) {
-		ret = -EFAULT;
-		goto out;
+	if (ubuf) {
+		if (copy_to_user(ubuf, READ_ONCE(client->rbuf.rpos), n)) {
+			ret = -EFAULT;
+			goto out;
+		}
+	} else {
+		memcpy(kbuf, READ_ONCE(client->rbuf.rpos), n);
 	}
 
 	if (sbefifo_buf_readnb(&client->rbuf, n)) {
@@ -611,6 +620,14 @@ static ssize_t sbefifo_read(struct file *file, char __user *buf, size_t len,
 	return ret;
 }
 
+static ssize_t sbefifo_read(struct file *file, char __user *buf, size_t len,
+			    loff_t *offset)
+{
+	struct sbefifo_client *client = file->private_data;
+
+	return sbefifo_read_common(client, buf, NULL, len);
+}
+
 static bool sbefifo_write_ready(struct sbefifo *sbefifo,
 				struct sbefifo_xfr *xfr,
 				struct sbefifo_client *client, size_t *n)
@@ -623,10 +640,10 @@ static bool sbefifo_write_ready(struct sbefifo *sbefifo,
 	return READ_ONCE(sbefifo->rc) || (next == xfr && *n);
 }
 
-static ssize_t sbefifo_write(struct file *file, const char __user *buf,
-			     size_t len, loff_t *offset)
+static ssize_t sbefifo_write_common(struct sbefifo_client *client,
+				    const char __user *ubuf, const char *kbuf,
+				    size_t len)
 {
-	struct sbefifo_client *client = file->private_data;
 	struct sbefifo *sbefifo = client->dev;
 	struct sbefifo_buf *wbuf = &client->wbuf;
 	struct sbefifo_xfr *xfr;
@@ -645,7 +662,7 @@ static ssize_t sbefifo_write(struct file *file, const char __user *buf,
 	spin_lock_irq(&sbefifo->lock);
 
 	xfr = sbefifo_next_xfr(sbefifo);	/* next xfr to be executed */
-	if ((file->f_flags & O_NONBLOCK) && xfr && n < len) {
+	if ((client->f_flags & O_NONBLOCK) && xfr && n < len) {
 		spin_unlock_irq(&sbefifo->lock);
 		ret = -EAGAIN;
 		goto out;
@@ -685,18 +702,24 @@ static ssize_t sbefifo_write(struct file *file, const char __user *buf,
 
 		n = min_t(size_t, n, len);
 
-		if (copy_from_user(READ_ONCE(wbuf->wpos), buf, n)) {
-			set_bit(SBEFIFO_XFR_CANCEL, &xfr->flags);
-			sbefifo_get(sbefifo);
-			if (mod_timer(&sbefifo->poll_timer, jiffies))
-				sbefifo_put(sbefifo);
-			ret = -EFAULT;
-			goto out;
+		if (ubuf) {
+			if (copy_from_user(READ_ONCE(wbuf->wpos), ubuf, n)) {
+				set_bit(SBEFIFO_XFR_CANCEL, &xfr->flags);
+				sbefifo_get(sbefifo);
+				if (mod_timer(&sbefifo->poll_timer, jiffies))
+					sbefifo_put(sbefifo);
+				ret = -EFAULT;
+				goto out;
+			}
+
+			ubuf += n;
+		} else {
+			memcpy(READ_ONCE(wbuf->wpos), kbuf, n);
+			kbuf += n;
 		}
 
 		sbefifo_buf_wrotenb(wbuf, n);
 		len -= n;
-		buf += n;
 		ret += n;
 
 		/* Set this before starting timer to avoid race condition on
@@ -718,6 +741,14 @@ static ssize_t sbefifo_write(struct file *file, const char __user *buf,
 	return ret;
 }
 
+static ssize_t sbefifo_write(struct file *file, const char __user *buf,
+			     size_t len, loff_t *offset)
+{
+	struct sbefifo_client *client = file->private_data;
+
+	return sbefifo_write_common(client, buf, NULL, len);
+}
+
 static int sbefifo_release(struct inode *inode, struct file *file)
 {
 	struct sbefifo_client *client = file->private_data;
@@ -737,12 +768,65 @@ static int sbefifo_release(struct inode *inode, struct file *file)
 	.release	= sbefifo_release,
 };
 
+struct sbefifo_client *sbefifo_drv_open(struct device *dev,
+					unsigned long flags)
+{
+	struct sbefifo_client *client;
+	struct sbefifo *sbefifo = dev_get_drvdata(dev);
+
+	if (!sbefifo)
+		return NULL;
+
+	client = sbefifo_new_client(sbefifo);
+	if (client)
+		client->f_flags = flags;
+
+	return client;
+}
+EXPORT_SYMBOL_GPL(sbefifo_drv_open);
+
+int sbefifo_drv_read(struct sbefifo_client *client, char *buf, size_t len)
+{
+	return sbefifo_read_common(client, NULL, buf, len);
+}
+EXPORT_SYMBOL_GPL(sbefifo_drv_read);
+
+int sbefifo_drv_write(struct sbefifo_client *client, const char *buf,
+		      size_t len)
+{
+	return sbefifo_write_common(client, NULL, buf, len);
+}
+EXPORT_SYMBOL_GPL(sbefifo_drv_write);
+
+void sbefifo_drv_release(struct sbefifo_client *client)
+{
+	if (!client)
+		return;
+
+	sbefifo_put_client(client);
+}
+EXPORT_SYMBOL_GPL(sbefifo_drv_release);
+
+static int sbefifo_unregister_child(struct device *dev, void *data)
+{
+	struct platform_device *child = to_platform_device(dev);
+
+	of_device_unregister(child);
+	if (dev->of_node)
+		of_node_clear_flag(dev->of_node, OF_POPULATED);
+
+	return 0;
+}
+
 static int sbefifo_probe(struct device *dev)
 {
 	struct fsi_device *fsi_dev = to_fsi_dev(dev);
 	struct sbefifo *sbefifo;
+	struct device_node *np;
+	struct platform_device *child;
+	char child_name[32];
 	u32 sts;
-	int ret;
+	int ret, child_idx = 0;
 
 	sbefifo = kzalloc(sizeof(*sbefifo), GFP_KERNEL);
 	if (!sbefifo)
@@ -793,6 +877,16 @@ static int sbefifo_probe(struct device *dev)
 		return ret;
 	}
 
+	/* create platform devs for dts child nodes (occ, etc) */
+	for_each_available_child_of_node(dev->of_node, np) {
+		snprintf(child_name, sizeof(child_name), "%s-dev%d",
+			 sbefifo->name, child_idx++);
+		child = of_platform_device_create(np, child_name, dev);
+		if (!child)
+			dev_warn(dev, "failed to create child %s dev\n",
+				 child_name);
+	}
+
 	dev_set_drvdata(dev, sbefifo);
 
 	return 0;
@@ -807,6 +901,7 @@ static int sbefifo_remove(struct device *dev)
 	wake_up(&sbefifo->wait);
 
 	misc_deregister(&sbefifo->mdev);
+	device_for_each_child(dev, NULL, sbefifo_unregister_child);
 
 	ida_simple_remove(&sbefifo_ida, sbefifo->idx);
 
include/linux/fsi-sbefifo.h new file +30 -0
new file mode 100644
index 0000000..8e55891
@@ -0,0 +1,30 @@
+/*
+ * SBEFIFO FSI Client device driver
+ *
+ * Copyright (C) IBM Corporation 2017
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERGCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef LINUX_FSI_SBEFIFO_H
+#define LINUX_FSI_SBEFIFO_H
+
+struct device;
+struct sbefifo_client;
+
+extern struct sbefifo_client *sbefifo_drv_open(struct device *dev,
+					       unsigned long flags);
+extern int sbefifo_drv_read(struct sbefifo_client *client, char *buf,
+			    size_t len);
+extern int sbefifo_drv_write(struct sbefifo_client *client, const char *buf,
+			     size_t len);
+extern void sbefifo_drv_release(struct sbefifo_client *client);
+
+#endif /* LINUX_FSI_SBEFIFO_H */
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH v3 4/6 dt-bindings: fsi: Add OCC documentation

In reply to Eddie James

From: "Edward A. James" <[email protected]>

Document the bindings for the P9 OCC device. OCC devices are accessed through the SBEFIFO.

---
 Documentation/devicetree/bindings/fsi/ibm,p9-occ.txt | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/fsi/ibm,p9-occ.txt
Documentation/devicetree/bindings/fsi/ibm,p9-occ.txt new file +15 -0
new file mode 100644
index 0000000..bcaefc9
@@ -0,0 +1,15 @@
+Device-tree bindings for P9 On-Chip Controller
+----------------------------------------------
+
+Required properties:
+ - compatible = "ibm,p9-occ";
+
+Optional properties:
+ - reg = <processor index>;	: Index for the processor this OCC is on.
+
+Examples:
+
+    occ@1 {
+        compatible = "ibm,p9-occ";
+        reg = <1>;
+    };
Signature · 1 line
1.8.3.1
maintainer
#7 lore raw

Re: [PATCH v3 4/6] dt-bindings: fsi: Add OCC documentation

Quoted 17 lines · Eddie James

From: "Edward A. James" <eajames-r/[email protected]>

Document the bindings for the P9 OCC device. OCC devices are accessed through the SBEFIFO.

---
 Documentation/devicetree/bindings/fsi/ibm,p9-occ.txt | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/fsi/ibm,p9-occ.txt
Documentation/devicetree/bindings/fsi/ibm,p9-occ.txt new file +0 -0
new file mode 100644
index 0000000..bcaefc9

Documentation/devicetree/bindings/fsi/ibm,p9-occ.txt line 8

Quoted 8 lines
Documentation/devicetree/bindings/fsi/ibm,p9-occ.txt new file +8 -0
@@ -0,0 +1,15 @@
+Device-tree bindings for P9 On-Chip Controller
+----------------------------------------------
+
+Required properties:
+ - compatible = "ibm,p9-occ";
+
+Optional properties:
+ - reg = <processor index>;	: Index for the processor this OCC is on.

Need to say what this must be a child of.

Quoted 10 lines
Documentation/devicetree/bindings/fsi/ibm,p9-occ.txt new file +7 -0
+
+Examples:
+
+    occ@1 {
+        compatible = "ibm,p9-occ";
+        reg = <1>;
+    };
Signature · 1 line
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw

PATCH v3 5/6 drivers: fsi: Add On-Chip Controller (OCC) driver

In reply to Eddie James

From: "Edward A. James" <[email protected]>

The OCC is a device embedded on a POWER processor that collects and aggregates sensor data from the processor and system. The OCC can provide the raw sensor data as well as perform thermal and power management on the system.

This driver provides an atomic communications channel between a service processor (e.g. a BMC) and the OCC. The driver is dependent on the FSI SBEFIFO driver to get hardware access through the SBE to the OCC SRAM. Commands are issued to the SBE to send or fetch data to the SRAM.

The format of communications to the OCC is writing a command to SRAM, followed by a sending a "doorbell" or attention to the OCC, followed by reading the response from OCC. All of this takes place atomically so that multiple users don't collide in the SRAM.

---
 drivers/fsi/Kconfig   |  10 +
 drivers/fsi/Makefile  |   1 +
 drivers/fsi/fsi-occ.c | 756 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 767 insertions(+)
 create mode 100644 drivers/fsi/fsi-occ.c
drivers/fsi/Kconfig +10 -0
index 8c4d903..8ed4602 100644
@@ -40,6 +40,16 @@ config FSI_SBEFIFO
 	a pipe-like FSI device for communicating with the self boot engine
 	(SBE) on POWER processors.
 
+config FSI_OCC
+	tristate "OCC SBEFIFO client device driver"
+	depends on FSI_SBEFIFO
+	---help---
+	This option enables an SBEFIFO based On-Chip Controller (OCC) device
+	driver. The OCC is a device embedded on a POWER processor that collects
+	and aggregates sensor data from the processor and system. The OCC can
+	provide the raw sensor data as well as perform thermal and power
+	management on the system.
+
 endif
 
 endmenu
drivers/fsi/Makefile +1 -0
index 851182e..75fdc6d 100644
@@ -4,3 +4,4 @@ obj-$(CONFIG_FSI_MASTER_HUB) += fsi-master-hub.o
 obj-$(CONFIG_FSI_MASTER_GPIO) += fsi-master-gpio.o
 obj-$(CONFIG_FSI_SCOM) += fsi-scom.o
 obj-$(CONFIG_FSI_SBEFIFO) += fsi-sbefifo.o
+obj-$(CONFIG_FSI_OCC) += fsi-occ.o
drivers/fsi/fsi-occ.c new file +756 -0

756 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#9 lore raw

PATCH v3 6/6 drivers: fsi: occ: Add in-kernel API

In reply to Eddie James

From: "Edward A. James" <[email protected]>

Add an in-kernel read/write API with exported functions. This is necessary for other drivers which want to directly interact with the OCC. Also add a child platform device node for the associated hwmon device.

---
 drivers/fsi/fsi-occ.c   | 143 ++++++++++++++++++++++++++++++++++++++++--------
 include/linux/fsi-occ.h |  41 ++++++++++++++
 2 files changed, 160 insertions(+), 24 deletions(-)
 create mode 100644 include/linux/fsi-occ.h
drivers/fsi/fsi-occ.c +119 -24
index 3a18f90..7b927bc 100644
@@ -12,6 +12,7 @@
 #include <linux/err.h>
 #include <linux/errno.h>
 #include <linux/fs.h>
+#include <linux/fsi-occ.h>
 #include <linux/fsi-sbefifo.h>
 #include <linux/idr.h>
 #include <linux/kernel.h>
@@ -32,8 +33,6 @@
 #define OCC_CMD_DATA_BYTES	4090
 #define OCC_RESP_DATA_BYTES	4089
 
-#define OCC_RESP_CMD_IN_PRG	0xFF
-
 #define OCC_TIMEOUT_MS		1000
 #define OCC_CMD_IN_PRG_WAIT_MS	50
 
@@ -140,36 +139,43 @@ static int occ_enqueue_xfr(struct occ_xfr *xfr)
 	return 0;
 }
 
-static int occ_open(struct inode *inode, struct file *file)
+static struct occ_client *occ_open_common(struct occ *occ, unsigned long flags)
 {
-	struct miscdevice *mdev = file->private_data;
-	struct occ *occ = to_occ(mdev);
 	struct occ_client *client = kzalloc(sizeof(*client), GFP_KERNEL);
 
-	if (!client)
-		return -ENOMEM;
-
-	if (occ->cancel)
-		return -ECANCELED;
+	if (!client || occ->cancel)
+		return NULL;
 
 	client->occ = occ;
 	spin_lock_init(&client->lock);
 	init_waitqueue_head(&client->wait);
 
-	if (file->f_flags & O_NONBLOCK)
+	if (flags & O_NONBLOCK)
 		set_bit(CLIENT_NONBLOCKING, &client->flags);
 
+	return client;
+}
+
+static int occ_open(struct inode *inode, struct file *file)
+{
+	struct occ_client *client;
+	struct miscdevice *mdev = file->private_data;
+	struct occ *occ = to_occ(mdev);
+
+	client = occ_open_common(occ, file->f_flags);
+	if (!client)
+		return -ENOMEM;
+
 	file->private_data = client;
 
 	return 0;
 }
 
-static ssize_t occ_read(struct file *file, char __user *buf, size_t len,
-			loff_t *offset)
+static ssize_t occ_read_common(struct occ_client *client, char __user *ubuf,
+			       char *kbuf, size_t len)
 {
 	int rc;
 	size_t bytes;
-	struct occ_client *client = file->private_data;
 	struct occ_xfr *xfr = &client->xfr;
 	struct occ *occ = client->occ;
 
@@ -227,9 +233,15 @@ static ssize_t occ_read(struct file *file, char __user *buf, size_t len,
 		goto done;
 	}
 
-	if (copy_to_user(buf, &xfr->buf[client->read_offset], bytes)) {
-		rc = -EFAULT;
-		goto done;
+	bytes = min(len, xfr->resp_data_length - client->read_offset);
+	if (ubuf) {
+		if (copy_to_user(ubuf, &xfr->buf[client->read_offset],
+				 bytes)) {
+			rc = -EFAULT;
+			goto done;
+		}
+	} else {
+		memcpy(kbuf, &xfr->buf[client->read_offset], bytes);
 	}
 
 	client->read_offset += bytes;
@@ -245,13 +257,21 @@ static ssize_t occ_read(struct file *file, char __user *buf, size_t len,
 	return rc;
 }
 
-static ssize_t occ_write(struct file *file, const char __user *buf,
-			 size_t len, loff_t *offset)
+static ssize_t occ_read(struct file *file, char __user *buf, size_t len,
+			loff_t *offset)
+{
+	struct occ_client *client = file->private_data;
+
+	return occ_read_common(client, buf, NULL, len);
+}
+
+static ssize_t occ_write_common(struct occ_client *client,
+				const char __user *ubuf, const char *kbuf,
+				size_t len)
 {
 	int rc;
 	unsigned int i;
 	u16 data_length, checksum = 0;
-	struct occ_client *client = file->private_data;
 	struct occ_xfr *xfr = &client->xfr;
 
 	if (len > (OCC_CMD_DATA_BYTES + 3) || len < 3)
@@ -272,9 +292,13 @@ static ssize_t occ_write(struct file *file, const char __user *buf,
 	 * bytes 1-2: data length (msb first)
 	 * bytes 3-n: data
 	 */
-	if (copy_from_user(&xfr->buf[1], buf, len)) {
-		rc = -EFAULT;
-		goto done;
+	if (ubuf) {
+		if (copy_from_user(&xfr->buf[1], ubuf, len)) {
+			rc = -EFAULT;
+			goto done;
+		}
+	} else {
+		memcpy(&xfr->buf[1], kbuf, len);
 	}
 
 	data_length = (xfr->buf[2] << 8) + xfr->buf[3];
@@ -303,9 +327,16 @@ static ssize_t occ_write(struct file *file, const char __user *buf,
 	return rc;
 }
 
-static int occ_release(struct inode *inode, struct file *file)
+static ssize_t occ_write(struct file *file, const char __user *buf,
+			 size_t len, loff_t *offset)
 {
 	struct occ_client *client = file->private_data;
+
+	return occ_write_common(client, buf, NULL, len);
+}
+
+static int occ_release_common(struct occ_client *client)
+{
 	struct occ_xfr *xfr = &client->xfr;
 	struct occ *occ = client->occ;
 
@@ -346,6 +377,13 @@ static int occ_release(struct inode *inode, struct file *file)
 	return 0;
 }
 
+static int occ_release(struct inode *inode, struct file *file)
+{
+	struct occ_client *client = file->private_data;
+
+	return occ_release_common(client);
+}
+
 static const struct file_operations occ_fops = {
 	.owner = THIS_MODULE,
 	.open = occ_open,
@@ -643,12 +681,56 @@ static void occ_worker(struct work_struct *work)
 		goto again;
 }
 
+struct occ_client *occ_drv_open(struct device *dev, unsigned long flags)
+{
+	struct occ *occ = dev_get_drvdata(dev);
+
+	if (!occ)
+		return NULL;
+
+	return occ_open_common(occ, flags);
+}
+EXPORT_SYMBOL_GPL(occ_drv_open);
+
+int occ_drv_read(struct occ_client *client, char *buf, size_t len)
+{
+	return occ_read_common(client, NULL, buf, len);
+}
+EXPORT_SYMBOL_GPL(occ_drv_read);
+
+int occ_drv_write(struct occ_client *client, const char *buf, size_t len)
+{
+	return occ_write_common(client, NULL, buf, len);
+}
+EXPORT_SYMBOL_GPL(occ_drv_write);
+
+void occ_drv_release(struct occ_client *client)
+{
+	occ_release_common(client);
+}
+EXPORT_SYMBOL_GPL(occ_drv_release);
+
+static int occ_unregister_child(struct device *dev, void *data)
+{
+	struct platform_device *child = to_platform_device(dev);
+
+	platform_device_unregister(child);
+
+	return 0;
+}
+
 static int occ_probe(struct platform_device *pdev)
 {
 	int rc;
 	u32 reg;
 	struct occ *occ;
+	struct platform_device *child;
+	struct platform_device_info child_info;
 	struct device *dev = &pdev->dev;
+	struct property_entry child_properties[] = {
+		PROPERTY_ENTRY_STRING("compatible", "ibm,p9-occ-hwmon"),
+		{ }
+	};
 
 	occ = devm_kzalloc(dev, sizeof(*occ), GFP_KERNEL);
 	if (!occ)
@@ -659,8 +741,11 @@ static int occ_probe(struct platform_device *pdev)
 	spin_lock_init(&occ->list_lock);
 	mutex_init(&occ->occ_lock);
 	INIT_WORK(&occ->work, occ_worker);
+	memset(&child_info, 0, sizeof(child_info));
 
 	if (dev->of_node) {
+		child_info.fwnode = &dev->of_node->fwnode;
+
 		rc = of_property_read_u32(dev->of_node, "reg", &reg);
 		if (!rc) {
 			/* make sure we don't have a duplicate from dts */
@@ -690,6 +775,15 @@ static int occ_probe(struct platform_device *pdev)
 		return rc;
 	}
 
+	/* create device for hwmon driver */
+	child_info.id = occ->idx;
+	child_info.parent = dev;
+	child_info.name = "occ-hwmon";
+	child_info.properties = child_properties;
+	child = platform_device_register_full(&child_info);
+	if (!child)
+		dev_warn(dev, "failed to register %s dev\n", child_info.name);
+
 	platform_set_drvdata(pdev, occ);
 
 	return 0;
@@ -708,6 +802,7 @@ static int occ_remove(struct platform_device *pdev)
 	}
 
 	misc_deregister(&occ->mdev);
+	device_for_each_child(&pdev->dev, NULL, occ_unregister_child);
 
 	flush_work(&occ->work);
 
include/linux/fsi-occ.h new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
1.8.3.1