Re: [PATCH 3/7] net: dsa: ar8xxx: add regmap support

2015-05-30 Thread Sergey Ryazanov
2015-05-29 20:59 GMT+03:00 Andrew Lunn :
> On Fri, May 29, 2015 at 10:36:49AM -0700, Mathieu Olivari wrote:
>> Alternatively, we could have something similar to what happens for the phy
>> in the wireless subsystems. Wireless PHYs are not registered as net_device
>> but they can still be listed, queried or configured through netlink.
>
> It is a reasonable idea, but you retrieve most of the useful
> information using ethtool. That, as far as i know, operates on
> net_devices, not phys.
>
May be it's time to rework Ethernet cards handling to decouple
"Network interfaces" from "Ethernet ports"?

-- 
Sergey
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/7] net: dsa: ar8xxx: add regmap support

2015-05-29 Thread Andrew Lunn
On Fri, May 29, 2015 at 10:36:49AM -0700, Mathieu Olivari wrote:
> Alternatively, we could have something similar to what happens for the phy
> in the wireless subsystems. Wireless PHYs are not registered as net_device
> but they can still be listed, queried or configured through netlink.

It is a reasonable idea, but you retrieve most of the useful
information using ethtool. That, as far as i know, operates on
net_devices, not phys.

 Andrew
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH 3/7] net: dsa: ar8xxx: add regmap support

2015-05-29 Thread Mathieu Olivari
Alternatively, we could have something similar to what happens for the phy
in the wireless subsystems. Wireless PHYs are not registered as net_device
but they can still be listed, queried or configured through netlink.
Just thinking out loud here.

Thanks,
Mathieu

-Original Message-
From: Andrew Lunn [mailto:and...@lunn.ch] 
Sent: Thursday, May 28, 2015 7:44 PM
To: Florian Fainelli
Cc: Mathieu Olivari; robh...@kernel.org; pawel.m...@arm.com;
mark.rutl...@arm.com; ijc+devicet...@hellion.org.uk; ga...@codeaurora.org;
da...@davemloft.net; li...@roeck-us.net; gang.chen.5...@gmail.com;
j...@resnulli.us; lei...@staticky.com; f...@skynet.be;
pavel.nakonec...@skitlab.ru; j...@perches.com; sfel...@gmail.com;
n...@openwrt.org; juh...@openwrt.org; devicet...@vger.kernel.org;
linux-ker...@vger.kernel.org; netdev@vger.kernel.org
Subject: Re: [PATCH 3/7] net: dsa: ar8xxx: add regmap support

> Fair enough, are there other global "things" besides counters that 
> could deserve adding maybe some sort of global/master net_device to 
> help query switch-wide information?

This was discussed a while back. I like the current abstraction, all
interfaces are real interfaces you can send and receive packets over. This
pseudo interface cannot be used for packet transfer, which seems odd.

Having access to registers for debugging, so debugfs seems like the best
option to me.

 Andrew

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/7] net: dsa: ar8xxx: add regmap support

2015-05-28 Thread Andrew Lunn
> Fair enough, are there other global "things" besides counters that could
> deserve adding maybe some sort of global/master net_device to help query
> switch-wide information?

This was discussed a while back. I like the current abstraction, all
interfaces are real interfaces you can send and receive packets
over. This pseudo interface cannot be used for packet transfer, which
seems odd.

Having access to registers for debugging, so debugfs seems like the
best option to me.

 Andrew
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/7] net: dsa: ar8xxx: add regmap support

2015-05-28 Thread Florian Fainelli
Le 05/28/15 19:23, Andrew Lunn a écrit :
> On Thu, May 28, 2015 at 06:58:14PM -0700, Florian Fainelli wrote:
>> Le 05/28/15 18:42, Mathieu Olivari a écrit :
>>> All switch registers can now be dumped using regmap/debugfs.
>>>
>>> \# cat /sys/kernel/debug/regmap//registers
>>> : 1302
>>> 0004: ...
>>> ...
>>
>> ethtool has a register dump command, which should already be supported
>> by the current code in net/dsa/slave.c, is there a particular reason why
>> you use debugfs here instead?
> 
> Hi Florian
> 
> ethtool -d allows you to dump the registers for a port which has a
> slave device. It is sometimes useful to dump the cpu ports registers,
> or DSA ports, i.e. inter switch ports. Marvell devices also have two
> sets of global registers, not specific to any port.
> 
> For my debugging, i have code which allows you to read the registers
> via debugfs.

Fair enough, are there other global "things" besides counters that could
deserve adding maybe some sort of global/master net_device to help query
switch-wide information?
-- 
Florian
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/7] net: dsa: ar8xxx: add regmap support

2015-05-28 Thread Andrew Lunn
On Thu, May 28, 2015 at 06:58:14PM -0700, Florian Fainelli wrote:
> Le 05/28/15 18:42, Mathieu Olivari a écrit :
> > All switch registers can now be dumped using regmap/debugfs.
> > 
> > \# cat /sys/kernel/debug/regmap//registers
> > : 1302
> > 0004: ...
> > ...
> 
> ethtool has a register dump command, which should already be supported
> by the current code in net/dsa/slave.c, is there a particular reason why
> you use debugfs here instead?

Hi Florian

ethtool -d allows you to dump the registers for a port which has a
slave device. It is sometimes useful to dump the cpu ports registers,
or DSA ports, i.e. inter switch ports. Marvell devices also have two
sets of global registers, not specific to any port.

For my debugging, i have code which allows you to read the registers
via debugfs.

Andrew
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/7] net: dsa: ar8xxx: add regmap support

2015-05-28 Thread Florian Fainelli
Le 05/28/15 18:42, Mathieu Olivari a écrit :
> All switch registers can now be dumped using regmap/debugfs.
> 
> \# cat /sys/kernel/debug/regmap//registers
> : 1302
> 0004: ...
> ...

ethtool has a register dump command, which should already be supported
by the current code in net/dsa/slave.c, is there a particular reason why
you use debugfs here instead?
-- 
Florian
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/7] net: dsa: ar8xxx: add regmap support

2015-05-28 Thread Mathieu Olivari
All switch registers can now be dumped using regmap/debugfs.

\# cat /sys/kernel/debug/regmap//registers
: 1302
0004: ...
...

Signed-off-by: Mathieu Olivari 
---
 drivers/net/dsa/Kconfig  |  1 +
 drivers/net/dsa/ar8xxx.c | 60 
 drivers/net/dsa/ar8xxx.h |  5 
 3 files changed, 66 insertions(+)

diff --git a/drivers/net/dsa/Kconfig b/drivers/net/dsa/Kconfig
index 2aae541..17fb296 100644
--- a/drivers/net/dsa/Kconfig
+++ b/drivers/net/dsa/Kconfig
@@ -68,6 +68,7 @@ config NET_DSA_BCM_SF2
 config NET_DSA_AR8XXX
tristate "Qualcomm Atheros AR8XXX Ethernet switch family support"
depends on NET_DSA
+   select REGMAP
---help---
  This enables support for the Qualcomm Atheros AR8XXX Ethernet
  switch chips.
diff --git a/drivers/net/dsa/ar8xxx.c b/drivers/net/dsa/ar8xxx.c
index 2f0fa4d..327abd4 100644
--- a/drivers/net/dsa/ar8xxx.c
+++ b/drivers/net/dsa/ar8xxx.c
@@ -176,6 +176,57 @@ static char *ar8xxx_probe(struct device *host_dev, int 
sw_addr)
}
 }
 
+static int ar8xxx_regmap_read(void *ctx, uint32_t reg, uint32_t *val)
+{
+   struct dsa_switch *ds = (struct dsa_switch *)ctx;
+
+   *val = ar8xxx_read(ds, reg);
+
+   return 0;
+}
+
+static int ar8xxx_regmap_write(void *ctx, uint32_t reg, uint32_t val)
+{
+   struct dsa_switch *ds = (struct dsa_switch *)ctx;
+
+   ar8xxx_write(ds, reg, val);
+
+   return 0;
+}
+
+static const struct regmap_range ar8xxx_readable_ranges[] = {
+   regmap_reg_range(0x, 0x00e4), /* Global control */
+   regmap_reg_range(0x0100, 0x0168), /* EEE control */
+   regmap_reg_range(0x0200, 0x0270), /* Parser control */
+   regmap_reg_range(0x0400, 0x0454), /* ACL */
+   regmap_reg_range(0x0600, 0x0718), /* Lookup */
+   regmap_reg_range(0x0800, 0x0b70), /* QM */
+   regmap_reg_range(0x0C00, 0x0c80), /* PKT */
+   regmap_reg_range(0x1000, 0x10ac), /* MIB - Port0 */
+   regmap_reg_range(0x1100, 0x11ac), /* MIB - Port1 */
+   regmap_reg_range(0x1200, 0x12ac), /* MIB - Port2 */
+   regmap_reg_range(0x1300, 0x13ac), /* MIB - Port3 */
+   regmap_reg_range(0x1400, 0x14ac), /* MIB - Port4 */
+   regmap_reg_range(0x1500, 0x15ac), /* MIB - Port5 */
+   regmap_reg_range(0x1600, 0x16ac), /* MIB - Port6 */
+
+};
+
+static struct regmap_access_table ar8xxx_readable_table = {
+   .yes_ranges = ar8xxx_readable_ranges,
+   .n_yes_ranges = ARRAY_SIZE(ar8xxx_readable_ranges),
+};
+
+struct regmap_config ar8xxx_regmap_config = {
+   .reg_bits = 16,
+   .val_bits = 32,
+   .reg_stride = 4,
+   .max_register = 0x16ac, /* end MIB - Port6 range */
+   .reg_read = ar8xxx_regmap_read,
+   .reg_write = ar8xxx_regmap_write,
+   .rd_table = &ar8xxx_readable_table,
+};
+
 static int ar8xxx_set_pad_ctrl(struct dsa_switch *ds, int port, int mode)
 {
int reg;
@@ -219,9 +270,17 @@ static int ar8xxx_set_pad_ctrl(struct dsa_switch *ds, int 
port, int mode)
 
 static int ar8xxx_setup(struct dsa_switch *ds)
 {
+   struct ar8xxx_priv *priv = ds_to_priv(ds);
struct net_device *netdev = ds->dst->pd->of_netdev;
int ret, i, phy_mode;
 
+   /* Start by setting up the register mapping */
+   priv->regmap = devm_regmap_init(ds->master_dev, NULL, ds,
+   &ar8xxx_regmap_config);
+
+   if (IS_ERR(priv->regmap))
+   pr_warn("regmap initialization failed");
+
/* Initialize CPU port pad mode (xMII type, delays...) */
phy_mode = of_get_phy_mode(netdev->dev.parent->of_node);
if (phy_mode < 0) {
@@ -365,6 +424,7 @@ static void ar8xxx_poll_link(struct dsa_switch *ds)
 
 static struct dsa_switch_driver ar8xxx_switch_driver = {
.tag_protocol   = DSA_TAG_PROTO_NONE,
+   .priv_size  = sizeof(struct ar8xxx_priv),
.probe  = ar8xxx_probe,
.setup  = ar8xxx_setup,
.set_addr   = ar8xxx_set_addr,
diff --git a/drivers/net/dsa/ar8xxx.h b/drivers/net/dsa/ar8xxx.h
index 7c7a125..98cc7ed 100644
--- a/drivers/net/dsa/ar8xxx.h
+++ b/drivers/net/dsa/ar8xxx.h
@@ -17,6 +17,11 @@
 #define __AR8XXX_H
 
 #include 
+#include 
+
+struct ar8xxx_priv {
+   struct regmap *regmap;
+};
 
 struct ar8xxx_mib_desc {
unsigned int size;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html