netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] net: dsa: mv88e6xxx: add write access to debugfs regs file
@ 2015-07-09 21:13 Vivien Didelot
  2015-07-11  6:01 ` David Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Vivien Didelot @ 2015-07-09 21:13 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Guenter Roeck, Andrew Lunn, linux-kernel, kernel,
	Vivien Didelot

Allow write access to the regs file in the debugfs interface, with the
following parameters:

    echo <name> <reg> <value> > regs

Where "name" is the register name (as shown in the header row), "reg" is
the register address (as shown in the first column) and "value" is the
16-bit value. e.g.:

    echo GLOBAL 1a 5550 > regs

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
---
 drivers/net/dsa/mv88e6xxx.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/net/dsa/mv88e6xxx.c b/drivers/net/dsa/mv88e6xxx.c
index 8c130c0..9d14b1a 100644
--- a/drivers/net/dsa/mv88e6xxx.c
+++ b/drivers/net/dsa/mv88e6xxx.c
@@ -1648,6 +1648,38 @@ static int mv88e6xxx_regs_show(struct seq_file *s, void *p)
 	return 0;
 }
 
+static ssize_t mv88e6xxx_regs_write(struct file *file, const char __user *buf,
+				    size_t count, loff_t *ppos)
+{
+	struct seq_file *s = file->private_data;
+	struct dsa_switch *ds = s->private;
+	struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
+	char name[32] = { 0 };
+	unsigned int port, reg, val;
+	int ret;
+
+	if (count > sizeof(name) - 1)
+		return -EINVAL;
+
+	ret = sscanf(buf, "%s %x %x", name, &reg, &val);
+	if (ret != 3)
+		return -EINVAL;
+
+	if (reg > 0x1f || val > 0xffff)
+		return -ERANGE;
+
+	if (strcasecmp(name, "GLOBAL") == 0)
+		ret = mv88e6xxx_reg_write(ds, REG_GLOBAL, reg, val);
+	else if (strcasecmp(name, "GLOBAL2") == 0)
+		ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, reg, val);
+	else if (kstrtouint(name, 10, &port) == 0 && port < ps->num_ports)
+		ret = mv88e6xxx_reg_write(ds, REG_PORT(port), reg, val);
+	else
+		return -EINVAL;
+
+	return ret < 0 ? ret : count;
+}
+
 static int mv88e6xxx_regs_open(struct inode *inode, struct file *file)
 {
 	return single_open(file, mv88e6xxx_regs_show, inode->i_private);
@@ -1656,6 +1688,7 @@ static int mv88e6xxx_regs_open(struct inode *inode, struct file *file)
 static const struct file_operations mv88e6xxx_regs_fops = {
 	.open   = mv88e6xxx_regs_open,
 	.read   = seq_read,
+	.write	= mv88e6xxx_regs_write,
 	.llseek = no_llseek,
 	.release = single_release,
 	.owner  = THIS_MODULE,
@@ -1895,7 +1928,7 @@ int mv88e6xxx_setup_common(struct dsa_switch *ds)
 	ps->dbgfs = debugfs_create_dir(name, NULL);
 	kfree(name);
 
-	debugfs_create_file("regs", S_IRUGO, ps->dbgfs, ds,
+	debugfs_create_file("regs", S_IRUGO | S_IWUSR, ps->dbgfs, ds,
 			    &mv88e6xxx_regs_fops);
 
 	debugfs_create_file("atu", S_IRUGO, ps->dbgfs, ds,
-- 
2.4.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-07-13  3:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-09 21:13 [PATCH v2] net: dsa: mv88e6xxx: add write access to debugfs regs file Vivien Didelot
2015-07-11  6:01 ` David Miller
2015-07-11 18:36   ` Vivien Didelot
2015-07-12  2:08     ` David Miller
2015-07-13  1:39       ` Vivien Didelot
2015-07-13  3:25         ` David Miller

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).