[PATCH 2/2] ath9K: debugfs: Fix SPUR-DOWN field

2019-02-21 Thread Andrea Greco
From: Andrea Greco 

SPUR DOWN field return spurup inside of spurdown

Signed-off-by: Andrea Greco 
---
 drivers/net/wireless/ath/ath9k/debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath9k/debug.c 
b/drivers/net/wireless/ath/ath9k/debug.c
index 4399e9ad058f..d4a2cdf9212c 100644
--- a/drivers/net/wireless/ath/ath9k/debug.c
+++ b/drivers/net/wireless/ath/ath9k/debug.c
@@ -148,7 +148,7 @@ static ssize_t read_file_ani(struct file *file, char __user 
*user_buf,
{ "OFDM LEVEL", ah->ani.ofdmNoiseImmunityLevel },
{ "CCK LEVEL", ah->ani.cckNoiseImmunityLevel },
{ "SPUR UP", ah->stats.ast_ani_spurup },
-   { "SPUR DOWN", ah->stats.ast_ani_spurup },
+   { "SPUR DOWN", ah->stats.ast_ani_spurdown },
{ "OFDM WS-DET ON", ah->stats.ast_ani_ofdmon },
{ "OFDM WS-DET OFF", ah->stats.ast_ani_ofdmoff },
{ "MRC-CCK ON", ah->stats.ast_ani_ccklow },
-- 
2.17.2



[PATCH 1/2] nl80211: Allow change CW to Ad-Hock network

2019-02-21 Thread Andrea Greco
From: Andrea Greco 

Add net-link support for change CW in Ad-Hock network

Signed-off-by: Andrea Greco 
---
 net/wireless/nl80211.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index d91a408db113..4fcc63fa4380 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -2731,7 +2731,8 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct 
genl_info *info)
return -EINVAL;
 
if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
-   netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
+   netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO &&
+   netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
return -EINVAL;
 
if (!netif_running(netdev))
-- 
2.17.2



[PATCH 4/6] arcnet: com20020: bindings for smsc com20020

2018-06-11 Thread Andrea Greco
From: Andrea Greco 

Add devicetree bindings for smsc com20020

Signed-off-by: Andrea Greco 
---
 .../devicetree/bindings/net/smsc-com20020.txt   | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/smsc-com20020.txt

diff --git a/Documentation/devicetree/bindings/net/smsc-com20020.txt 
b/Documentation/devicetree/bindings/net/smsc-com20020.txt
new file mode 100644
index ..660a4a751f29
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/smsc-com20020.txt
@@ -0,0 +1,21 @@
+SMSC com20020 Arcnet network controller
+
+Required property:
+- timeout-ns: Arcnet bus timeout, Idle Time (328000 - 20500)
+- bus-speed-bps: Arcnet bus speed (1000 - 156250)
+- smsc,xtal-mhz: External oscillator frequency
+- smsc,backplane-enabled: Controller use backplane mode
+- reset-gpios: Chip reset pin
+- interrupts: Should contain controller interrupt
+
+arcnet@2800 {
+   compatible = "smsc,com20020";
+
+   timeout-ns = <20500>;
+   bus-speed-hz = <1000>;
+   smsc,xtal-mhz = <20>;
+   smsc,backplane-enabled;
+
+   reset-gpios = < 21 GPIO_ACTIVE_LOW>;
+   interrupts = < 10 GPIO_ACTIVE_LOW>;
+};
-- 
2.14.4



[PATCH 4/6] arcnet: com20020: bindings for smsc com20020

2018-06-11 Thread Andrea Greco
From: Andrea Greco 

Add devicetree bindings for smsc com20020

Signed-off-by: Andrea Greco 
---
 .../devicetree/bindings/net/smsc-com20020.txt   | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/smsc-com20020.txt

diff --git a/Documentation/devicetree/bindings/net/smsc-com20020.txt 
b/Documentation/devicetree/bindings/net/smsc-com20020.txt
new file mode 100644
index ..660a4a751f29
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/smsc-com20020.txt
@@ -0,0 +1,21 @@
+SMSC com20020 Arcnet network controller
+
+Required property:
+- timeout-ns: Arcnet bus timeout, Idle Time (328000 - 20500)
+- bus-speed-bps: Arcnet bus speed (1000 - 156250)
+- smsc,xtal-mhz: External oscillator frequency
+- smsc,backplane-enabled: Controller use backplane mode
+- reset-gpios: Chip reset pin
+- interrupts: Should contain controller interrupt
+
+arcnet@2800 {
+   compatible = "smsc,com20020";
+
+   timeout-ns = <20500>;
+   bus-speed-hz = <1000>;
+   smsc,xtal-mhz = <20>;
+   smsc,backplane-enabled;
+
+   reset-gpios = < 21 GPIO_ACTIVE_LOW>;
+   interrupts = < 10 GPIO_ACTIVE_LOW>;
+};
-- 
2.14.4



[PATCH 6/6] arcnet: com20020: Add ethtool support

2018-06-11 Thread Andrea Greco
From: Andrea Greco 

Setup ethtols for export com20020 diag register

Signed-off-by: Andrea Greco 
---
 drivers/net/arcnet/com20020-io.c  |  1 +
 drivers/net/arcnet/com20020-isa.c |  1 +
 drivers/net/arcnet/com20020.c | 24 
 drivers/net/arcnet/com20020.h |  1 +
 drivers/net/arcnet/com20020_cs.c  |  1 +
 include/uapi/linux/if_arcnet.h|  6 ++
 6 files changed, 34 insertions(+)

diff --git a/drivers/net/arcnet/com20020-io.c b/drivers/net/arcnet/com20020-io.c
index 23c24d4de5a9..9954d3a30ff6 100644
--- a/drivers/net/arcnet/com20020-io.c
+++ b/drivers/net/arcnet/com20020-io.c
@@ -203,6 +203,7 @@ static int com20020_probe(struct platform_device *pdev)
 
dev = alloc_arcdev(NULL);
dev->netdev_ops = _netdev_ops;
+   dev->ethtool_ops = _ethtool_ops;
lp = netdev_priv(dev);
 
lp->card_flags = ARC_CAN_10MBIT;
diff --git a/drivers/net/arcnet/com20020-isa.c 
b/drivers/net/arcnet/com20020-isa.c
index 757586de5d08..eba1bd82226c 100644
--- a/drivers/net/arcnet/com20020-isa.c
+++ b/drivers/net/arcnet/com20020-isa.c
@@ -155,6 +155,7 @@ static int __init com20020_init(void)
dev->dev_addr[0] = node;
 
dev->netdev_ops = _netdev_ops;
+   dev->ethtool_ops = _ethtool_ops;
 
lp = netdev_priv(dev);
 
diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index 1a0fd30fe8ae..60e5ae401b1b 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -232,6 +232,29 @@ const struct net_device_ops com20020_netdev_ops = {
.ndo_set_rx_mode = com20020_set_mc_list,
 };
 
+static int com20020_ethtool_regs_len(struct net_device *netdev)
+{
+   return sizeof(struct com20020_ethtool_regs);
+}
+
+static void com20020_ethtool_regs_read(struct net_device *dev,
+  struct ethtool_regs *regs, void *p)
+{
+   struct arcnet_local *lp = netdev_priv(dev);
+   struct com20020_ethtool_regs *com_reg = p;
+
+   memset(p, 0, sizeof(struct com20020_ethtool_regs));
+
+   com_reg->status = lp->hw.status(dev) & 0xFF;
+   com_reg->diag_register = (lp->hw.status(dev) >> 8) & 0xFF;
+   com_reg->reconf_count = lp->num_recons;
+}
+
+const struct ethtool_ops com20020_ethtool_ops = {
+   .get_regs = com20020_ethtool_regs_read,
+   .get_regs_len  = com20020_ethtool_regs_len,
+};
+
 /* Set up the struct net_device associated with this card.  Called after
  * probing succeeds.
  */
@@ -438,6 +461,7 @@ static void com20020_set_mc_list(struct net_device *dev)
 EXPORT_SYMBOL(com20020_check);
 EXPORT_SYMBOL(com20020_found);
 EXPORT_SYMBOL(com20020_netdev_ops);
+EXPORT_SYMBOL(com20020_ethtool_ops);
 #endif
 
 MODULE_LICENSE("GPL");
diff --git a/drivers/net/arcnet/com20020.h b/drivers/net/arcnet/com20020.h
index af18c7edc4fa..616f047b3661 100644
--- a/drivers/net/arcnet/com20020.h
+++ b/drivers/net/arcnet/com20020.h
@@ -31,6 +31,7 @@
 int com20020_check(struct net_device *dev);
 int com20020_found(struct net_device *dev, int shared);
 extern const struct net_device_ops com20020_netdev_ops;
+extern const struct ethtool_ops com20020_ethtool_ops;
 
 /* The number of low I/O ports used by the card. */
 #define ARCNET_TOTAL_SIZE 8
diff --git a/drivers/net/arcnet/com20020_cs.c b/drivers/net/arcnet/com20020_cs.c
index bca4e6c15e4f..127aff55794d 100644
--- a/drivers/net/arcnet/com20020_cs.c
+++ b/drivers/net/arcnet/com20020_cs.c
@@ -241,6 +241,7 @@ static int com20020_config(struct pcmcia_device *link)
}
 
dev->irq = link->irq;
+   dev->ethtool_ops = _ethtool_ops;
 
ret = pcmcia_enable_device(link);
if (ret)
diff --git a/include/uapi/linux/if_arcnet.h b/include/uapi/linux/if_arcnet.h
index 683878036d76..790c0fa7386d 100644
--- a/include/uapi/linux/if_arcnet.h
+++ b/include/uapi/linux/if_arcnet.h
@@ -127,4 +127,10 @@ struct archdr {
} soft;
 };
 
+struct com20020_ethtool_regs {
+   __u8 status;
+   __u8 diag_register;
+   __u32 reconf_count;
+};
+
 #endif /* _LINUX_IF_ARCNET_H */
-- 
2.14.4



[PATCH 6/6] arcnet: com20020: Add ethtool support

2018-06-11 Thread Andrea Greco
From: Andrea Greco 

Setup ethtols for export com20020 diag register

Signed-off-by: Andrea Greco 
---
 drivers/net/arcnet/com20020-io.c  |  1 +
 drivers/net/arcnet/com20020-isa.c |  1 +
 drivers/net/arcnet/com20020.c | 24 
 drivers/net/arcnet/com20020.h |  1 +
 drivers/net/arcnet/com20020_cs.c  |  1 +
 include/uapi/linux/if_arcnet.h|  6 ++
 6 files changed, 34 insertions(+)

diff --git a/drivers/net/arcnet/com20020-io.c b/drivers/net/arcnet/com20020-io.c
index 23c24d4de5a9..9954d3a30ff6 100644
--- a/drivers/net/arcnet/com20020-io.c
+++ b/drivers/net/arcnet/com20020-io.c
@@ -203,6 +203,7 @@ static int com20020_probe(struct platform_device *pdev)
 
dev = alloc_arcdev(NULL);
dev->netdev_ops = _netdev_ops;
+   dev->ethtool_ops = _ethtool_ops;
lp = netdev_priv(dev);
 
lp->card_flags = ARC_CAN_10MBIT;
diff --git a/drivers/net/arcnet/com20020-isa.c 
b/drivers/net/arcnet/com20020-isa.c
index 757586de5d08..eba1bd82226c 100644
--- a/drivers/net/arcnet/com20020-isa.c
+++ b/drivers/net/arcnet/com20020-isa.c
@@ -155,6 +155,7 @@ static int __init com20020_init(void)
dev->dev_addr[0] = node;
 
dev->netdev_ops = _netdev_ops;
+   dev->ethtool_ops = _ethtool_ops;
 
lp = netdev_priv(dev);
 
diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index 1a0fd30fe8ae..60e5ae401b1b 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -232,6 +232,29 @@ const struct net_device_ops com20020_netdev_ops = {
.ndo_set_rx_mode = com20020_set_mc_list,
 };
 
+static int com20020_ethtool_regs_len(struct net_device *netdev)
+{
+   return sizeof(struct com20020_ethtool_regs);
+}
+
+static void com20020_ethtool_regs_read(struct net_device *dev,
+  struct ethtool_regs *regs, void *p)
+{
+   struct arcnet_local *lp = netdev_priv(dev);
+   struct com20020_ethtool_regs *com_reg = p;
+
+   memset(p, 0, sizeof(struct com20020_ethtool_regs));
+
+   com_reg->status = lp->hw.status(dev) & 0xFF;
+   com_reg->diag_register = (lp->hw.status(dev) >> 8) & 0xFF;
+   com_reg->reconf_count = lp->num_recons;
+}
+
+const struct ethtool_ops com20020_ethtool_ops = {
+   .get_regs = com20020_ethtool_regs_read,
+   .get_regs_len  = com20020_ethtool_regs_len,
+};
+
 /* Set up the struct net_device associated with this card.  Called after
  * probing succeeds.
  */
@@ -438,6 +461,7 @@ static void com20020_set_mc_list(struct net_device *dev)
 EXPORT_SYMBOL(com20020_check);
 EXPORT_SYMBOL(com20020_found);
 EXPORT_SYMBOL(com20020_netdev_ops);
+EXPORT_SYMBOL(com20020_ethtool_ops);
 #endif
 
 MODULE_LICENSE("GPL");
diff --git a/drivers/net/arcnet/com20020.h b/drivers/net/arcnet/com20020.h
index af18c7edc4fa..616f047b3661 100644
--- a/drivers/net/arcnet/com20020.h
+++ b/drivers/net/arcnet/com20020.h
@@ -31,6 +31,7 @@
 int com20020_check(struct net_device *dev);
 int com20020_found(struct net_device *dev, int shared);
 extern const struct net_device_ops com20020_netdev_ops;
+extern const struct ethtool_ops com20020_ethtool_ops;
 
 /* The number of low I/O ports used by the card. */
 #define ARCNET_TOTAL_SIZE 8
diff --git a/drivers/net/arcnet/com20020_cs.c b/drivers/net/arcnet/com20020_cs.c
index bca4e6c15e4f..127aff55794d 100644
--- a/drivers/net/arcnet/com20020_cs.c
+++ b/drivers/net/arcnet/com20020_cs.c
@@ -241,6 +241,7 @@ static int com20020_config(struct pcmcia_device *link)
}
 
dev->irq = link->irq;
+   dev->ethtool_ops = _ethtool_ops;
 
ret = pcmcia_enable_device(link);
if (ret)
diff --git a/include/uapi/linux/if_arcnet.h b/include/uapi/linux/if_arcnet.h
index 683878036d76..790c0fa7386d 100644
--- a/include/uapi/linux/if_arcnet.h
+++ b/include/uapi/linux/if_arcnet.h
@@ -127,4 +127,10 @@ struct archdr {
} soft;
 };
 
+struct com20020_ethtool_regs {
+   __u8 status;
+   __u8 diag_register;
+   __u32 reconf_count;
+};
+
 #endif /* _LINUX_IF_ARCNET_H */
-- 
2.14.4



[PATCH 5/6] arcnet: com20020: Fixup missing SLOWARB bit

2018-06-11 Thread Andrea Greco
From: Andrea Greco 

If com20020 clock is major of 40Mhz SLOWARB bit is requested.

Signed-off-by: Andrea Greco 
---
 drivers/net/arcnet/com20020.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index 8d979a66d8e9..1a0fd30fe8ae 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -133,6 +133,10 @@ int com20020_check(struct net_device *dev)
lp->setup = lp->clockm ? 0 : (lp->clockp << 1);
lp->setup2 = (lp->clockm << 4) | 8;
 
+   /* If clock is major of 40Mhz, SLOWARB bit must be set */
+   if (lp->clockm > 1)
+   lp->setup2 |= SLOWARB;
+
/* CHECK: should we do this for SOHARD cards ? */
/* Enable P1Mode for backplane mode */
lp->setup = lp->setup | P1MODE;
-- 
2.14.4



[PATCH 4/6] arcnet: com20020: bindings for smsc com20020

2018-06-11 Thread Andrea Greco
From: Andrea Greco 

Add devicetree bindings for smsc com20020

Signed-off-by: Andrea Greco 
---
 .../devicetree/bindings/net/smsc-com20020.txt   | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/smsc-com20020.txt

diff --git a/Documentation/devicetree/bindings/net/smsc-com20020.txt 
b/Documentation/devicetree/bindings/net/smsc-com20020.txt
new file mode 100644
index ..660a4a751f29
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/smsc-com20020.txt
@@ -0,0 +1,21 @@
+SMSC com20020 Arcnet network controller
+
+Required property:
+- timeout-ns: Arcnet bus timeout, Idle Time (328000 - 20500)
+- bus-speed-bps: Arcnet bus speed (1000 - 156250)
+- smsc,xtal-mhz: External oscillator frequency
+- smsc,backplane-enabled: Controller use backplane mode
+- reset-gpios: Chip reset pin
+- interrupts: Should contain controller interrupt
+
+arcnet@2800 {
+   compatible = "smsc,com20020";
+
+   timeout-ns = <20500>;
+   bus-speed-hz = <1000>;
+   smsc,xtal-mhz = <20>;
+   smsc,backplane-enabled;
+
+   reset-gpios = < 21 GPIO_ACTIVE_LOW>;
+   interrupts = < 10 GPIO_ACTIVE_LOW>;
+};
-- 
2.14.4



[PATCH 5/6] arcnet: com20020: Fixup missing SLOWARB bit

2018-06-11 Thread Andrea Greco
From: Andrea Greco 

If com20020 clock is major of 40Mhz SLOWARB bit is requested.

Signed-off-by: Andrea Greco 
---
 drivers/net/arcnet/com20020.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index 8d979a66d8e9..1a0fd30fe8ae 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -133,6 +133,10 @@ int com20020_check(struct net_device *dev)
lp->setup = lp->clockm ? 0 : (lp->clockp << 1);
lp->setup2 = (lp->clockm << 4) | 8;
 
+   /* If clock is major of 40Mhz, SLOWARB bit must be set */
+   if (lp->clockm > 1)
+   lp->setup2 |= SLOWARB;
+
/* CHECK: should we do this for SOHARD cards ? */
/* Enable P1Mode for backplane mode */
lp->setup = lp->setup | P1MODE;
-- 
2.14.4



[PATCH 4/6] arcnet: com20020: bindings for smsc com20020

2018-06-11 Thread Andrea Greco
From: Andrea Greco 

Add devicetree bindings for smsc com20020

Signed-off-by: Andrea Greco 
---
 .../devicetree/bindings/net/smsc-com20020.txt   | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/smsc-com20020.txt

diff --git a/Documentation/devicetree/bindings/net/smsc-com20020.txt 
b/Documentation/devicetree/bindings/net/smsc-com20020.txt
new file mode 100644
index ..660a4a751f29
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/smsc-com20020.txt
@@ -0,0 +1,21 @@
+SMSC com20020 Arcnet network controller
+
+Required property:
+- timeout-ns: Arcnet bus timeout, Idle Time (328000 - 20500)
+- bus-speed-bps: Arcnet bus speed (1000 - 156250)
+- smsc,xtal-mhz: External oscillator frequency
+- smsc,backplane-enabled: Controller use backplane mode
+- reset-gpios: Chip reset pin
+- interrupts: Should contain controller interrupt
+
+arcnet@2800 {
+   compatible = "smsc,com20020";
+
+   timeout-ns = <20500>;
+   bus-speed-hz = <1000>;
+   smsc,xtal-mhz = <20>;
+   smsc,backplane-enabled;
+
+   reset-gpios = < 21 GPIO_ACTIVE_LOW>;
+   interrupts = < 10 GPIO_ACTIVE_LOW>;
+};
-- 
2.14.4



[PATCH 3/6] arcnet: com20020: Add com20020 io mapped version

2018-06-11 Thread Andrea Greco
From: Andrea Greco 

Add support for com20022I/com20020, io mapped.

Signed-off-by: Andrea Greco 
---
 drivers/net/arcnet/Kconfig   |   9 +-
 drivers/net/arcnet/Makefile  |   1 +
 drivers/net/arcnet/com20020-io.c | 315 +++
 drivers/net/arcnet/com20020.c|   5 +-
 4 files changed, 327 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/arcnet/com20020-io.c

diff --git a/drivers/net/arcnet/Kconfig b/drivers/net/arcnet/Kconfig
index afc5898e7a16..f72620dc63ec 100644
--- a/drivers/net/arcnet/Kconfig
+++ b/drivers/net/arcnet/Kconfig
@@ -3,7 +3,7 @@
 #
 
 menuconfig ARCNET
-   depends on NETDEVICES && (ISA || PCI || PCMCIA)
+   depends on NETDEVICES
tristate "ARCnet support"
---help---
  If you have a network card of this type, say Y and check out the
@@ -129,5 +129,12 @@ config ARCNET_COM20020_CS
 
  To compile this driver as a module, choose M here: the module will be
  called com20020_cs.  If unsure, say N.
+config ARCNET_COM20020_IO
+   tristate "Support for COM20020 (IO mapped)"
+   depends on ARCNET_COM20020
+   help
+ Say Y here if your custom board mount com20020 chipset or friends.
+ Supported Chipset: com20020, com20022, com20022I-3v3
+ If unsure, say N.
 
 endif # ARCNET
diff --git a/drivers/net/arcnet/Makefile b/drivers/net/arcnet/Makefile
index 53525e8ea130..18da4341f404 100644
--- a/drivers/net/arcnet/Makefile
+++ b/drivers/net/arcnet/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_ARCNET_COM20020) += com20020.o
 obj-$(CONFIG_ARCNET_COM20020_ISA) += com20020-isa.o
 obj-$(CONFIG_ARCNET_COM20020_PCI) += com20020-pci.o
 obj-$(CONFIG_ARCNET_COM20020_CS) += com20020_cs.o
+obj-$(CONFIG_ARCNET_COM20020_IO) += com20020-io.o
diff --git a/drivers/net/arcnet/com20020-io.c b/drivers/net/arcnet/com20020-io.c
new file mode 100644
index ..23c24d4de5a9
--- /dev/null
+++ b/drivers/net/arcnet/com20020-io.c
@@ -0,0 +1,315 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/* Linux ARCnet driver for com 20020.
+ *
+ * datasheet:
+ * http://ww1.microchip.com/downloads/en/DeviceDoc/200223vrevc.pdf
+ * http://ww1.microchip.com/downloads/en/DeviceDoc/20020.pdf
+ *
+ * Supported chip version:
+ * - com20020
+ * - com20022
+ * - com20022I-3v3
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "arcdevice.h"
+#include "com20020.h"
+
+/* Reset (5 * xTalFreq), minimal com20020 xTal is 10Mhz */
+#define RESET_DELAY 500
+
+static unsigned int io_arc_inb(int addr, int offset)
+{
+   return ioread8((void *__iomem) addr + offset);
+}
+
+static void io_arc_outb(int value, int addr, int offset)
+{
+   iowrite8(value, (void *__iomem)addr + offset);
+}
+
+static void io_arc_insb(int  addr, int offset, void *buffer, int count)
+{
+   ioread8_rep((void *__iomem) (addr + offset), buffer, count);
+}
+
+static void io_arc_outsb(int addr, int offset, void *buffer, int count)
+{
+   iowrite8_rep((void *__iomem) (addr + offset), buffer, count);
+}
+
+enum com20020_xtal_freq {
+   freq_10Mhz = 10,
+   freq_20Mhz = 20,
+};
+
+enum com20020_arcnet_speed {
+   arc_speed_10M_bps = 1000,
+   arc_speed_5M_bps = 500,
+   arc_speed_2M50_bps = 250,
+   arc_speed_1M25_bps = 125,
+   arc_speed_625K_bps = 625000,
+   arc_speed_312K5_bps = 312500,
+   arc_speed_156K25_bps = 156250,
+};
+
+enum com20020_timeout {
+   arc_timeout_328us =   328000,
+   arc_timeout_164us = 164000,
+   arc_timeout_82us =  82000,
+   arc_timeout_20u5s =  20500,
+};
+
+static int setup_clock(int *clockp, int *clockm, int xtal, int arcnet_speed)
+{
+   int pll_factor, req_clock_frq = 20;
+
+   switch (arcnet_speed) {
+   case arc_speed_10M_bps:
+   req_clock_frq = 80;
+   *clockp = 0;
+   break;
+   case arc_speed_5M_bps:
+   req_clock_frq = 40;
+   *clockp = 0;
+   break;
+   case arc_speed_2M50_bps:
+   *clockp = 0;
+   break;
+   case arc_speed_1M25_bps:
+   *clockp = 1;
+   break;
+   case arc_speed_625K_bps:
+   *clockp = 2;
+   break;
+   case arc_speed_312K5_bps:
+   *clockp = 3;
+   break;
+   case arc_speed_156K25_bps:
+   *clockp = 4;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   if (xtal != freq_10Mhz && xtal != freq_20Mhz)
+   return -EINVAL;
+
+   pll_factor = (unsigned int)req_clock_frq / xtal;
+
+   switch (pll_factor) {
+   case 1:
+   *clockm = 0;
+   break;
+   case 2:
+   *clockm = 1;
+   break;
+   case 4:
+   *clockm = 3;
+ 

[PATCH 3/6] arcnet: com20020: Add com20020 io mapped version

2018-06-11 Thread Andrea Greco
From: Andrea Greco 

Add support for com20022I/com20020, io mapped.

Signed-off-by: Andrea Greco 
---
 drivers/net/arcnet/Kconfig   |   9 +-
 drivers/net/arcnet/Makefile  |   1 +
 drivers/net/arcnet/com20020-io.c | 315 +++
 drivers/net/arcnet/com20020.c|   5 +-
 4 files changed, 327 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/arcnet/com20020-io.c

diff --git a/drivers/net/arcnet/Kconfig b/drivers/net/arcnet/Kconfig
index afc5898e7a16..f72620dc63ec 100644
--- a/drivers/net/arcnet/Kconfig
+++ b/drivers/net/arcnet/Kconfig
@@ -3,7 +3,7 @@
 #
 
 menuconfig ARCNET
-   depends on NETDEVICES && (ISA || PCI || PCMCIA)
+   depends on NETDEVICES
tristate "ARCnet support"
---help---
  If you have a network card of this type, say Y and check out the
@@ -129,5 +129,12 @@ config ARCNET_COM20020_CS
 
  To compile this driver as a module, choose M here: the module will be
  called com20020_cs.  If unsure, say N.
+config ARCNET_COM20020_IO
+   tristate "Support for COM20020 (IO mapped)"
+   depends on ARCNET_COM20020
+   help
+ Say Y here if your custom board mount com20020 chipset or friends.
+ Supported Chipset: com20020, com20022, com20022I-3v3
+ If unsure, say N.
 
 endif # ARCNET
diff --git a/drivers/net/arcnet/Makefile b/drivers/net/arcnet/Makefile
index 53525e8ea130..18da4341f404 100644
--- a/drivers/net/arcnet/Makefile
+++ b/drivers/net/arcnet/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_ARCNET_COM20020) += com20020.o
 obj-$(CONFIG_ARCNET_COM20020_ISA) += com20020-isa.o
 obj-$(CONFIG_ARCNET_COM20020_PCI) += com20020-pci.o
 obj-$(CONFIG_ARCNET_COM20020_CS) += com20020_cs.o
+obj-$(CONFIG_ARCNET_COM20020_IO) += com20020-io.o
diff --git a/drivers/net/arcnet/com20020-io.c b/drivers/net/arcnet/com20020-io.c
new file mode 100644
index ..23c24d4de5a9
--- /dev/null
+++ b/drivers/net/arcnet/com20020-io.c
@@ -0,0 +1,315 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/* Linux ARCnet driver for com 20020.
+ *
+ * datasheet:
+ * http://ww1.microchip.com/downloads/en/DeviceDoc/200223vrevc.pdf
+ * http://ww1.microchip.com/downloads/en/DeviceDoc/20020.pdf
+ *
+ * Supported chip version:
+ * - com20020
+ * - com20022
+ * - com20022I-3v3
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "arcdevice.h"
+#include "com20020.h"
+
+/* Reset (5 * xTalFreq), minimal com20020 xTal is 10Mhz */
+#define RESET_DELAY 500
+
+static unsigned int io_arc_inb(int addr, int offset)
+{
+   return ioread8((void *__iomem) addr + offset);
+}
+
+static void io_arc_outb(int value, int addr, int offset)
+{
+   iowrite8(value, (void *__iomem)addr + offset);
+}
+
+static void io_arc_insb(int  addr, int offset, void *buffer, int count)
+{
+   ioread8_rep((void *__iomem) (addr + offset), buffer, count);
+}
+
+static void io_arc_outsb(int addr, int offset, void *buffer, int count)
+{
+   iowrite8_rep((void *__iomem) (addr + offset), buffer, count);
+}
+
+enum com20020_xtal_freq {
+   freq_10Mhz = 10,
+   freq_20Mhz = 20,
+};
+
+enum com20020_arcnet_speed {
+   arc_speed_10M_bps = 1000,
+   arc_speed_5M_bps = 500,
+   arc_speed_2M50_bps = 250,
+   arc_speed_1M25_bps = 125,
+   arc_speed_625K_bps = 625000,
+   arc_speed_312K5_bps = 312500,
+   arc_speed_156K25_bps = 156250,
+};
+
+enum com20020_timeout {
+   arc_timeout_328us =   328000,
+   arc_timeout_164us = 164000,
+   arc_timeout_82us =  82000,
+   arc_timeout_20u5s =  20500,
+};
+
+static int setup_clock(int *clockp, int *clockm, int xtal, int arcnet_speed)
+{
+   int pll_factor, req_clock_frq = 20;
+
+   switch (arcnet_speed) {
+   case arc_speed_10M_bps:
+   req_clock_frq = 80;
+   *clockp = 0;
+   break;
+   case arc_speed_5M_bps:
+   req_clock_frq = 40;
+   *clockp = 0;
+   break;
+   case arc_speed_2M50_bps:
+   *clockp = 0;
+   break;
+   case arc_speed_1M25_bps:
+   *clockp = 1;
+   break;
+   case arc_speed_625K_bps:
+   *clockp = 2;
+   break;
+   case arc_speed_312K5_bps:
+   *clockp = 3;
+   break;
+   case arc_speed_156K25_bps:
+   *clockp = 4;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   if (xtal != freq_10Mhz && xtal != freq_20Mhz)
+   return -EINVAL;
+
+   pll_factor = (unsigned int)req_clock_frq / xtal;
+
+   switch (pll_factor) {
+   case 1:
+   *clockm = 0;
+   break;
+   case 2:
+   *clockm = 1;
+   break;
+   case 4:
+   *clockm = 3;
+ 

[PATCH 2/6] arcnet: com20020: Add IO cb for configure rw

2018-06-11 Thread Andrea Greco
From: Andrea Greco 

Add IO callback. No logic change are intended.
Now every driver implementation could specify IO callback.
Default IO callback is provided.

Signed-off-by: Andrea Greco 
---
 drivers/net/arcnet/arcdevice.h|   4 ++
 drivers/net/arcnet/com20020-isa.c |  21 --
 drivers/net/arcnet/com20020-pci.c |  11 +++-
 drivers/net/arcnet/com20020.c | 134 --
 drivers/net/arcnet/com20020.h |   9 ++-
 drivers/net/arcnet/com20020_cs.c  |  23 +--
 6 files changed, 134 insertions(+), 68 deletions(-)

diff --git a/drivers/net/arcnet/arcdevice.h b/drivers/net/arcnet/arcdevice.h
index d09b2b46ab63..cb7afadac5f6 100644
--- a/drivers/net/arcnet/arcdevice.h
+++ b/drivers/net/arcnet/arcdevice.h
@@ -324,6 +324,10 @@ struct arcnet_local {
void (*close)(struct net_device *dev);
void (*datatrigger) (struct net_device * dev, int enable);
void (*recontrigger) (struct net_device * dev, int enable);
+   unsigned int (*arc_inb)(int addr, int offset);
+   void (*arc_outb)(int value, int addr, int offset);
+   void (*arc_insb)(int addr, int offset, void *buff, int cnt);
+   void (*arc_outsb)(int addr, int offset, void *buff, int cnt);
 
void (*copy_to_card)(struct net_device *dev, int bufnum,
 int offset, void *buf, int count);
diff --git a/drivers/net/arcnet/com20020-isa.c 
b/drivers/net/arcnet/com20020-isa.c
index 38fa60ddaf2e..757586de5d08 100644
--- a/drivers/net/arcnet/com20020-isa.c
+++ b/drivers/net/arcnet/com20020-isa.c
@@ -67,7 +67,7 @@ static int __init com20020isa_probe(struct net_device *dev)
   ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
return -ENXIO;
}
-   if (arcnet_inb(ioaddr, COM20020_REG_R_STATUS) == 0xFF) {
+   if (lp->hw.arc_inb(ioaddr, COM20020_REG_R_STATUS) == 0xFF) {
arc_printk(D_NORMAL, dev, "IO address %x empty\n", ioaddr);
err = -ENODEV;
goto out;
@@ -83,20 +83,21 @@ static int __init com20020isa_probe(struct net_device *dev)
 * we tell it to start receiving.
 */
arc_printk(D_INIT_REASONS, dev, "intmask was %02Xh\n",
-  arcnet_inb(ioaddr, COM20020_REG_R_STATUS));
-   arcnet_outb(0, ioaddr, COM20020_REG_W_INTMASK);
+  lp->hw.arc_inb(ioaddr, COM20020_REG_R_STATUS));
+   lp->hw.arc_outb(0, ioaddr, COM20020_REG_W_INTMASK);
airqmask = probe_irq_on();
-   arcnet_outb(NORXflag, ioaddr, COM20020_REG_W_INTMASK);
+   lp->hw.arc_outb(NORXflag, ioaddr, COM20020_REG_W_INTMASK);
udelay(1);
-   arcnet_outb(0, ioaddr, COM20020_REG_W_INTMASK);
+   lp->hw.arc_outb(0, ioaddr, COM20020_REG_W_INTMASK);
dev->irq = probe_irq_off(airqmask);
 
if ((int)dev->irq <= 0) {
arc_printk(D_INIT_REASONS, dev, "Autoprobe IRQ failed 
first time\n");
airqmask = probe_irq_on();
-   arcnet_outb(NORXflag, ioaddr, COM20020_REG_W_INTMASK);
+   lp->hw.arc_outb(NORXflag, ioaddr,
+   COM20020_REG_W_INTMASK);
udelay(5);
-   arcnet_outb(0, ioaddr, COM20020_REG_W_INTMASK);
+   lp->hw.arc_outb(0, ioaddr, COM20020_REG_W_INTMASK);
dev->irq = probe_irq_off(airqmask);
if ((int)dev->irq <= 0) {
arc_printk(D_NORMAL, dev, "Autoprobe IRQ 
failed.\n");
@@ -156,6 +157,12 @@ static int __init com20020_init(void)
dev->netdev_ops = _netdev_ops;
 
lp = netdev_priv(dev);
+
+   lp->hw.arc_inb = com20020_def_arc_inb;
+   lp->hw.arc_outb = com20020_def_arc_outb;
+   lp->hw.arc_insb = com20020_def_arc_insb;
+   lp->hw.arc_outsb = com20020_def_arc_outsb;
+
lp->backplane = backplane;
lp->clockp = clockp & 7;
lp->clockm = clockm & 3;
diff --git a/drivers/net/arcnet/com20020-pci.c 
b/drivers/net/arcnet/com20020-pci.c
index eb7f76753c9c..dcf12e5cf889 100644
--- a/drivers/net/arcnet/com20020-pci.c
+++ b/drivers/net/arcnet/com20020-pci.c
@@ -181,12 +181,17 @@ static int com20020pci_probe(struct pci_dev *pdev,
goto out_port;
}
 
+   lp->hw.arc_inb = com20020_def_arc_inb;
+   lp->hw.arc_outb = com20020_def_arc_outb;
+   lp->hw.arc_insb = com20020_def_arc_insb;
+   lp->hw.arc_outsb = com20020_def_arc_outsb;
+
/* Dummy access after Reset
 * ARCNET controller needs
  

[PATCH 2/6] arcnet: com20020: Add IO cb for configure rw

2018-06-11 Thread Andrea Greco
From: Andrea Greco 

Add IO callback. No logic change are intended.
Now every driver implementation could specify IO callback.
Default IO callback is provided.

Signed-off-by: Andrea Greco 
---
 drivers/net/arcnet/arcdevice.h|   4 ++
 drivers/net/arcnet/com20020-isa.c |  21 --
 drivers/net/arcnet/com20020-pci.c |  11 +++-
 drivers/net/arcnet/com20020.c | 134 --
 drivers/net/arcnet/com20020.h |   9 ++-
 drivers/net/arcnet/com20020_cs.c  |  23 +--
 6 files changed, 134 insertions(+), 68 deletions(-)

diff --git a/drivers/net/arcnet/arcdevice.h b/drivers/net/arcnet/arcdevice.h
index d09b2b46ab63..cb7afadac5f6 100644
--- a/drivers/net/arcnet/arcdevice.h
+++ b/drivers/net/arcnet/arcdevice.h
@@ -324,6 +324,10 @@ struct arcnet_local {
void (*close)(struct net_device *dev);
void (*datatrigger) (struct net_device * dev, int enable);
void (*recontrigger) (struct net_device * dev, int enable);
+   unsigned int (*arc_inb)(int addr, int offset);
+   void (*arc_outb)(int value, int addr, int offset);
+   void (*arc_insb)(int addr, int offset, void *buff, int cnt);
+   void (*arc_outsb)(int addr, int offset, void *buff, int cnt);
 
void (*copy_to_card)(struct net_device *dev, int bufnum,
 int offset, void *buf, int count);
diff --git a/drivers/net/arcnet/com20020-isa.c 
b/drivers/net/arcnet/com20020-isa.c
index 38fa60ddaf2e..757586de5d08 100644
--- a/drivers/net/arcnet/com20020-isa.c
+++ b/drivers/net/arcnet/com20020-isa.c
@@ -67,7 +67,7 @@ static int __init com20020isa_probe(struct net_device *dev)
   ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
return -ENXIO;
}
-   if (arcnet_inb(ioaddr, COM20020_REG_R_STATUS) == 0xFF) {
+   if (lp->hw.arc_inb(ioaddr, COM20020_REG_R_STATUS) == 0xFF) {
arc_printk(D_NORMAL, dev, "IO address %x empty\n", ioaddr);
err = -ENODEV;
goto out;
@@ -83,20 +83,21 @@ static int __init com20020isa_probe(struct net_device *dev)
 * we tell it to start receiving.
 */
arc_printk(D_INIT_REASONS, dev, "intmask was %02Xh\n",
-  arcnet_inb(ioaddr, COM20020_REG_R_STATUS));
-   arcnet_outb(0, ioaddr, COM20020_REG_W_INTMASK);
+  lp->hw.arc_inb(ioaddr, COM20020_REG_R_STATUS));
+   lp->hw.arc_outb(0, ioaddr, COM20020_REG_W_INTMASK);
airqmask = probe_irq_on();
-   arcnet_outb(NORXflag, ioaddr, COM20020_REG_W_INTMASK);
+   lp->hw.arc_outb(NORXflag, ioaddr, COM20020_REG_W_INTMASK);
udelay(1);
-   arcnet_outb(0, ioaddr, COM20020_REG_W_INTMASK);
+   lp->hw.arc_outb(0, ioaddr, COM20020_REG_W_INTMASK);
dev->irq = probe_irq_off(airqmask);
 
if ((int)dev->irq <= 0) {
arc_printk(D_INIT_REASONS, dev, "Autoprobe IRQ failed 
first time\n");
airqmask = probe_irq_on();
-   arcnet_outb(NORXflag, ioaddr, COM20020_REG_W_INTMASK);
+   lp->hw.arc_outb(NORXflag, ioaddr,
+   COM20020_REG_W_INTMASK);
udelay(5);
-   arcnet_outb(0, ioaddr, COM20020_REG_W_INTMASK);
+   lp->hw.arc_outb(0, ioaddr, COM20020_REG_W_INTMASK);
dev->irq = probe_irq_off(airqmask);
if ((int)dev->irq <= 0) {
arc_printk(D_NORMAL, dev, "Autoprobe IRQ 
failed.\n");
@@ -156,6 +157,12 @@ static int __init com20020_init(void)
dev->netdev_ops = _netdev_ops;
 
lp = netdev_priv(dev);
+
+   lp->hw.arc_inb = com20020_def_arc_inb;
+   lp->hw.arc_outb = com20020_def_arc_outb;
+   lp->hw.arc_insb = com20020_def_arc_insb;
+   lp->hw.arc_outsb = com20020_def_arc_outsb;
+
lp->backplane = backplane;
lp->clockp = clockp & 7;
lp->clockm = clockm & 3;
diff --git a/drivers/net/arcnet/com20020-pci.c 
b/drivers/net/arcnet/com20020-pci.c
index eb7f76753c9c..dcf12e5cf889 100644
--- a/drivers/net/arcnet/com20020-pci.c
+++ b/drivers/net/arcnet/com20020-pci.c
@@ -181,12 +181,17 @@ static int com20020pci_probe(struct pci_dev *pdev,
goto out_port;
}
 
+   lp->hw.arc_inb = com20020_def_arc_inb;
+   lp->hw.arc_outb = com20020_def_arc_outb;
+   lp->hw.arc_insb = com20020_def_arc_insb;
+   lp->hw.arc_outsb = com20020_def_arc_outsb;
+
/* Dummy access after Reset
 * ARCNET controller needs
  

[PATCH 1/6] arcnet: leds: Removed leds dependecy

2018-06-11 Thread Andrea Greco
From: Andrea Greco 

Only PCI driver depends from leds class.

Signed-off-by: Andrea Greco 
---
 drivers/net/arcnet/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/arcnet/Kconfig b/drivers/net/arcnet/Kconfig
index 39bd16f3f86d..afc5898e7a16 100644
--- a/drivers/net/arcnet/Kconfig
+++ b/drivers/net/arcnet/Kconfig
@@ -103,7 +103,6 @@ config ARCNET_RIM_I
 
 config ARCNET_COM20020
tristate "ARCnet COM20020 chipset driver"
-   depends on LEDS_CLASS
help
  This is the driver for the new COM20020 chipset. It supports such
  things as promiscuous mode, so packet sniffing is possible, and
@@ -118,6 +117,7 @@ config ARCNET_COM20020_ISA
 
 config ARCNET_COM20020_PCI
tristate "Support for COM20020 on PCI"
+   depends on LEDS_CLASS
depends on ARCNET_COM20020 && PCI
 
 config ARCNET_COM20020_CS
-- 
2.14.4



[PATCH 1/6] arcnet: leds: Removed leds dependecy

2018-06-11 Thread Andrea Greco
From: Andrea Greco 

Only PCI driver depends from leds class.

Signed-off-by: Andrea Greco 
---
 drivers/net/arcnet/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/arcnet/Kconfig b/drivers/net/arcnet/Kconfig
index 39bd16f3f86d..afc5898e7a16 100644
--- a/drivers/net/arcnet/Kconfig
+++ b/drivers/net/arcnet/Kconfig
@@ -103,7 +103,6 @@ config ARCNET_RIM_I
 
 config ARCNET_COM20020
tristate "ARCnet COM20020 chipset driver"
-   depends on LEDS_CLASS
help
  This is the driver for the new COM20020 chipset. It supports such
  things as promiscuous mode, so packet sniffing is possible, and
@@ -118,6 +117,7 @@ config ARCNET_COM20020_ISA
 
 config ARCNET_COM20020_PCI
tristate "Support for COM20020 on PCI"
+   depends on LEDS_CLASS
depends on ARCNET_COM20020 && PCI
 
 config ARCNET_COM20020_CS
-- 
2.14.4



Re: [PATCH 2/4] arcnet: com20020: bindings for smsc com20020

2018-05-23 Thread Andrea Greco
On 05/23/2018 06:49 PM, Rob Herring wrote:
> One typo, otherwise:
>
> Reviewed-by: Rob Herring 

Yes typo, Fixed over my branch, sorry for that...
I expect a comment about bps, Bit per Second, used in `bus-speed-bps`
You will add it by your self in property-units.txt, or required my patch?
If your confirm that, ready for: Reviewed-by

Regards, Andrea


Re: [PATCH 2/4] arcnet: com20020: bindings for smsc com20020

2018-05-23 Thread Andrea Greco
On 05/23/2018 06:49 PM, Rob Herring wrote:
> One typo, otherwise:
>
> Reviewed-by: Rob Herring 

Yes typo, Fixed over my branch, sorry for that...
I expect a comment about bps, Bit per Second, used in `bus-speed-bps`
You will add it by your self in property-units.txt, or required my patch?
If your confirm that, ready for: Reviewed-by

Regards, Andrea


Re: [PATCH 1/4] arcnet: com20020: Add com20020 io mapped version

2018-05-22 Thread Andrea Greco

On 05/18/2018 07:51 PM, David Miller wrote:

From: Andrea Greco <andrea.greco.gapmil...@gmail.com>
Date: Fri, 18 May 2018 14:18:41 +0200


In com20020.c found this:
/* FIXME: do this some other way! */
if (!dev->dev_addr[0])
dev->dev_addr[0] = arcnet_inb(ioaddr, 8);

NODE-ID, must be univoque, for all arcnet network.
My previews idea was take random value but, this could create a
collision over network.

A possible solution is:
In case of collision com20020 set a bit in status register.
Then peak a new NODE-ID and repeat this while correct NODE-ID is found.

Other ideas is pass it via DTS.
But suppose have 2 same product in same network, same address same problem.
For this reason i prefer left standard driver behavior.

Other ideas for solve this ?


Is there no way to obtain a unique value from the device?

If having a unique ID to talk on the ARCNET is so critical, there must
be some way to properly allocation and use a unique ID.


Device can rise interrupt in case of Duplicate ID over the network.


I guess this must be a general problem with this driver already.
I think arcnet network and relative NODE-ID designed during project 
phase, and address is always fixed.


In fact:
Other version of this dirver: PCI, ISA friends.
Simple work as module, and Node-ID is param of modules.

My opinion is that:
Before run `ifconfig arc0 up`, user has to setup hardware address with 
`ip link set dev arc0 address D2`.


All this is like a IP network with static address. If your IP address is 
duplicated, is not IP problem.



You still need to address the issue of 'dev' being leaked on probe
error paths.
For solve this,i think all considered a random address could be a good 
solution.


Regards, Andrea


Re: [PATCH 1/4] arcnet: com20020: Add com20020 io mapped version

2018-05-22 Thread Andrea Greco

On 05/18/2018 07:51 PM, David Miller wrote:

From: Andrea Greco 
Date: Fri, 18 May 2018 14:18:41 +0200


In com20020.c found this:
/* FIXME: do this some other way! */
if (!dev->dev_addr[0])
dev->dev_addr[0] = arcnet_inb(ioaddr, 8);

NODE-ID, must be univoque, for all arcnet network.
My previews idea was take random value but, this could create a
collision over network.

A possible solution is:
In case of collision com20020 set a bit in status register.
Then peak a new NODE-ID and repeat this while correct NODE-ID is found.

Other ideas is pass it via DTS.
But suppose have 2 same product in same network, same address same problem.
For this reason i prefer left standard driver behavior.

Other ideas for solve this ?


Is there no way to obtain a unique value from the device?

If having a unique ID to talk on the ARCNET is so critical, there must
be some way to properly allocation and use a unique ID.


Device can rise interrupt in case of Duplicate ID over the network.


I guess this must be a general problem with this driver already.
I think arcnet network and relative NODE-ID designed during project 
phase, and address is always fixed.


In fact:
Other version of this dirver: PCI, ISA friends.
Simple work as module, and Node-ID is param of modules.

My opinion is that:
Before run `ifconfig arc0 up`, user has to setup hardware address with 
`ip link set dev arc0 address D2`.


All this is like a IP network with static address. If your IP address is 
duplicated, is not IP problem.



You still need to address the issue of 'dev' being leaked on probe
error paths.
For solve this,i think all considered a random address could be a good 
solution.


Regards, Andrea


Re: [PATCH 1/4] arcnet: com20020: Add com20020 io mapped version

2018-05-18 Thread Andrea Greco
On 05/17/2018 10:31 PM, David Miller wrote:
> From: Andrea Greco <andrea.greco.gapmil...@gmail.com>
> Date: Thu, 17 May 2018 15:05:29 +0200
>
>> + /* Will be set by userspace during if setup */
>> + dev->dev_addr[0] = 0;
>
> Hmmm... really?
>
> Also, every error path from this point forward will leak 'dev'.
>

In com20020.c found this:
/* FIXME: do this some other way! */
if (!dev->dev_addr[0])
dev->dev_addr[0] = arcnet_inb(ioaddr, 8);

NODE-ID, must be univoque, for all arcnet network.
My previews idea was take random value but, this could create a
collision over network.

A possible solution is:
In case of collision com20020 set a bit in status register.
Then peak a new NODE-ID and repeat this while correct NODE-ID is found.

Other ideas is pass it via DTS.
But suppose have 2 same product in same network, same address same problem.
For this reason i prefer left standard driver behavior.

Other ideas for solve this ?

Other question discussed with Tobin in RFC patch is:

At now a devm_ioremap is done by this driver.

Other version of this driver, PCI, PCMCIA, ISA do not remap memory.
Other implementation, use:inb outb for r/w operation.
I do a ugly #ifndef and redefine arcnet_inb in case is defined
CONFIG_ARCNET_COM20020_IO.

My proposal was:
Add relative callback arcnet_inb, arcnet_outb and friends hw struct in
arcdevice.h, then every driver set callback with required function.

Regards, Andrea


Re: [PATCH 1/4] arcnet: com20020: Add com20020 io mapped version

2018-05-18 Thread Andrea Greco
On 05/17/2018 10:31 PM, David Miller wrote:
> From: Andrea Greco 
> Date: Thu, 17 May 2018 15:05:29 +0200
>
>> + /* Will be set by userspace during if setup */
>> + dev->dev_addr[0] = 0;
>
> Hmmm... really?
>
> Also, every error path from this point forward will leak 'dev'.
>

In com20020.c found this:
/* FIXME: do this some other way! */
if (!dev->dev_addr[0])
dev->dev_addr[0] = arcnet_inb(ioaddr, 8);

NODE-ID, must be univoque, for all arcnet network.
My previews idea was take random value but, this could create a
collision over network.

A possible solution is:
In case of collision com20020 set a bit in status register.
Then peak a new NODE-ID and repeat this while correct NODE-ID is found.

Other ideas is pass it via DTS.
But suppose have 2 same product in same network, same address same problem.
For this reason i prefer left standard driver behavior.

Other ideas for solve this ?

Other question discussed with Tobin in RFC patch is:

At now a devm_ioremap is done by this driver.

Other version of this driver, PCI, PCMCIA, ISA do not remap memory.
Other implementation, use:inb outb for r/w operation.
I do a ugly #ifndef and redefine arcnet_inb in case is defined
CONFIG_ARCNET_COM20020_IO.

My proposal was:
Add relative callback arcnet_inb, arcnet_outb and friends hw struct in
arcdevice.h, then every driver set callback with required function.

Regards, Andrea


[PATCH 4/4] arcnet: com20020: Add ethtool support

2018-05-17 Thread Andrea Greco
From: Andrea Greco <a.gr...@4sigma.it>

Setup ethtols for export com20020 diag register

Signed-off-by: Andrea Greco <a.gr...@4sigma.it>
---
 drivers/net/arcnet/com20020-io.c  |  1 +
 drivers/net/arcnet/com20020-isa.c |  1 +
 drivers/net/arcnet/com20020.c | 24 
 drivers/net/arcnet/com20020.h |  1 +
 drivers/net/arcnet/com20020_cs.c  |  1 +
 include/uapi/linux/if_arcnet.h|  6 ++
 6 files changed, 34 insertions(+)

diff --git a/drivers/net/arcnet/com20020-io.c b/drivers/net/arcnet/com20020-io.c
index fce458242193..0d4355bcd873 100644
--- a/drivers/net/arcnet/com20020-io.c
+++ b/drivers/net/arcnet/com20020-io.c
@@ -183,6 +183,7 @@ static int com20020_probe(struct platform_device *pdev)
 
dev = alloc_arcdev(NULL);
dev->netdev_ops = _netdev_ops;
+   dev->ethtool_ops = _ethtool_ops;
lp = netdev_priv(dev);
 
lp->card_flags = ARC_CAN_10MBIT;
diff --git a/drivers/net/arcnet/com20020-isa.c 
b/drivers/net/arcnet/com20020-isa.c
index 38fa60ddaf2e..44ab6dcccb58 100644
--- a/drivers/net/arcnet/com20020-isa.c
+++ b/drivers/net/arcnet/com20020-isa.c
@@ -154,6 +154,7 @@ static int __init com20020_init(void)
dev->dev_addr[0] = node;
 
dev->netdev_ops = _netdev_ops;
+   dev->ethtool_ops = _ethtool_ops;
 
lp = netdev_priv(dev);
lp->backplane = backplane;
diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index f1de02f05305..02dd93a18e53 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -201,6 +201,29 @@ const struct net_device_ops com20020_netdev_ops = {
.ndo_set_rx_mode = com20020_set_mc_list,
 };
 
+static int com20020_ethtool_regs_len(struct net_device *netdev)
+{
+   return sizeof(struct com20020_ethtool_regs);
+}
+
+static void com20020_ethtool_regs_read(struct net_device *dev,
+  struct ethtool_regs *regs, void *p)
+{
+   struct arcnet_local *lp = netdev_priv(dev);
+   struct com20020_ethtool_regs *com_reg = p;
+
+   memset(p, 0, sizeof(struct com20020_ethtool_regs));
+
+   com_reg->status = lp->hw.status(dev) & 0xFF;
+   com_reg->diag_register = (lp->hw.status(dev) >> 8) & 0xFF;
+   com_reg->reconf_count = lp->num_recons;
+}
+
+const struct ethtool_ops com20020_ethtool_ops = {
+   .get_regs = com20020_ethtool_regs_read,
+   .get_regs_len  = com20020_ethtool_regs_len,
+};
+
 /* Set up the struct net_device associated with this card.  Called after
  * probing succeeds.
  */
@@ -402,6 +425,7 @@ static void com20020_set_mc_list(struct net_device *dev)
 EXPORT_SYMBOL(com20020_check);
 EXPORT_SYMBOL(com20020_found);
 EXPORT_SYMBOL(com20020_netdev_ops);
+EXPORT_SYMBOL(com20020_ethtool_ops);
 #endif
 
 MODULE_LICENSE("GPL");
diff --git a/drivers/net/arcnet/com20020.h b/drivers/net/arcnet/com20020.h
index 0bcc5d0a6903..a1024c8f8a1f 100644
--- a/drivers/net/arcnet/com20020.h
+++ b/drivers/net/arcnet/com20020.h
@@ -31,6 +31,7 @@
 int com20020_check(struct net_device *dev);
 int com20020_found(struct net_device *dev, int shared);
 extern const struct net_device_ops com20020_netdev_ops;
+extern const struct ethtool_ops com20020_ethtool_ops;
 
 /* The number of low I/O ports used by the card. */
 #define ARCNET_TOTAL_SIZE 8
diff --git a/drivers/net/arcnet/com20020_cs.c b/drivers/net/arcnet/com20020_cs.c
index cf607ffcf358..ae64f436fd54 100644
--- a/drivers/net/arcnet/com20020_cs.c
+++ b/drivers/net/arcnet/com20020_cs.c
@@ -233,6 +233,7 @@ static int com20020_config(struct pcmcia_device *link)
}
 
dev->irq = link->irq;
+   dev->ethtool_ops = _ethtool_ops;
 
ret = pcmcia_enable_device(link);
if (ret)
diff --git a/include/uapi/linux/if_arcnet.h b/include/uapi/linux/if_arcnet.h
index 683878036d76..790c0fa7386d 100644
--- a/include/uapi/linux/if_arcnet.h
+++ b/include/uapi/linux/if_arcnet.h
@@ -127,4 +127,10 @@ struct archdr {
} soft;
 };
 
+struct com20020_ethtool_regs {
+   __u8 status;
+   __u8 diag_register;
+   __u32 reconf_count;
+};
+
 #endif /* _LINUX_IF_ARCNET_H */
-- 
2.14.3



[PATCH 4/4] arcnet: com20020: Add ethtool support

2018-05-17 Thread Andrea Greco
From: Andrea Greco 

Setup ethtols for export com20020 diag register

Signed-off-by: Andrea Greco 
---
 drivers/net/arcnet/com20020-io.c  |  1 +
 drivers/net/arcnet/com20020-isa.c |  1 +
 drivers/net/arcnet/com20020.c | 24 
 drivers/net/arcnet/com20020.h |  1 +
 drivers/net/arcnet/com20020_cs.c  |  1 +
 include/uapi/linux/if_arcnet.h|  6 ++
 6 files changed, 34 insertions(+)

diff --git a/drivers/net/arcnet/com20020-io.c b/drivers/net/arcnet/com20020-io.c
index fce458242193..0d4355bcd873 100644
--- a/drivers/net/arcnet/com20020-io.c
+++ b/drivers/net/arcnet/com20020-io.c
@@ -183,6 +183,7 @@ static int com20020_probe(struct platform_device *pdev)
 
dev = alloc_arcdev(NULL);
dev->netdev_ops = _netdev_ops;
+   dev->ethtool_ops = _ethtool_ops;
lp = netdev_priv(dev);
 
lp->card_flags = ARC_CAN_10MBIT;
diff --git a/drivers/net/arcnet/com20020-isa.c 
b/drivers/net/arcnet/com20020-isa.c
index 38fa60ddaf2e..44ab6dcccb58 100644
--- a/drivers/net/arcnet/com20020-isa.c
+++ b/drivers/net/arcnet/com20020-isa.c
@@ -154,6 +154,7 @@ static int __init com20020_init(void)
dev->dev_addr[0] = node;
 
dev->netdev_ops = _netdev_ops;
+   dev->ethtool_ops = _ethtool_ops;
 
lp = netdev_priv(dev);
lp->backplane = backplane;
diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index f1de02f05305..02dd93a18e53 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -201,6 +201,29 @@ const struct net_device_ops com20020_netdev_ops = {
.ndo_set_rx_mode = com20020_set_mc_list,
 };
 
+static int com20020_ethtool_regs_len(struct net_device *netdev)
+{
+   return sizeof(struct com20020_ethtool_regs);
+}
+
+static void com20020_ethtool_regs_read(struct net_device *dev,
+  struct ethtool_regs *regs, void *p)
+{
+   struct arcnet_local *lp = netdev_priv(dev);
+   struct com20020_ethtool_regs *com_reg = p;
+
+   memset(p, 0, sizeof(struct com20020_ethtool_regs));
+
+   com_reg->status = lp->hw.status(dev) & 0xFF;
+   com_reg->diag_register = (lp->hw.status(dev) >> 8) & 0xFF;
+   com_reg->reconf_count = lp->num_recons;
+}
+
+const struct ethtool_ops com20020_ethtool_ops = {
+   .get_regs = com20020_ethtool_regs_read,
+   .get_regs_len  = com20020_ethtool_regs_len,
+};
+
 /* Set up the struct net_device associated with this card.  Called after
  * probing succeeds.
  */
@@ -402,6 +425,7 @@ static void com20020_set_mc_list(struct net_device *dev)
 EXPORT_SYMBOL(com20020_check);
 EXPORT_SYMBOL(com20020_found);
 EXPORT_SYMBOL(com20020_netdev_ops);
+EXPORT_SYMBOL(com20020_ethtool_ops);
 #endif
 
 MODULE_LICENSE("GPL");
diff --git a/drivers/net/arcnet/com20020.h b/drivers/net/arcnet/com20020.h
index 0bcc5d0a6903..a1024c8f8a1f 100644
--- a/drivers/net/arcnet/com20020.h
+++ b/drivers/net/arcnet/com20020.h
@@ -31,6 +31,7 @@
 int com20020_check(struct net_device *dev);
 int com20020_found(struct net_device *dev, int shared);
 extern const struct net_device_ops com20020_netdev_ops;
+extern const struct ethtool_ops com20020_ethtool_ops;
 
 /* The number of low I/O ports used by the card. */
 #define ARCNET_TOTAL_SIZE 8
diff --git a/drivers/net/arcnet/com20020_cs.c b/drivers/net/arcnet/com20020_cs.c
index cf607ffcf358..ae64f436fd54 100644
--- a/drivers/net/arcnet/com20020_cs.c
+++ b/drivers/net/arcnet/com20020_cs.c
@@ -233,6 +233,7 @@ static int com20020_config(struct pcmcia_device *link)
}
 
dev->irq = link->irq;
+   dev->ethtool_ops = _ethtool_ops;
 
ret = pcmcia_enable_device(link);
if (ret)
diff --git a/include/uapi/linux/if_arcnet.h b/include/uapi/linux/if_arcnet.h
index 683878036d76..790c0fa7386d 100644
--- a/include/uapi/linux/if_arcnet.h
+++ b/include/uapi/linux/if_arcnet.h
@@ -127,4 +127,10 @@ struct archdr {
} soft;
 };
 
+struct com20020_ethtool_regs {
+   __u8 status;
+   __u8 diag_register;
+   __u32 reconf_count;
+};
+
 #endif /* _LINUX_IF_ARCNET_H */
-- 
2.14.3



[PATCH 3/4] arcnet: com20020: Fixup missing SLOWARB bit

2018-05-17 Thread Andrea Greco
From: Andrea Greco <a.gr...@4sigma.it>

If com20020 clock is major of 40Mhz SLOWARB bit is requested.

Signed-off-by: Andrea Greco <a.gr...@4sigma.it>
---
 drivers/net/arcnet/com20020.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index 2fd00d2dd6bf..f1de02f05305 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -102,6 +102,10 @@ int com20020_check(struct net_device *dev)
lp->setup = lp->clockm ? 0 : (lp->clockp << 1);
lp->setup2 = (lp->clockm << 4) | 8;
 
+   /* If clock is major of 40Mhz, SLOWARB bit must be set */
+   if (lp->clockm > 1)
+   lp->setup2 |= SLOWARB;
+
/* CHECK: should we do this for SOHARD cards ? */
/* Enable P1Mode for backplane mode */
lp->setup = lp->setup | P1MODE;
-- 
2.14.3



[PATCH 3/4] arcnet: com20020: Fixup missing SLOWARB bit

2018-05-17 Thread Andrea Greco
From: Andrea Greco 

If com20020 clock is major of 40Mhz SLOWARB bit is requested.

Signed-off-by: Andrea Greco 
---
 drivers/net/arcnet/com20020.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index 2fd00d2dd6bf..f1de02f05305 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -102,6 +102,10 @@ int com20020_check(struct net_device *dev)
lp->setup = lp->clockm ? 0 : (lp->clockp << 1);
lp->setup2 = (lp->clockm << 4) | 8;
 
+   /* If clock is major of 40Mhz, SLOWARB bit must be set */
+   if (lp->clockm > 1)
+   lp->setup2 |= SLOWARB;
+
/* CHECK: should we do this for SOHARD cards ? */
/* Enable P1Mode for backplane mode */
lp->setup = lp->setup | P1MODE;
-- 
2.14.3



[PATCH 2/4] arcnet: com20020: bindings for smsc com20020

2018-05-17 Thread Andrea Greco
From: Andrea Greco <a.gr...@4sigma.it>

Add devicetree bindings for smsc com20020

Signed-off-by: Andrea Greco <a.gr...@4sigma.it>
---
 .../devicetree/bindings/net/smsc-com20020.txt   | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/smsc-com20020.txt

diff --git a/Documentation/devicetree/bindings/net/smsc-com20020.txt 
b/Documentation/devicetree/bindings/net/smsc-com20020.txt
new file mode 100644
index ..92360b054873
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/smsc-com20020.txt
@@ -0,0 +1,21 @@
+SMSC com20020 Arcnet network controller
+
+Required propelty:
+- timeout-ns: Arcnet bus timeout, Idle Time (328000 - 20500)
+- bus-speed-bps: Arcnet bus speed (1000 - 156250)
+- smsc,xtal-mhz: External oscillator frequency
+- smsc,backplane-enabled: Controller use backplane mode
+- reset-gpios: Chip reset pin
+- interrupts: Should contain controller interrupt
+
+arcnet@2800 {
+compatible = "smsc,com20020";
+
+   timeout-ns = <20500>;
+   bus-speed-bps = <1000>;
+   smsc,xtal-mhz = <20>;
+   smsc,backplane-enabled;
+
+   reset-gpios = < 21 GPIO_ACTIVE_LOW>;
+   interrupts = < 10 GPIO_ACTIVE_LOW>;
+};
-- 
2.14.3



[PATCH 2/4] arcnet: com20020: bindings for smsc com20020

2018-05-17 Thread Andrea Greco
From: Andrea Greco 

Add devicetree bindings for smsc com20020

Signed-off-by: Andrea Greco 
---
 .../devicetree/bindings/net/smsc-com20020.txt   | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/smsc-com20020.txt

diff --git a/Documentation/devicetree/bindings/net/smsc-com20020.txt 
b/Documentation/devicetree/bindings/net/smsc-com20020.txt
new file mode 100644
index ..92360b054873
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/smsc-com20020.txt
@@ -0,0 +1,21 @@
+SMSC com20020 Arcnet network controller
+
+Required propelty:
+- timeout-ns: Arcnet bus timeout, Idle Time (328000 - 20500)
+- bus-speed-bps: Arcnet bus speed (1000 - 156250)
+- smsc,xtal-mhz: External oscillator frequency
+- smsc,backplane-enabled: Controller use backplane mode
+- reset-gpios: Chip reset pin
+- interrupts: Should contain controller interrupt
+
+arcnet@2800 {
+compatible = "smsc,com20020";
+
+   timeout-ns = <20500>;
+   bus-speed-bps = <1000>;
+   smsc,xtal-mhz = <20>;
+   smsc,backplane-enabled;
+
+   reset-gpios = < 21 GPIO_ACTIVE_LOW>;
+   interrupts = < 10 GPIO_ACTIVE_LOW>;
+};
-- 
2.14.3



[PATCH 1/4] arcnet: com20020: Add com20020 io mapped version

2018-05-17 Thread Andrea Greco
From: Andrea Greco <a.gr...@4sigma.it>

Add support for com20022I/com20020, io mapped.

Signed-off-by: Andrea Greco <a.gr...@4sigma.it>
---
 drivers/net/arcnet/Kconfig   |   9 +-
 drivers/net/arcnet/Makefile  |   1 +
 drivers/net/arcnet/arcdevice.h   |  14 ++
 drivers/net/arcnet/com20020-io.c | 287 +++
 drivers/net/arcnet/com20020.c|   5 +-
 5 files changed, 313 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/arcnet/com20020-io.c

diff --git a/drivers/net/arcnet/Kconfig b/drivers/net/arcnet/Kconfig
index 39bd16f3f86d..85e60ed29fa8 100644
--- a/drivers/net/arcnet/Kconfig
+++ b/drivers/net/arcnet/Kconfig
@@ -3,7 +3,7 @@
 #
 
 menuconfig ARCNET
-   depends on NETDEVICES && (ISA || PCI || PCMCIA)
+   depends on NETDEVICES
tristate "ARCnet support"
---help---
  If you have a network card of this type, say Y and check out the
@@ -129,5 +129,12 @@ config ARCNET_COM20020_CS
 
  To compile this driver as a module, choose M here: the module will be
  called com20020_cs.  If unsure, say N.
+config ARCNET_COM20020_IO
+   bool "Support for COM20020 (IO mapped)"
+   depends on ARCNET_COM20020 && !(ARCNET_COM20020_PCI || 
ARCNET_COM20020_ISA || ARCNET_COM20020_CS)
+   help
+ Say Y here if your custom board mount com20020 chipset or friends.
+ Supported Chipset: com20020, com20022, com20022I-3v3
+ If unsure, say N.
 
 endif # ARCNET
diff --git a/drivers/net/arcnet/Makefile b/drivers/net/arcnet/Makefile
index 53525e8ea130..18da4341f404 100644
--- a/drivers/net/arcnet/Makefile
+++ b/drivers/net/arcnet/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_ARCNET_COM20020) += com20020.o
 obj-$(CONFIG_ARCNET_COM20020_ISA) += com20020-isa.o
 obj-$(CONFIG_ARCNET_COM20020_PCI) += com20020-pci.o
 obj-$(CONFIG_ARCNET_COM20020_CS) += com20020_cs.o
+obj-$(CONFIG_ARCNET_COM20020_IO) += com20020-io.o
diff --git a/drivers/net/arcnet/arcdevice.h b/drivers/net/arcnet/arcdevice.h
index d09b2b46ab63..86c36d9b666b 100644
--- a/drivers/net/arcnet/arcdevice.h
+++ b/drivers/net/arcnet/arcdevice.h
@@ -371,6 +371,19 @@ void arcnet_timeout(struct net_device *dev);
 #define BUS_ALIGN  1
 #endif
 
+#ifdef CONFIG_ARCNET_COM20020_IO
+#define arcnet_inb(addr, offset)   \
+   ioread8((void __iomem *)(addr) + BUS_ALIGN * offset)
+
+#define arcnet_outb(value, addr, offset)   \
+   iowrite8(value, (void __iomem *)addr + BUS_ALIGN * offset)
+
+#define arcnet_insb(addr, offset, buffer, count)   \
+   ioread8_rep((void __iomem *)addr + BUS_ALIGN * offset, buffer, count)
+
+#define arcnet_outsb(addr, offset, buffer, count)  \
+   iowrite8_rep((void __iomem *)addr + BUS_ALIGN * offset, buffer, count)
+#else
 /* addr and offset allow register like names to define the actual IO  address.
  * A configuration option multiplies the offset for alignment.
  */
@@ -388,6 +401,7 @@ void arcnet_timeout(struct net_device *dev);
readb((addr) + (offset))
 #define arcnet_writeb(value, addr, offset) \
writeb(value, (addr) + (offset))
+#endif
 
 #endif /* __KERNEL__ */
 #endif /* _LINUX_ARCDEVICE_H */
diff --git a/drivers/net/arcnet/com20020-io.c b/drivers/net/arcnet/com20020-io.c
new file mode 100644
index ..fce458242193
--- /dev/null
+++ b/drivers/net/arcnet/com20020-io.c
@@ -0,0 +1,287 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/* Linux ARCnet driver for com 20020.
+ *
+ * datasheet:
+ * http://ww1.microchip.com/downloads/en/DeviceDoc/200223vrevc.pdf
+ * http://ww1.microchip.com/downloads/en/DeviceDoc/20020.pdf
+ *
+ * Supported chip version:
+ * - com20020
+ * - com20022
+ * - com20022I-3v3
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "arcdevice.h"
+#include "com20020.h"
+
+/* Reset (5 * xTalFreq), minimal com20020 xTal is 10Mhz */
+#define RESET_DELAY 500
+
+enum com20020_xtal_freq {
+   freq_10Mhz = 10,
+   freq_20Mhz = 20,
+};
+
+enum com20020_arcnet_speed {
+   arc_speed_10M_bps = 1000,
+   arc_speed_5M_bps = 500,
+   arc_speed_2M50_bps = 250,
+   arc_speed_1M25_bps = 125,
+   arc_speed_625K_bps = 625000,
+   arc_speed_312K5_bps = 312500,
+   arc_speed_156K25_bps = 156250,
+};
+
+enum com20020_timeout {
+   arc_timeout_328us =   328000,
+   arc_timeout_164us = 164000,
+   arc_timeout_82us =  82000,
+   arc_timeout_20u5s =  20500,
+};
+
+static int setup_clock(int *clockp, int *clockm, int xtal, int arcnet_speed)
+{
+   int pll_factor, req_clock_frq = 20;
+
+   switch (arcnet_speed) {
+   case arc_speed_10M_bps:
+   req_clock_frq = 

[PATCH 1/4] arcnet: com20020: Add com20020 io mapped version

2018-05-17 Thread Andrea Greco
From: Andrea Greco 

Add support for com20022I/com20020, io mapped.

Signed-off-by: Andrea Greco 
---
 drivers/net/arcnet/Kconfig   |   9 +-
 drivers/net/arcnet/Makefile  |   1 +
 drivers/net/arcnet/arcdevice.h   |  14 ++
 drivers/net/arcnet/com20020-io.c | 287 +++
 drivers/net/arcnet/com20020.c|   5 +-
 5 files changed, 313 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/arcnet/com20020-io.c

diff --git a/drivers/net/arcnet/Kconfig b/drivers/net/arcnet/Kconfig
index 39bd16f3f86d..85e60ed29fa8 100644
--- a/drivers/net/arcnet/Kconfig
+++ b/drivers/net/arcnet/Kconfig
@@ -3,7 +3,7 @@
 #
 
 menuconfig ARCNET
-   depends on NETDEVICES && (ISA || PCI || PCMCIA)
+   depends on NETDEVICES
tristate "ARCnet support"
---help---
  If you have a network card of this type, say Y and check out the
@@ -129,5 +129,12 @@ config ARCNET_COM20020_CS
 
  To compile this driver as a module, choose M here: the module will be
  called com20020_cs.  If unsure, say N.
+config ARCNET_COM20020_IO
+   bool "Support for COM20020 (IO mapped)"
+   depends on ARCNET_COM20020 && !(ARCNET_COM20020_PCI || 
ARCNET_COM20020_ISA || ARCNET_COM20020_CS)
+   help
+ Say Y here if your custom board mount com20020 chipset or friends.
+ Supported Chipset: com20020, com20022, com20022I-3v3
+ If unsure, say N.
 
 endif # ARCNET
diff --git a/drivers/net/arcnet/Makefile b/drivers/net/arcnet/Makefile
index 53525e8ea130..18da4341f404 100644
--- a/drivers/net/arcnet/Makefile
+++ b/drivers/net/arcnet/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_ARCNET_COM20020) += com20020.o
 obj-$(CONFIG_ARCNET_COM20020_ISA) += com20020-isa.o
 obj-$(CONFIG_ARCNET_COM20020_PCI) += com20020-pci.o
 obj-$(CONFIG_ARCNET_COM20020_CS) += com20020_cs.o
+obj-$(CONFIG_ARCNET_COM20020_IO) += com20020-io.o
diff --git a/drivers/net/arcnet/arcdevice.h b/drivers/net/arcnet/arcdevice.h
index d09b2b46ab63..86c36d9b666b 100644
--- a/drivers/net/arcnet/arcdevice.h
+++ b/drivers/net/arcnet/arcdevice.h
@@ -371,6 +371,19 @@ void arcnet_timeout(struct net_device *dev);
 #define BUS_ALIGN  1
 #endif
 
+#ifdef CONFIG_ARCNET_COM20020_IO
+#define arcnet_inb(addr, offset)   \
+   ioread8((void __iomem *)(addr) + BUS_ALIGN * offset)
+
+#define arcnet_outb(value, addr, offset)   \
+   iowrite8(value, (void __iomem *)addr + BUS_ALIGN * offset)
+
+#define arcnet_insb(addr, offset, buffer, count)   \
+   ioread8_rep((void __iomem *)addr + BUS_ALIGN * offset, buffer, count)
+
+#define arcnet_outsb(addr, offset, buffer, count)  \
+   iowrite8_rep((void __iomem *)addr + BUS_ALIGN * offset, buffer, count)
+#else
 /* addr and offset allow register like names to define the actual IO  address.
  * A configuration option multiplies the offset for alignment.
  */
@@ -388,6 +401,7 @@ void arcnet_timeout(struct net_device *dev);
readb((addr) + (offset))
 #define arcnet_writeb(value, addr, offset) \
writeb(value, (addr) + (offset))
+#endif
 
 #endif /* __KERNEL__ */
 #endif /* _LINUX_ARCDEVICE_H */
diff --git a/drivers/net/arcnet/com20020-io.c b/drivers/net/arcnet/com20020-io.c
new file mode 100644
index ..fce458242193
--- /dev/null
+++ b/drivers/net/arcnet/com20020-io.c
@@ -0,0 +1,287 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/* Linux ARCnet driver for com 20020.
+ *
+ * datasheet:
+ * http://ww1.microchip.com/downloads/en/DeviceDoc/200223vrevc.pdf
+ * http://ww1.microchip.com/downloads/en/DeviceDoc/20020.pdf
+ *
+ * Supported chip version:
+ * - com20020
+ * - com20022
+ * - com20022I-3v3
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "arcdevice.h"
+#include "com20020.h"
+
+/* Reset (5 * xTalFreq), minimal com20020 xTal is 10Mhz */
+#define RESET_DELAY 500
+
+enum com20020_xtal_freq {
+   freq_10Mhz = 10,
+   freq_20Mhz = 20,
+};
+
+enum com20020_arcnet_speed {
+   arc_speed_10M_bps = 1000,
+   arc_speed_5M_bps = 500,
+   arc_speed_2M50_bps = 250,
+   arc_speed_1M25_bps = 125,
+   arc_speed_625K_bps = 625000,
+   arc_speed_312K5_bps = 312500,
+   arc_speed_156K25_bps = 156250,
+};
+
+enum com20020_timeout {
+   arc_timeout_328us =   328000,
+   arc_timeout_164us = 164000,
+   arc_timeout_82us =  82000,
+   arc_timeout_20u5s =  20500,
+};
+
+static int setup_clock(int *clockp, int *clockm, int xtal, int arcnet_speed)
+{
+   int pll_factor, req_clock_frq = 20;
+
+   switch (arcnet_speed) {
+   case arc_speed_10M_bps:
+   req_clock_frq = 80;
+   *clockp = 0;
+   break;
+   

Re: [RFC PATCH 1/3] arcnet: com20020: Add memory map of com20020

2018-05-11 Thread Andrea Greco
On 05/08/2018 06:16 PM, Rob Herring wrote:
> On Sat, May 05, 2018 at 11:34:45PM +0200, Andrea Greco wrote:
>> From: Andrea Greco <a.gr...@4sigma.it>
>>
>> Add support for com20022I/com20020, memory mapped chip version.
>> Support bus: Intel 80xx and Motorola 68xx.
>> Bus size: Only 8 bit bus size is supported.
>> Added related device tree bindings
>>
>> Signed-off-by: Andrea Greco <a.gr...@4sigma.it>
>> ---
>>   .../devicetree/bindings/net/smsc-com20020.txt  |  23 +++
>
> Please split bindings to separate patch.

Ok
>
>>   drivers/net/arcnet/Kconfig |  12 +-
>>   drivers/net/arcnet/Makefile|   1 +
>>   drivers/net/arcnet/arcdevice.h |  27 ++-
>>   drivers/net/arcnet/com20020-membus.c   | 191 
>> +
>>   drivers/net/arcnet/com20020.c  |   9 +-
>>   6 files changed, 253 insertions(+), 10 deletions(-)
>>   create mode 100644 Documentation/devicetree/bindings/net/smsc-com20020.txt
>>   create mode 100644 drivers/net/arcnet/com20020-membus.c
>>
>> diff --git a/Documentation/devicetree/bindings/net/smsc-com20020.txt 
>> b/Documentation/devicetree/bindings/net/smsc-com20020.txt
>> new file mode 100644
>> index ..39c5b19c55af
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/net/smsc-com20020.txt
>> @@ -0,0 +1,23 @@
>> +SMSC com20020, com20022I
>
> What does this device do?
>

Changed in:
SMSC com20020 Arcnet network controller

>> +
>> +timeout: Arcnet timeout, checkout datashet
>> +clockp: Clock Prescaler, checkout datashet
>
> s/datashet/datasheet/
>
>> +clockm: Clock multiplier, checkout datasheet
>
> Would these 3 properties be common for arcnet devices? If not, then they
> should have a vendor prefix.
>

Timeout is arcnet propelty:
Other is smsc params, then become:
- timeout: Arcnet timeout
- smsc-clockp: Clock Prescaler
- smsc-clockm: Clock multiplier
- smsc-backplane: Controller use backplane mode inside of transceiver

I forget backplane propelty, but is required

>> +
>> +phy-reset-gpios: Chip reset ppin
>
> Use 'reset-gpios' as that is standard.
>
>> +phy-irq-gpios: Chip irq pin
>
> Use 'interrupts'. Interrupt capable gpio controllers are also interrupt
> controllers.
>

Ok, change to standard

>> +
>> +com20020_A@0 {
>
> Node names should be generic based on the class of device. I don't think
> we have one defined, but how about 'arcnet'.
>
> Unit addresses must have a corresponding reg property. How is this
> device accessed?
>

Then: arcnet@2800

>> +compatible = "smsc,com20020";
>
> Not documented.
>
I miss something? Where add this doc?
Is not this file?
Documentation/devicetree/bindings/net/smsc-com20020.txt

>> +
>> + timeout = <0x3>;
>> + backplane = <0x0>;
>> +
>> + clockp = <0x0>;
>> + clockm = <0x3>;
>> +
>> + phy-reset-gpios = < 21 GPIO_ACTIVE_LOW>;
>> + phy-irq-gpios = < 10 GPIO_ACTIVE_LOW>;
>> +
>> + status = "okay";
>
> Don't should status in examples.
>
>> +};
Ok

Final result of new Patch, for bindings:

SMSC com20020 Arcnet network controller

Required propelty:
- timeout: Arcnet timeout
- smsc-clockp: Clock Prescaler
- smsc-clockm: Clock multiplier
- smsc-backplane: Controller use backplane mode inside of transceiver

- reset-gpios: Chip reset pin
- interrupts: Should contain controller interrupt

arcnet@2800 {
 compatible = "smsc,com20020";

timeout = <0x3>;
smsc-backplane = <0x0>;
smsc-clockp = <0x0>;
smsc-clockm = <0x3>;

reset-gpios = < 21 GPIO_ACTIVE_LOW>;
interrupts = < 10 GPIO_ACTIVE_LOW>;
};

Andrea


Re: [RFC PATCH 1/3] arcnet: com20020: Add memory map of com20020

2018-05-11 Thread Andrea Greco
On 05/08/2018 06:16 PM, Rob Herring wrote:
> On Sat, May 05, 2018 at 11:34:45PM +0200, Andrea Greco wrote:
>> From: Andrea Greco 
>>
>> Add support for com20022I/com20020, memory mapped chip version.
>> Support bus: Intel 80xx and Motorola 68xx.
>> Bus size: Only 8 bit bus size is supported.
>> Added related device tree bindings
>>
>> Signed-off-by: Andrea Greco 
>> ---
>>   .../devicetree/bindings/net/smsc-com20020.txt  |  23 +++
>
> Please split bindings to separate patch.

Ok
>
>>   drivers/net/arcnet/Kconfig |  12 +-
>>   drivers/net/arcnet/Makefile|   1 +
>>   drivers/net/arcnet/arcdevice.h |  27 ++-
>>   drivers/net/arcnet/com20020-membus.c   | 191 
>> +
>>   drivers/net/arcnet/com20020.c  |   9 +-
>>   6 files changed, 253 insertions(+), 10 deletions(-)
>>   create mode 100644 Documentation/devicetree/bindings/net/smsc-com20020.txt
>>   create mode 100644 drivers/net/arcnet/com20020-membus.c
>>
>> diff --git a/Documentation/devicetree/bindings/net/smsc-com20020.txt 
>> b/Documentation/devicetree/bindings/net/smsc-com20020.txt
>> new file mode 100644
>> index ..39c5b19c55af
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/net/smsc-com20020.txt
>> @@ -0,0 +1,23 @@
>> +SMSC com20020, com20022I
>
> What does this device do?
>

Changed in:
SMSC com20020 Arcnet network controller

>> +
>> +timeout: Arcnet timeout, checkout datashet
>> +clockp: Clock Prescaler, checkout datashet
>
> s/datashet/datasheet/
>
>> +clockm: Clock multiplier, checkout datasheet
>
> Would these 3 properties be common for arcnet devices? If not, then they
> should have a vendor prefix.
>

Timeout is arcnet propelty:
Other is smsc params, then become:
- timeout: Arcnet timeout
- smsc-clockp: Clock Prescaler
- smsc-clockm: Clock multiplier
- smsc-backplane: Controller use backplane mode inside of transceiver

I forget backplane propelty, but is required

>> +
>> +phy-reset-gpios: Chip reset ppin
>
> Use 'reset-gpios' as that is standard.
>
>> +phy-irq-gpios: Chip irq pin
>
> Use 'interrupts'. Interrupt capable gpio controllers are also interrupt
> controllers.
>

Ok, change to standard

>> +
>> +com20020_A@0 {
>
> Node names should be generic based on the class of device. I don't think
> we have one defined, but how about 'arcnet'.
>
> Unit addresses must have a corresponding reg property. How is this
> device accessed?
>

Then: arcnet@2800

>> +compatible = "smsc,com20020";
>
> Not documented.
>
I miss something? Where add this doc?
Is not this file?
Documentation/devicetree/bindings/net/smsc-com20020.txt

>> +
>> + timeout = <0x3>;
>> + backplane = <0x0>;
>> +
>> + clockp = <0x0>;
>> + clockm = <0x3>;
>> +
>> + phy-reset-gpios = < 21 GPIO_ACTIVE_LOW>;
>> + phy-irq-gpios = < 10 GPIO_ACTIVE_LOW>;
>> +
>> + status = "okay";
>
> Don't should status in examples.
>
>> +};
Ok

Final result of new Patch, for bindings:

SMSC com20020 Arcnet network controller

Required propelty:
- timeout: Arcnet timeout
- smsc-clockp: Clock Prescaler
- smsc-clockm: Clock multiplier
- smsc-backplane: Controller use backplane mode inside of transceiver

- reset-gpios: Chip reset pin
- interrupts: Should contain controller interrupt

arcnet@2800 {
 compatible = "smsc,com20020";

timeout = <0x3>;
smsc-backplane = <0x0>;
smsc-clockp = <0x0>;
smsc-clockm = <0x3>;

reset-gpios = < 21 GPIO_ACTIVE_LOW>;
interrupts = < 10 GPIO_ACTIVE_LOW>;
};

Andrea


Re: [RFC PATCH 2/3] arcnet: com20020: Fixup missing SLOWARB bit

2018-05-08 Thread Andrea Greco

On 05/07/2018 04:55 AM, Tobin C. Harding wrote:

On Sat, May 05, 2018 at 11:37:54PM +0200, Andrea Greco wrote:

From: Andrea Greco <a.gr...@4sigma.it>

If com20020 clock is major of 40Mhz SLOWARB bit is requested.

Signed-off-by: Andrea Greco <a.gr...@4sigma.it>
---
  drivers/net/arcnet/com20020.c | 4 
  1 file changed, 4 insertions(+)

diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index f09ea77dd6a8..abd32ed8ec9b 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -102,6 +102,10 @@ int com20020_check(struct net_device *dev)
lp->setup = lp->clockm ? 0 : (lp->clockp << 1);
lp->setup2 = (lp->clockm << 4) | 8;
  
+	// If clock is major of 40Mhz, SLOWARB bit must be set


/* C89 style comments please :) */



Done



Hope this helps,
Tobin.



Re: [RFC PATCH 2/3] arcnet: com20020: Fixup missing SLOWARB bit

2018-05-08 Thread Andrea Greco

On 05/07/2018 04:55 AM, Tobin C. Harding wrote:

On Sat, May 05, 2018 at 11:37:54PM +0200, Andrea Greco wrote:

From: Andrea Greco 

If com20020 clock is major of 40Mhz SLOWARB bit is requested.

Signed-off-by: Andrea Greco 
---
  drivers/net/arcnet/com20020.c | 4 
  1 file changed, 4 insertions(+)

diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index f09ea77dd6a8..abd32ed8ec9b 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -102,6 +102,10 @@ int com20020_check(struct net_device *dev)
lp->setup = lp->clockm ? 0 : (lp->clockp << 1);
lp->setup2 = (lp->clockm << 4) | 8;
  
+	// If clock is major of 40Mhz, SLOWARB bit must be set


/* C89 style comments please :) */



Done



Hope this helps,
Tobin.



Re: [RFC PATCH 1/3] arcnet: com20020: Add memory map of com20020

2018-05-08 Thread Andrea Greco

On 05/07/2018 04:55 AM, Tobin C. Harding wrote:

On Sat, May 05, 2018 at 11:34:45PM +0200, Andrea Greco wrote:

From: Andrea Greco <a.gr...@4sigma.it>


Hi Andrea,

Here are some (mostly stylistic) suggestions to help you get your driver merged.


Add support for com20022I/com20020, memory mapped chip version.
Support bus: Intel 80xx and Motorola 68xx.
Bus size: Only 8 bit bus size is supported.
Added related device tree bindings

Signed-off-by: Andrea Greco <a.gr...@4sigma.it>
---
  .../devicetree/bindings/net/smsc-com20020.txt  |  23 +++
  drivers/net/arcnet/Kconfig |  12 +-
  drivers/net/arcnet/Makefile|   1 +
  drivers/net/arcnet/arcdevice.h |  27 ++-
  drivers/net/arcnet/com20020-membus.c   | 191 +
  drivers/net/arcnet/com20020.c  |   9 +-
  6 files changed, 253 insertions(+), 10 deletions(-)
  create mode 100644 Documentation/devicetree/bindings/net/smsc-com20020.txt
  create mode 100644 drivers/net/arcnet/com20020-membus.c

diff --git a/Documentation/devicetree/bindings/net/smsc-com20020.txt 
b/Documentation/devicetree/bindings/net/smsc-com20020.txt
new file mode 100644
index ..39c5b19c55af
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/smsc-com20020.txt
@@ -0,0 +1,23 @@
+SMSC com20020, com20022I
+
+timeout: Arcnet timeout, checkout datashet
+clockp: Clock Prescaler, checkout datashet
+clockm: Clock multiplier, checkout datasheet
+
+phy-reset-gpios: Chip reset ppin
+phy-irq-gpios: Chip irq pin


ppin Corrected by my-self.


+
+com20020_A@0 {
+compatible = "smsc,com20020";
+
+   timeout = <0x3>;
+   backplane = <0x0>;
+
+   clockp = <0x0>;
+   clockm = <0x3>;
+
+   phy-reset-gpios = < 21 GPIO_ACTIVE_LOW>;
+   phy-irq-gpios = < 10 GPIO_ACTIVE_LOW>;
+
+   status = "okay";
+};
diff --git a/drivers/net/arcnet/Kconfig b/drivers/net/arcnet/Kconfig
index 39bd16f3f86d..d39faf45be1e 100644
--- a/drivers/net/arcnet/Kconfig
+++ b/drivers/net/arcnet/Kconfig
@@ -3,7 +3,7 @@
  #
  
  menuconfig ARCNET

-   depends on NETDEVICES && (ISA || PCI || PCMCIA)
+   depends on NETDEVICES
tristate "ARCnet support"
---help---
  If you have a network card of this type, say Y and check out the
@@ -129,5 +129,15 @@ config ARCNET_COM20020_CS
  
  	  To compile this driver as a module, choose M here: the module will be

  called com20020_cs.  If unsure, say N.
+config ARCNET_COM20020_MEMORY_BUS
+   bool "Support for COM20020 on external memory"
+   depends on ARCNET_COM20020 && !(ARCNET_COM20020_PCI || 
ARCNET_COM20020_ISA || ARCNET_COM20020_CS)
+   help
+ Say Y here if on your custom board mount com20020 or friends.
+
+ Com20022I support arcnet bus 10Mbitps.
+ This driver support only 8bit


This driver only supports 8bit bus size.


   , and DMA is not supported is attached 
on your board at external interface bus.


This bit does not make sense, sorry.

Removed description,

Proposal for v2:
Say Y here if your custom board mount com20020 chipset or friends.
Supported Chipset: com20020, com20022, com20022I-3v3.
If unsure, say N.


+ Supported bus Intel80xx / Motorola 68xx.
+ This driver not work with other com20020 module: PCI or PCMCIA 
compiled as [M].


I'm not sure exactly what you want to say here, perhaps:

  This driver does not work with other com20020 modules compiled
  as PCI or PCMCIA [M].


About this, all removed from kconfig
For PCI, PCMCIA, checkout downside

  
  endif # ARCNET

diff --git a/drivers/net/arcnet/Makefile b/drivers/net/arcnet/Makefile
index 53525e8ea130..19425c1e06f4 100644
--- a/drivers/net/arcnet/Makefile
+++ b/drivers/net/arcnet/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_ARCNET_COM20020) += com20020.o
  obj-$(CONFIG_ARCNET_COM20020_ISA) += com20020-isa.o
  obj-$(CONFIG_ARCNET_COM20020_PCI) += com20020-pci.o
  obj-$(CONFIG_ARCNET_COM20020_CS) += com20020_cs.o
+obj-$(CONFIG_ARCNET_COM20020_MEMORY_BUS) += com20020-membus.o
diff --git a/drivers/net/arcnet/arcdevice.h b/drivers/net/arcnet/arcdevice.h
index d09b2b46ab63..16c608269cca 100644
--- a/drivers/net/arcnet/arcdevice.h
+++ b/drivers/net/arcnet/arcdevice.h
@@ -201,7 +201,7 @@ struct ArcProto {
void (*rx)(struct net_device *dev, int bufnum,
   struct archdr *pkthdr, int length);
int (*build_header)(struct sk_buff *skb, struct net_device *dev,
-   unsigned short ethproto, uint8_t daddr);
+   unsigned short ethproto, uint8_t daddr);


   +unsigned short ethproto, uint8_t daddr);

Please use Linux coding style style, parameters continuing on separate
line are aligned with opening parenthesis.


/* these functions r

Re: [RFC PATCH 1/3] arcnet: com20020: Add memory map of com20020

2018-05-08 Thread Andrea Greco

On 05/07/2018 04:55 AM, Tobin C. Harding wrote:

On Sat, May 05, 2018 at 11:34:45PM +0200, Andrea Greco wrote:

From: Andrea Greco 


Hi Andrea,

Here are some (mostly stylistic) suggestions to help you get your driver merged.


Add support for com20022I/com20020, memory mapped chip version.
Support bus: Intel 80xx and Motorola 68xx.
Bus size: Only 8 bit bus size is supported.
Added related device tree bindings

Signed-off-by: Andrea Greco 
---
  .../devicetree/bindings/net/smsc-com20020.txt  |  23 +++
  drivers/net/arcnet/Kconfig |  12 +-
  drivers/net/arcnet/Makefile|   1 +
  drivers/net/arcnet/arcdevice.h |  27 ++-
  drivers/net/arcnet/com20020-membus.c   | 191 +
  drivers/net/arcnet/com20020.c  |   9 +-
  6 files changed, 253 insertions(+), 10 deletions(-)
  create mode 100644 Documentation/devicetree/bindings/net/smsc-com20020.txt
  create mode 100644 drivers/net/arcnet/com20020-membus.c

diff --git a/Documentation/devicetree/bindings/net/smsc-com20020.txt 
b/Documentation/devicetree/bindings/net/smsc-com20020.txt
new file mode 100644
index ..39c5b19c55af
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/smsc-com20020.txt
@@ -0,0 +1,23 @@
+SMSC com20020, com20022I
+
+timeout: Arcnet timeout, checkout datashet
+clockp: Clock Prescaler, checkout datashet
+clockm: Clock multiplier, checkout datasheet
+
+phy-reset-gpios: Chip reset ppin
+phy-irq-gpios: Chip irq pin


ppin Corrected by my-self.


+
+com20020_A@0 {
+compatible = "smsc,com20020";
+
+   timeout = <0x3>;
+   backplane = <0x0>;
+
+   clockp = <0x0>;
+   clockm = <0x3>;
+
+   phy-reset-gpios = < 21 GPIO_ACTIVE_LOW>;
+   phy-irq-gpios = < 10 GPIO_ACTIVE_LOW>;
+
+   status = "okay";
+};
diff --git a/drivers/net/arcnet/Kconfig b/drivers/net/arcnet/Kconfig
index 39bd16f3f86d..d39faf45be1e 100644
--- a/drivers/net/arcnet/Kconfig
+++ b/drivers/net/arcnet/Kconfig
@@ -3,7 +3,7 @@
  #
  
  menuconfig ARCNET

-   depends on NETDEVICES && (ISA || PCI || PCMCIA)
+   depends on NETDEVICES
tristate "ARCnet support"
---help---
  If you have a network card of this type, say Y and check out the
@@ -129,5 +129,15 @@ config ARCNET_COM20020_CS
  
  	  To compile this driver as a module, choose M here: the module will be

  called com20020_cs.  If unsure, say N.
+config ARCNET_COM20020_MEMORY_BUS
+   bool "Support for COM20020 on external memory"
+   depends on ARCNET_COM20020 && !(ARCNET_COM20020_PCI || 
ARCNET_COM20020_ISA || ARCNET_COM20020_CS)
+   help
+ Say Y here if on your custom board mount com20020 or friends.
+
+ Com20022I support arcnet bus 10Mbitps.
+ This driver support only 8bit


This driver only supports 8bit bus size.


   , and DMA is not supported is attached 
on your board at external interface bus.


This bit does not make sense, sorry.

Removed description,

Proposal for v2:
Say Y here if your custom board mount com20020 chipset or friends.
Supported Chipset: com20020, com20022, com20022I-3v3.
If unsure, say N.


+ Supported bus Intel80xx / Motorola 68xx.
+ This driver not work with other com20020 module: PCI or PCMCIA 
compiled as [M].


I'm not sure exactly what you want to say here, perhaps:

  This driver does not work with other com20020 modules compiled
  as PCI or PCMCIA [M].


About this, all removed from kconfig
For PCI, PCMCIA, checkout downside

  
  endif # ARCNET

diff --git a/drivers/net/arcnet/Makefile b/drivers/net/arcnet/Makefile
index 53525e8ea130..19425c1e06f4 100644
--- a/drivers/net/arcnet/Makefile
+++ b/drivers/net/arcnet/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_ARCNET_COM20020) += com20020.o
  obj-$(CONFIG_ARCNET_COM20020_ISA) += com20020-isa.o
  obj-$(CONFIG_ARCNET_COM20020_PCI) += com20020-pci.o
  obj-$(CONFIG_ARCNET_COM20020_CS) += com20020_cs.o
+obj-$(CONFIG_ARCNET_COM20020_MEMORY_BUS) += com20020-membus.o
diff --git a/drivers/net/arcnet/arcdevice.h b/drivers/net/arcnet/arcdevice.h
index d09b2b46ab63..16c608269cca 100644
--- a/drivers/net/arcnet/arcdevice.h
+++ b/drivers/net/arcnet/arcdevice.h
@@ -201,7 +201,7 @@ struct ArcProto {
void (*rx)(struct net_device *dev, int bufnum,
   struct archdr *pkthdr, int length);
int (*build_header)(struct sk_buff *skb, struct net_device *dev,
-   unsigned short ethproto, uint8_t daddr);
+   unsigned short ethproto, uint8_t daddr);


   +unsigned short ethproto, uint8_t daddr);

Please use Linux coding style style, parameters continuing on separate
line are aligned with opening parenthesis.


/* these functions return '1' if the skb can now be freed */

[RFC PATCH 2/3] arcnet: com20020: Fixup missing SLOWARB bit

2018-05-05 Thread Andrea Greco
From: Andrea Greco <a.gr...@4sigma.it>

If com20020 clock is major of 40Mhz SLOWARB bit is requested.

Signed-off-by: Andrea Greco <a.gr...@4sigma.it>
---
 drivers/net/arcnet/com20020.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index f09ea77dd6a8..abd32ed8ec9b 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -102,6 +102,10 @@ int com20020_check(struct net_device *dev)
lp->setup = lp->clockm ? 0 : (lp->clockp << 1);
lp->setup2 = (lp->clockm << 4) | 8;
 
+   // If clock is major of 40Mhz, SLOWARB bit must be set
+   if (lp->clockm > 1)
+   lp->setup2 |= SLOWARB;
+
/* CHECK: should we do this for SOHARD cards ? */
/* Enable P1Mode for backplane mode */
lp->setup = lp->setup | P1MODE;
-- 
2.14.3



[RFC PATCH 2/3] arcnet: com20020: Fixup missing SLOWARB bit

2018-05-05 Thread Andrea Greco
From: Andrea Greco 

If com20020 clock is major of 40Mhz SLOWARB bit is requested.

Signed-off-by: Andrea Greco 
---
 drivers/net/arcnet/com20020.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index f09ea77dd6a8..abd32ed8ec9b 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -102,6 +102,10 @@ int com20020_check(struct net_device *dev)
lp->setup = lp->clockm ? 0 : (lp->clockp << 1);
lp->setup2 = (lp->clockm << 4) | 8;
 
+   // If clock is major of 40Mhz, SLOWARB bit must be set
+   if (lp->clockm > 1)
+   lp->setup2 |= SLOWARB;
+
/* CHECK: should we do this for SOHARD cards ? */
/* Enable P1Mode for backplane mode */
lp->setup = lp->setup | P1MODE;
-- 
2.14.3



[RFC PATCH 3/3] arcnet: com20020: Add ethtool support

2018-05-05 Thread Andrea Greco
From: Andrea Greco <a.gr...@4sigma.it>

Setup ethtols for export com20020 diag register

Signed-off-by: Andrea Greco <a.gr...@4sigma.it>
---
 drivers/net/arcnet/com20020-isa.c|  1 +
 drivers/net/arcnet/com20020-membus.c |  1 +
 drivers/net/arcnet/com20020.c| 29 +
 drivers/net/arcnet/com20020.h|  1 +
 drivers/net/arcnet/com20020_cs.c |  1 +
 include/uapi/linux/if_arcnet.h   |  6 ++
 6 files changed, 39 insertions(+)

diff --git a/drivers/net/arcnet/com20020-isa.c 
b/drivers/net/arcnet/com20020-isa.c
index 38fa60ddaf2e..44ab6dcccb58 100644
--- a/drivers/net/arcnet/com20020-isa.c
+++ b/drivers/net/arcnet/com20020-isa.c
@@ -154,6 +154,7 @@ static int __init com20020_init(void)
dev->dev_addr[0] = node;
 
dev->netdev_ops = _netdev_ops;
+   dev->ethtool_ops = _ethtool_ops;
 
lp = netdev_priv(dev);
lp->backplane = backplane;
diff --git a/drivers/net/arcnet/com20020-membus.c 
b/drivers/net/arcnet/com20020-membus.c
index 6e4a2f3a84f7..9eead734a3cf 100644
--- a/drivers/net/arcnet/com20020-membus.c
+++ b/drivers/net/arcnet/com20020-membus.c
@@ -91,6 +91,7 @@ static int com20020_probe(struct platform_device *pdev)
 
dev = alloc_arcdev(NULL);// Let autoassign name arc%d
dev->netdev_ops = _netdev_ops;
+   dev->ethtool_ops = _ethtool_ops;
lp = netdev_priv(dev);
 
lp->card_flags = ARC_CAN_10MBIT;/* pretend all of them can 10Mbit */
diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index abd32ed8ec9b..2089b45e81c8 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -201,6 +201,34 @@ const struct net_device_ops com20020_netdev_ops = {
.ndo_set_rx_mode = com20020_set_mc_list,
 };
 
+static int com20020_ethtool_regs_len(struct net_device *netdev)
+{
+   return sizeof(struct com20020_ethtool_regs);
+}
+
+static void com20020_ethtool_regs_read(struct net_device *dev,
+  struct ethtool_regs *regs, void *p)
+{
+   struct arcnet_local *lp;
+   struct com20020_ethtool_regs *com_reg;
+
+   lp = netdev_priv(dev);
+   memset(p, 0, sizeof(struct com20020_ethtool_regs));
+
+   regs->version = 1;
+
+   com_reg = p;
+
+   com_reg->status = lp->hw.status(dev) & 0xFF;
+   com_reg->diag_register = (lp->hw.status(dev) >> 8) & 0xFF;
+   com_reg->reconf_count = lp->num_recons;
+}
+
+const struct ethtool_ops com20020_ethtool_ops = {
+   .get_regs = com20020_ethtool_regs_read,
+   .get_regs_len  = com20020_ethtool_regs_len,
+};
+
 /* Set up the struct net_device associated with this card.  Called after
  * probing succeeds.
  */
@@ -402,6 +430,7 @@ static void com20020_set_mc_list(struct net_device *dev)
 EXPORT_SYMBOL(com20020_check);
 EXPORT_SYMBOL(com20020_found);
 EXPORT_SYMBOL(com20020_netdev_ops);
+EXPORT_SYMBOL(com20020_ethtool_ops);
 #endif
 
 MODULE_LICENSE("GPL");
diff --git a/drivers/net/arcnet/com20020.h b/drivers/net/arcnet/com20020.h
index 0bcc5d0a6903..a1024c8f8a1f 100644
--- a/drivers/net/arcnet/com20020.h
+++ b/drivers/net/arcnet/com20020.h
@@ -31,6 +31,7 @@
 int com20020_check(struct net_device *dev);
 int com20020_found(struct net_device *dev, int shared);
 extern const struct net_device_ops com20020_netdev_ops;
+extern const struct ethtool_ops com20020_ethtool_ops;
 
 /* The number of low I/O ports used by the card. */
 #define ARCNET_TOTAL_SIZE 8
diff --git a/drivers/net/arcnet/com20020_cs.c b/drivers/net/arcnet/com20020_cs.c
index cf607ffcf358..ae64f436fd54 100644
--- a/drivers/net/arcnet/com20020_cs.c
+++ b/drivers/net/arcnet/com20020_cs.c
@@ -233,6 +233,7 @@ static int com20020_config(struct pcmcia_device *link)
}
 
dev->irq = link->irq;
+   dev->ethtool_ops = _ethtool_ops;
 
ret = pcmcia_enable_device(link);
if (ret)
diff --git a/include/uapi/linux/if_arcnet.h b/include/uapi/linux/if_arcnet.h
index 683878036d76..790c0fa7386d 100644
--- a/include/uapi/linux/if_arcnet.h
+++ b/include/uapi/linux/if_arcnet.h
@@ -127,4 +127,10 @@ struct archdr {
} soft;
 };
 
+struct com20020_ethtool_regs {
+   __u8 status;
+   __u8 diag_register;
+   __u32 reconf_count;
+};
+
 #endif /* _LINUX_IF_ARCNET_H */
-- 
2.14.3



[RFC PATCH 1/3] arcnet: com20020: Add memory map of com20020

2018-05-05 Thread Andrea Greco
From: Andrea Greco <a.gr...@4sigma.it>

Add support for com20022I/com20020, memory mapped chip version.
Support bus: Intel 80xx and Motorola 68xx.
Bus size: Only 8 bit bus size is supported.
Added related device tree bindings

Signed-off-by: Andrea Greco <a.gr...@4sigma.it>
---
 .../devicetree/bindings/net/smsc-com20020.txt  |  23 +++
 drivers/net/arcnet/Kconfig |  12 +-
 drivers/net/arcnet/Makefile|   1 +
 drivers/net/arcnet/arcdevice.h |  27 ++-
 drivers/net/arcnet/com20020-membus.c   | 191 +
 drivers/net/arcnet/com20020.c  |   9 +-
 6 files changed, 253 insertions(+), 10 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/smsc-com20020.txt
 create mode 100644 drivers/net/arcnet/com20020-membus.c

diff --git a/Documentation/devicetree/bindings/net/smsc-com20020.txt 
b/Documentation/devicetree/bindings/net/smsc-com20020.txt
new file mode 100644
index ..39c5b19c55af
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/smsc-com20020.txt
@@ -0,0 +1,23 @@
+SMSC com20020, com20022I
+
+timeout: Arcnet timeout, checkout datashet
+clockp: Clock Prescaler, checkout datashet
+clockm: Clock multiplier, checkout datasheet
+
+phy-reset-gpios: Chip reset ppin
+phy-irq-gpios: Chip irq pin
+
+com20020_A@0 {
+compatible = "smsc,com20020";
+
+   timeout = <0x3>;
+   backplane = <0x0>;
+
+   clockp = <0x0>;
+   clockm = <0x3>;
+
+   phy-reset-gpios = < 21 GPIO_ACTIVE_LOW>;
+   phy-irq-gpios = < 10 GPIO_ACTIVE_LOW>;
+
+   status = "okay";
+};
diff --git a/drivers/net/arcnet/Kconfig b/drivers/net/arcnet/Kconfig
index 39bd16f3f86d..d39faf45be1e 100644
--- a/drivers/net/arcnet/Kconfig
+++ b/drivers/net/arcnet/Kconfig
@@ -3,7 +3,7 @@
 #
 
 menuconfig ARCNET
-   depends on NETDEVICES && (ISA || PCI || PCMCIA)
+   depends on NETDEVICES
tristate "ARCnet support"
---help---
  If you have a network card of this type, say Y and check out the
@@ -129,5 +129,15 @@ config ARCNET_COM20020_CS
 
  To compile this driver as a module, choose M here: the module will be
  called com20020_cs.  If unsure, say N.
+config ARCNET_COM20020_MEMORY_BUS
+   bool "Support for COM20020 on external memory"
+   depends on ARCNET_COM20020 && !(ARCNET_COM20020_PCI || 
ARCNET_COM20020_ISA || ARCNET_COM20020_CS)
+   help
+ Say Y here if on your custom board mount com20020 or friends.
+
+ Com20022I support arcnet bus 10Mbitps.
+ This driver support only 8bit, and DMA is not supported is attached 
on your board at external interface bus.
+ Supported bus Intel80xx / Motorola 68xx.
+ This driver not work with other com20020 module: PCI or PCMCIA 
compiled as [M].
 
 endif # ARCNET
diff --git a/drivers/net/arcnet/Makefile b/drivers/net/arcnet/Makefile
index 53525e8ea130..19425c1e06f4 100644
--- a/drivers/net/arcnet/Makefile
+++ b/drivers/net/arcnet/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_ARCNET_COM20020) += com20020.o
 obj-$(CONFIG_ARCNET_COM20020_ISA) += com20020-isa.o
 obj-$(CONFIG_ARCNET_COM20020_PCI) += com20020-pci.o
 obj-$(CONFIG_ARCNET_COM20020_CS) += com20020_cs.o
+obj-$(CONFIG_ARCNET_COM20020_MEMORY_BUS) += com20020-membus.o
diff --git a/drivers/net/arcnet/arcdevice.h b/drivers/net/arcnet/arcdevice.h
index d09b2b46ab63..16c608269cca 100644
--- a/drivers/net/arcnet/arcdevice.h
+++ b/drivers/net/arcnet/arcdevice.h
@@ -201,7 +201,7 @@ struct ArcProto {
void (*rx)(struct net_device *dev, int bufnum,
   struct archdr *pkthdr, int length);
int (*build_header)(struct sk_buff *skb, struct net_device *dev,
-   unsigned short ethproto, uint8_t daddr);
+   unsigned short ethproto, uint8_t daddr);
 
/* these functions return '1' if the skb can now be freed */
int (*prepare_tx)(struct net_device *dev, struct archdr *pkt,
@@ -326,9 +326,9 @@ struct arcnet_local {
void (*recontrigger) (struct net_device * dev, int enable);
 
void (*copy_to_card)(struct net_device *dev, int bufnum,
-int offset, void *buf, int count);
+int offset, void *buf, int count);
void (*copy_from_card)(struct net_device *dev, int bufnum,
-  int offset, void *buf, int count);
+  int offset, void *buf, int count);
} hw;
 
void __iomem *mem_start;/* pointer to ioremap'ed MMIO */
@@ -360,7 +360,7 @@ struct net_device *alloc_arcdev(const char *name);
 int arcnet_open(struct net_device *dev);
 int arcnet_close(struct net_device *dev);
 netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
-

[RFC PATCH 1/3] arcnet: com20020: Add memory map of com20020

2018-05-05 Thread Andrea Greco
From: Andrea Greco 

Add support for com20022I/com20020, memory mapped chip version.
Support bus: Intel 80xx and Motorola 68xx.
Bus size: Only 8 bit bus size is supported.
Added related device tree bindings

Signed-off-by: Andrea Greco 
---
 .../devicetree/bindings/net/smsc-com20020.txt  |  23 +++
 drivers/net/arcnet/Kconfig |  12 +-
 drivers/net/arcnet/Makefile|   1 +
 drivers/net/arcnet/arcdevice.h |  27 ++-
 drivers/net/arcnet/com20020-membus.c   | 191 +
 drivers/net/arcnet/com20020.c  |   9 +-
 6 files changed, 253 insertions(+), 10 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/smsc-com20020.txt
 create mode 100644 drivers/net/arcnet/com20020-membus.c

diff --git a/Documentation/devicetree/bindings/net/smsc-com20020.txt 
b/Documentation/devicetree/bindings/net/smsc-com20020.txt
new file mode 100644
index ..39c5b19c55af
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/smsc-com20020.txt
@@ -0,0 +1,23 @@
+SMSC com20020, com20022I
+
+timeout: Arcnet timeout, checkout datashet
+clockp: Clock Prescaler, checkout datashet
+clockm: Clock multiplier, checkout datasheet
+
+phy-reset-gpios: Chip reset ppin
+phy-irq-gpios: Chip irq pin
+
+com20020_A@0 {
+compatible = "smsc,com20020";
+
+   timeout = <0x3>;
+   backplane = <0x0>;
+
+   clockp = <0x0>;
+   clockm = <0x3>;
+
+   phy-reset-gpios = < 21 GPIO_ACTIVE_LOW>;
+   phy-irq-gpios = < 10 GPIO_ACTIVE_LOW>;
+
+   status = "okay";
+};
diff --git a/drivers/net/arcnet/Kconfig b/drivers/net/arcnet/Kconfig
index 39bd16f3f86d..d39faf45be1e 100644
--- a/drivers/net/arcnet/Kconfig
+++ b/drivers/net/arcnet/Kconfig
@@ -3,7 +3,7 @@
 #
 
 menuconfig ARCNET
-   depends on NETDEVICES && (ISA || PCI || PCMCIA)
+   depends on NETDEVICES
tristate "ARCnet support"
---help---
  If you have a network card of this type, say Y and check out the
@@ -129,5 +129,15 @@ config ARCNET_COM20020_CS
 
  To compile this driver as a module, choose M here: the module will be
  called com20020_cs.  If unsure, say N.
+config ARCNET_COM20020_MEMORY_BUS
+   bool "Support for COM20020 on external memory"
+   depends on ARCNET_COM20020 && !(ARCNET_COM20020_PCI || 
ARCNET_COM20020_ISA || ARCNET_COM20020_CS)
+   help
+ Say Y here if on your custom board mount com20020 or friends.
+
+ Com20022I support arcnet bus 10Mbitps.
+ This driver support only 8bit, and DMA is not supported is attached 
on your board at external interface bus.
+ Supported bus Intel80xx / Motorola 68xx.
+ This driver not work with other com20020 module: PCI or PCMCIA 
compiled as [M].
 
 endif # ARCNET
diff --git a/drivers/net/arcnet/Makefile b/drivers/net/arcnet/Makefile
index 53525e8ea130..19425c1e06f4 100644
--- a/drivers/net/arcnet/Makefile
+++ b/drivers/net/arcnet/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_ARCNET_COM20020) += com20020.o
 obj-$(CONFIG_ARCNET_COM20020_ISA) += com20020-isa.o
 obj-$(CONFIG_ARCNET_COM20020_PCI) += com20020-pci.o
 obj-$(CONFIG_ARCNET_COM20020_CS) += com20020_cs.o
+obj-$(CONFIG_ARCNET_COM20020_MEMORY_BUS) += com20020-membus.o
diff --git a/drivers/net/arcnet/arcdevice.h b/drivers/net/arcnet/arcdevice.h
index d09b2b46ab63..16c608269cca 100644
--- a/drivers/net/arcnet/arcdevice.h
+++ b/drivers/net/arcnet/arcdevice.h
@@ -201,7 +201,7 @@ struct ArcProto {
void (*rx)(struct net_device *dev, int bufnum,
   struct archdr *pkthdr, int length);
int (*build_header)(struct sk_buff *skb, struct net_device *dev,
-   unsigned short ethproto, uint8_t daddr);
+   unsigned short ethproto, uint8_t daddr);
 
/* these functions return '1' if the skb can now be freed */
int (*prepare_tx)(struct net_device *dev, struct archdr *pkt,
@@ -326,9 +326,9 @@ struct arcnet_local {
void (*recontrigger) (struct net_device * dev, int enable);
 
void (*copy_to_card)(struct net_device *dev, int bufnum,
-int offset, void *buf, int count);
+int offset, void *buf, int count);
void (*copy_from_card)(struct net_device *dev, int bufnum,
-  int offset, void *buf, int count);
+  int offset, void *buf, int count);
} hw;
 
void __iomem *mem_start;/* pointer to ioremap'ed MMIO */
@@ -360,7 +360,7 @@ struct net_device *alloc_arcdev(const char *name);
 int arcnet_open(struct net_device *dev);
 int arcnet_close(struct net_device *dev);
 netdev_tx_t arcnet_send_packet(struct sk_buff *skb,
-  struct net_device *dev);
+ 

[RFC PATCH 3/3] arcnet: com20020: Add ethtool support

2018-05-05 Thread Andrea Greco
From: Andrea Greco 

Setup ethtols for export com20020 diag register

Signed-off-by: Andrea Greco 
---
 drivers/net/arcnet/com20020-isa.c|  1 +
 drivers/net/arcnet/com20020-membus.c |  1 +
 drivers/net/arcnet/com20020.c| 29 +
 drivers/net/arcnet/com20020.h|  1 +
 drivers/net/arcnet/com20020_cs.c |  1 +
 include/uapi/linux/if_arcnet.h   |  6 ++
 6 files changed, 39 insertions(+)

diff --git a/drivers/net/arcnet/com20020-isa.c 
b/drivers/net/arcnet/com20020-isa.c
index 38fa60ddaf2e..44ab6dcccb58 100644
--- a/drivers/net/arcnet/com20020-isa.c
+++ b/drivers/net/arcnet/com20020-isa.c
@@ -154,6 +154,7 @@ static int __init com20020_init(void)
dev->dev_addr[0] = node;
 
dev->netdev_ops = _netdev_ops;
+   dev->ethtool_ops = _ethtool_ops;
 
lp = netdev_priv(dev);
lp->backplane = backplane;
diff --git a/drivers/net/arcnet/com20020-membus.c 
b/drivers/net/arcnet/com20020-membus.c
index 6e4a2f3a84f7..9eead734a3cf 100644
--- a/drivers/net/arcnet/com20020-membus.c
+++ b/drivers/net/arcnet/com20020-membus.c
@@ -91,6 +91,7 @@ static int com20020_probe(struct platform_device *pdev)
 
dev = alloc_arcdev(NULL);// Let autoassign name arc%d
dev->netdev_ops = _netdev_ops;
+   dev->ethtool_ops = _ethtool_ops;
lp = netdev_priv(dev);
 
lp->card_flags = ARC_CAN_10MBIT;/* pretend all of them can 10Mbit */
diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index abd32ed8ec9b..2089b45e81c8 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -201,6 +201,34 @@ const struct net_device_ops com20020_netdev_ops = {
.ndo_set_rx_mode = com20020_set_mc_list,
 };
 
+static int com20020_ethtool_regs_len(struct net_device *netdev)
+{
+   return sizeof(struct com20020_ethtool_regs);
+}
+
+static void com20020_ethtool_regs_read(struct net_device *dev,
+  struct ethtool_regs *regs, void *p)
+{
+   struct arcnet_local *lp;
+   struct com20020_ethtool_regs *com_reg;
+
+   lp = netdev_priv(dev);
+   memset(p, 0, sizeof(struct com20020_ethtool_regs));
+
+   regs->version = 1;
+
+   com_reg = p;
+
+   com_reg->status = lp->hw.status(dev) & 0xFF;
+   com_reg->diag_register = (lp->hw.status(dev) >> 8) & 0xFF;
+   com_reg->reconf_count = lp->num_recons;
+}
+
+const struct ethtool_ops com20020_ethtool_ops = {
+   .get_regs = com20020_ethtool_regs_read,
+   .get_regs_len  = com20020_ethtool_regs_len,
+};
+
 /* Set up the struct net_device associated with this card.  Called after
  * probing succeeds.
  */
@@ -402,6 +430,7 @@ static void com20020_set_mc_list(struct net_device *dev)
 EXPORT_SYMBOL(com20020_check);
 EXPORT_SYMBOL(com20020_found);
 EXPORT_SYMBOL(com20020_netdev_ops);
+EXPORT_SYMBOL(com20020_ethtool_ops);
 #endif
 
 MODULE_LICENSE("GPL");
diff --git a/drivers/net/arcnet/com20020.h b/drivers/net/arcnet/com20020.h
index 0bcc5d0a6903..a1024c8f8a1f 100644
--- a/drivers/net/arcnet/com20020.h
+++ b/drivers/net/arcnet/com20020.h
@@ -31,6 +31,7 @@
 int com20020_check(struct net_device *dev);
 int com20020_found(struct net_device *dev, int shared);
 extern const struct net_device_ops com20020_netdev_ops;
+extern const struct ethtool_ops com20020_ethtool_ops;
 
 /* The number of low I/O ports used by the card. */
 #define ARCNET_TOTAL_SIZE 8
diff --git a/drivers/net/arcnet/com20020_cs.c b/drivers/net/arcnet/com20020_cs.c
index cf607ffcf358..ae64f436fd54 100644
--- a/drivers/net/arcnet/com20020_cs.c
+++ b/drivers/net/arcnet/com20020_cs.c
@@ -233,6 +233,7 @@ static int com20020_config(struct pcmcia_device *link)
}
 
dev->irq = link->irq;
+   dev->ethtool_ops = _ethtool_ops;
 
ret = pcmcia_enable_device(link);
if (ret)
diff --git a/include/uapi/linux/if_arcnet.h b/include/uapi/linux/if_arcnet.h
index 683878036d76..790c0fa7386d 100644
--- a/include/uapi/linux/if_arcnet.h
+++ b/include/uapi/linux/if_arcnet.h
@@ -127,4 +127,10 @@ struct archdr {
} soft;
 };
 
+struct com20020_ethtool_regs {
+   __u8 status;
+   __u8 diag_register;
+   __u32 reconf_count;
+};
+
 #endif /* _LINUX_IF_ARCNET_H */
-- 
2.14.3



[PATCH] RTC: DS1340 Add support for trickle charger.

2018-04-20 Thread Andrea Greco
From: Andrea Greco <a.gr...@4sigma.it>

Add support Dallas DS1340 trickle charger function.

Signed-off-by: Andrea Greco <a.gr...@4sigma.it>
---
 drivers/rtc/rtc-ds1307.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index a13e59edff53..e9ec4160d7f6 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -201,6 +201,7 @@ static const struct chip_desc chips[last_ds_type] = {
.century_reg= DS1307_REG_HOUR,
.century_enable_bit = DS1340_BIT_CENTURY_EN,
.century_bit= DS1340_BIT_CENTURY,
+   .do_trickle_setup = _trickle_setup_ds1339,
.trickle_charger_reg = 0x08,
},
[ds_1341] = {
@@ -1371,6 +1372,7 @@ static void ds1307_clks_register(struct ds1307 *ds1307)
 static const struct regmap_config regmap_config = {
.reg_bits = 8,
.val_bits = 8,
+   .max_register = 0x9,
 };
 
 static int ds1307_probe(struct i2c_client *client,
-- 
2.14.3



[PATCH] RTC: DS1340 Add support for trickle charger.

2018-04-20 Thread Andrea Greco
From: Andrea Greco 

Add support Dallas DS1340 trickle charger function.

Signed-off-by: Andrea Greco 
---
 drivers/rtc/rtc-ds1307.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index a13e59edff53..e9ec4160d7f6 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -201,6 +201,7 @@ static const struct chip_desc chips[last_ds_type] = {
.century_reg= DS1307_REG_HOUR,
.century_enable_bit = DS1340_BIT_CENTURY_EN,
.century_bit= DS1340_BIT_CENTURY,
+   .do_trickle_setup = _trickle_setup_ds1339,
.trickle_charger_reg = 0x08,
},
[ds_1341] = {
@@ -1371,6 +1372,7 @@ static void ds1307_clks_register(struct ds1307 *ds1307)
 static const struct regmap_config regmap_config = {
.reg_bits = 8,
.val_bits = 8,
+   .max_register = 0x9,
 };
 
 static int ds1307_probe(struct i2c_client *client,
-- 
2.14.3