Skip to contentSkip to conversation

drivers: fsi: scom: Add reset functionality and sysfs interface

PATCH In review Eddie James 3 participants 7 messages Feb 17, 2017 – Feb 21, 2017 FSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: fsi: scom: Add reset functionality and sysfs interface

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

full reset only

---
 drivers/fsi/fsi-scom.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 50 insertions(+), 1 deletion(-)
drivers/fsi/fsi-scom.c +50 -1
index ff8267b..c73bd91 100644
@@ -32,7 +32,10 @@
 #define SCOM_DATA0_REG		0x00
 #define SCOM_DATA1_REG		0x04
 #define SCOM_CMD_REG		0x08
+#define SCOM_FSI2PIB_RESET_REG	0x18
 #define SCOM_RESET_REG		0x1C
+#define SCOM_COMP_MASK_REG	0x30
+#define SCOM_TRUE_MASK_REG	0x34
 
 #define SCOM_RESET_CMD		0x80000000
 #define SCOM_WRITE_CMD		0x80000000
@@ -156,7 +159,7 @@ static ssize_t scom_write(struct file *filep, const char __user *buf,
 	if (rc)
 		dev_dbg(dev, "put_scom failed with:%d\n", rc);
 
-	return rc;
+	return rc ? rc : len;
 }
 
 static loff_t scom_llseek(struct file *file, loff_t offset, int whence)
@@ -181,6 +184,48 @@ static const struct file_operations scom_fops = {
 	.write	= scom_write,
 };
 
+static int scom_reset_fsi2pib(struct fsi_device *fsi_dev)
+{
+	int rc;
+	u32 dummy = 0xFFFFFFFF;
+
+	rc = fsi_device_write(fsi_dev, SCOM_FSI2PIB_RESET_REG, &dummy,
+			      sizeof(u32));
+	if (rc)
+		dev_dbg(&fsi_dev->dev,
+			"failed to write fsi2pib reset register rc:%d\n", rc);
+
+	return rc;
+}
+
+static int scom_full_reset(struct fsi_device *fsi_dev)
+{
+	int rc = 0;
+	u32 dummy = 0xFFFFFFFF;
+
+	rc = fsi_device_write(fsi_dev, SCOM_RESET_REG, &dummy, sizeof(u32));
+	if (rc) {
+		dev_dbg(&fsi_dev->dev,
+			"failed to write scom reset register rc:%d\n", rc);
+		return rc;
+	}
+
+	return scom_reset_fsi2pib(fsi_dev);
+}
+
+static ssize_t store_reset_register(struct device *dev,
+				    struct device_attribute *attr,
+				    const char *buf, size_t count)
+{
+	int rc;
+	struct fsi_device *fsi_dev = to_fsi_dev(dev);
+
+	rc = scom_full_reset(fsi_dev);
+
+	return rc ? rc : count;
+}
+DEVICE_ATTR(reset, 0200, NULL, store_reset_register);
+
 static int scom_probe(struct device *dev)
 {
 	struct fsi_device *fsi_dev = to_fsi_dev(dev);
@@ -200,6 +245,8 @@ static int scom_probe(struct device *dev)
 	scom->mdev.parent = dev;
 	list_add(&scom->link, &scom_devices);
 
+	device_create_file(dev, &dev_attr_reset);
+
 	return misc_register(&scom->mdev);
 }
 
@@ -207,6 +254,8 @@ static int scom_remove(struct device *dev)
 {
 	struct scom_device *scom, *scom_tmp;
 	struct fsi_device *fsi_dev = to_fsi_dev(dev);
+
+	device_remove_file(dev, &dev_attr_reset);
 	
 	list_for_each_entry_safe(scom, scom_tmp, &scom_devices, link) {
 		if (scom->fsi_dev == fsi_dev) {
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 3 lines · Eddie James

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

full reset only

The commit message needs some work. Use full sentences, explain why the patch is required.

Quoted 22 lines
---
 drivers/fsi/fsi-scom.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 50 insertions(+), 1 deletion(-)
drivers/fsi/fsi-scom.c +3 -0
index ff8267b..c73bd91 100644
@@ -32,7 +32,10 @@
 #define SCOM_DATA0_REG         0x00
 #define SCOM_DATA1_REG         0x04
 #define SCOM_CMD_REG           0x08
+#define SCOM_FSI2PIB_RESET_REG 0x18
 #define SCOM_RESET_REG         0x1C
+#define SCOM_COMP_MASK_REG     0x30
+#define SCOM_TRUE_MASK_REG     0x34
 
 #define SCOM_RESET_CMD         0x80000000
 #define SCOM_WRITE_CMD         0x80000000

drivers/fsi/fsi-scom.c static ssize_t scom_write(struct file *filep, const char __user *buf, · line 162

Quoted 5 lines
drivers/fsi/fsi-scom.c +1 -1
@@ -156,7 +159,7 @@ static ssize_t scom_write(struct file *filep, const char __user *buf,
        if (rc)
                dev_dbg(dev, "put_scom failed with:%d\n", rc);
 
-       return rc;
+       return rc ? rc : len;

This looks like an unrelated fix.

Quoted 7 lines
drivers/fsi/fsi-scom.c +0 -0
 }
 
 static loff_t scom_llseek(struct file *file, loff_t offset, int whence)
@@ -181,6 +184,48 @@ static const struct file_operations scom_fops = {
        .write  = scom_write,
 };
 

drivers/fsi/fsi-scom.c static const struct file_operations scom_fops = { · line 196

Quoted 10 lines
drivers/fsi/fsi-scom.c +10 -0
+static int scom_reset_fsi2pib(struct fsi_device *fsi_dev)
+{
+       int rc;
+       u32 dummy = 0xFFFFFFFF;
+
+       rc = fsi_device_write(fsi_dev, SCOM_FSI2PIB_RESET_REG, &dummy,
+                             sizeof(u32));
+       if (rc)
+               dev_dbg(&fsi_dev->dev,
+                       "failed to write fsi2pib reset register rc:%d\n", rc);

Is this expected behaviour? If not, use dev_err.

drivers/fsi/fsi-scom.c static const struct file_operations scom_fops = { · line 206

Quoted 10 lines
drivers/fsi/fsi-scom.c +10 -0
+
+       return rc;
+}
+
+static int scom_full_reset(struct fsi_device *fsi_dev)
+{
+       int rc = 0;
+       u32 dummy = 0xFFFFFFFF;
+
+       rc = fsi_device_write(fsi_dev, SCOM_RESET_REG, &dummy, sizeof(u32));

sizeof(dummy)

Quoted 26 lines
drivers/fsi/fsi-scom.c +22 -0
+       if (rc) {
+               dev_dbg(&fsi_dev->dev,
+                       "failed to write scom reset register rc:%d\n", rc);
+               return rc;
+       }
+
+       return scom_reset_fsi2pib(fsi_dev);
+}
+
+static ssize_t store_reset_register(struct device *dev,
+                                   struct device_attribute *attr,
+                                   const char *buf, size_t count)
+{
+       int rc;
+       struct fsi_device *fsi_dev = to_fsi_dev(dev);
+
+       rc = scom_full_reset(fsi_dev);
+
+       return rc ? rc : count;
+}
+DEVICE_ATTR(reset, 0200, NULL, store_reset_register);
+
 static int scom_probe(struct device *dev)
 {
        struct fsi_device *fsi_dev = to_fsi_dev(dev);

drivers/fsi/fsi-scom.c static int scom_probe(struct device *dev) · line 249

Quoted 5 lines
drivers/fsi/fsi-scom.c +2 -0
@@ -200,6 +245,8 @@ static int scom_probe(struct device *dev)
        scom->mdev.parent = dev;
        list_add(&scom->link, &scom_devices);
 
+       device_create_file(dev, &dev_attr_reset);
+

What is the expected behaviour if two different userspace programs have the reset and chardev open?

Quoted 15 lines
drivers/fsi/fsi-scom.c +2 -1
        return misc_register(&scom->mdev);
 }
 
@@ -207,6 +254,8 @@ static int scom_remove(struct device *dev)
 {
        struct scom_device *scom, *scom_tmp;
        struct fsi_device *fsi_dev = to_fsi_dev(dev);
+
+       device_remove_file(dev, &dev_attr_reset);
 
        list_for_each_entry_safe(scom, scom_tmp, &scom_devices, link) {
                if (scom->fsi_dev == fsi_dev) {
--

1.8.3.1

#2 lore raw
Quoted 6 lines · Joel Stanley
Quoted 3 lines · Eddie James

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

full reset only

The commit message needs some work. Use full sentences, explain why the patch is required.

Ok.

Quoted 25 lines
Quoted 25 lines
---
  drivers/fsi/fsi-scom.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-
  1 file changed, 50 insertions(+), 1 deletion(-)
drivers/fsi/fsi-scom.c +3 -0
index ff8267b..c73bd91 100644
@@ -32,7 +32,10 @@
  #define SCOM_DATA0_REG         0x00
  #define SCOM_DATA1_REG         0x04
  #define SCOM_CMD_REG           0x08
+#define SCOM_FSI2PIB_RESET_REG 0x18
  #define SCOM_RESET_REG         0x1C
+#define SCOM_COMP_MASK_REG     0x30
+#define SCOM_TRUE_MASK_REG     0x34
 
  #define SCOM_RESET_CMD         0x80000000
  #define SCOM_WRITE_CMD         0x80000000
@@ -156,7 +159,7 @@ static ssize_t scom_write(struct file *filep, const char __user *buf,
         if (rc)
                 dev_dbg(dev, "put_scom failed with:%d\n", rc);
 
Quoted 3 lines

drivers/fsi/fsi-scom.c static ssize_t scom_write(struct file *filep, const char __user *buf, · line 162

Quoted 2 lines
drivers/fsi/fsi-scom.c +1 -1
-       return rc;
+       return rc ? rc : len;

This looks like an unrelated fix.

Yes, I guess a separate patch is in order.

Quoted 8 lines
Quoted 8 lines
drivers/fsi/fsi-scom.c +0 -0
  }
 
  static loff_t scom_llseek(struct file *file, loff_t offset, int whence)
@@ -181,6 +184,48 @@ static const struct file_operations scom_fops = {
         .write  = scom_write,
  };
 
Quoted 11 lines

drivers/fsi/fsi-scom.c static const struct file_operations scom_fops = { · line 196

Quoted 10 lines
drivers/fsi/fsi-scom.c +10 -0
+static int scom_reset_fsi2pib(struct fsi_device *fsi_dev)
+{
+       int rc;
+       u32 dummy = 0xFFFFFFFF;
+
+       rc = fsi_device_write(fsi_dev, SCOM_FSI2PIB_RESET_REG, &dummy,
+                             sizeof(u32));
+       if (rc)
+               dev_dbg(&fsi_dev->dev,
+                       "failed to write fsi2pib reset register rc:%d\n", rc);

Is this expected behaviour? If not, use dev_err.

The rest of the driver uses dev_dbg even in error situations, so I tried to follow suit here.

Quoted 42 lines

drivers/fsi/fsi-scom.c static const struct file_operations scom_fops = { · line 206

Quoted 11 lines
drivers/fsi/fsi-scom.c +10 -0
+
+       return rc;
+}
+
+static int scom_full_reset(struct fsi_device *fsi_dev)
+{
+       int rc = 0;
+       u32 dummy = 0xFFFFFFFF;
+
+       rc = fsi_device_write(fsi_dev, SCOM_RESET_REG, &dummy, sizeof(u32));

sizeof(dummy)

Quoted 29 lines
drivers/fsi/fsi-scom.c +22 -0
+       if (rc) {
+               dev_dbg(&fsi_dev->dev,
+                       "failed to write scom reset register rc:%d\n", rc);
+               return rc;
+       }
+
+       return scom_reset_fsi2pib(fsi_dev);
+}
+
+static ssize_t store_reset_register(struct device *dev,
+                                   struct device_attribute *attr,
+                                   const char *buf, size_t count)
+{
+       int rc;
+       struct fsi_device *fsi_dev = to_fsi_dev(dev);
+
+       rc = scom_full_reset(fsi_dev);
+
+       return rc ? rc : count;
+}
+DEVICE_ATTR(reset, 0200, NULL, store_reset_register);
+
  static int scom_probe(struct device *dev)
  {
         struct fsi_device *fsi_dev = to_fsi_dev(dev);
@@ -200,6 +245,8 @@ static int scom_probe(struct device *dev)
         scom->mdev.parent = dev;
         list_add(&scom->link, &scom_devices);
 
Quoted 4 lines

drivers/fsi/fsi-scom.c static int scom_probe(struct device *dev) · line 249

Quoted 2 lines
drivers/fsi/fsi-scom.c +2 -0
+       device_create_file(dev, &dev_attr_reset);
+

What is the expected behaviour if two different userspace programs have the reset and chardev open?

Probably a bus error or some sort of scom error if you write reset while you have a getscom/putscom operation going. Could add some locking?

Thanks,
Eddie

Quoted 16 lines
Quoted 16 lines
drivers/fsi/fsi-scom.c +2 -1
         return misc_register(&scom->mdev);
  }
 
@@ -207,6 +254,8 @@ static int scom_remove(struct device *dev)
  {
         struct scom_device *scom, *scom_tmp;
         struct fsi_device *fsi_dev = to_fsi_dev(dev);
+
+       device_remove_file(dev, &dev_attr_reset);
 
         list_for_each_entry_safe(scom, scom_tmp, &scom_devices, link) {
                 if (scom->fsi_dev == fsi_dev) {
--

1.8.3.1

#3 lore raw

I'm abandoning this. The reset procedure is simple enough to do from the cronus ADAL layer. In FSP code it had a bunch of checks for cfam type, so I thought it would continue to make sense in the driver. But we don't need that here.

Thanks,

Eddie

Quoted 139 lines · Eddie James
Quoted 6 lines · Joel Stanley
Quoted 3 lines · Eddie James

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

full reset only

The commit message needs some work. Use full sentences, explain why the patch is required.

Ok.

Quoted 27 lines
Quoted 27 lines
---
  drivers/fsi/fsi-scom.c | 51 
+++++++++++++++++++++++++++++++++++++++++++++++++-
  1 file changed, 50 insertions(+), 1 deletion(-)
drivers/fsi/fsi-scom.c +3 -0
index ff8267b..c73bd91 100644
@@ -32,7 +32,10 @@
  #define SCOM_DATA0_REG         0x00
  #define SCOM_DATA1_REG         0x04
  #define SCOM_CMD_REG           0x08
+#define SCOM_FSI2PIB_RESET_REG 0x18
  #define SCOM_RESET_REG         0x1C
+#define SCOM_COMP_MASK_REG     0x30
+#define SCOM_TRUE_MASK_REG     0x34
 
  #define SCOM_RESET_CMD         0x80000000
  #define SCOM_WRITE_CMD         0x80000000
@@ -156,7 +159,7 @@ static ssize_t scom_write(struct file *filep, 
 const char __user *buf,
         if (rc)
                 dev_dbg(dev, "put_scom failed with:%d\n", rc);
 
Quoted 3 lines

drivers/fsi/fsi-scom.c static ssize_t scom_write(struct file *filep, const char __user *buf, · line 162

Quoted 2 lines
drivers/fsi/fsi-scom.c +1 -1
-       return rc;
+       return rc ? rc : len;

This looks like an unrelated fix.

Yes, I guess a separate patch is in order.

Quoted 9 lines
Quoted 9 lines
drivers/fsi/fsi-scom.c +0 -0
  }
 

static loff_t scom_llseek(struct file *file, loff_t offset, int
whence)

drivers/fsi/fsi-scom.c +0 -0
@@ -181,6 +184,48 @@ static const struct file_operations scom_fops = {
         .write  = scom_write,
  };
 
Quoted 12 lines

drivers/fsi/fsi-scom.c static const struct file_operations scom_fops = {

Quoted 11 lines
drivers/fsi/fsi-scom.c +10 -0
+static int scom_reset_fsi2pib(struct fsi_device *fsi_dev)
+{
+       int rc;
+       u32 dummy = 0xFFFFFFFF;
+
+       rc = fsi_device_write(fsi_dev, SCOM_FSI2PIB_RESET_REG, &dummy,
+                             sizeof(u32));
+       if (rc)
+               dev_dbg(&fsi_dev->dev,
+                       "failed to write fsi2pib reset register 
 rc:%d\n", rc);

Is this expected behaviour? If not, use dev_err.

The rest of the driver uses dev_dbg even in error situations, so I tried to follow suit here.

Quoted 44 lines

drivers/fsi/fsi-scom.c static const struct file_operations scom_fops = {

Quoted 12 lines
drivers/fsi/fsi-scom.c +10 -0
+
+       return rc;
+}
+
+static int scom_full_reset(struct fsi_device *fsi_dev)
+{
+       int rc = 0;
+       u32 dummy = 0xFFFFFFFF;
+
+       rc = fsi_device_write(fsi_dev, SCOM_RESET_REG, &dummy, 
 sizeof(u32));

sizeof(dummy)

Quoted 30 lines
drivers/fsi/fsi-scom.c +22 -0
+       if (rc) {
+               dev_dbg(&fsi_dev->dev,
+                       "failed to write scom reset register 
 rc:%d\n", rc);
+               return rc;
+       }
+
+       return scom_reset_fsi2pib(fsi_dev);
+}
+
+static ssize_t store_reset_register(struct device *dev,
+                                   struct device_attribute *attr,
+                                   const char *buf, size_t count)
+{
+       int rc;
+       struct fsi_device *fsi_dev = to_fsi_dev(dev);
+
+       rc = scom_full_reset(fsi_dev);
+
+       return rc ? rc : count;
+}
+DEVICE_ATTR(reset, 0200, NULL, store_reset_register);
+
  static int scom_probe(struct device *dev)
  {
         struct fsi_device *fsi_dev = to_fsi_dev(dev);
drivers/fsi/fsi-scom.c +0 -0
@@ -200,6 +245,8 @@ static int scom_probe(struct device *dev)
         scom->mdev.parent = dev;
         list_add(&scom->link, &scom_devices);
 
Quoted 4 lines

drivers/fsi/fsi-scom.c static int scom_probe(struct device *dev) · line 249

Quoted 2 lines
drivers/fsi/fsi-scom.c +2 -0
+       device_create_file(dev, &dev_attr_reset);
+

What is the expected behaviour if two different userspace programs have the reset and chardev open?

Probably a bus error or some sort of scom error if you write reset while you have a getscom/putscom operation going. Could add some locking?

Thanks,
Eddie

Quoted 17 lines
Quoted 17 lines
drivers/fsi/fsi-scom.c +2 -0
         return misc_register(&scom->mdev);
  }
 
@@ -207,6 +254,8 @@ static int scom_remove(struct device *dev)
  {
         struct scom_device *scom, *scom_tmp;
         struct fsi_device *fsi_dev = to_fsi_dev(dev);
+
+       device_remove_file(dev, &dev_attr_reset);
 
         list_for_each_entry_safe(scom, scom_tmp, &scom_devices, 
 link) {
                 if (scom->fsi_dev == fsi_dev) {
Signature · 1 line
1.8.3.1
#4 lore raw
In reply to Eddie James

Hi Eddie,

The changelog doesn't have much context, so a bit of a question:

drivers/fsi/fsi-scom.c static const struct file_operations scom_fops = { · line 228

Quoted 13 lines
drivers/fsi/fsi-scom.c +13 -0
+static ssize_t store_reset_register(struct device *dev,
+				    struct device_attribute *attr,
+				    const char *buf, size_t count)
+{
+	int rc;
+	struct fsi_device *fsi_dev = to_fsi_dev(dev);
+
+	rc = scom_full_reset(fsi_dev);
+
+	return rc ? rc : count;
+}
+DEVICE_ATTR(reset, 0200, NULL, store_reset_register);
+

How does this interact with the scom read/write operations? Having different interfaces access methods (file for one, sysfs interface for another)for both seems like an invitation for trouble - would this make more sense as an ioctl on the existing fd?

Cheers,

Jeremy

#5 lore raw
Quoted 13 lines · Jeremy Kerr

Hi Eddie,

The changelog doesn't have much context, so a bit of a question:

Quoted 9 lines
drivers/fsi/fsi-scom.c +9 -0
+static ssize_t store_reset_register(struct device *dev,
+				    struct device_attribute *attr,
+				    const char *buf, size_t count)
+{
+	int rc;
+	struct fsi_device *fsi_dev = to_fsi_dev(dev);
+
+	rc = scom_full_reset(fsi_dev);
+
Quoted 8 lines

drivers/fsi/fsi-scom.c static const struct file_operations scom_fops = { · line 228

Quoted 4 lines
drivers/fsi/fsi-scom.c +4 -0
+	return rc ? rc : count;
+}
+DEVICE_ATTR(reset, 0200, NULL, store_reset_register);
+

How does this interact with the scom read/write operations? Having different interfaces access methods (file for one, sysfs interface for another)for both seems like an invitation for trouble - would this make more sense as an ioctl on the existing fd?

It would, but I was under the impression ioctls were frowned upon for some reason? Since we only have one option (reset), I felt a sysfs entry made more sense for now? It doesn't interact at all with the read/write operations, though I suppose if you wrote reset while in the middle of a getscom/putscom, you'd probably end up with a bus error. I'd classify that as user error. We could add some sort of locking.

Quoted 6 lines

Cheers,

Jeremy

#6 lore raw

Hi Eddie,

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
drivers/fsi/fsi-scom.c +9 -0
+static ssize_t store_reset_register(struct device *dev,
+                    struct device_attribute *attr,
+                    const char *buf, size_t count)
+{
+    int rc;
+    struct fsi_device *fsi_dev = to_fsi_dev(dev);
+
+    rc = scom_full_reset(fsi_dev);
+
Quoted 8 lines

drivers/fsi/fsi-scom.c static const struct file_operations scom_fops = { · line 228

Quoted 4 lines
drivers/fsi/fsi-scom.c +4 -0
+    return rc ? rc : count;
+}
+DEVICE_ATTR(reset, 0200, NULL, store_reset_register);
+

How does this interact with the scom read/write operations? Having different interfaces access methods (file for one, sysfs interface for another)for both seems like an invitation for trouble - would this make more sense as an ioctl on the existing fd?

Quoted 2 lines

It would, but I was under the impression ioctls were frowned upon for some reason?

The downside of an ioctl is that it needs a new definition in kernel headers (ie, the ioctl number and any structures required for input/output data).

However, I think it's entirely suitable in this case - we have the usual flow of data (the scoms) over read()/write(), and control operations (reset) using an ioctl.

However, that assumes that the reset is something that a user may want to issue in normal operation, rather than a debug or diagnosis event. Is that the case here?

Cheers,

Jeremy