[PATCH] net: smsc95xx: Fix MTU range

2018-11-08 Thread Stefan Wahren
The commit f77f0aee4da4 ("net: use core MTU range checking in USB NIC
drivers") introduce a common MTU handling for usbnet. But it's missing
the necessary changes for smsc95xx. So set the MTU range accordingly.

This patch has been tested on a Raspberry Pi 3.

Fixes: f77f0aee4da4 ("net: use core MTU range checking in USB NIC drivers")
Signed-off-by: Stefan Wahren 
---
 drivers/net/usb/smsc95xx.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index 262e7a3..5974478 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -1321,6 +1321,8 @@ static int smsc95xx_bind(struct usbnet *dev, struct 
usb_interface *intf)
dev->net->ethtool_ops = _ethtool_ops;
dev->net->flags |= IFF_MULTICAST;
dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM;
+   dev->net->min_mtu = ETH_MIN_MTU;
+   dev->net->max_mtu = ETH_DATA_LEN;
dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
 
pdata->dev = dev;
-- 
2.7.4



smsc95xx: Invalid max MTU

2018-09-05 Thread Stefan Wahren
Hi,

recently there was a user who reports that his Raspberry Pi 3B didn't work as 
expected [1].

The problem is that the smsc95xx driver accepts to high MTU values ( > 9000) 
from userspace like dhcp-client, but according to the LAN9500 databook the chip 
seems only capable to handle MTU sizes <= 1500.

It looks like that smsc95xx slipped through the cracks during the creation of 
commit f77f0aee4da4 ("net: use core MTU range checking in USB NIC drivers"). 
Unfortunately i don't have all the chips listed in this driver.

So my questions would be the following patch correct:

diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index 06b4d29..420a0e4 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -1318,6 +1318,7 @@ static int smsc95xx_bind(struct usbnet *dev, struct 
usb_interface *intf)
dev->net->ethtool_ops = _ethtool_ops;
dev->net->flags |= IFF_MULTICAST;
dev->net->hard_header_len += SMSC95XX_TX_OVERHEAD_CSUM;
+   dev->net->max_mtu = ETH_DATA_LEN;
dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
 
pdata->dev = dev;

[1] - https://github.com/raspberrypi/linux/issues/2660


Re: [offlist] Re: Crash in netlink/sk_filter_trim_cap on ARMv7 on 4.18rc1

2018-08-17 Thread Stefan Wahren
Hi Daniel,

> Daniel Borkmann  hat am 17. August 2018 um 20:30 
> geschrieben:
> 
> 
> On 08/17/2018 06:17 PM, Russell King - ARM Linux wrote:
> > On Fri, Aug 17, 2018 at 02:40:19PM +0200, Daniel Borkmann wrote:
> >> I'd have one potential bug suspicion, for the 4.18 one you were trying,
> >> could you run with the below patch to see whether it would help?
> > 
> > I think this is almost certainly the problem - looking at the history,
> > it seems that the "-4" was assumed to be part of the scratch stuff in
> > commit 38ca93060163 ("bpf, arm32: save 4 bytes of unneeded stack space")
> > but it isn't - it's because "off" of zero refers to the top word in the
> > stack (iow at STACK_SIZE-4).
> 
> Yeah agree, my thinking as well (albeit bit late, sigh, sorry about that).
> Waiting for Peter to get back with results for definite confirmation. Your
> rework in 1c35ba122d4a ("ARM: net: bpf: use negative numbers for stacked
> registers") and 96cced4e774a ("ARM: net: bpf: access eBPF scratch space using
> ARM FP register") fixes this in mainline, so unless I'm missing something this
> would only need a stand-alone fix for 4.18/stable which I can cook up and
> submit then.

i was able to reproduce this issue on RPi 3 with Linux 4.18.1 + 
multi_v7_defconfig and the following  config changes:

 --- a/arch/arm/configs/multi_v7_defconfig
+++ b/arch/arm/configs/multi_v7_defconfig
@@ -2,7 +2,10 @@ CONFIG_SYSVIPC=y
 CONFIG_NO_HZ=y
 CONFIG_HIGH_RES_TIMERS=y
 CONFIG_CGROUPS=y
+CONFIG_CGROUP_BPF=y
 CONFIG_BLK_DEV_INITRD=y
+CONFIG_BPF_SYSCALL=y
+CONFIG_BPF_JIT_ALWAYS_ON=y
 CONFIG_EMBEDDED=y
 CONFIG_PERF_EVENTS=y
 CONFIG_MODULES=y
@@ -153,6 +156,8 @@ CONFIG_IPV6_MIP6=m
 CONFIG_IPV6_TUNNEL=m
 CONFIG_IPV6_MULTIPLE_TABLES=y
 CONFIG_NET_DSA=m
+CONFIG_BPF_JIT=y
+CONFIG_BPF_STREAM_PARSER=y
 CONFIG_CAN=y
 CONFIG_CAN_AT91=m
 CONFIG_CAN_FLEXCAN=m

After applying the "-4" patch the oopses doesn't appear during boot anymore.

Stefan

> 
> Thanks,
> Daniel
> 
> ___
> linux-arm-kernel mailing list
> linux-arm-ker...@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel


net: smsc95xx: aligment issues

2018-04-28 Thread Stefan Wahren
Hi,
after connecting a Raspberry Pi 1 B to my local network i'm seeing aligment 
issues under /proc/cpu/alignment:

User:   0
System: 142 (_decode_session4+0x12c/0x3c8)
Skipped:0
Half:   0
Word:   0
DWord:  127
Multi:  15
User faults:2 (fixup)

I've also seen outputs with _csum_ipv6_magic.

Kernel config: bcm2835_defconfig
Reproducible kernel trees: current linux-next, 4.17-rc2 and 4.14.37 (i didn't 
test older versions)

Please tell if you need more information to narrow down this issue.

Best regards
Stefan


[PATCH v8 net-next 07/17] net: qca_spi: remove QCASPI_MTU

2017-05-29 Thread Stefan Wahren
There is no need for an additional MTU define.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_spi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index f155548..7464628 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -69,7 +69,6 @@ static int qcaspi_pluggable = QCASPI_PLUGGABLE_MIN;
 module_param(qcaspi_pluggable, int, 0);
 MODULE_PARM_DESC(qcaspi_pluggable, "Pluggable SPI connection (yes/no).");
 
-#define QCASPI_MTU QCAFRM_MAX_MTU
 #define QCASPI_TX_TIMEOUT (1 * HZ)
 #define QCASPI_QCA7K_REBOOT_TIME_MS 1000
 
@@ -746,7 +745,7 @@ qcaspi_netdev_init(struct net_device *dev)
 {
struct qcaspi *qca = netdev_priv(dev);
 
-   dev->mtu = QCASPI_MTU;
+   dev->mtu = QCAFRM_MAX_MTU;
dev->type = ARPHRD_ETHER;
qca->clkspeed = qcaspi_clkspeed;
qca->burst_len = qcaspi_burst_len;
-- 
2.1.4



[PATCH v8 net-next 08/17] net: qualcomm: move qcaspi_tx_cmd to qca_spi.c

2017-05-29 Thread Stefan Wahren
The function qcaspi_tx_cmd() is only called from qca_spi.c. So we better
move it there.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_7k.c  | 24 
 drivers/net/ethernet/qualcomm/qca_7k.h  |  1 -
 drivers/net/ethernet/qualcomm/qca_spi.c | 24 
 3 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_7k.c 
b/drivers/net/ethernet/qualcomm/qca_7k.c
index e9162e1..ffe7a16 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k.c
@@ -121,27 +121,3 @@ qcaspi_write_register(struct qcaspi *qca, u16 reg, u16 
value)
 
return ret;
 }
-
-int
-qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd)
-{
-   __be16 tx_data;
-   struct spi_message *msg = >spi_msg1;
-   struct spi_transfer *transfer = >spi_xfer1;
-   int ret;
-
-   tx_data = cpu_to_be16(cmd);
-   transfer->len = sizeof(tx_data);
-   transfer->tx_buf = _data;
-   transfer->rx_buf = NULL;
-
-   ret = spi_sync(qca->spi_dev, msg);
-
-   if (!ret)
-   ret = msg->status;
-
-   if (ret)
-   qcaspi_spi_error(qca);
-
-   return ret;
-}
diff --git a/drivers/net/ethernet/qualcomm/qca_7k.h 
b/drivers/net/ethernet/qualcomm/qca_7k.h
index 4047f0a..27124c2 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.h
+++ b/drivers/net/ethernet/qualcomm/qca_7k.h
@@ -67,6 +67,5 @@
 void qcaspi_spi_error(struct qcaspi *qca);
 int qcaspi_read_register(struct qcaspi *qca, u16 reg, u16 *result);
 int qcaspi_write_register(struct qcaspi *qca, u16 reg, u16 value);
-int qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd);
 
 #endif /* _QCA_7K_H */
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 7464628..50adc4f 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -192,6 +192,30 @@ qcaspi_read_legacy(struct qcaspi *qca, u8 *dst, u32 len)
 }
 
 static int
+qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd)
+{
+   __be16 tx_data;
+   struct spi_message *msg = >spi_msg1;
+   struct spi_transfer *transfer = >spi_xfer1;
+   int ret;
+
+   tx_data = cpu_to_be16(cmd);
+   transfer->len = sizeof(tx_data);
+   transfer->tx_buf = _data;
+   transfer->rx_buf = NULL;
+
+   ret = spi_sync(qca->spi_dev, msg);
+
+   if (!ret)
+   ret = msg->status;
+
+   if (ret)
+   qcaspi_spi_error(qca);
+
+   return ret;
+}
+
+static int
 qcaspi_tx_frame(struct qcaspi *qca, struct sk_buff *skb)
 {
u32 count;
-- 
2.1.4



[PATCH v8 net-next 01/17] net: qualcomm: qca_7k: clean up header includes

2017-05-29 Thread Stefan Wahren
Currently the includes doesn't reflect the dependencies. So
fix this up by removing all unnecessary entries and add the
necessary ones explicit.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_7k.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_7k.c 
b/drivers/net/ethernet/qualcomm/qca_7k.c
index f0066fb..e9162e1 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k.c
@@ -23,11 +23,9 @@
  *   kernel-based SPI device.
  */
 
-#include 
-#include 
-#include 
+#include 
+#include 
 #include 
-#include 
 
 #include "qca_7k.h"
 
-- 
2.1.4



[PATCH v8 net-next 12/17] net: qualcomm: make qca_7k_common a separate kernel module

2017-05-29 Thread Stefan Wahren
In order to share common functions between QCA7000 SPI and UART protocol
driver the qca_7k_common needs to be a separate kernel module.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/Kconfig |  8 +++-
 drivers/net/ethernet/qualcomm/Makefile|  5 +++--
 drivers/net/ethernet/qualcomm/qca_7k_common.c | 10 ++
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/Kconfig 
b/drivers/net/ethernet/qualcomm/Kconfig
index d7720bf..b4c369d 100644
--- a/drivers/net/ethernet/qualcomm/Kconfig
+++ b/drivers/net/ethernet/qualcomm/Kconfig
@@ -16,7 +16,13 @@ config NET_VENDOR_QUALCOMM
 if NET_VENDOR_QUALCOMM
 
 config QCA7000
-   tristate "Qualcomm Atheros QCA7000 support"
+   tristate
+   help
+ This enables support for the Qualcomm Atheros QCA7000.
+
+config QCA7000_SPI
+   tristate "Qualcomm Atheros QCA7000 SPI support"
+   select QCA7000
depends on SPI_MASTER && OF
---help---
  This SPI protocol driver supports the Qualcomm Atheros QCA7000.
diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index 5e17bf1..65556ca 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -2,7 +2,8 @@
 # Makefile for the Qualcomm network device drivers.
 #
 
-obj-$(CONFIG_QCA7000) += qcaspi.o
-qcaspi-objs := qca_spi.o qca_7k_common.o qca_7k.o qca_debug.o
+obj-$(CONFIG_QCA7000) += qca_7k_common.o
+obj-$(CONFIG_QCA7000_SPI) += qcaspi.o
+qcaspi-objs := qca_7k.o qca_debug.o qca_spi.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_7k_common.c 
b/drivers/net/ethernet/qualcomm/qca_7k_common.c
index 0d3daa9..6b511f0 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k_common.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k_common.c
@@ -21,7 +21,9 @@
  *   by an atheros frame while transmitted over a serial channel;
  */
 
+#include 
 #include 
+#include 
 
 #include "qca_7k_common.h"
 
@@ -46,6 +48,7 @@ qcafrm_create_header(u8 *buf, u16 length)
 
return QCAFRM_HEADER_LEN;
 }
+EXPORT_SYMBOL_GPL(qcafrm_create_header);
 
 u16
 qcafrm_create_footer(u8 *buf)
@@ -57,6 +60,7 @@ qcafrm_create_footer(u8 *buf)
buf[1] = 0x55;
return QCAFRM_FOOTER_LEN;
 }
+EXPORT_SYMBOL_GPL(qcafrm_create_footer);
 
 /*   Gather received bytes and try to extract a full ethernet frame by
  *   following a simple state machine.
@@ -154,3 +158,9 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
 
return ret;
 }
+EXPORT_SYMBOL_GPL(qcafrm_fsm_decode);
+
+MODULE_DESCRIPTION("Qualcomm Atheros QCA7000 common");
+MODULE_AUTHOR("Qualcomm Atheros Communications");
+MODULE_AUTHOR("Stefan Wahren <stefan.wah...@i2se.com>");
+MODULE_LICENSE("Dual BSD/GPL");
-- 
2.1.4



[PATCH v8 net-next 15/17] dt-bindings: slave-device: add current-speed property

2017-05-29 Thread Stefan Wahren
This adds a new DT property to define the current baud rate of the
slave device.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
Reviewed-by: Rob Herring <r...@kernel.org>
---
 Documentation/devicetree/bindings/serial/slave-device.txt | 9 +
 1 file changed, 9 insertions(+)

diff --git a/Documentation/devicetree/bindings/serial/slave-device.txt 
b/Documentation/devicetree/bindings/serial/slave-device.txt
index f660379..40110e0 100644
--- a/Documentation/devicetree/bindings/serial/slave-device.txt
+++ b/Documentation/devicetree/bindings/serial/slave-device.txt
@@ -21,6 +21,15 @@ Optional Properties:
  can support. For example, a particular board has some signal
  quality issue or the host processor can't support higher
  baud rates.
+- current-speed: The current baud rate the device operates at. This 
should
+ only be present in case a driver has no chance to know
+ the baud rate of the slave device.
+ Examples:
+   * device supports auto-baud
+   * the rate is setup by a bootloader and there is no
+ way to reset the device
+   * device baud rate is configured by its firmware but
+ there is no way to request the actual settings
 
 Example:
 
-- 
2.1.4



[PATCH v8 net-next 13/17] dt-bindings: qca7000-spi: Rework binding

2017-05-29 Thread Stefan Wahren
In preparation for the QCA7000 UART binding rework the binding document.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 .../devicetree/bindings/net/qca-qca7000-spi.txt| 49 +-
 1 file changed, 29 insertions(+), 20 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/qca-qca7000-spi.txt 
b/Documentation/devicetree/bindings/net/qca-qca7000-spi.txt
index c74989c..a37f656 100644
--- a/Documentation/devicetree/bindings/net/qca-qca7000-spi.txt
+++ b/Documentation/devicetree/bindings/net/qca-qca7000-spi.txt
@@ -1,29 +1,38 @@
-* Qualcomm QCA7000 (Ethernet over SPI protocol)
+* Qualcomm QCA7000
 
-Note: The QCA7000 is useable as a SPI device. In this case it must be defined
-as a child of a SPI master in the device tree.
+The QCA7000 is a serial-to-powerline bridge with a host interface which could
+be configured either as SPI or UART slave. This configuration is done by
+the QCA7000 firmware.
+
+(a) Ethernet over SPI
+
+In order to use the QCA7000 as SPI device it must be defined as a child of a
+SPI master in the device tree.
 
 Required properties:
-- compatible : Should be "qca,qca7000"
-- reg : Should specify the SPI chip select
-- interrupts : The first cell should specify the index of the source interrupt
-  and the second cell should specify the trigger type as rising edge
-- spi-cpha : Must be set
-- spi-cpol: Must be set
+- compatible   : Should be "qca,qca7000"
+- reg  : Should specify the SPI chip select
+- interrupts   : The first cell should specify the index of the source
+ interrupt and the second cell should specify the trigger
+ type as rising edge
+- spi-cpha : Must be set
+- spi-cpol : Must be set
 
 Optional properties:
-- interrupt-parent : Specify the pHandle of the source interrupt
+- interrupt-parent  : Specify the pHandle of the source interrupt
 - spi-max-frequency : Maximum frequency of the SPI bus the chip can operate at.
-  Numbers smaller than 100 or greater than 1600 are invalid. Missing
-  the property will set the SPI frequency to 800 Hertz.
-- local-mac-address: 6 bytes, MAC address
-- qca,legacy-mode : Set the SPI data transfer of the QCA7000 to legacy mode.
-  In this mode the SPI master must toggle the chip select between each data
-  word. In burst mode these gaps aren't necessary, which is faster.
-  This setting depends on how the QCA7000 is setup via GPIO pin strapping.
-  If the property is missing the driver defaults to burst mode.
-
-Example:
+ Numbers smaller than 100 or greater than 1600
+ are invalid. Missing the property will set the SPI
+ frequency to 800 Hertz.
+- local-mac-address : see ./ethernet.txt
+- qca,legacy-mode   : Set the SPI data transfer of the QCA7000 to legacy mode.
+ In this mode the SPI master must toggle the chip select
+ between each data word. In burst mode these gaps aren't
+ necessary, which is faster. This setting depends on how
+ the QCA7000 is setup via GPIO pin strapping. If the
+ property is missing the driver defaults to burst mode.
+
+SPI Example:
 
 /* Freescale i.MX28 SPI master*/
 ssp2: spi@80014000 {
-- 
2.1.4



[PATCH v8 net-next 10/17] net: qualcomm: rename qca_framing.c to qca_7k_common.c

2017-05-29 Thread Stefan Wahren
As preparation for the upcoming UART driver we need a module
which contains common functions for both interfaces. The module
qca_framing is a good candidate but renaming to qca_7k_common would
make it clear.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/Makefile   | 2 +-
 drivers/net/ethernet/qualcomm/{qca_framing.c => qca_7k_common.c} | 2 +-
 drivers/net/ethernet/qualcomm/{qca_framing.h => qca_7k_common.h} | 0
 drivers/net/ethernet/qualcomm/qca_spi.c  | 2 +-
 drivers/net/ethernet/qualcomm/qca_spi.h  | 2 +-
 5 files changed, 4 insertions(+), 4 deletions(-)
 rename drivers/net/ethernet/qualcomm/{qca_framing.c => qca_7k_common.c} (99%)
 rename drivers/net/ethernet/qualcomm/{qca_framing.h => qca_7k_common.h} (100%)

diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index aacb0a5..5e17bf1 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -3,6 +3,6 @@
 #
 
 obj-$(CONFIG_QCA7000) += qcaspi.o
-qcaspi-objs := qca_spi.o qca_framing.o qca_7k.o qca_debug.o
+qcaspi-objs := qca_spi.o qca_7k_common.o qca_7k.o qca_debug.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_framing.c 
b/drivers/net/ethernet/qualcomm/qca_7k_common.c
similarity index 99%
rename from drivers/net/ethernet/qualcomm/qca_framing.c
rename to drivers/net/ethernet/qualcomm/qca_7k_common.c
index 2341f2b..6d17fbd 100644
--- a/drivers/net/ethernet/qualcomm/qca_framing.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k_common.c
@@ -23,7 +23,7 @@
 
 #include 
 
-#include "qca_framing.h"
+#include "qca_7k_common.h"
 
 u16
 qcafrm_create_header(u8 *buf, u16 length)
diff --git a/drivers/net/ethernet/qualcomm/qca_framing.h 
b/drivers/net/ethernet/qualcomm/qca_7k_common.h
similarity index 100%
rename from drivers/net/ethernet/qualcomm/qca_framing.h
rename to drivers/net/ethernet/qualcomm/qca_7k_common.h
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index ee90af3..43cc7de 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -43,8 +43,8 @@
 #include 
 
 #include "qca_7k.h"
+#include "qca_7k_common.h"
 #include "qca_debug.h"
-#include "qca_framing.h"
 #include "qca_spi.h"
 
 #define MAX_DMA_BURST_LEN 5000
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.h 
b/drivers/net/ethernet/qualcomm/qca_spi.h
index 064853d..fc4beb1 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.h
+++ b/drivers/net/ethernet/qualcomm/qca_spi.h
@@ -32,7 +32,7 @@
 #include 
 #include 
 
-#include "qca_framing.h"
+#include "qca_7k_common.h"
 
 #define QCASPI_DRV_VERSION "0.2.7-i"
 #define QCASPI_DRV_NAME"qcaspi"
-- 
2.1.4



[PATCH v8 net-next 03/17] net: qca_7k: Use BIT macro

2017-05-29 Thread Stefan Wahren
Use the BIT macro for the CONFIG and INT register values.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_7k.h | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_7k.h 
b/drivers/net/ethernet/qualcomm/qca_7k.h
index 1cad851..4047f0a 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.h
+++ b/drivers/net/ethernet/qualcomm/qca_7k.h
@@ -54,15 +54,15 @@
 #define SPI_REG_ACTION_CTRL 0x1B00
 
 /*   SPI_CONFIG register definition; */
-#define QCASPI_SLAVE_RESET_BIT (1 << 6)
+#define QCASPI_SLAVE_RESET_BIT  BIT(6)
 
 /*   INTR_CAUSE/ENABLE register definition.  */
-#define SPI_INT_WRBUF_BELOW_WM (1 << 10)
-#define SPI_INT_CPU_ON (1 << 6)
-#define SPI_INT_ADDR_ERR   (1 << 3)
-#define SPI_INT_WRBUF_ERR  (1 << 2)
-#define SPI_INT_RDBUF_ERR  (1 << 1)
-#define SPI_INT_PKT_AVLBL  (1 << 0)
+#define SPI_INT_WRBUF_BELOW_WM  BIT(10)
+#define SPI_INT_CPU_ON  BIT(6)
+#define SPI_INT_ADDR_ERRBIT(3)
+#define SPI_INT_WRBUF_ERR   BIT(2)
+#define SPI_INT_RDBUF_ERR   BIT(1)
+#define SPI_INT_PKT_AVLBL   BIT(0)
 
 void qcaspi_spi_error(struct qcaspi *qca);
 int qcaspi_read_register(struct qcaspi *qca, u16 reg, u16 *result);
-- 
2.1.4



[PATCH v8 net-next 00/17] net: qualcomm: add QCA7000 UART driver

2017-05-29 Thread Stefan Wahren
The Qualcomm QCA7000 HomePlug GreenPHY supports two interfaces:
UART and SPI. This patch series adds the missing support for UART.

This driver based on the Qualcomm code [1], but contains some changes:
* use random MAC address per default
* use net_device_stats from device
* share frame decoding between SPI and UART driver
* improve error handling
* reimplement tty_wakeup with work queue (based on slcan)
* use new serial device bus instead of ldisc

The patches 1 - 3 are just for clean up and are not related to
the UART support. Patch 4 adds SET_NETDEV_DEV() to qca_spi.
Patches 5 - 16 prepare the existing QCA7000 code for UART support.
The last patch contains the new driver.

The code itself has been tested on a Freescale i.MX28 board and
a Raspberry Pi Zero.

Changes in v8:
  * add necessary header includes to qca_7k.c in order to reflect
dependencies

Changes in v7:
  * fix race between tx workqueue and device deregistration (reported by Lino)

Changes in v6:
  * rebase to current linux-next
  * use SET_NETDEV_DEV() for qca_spi and qca_uart
  * rename binding to qca,qca7000.txt
  * use qca,qca7000 compatible for both driver
  * handle error cases in qca_uart_probe properly
  * fix skb leak in error path of qcauart_netdev_init
  * use dev_kfree_skb_any instead of kfree_skb
  * take care of tx_work on close / remove
  * use devm_kmalloc for tx buffer
  * minor cleanups

Changes in v5:
  * rebase to current linux-next
  * fix alignment issues in rx path
  * fix buffer overrun with big ethernet frames
  * fix init of UART decoding fsm
  * add device UART settings to Kconfig help
  * add current-speed to slave-device binding
  * merge SPI and UART binding document
  * rename qca_common to qca_7k_common
  * drop patch for retrieving UART settings
  * several cleanups

Changes in v4:
  * rebase to current linux-next
  * use parameter -M for git format-patch
  * change order of local variables where possible
  * implement basic serdev support (without hardware flow control)

Changes in v3:
  * rebase to current net-next

Changes in v2:
  * fix build issue by using netif_trans_update() and dev_trans_start()

[1] - https://github.com/IoE/qca7000

Stefan Wahren (17):
  net: qualcomm: qca_7k: clean up header includes
  net: qca_framing: use u16 for frame offset
  net: qca_7k: Use BIT macro
  net: qca_spi: Use SET_NETDEV_DEV()
  net: qualcomm: use net_device_ops instead of direct call
  net: qualcomm: Improve readability of length defines
  net: qca_spi: remove QCASPI_MTU
  net: qualcomm: move qcaspi_tx_cmd to qca_spi.c
  net: qca_spi: Clarify MODULE_DESCRIPTION
  net: qualcomm: rename qca_framing.c to qca_7k_common.c
  net: qualcomm: prepare frame decoding for UART driver
  net: qualcomm: make qca_7k_common a separate kernel module
  dt-bindings: qca7000-spi: Rework binding
  dt-bindings: qca7000: rename binding
  dt-bindings: slave-device: add current-speed property
  dt-bindings: qca7000: append UART interface to binding
  net: qualcomm: add QCA7000 UART driver

 .../devicetree/bindings/net/qca,qca7000.txt|  88 +
 .../devicetree/bindings/net/qca-qca7000-spi.txt|  47 ---
 .../devicetree/bindings/serial/slave-device.txt|   9 +
 drivers/net/ethernet/qualcomm/Kconfig  |  24 +-
 drivers/net/ethernet/qualcomm/Makefile |   7 +-
 drivers/net/ethernet/qualcomm/qca_7k.c |  30 +-
 drivers/net/ethernet/qualcomm/qca_7k.h |  15 +-
 .../qualcomm/{qca_framing.c => qca_7k_common.c}|  26 +-
 .../qualcomm/{qca_framing.h => qca_7k_common.h}|  24 +-
 drivers/net/ethernet/qualcomm/qca_debug.c  |   5 +-
 drivers/net/ethernet/qualcomm/qca_spi.c|  48 ++-
 drivers/net/ethernet/qualcomm/qca_spi.h|   5 +-
 drivers/net/ethernet/qualcomm/qca_uart.c   | 423 +
 13 files changed, 632 insertions(+), 119 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/qca,qca7000.txt
 delete mode 100644 Documentation/devicetree/bindings/net/qca-qca7000-spi.txt
 rename drivers/net/ethernet/qualcomm/{qca_framing.c => qca_7k_common.c} (85%)
 rename drivers/net/ethernet/qualcomm/{qca_framing.h => qca_7k_common.h} (86%)
 create mode 100644 drivers/net/ethernet/qualcomm/qca_uart.c

-- 
2.1.4



[PATCH v8 net-next 11/17] net: qualcomm: prepare frame decoding for UART driver

2017-05-29 Thread Stefan Wahren
Unfortunately the frame format is not exactly identical between SPI
and UART. In case of SPI there is an additional HW length at the
beginning. So store the initial state to make the decoding state machine
more flexible and easy to extend for UART support.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_7k_common.c | 12 ++--
 drivers/net/ethernet/qualcomm/qca_7k_common.h |  8 ++--
 drivers/net/ethernet/qualcomm/qca_spi.c   |  2 +-
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_7k_common.c 
b/drivers/net/ethernet/qualcomm/qca_7k_common.c
index 6d17fbd..0d3daa9 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k_common.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k_common.c
@@ -83,7 +83,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 
buf_len, u8 recv_by
 
if (recv_byte != 0x00) {
/* first two bytes of length must be 0 */
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
}
break;
case QCAFRM_HW_LEN2:
@@ -97,7 +97,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 
buf_len, u8 recv_by
case QCAFRM_WAIT_AA4:
if (recv_byte != 0xAA) {
ret = QCAFRM_NOHEAD;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state--;
}
@@ -119,7 +119,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
len = handle->offset;
if (len > buf_len || len < QCAFRM_MIN_LEN) {
ret = QCAFRM_INVLEN;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state = (enum qcafrm_state)(len + 1);
/* Remaining number of bytes. */
@@ -135,7 +135,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
case QCAFRM_WAIT_551:
if (recv_byte != 0x55) {
ret = QCAFRM_NOTAIL;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state = QCAFRM_WAIT_552;
}
@@ -143,11 +143,11 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
case QCAFRM_WAIT_552:
if (recv_byte != 0x55) {
ret = QCAFRM_NOTAIL;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
ret = handle->offset;
/* Frame is fully received. */
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
}
break;
}
diff --git a/drivers/net/ethernet/qualcomm/qca_7k_common.h 
b/drivers/net/ethernet/qualcomm/qca_7k_common.h
index 5df7c65..07bdd6c 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k_common.h
+++ b/drivers/net/ethernet/qualcomm/qca_7k_common.h
@@ -61,6 +61,7 @@
 #define QCAFRM_ERR_BASE -1000
 
 enum qcafrm_state {
+   /* HW length is only available on SPI */
QCAFRM_HW_LEN0 = 0x8000,
QCAFRM_HW_LEN1 = QCAFRM_HW_LEN0 - 1,
QCAFRM_HW_LEN2 = QCAFRM_HW_LEN1 - 1,
@@ -101,6 +102,8 @@ enum qcafrm_state {
 struct qcafrm_handle {
/*  Current decoding state */
enum qcafrm_state state;
+   /* Initial state depends on connection type */
+   enum qcafrm_state init;
 
/* Offset in buffer (borrowed for length too) */
u16 offset;
@@ -113,9 +116,10 @@ u16 qcafrm_create_header(u8 *buf, u16 len);
 
 u16 qcafrm_create_footer(u8 *buf);
 
-static inline void qcafrm_fsm_init(struct qcafrm_handle *handle)
+static inline void qcafrm_fsm_init_spi(struct qcafrm_handle *handle)
 {
-   handle->state = QCAFRM_HW_LEN0;
+   handle->init = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
 }
 
 /*   Gather received bytes and try to extract a full Ethernet frame
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 43cc7de..de78f60 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -638,7 +638,7 @@ qcaspi_netdev_open(struct net_device *dev)
qca->intr_req = 1;
qca->intr_svc = 0;
qca->sync = QCASPI_SYNC_UNKNOWN;
-   qcafrm_fsm_init(>frm_handle);
+   qcafrm_fsm_init_spi(>frm_handle);
 
qca->spi_thread = kthread_run((void *)qcaspi_spi_thread,
  qca, "%s", dev->name);
-- 
2.1.4



[PATCH v8 net-next 16/17] dt-bindings: qca7000: append UART interface to binding

2017-05-29 Thread Stefan Wahren
This merges the serdev binding for the QCA7000 UART driver (Ethernet over
UART) into the existing document.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 .../devicetree/bindings/net/qca,qca7000.txt| 32 ++
 1 file changed, 32 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/qca,qca7000.txt 
b/Documentation/devicetree/bindings/net/qca,qca7000.txt
index a37f656..6d9efb2 100644
--- a/Documentation/devicetree/bindings/net/qca,qca7000.txt
+++ b/Documentation/devicetree/bindings/net/qca,qca7000.txt
@@ -54,3 +54,35 @@ ssp2: spi@80014000 {
local-mac-address = [ A0 B0 C0 D0 E0 F0 ];
};
 };
+
+(b) Ethernet over UART
+
+In order to use the QCA7000 as UART slave it must be defined as a child of a
+UART master in the device tree. It is possible to preconfigure the UART
+settings of the QCA7000 firmware, but it's not possible to change them during
+runtime.
+
+Required properties:
+- compatible: Should be "qca,qca7000"
+
+Optional properties:
+- local-mac-address : see ./ethernet.txt
+- current-speed : current baud rate of QCA7000 which defaults to 115200
+ if absent, see also ../serial/slave-device.txt
+
+UART Example:
+
+/* Freescale i.MX28 UART */
+auart0: serial@8006a000 {
+   compatible = "fsl,imx28-auart", "fsl,imx23-auart";
+   reg = <0x8006a000 0x2000>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_2pins_a>;
+   status = "okay";
+
+   qca7000: ethernet {
+   compatible = "qca,qca7000";
+   local-mac-address = [ A0 B0 C0 D0 E0 F0 ];
+   current-speed = <38400>;
+   };
+};
-- 
2.1.4



[PATCH v8 net-next 02/17] net: qca_framing: use u16 for frame offset

2017-05-29 Thread Stefan Wahren
It doesn't make sense to use a signed variable for offset here, so
fix it up.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_framing.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_framing.h 
b/drivers/net/ethernet/qualcomm/qca_framing.h
index d5e795d..8b385e6 100644
--- a/drivers/net/ethernet/qualcomm/qca_framing.h
+++ b/drivers/net/ethernet/qualcomm/qca_framing.h
@@ -103,7 +103,7 @@ struct qcafrm_handle {
enum qcafrm_state state;
 
/* Offset in buffer (borrowed for length too) */
-   s16 offset;
+   u16 offset;
 
/* Frame length as kept by this module */
u16 len;
-- 
2.1.4



[PATCH v8 net-next 14/17] dt-bindings: qca7000: rename binding

2017-05-29 Thread Stefan Wahren
Before we can merge the QCA7000 UART binding the document needs to be
renamed.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 .../devicetree/bindings/net/{qca-qca7000-spi.txt => qca,qca7000.txt}  | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename Documentation/devicetree/bindings/net/{qca-qca7000-spi.txt => 
qca,qca7000.txt} (100%)

diff --git a/Documentation/devicetree/bindings/net/qca-qca7000-spi.txt 
b/Documentation/devicetree/bindings/net/qca,qca7000.txt
similarity index 100%
rename from Documentation/devicetree/bindings/net/qca-qca7000-spi.txt
rename to Documentation/devicetree/bindings/net/qca,qca7000.txt
-- 
2.1.4



[PATCH v8 net-next 17/17] net: qualcomm: add QCA7000 UART driver

2017-05-29 Thread Stefan Wahren
This patch adds the Ethernet over UART driver for the
Qualcomm QCA7000 HomePlug GreenPHY.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
Reviewed-by: Lino Sanfilippo <linosanfili...@gmx.de>
---
 drivers/net/ethernet/qualcomm/Kconfig |  16 +
 drivers/net/ethernet/qualcomm/Makefile|   2 +
 drivers/net/ethernet/qualcomm/qca_7k_common.h |   6 +
 drivers/net/ethernet/qualcomm/qca_uart.c  | 423 ++
 4 files changed, 447 insertions(+)
 create mode 100644 drivers/net/ethernet/qualcomm/qca_uart.c

diff --git a/drivers/net/ethernet/qualcomm/Kconfig 
b/drivers/net/ethernet/qualcomm/Kconfig
index b4c369d..877675a 100644
--- a/drivers/net/ethernet/qualcomm/Kconfig
+++ b/drivers/net/ethernet/qualcomm/Kconfig
@@ -30,6 +30,22 @@ config QCA7000_SPI
  To compile this driver as a module, choose M here. The module
  will be called qcaspi.
 
+config QCA7000_UART
+   tristate "Qualcomm Atheros QCA7000 UART support"
+   select QCA7000
+   depends on SERIAL_DEV_BUS && OF
+   ---help---
+ This UART protocol driver supports the Qualcomm Atheros QCA7000.
+
+ Currently the driver assumes these device UART settings:
+   Data bits: 8
+   Parity: None
+   Stop bits: 1
+   Flow control: None
+
+ To compile this driver as a module, choose M here. The module
+ will be called qcauart.
+
 config QCOM_EMAC
tristate "Qualcomm Technologies, Inc. EMAC Gigabit Ethernet support"
depends on HAS_DMA && HAS_IOMEM
diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index 65556ca..92fa7c4 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -5,5 +5,7 @@
 obj-$(CONFIG_QCA7000) += qca_7k_common.o
 obj-$(CONFIG_QCA7000_SPI) += qcaspi.o
 qcaspi-objs := qca_7k.o qca_debug.o qca_spi.o
+obj-$(CONFIG_QCA7000_UART) += qcauart.o
+qcauart-objs := qca_uart.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_7k_common.h 
b/drivers/net/ethernet/qualcomm/qca_7k_common.h
index 07bdd6c..928554f 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k_common.h
+++ b/drivers/net/ethernet/qualcomm/qca_7k_common.h
@@ -122,6 +122,12 @@ static inline void qcafrm_fsm_init_spi(struct 
qcafrm_handle *handle)
handle->state = handle->init;
 }
 
+static inline void qcafrm_fsm_init_uart(struct qcafrm_handle *handle)
+{
+   handle->init = QCAFRM_WAIT_AA1;
+   handle->state = handle->init;
+}
+
 /*   Gather received bytes and try to extract a full Ethernet frame
  *   by following a simple state machine.
  *
diff --git a/drivers/net/ethernet/qualcomm/qca_uart.c 
b/drivers/net/ethernet/qualcomm/qca_uart.c
new file mode 100644
index 000..db6068c
--- /dev/null
+++ b/drivers/net/ethernet/qualcomm/qca_uart.c
@@ -0,0 +1,423 @@
+/*
+ *   Copyright (c) 2011, 2012, Qualcomm Atheros Communications Inc.
+ *   Copyright (c) 2017, I2SE GmbH
+ *
+ *   Permission to use, copy, modify, and/or distribute this software
+ *   for any purpose with or without fee is hereby granted, provided
+ *   that the above copyright notice and this permission notice appear
+ *   in all copies.
+ *
+ *   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ *   WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ *   WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ *   THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
+ *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ *   LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ *   NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ *   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*   This module implements the Qualcomm Atheros UART protocol for
+ *   kernel-based UART device; it is essentially an Ethernet-to-UART
+ *   serial converter;
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "qca_7k_common.h"
+
+#define QCAUART_DRV_VERSION "0.1.0"
+#define QCAUART_DRV_NAME "qcauart"
+#define QCAUART_TX_TIMEOUT (1 * HZ)
+
+struct qcauart {
+   struct net_device *net_dev;
+   spinlock_t lock;/* transmit lock */
+   struct work_struct tx_work; /* Flushes transmit buffer   */
+
+   struct serdev_device *serdev;
+   struct qcafrm_handle frm_handle;
+   struct sk_buff *rx_skb;
+
+   unsigned char *tx_head; /* pointer to next XMIT byte */
+   int tx_left;/* bytes left in XMIT queue  */
+   unsigned char *tx_buffer;
+};
+
+static int
+qca_tty_receive(struct serdev_device *serdev, const unsigned char *data,
+   size_t count)
+{
+

[PATCH v8 net-next 09/17] net: qca_spi: Clarify MODULE_DESCRIPTION

2017-05-29 Thread Stefan Wahren
Since this driver is specific to the QCA7000, we should make the module
description more precisely.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 50adc4f..ee90af3 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -999,7 +999,7 @@ static struct spi_driver qca_spi_driver = {
 };
 module_spi_driver(qca_spi_driver);
 
-MODULE_DESCRIPTION("Qualcomm Atheros SPI Driver");
+MODULE_DESCRIPTION("Qualcomm Atheros QCA7000 SPI Driver");
 MODULE_AUTHOR("Qualcomm Atheros Communications");
 MODULE_AUTHOR("Stefan Wahren <stefan.wah...@i2se.com>");
 MODULE_LICENSE("Dual BSD/GPL");
-- 
2.1.4



[PATCH v8 net-next 06/17] net: qualcomm: Improve readability of length defines

2017-05-29 Thread Stefan Wahren
In order to avoid mixing things up, make the MTU and frame length
defines easier to read.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_framing.c |  2 +-
 drivers/net/ethernet/qualcomm/qca_framing.h |  8 
 drivers/net/ethernet/qualcomm/qca_spi.c | 12 ++--
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_framing.c 
b/drivers/net/ethernet/qualcomm/qca_framing.c
index faa924c..2341f2b 100644
--- a/drivers/net/ethernet/qualcomm/qca_framing.c
+++ b/drivers/net/ethernet/qualcomm/qca_framing.c
@@ -117,7 +117,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
break;
case QCAFRM_WAIT_RSVD_BYTE2:
len = handle->offset;
-   if (len > buf_len || len < QCAFRM_ETHMINLEN) {
+   if (len > buf_len || len < QCAFRM_MIN_LEN) {
ret = QCAFRM_INVLEN;
handle->state = QCAFRM_HW_LEN0;
} else {
diff --git a/drivers/net/ethernet/qualcomm/qca_framing.h 
b/drivers/net/ethernet/qualcomm/qca_framing.h
index 8b385e6..5df7c65 100644
--- a/drivers/net/ethernet/qualcomm/qca_framing.h
+++ b/drivers/net/ethernet/qualcomm/qca_framing.h
@@ -44,12 +44,12 @@
 #define QCAFRM_INVFRAME (QCAFRM_ERR_BASE - 4)
 
 /* Min/Max Ethernet MTU: 46/1500 */
-#define QCAFRM_ETHMINMTU (ETH_ZLEN - ETH_HLEN)
-#define QCAFRM_ETHMAXMTU ETH_DATA_LEN
+#define QCAFRM_MIN_MTU (ETH_ZLEN - ETH_HLEN)
+#define QCAFRM_MAX_MTU ETH_DATA_LEN
 
 /* Min/Max frame lengths */
-#define QCAFRM_ETHMINLEN (QCAFRM_ETHMINMTU + ETH_HLEN)
-#define QCAFRM_ETHMAXLEN (QCAFRM_ETHMAXMTU + VLAN_ETH_HLEN)
+#define QCAFRM_MIN_LEN (QCAFRM_MIN_MTU + ETH_HLEN)
+#define QCAFRM_MAX_LEN (QCAFRM_MAX_MTU + VLAN_ETH_HLEN)
 
 /* QCA7K header len */
 #define QCAFRM_HEADER_LEN 8
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 7e039e3..f155548 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -69,7 +69,7 @@ static int qcaspi_pluggable = QCASPI_PLUGGABLE_MIN;
 module_param(qcaspi_pluggable, int, 0);
 MODULE_PARM_DESC(qcaspi_pluggable, "Pluggable SPI connection (yes/no).");
 
-#define QCASPI_MTU QCAFRM_ETHMAXMTU
+#define QCASPI_MTU QCAFRM_MAX_MTU
 #define QCASPI_TX_TIMEOUT (1 * HZ)
 #define QCASPI_QCA7K_REBOOT_TIME_MS 1000
 
@@ -403,7 +403,7 @@ qcaspi_tx_ring_has_space(struct tx_ring *txr)
if (txr->skb[txr->tail])
return 0;
 
-   return (txr->size + QCAFRM_ETHMAXLEN < QCASPI_HW_BUF_LEN) ? 1 : 0;
+   return (txr->size + QCAFRM_MAX_LEN < QCASPI_HW_BUF_LEN) ? 1 : 0;
 }
 
 /*   Flush the tx ring. This function is only safe to
@@ -667,8 +667,8 @@ qcaspi_netdev_xmit(struct sk_buff *skb, struct net_device 
*dev)
struct sk_buff *tskb;
u8 pad_len = 0;
 
-   if (skb->len < QCAFRM_ETHMINLEN)
-   pad_len = QCAFRM_ETHMINLEN - skb->len;
+   if (skb->len < QCAFRM_MIN_LEN)
+   pad_len = QCAFRM_MIN_LEN - skb->len;
 
if (qca->txr.skb[qca->txr.tail]) {
netdev_warn(qca->net_dev, "queue was unexpectedly full!\n");
@@ -805,8 +805,8 @@ qcaspi_netdev_setup(struct net_device *dev)
dev->tx_queue_len = 100;
 
/* MTU range: 46 - 1500 */
-   dev->min_mtu = QCAFRM_ETHMINMTU;
-   dev->max_mtu = QCAFRM_ETHMAXMTU;
+   dev->min_mtu = QCAFRM_MIN_MTU;
+   dev->max_mtu = QCAFRM_MAX_MTU;
 
qca = netdev_priv(dev);
memset(qca, 0, sizeof(struct qcaspi));
-- 
2.1.4



[PATCH v8 net-next 04/17] net: qca_spi: Use SET_NETDEV_DEV()

2017-05-29 Thread Stefan Wahren
Use SET_NETDEV_DEV() in qca_spi to create the "/sys/class/net//device"
symlink.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_spi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 24ca7df..0c3fdee 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -894,6 +894,7 @@ qca_spi_probe(struct spi_device *spi)
return -ENOMEM;
 
qcaspi_netdev_setup(qcaspi_devs);
+   SET_NETDEV_DEV(qcaspi_devs, >dev);
 
qca = netdev_priv(qcaspi_devs);
if (!qca) {
-- 
2.1.4



[PATCH v8 net-next 05/17] net: qualcomm: use net_device_ops instead of direct call

2017-05-29 Thread Stefan Wahren
There is no need to export qcaspi_netdev_open and qcaspi_netdev_close
because they are also accessible via the net_device_ops.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_debug.c | 5 +++--
 drivers/net/ethernet/qualcomm/qca_spi.c   | 4 ++--
 drivers/net/ethernet/qualcomm/qca_spi.h   | 3 ---
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_debug.c 
b/drivers/net/ethernet/qualcomm/qca_debug.c
index d145df9..92b6be9 100644
--- a/drivers/net/ethernet/qualcomm/qca_debug.c
+++ b/drivers/net/ethernet/qualcomm/qca_debug.c
@@ -275,6 +275,7 @@ qcaspi_get_ringparam(struct net_device *dev, struct 
ethtool_ringparam *ring)
 static int
 qcaspi_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
 {
+   const struct net_device_ops *ops = dev->netdev_ops;
struct qcaspi *qca = netdev_priv(dev);
 
if ((ring->rx_pending) ||
@@ -283,13 +284,13 @@ qcaspi_set_ringparam(struct net_device *dev, struct 
ethtool_ringparam *ring)
return -EINVAL;
 
if (netif_running(dev))
-   qcaspi_netdev_close(dev);
+   ops->ndo_stop(dev);
 
qca->txr.count = max_t(u32, ring->tx_pending, TX_RING_MIN_LEN);
qca->txr.count = min_t(u16, qca->txr.count, TX_RING_MAX_LEN);
 
if (netif_running(dev))
-   qcaspi_netdev_open(dev);
+   ops->ndo_open(dev);
 
return 0;
 }
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 0c3fdee..7e039e3 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -603,7 +603,7 @@ qcaspi_intr_handler(int irq, void *data)
return IRQ_HANDLED;
 }
 
-int
+static int
 qcaspi_netdev_open(struct net_device *dev)
 {
struct qcaspi *qca = netdev_priv(dev);
@@ -640,7 +640,7 @@ qcaspi_netdev_open(struct net_device *dev)
return 0;
 }
 
-int
+static int
 qcaspi_netdev_close(struct net_device *dev)
 {
struct qcaspi *qca = netdev_priv(dev);
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.h 
b/drivers/net/ethernet/qualcomm/qca_spi.h
index 6e31a0e..064853d 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.h
+++ b/drivers/net/ethernet/qualcomm/qca_spi.h
@@ -108,7 +108,4 @@ struct qcaspi {
u16 burst_len;
 };
 
-int qcaspi_netdev_open(struct net_device *dev);
-int qcaspi_netdev_close(struct net_device *dev);
-
 #endif /* _QCA_SPI_H */
-- 
2.1.4



Re: [PATCH v6 net-next 01/17] net: qualcomm: remove unnecessary includes

2017-05-24 Thread Stefan Wahren

> David Miller <da...@davemloft.net> hat am 24. Mai 2017 um 21:41 geschrieben:
> 
> 
> From: Stefan Wahren <stefan.wah...@i2se.com>
> Date: Tue, 23 May 2017 15:12:37 +0200
> 
> > Most of the includes in qca_7k.c are unnecessary so we better remove them.
> > 
> > Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
> > ---
> >  drivers/net/ethernet/qualcomm/qca_7k.c | 4 
> >  1 file changed, 4 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/qualcomm/qca_7k.c 
> > b/drivers/net/ethernet/qualcomm/qca_7k.c
> > index f0066fb..557d53c 100644
> > --- a/drivers/net/ethernet/qualcomm/qca_7k.c
> > +++ b/drivers/net/ethernet/qualcomm/qca_7k.c
> > @@ -23,11 +23,7 @@
> >   *   kernel-based SPI device.
> >   */
> >  
> > -#include 
> > -#include 
> > -#include 
> >  #include 
> > -#include 
> >  
> >  #include "qca_7k.h"
> >  
> > -- 
> > 2.1.4
> > 
> 
> Changes like this drive me crazy.
> 
> The only reason you can remove those headers is because you are obtaining
> things indirectly via qca_7k.h
> 
> And if that is indeed the case, you are also getting qca_spi.h which
> in turn includes linux/spi/spi.h
> 
> So you could have removed that as well.
> 
> But seriously, it is so much harder to understand a driver and what
> interfaces it needs via header files when you hide _all_ of it behind
> these local private header files which just include _everything_
> and then _every_ foo.c file in your driver gets _all_ of those kernel
> headers whether they need it or not.
> 
> So if just one foo.c file needs 20 extra kernel headers than the rest
> of the files in the driver, every foo.c file eats that cost of
> including them.
> 
> I really don't like when drivers move in this direction for that
> reason.  And at best, as described at the beginning of my response,
> this change is incomplete.
>

The intension of this change wasn't to hide the includes into qca_7k.h

AFAIK these ones above aren't necessary (no init, no kernel module, no kernel 
parameter, no kernel version) for this C file. So i will double check it.


Re: [PATCH RESEND v7 net-next 17/17] net: qualcomm: add QCA7000 UART driver

2017-05-24 Thread Stefan Wahren
Am 24.05.2017 um 16:21 schrieb Lino Sanfilippo:
> Hi,
>
>
>> This patch adds the Ethernet over UART driver for the
>> Qualcomm QCA7000 HomePlug GreenPHY.
>>
>> Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
>> ---
> Reviewed-by: Lino Sanfilippo <linosanfili...@gmx.de>
>

Thanks
Stefan


[PATCH RESEND v7 net-next 17/17] net: qualcomm: add QCA7000 UART driver

2017-05-24 Thread Stefan Wahren
This patch adds the Ethernet over UART driver for the
Qualcomm QCA7000 HomePlug GreenPHY.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/Kconfig |  16 +
 drivers/net/ethernet/qualcomm/Makefile|   2 +
 drivers/net/ethernet/qualcomm/qca_7k_common.h |   6 +
 drivers/net/ethernet/qualcomm/qca_uart.c  | 423 ++
 4 files changed, 447 insertions(+)
 create mode 100644 drivers/net/ethernet/qualcomm/qca_uart.c

Changes in v7:
* fix race between tx workqueue and device deregistration (reported by Lino)

diff --git a/drivers/net/ethernet/qualcomm/Kconfig 
b/drivers/net/ethernet/qualcomm/Kconfig
index b4c369d..877675a 100644
--- a/drivers/net/ethernet/qualcomm/Kconfig
+++ b/drivers/net/ethernet/qualcomm/Kconfig
@@ -30,6 +30,22 @@ config QCA7000_SPI
  To compile this driver as a module, choose M here. The module
  will be called qcaspi.
 
+config QCA7000_UART
+   tristate "Qualcomm Atheros QCA7000 UART support"
+   select QCA7000
+   depends on SERIAL_DEV_BUS && OF
+   ---help---
+ This UART protocol driver supports the Qualcomm Atheros QCA7000.
+
+ Currently the driver assumes these device UART settings:
+   Data bits: 8
+   Parity: None
+   Stop bits: 1
+   Flow control: None
+
+ To compile this driver as a module, choose M here. The module
+ will be called qcauart.
+
 config QCOM_EMAC
tristate "Qualcomm Technologies, Inc. EMAC Gigabit Ethernet support"
depends on HAS_DMA && HAS_IOMEM
diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index 65556ca..92fa7c4 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -5,5 +5,7 @@
 obj-$(CONFIG_QCA7000) += qca_7k_common.o
 obj-$(CONFIG_QCA7000_SPI) += qcaspi.o
 qcaspi-objs := qca_7k.o qca_debug.o qca_spi.o
+obj-$(CONFIG_QCA7000_UART) += qcauart.o
+qcauart-objs := qca_uart.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_7k_common.h 
b/drivers/net/ethernet/qualcomm/qca_7k_common.h
index 07bdd6c..928554f 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k_common.h
+++ b/drivers/net/ethernet/qualcomm/qca_7k_common.h
@@ -122,6 +122,12 @@ static inline void qcafrm_fsm_init_spi(struct 
qcafrm_handle *handle)
handle->state = handle->init;
 }
 
+static inline void qcafrm_fsm_init_uart(struct qcafrm_handle *handle)
+{
+   handle->init = QCAFRM_WAIT_AA1;
+   handle->state = handle->init;
+}
+
 /*   Gather received bytes and try to extract a full Ethernet frame
  *   by following a simple state machine.
  *
diff --git a/drivers/net/ethernet/qualcomm/qca_uart.c 
b/drivers/net/ethernet/qualcomm/qca_uart.c
new file mode 100644
index 000..db6068c
--- /dev/null
+++ b/drivers/net/ethernet/qualcomm/qca_uart.c
@@ -0,0 +1,423 @@
+/*
+ *   Copyright (c) 2011, 2012, Qualcomm Atheros Communications Inc.
+ *   Copyright (c) 2017, I2SE GmbH
+ *
+ *   Permission to use, copy, modify, and/or distribute this software
+ *   for any purpose with or without fee is hereby granted, provided
+ *   that the above copyright notice and this permission notice appear
+ *   in all copies.
+ *
+ *   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ *   WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ *   WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ *   THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
+ *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ *   LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ *   NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ *   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*   This module implements the Qualcomm Atheros UART protocol for
+ *   kernel-based UART device; it is essentially an Ethernet-to-UART
+ *   serial converter;
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "qca_7k_common.h"
+
+#define QCAUART_DRV_VERSION "0.1.0"
+#define QCAUART_DRV_NAME "qcauart"
+#define QCAUART_TX_TIMEOUT (1 * HZ)
+
+struct qcauart {
+   struct net_device *net_dev;
+   spinlock_t lock;/* transmit lock */
+   struct work_struct tx_work; /* Flushes transmit buffer   */
+
+   struct serdev_device *serdev;
+   struct qcafrm_handle frm_handle;
+   struct sk_buff *rx_skb;
+
+   unsigned char *tx_head; /* pointer to next XMIT byte */
+   int tx_left;/* bytes left in XMIT queue  */
+   unsigned char *tx_buffer;
+};
+
+static int
+qca_tty_receive(struct serdev_device *serdev, const unsigned char *data

[PATCH v7 net-next 17/17] net: qualcomm: add QCA7000 UART driver

2017-05-24 Thread Stefan Wahren
This patch adds the Ethernet over UART driver for the
Qualcomm QCA7000 HomePlug GreenPHY.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/Kconfig |  16 +
 drivers/net/ethernet/qualcomm/Makefile|   2 +
 drivers/net/ethernet/qualcomm/qca_7k_common.h |   6 +
 drivers/net/ethernet/qualcomm/qca_uart.c  | 423 ++
 4 files changed, 447 insertions(+)
 create mode 100644 drivers/net/ethernet/qualcomm/qca_uart.c

diff --git a/drivers/net/ethernet/qualcomm/Kconfig 
b/drivers/net/ethernet/qualcomm/Kconfig
index b4c369d..877675a 100644
--- a/drivers/net/ethernet/qualcomm/Kconfig
+++ b/drivers/net/ethernet/qualcomm/Kconfig
@@ -30,6 +30,22 @@ config QCA7000_SPI
  To compile this driver as a module, choose M here. The module
  will be called qcaspi.
 
+config QCA7000_UART
+   tristate "Qualcomm Atheros QCA7000 UART support"
+   select QCA7000
+   depends on SERIAL_DEV_BUS && OF
+   ---help---
+ This UART protocol driver supports the Qualcomm Atheros QCA7000.
+
+ Currently the driver assumes these device UART settings:
+   Data bits: 8
+   Parity: None
+   Stop bits: 1
+   Flow control: None
+
+ To compile this driver as a module, choose M here. The module
+ will be called qcauart.
+
 config QCOM_EMAC
tristate "Qualcomm Technologies, Inc. EMAC Gigabit Ethernet support"
depends on HAS_DMA && HAS_IOMEM
diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index 65556ca..92fa7c4 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -5,5 +5,7 @@
 obj-$(CONFIG_QCA7000) += qca_7k_common.o
 obj-$(CONFIG_QCA7000_SPI) += qcaspi.o
 qcaspi-objs := qca_7k.o qca_debug.o qca_spi.o
+obj-$(CONFIG_QCA7000_UART) += qcauart.o
+qcauart-objs := qca_uart.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_7k_common.h 
b/drivers/net/ethernet/qualcomm/qca_7k_common.h
index 07bdd6c..928554f 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k_common.h
+++ b/drivers/net/ethernet/qualcomm/qca_7k_common.h
@@ -122,6 +122,12 @@ static inline void qcafrm_fsm_init_spi(struct 
qcafrm_handle *handle)
handle->state = handle->init;
 }
 
+static inline void qcafrm_fsm_init_uart(struct qcafrm_handle *handle)
+{
+   handle->init = QCAFRM_WAIT_AA1;
+   handle->state = handle->init;
+}
+
 /*   Gather received bytes and try to extract a full Ethernet frame
  *   by following a simple state machine.
  *
diff --git a/drivers/net/ethernet/qualcomm/qca_uart.c 
b/drivers/net/ethernet/qualcomm/qca_uart.c
new file mode 100644
index 000..db6068c
--- /dev/null
+++ b/drivers/net/ethernet/qualcomm/qca_uart.c
@@ -0,0 +1,423 @@
+/*
+ *   Copyright (c) 2011, 2012, Qualcomm Atheros Communications Inc.
+ *   Copyright (c) 2017, I2SE GmbH
+ *
+ *   Permission to use, copy, modify, and/or distribute this software
+ *   for any purpose with or without fee is hereby granted, provided
+ *   that the above copyright notice and this permission notice appear
+ *   in all copies.
+ *
+ *   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ *   WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ *   WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ *   THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
+ *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ *   LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ *   NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ *   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*   This module implements the Qualcomm Atheros UART protocol for
+ *   kernel-based UART device; it is essentially an Ethernet-to-UART
+ *   serial converter;
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "qca_7k_common.h"
+
+#define QCAUART_DRV_VERSION "0.1.0"
+#define QCAUART_DRV_NAME "qcauart"
+#define QCAUART_TX_TIMEOUT (1 * HZ)
+
+struct qcauart {
+   struct net_device *net_dev;
+   spinlock_t lock;/* transmit lock */
+   struct work_struct tx_work; /* Flushes transmit buffer   */
+
+   struct serdev_device *serdev;
+   struct qcafrm_handle frm_handle;
+   struct sk_buff *rx_skb;
+
+   unsigned char *tx_head; /* pointer to next XMIT byte */
+   int tx_left;/* bytes left in XMIT queue  */
+   unsigned char *tx_buffer;
+};
+
+static int
+qca_tty_receive(struct serdev_device *serdev, const unsigned char *data,
+   size_t count)
+{
+   struct qcauart *qca = serdev_device_get_drvdata(serdev);
+ 

Re: [PATCH v6 net-next 17/17] net: qualcomm: add QCA7000 UART driver

2017-05-24 Thread Stefan Wahren
Am 23.05.2017 um 23:01 schrieb Lino Sanfilippo:
> On 23.05.2017 21:38, Stefan Wahren wrote:
>>> Lino Sanfilippo <linosanfili...@gmx.de> hat am 23. Mai 2017 um 20:16 
>>> geschrieben:
>>>
>>> I suggest to avoid this possible race by first unregistering the netdevice 
>>> and then 
>>> calling cancel_work_sync().
>> What makes you sure that's safe to unregister the netdev while the tx work 
>> queue is possibly active?
> unregister_netdevice() calls netdev_close() if the interface is still up. 
> netdev_close() calls flush_work()
> so the unregistration is delayed until the tx work function is finished. 
> Furthermore both close() and
> tx work are synchronized by means of the qca->lock which also guarantees that 
> unregister_netdevice() wont
> be finished until the tx work is done.
>

Thanks for the explanation. I suspect there could be the same race
between serdev_device_close() and the tx work queue.

So i would propose a variant of your original suggestion:

unregister_netdev(qca->net_dev);

/* Flush any pending characters in the driver. */
serdev_device_close(serdev);
cancel_work_sync(>tx_work);

Since we have the same pattern in the error path of the probe function,
the same applies there.

Stefan


Re: [PATCH v6 net-next 17/17] net: qualcomm: add QCA7000 UART driver

2017-05-23 Thread Stefan Wahren

> Lino Sanfilippo <linosanfili...@gmx.de> hat am 23. Mai 2017 um 20:16 
> geschrieben:
> 
> 
> Hi,
> 
> On 23.05.2017 15:12, Stefan Wahren wrote:
> 
> 
> > +}
> > +
> > +static void qca_uart_remove(struct serdev_device *serdev)
> > +{
> > +   struct qcauart *qca = serdev_device_get_drvdata(serdev);
> > +
> > +   netif_carrier_off(qca->net_dev);
> > +   cancel_work_sync(>tx_work);
> > +   unregister_netdev(qca->net_dev);
> 
> Note that it is still possible that the tx work is queued right after 
> cancel_work_sync()
> returned and before the net device is unregistered (and thus the check for 
> the net device
> being up at the beginning of the tx work function is passed and the function 
> is executed).

Even if the carrier is off? Since i see this pattern in some drivers, can you 
please point me to a reference like a thread or something else?

> I suggest to avoid this possible race by first unregistering the netdevice 
> and then 
> calling cancel_work_sync().

What makes you sure that's safe to unregister the netdev while the tx work 
queue is possibly active?

> Regards,
> Lino 
>


[PATCH v6 net-next 02/17] net: qca_framing: use u16 for frame offset

2017-05-23 Thread Stefan Wahren
It doesn't make sense to use a signed variable for offset here, so
fix it up.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_framing.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_framing.h 
b/drivers/net/ethernet/qualcomm/qca_framing.h
index d5e795d..8b385e6 100644
--- a/drivers/net/ethernet/qualcomm/qca_framing.h
+++ b/drivers/net/ethernet/qualcomm/qca_framing.h
@@ -103,7 +103,7 @@ struct qcafrm_handle {
enum qcafrm_state state;
 
/* Offset in buffer (borrowed for length too) */
-   s16 offset;
+   u16 offset;
 
/* Frame length as kept by this module */
u16 len;
-- 
2.1.4



[PATCH v6 net-next 04/17] net: qca_spi: Use SET_NETDEV_DEV()

2017-05-23 Thread Stefan Wahren
Use SET_NETDEV_DEV() in qca_spi to create the "/sys/class/net//device"
symlink.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_spi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 24ca7df..0c3fdee 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -894,6 +894,7 @@ qca_spi_probe(struct spi_device *spi)
return -ENOMEM;
 
qcaspi_netdev_setup(qcaspi_devs);
+   SET_NETDEV_DEV(qcaspi_devs, >dev);
 
qca = netdev_priv(qcaspi_devs);
if (!qca) {
-- 
2.1.4



[PATCH v6 net-next 03/17] net: qca_7k: Use BIT macro

2017-05-23 Thread Stefan Wahren
Use the BIT macro for the CONFIG and INT register values.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_7k.h | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_7k.h 
b/drivers/net/ethernet/qualcomm/qca_7k.h
index 1cad851..4047f0a 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.h
+++ b/drivers/net/ethernet/qualcomm/qca_7k.h
@@ -54,15 +54,15 @@
 #define SPI_REG_ACTION_CTRL 0x1B00
 
 /*   SPI_CONFIG register definition; */
-#define QCASPI_SLAVE_RESET_BIT (1 << 6)
+#define QCASPI_SLAVE_RESET_BIT  BIT(6)
 
 /*   INTR_CAUSE/ENABLE register definition.  */
-#define SPI_INT_WRBUF_BELOW_WM (1 << 10)
-#define SPI_INT_CPU_ON (1 << 6)
-#define SPI_INT_ADDR_ERR   (1 << 3)
-#define SPI_INT_WRBUF_ERR  (1 << 2)
-#define SPI_INT_RDBUF_ERR  (1 << 1)
-#define SPI_INT_PKT_AVLBL  (1 << 0)
+#define SPI_INT_WRBUF_BELOW_WM  BIT(10)
+#define SPI_INT_CPU_ON  BIT(6)
+#define SPI_INT_ADDR_ERRBIT(3)
+#define SPI_INT_WRBUF_ERR   BIT(2)
+#define SPI_INT_RDBUF_ERR   BIT(1)
+#define SPI_INT_PKT_AVLBL   BIT(0)
 
 void qcaspi_spi_error(struct qcaspi *qca);
 int qcaspi_read_register(struct qcaspi *qca, u16 reg, u16 *result);
-- 
2.1.4



[PATCH v6 net-next 09/17] net: qca_spi: Clarify MODULE_DESCRIPTION

2017-05-23 Thread Stefan Wahren
Since this driver is specific to the QCA7000, we should make the module
description more precisely.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 50adc4f..ee90af3 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -999,7 +999,7 @@ static struct spi_driver qca_spi_driver = {
 };
 module_spi_driver(qca_spi_driver);
 
-MODULE_DESCRIPTION("Qualcomm Atheros SPI Driver");
+MODULE_DESCRIPTION("Qualcomm Atheros QCA7000 SPI Driver");
 MODULE_AUTHOR("Qualcomm Atheros Communications");
 MODULE_AUTHOR("Stefan Wahren <stefan.wah...@i2se.com>");
 MODULE_LICENSE("Dual BSD/GPL");
-- 
2.1.4



[PATCH v6 net-next 12/17] net: qualcomm: make qca_7k_common a separate kernel module

2017-05-23 Thread Stefan Wahren
In order to share common functions between QCA7000 SPI and UART protocol
driver the qca_7k_common needs to be a separate kernel module.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/Kconfig |  8 +++-
 drivers/net/ethernet/qualcomm/Makefile|  5 +++--
 drivers/net/ethernet/qualcomm/qca_7k_common.c | 10 ++
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/Kconfig 
b/drivers/net/ethernet/qualcomm/Kconfig
index d7720bf..b4c369d 100644
--- a/drivers/net/ethernet/qualcomm/Kconfig
+++ b/drivers/net/ethernet/qualcomm/Kconfig
@@ -16,7 +16,13 @@ config NET_VENDOR_QUALCOMM
 if NET_VENDOR_QUALCOMM
 
 config QCA7000
-   tristate "Qualcomm Atheros QCA7000 support"
+   tristate
+   help
+ This enables support for the Qualcomm Atheros QCA7000.
+
+config QCA7000_SPI
+   tristate "Qualcomm Atheros QCA7000 SPI support"
+   select QCA7000
depends on SPI_MASTER && OF
---help---
  This SPI protocol driver supports the Qualcomm Atheros QCA7000.
diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index 5e17bf1..65556ca 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -2,7 +2,8 @@
 # Makefile for the Qualcomm network device drivers.
 #
 
-obj-$(CONFIG_QCA7000) += qcaspi.o
-qcaspi-objs := qca_spi.o qca_7k_common.o qca_7k.o qca_debug.o
+obj-$(CONFIG_QCA7000) += qca_7k_common.o
+obj-$(CONFIG_QCA7000_SPI) += qcaspi.o
+qcaspi-objs := qca_7k.o qca_debug.o qca_spi.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_7k_common.c 
b/drivers/net/ethernet/qualcomm/qca_7k_common.c
index 0d3daa9..6b511f0 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k_common.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k_common.c
@@ -21,7 +21,9 @@
  *   by an atheros frame while transmitted over a serial channel;
  */
 
+#include 
 #include 
+#include 
 
 #include "qca_7k_common.h"
 
@@ -46,6 +48,7 @@ qcafrm_create_header(u8 *buf, u16 length)
 
return QCAFRM_HEADER_LEN;
 }
+EXPORT_SYMBOL_GPL(qcafrm_create_header);
 
 u16
 qcafrm_create_footer(u8 *buf)
@@ -57,6 +60,7 @@ qcafrm_create_footer(u8 *buf)
buf[1] = 0x55;
return QCAFRM_FOOTER_LEN;
 }
+EXPORT_SYMBOL_GPL(qcafrm_create_footer);
 
 /*   Gather received bytes and try to extract a full ethernet frame by
  *   following a simple state machine.
@@ -154,3 +158,9 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
 
return ret;
 }
+EXPORT_SYMBOL_GPL(qcafrm_fsm_decode);
+
+MODULE_DESCRIPTION("Qualcomm Atheros QCA7000 common");
+MODULE_AUTHOR("Qualcomm Atheros Communications");
+MODULE_AUTHOR("Stefan Wahren <stefan.wah...@i2se.com>");
+MODULE_LICENSE("Dual BSD/GPL");
-- 
2.1.4



[PATCH v6 net-next 17/17] net: qualcomm: add QCA7000 UART driver

2017-05-23 Thread Stefan Wahren
This patch adds the Ethernet over UART driver for the
Qualcomm QCA7000 HomePlug GreenPHY.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/Kconfig |  16 +
 drivers/net/ethernet/qualcomm/Makefile|   2 +
 drivers/net/ethernet/qualcomm/qca_7k_common.h |   6 +
 drivers/net/ethernet/qualcomm/qca_uart.c  | 423 ++
 4 files changed, 447 insertions(+)
 create mode 100644 drivers/net/ethernet/qualcomm/qca_uart.c

diff --git a/drivers/net/ethernet/qualcomm/Kconfig 
b/drivers/net/ethernet/qualcomm/Kconfig
index b4c369d..877675a 100644
--- a/drivers/net/ethernet/qualcomm/Kconfig
+++ b/drivers/net/ethernet/qualcomm/Kconfig
@@ -30,6 +30,22 @@ config QCA7000_SPI
  To compile this driver as a module, choose M here. The module
  will be called qcaspi.
 
+config QCA7000_UART
+   tristate "Qualcomm Atheros QCA7000 UART support"
+   select QCA7000
+   depends on SERIAL_DEV_BUS && OF
+   ---help---
+ This UART protocol driver supports the Qualcomm Atheros QCA7000.
+
+ Currently the driver assumes these device UART settings:
+   Data bits: 8
+   Parity: None
+   Stop bits: 1
+   Flow control: None
+
+ To compile this driver as a module, choose M here. The module
+ will be called qcauart.
+
 config QCOM_EMAC
tristate "Qualcomm Technologies, Inc. EMAC Gigabit Ethernet support"
depends on HAS_DMA && HAS_IOMEM
diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index 65556ca..92fa7c4 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -5,5 +5,7 @@
 obj-$(CONFIG_QCA7000) += qca_7k_common.o
 obj-$(CONFIG_QCA7000_SPI) += qcaspi.o
 qcaspi-objs := qca_7k.o qca_debug.o qca_spi.o
+obj-$(CONFIG_QCA7000_UART) += qcauart.o
+qcauart-objs := qca_uart.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_7k_common.h 
b/drivers/net/ethernet/qualcomm/qca_7k_common.h
index 07bdd6c..928554f 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k_common.h
+++ b/drivers/net/ethernet/qualcomm/qca_7k_common.h
@@ -122,6 +122,12 @@ static inline void qcafrm_fsm_init_spi(struct 
qcafrm_handle *handle)
handle->state = handle->init;
 }
 
+static inline void qcafrm_fsm_init_uart(struct qcafrm_handle *handle)
+{
+   handle->init = QCAFRM_WAIT_AA1;
+   handle->state = handle->init;
+}
+
 /*   Gather received bytes and try to extract a full Ethernet frame
  *   by following a simple state machine.
  *
diff --git a/drivers/net/ethernet/qualcomm/qca_uart.c 
b/drivers/net/ethernet/qualcomm/qca_uart.c
new file mode 100644
index 000..43d91ba
--- /dev/null
+++ b/drivers/net/ethernet/qualcomm/qca_uart.c
@@ -0,0 +1,423 @@
+/*
+ *   Copyright (c) 2011, 2012, Qualcomm Atheros Communications Inc.
+ *   Copyright (c) 2017, I2SE GmbH
+ *
+ *   Permission to use, copy, modify, and/or distribute this software
+ *   for any purpose with or without fee is hereby granted, provided
+ *   that the above copyright notice and this permission notice appear
+ *   in all copies.
+ *
+ *   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ *   WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ *   WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ *   THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
+ *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ *   LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ *   NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ *   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*   This module implements the Qualcomm Atheros UART protocol for
+ *   kernel-based UART device; it is essentially an Ethernet-to-UART
+ *   serial converter;
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "qca_7k_common.h"
+
+#define QCAUART_DRV_VERSION "0.1.0"
+#define QCAUART_DRV_NAME "qcauart"
+#define QCAUART_TX_TIMEOUT (1 * HZ)
+
+struct qcauart {
+   struct net_device *net_dev;
+   spinlock_t lock;/* transmit lock */
+   struct work_struct tx_work; /* Flushes transmit buffer   */
+
+   struct serdev_device *serdev;
+   struct qcafrm_handle frm_handle;
+   struct sk_buff *rx_skb;
+
+   unsigned char *tx_head; /* pointer to next XMIT byte */
+   int tx_left;/* bytes left in XMIT queue  */
+   unsigned char *tx_buffer;
+};
+
+static int
+qca_tty_receive(struct serdev_device *serdev, const unsigned char *data,
+   size_t count)
+{
+   struct qcauart *qca = serdev_device_get_drvdata(serdev);
+ 

[PATCH v6 net-next 15/17] dt-bindings: slave-device: add current-speed property

2017-05-23 Thread Stefan Wahren
This adds a new DT property to define the current baud rate of the
slave device.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
Reviewed-by: Rob Herring <r...@kernel.org>
---
 Documentation/devicetree/bindings/serial/slave-device.txt | 9 +
 1 file changed, 9 insertions(+)

diff --git a/Documentation/devicetree/bindings/serial/slave-device.txt 
b/Documentation/devicetree/bindings/serial/slave-device.txt
index f660379..40110e0 100644
--- a/Documentation/devicetree/bindings/serial/slave-device.txt
+++ b/Documentation/devicetree/bindings/serial/slave-device.txt
@@ -21,6 +21,15 @@ Optional Properties:
  can support. For example, a particular board has some signal
  quality issue or the host processor can't support higher
  baud rates.
+- current-speed: The current baud rate the device operates at. This 
should
+ only be present in case a driver has no chance to know
+ the baud rate of the slave device.
+ Examples:
+   * device supports auto-baud
+   * the rate is setup by a bootloader and there is no
+ way to reset the device
+   * device baud rate is configured by its firmware but
+ there is no way to request the actual settings
 
 Example:
 
-- 
2.1.4



[PATCH v6 net-next 05/17] net: qualcomm: use net_device_ops instead of direct call

2017-05-23 Thread Stefan Wahren
There is no need to export qcaspi_netdev_open and qcaspi_netdev_close
because they are also accessible via the net_device_ops.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_debug.c | 5 +++--
 drivers/net/ethernet/qualcomm/qca_spi.c   | 4 ++--
 drivers/net/ethernet/qualcomm/qca_spi.h   | 3 ---
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_debug.c 
b/drivers/net/ethernet/qualcomm/qca_debug.c
index d145df9..92b6be9 100644
--- a/drivers/net/ethernet/qualcomm/qca_debug.c
+++ b/drivers/net/ethernet/qualcomm/qca_debug.c
@@ -275,6 +275,7 @@ qcaspi_get_ringparam(struct net_device *dev, struct 
ethtool_ringparam *ring)
 static int
 qcaspi_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
 {
+   const struct net_device_ops *ops = dev->netdev_ops;
struct qcaspi *qca = netdev_priv(dev);
 
if ((ring->rx_pending) ||
@@ -283,13 +284,13 @@ qcaspi_set_ringparam(struct net_device *dev, struct 
ethtool_ringparam *ring)
return -EINVAL;
 
if (netif_running(dev))
-   qcaspi_netdev_close(dev);
+   ops->ndo_stop(dev);
 
qca->txr.count = max_t(u32, ring->tx_pending, TX_RING_MIN_LEN);
qca->txr.count = min_t(u16, qca->txr.count, TX_RING_MAX_LEN);
 
if (netif_running(dev))
-   qcaspi_netdev_open(dev);
+   ops->ndo_open(dev);
 
return 0;
 }
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 0c3fdee..7e039e3 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -603,7 +603,7 @@ qcaspi_intr_handler(int irq, void *data)
return IRQ_HANDLED;
 }
 
-int
+static int
 qcaspi_netdev_open(struct net_device *dev)
 {
struct qcaspi *qca = netdev_priv(dev);
@@ -640,7 +640,7 @@ qcaspi_netdev_open(struct net_device *dev)
return 0;
 }
 
-int
+static int
 qcaspi_netdev_close(struct net_device *dev)
 {
struct qcaspi *qca = netdev_priv(dev);
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.h 
b/drivers/net/ethernet/qualcomm/qca_spi.h
index 6e31a0e..064853d 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.h
+++ b/drivers/net/ethernet/qualcomm/qca_spi.h
@@ -108,7 +108,4 @@ struct qcaspi {
u16 burst_len;
 };
 
-int qcaspi_netdev_open(struct net_device *dev);
-int qcaspi_netdev_close(struct net_device *dev);
-
 #endif /* _QCA_SPI_H */
-- 
2.1.4



[PATCH v6 net-next 10/17] net: qualcomm: rename qca_framing.c to qca_7k_common.c

2017-05-23 Thread Stefan Wahren
As preparation for the upcoming UART driver we need a module
which contains common functions for both interfaces. The module
qca_framing is a good candidate but renaming to qca_7k_common would
make it clear.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/Makefile   | 2 +-
 drivers/net/ethernet/qualcomm/{qca_framing.c => qca_7k_common.c} | 2 +-
 drivers/net/ethernet/qualcomm/{qca_framing.h => qca_7k_common.h} | 0
 drivers/net/ethernet/qualcomm/qca_spi.c  | 2 +-
 drivers/net/ethernet/qualcomm/qca_spi.h  | 2 +-
 5 files changed, 4 insertions(+), 4 deletions(-)
 rename drivers/net/ethernet/qualcomm/{qca_framing.c => qca_7k_common.c} (99%)
 rename drivers/net/ethernet/qualcomm/{qca_framing.h => qca_7k_common.h} (100%)

diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index aacb0a5..5e17bf1 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -3,6 +3,6 @@
 #
 
 obj-$(CONFIG_QCA7000) += qcaspi.o
-qcaspi-objs := qca_spi.o qca_framing.o qca_7k.o qca_debug.o
+qcaspi-objs := qca_spi.o qca_7k_common.o qca_7k.o qca_debug.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_framing.c 
b/drivers/net/ethernet/qualcomm/qca_7k_common.c
similarity index 99%
rename from drivers/net/ethernet/qualcomm/qca_framing.c
rename to drivers/net/ethernet/qualcomm/qca_7k_common.c
index 2341f2b..6d17fbd 100644
--- a/drivers/net/ethernet/qualcomm/qca_framing.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k_common.c
@@ -23,7 +23,7 @@
 
 #include 
 
-#include "qca_framing.h"
+#include "qca_7k_common.h"
 
 u16
 qcafrm_create_header(u8 *buf, u16 length)
diff --git a/drivers/net/ethernet/qualcomm/qca_framing.h 
b/drivers/net/ethernet/qualcomm/qca_7k_common.h
similarity index 100%
rename from drivers/net/ethernet/qualcomm/qca_framing.h
rename to drivers/net/ethernet/qualcomm/qca_7k_common.h
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index ee90af3..43cc7de 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -43,8 +43,8 @@
 #include 
 
 #include "qca_7k.h"
+#include "qca_7k_common.h"
 #include "qca_debug.h"
-#include "qca_framing.h"
 #include "qca_spi.h"
 
 #define MAX_DMA_BURST_LEN 5000
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.h 
b/drivers/net/ethernet/qualcomm/qca_spi.h
index 064853d..fc4beb1 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.h
+++ b/drivers/net/ethernet/qualcomm/qca_spi.h
@@ -32,7 +32,7 @@
 #include 
 #include 
 
-#include "qca_framing.h"
+#include "qca_7k_common.h"
 
 #define QCASPI_DRV_VERSION "0.2.7-i"
 #define QCASPI_DRV_NAME"qcaspi"
-- 
2.1.4



[PATCH v6 net-next 14/17] dt-bindings: qca7000: rename binding

2017-05-23 Thread Stefan Wahren
Before we can merge the QCA7000 UART binding the document needs to be
renamed.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 .../devicetree/bindings/net/{qca-qca7000-spi.txt => qca,qca7000.txt}  | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename Documentation/devicetree/bindings/net/{qca-qca7000-spi.txt => 
qca,qca7000.txt} (100%)

diff --git a/Documentation/devicetree/bindings/net/qca-qca7000-spi.txt 
b/Documentation/devicetree/bindings/net/qca,qca7000.txt
similarity index 100%
rename from Documentation/devicetree/bindings/net/qca-qca7000-spi.txt
rename to Documentation/devicetree/bindings/net/qca,qca7000.txt
-- 
2.1.4



[PATCH v6 net-next 06/17] net: qualcomm: Improve readability of length defines

2017-05-23 Thread Stefan Wahren
In order to avoid mixing things up, make the MTU and frame length
defines easier to read.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_framing.c |  2 +-
 drivers/net/ethernet/qualcomm/qca_framing.h |  8 
 drivers/net/ethernet/qualcomm/qca_spi.c | 12 ++--
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_framing.c 
b/drivers/net/ethernet/qualcomm/qca_framing.c
index faa924c..2341f2b 100644
--- a/drivers/net/ethernet/qualcomm/qca_framing.c
+++ b/drivers/net/ethernet/qualcomm/qca_framing.c
@@ -117,7 +117,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
break;
case QCAFRM_WAIT_RSVD_BYTE2:
len = handle->offset;
-   if (len > buf_len || len < QCAFRM_ETHMINLEN) {
+   if (len > buf_len || len < QCAFRM_MIN_LEN) {
ret = QCAFRM_INVLEN;
handle->state = QCAFRM_HW_LEN0;
} else {
diff --git a/drivers/net/ethernet/qualcomm/qca_framing.h 
b/drivers/net/ethernet/qualcomm/qca_framing.h
index 8b385e6..5df7c65 100644
--- a/drivers/net/ethernet/qualcomm/qca_framing.h
+++ b/drivers/net/ethernet/qualcomm/qca_framing.h
@@ -44,12 +44,12 @@
 #define QCAFRM_INVFRAME (QCAFRM_ERR_BASE - 4)
 
 /* Min/Max Ethernet MTU: 46/1500 */
-#define QCAFRM_ETHMINMTU (ETH_ZLEN - ETH_HLEN)
-#define QCAFRM_ETHMAXMTU ETH_DATA_LEN
+#define QCAFRM_MIN_MTU (ETH_ZLEN - ETH_HLEN)
+#define QCAFRM_MAX_MTU ETH_DATA_LEN
 
 /* Min/Max frame lengths */
-#define QCAFRM_ETHMINLEN (QCAFRM_ETHMINMTU + ETH_HLEN)
-#define QCAFRM_ETHMAXLEN (QCAFRM_ETHMAXMTU + VLAN_ETH_HLEN)
+#define QCAFRM_MIN_LEN (QCAFRM_MIN_MTU + ETH_HLEN)
+#define QCAFRM_MAX_LEN (QCAFRM_MAX_MTU + VLAN_ETH_HLEN)
 
 /* QCA7K header len */
 #define QCAFRM_HEADER_LEN 8
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 7e039e3..f155548 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -69,7 +69,7 @@ static int qcaspi_pluggable = QCASPI_PLUGGABLE_MIN;
 module_param(qcaspi_pluggable, int, 0);
 MODULE_PARM_DESC(qcaspi_pluggable, "Pluggable SPI connection (yes/no).");
 
-#define QCASPI_MTU QCAFRM_ETHMAXMTU
+#define QCASPI_MTU QCAFRM_MAX_MTU
 #define QCASPI_TX_TIMEOUT (1 * HZ)
 #define QCASPI_QCA7K_REBOOT_TIME_MS 1000
 
@@ -403,7 +403,7 @@ qcaspi_tx_ring_has_space(struct tx_ring *txr)
if (txr->skb[txr->tail])
return 0;
 
-   return (txr->size + QCAFRM_ETHMAXLEN < QCASPI_HW_BUF_LEN) ? 1 : 0;
+   return (txr->size + QCAFRM_MAX_LEN < QCASPI_HW_BUF_LEN) ? 1 : 0;
 }
 
 /*   Flush the tx ring. This function is only safe to
@@ -667,8 +667,8 @@ qcaspi_netdev_xmit(struct sk_buff *skb, struct net_device 
*dev)
struct sk_buff *tskb;
u8 pad_len = 0;
 
-   if (skb->len < QCAFRM_ETHMINLEN)
-   pad_len = QCAFRM_ETHMINLEN - skb->len;
+   if (skb->len < QCAFRM_MIN_LEN)
+   pad_len = QCAFRM_MIN_LEN - skb->len;
 
if (qca->txr.skb[qca->txr.tail]) {
netdev_warn(qca->net_dev, "queue was unexpectedly full!\n");
@@ -805,8 +805,8 @@ qcaspi_netdev_setup(struct net_device *dev)
dev->tx_queue_len = 100;
 
/* MTU range: 46 - 1500 */
-   dev->min_mtu = QCAFRM_ETHMINMTU;
-   dev->max_mtu = QCAFRM_ETHMAXMTU;
+   dev->min_mtu = QCAFRM_MIN_MTU;
+   dev->max_mtu = QCAFRM_MAX_MTU;
 
qca = netdev_priv(dev);
memset(qca, 0, sizeof(struct qcaspi));
-- 
2.1.4



[PATCH v6 net-next 07/17] net: qca_spi: remove QCASPI_MTU

2017-05-23 Thread Stefan Wahren
There is no need for an additional MTU define.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_spi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index f155548..7464628 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -69,7 +69,6 @@ static int qcaspi_pluggable = QCASPI_PLUGGABLE_MIN;
 module_param(qcaspi_pluggable, int, 0);
 MODULE_PARM_DESC(qcaspi_pluggable, "Pluggable SPI connection (yes/no).");
 
-#define QCASPI_MTU QCAFRM_MAX_MTU
 #define QCASPI_TX_TIMEOUT (1 * HZ)
 #define QCASPI_QCA7K_REBOOT_TIME_MS 1000
 
@@ -746,7 +745,7 @@ qcaspi_netdev_init(struct net_device *dev)
 {
struct qcaspi *qca = netdev_priv(dev);
 
-   dev->mtu = QCASPI_MTU;
+   dev->mtu = QCAFRM_MAX_MTU;
dev->type = ARPHRD_ETHER;
qca->clkspeed = qcaspi_clkspeed;
qca->burst_len = qcaspi_burst_len;
-- 
2.1.4



[PATCH v6 net-next 11/17] net: qualcomm: prepare frame decoding for UART driver

2017-05-23 Thread Stefan Wahren
Unfortunately the frame format is not exactly identical between SPI
and UART. In case of SPI there is an additional HW length at the
beginning. So store the initial state to make the decoding state machine
more flexible and easy to extend for UART support.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_7k_common.c | 12 ++--
 drivers/net/ethernet/qualcomm/qca_7k_common.h |  8 ++--
 drivers/net/ethernet/qualcomm/qca_spi.c   |  2 +-
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_7k_common.c 
b/drivers/net/ethernet/qualcomm/qca_7k_common.c
index 6d17fbd..0d3daa9 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k_common.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k_common.c
@@ -83,7 +83,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 
buf_len, u8 recv_by
 
if (recv_byte != 0x00) {
/* first two bytes of length must be 0 */
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
}
break;
case QCAFRM_HW_LEN2:
@@ -97,7 +97,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 
buf_len, u8 recv_by
case QCAFRM_WAIT_AA4:
if (recv_byte != 0xAA) {
ret = QCAFRM_NOHEAD;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state--;
}
@@ -119,7 +119,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
len = handle->offset;
if (len > buf_len || len < QCAFRM_MIN_LEN) {
ret = QCAFRM_INVLEN;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state = (enum qcafrm_state)(len + 1);
/* Remaining number of bytes. */
@@ -135,7 +135,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
case QCAFRM_WAIT_551:
if (recv_byte != 0x55) {
ret = QCAFRM_NOTAIL;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state = QCAFRM_WAIT_552;
}
@@ -143,11 +143,11 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
case QCAFRM_WAIT_552:
if (recv_byte != 0x55) {
ret = QCAFRM_NOTAIL;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
ret = handle->offset;
/* Frame is fully received. */
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
}
break;
}
diff --git a/drivers/net/ethernet/qualcomm/qca_7k_common.h 
b/drivers/net/ethernet/qualcomm/qca_7k_common.h
index 5df7c65..07bdd6c 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k_common.h
+++ b/drivers/net/ethernet/qualcomm/qca_7k_common.h
@@ -61,6 +61,7 @@
 #define QCAFRM_ERR_BASE -1000
 
 enum qcafrm_state {
+   /* HW length is only available on SPI */
QCAFRM_HW_LEN0 = 0x8000,
QCAFRM_HW_LEN1 = QCAFRM_HW_LEN0 - 1,
QCAFRM_HW_LEN2 = QCAFRM_HW_LEN1 - 1,
@@ -101,6 +102,8 @@ enum qcafrm_state {
 struct qcafrm_handle {
/*  Current decoding state */
enum qcafrm_state state;
+   /* Initial state depends on connection type */
+   enum qcafrm_state init;
 
/* Offset in buffer (borrowed for length too) */
u16 offset;
@@ -113,9 +116,10 @@ u16 qcafrm_create_header(u8 *buf, u16 len);
 
 u16 qcafrm_create_footer(u8 *buf);
 
-static inline void qcafrm_fsm_init(struct qcafrm_handle *handle)
+static inline void qcafrm_fsm_init_spi(struct qcafrm_handle *handle)
 {
-   handle->state = QCAFRM_HW_LEN0;
+   handle->init = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
 }
 
 /*   Gather received bytes and try to extract a full Ethernet frame
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 43cc7de..de78f60 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -638,7 +638,7 @@ qcaspi_netdev_open(struct net_device *dev)
qca->intr_req = 1;
qca->intr_svc = 0;
qca->sync = QCASPI_SYNC_UNKNOWN;
-   qcafrm_fsm_init(>frm_handle);
+   qcafrm_fsm_init_spi(>frm_handle);
 
qca->spi_thread = kthread_run((void *)qcaspi_spi_thread,
  qca, "%s", dev->name);
-- 
2.1.4



[PATCH v6 net-next 00/17] net: qualcomm: add QCA7000 UART driver

2017-05-23 Thread Stefan Wahren
The Qualcomm QCA7000 HomePlug GreenPHY supports two interfaces:
UART and SPI. This patch series adds the missing support for UART.

This driver based on the Qualcomm code [1], but contains some changes:
* use random MAC address per default
* use net_device_stats from device
* share frame decoding between SPI and UART driver
* improve error handling
* reimplement tty_wakeup with work queue (based on slcan)
* use new serial device bus instead of ldisc

The patches 1 - 3 are just for clean up and are not related to
the UART support. Patch 4 adds SET_NETDEV_DEV() to qca_spi.
Patches 5 - 16 prepare the existing QCA7000 code for UART support.
The last patch contains the new driver.

The code itself has been tested on a Freescale i.MX28 board and
a Raspberry Pi Zero.

Changes in v6:
  * rebase to current linux-next
  * use SET_NETDEV_DEV() for qca_spi and qca_uart
  * rename binding to qca,qca7000.txt
  * use qca,qca7000 compatible for both driver
  * handle error cases in qca_uart_probe properly
  * fix skb leak in error path of qcauart_netdev_init
  * use dev_kfree_skb_any instead of kfree_skb
  * take care of tx_work on close / remove
  * use devm_kmalloc for tx buffer
  * minor cleanups

Changes in v5:
  * rebase to current linux-next
  * fix alignment issues in rx path
  * fix buffer overrun with big ethernet frames
  * fix init of UART decoding fsm
  * add device UART settings to Kconfig help
  * add current-speed to slave-device binding
  * merge SPI and UART binding document
  * rename qca_common to qca_7k_common
  * drop patch for retrieving UART settings
  * several cleanups

Changes in v4:
  * rebase to current linux-next
  * use parameter -M for git format-patch
  * change order of local variables where possible
  * implement basic serdev support (without hardware flow control)

Changes in v3:
  * rebase to current net-next

Changes in v2:
  * fix build issue by using netif_trans_update() and dev_trans_start()

[1] - https://github.com/IoE/qca7000

Stefan Wahren (17):
  net: qualcomm: remove unnecessary includes
  net: qca_framing: use u16 for frame offset
  net: qca_7k: Use BIT macro
  net: qca_spi: Use SET_NETDEV_DEV()
  net: qualcomm: use net_device_ops instead of direct call
  net: qualcomm: Improve readability of length defines
  net: qca_spi: remove QCASPI_MTU
  net: qualcomm: move qcaspi_tx_cmd to qca_spi.c
  net: qca_spi: Clarify MODULE_DESCRIPTION
  net: qualcomm: rename qca_framing.c to qca_7k_common.c
  net: qualcomm: prepare frame decoding for UART driver
  net: qualcomm: make qca_7k_common a separate kernel module
  dt-bindings: qca7000-spi: Rework binding
  dt-bindings: qca7000: rename binding
  dt-bindings: slave-device: add current-speed property
  dt-bindings: qca7000: append UART interface to binding
  net: qualcomm: add QCA7000 UART driver

 .../devicetree/bindings/net/qca,qca7000.txt|  88 +
 .../devicetree/bindings/net/qca-qca7000-spi.txt|  47 ---
 .../devicetree/bindings/serial/slave-device.txt|   9 +
 drivers/net/ethernet/qualcomm/Kconfig  |  24 +-
 drivers/net/ethernet/qualcomm/Makefile |   7 +-
 drivers/net/ethernet/qualcomm/qca_7k.c |  28 --
 drivers/net/ethernet/qualcomm/qca_7k.h |  15 +-
 .../qualcomm/{qca_framing.c => qca_7k_common.c}|  26 +-
 .../qualcomm/{qca_framing.h => qca_7k_common.h}|  24 +-
 drivers/net/ethernet/qualcomm/qca_debug.c  |   5 +-
 drivers/net/ethernet/qualcomm/qca_spi.c|  48 ++-
 drivers/net/ethernet/qualcomm/qca_spi.h|   5 +-
 drivers/net/ethernet/qualcomm/qca_uart.c   | 423 +
 13 files changed, 630 insertions(+), 119 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/qca,qca7000.txt
 delete mode 100644 Documentation/devicetree/bindings/net/qca-qca7000-spi.txt
 rename drivers/net/ethernet/qualcomm/{qca_framing.c => qca_7k_common.c} (85%)
 rename drivers/net/ethernet/qualcomm/{qca_framing.h => qca_7k_common.h} (86%)
 create mode 100644 drivers/net/ethernet/qualcomm/qca_uart.c

-- 
2.1.4



[PATCH v6 net-next 13/17] dt-bindings: qca7000-spi: Rework binding

2017-05-23 Thread Stefan Wahren
In preparation for the QCA7000 UART binding rework the binding document.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 .../devicetree/bindings/net/qca-qca7000-spi.txt| 49 +-
 1 file changed, 29 insertions(+), 20 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/qca-qca7000-spi.txt 
b/Documentation/devicetree/bindings/net/qca-qca7000-spi.txt
index c74989c..a37f656 100644
--- a/Documentation/devicetree/bindings/net/qca-qca7000-spi.txt
+++ b/Documentation/devicetree/bindings/net/qca-qca7000-spi.txt
@@ -1,29 +1,38 @@
-* Qualcomm QCA7000 (Ethernet over SPI protocol)
+* Qualcomm QCA7000
 
-Note: The QCA7000 is useable as a SPI device. In this case it must be defined
-as a child of a SPI master in the device tree.
+The QCA7000 is a serial-to-powerline bridge with a host interface which could
+be configured either as SPI or UART slave. This configuration is done by
+the QCA7000 firmware.
+
+(a) Ethernet over SPI
+
+In order to use the QCA7000 as SPI device it must be defined as a child of a
+SPI master in the device tree.
 
 Required properties:
-- compatible : Should be "qca,qca7000"
-- reg : Should specify the SPI chip select
-- interrupts : The first cell should specify the index of the source interrupt
-  and the second cell should specify the trigger type as rising edge
-- spi-cpha : Must be set
-- spi-cpol: Must be set
+- compatible   : Should be "qca,qca7000"
+- reg  : Should specify the SPI chip select
+- interrupts   : The first cell should specify the index of the source
+ interrupt and the second cell should specify the trigger
+ type as rising edge
+- spi-cpha : Must be set
+- spi-cpol : Must be set
 
 Optional properties:
-- interrupt-parent : Specify the pHandle of the source interrupt
+- interrupt-parent  : Specify the pHandle of the source interrupt
 - spi-max-frequency : Maximum frequency of the SPI bus the chip can operate at.
-  Numbers smaller than 100 or greater than 1600 are invalid. Missing
-  the property will set the SPI frequency to 800 Hertz.
-- local-mac-address: 6 bytes, MAC address
-- qca,legacy-mode : Set the SPI data transfer of the QCA7000 to legacy mode.
-  In this mode the SPI master must toggle the chip select between each data
-  word. In burst mode these gaps aren't necessary, which is faster.
-  This setting depends on how the QCA7000 is setup via GPIO pin strapping.
-  If the property is missing the driver defaults to burst mode.
-
-Example:
+ Numbers smaller than 100 or greater than 1600
+ are invalid. Missing the property will set the SPI
+ frequency to 800 Hertz.
+- local-mac-address : see ./ethernet.txt
+- qca,legacy-mode   : Set the SPI data transfer of the QCA7000 to legacy mode.
+ In this mode the SPI master must toggle the chip select
+ between each data word. In burst mode these gaps aren't
+ necessary, which is faster. This setting depends on how
+ the QCA7000 is setup via GPIO pin strapping. If the
+ property is missing the driver defaults to burst mode.
+
+SPI Example:
 
 /* Freescale i.MX28 SPI master*/
 ssp2: spi@80014000 {
-- 
2.1.4



[PATCH v6 net-next 16/17] dt-bindings: qca7000: append UART interface to binding

2017-05-23 Thread Stefan Wahren
This merges the serdev binding for the QCA7000 UART driver (Ethernet over
UART) into the existing document.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 .../devicetree/bindings/net/qca,qca7000.txt| 32 ++
 1 file changed, 32 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/qca,qca7000.txt 
b/Documentation/devicetree/bindings/net/qca,qca7000.txt
index a37f656..6d9efb2 100644
--- a/Documentation/devicetree/bindings/net/qca,qca7000.txt
+++ b/Documentation/devicetree/bindings/net/qca,qca7000.txt
@@ -54,3 +54,35 @@ ssp2: spi@80014000 {
local-mac-address = [ A0 B0 C0 D0 E0 F0 ];
};
 };
+
+(b) Ethernet over UART
+
+In order to use the QCA7000 as UART slave it must be defined as a child of a
+UART master in the device tree. It is possible to preconfigure the UART
+settings of the QCA7000 firmware, but it's not possible to change them during
+runtime.
+
+Required properties:
+- compatible: Should be "qca,qca7000"
+
+Optional properties:
+- local-mac-address : see ./ethernet.txt
+- current-speed : current baud rate of QCA7000 which defaults to 115200
+ if absent, see also ../serial/slave-device.txt
+
+UART Example:
+
+/* Freescale i.MX28 UART */
+auart0: serial@8006a000 {
+   compatible = "fsl,imx28-auart", "fsl,imx23-auart";
+   reg = <0x8006a000 0x2000>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_2pins_a>;
+   status = "okay";
+
+   qca7000: ethernet {
+   compatible = "qca,qca7000";
+   local-mac-address = [ A0 B0 C0 D0 E0 F0 ];
+   current-speed = <38400>;
+   };
+};
-- 
2.1.4



[PATCH v6 net-next 01/17] net: qualcomm: remove unnecessary includes

2017-05-23 Thread Stefan Wahren
Most of the includes in qca_7k.c are unnecessary so we better remove them.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_7k.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_7k.c 
b/drivers/net/ethernet/qualcomm/qca_7k.c
index f0066fb..557d53c 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k.c
@@ -23,11 +23,7 @@
  *   kernel-based SPI device.
  */
 
-#include 
-#include 
-#include 
 #include 
-#include 
 
 #include "qca_7k.h"
 
-- 
2.1.4



[PATCH v6 net-next 08/17] net: qualcomm: move qcaspi_tx_cmd to qca_spi.c

2017-05-23 Thread Stefan Wahren
The function qcaspi_tx_cmd() is only called from qca_spi.c. So we better
move it there.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_7k.c  | 24 
 drivers/net/ethernet/qualcomm/qca_7k.h  |  1 -
 drivers/net/ethernet/qualcomm/qca_spi.c | 24 
 3 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_7k.c 
b/drivers/net/ethernet/qualcomm/qca_7k.c
index 557d53c..aa90a1d 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k.c
@@ -119,27 +119,3 @@ qcaspi_write_register(struct qcaspi *qca, u16 reg, u16 
value)
 
return ret;
 }
-
-int
-qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd)
-{
-   __be16 tx_data;
-   struct spi_message *msg = >spi_msg1;
-   struct spi_transfer *transfer = >spi_xfer1;
-   int ret;
-
-   tx_data = cpu_to_be16(cmd);
-   transfer->len = sizeof(tx_data);
-   transfer->tx_buf = _data;
-   transfer->rx_buf = NULL;
-
-   ret = spi_sync(qca->spi_dev, msg);
-
-   if (!ret)
-   ret = msg->status;
-
-   if (ret)
-   qcaspi_spi_error(qca);
-
-   return ret;
-}
diff --git a/drivers/net/ethernet/qualcomm/qca_7k.h 
b/drivers/net/ethernet/qualcomm/qca_7k.h
index 4047f0a..27124c2 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.h
+++ b/drivers/net/ethernet/qualcomm/qca_7k.h
@@ -67,6 +67,5 @@
 void qcaspi_spi_error(struct qcaspi *qca);
 int qcaspi_read_register(struct qcaspi *qca, u16 reg, u16 *result);
 int qcaspi_write_register(struct qcaspi *qca, u16 reg, u16 value);
-int qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd);
 
 #endif /* _QCA_7K_H */
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 7464628..50adc4f 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -192,6 +192,30 @@ qcaspi_read_legacy(struct qcaspi *qca, u8 *dst, u32 len)
 }
 
 static int
+qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd)
+{
+   __be16 tx_data;
+   struct spi_message *msg = >spi_msg1;
+   struct spi_transfer *transfer = >spi_xfer1;
+   int ret;
+
+   tx_data = cpu_to_be16(cmd);
+   transfer->len = sizeof(tx_data);
+   transfer->tx_buf = _data;
+   transfer->rx_buf = NULL;
+
+   ret = spi_sync(qca->spi_dev, msg);
+
+   if (!ret)
+   ret = msg->status;
+
+   if (ret)
+   qcaspi_spi_error(qca);
+
+   return ret;
+}
+
+static int
 qcaspi_tx_frame(struct qcaspi *qca, struct sk_buff *skb)
 {
u32 count;
-- 
2.1.4



Re: [PATCH v5 15/17] dt-bindings: qca7000: append UART interface to binding

2017-05-19 Thread Stefan Wahren
Hi Rob,

Am 12.05.2017 um 08:43 schrieb Jakub Kicinski:
> On Fri, 12 May 2017 06:15:52 +, Michael Heimpold wrote:
>> Hi,
>>
>> Zitat von Jakub Kicinski <kubak...@wp.pl>:
>>
>>> On Thu, 11 May 2017 21:12:22 +0200, Michael Heimpold wrote:  
>>>> Am Mittwoch, 10. Mai 2017, 10:53:26 CEST schrieb Stefan Wahren:  
>>>>> This merges the serdev binding for the QCA7000 UART driver (Ethernet over
>>>>> UART) into the existing document.
>>>>>
>>>>> Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
>>>>> ---
>>>>>  .../devicetree/bindings/net/qca-qca7000.txt| 32
>>>>> ++ 1 file changed, 32 insertions(+)
>>>>>
>>>>> diff --git a/Documentation/devicetree/bindings/net/qca-qca7000.txt
>>>>> b/Documentation/devicetree/bindings/net/qca-qca7000.txt index
>>>>> a37f656..08364c3 100644
>>>>> --- a/Documentation/devicetree/bindings/net/qca-qca7000.txt
>>>>> +++ b/Documentation/devicetree/bindings/net/qca-qca7000.txt
>>>>> @@ -54,3 +54,35 @@ ssp2: spi@80014000 {
>>>>>   local-mac-address = [ A0 B0 C0 D0 E0 F0 ];
>>>>>   };
>>>>>  };
>>>>> +
>>>>> +(b) Ethernet over UART
>>>>> +
>>>>> +In order to use the QCA7000 as UART slave it must be defined as
>>>> a child of  
>>>>> a +UART master in the device tree. It is possible to preconfigure the UART
>>>>> +settings of the QCA7000 firmware, but it's not possible to change them
>>>>> during +runtime.
>>>>> +
>>>>> +Required properties:
>>>>> +- compatible: Should be "qca,qca7000-uart"  
>>>> I already discussed this with Stefan off-list a little bit, but I would 
>>>> like
>>>> to bring this to a broader audience: I'm not sure whether the compatible
>>>> should contain the "-uart" suffix, because the hardware chip is the  
>>>> very same
>>>> QCA7000 chip which can also be used with SPI protocol.
>>>> The only difference is the loaded firmware within the chip which can either
>>>> speak SPI or UART protocol (but not both at the same time - due to shared
>>>> pins). So the hardware design decides which interface type is used.
>>>>
>>>> At the moment, this patch series adds a dedicated driver for the UART
>>>> protocol, in parallel to the existing SPI driver. So a different compatible
>>>> string is needed here to match against the new driver.
>>>>
>>>> An alternative approach would be to re-use the existing compatible string
>>>> "qca,qca7000" for both, the SPI and UART protocol, because a "smarter"
>>>> (combined) driver would detect which protocol to use. For example the 
>>>> driver
>>>> could check for spi-cpha and/or spi-cpol which are required for SPI  
>>>> protocol:
>>>> if these exists the driver could assume that SPI must be used, if both are
>>>> missing then UART protocol should be used.
>>>> (This way it would not be necessary to check whether the node is a child of
>>>> a SPI or UART master node - but maybe this is even easier - I don't know)
>>>>
>>>> Or in shorter words: my concern is that while "qca7000-uart" describes the
>>>> hardware, it's too closely coupled to the driver implementation. Having
>>>> some feedback of the experts would be nice :-)  
>>> I'm no expert, but devices which can do both I2C and SPI are quite
>>> common, and they usually have the same compatible string for both
>>> buses.  
>> do you have an example driver at hand? I only found GPIO mcp23s08 driver,
>> which can handle both I2C and SPI chips, but there are different compatible
>> strings used to distinguish several chip models.
> I think drivers/tty/serial/sc16is7xx.c has the same strings, and some
> Kconfig magic to work when either bus is enabled in .config.
>
> Quick grep shows there are couple more potential ones to look at:
>
> $ find . -name Kconfig | xargs grep -n 'SPI_MASTER.* I2C' 
> ./drivers/tty/serial/Kconfig:1208:depends on (SPI_MASTER && !I2C) || 
> I2C
> ./drivers/mfd/Kconfig:327:depends on (SPI_MASTER || I2C)
> ./drivers/iio/dac/Kconfig:10: depends on (SPI_MASTER && I2C!=m) || I2C
> ./drivers/iio/dac/Kconfig:34: depends on (SPI_MASTER && I2C!=m) || I2C
> ./dr

Re: [PATCH v5 16/17] tty: serdev-ttyport: return actual baudrate from ttyport_set_baudrate

2017-05-17 Thread Stefan Wahren
Hi Greg,

Am 10.05.2017 um 10:53 schrieb Stefan Wahren:
> Instead of returning the requested baudrate, we better return the
> actual one because it isn't always the same.
>
> Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
> Acked-by: Rob Herring <r...@kernel.org>
> ---
>  drivers/tty/serdev/serdev-ttyport.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/tty/serdev/serdev-ttyport.c 
> b/drivers/tty/serdev/serdev-ttyport.c
> index 487c88f..2cfdf34 100644
> --- a/drivers/tty/serdev/serdev-ttyport.c
> +++ b/drivers/tty/serdev/serdev-ttyport.c
> @@ -151,7 +151,7 @@ static unsigned int ttyport_set_baudrate(struct 
> serdev_controller *ctrl, unsigne
>  
>   /* tty_set_termios() return not checked as it is always 0 */
>   tty_set_termios(tty, );
> - return speed;
> + return ktermios.c_ospeed;
>  }
>  
>  static void ttyport_set_flow_control(struct serdev_controller *ctrl, bool 
> enable)

there is no dependency to this series. I would be happy if this could be
applied, so i don't have to carry it for the next version.

Thanks
Stefan


[PATCH v5 11/17] net: qualcomm: make qca_7k_common a separate kernel module

2017-05-10 Thread Stefan Wahren
In order to share common functions between QCA7000 SPI and UART protocol
driver the qca_7k_common needs to be a separate kernel module.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/Kconfig |  8 +++-
 drivers/net/ethernet/qualcomm/Makefile|  5 +++--
 drivers/net/ethernet/qualcomm/qca_7k_common.c | 10 ++
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/Kconfig 
b/drivers/net/ethernet/qualcomm/Kconfig
index d7720bf..b4c369d 100644
--- a/drivers/net/ethernet/qualcomm/Kconfig
+++ b/drivers/net/ethernet/qualcomm/Kconfig
@@ -16,7 +16,13 @@ config NET_VENDOR_QUALCOMM
 if NET_VENDOR_QUALCOMM
 
 config QCA7000
-   tristate "Qualcomm Atheros QCA7000 support"
+   tristate
+   help
+ This enables support for the Qualcomm Atheros QCA7000.
+
+config QCA7000_SPI
+   tristate "Qualcomm Atheros QCA7000 SPI support"
+   select QCA7000
depends on SPI_MASTER && OF
---help---
  This SPI protocol driver supports the Qualcomm Atheros QCA7000.
diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index 5e17bf1..65556ca 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -2,7 +2,8 @@
 # Makefile for the Qualcomm network device drivers.
 #
 
-obj-$(CONFIG_QCA7000) += qcaspi.o
-qcaspi-objs := qca_spi.o qca_7k_common.o qca_7k.o qca_debug.o
+obj-$(CONFIG_QCA7000) += qca_7k_common.o
+obj-$(CONFIG_QCA7000_SPI) += qcaspi.o
+qcaspi-objs := qca_7k.o qca_debug.o qca_spi.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_7k_common.c 
b/drivers/net/ethernet/qualcomm/qca_7k_common.c
index 0d3daa9..6b511f0 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k_common.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k_common.c
@@ -21,7 +21,9 @@
  *   by an atheros frame while transmitted over a serial channel;
  */
 
+#include 
 #include 
+#include 
 
 #include "qca_7k_common.h"
 
@@ -46,6 +48,7 @@ qcafrm_create_header(u8 *buf, u16 length)
 
return QCAFRM_HEADER_LEN;
 }
+EXPORT_SYMBOL_GPL(qcafrm_create_header);
 
 u16
 qcafrm_create_footer(u8 *buf)
@@ -57,6 +60,7 @@ qcafrm_create_footer(u8 *buf)
buf[1] = 0x55;
return QCAFRM_FOOTER_LEN;
 }
+EXPORT_SYMBOL_GPL(qcafrm_create_footer);
 
 /*   Gather received bytes and try to extract a full ethernet frame by
  *   following a simple state machine.
@@ -154,3 +158,9 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
 
return ret;
 }
+EXPORT_SYMBOL_GPL(qcafrm_fsm_decode);
+
+MODULE_DESCRIPTION("Qualcomm Atheros QCA7000 common");
+MODULE_AUTHOR("Qualcomm Atheros Communications");
+MODULE_AUTHOR("Stefan Wahren <stefan.wah...@i2se.com>");
+MODULE_LICENSE("Dual BSD/GPL");
-- 
2.1.4



[PATCH v5 04/17] net: qualcomm: use net_device_ops instead of direct call

2017-05-10 Thread Stefan Wahren
There is no need to export qcaspi_netdev_open and qcaspi_netdev_close
because they are also accessible via the net_device_ops.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_debug.c | 5 +++--
 drivers/net/ethernet/qualcomm/qca_spi.c   | 4 ++--
 drivers/net/ethernet/qualcomm/qca_spi.h   | 3 ---
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_debug.c 
b/drivers/net/ethernet/qualcomm/qca_debug.c
index d145df9..92b6be9 100644
--- a/drivers/net/ethernet/qualcomm/qca_debug.c
+++ b/drivers/net/ethernet/qualcomm/qca_debug.c
@@ -275,6 +275,7 @@ qcaspi_get_ringparam(struct net_device *dev, struct 
ethtool_ringparam *ring)
 static int
 qcaspi_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
 {
+   const struct net_device_ops *ops = dev->netdev_ops;
struct qcaspi *qca = netdev_priv(dev);
 
if ((ring->rx_pending) ||
@@ -283,13 +284,13 @@ qcaspi_set_ringparam(struct net_device *dev, struct 
ethtool_ringparam *ring)
return -EINVAL;
 
if (netif_running(dev))
-   qcaspi_netdev_close(dev);
+   ops->ndo_stop(dev);
 
qca->txr.count = max_t(u32, ring->tx_pending, TX_RING_MIN_LEN);
qca->txr.count = min_t(u16, qca->txr.count, TX_RING_MAX_LEN);
 
if (netif_running(dev))
-   qcaspi_netdev_open(dev);
+   ops->ndo_open(dev);
 
return 0;
 }
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 8590109..5c79612 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -602,7 +602,7 @@ qcaspi_intr_handler(int irq, void *data)
return IRQ_HANDLED;
 }
 
-int
+static int
 qcaspi_netdev_open(struct net_device *dev)
 {
struct qcaspi *qca = netdev_priv(dev);
@@ -639,7 +639,7 @@ qcaspi_netdev_open(struct net_device *dev)
return 0;
 }
 
-int
+static int
 qcaspi_netdev_close(struct net_device *dev)
 {
struct qcaspi *qca = netdev_priv(dev);
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.h 
b/drivers/net/ethernet/qualcomm/qca_spi.h
index 6e31a0e..064853d 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.h
+++ b/drivers/net/ethernet/qualcomm/qca_spi.h
@@ -108,7 +108,4 @@ struct qcaspi {
u16 burst_len;
 };
 
-int qcaspi_netdev_open(struct net_device *dev);
-int qcaspi_netdev_close(struct net_device *dev);
-
 #endif /* _QCA_SPI_H */
-- 
2.1.4



[PATCH v5 07/17] net: qualcomm: move qcaspi_tx_cmd to qca_spi.c

2017-05-10 Thread Stefan Wahren
The function qcaspi_tx_cmd() is only called from qca_spi.c. So we better
move it there.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_7k.c  | 24 
 drivers/net/ethernet/qualcomm/qca_7k.h  |  1 -
 drivers/net/ethernet/qualcomm/qca_spi.c | 24 
 3 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_7k.c 
b/drivers/net/ethernet/qualcomm/qca_7k.c
index 557d53c..aa90a1d 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k.c
@@ -119,27 +119,3 @@ qcaspi_write_register(struct qcaspi *qca, u16 reg, u16 
value)
 
return ret;
 }
-
-int
-qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd)
-{
-   __be16 tx_data;
-   struct spi_message *msg = >spi_msg1;
-   struct spi_transfer *transfer = >spi_xfer1;
-   int ret;
-
-   tx_data = cpu_to_be16(cmd);
-   transfer->len = sizeof(tx_data);
-   transfer->tx_buf = _data;
-   transfer->rx_buf = NULL;
-
-   ret = spi_sync(qca->spi_dev, msg);
-
-   if (!ret)
-   ret = msg->status;
-
-   if (ret)
-   qcaspi_spi_error(qca);
-
-   return ret;
-}
diff --git a/drivers/net/ethernet/qualcomm/qca_7k.h 
b/drivers/net/ethernet/qualcomm/qca_7k.h
index 4047f0a..27124c2 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.h
+++ b/drivers/net/ethernet/qualcomm/qca_7k.h
@@ -67,6 +67,5 @@
 void qcaspi_spi_error(struct qcaspi *qca);
 int qcaspi_read_register(struct qcaspi *qca, u16 reg, u16 *result);
 int qcaspi_write_register(struct qcaspi *qca, u16 reg, u16 value);
-int qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd);
 
 #endif /* _QCA_7K_H */
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index a239ac4..c727357 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -192,6 +192,30 @@ qcaspi_read_legacy(struct qcaspi *qca, u8 *dst, u32 len)
 }
 
 static int
+qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd)
+{
+   __be16 tx_data;
+   struct spi_message *msg = >spi_msg1;
+   struct spi_transfer *transfer = >spi_xfer1;
+   int ret;
+
+   tx_data = cpu_to_be16(cmd);
+   transfer->len = sizeof(tx_data);
+   transfer->tx_buf = _data;
+   transfer->rx_buf = NULL;
+
+   ret = spi_sync(qca->spi_dev, msg);
+
+   if (!ret)
+   ret = msg->status;
+
+   if (ret)
+   qcaspi_spi_error(qca);
+
+   return ret;
+}
+
+static int
 qcaspi_tx_frame(struct qcaspi *qca, struct sk_buff *skb)
 {
u32 count;
-- 
2.1.4



[PATCH v5 00/17] net: qualcomm: add QCA7000 UART driver

2017-05-10 Thread Stefan Wahren
The Qualcomm QCA7000 HomePlug GreenPHY supports two interfaces:
UART and SPI. This patch series adds the missing support for UART.

This driver based on the Qualcomm code [1], but contains some changes:
* use random MAC address per default
* use net_device_stats from device
* share frame decoding between SPI and UART driver
* improve error handling
* reimplement tty_wakeup with work queue (based on slcan)
* use new serial device bus instead of ldisc

The patches 1 - 3 are just for clean up and are not related to
the UART support. Patches 4 - 15 prepare the existing QCA7000
code for UART support. Patch 16 is a improvement for serial device
bus. Patch 17 contains the new driver.

Cherry picking of the dt-bindings and serdev patch is okay. The
UART driver functionally (not compile) depends on this unmerged
patch [2].

The code itself has been tested on a Freescale i.MX28 board and
a Raspberry Pi Zero.

Changes in v5:
  * rebase to current linux-next
  * fix alignment issues in rx path
  * fix buffer overrun with big ethernet frames
  * fix init of UART decoding fsm
  * add device UART settings to Kconfig help
  * add current-speed to slave-device binding
  * merge SPI and UART binding document
  * rename qca_common to qca_7k_common
  * drop patch for retrieving UART settings
  * several cleanups

Changes in v4:
  * rebase to current linux-next
  * use parameter -M for git format-patch
  * change order of local variables where possible
  * implement basic serdev support (without hardware flow control)

Changes in v3:
  * rebase to current net-next

Changes in v2:
  * fix build issue by using netif_trans_update() and dev_trans_start()

[1] - https://github.com/IoE/qca7000
[2] - http://marc.info/?l=linux-serial=149338017301309=2

Stefan Wahren (17):
  net: qualcomm: remove unnecessary includes
  net: qca_framing: use u16 for frame offset
  net: qca_7k: Use BIT macro
  net: qualcomm: use net_device_ops instead of direct call
  net: qualcomm: Improve readability of length defines
  net: qca_spi: remove QCASPI_MTU
  net: qualcomm: move qcaspi_tx_cmd to qca_spi.c
  net: qca_spi: Clarify MODULE_DESCRIPTION
  net: qualcomm: rename qca_framing.c to qca_7k_common.c
  net: qualcomm: prepare frame decoding for UART driver
  net: qualcomm: make qca_7k_common a separate kernel module
  dt-bindings: qca7000-spi: Rework binding
  dt-bindings: qca7000: rename binding
  dt-bindings: slave-device: add current-speed property
  dt-bindings: qca7000: append UART interface to binding
  tty: serdev-ttyport: return actual baudrate from ttyport_set_baudrate
  net: qualcomm: add QCA7000 UART driver

 .../devicetree/bindings/net/qca-qca7000-spi.txt|  47 ---
 .../devicetree/bindings/net/qca-qca7000.txt|  88 +
 .../devicetree/bindings/serial/slave-device.txt|   9 +
 drivers/net/ethernet/qualcomm/Kconfig  |  24 +-
 drivers/net/ethernet/qualcomm/Makefile |   7 +-
 drivers/net/ethernet/qualcomm/qca_7k.c |  28 --
 drivers/net/ethernet/qualcomm/qca_7k.h |  15 +-
 .../qualcomm/{qca_framing.c => qca_7k_common.c}|  26 +-
 .../qualcomm/{qca_framing.h => qca_7k_common.h}|  24 +-
 drivers/net/ethernet/qualcomm/qca_debug.c  |   5 +-
 drivers/net/ethernet/qualcomm/qca_spi.c|  47 ++-
 drivers/net/ethernet/qualcomm/qca_spi.h|   5 +-
 drivers/net/ethernet/qualcomm/qca_uart.c   | 423 +
 drivers/tty/serdev/serdev-ttyport.c|   2 +-
 14 files changed, 630 insertions(+), 120 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/net/qca-qca7000-spi.txt
 create mode 100644 Documentation/devicetree/bindings/net/qca-qca7000.txt
 rename drivers/net/ethernet/qualcomm/{qca_framing.c => qca_7k_common.c} (85%)
 rename drivers/net/ethernet/qualcomm/{qca_framing.h => qca_7k_common.h} (86%)
 create mode 100644 drivers/net/ethernet/qualcomm/qca_uart.c

-- 
2.1.4



[PATCH v5 10/17] net: qualcomm: prepare frame decoding for UART driver

2017-05-10 Thread Stefan Wahren
Unfortunately the frame format is not exactly identical between SPI
and UART. In case of SPI there is an additional HW length at the
beginning. So store the initial state to make the decoding state machine
more flexible and easy to extend for UART support.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_7k_common.c | 12 ++--
 drivers/net/ethernet/qualcomm/qca_7k_common.h |  8 ++--
 drivers/net/ethernet/qualcomm/qca_spi.c   |  2 +-
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_7k_common.c 
b/drivers/net/ethernet/qualcomm/qca_7k_common.c
index 6d17fbd..0d3daa9 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k_common.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k_common.c
@@ -83,7 +83,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 
buf_len, u8 recv_by
 
if (recv_byte != 0x00) {
/* first two bytes of length must be 0 */
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
}
break;
case QCAFRM_HW_LEN2:
@@ -97,7 +97,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 
buf_len, u8 recv_by
case QCAFRM_WAIT_AA4:
if (recv_byte != 0xAA) {
ret = QCAFRM_NOHEAD;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state--;
}
@@ -119,7 +119,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
len = handle->offset;
if (len > buf_len || len < QCAFRM_MIN_LEN) {
ret = QCAFRM_INVLEN;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state = (enum qcafrm_state)(len + 1);
/* Remaining number of bytes. */
@@ -135,7 +135,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
case QCAFRM_WAIT_551:
if (recv_byte != 0x55) {
ret = QCAFRM_NOTAIL;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state = QCAFRM_WAIT_552;
}
@@ -143,11 +143,11 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
case QCAFRM_WAIT_552:
if (recv_byte != 0x55) {
ret = QCAFRM_NOTAIL;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
ret = handle->offset;
/* Frame is fully received. */
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
}
break;
}
diff --git a/drivers/net/ethernet/qualcomm/qca_7k_common.h 
b/drivers/net/ethernet/qualcomm/qca_7k_common.h
index 5df7c65..07bdd6c 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k_common.h
+++ b/drivers/net/ethernet/qualcomm/qca_7k_common.h
@@ -61,6 +61,7 @@
 #define QCAFRM_ERR_BASE -1000
 
 enum qcafrm_state {
+   /* HW length is only available on SPI */
QCAFRM_HW_LEN0 = 0x8000,
QCAFRM_HW_LEN1 = QCAFRM_HW_LEN0 - 1,
QCAFRM_HW_LEN2 = QCAFRM_HW_LEN1 - 1,
@@ -101,6 +102,8 @@ enum qcafrm_state {
 struct qcafrm_handle {
/*  Current decoding state */
enum qcafrm_state state;
+   /* Initial state depends on connection type */
+   enum qcafrm_state init;
 
/* Offset in buffer (borrowed for length too) */
u16 offset;
@@ -113,9 +116,10 @@ u16 qcafrm_create_header(u8 *buf, u16 len);
 
 u16 qcafrm_create_footer(u8 *buf);
 
-static inline void qcafrm_fsm_init(struct qcafrm_handle *handle)
+static inline void qcafrm_fsm_init_spi(struct qcafrm_handle *handle)
 {
-   handle->state = QCAFRM_HW_LEN0;
+   handle->init = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
 }
 
 /*   Gather received bytes and try to extract a full Ethernet frame
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 2bc3ba4..b7073a9 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -637,7 +637,7 @@ qcaspi_netdev_open(struct net_device *dev)
qca->intr_req = 1;
qca->intr_svc = 0;
qca->sync = QCASPI_SYNC_UNKNOWN;
-   qcafrm_fsm_init(>frm_handle);
+   qcafrm_fsm_init_spi(>frm_handle);
 
qca->spi_thread = kthread_run((void *)qcaspi_spi_thread,
  qca, "%s", dev->name);
-- 
2.1.4



[PATCH v5 08/17] net: qca_spi: Clarify MODULE_DESCRIPTION

2017-05-10 Thread Stefan Wahren
Since this driver is specific to the QCA7000, we should make the module
description more precisely.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index c727357..deec70f 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -997,7 +997,7 @@ static struct spi_driver qca_spi_driver = {
 };
 module_spi_driver(qca_spi_driver);
 
-MODULE_DESCRIPTION("Qualcomm Atheros SPI Driver");
+MODULE_DESCRIPTION("Qualcomm Atheros QCA7000 SPI Driver");
 MODULE_AUTHOR("Qualcomm Atheros Communications");
 MODULE_AUTHOR("Stefan Wahren <stefan.wah...@i2se.com>");
 MODULE_LICENSE("Dual BSD/GPL");
-- 
2.1.4



[PATCH v5 13/17] dt-bindings: qca7000: rename binding

2017-05-10 Thread Stefan Wahren
Before we can merge the QCA7000 UART binding the document needs to be
renamed.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 .../devicetree/bindings/net/{qca-qca7000-spi.txt => qca-qca7000.txt}  | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename Documentation/devicetree/bindings/net/{qca-qca7000-spi.txt => 
qca-qca7000.txt} (100%)

diff --git a/Documentation/devicetree/bindings/net/qca-qca7000-spi.txt 
b/Documentation/devicetree/bindings/net/qca-qca7000.txt
similarity index 100%
rename from Documentation/devicetree/bindings/net/qca-qca7000-spi.txt
rename to Documentation/devicetree/bindings/net/qca-qca7000.txt
-- 
2.1.4



[PATCH v5 12/17] dt-bindings: qca7000-spi: Rework binding

2017-05-10 Thread Stefan Wahren
In preparation for the QCA7000 UART binding rework the binding document.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 .../devicetree/bindings/net/qca-qca7000-spi.txt| 49 +-
 1 file changed, 29 insertions(+), 20 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/qca-qca7000-spi.txt 
b/Documentation/devicetree/bindings/net/qca-qca7000-spi.txt
index c74989c..a37f656 100644
--- a/Documentation/devicetree/bindings/net/qca-qca7000-spi.txt
+++ b/Documentation/devicetree/bindings/net/qca-qca7000-spi.txt
@@ -1,29 +1,38 @@
-* Qualcomm QCA7000 (Ethernet over SPI protocol)
+* Qualcomm QCA7000
 
-Note: The QCA7000 is useable as a SPI device. In this case it must be defined
-as a child of a SPI master in the device tree.
+The QCA7000 is a serial-to-powerline bridge with a host interface which could
+be configured either as SPI or UART slave. This configuration is done by
+the QCA7000 firmware.
+
+(a) Ethernet over SPI
+
+In order to use the QCA7000 as SPI device it must be defined as a child of a
+SPI master in the device tree.
 
 Required properties:
-- compatible : Should be "qca,qca7000"
-- reg : Should specify the SPI chip select
-- interrupts : The first cell should specify the index of the source interrupt
-  and the second cell should specify the trigger type as rising edge
-- spi-cpha : Must be set
-- spi-cpol: Must be set
+- compatible   : Should be "qca,qca7000"
+- reg  : Should specify the SPI chip select
+- interrupts   : The first cell should specify the index of the source
+ interrupt and the second cell should specify the trigger
+ type as rising edge
+- spi-cpha : Must be set
+- spi-cpol : Must be set
 
 Optional properties:
-- interrupt-parent : Specify the pHandle of the source interrupt
+- interrupt-parent  : Specify the pHandle of the source interrupt
 - spi-max-frequency : Maximum frequency of the SPI bus the chip can operate at.
-  Numbers smaller than 100 or greater than 1600 are invalid. Missing
-  the property will set the SPI frequency to 800 Hertz.
-- local-mac-address: 6 bytes, MAC address
-- qca,legacy-mode : Set the SPI data transfer of the QCA7000 to legacy mode.
-  In this mode the SPI master must toggle the chip select between each data
-  word. In burst mode these gaps aren't necessary, which is faster.
-  This setting depends on how the QCA7000 is setup via GPIO pin strapping.
-  If the property is missing the driver defaults to burst mode.
-
-Example:
+ Numbers smaller than 100 or greater than 1600
+ are invalid. Missing the property will set the SPI
+ frequency to 800 Hertz.
+- local-mac-address : see ./ethernet.txt
+- qca,legacy-mode   : Set the SPI data transfer of the QCA7000 to legacy mode.
+ In this mode the SPI master must toggle the chip select
+ between each data word. In burst mode these gaps aren't
+ necessary, which is faster. This setting depends on how
+ the QCA7000 is setup via GPIO pin strapping. If the
+ property is missing the driver defaults to burst mode.
+
+SPI Example:
 
 /* Freescale i.MX28 SPI master*/
 ssp2: spi@80014000 {
-- 
2.1.4



[PATCH v5 17/17] net: qualcomm: add QCA7000 UART driver

2017-05-10 Thread Stefan Wahren
This patch adds the Ethernet over UART driver for the
Qualcomm QCA7000 HomePlug GreenPHY.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/Kconfig |  16 +
 drivers/net/ethernet/qualcomm/Makefile|   2 +
 drivers/net/ethernet/qualcomm/qca_7k_common.h |   6 +
 drivers/net/ethernet/qualcomm/qca_uart.c  | 423 ++
 4 files changed, 447 insertions(+)
 create mode 100644 drivers/net/ethernet/qualcomm/qca_uart.c

diff --git a/drivers/net/ethernet/qualcomm/Kconfig 
b/drivers/net/ethernet/qualcomm/Kconfig
index b4c369d..877675a 100644
--- a/drivers/net/ethernet/qualcomm/Kconfig
+++ b/drivers/net/ethernet/qualcomm/Kconfig
@@ -30,6 +30,22 @@ config QCA7000_SPI
  To compile this driver as a module, choose M here. The module
  will be called qcaspi.
 
+config QCA7000_UART
+   tristate "Qualcomm Atheros QCA7000 UART support"
+   select QCA7000
+   depends on SERIAL_DEV_BUS && OF
+   ---help---
+ This UART protocol driver supports the Qualcomm Atheros QCA7000.
+
+ Currently the driver assumes these device UART settings:
+   Data bits: 8
+   Parity: None
+   Stop bits: 1
+   Flow control: None
+
+ To compile this driver as a module, choose M here. The module
+ will be called qcauart.
+
 config QCOM_EMAC
tristate "Qualcomm Technologies, Inc. EMAC Gigabit Ethernet support"
depends on HAS_DMA && HAS_IOMEM
diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index 65556ca..92fa7c4 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -5,5 +5,7 @@
 obj-$(CONFIG_QCA7000) += qca_7k_common.o
 obj-$(CONFIG_QCA7000_SPI) += qcaspi.o
 qcaspi-objs := qca_7k.o qca_debug.o qca_spi.o
+obj-$(CONFIG_QCA7000_UART) += qcauart.o
+qcauart-objs := qca_uart.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_7k_common.h 
b/drivers/net/ethernet/qualcomm/qca_7k_common.h
index 07bdd6c..928554f 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k_common.h
+++ b/drivers/net/ethernet/qualcomm/qca_7k_common.h
@@ -122,6 +122,12 @@ static inline void qcafrm_fsm_init_spi(struct 
qcafrm_handle *handle)
handle->state = handle->init;
 }
 
+static inline void qcafrm_fsm_init_uart(struct qcafrm_handle *handle)
+{
+   handle->init = QCAFRM_WAIT_AA1;
+   handle->state = handle->init;
+}
+
 /*   Gather received bytes and try to extract a full Ethernet frame
  *   by following a simple state machine.
  *
diff --git a/drivers/net/ethernet/qualcomm/qca_uart.c 
b/drivers/net/ethernet/qualcomm/qca_uart.c
new file mode 100644
index 000..1f6514c
--- /dev/null
+++ b/drivers/net/ethernet/qualcomm/qca_uart.c
@@ -0,0 +1,423 @@
+/*
+ *   Copyright (c) 2011, 2012, Qualcomm Atheros Communications Inc.
+ *   Copyright (c) 2017, I2SE GmbH
+ *
+ *   Permission to use, copy, modify, and/or distribute this software
+ *   for any purpose with or without fee is hereby granted, provided
+ *   that the above copyright notice and this permission notice appear
+ *   in all copies.
+ *
+ *   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ *   WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ *   WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ *   THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
+ *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ *   LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ *   NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ *   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*   This module implements the Qualcomm Atheros UART protocol for
+ *   kernel-based UART device; it is essentially an Ethernet-to-UART
+ *   serial converter;
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "qca_7k_common.h"
+
+#define QCAUART_DRV_VERSION "0.1.0"
+#define QCAUART_DRV_NAME "qcauart"
+#define QCAUART_TX_TIMEOUT (1 * HZ)
+
+struct qcauart {
+   struct net_device *net_dev;
+   spinlock_t lock;/* transmit lock */
+   struct work_struct tx_work; /* Flushes transmit buffer   */
+
+   struct serdev_device *serdev;
+   struct qcafrm_handle frm_handle;
+   struct sk_buff *rx_skb;
+
+   unsigned char *tx_head; /* pointer to next XMIT byte */
+   int tx_left;/* bytes left in XMIT queue  */
+   unsigned char *tx_buffer;
+};
+
+static int
+qca_tty_receive(struct serdev_device *serdev, const unsigned char *data,
+   size_t count)
+{
+   struct qcauart *qca = serdev_device_get_drvdata(serdev);
+ 

[PATCH v5 14/17] dt-bindings: slave-device: add current-speed property

2017-05-10 Thread Stefan Wahren
This adds a new DT property to define the current baud rate of the
slave device.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 Documentation/devicetree/bindings/serial/slave-device.txt | 9 +
 1 file changed, 9 insertions(+)

diff --git a/Documentation/devicetree/bindings/serial/slave-device.txt 
b/Documentation/devicetree/bindings/serial/slave-device.txt
index f660379..40110e0 100644
--- a/Documentation/devicetree/bindings/serial/slave-device.txt
+++ b/Documentation/devicetree/bindings/serial/slave-device.txt
@@ -21,6 +21,15 @@ Optional Properties:
  can support. For example, a particular board has some signal
  quality issue or the host processor can't support higher
  baud rates.
+- current-speed: The current baud rate the device operates at. This 
should
+ only be present in case a driver has no chance to know
+ the baud rate of the slave device.
+ Examples:
+   * device supports auto-baud
+   * the rate is setup by a bootloader and there is no
+ way to reset the device
+   * device baud rate is configured by its firmware but
+ there is no way to request the actual settings
 
 Example:
 
-- 
2.1.4



[PATCH v5 15/17] dt-bindings: qca7000: append UART interface to binding

2017-05-10 Thread Stefan Wahren
This merges the serdev binding for the QCA7000 UART driver (Ethernet over
UART) into the existing document.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 .../devicetree/bindings/net/qca-qca7000.txt| 32 ++
 1 file changed, 32 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/qca-qca7000.txt 
b/Documentation/devicetree/bindings/net/qca-qca7000.txt
index a37f656..08364c3 100644
--- a/Documentation/devicetree/bindings/net/qca-qca7000.txt
+++ b/Documentation/devicetree/bindings/net/qca-qca7000.txt
@@ -54,3 +54,35 @@ ssp2: spi@80014000 {
local-mac-address = [ A0 B0 C0 D0 E0 F0 ];
};
 };
+
+(b) Ethernet over UART
+
+In order to use the QCA7000 as UART slave it must be defined as a child of a
+UART master in the device tree. It is possible to preconfigure the UART
+settings of the QCA7000 firmware, but it's not possible to change them during
+runtime.
+
+Required properties:
+- compatible: Should be "qca,qca7000-uart"
+
+Optional properties:
+- local-mac-address : see ./ethernet.txt
+- current-speed : current baud rate of QCA7000 which defaults to 115200
+ if absent, see also ../serial/slave-device.txt
+
+UART Example:
+
+/* Freescale i.MX28 UART */
+auart0: serial@8006a000 {
+   compatible = "fsl,imx28-auart", "fsl,imx23-auart";
+   reg = <0x8006a000 0x2000>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_2pins_a>;
+   status = "okay";
+
+   qca7000: ethernet {
+   compatible = "qca,qca7000-uart";
+   local-mac-address = [ A0 B0 C0 D0 E0 F0 ];
+   current-speed = <38400>;
+   };
+};
-- 
2.1.4



[PATCH v5 02/17] net: qca_framing: use u16 for frame offset

2017-05-10 Thread Stefan Wahren
It doesn't make sense to use a signed variable for offset here, so
fix it up.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_framing.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_framing.h 
b/drivers/net/ethernet/qualcomm/qca_framing.h
index d5e795d..8b385e6 100644
--- a/drivers/net/ethernet/qualcomm/qca_framing.h
+++ b/drivers/net/ethernet/qualcomm/qca_framing.h
@@ -103,7 +103,7 @@ struct qcafrm_handle {
enum qcafrm_state state;
 
/* Offset in buffer (borrowed for length too) */
-   s16 offset;
+   u16 offset;
 
/* Frame length as kept by this module */
u16 len;
-- 
2.1.4



[PATCH v5 01/17] net: qualcomm: remove unnecessary includes

2017-05-10 Thread Stefan Wahren
Most of the includes in qca_7k.c are unnecessary so we better remove them.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_7k.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_7k.c 
b/drivers/net/ethernet/qualcomm/qca_7k.c
index f0066fb..557d53c 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k.c
@@ -23,11 +23,7 @@
  *   kernel-based SPI device.
  */
 
-#include 
-#include 
-#include 
 #include 
-#include 
 
 #include "qca_7k.h"
 
-- 
2.1.4



[PATCH v5 06/17] net: qca_spi: remove QCASPI_MTU

2017-05-10 Thread Stefan Wahren
There is no need for an additional MTU define.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_spi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index a0dbb92..a239ac4 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -69,7 +69,6 @@ static int qcaspi_pluggable = QCASPI_PLUGGABLE_MIN;
 module_param(qcaspi_pluggable, int, 0);
 MODULE_PARM_DESC(qcaspi_pluggable, "Pluggable SPI connection (yes/no).");
 
-#define QCASPI_MTU QCAFRM_MAX_MTU
 #define QCASPI_TX_TIMEOUT (1 * HZ)
 #define QCASPI_QCA7K_REBOOT_TIME_MS 1000
 
@@ -745,7 +744,7 @@ qcaspi_netdev_init(struct net_device *dev)
 {
struct qcaspi *qca = netdev_priv(dev);
 
-   dev->mtu = QCASPI_MTU;
+   dev->mtu = QCAFRM_MAX_MTU;
dev->type = ARPHRD_ETHER;
qca->clkspeed = qcaspi_clkspeed;
qca->burst_len = qcaspi_burst_len;
-- 
2.1.4



[PATCH v5 05/17] net: qualcomm: Improve readability of length defines

2017-05-10 Thread Stefan Wahren
In order to avoid mixing things up, make the MTU and frame length
defines easier to read.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_framing.c |  2 +-
 drivers/net/ethernet/qualcomm/qca_framing.h |  8 
 drivers/net/ethernet/qualcomm/qca_spi.c | 12 ++--
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_framing.c 
b/drivers/net/ethernet/qualcomm/qca_framing.c
index faa924c..2341f2b 100644
--- a/drivers/net/ethernet/qualcomm/qca_framing.c
+++ b/drivers/net/ethernet/qualcomm/qca_framing.c
@@ -117,7 +117,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
break;
case QCAFRM_WAIT_RSVD_BYTE2:
len = handle->offset;
-   if (len > buf_len || len < QCAFRM_ETHMINLEN) {
+   if (len > buf_len || len < QCAFRM_MIN_LEN) {
ret = QCAFRM_INVLEN;
handle->state = QCAFRM_HW_LEN0;
} else {
diff --git a/drivers/net/ethernet/qualcomm/qca_framing.h 
b/drivers/net/ethernet/qualcomm/qca_framing.h
index 8b385e6..5df7c65 100644
--- a/drivers/net/ethernet/qualcomm/qca_framing.h
+++ b/drivers/net/ethernet/qualcomm/qca_framing.h
@@ -44,12 +44,12 @@
 #define QCAFRM_INVFRAME (QCAFRM_ERR_BASE - 4)
 
 /* Min/Max Ethernet MTU: 46/1500 */
-#define QCAFRM_ETHMINMTU (ETH_ZLEN - ETH_HLEN)
-#define QCAFRM_ETHMAXMTU ETH_DATA_LEN
+#define QCAFRM_MIN_MTU (ETH_ZLEN - ETH_HLEN)
+#define QCAFRM_MAX_MTU ETH_DATA_LEN
 
 /* Min/Max frame lengths */
-#define QCAFRM_ETHMINLEN (QCAFRM_ETHMINMTU + ETH_HLEN)
-#define QCAFRM_ETHMAXLEN (QCAFRM_ETHMAXMTU + VLAN_ETH_HLEN)
+#define QCAFRM_MIN_LEN (QCAFRM_MIN_MTU + ETH_HLEN)
+#define QCAFRM_MAX_LEN (QCAFRM_MAX_MTU + VLAN_ETH_HLEN)
 
 /* QCA7K header len */
 #define QCAFRM_HEADER_LEN 8
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 5c79612..a0dbb92 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -69,7 +69,7 @@ static int qcaspi_pluggable = QCASPI_PLUGGABLE_MIN;
 module_param(qcaspi_pluggable, int, 0);
 MODULE_PARM_DESC(qcaspi_pluggable, "Pluggable SPI connection (yes/no).");
 
-#define QCASPI_MTU QCAFRM_ETHMAXMTU
+#define QCASPI_MTU QCAFRM_MAX_MTU
 #define QCASPI_TX_TIMEOUT (1 * HZ)
 #define QCASPI_QCA7K_REBOOT_TIME_MS 1000
 
@@ -402,7 +402,7 @@ qcaspi_tx_ring_has_space(struct tx_ring *txr)
if (txr->skb[txr->tail])
return 0;
 
-   return (txr->size + QCAFRM_ETHMAXLEN < QCASPI_HW_BUF_LEN) ? 1 : 0;
+   return (txr->size + QCAFRM_MAX_LEN < QCASPI_HW_BUF_LEN) ? 1 : 0;
 }
 
 /*   Flush the tx ring. This function is only safe to
@@ -666,8 +666,8 @@ qcaspi_netdev_xmit(struct sk_buff *skb, struct net_device 
*dev)
struct sk_buff *tskb;
u8 pad_len = 0;
 
-   if (skb->len < QCAFRM_ETHMINLEN)
-   pad_len = QCAFRM_ETHMINLEN - skb->len;
+   if (skb->len < QCAFRM_MIN_LEN)
+   pad_len = QCAFRM_MIN_LEN - skb->len;
 
if (qca->txr.skb[qca->txr.tail]) {
netdev_warn(qca->net_dev, "queue was unexpectedly full!\n");
@@ -804,8 +804,8 @@ qcaspi_netdev_setup(struct net_device *dev)
dev->tx_queue_len = 100;
 
/* MTU range: 46 - 1500 */
-   dev->min_mtu = QCAFRM_ETHMINMTU;
-   dev->max_mtu = QCAFRM_ETHMAXMTU;
+   dev->min_mtu = QCAFRM_MIN_MTU;
+   dev->max_mtu = QCAFRM_MAX_MTU;
 
qca = netdev_priv(dev);
memset(qca, 0, sizeof(struct qcaspi));
-- 
2.1.4



[PATCH v5 09/17] net: qualcomm: rename qca_framing.c to qca_7k_common.c

2017-05-10 Thread Stefan Wahren
As preparation for the upcoming UART driver we need a module
which contains common functions for both interfaces. The module
qca_framing is a good candidate but renaming to qca_7k_common would
make it clear.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/Makefile   | 2 +-
 drivers/net/ethernet/qualcomm/{qca_framing.c => qca_7k_common.c} | 2 +-
 drivers/net/ethernet/qualcomm/{qca_framing.h => qca_7k_common.h} | 0
 drivers/net/ethernet/qualcomm/qca_spi.c  | 2 +-
 drivers/net/ethernet/qualcomm/qca_spi.h  | 2 +-
 5 files changed, 4 insertions(+), 4 deletions(-)
 rename drivers/net/ethernet/qualcomm/{qca_framing.c => qca_7k_common.c} (99%)
 rename drivers/net/ethernet/qualcomm/{qca_framing.h => qca_7k_common.h} (100%)

diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index aacb0a5..5e17bf1 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -3,6 +3,6 @@
 #
 
 obj-$(CONFIG_QCA7000) += qcaspi.o
-qcaspi-objs := qca_spi.o qca_framing.o qca_7k.o qca_debug.o
+qcaspi-objs := qca_spi.o qca_7k_common.o qca_7k.o qca_debug.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_framing.c 
b/drivers/net/ethernet/qualcomm/qca_7k_common.c
similarity index 99%
rename from drivers/net/ethernet/qualcomm/qca_framing.c
rename to drivers/net/ethernet/qualcomm/qca_7k_common.c
index 2341f2b..6d17fbd 100644
--- a/drivers/net/ethernet/qualcomm/qca_framing.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k_common.c
@@ -23,7 +23,7 @@
 
 #include 
 
-#include "qca_framing.h"
+#include "qca_7k_common.h"
 
 u16
 qcafrm_create_header(u8 *buf, u16 length)
diff --git a/drivers/net/ethernet/qualcomm/qca_framing.h 
b/drivers/net/ethernet/qualcomm/qca_7k_common.h
similarity index 100%
rename from drivers/net/ethernet/qualcomm/qca_framing.h
rename to drivers/net/ethernet/qualcomm/qca_7k_common.h
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index deec70f..2bc3ba4 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -43,8 +43,8 @@
 #include 
 
 #include "qca_7k.h"
+#include "qca_7k_common.h"
 #include "qca_debug.h"
-#include "qca_framing.h"
 #include "qca_spi.h"
 
 #define MAX_DMA_BURST_LEN 5000
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.h 
b/drivers/net/ethernet/qualcomm/qca_spi.h
index 064853d..fc4beb1 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.h
+++ b/drivers/net/ethernet/qualcomm/qca_spi.h
@@ -32,7 +32,7 @@
 #include 
 #include 
 
-#include "qca_framing.h"
+#include "qca_7k_common.h"
 
 #define QCASPI_DRV_VERSION "0.2.7-i"
 #define QCASPI_DRV_NAME"qcaspi"
-- 
2.1.4



[PATCH v5 03/17] net: qca_7k: Use BIT macro

2017-05-10 Thread Stefan Wahren
Use the BIT macro for the CONFIG and INT register values.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_7k.h | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_7k.h 
b/drivers/net/ethernet/qualcomm/qca_7k.h
index 1cad851..4047f0a 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.h
+++ b/drivers/net/ethernet/qualcomm/qca_7k.h
@@ -54,15 +54,15 @@
 #define SPI_REG_ACTION_CTRL 0x1B00
 
 /*   SPI_CONFIG register definition; */
-#define QCASPI_SLAVE_RESET_BIT (1 << 6)
+#define QCASPI_SLAVE_RESET_BIT  BIT(6)
 
 /*   INTR_CAUSE/ENABLE register definition.  */
-#define SPI_INT_WRBUF_BELOW_WM (1 << 10)
-#define SPI_INT_CPU_ON (1 << 6)
-#define SPI_INT_ADDR_ERR   (1 << 3)
-#define SPI_INT_WRBUF_ERR  (1 << 2)
-#define SPI_INT_RDBUF_ERR  (1 << 1)
-#define SPI_INT_PKT_AVLBL  (1 << 0)
+#define SPI_INT_WRBUF_BELOW_WM  BIT(10)
+#define SPI_INT_CPU_ON  BIT(6)
+#define SPI_INT_ADDR_ERRBIT(3)
+#define SPI_INT_WRBUF_ERR   BIT(2)
+#define SPI_INT_RDBUF_ERR   BIT(1)
+#define SPI_INT_PKT_AVLBL   BIT(0)
 
 void qcaspi_spi_error(struct qcaspi *qca);
 int qcaspi_read_register(struct qcaspi *qca, u16 reg, u16 *result);
-- 
2.1.4



[PATCH v5 16/17] tty: serdev-ttyport: return actual baudrate from ttyport_set_baudrate

2017-05-10 Thread Stefan Wahren
Instead of returning the requested baudrate, we better return the
actual one because it isn't always the same.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
Acked-by: Rob Herring <r...@kernel.org>
---
 drivers/tty/serdev/serdev-ttyport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serdev/serdev-ttyport.c 
b/drivers/tty/serdev/serdev-ttyport.c
index 487c88f..2cfdf34 100644
--- a/drivers/tty/serdev/serdev-ttyport.c
+++ b/drivers/tty/serdev/serdev-ttyport.c
@@ -151,7 +151,7 @@ static unsigned int ttyport_set_baudrate(struct 
serdev_controller *ctrl, unsigne
 
/* tty_set_termios() return not checked as it is always 0 */
tty_set_termios(tty, );
-   return speed;
+   return ktermios.c_ospeed;
 }
 
 static void ttyport_set_flow_control(struct serdev_controller *ctrl, bool 
enable)
-- 
2.1.4



[PATCH] net: qca_spi: Fix alignment issues in rx path

2017-05-09 Thread Stefan Wahren
The qca_spi driver causes alignment issues on ARM devices.
So fix this by using netdev_alloc_skb_ip_align().

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
Fixes: 291ab06ecf67 ("net: qualcomm: new Ethernet over SPI driver for QCA7000")
---
 drivers/net/ethernet/qualcomm/qca_spi.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 513e6c7..24ca7df 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -296,8 +296,9 @@ qcaspi_receive(struct qcaspi *qca)
 
/* Allocate rx SKB if we don't have one available. */
if (!qca->rx_skb) {
-   qca->rx_skb = netdev_alloc_skb(net_dev,
-  net_dev->mtu + VLAN_ETH_HLEN);
+   qca->rx_skb = netdev_alloc_skb_ip_align(net_dev,
+   net_dev->mtu +
+   VLAN_ETH_HLEN);
if (!qca->rx_skb) {
netdev_dbg(net_dev, "out of RX resources\n");
qca->stats.out_of_mem++;
@@ -377,7 +378,7 @@ qcaspi_receive(struct qcaspi *qca)
qca->rx_skb, qca->rx_skb->dev);
qca->rx_skb->ip_summed = CHECKSUM_UNNECESSARY;
netif_rx_ni(qca->rx_skb);
-   qca->rx_skb = netdev_alloc_skb(net_dev,
+   qca->rx_skb = netdev_alloc_skb_ip_align(net_dev,
net_dev->mtu + VLAN_ETH_HLEN);
if (!qca->rx_skb) {
netdev_dbg(net_dev, "out of RX 
resources\n");
@@ -759,7 +760,8 @@ qcaspi_netdev_init(struct net_device *dev)
if (!qca->rx_buffer)
return -ENOBUFS;
 
-   qca->rx_skb = netdev_alloc_skb(dev, qca->net_dev->mtu + VLAN_ETH_HLEN);
+   qca->rx_skb = netdev_alloc_skb_ip_align(dev, qca->net_dev->mtu +
+   VLAN_ETH_HLEN);
if (!qca->rx_skb) {
kfree(qca->rx_buffer);
netdev_info(qca->net_dev, "Failed to allocate RX sk_buff.\n");
-- 
2.1.4



Re: [PATCH] qca_debug: Reduce function calls for sequence output in qcaspi_info_show()

2017-05-09 Thread Stefan Wahren
Am 08.05.2017 um 19:29 schrieb SF Markus Elfring:
> From: Markus Elfring 
> Date: Mon, 8 May 2017 19:21:27 +0200
>
> A bit of data was put into a sequence by separate function calls.
> Print the same data together with adjusted seq_printf() calls instead.

Sorry, i'm not happy with this patch. It doesn't increase readabilityand
mixes the output of multiple lines.

The only benefit is a little bit higher performance. But for debugfs
this won't be necessary.

Stefan

>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring 
> ---
>  drivers/net/ethernet/qualcomm/qca_debug.c | 10 ++
>  1 file changed, 2 insertions(+), 8 deletions(-)
>




Re: [PATCH RFC v4 10/10] tty: serdev: add functions to retrieve common UART settings

2017-03-28 Thread Stefan Wahren
Am 27.03.2017 um 22:00 schrieb Rob Herring:
> On Mon, Mar 27, 2017 at 8:37 AM, Stefan Wahren <stefan.wah...@i2se.com> wrote:
>> Currently serdev core doesn't provide functions to retrieve common
>> UART settings like data bits, stop bits or parity. This patch adds
>> the interface to the core and the necessary implementation for
>> serdev-ttyport.
> It doesn't provide them because why do you need to know? The attached
> device should request the settings it needs and be done with it. Maybe
> some devices can support a number of settings and you could want
> negotiate the settings with the UART, though surely 8N1 is in that
> list. It's rare to see something that's not 8N1 from what I've seen.

During development it's very helpful to check the current UART settings
and error counter. Currently i can't see a replacement for
/sys/class/tty/ttyXYZ .

Are there any plans about it?

>
> Rob




Re: [PATCH RFC v4 06/10] net: qualcomm: make qca_common a separate kernel module

2017-03-28 Thread Stefan Wahren
Am 27.03.2017 um 17:44 schrieb Dan Williams:
> On Mon, 2017-03-27 at 15:37 +0200, Stefan Wahren wrote:
>> In order to share common functions between QCA7000 SPI and UART
>> protocol
>> driver the qca_common needs to be a separate kernel module.
> Maybe "qca_eth_common"?  There are many things Qualcomm, slightly fewer
> things Qualcomm Atheros, and "qca_common" isn't very descriptive.

Since it is a Homeplug powerline chip which doesn't have any physical
connection to Ethernet only on protocol level, i wouldn't use eth in the
module name.

The code is very specific to the QCA7000, so how about "qca_7k_common"?

>
> Dan
>
>> Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
>> ---
>>  drivers/net/ethernet/qualcomm/Kconfig  |  8 +++-
>>  drivers/net/ethernet/qualcomm/Makefile |  5 +++--
>>  drivers/net/ethernet/qualcomm/qca_common.c | 10 ++
>>  3 files changed, 20 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/qualcomm/Kconfig
>> b/drivers/net/ethernet/qualcomm/Kconfig
>> index d7720bf..b4c369d 100644
>> --- a/drivers/net/ethernet/qualcomm/Kconfig
>> +++ b/drivers/net/ethernet/qualcomm/Kconfig
>> @@ -16,7 +16,13 @@ config NET_VENDOR_QUALCOMM
>>  if NET_VENDOR_QUALCOMM
>>  
>>  config QCA7000
>> -tristate "Qualcomm Atheros QCA7000 support"
>> +tristate
>> +help
>> +  This enables support for the Qualcomm Atheros QCA7000.
>> +
>> +config QCA7000_SPI
>> +tristate "Qualcomm Atheros QCA7000 SPI support"
>> +select QCA7000
>>  depends on SPI_MASTER && OF
>>  ---help---
>>This SPI protocol driver supports the Qualcomm Atheros
>> QCA7000.
>> diff --git a/drivers/net/ethernet/qualcomm/Makefile
>> b/drivers/net/ethernet/qualcomm/Makefile
>> index 8080570..00d8729 100644
>> --- a/drivers/net/ethernet/qualcomm/Makefile
>> +++ b/drivers/net/ethernet/qualcomm/Makefile
>> @@ -2,7 +2,8 @@
>>  # Makefile for the Qualcomm network device drivers.
>>  #
>>  
>> -obj-$(CONFIG_QCA7000) += qcaspi.o
>> -qcaspi-objs := qca_spi.o qca_common.o qca_7k.o qca_debug.o
>> +obj-$(CONFIG_QCA7000) += qca_common.o
>> +obj-$(CONFIG_QCA7000_SPI) += qcaspi.o
>> +qcaspi-objs := qca_7k.o qca_debug.o qca_spi.o
>>  
>>  obj-y += emac/
>> diff --git a/drivers/net/ethernet/qualcomm/qca_common.c
>> b/drivers/net/ethernet/qualcomm/qca_common.c
>> index d930524..f2c9e76 100644
>> --- a/drivers/net/ethernet/qualcomm/qca_common.c
>> +++ b/drivers/net/ethernet/qualcomm/qca_common.c
>> @@ -21,7 +21,9 @@
>>   *   by an atheros frame while transmitted over a serial channel;
>>   */
>>  
>> +#include 
>>  #include 
>> +#include 
>>  
>>  #include "qca_common.h"
>>  
>> @@ -46,6 +48,7 @@ qcafrm_create_header(u8 *buf, u16 length)
>>  
>>  return QCAFRM_HEADER_LEN;
>>  }
>> +EXPORT_SYMBOL_GPL(qcafrm_create_header);
>>  
>>  u16
>>  qcafrm_create_footer(u8 *buf)
>> @@ -57,6 +60,7 @@ qcafrm_create_footer(u8 *buf)
>>  buf[1] = 0x55;
>>  return QCAFRM_FOOTER_LEN;
>>  }
>> +EXPORT_SYMBOL_GPL(qcafrm_create_footer);
>>  
>>  /*   Gather received bytes and try to extract a full ethernet frame
>> by
>>   *   following a simple state machine.
>> @@ -154,3 +158,9 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle,
>> u8 *buf, u16 buf_len, u8 recv_by
>>  
>>  return ret;
>>  }
>> +EXPORT_SYMBOL_GPL(qcafrm_fsm_decode);
>> +
>> +MODULE_DESCRIPTION("Qualcomm Atheros Common");
>> +MODULE_AUTHOR("Qualcomm Atheros Communications");
>> +MODULE_AUTHOR("Stefan Wahren <stefan.wah...@i2se.com>");
>> +MODULE_LICENSE("Dual BSD/GPL");


*** Diese E-Mail ist allein für den bezeichneten Adressaten bestimmt. Sie kann 
rechtlich vertrauliche Informationen enthalten. Wenn Sie diese E-Mail 
irrtümlich erhalten haben, informieren Sie bitte unverzüglich den Absender per 
E-Mail und löschen Sie diese E-Mail von Ihrem Computer, ohne Kopien 
anzufertigen.
Vielen Dank. ***

*** This email is for the exclusive use of the addressee. It may contain 
legally privileged information. If you have received this message in error, 
please notify the sender by email immediately and delete the message from your 
computer without making any copies.
Thank you. ***



Re: [PATCH RFC v4 07/10] dt-bindings: net: add binding for QCA7000 UART

2017-03-28 Thread Stefan Wahren
Am 27.03.2017 um 22:30 schrieb Rob Herring:
> On Mon, Mar 27, 2017 at 8:37 AM, Stefan Wahren <stefan.wah...@i2se.com> wrote:
>> This is the serdev binding for the QCA7000 UART driver (Ethernet over UART).
>>
>> Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
>> ---
>>
>> According to this binding are still some questions:
>>
>> Where should be the optional hardware flow control defined (at master or 
>> slave side)?
> Probably should be in the slave side. We already have uart-has-rtscts
> and rts/cts-gpios for the UART. Those mean we have RTS/CTS, but not
> necessarily that we want to enable them.
>
> In many cases, the driver may know what it needs.

Like all the other UART settings the hardware flow control can be
configured in the QCA7000 firmware and the driver can't detect it.

Property suggestion for the slave side:

use-rtscts


>
>> Is it okay to have two bindings (qca-qca7000-spi and qca-qca7000-uart) or 
>> should they be merged?
> Are they mutually-exclusive or both are used at the same time?

They are mutually-exclusive because they use the same pins.

>  What
> are the dependencies between the interfaces?

Except they uses the same pins of the QCA7000, i can't see any dependency.

>
>>
>>  .../devicetree/bindings/net/qca-qca7000-uart.txt   | 31 
>> ++
>>  1 file changed, 31 insertions(+)
>>  create mode 100644 
>> Documentation/devicetree/bindings/net/qca-qca7000-uart.txt
>>
>> diff --git a/Documentation/devicetree/bindings/net/qca-qca7000-uart.txt 
>> b/Documentation/devicetree/bindings/net/qca-qca7000-uart.txt
>> new file mode 100644
>> index 000..f2e0450
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/net/qca-qca7000-uart.txt
>> @@ -0,0 +1,31 @@
>> +* Qualcomm QCA7000 (Ethernet over UART protocol)
>> +
>> +Note: This binding applies in case the QCA7000 is configured as a
>> +UART slave device. It is possible to preconfigure the UART settings
>> +of the QCA7000 firmware, which can't be changed during runtime.
>> +
>> +Required properties:
>> +- compatible: Should be "qca,qca7000-uart"
>> +
>> +Optional properties:
>> +- local-mac-address : 6 bytes, Specifies MAC address
> The description can be "see ./ethernet.txt"
>
>> +- current-speed : Specifies the serial device speed in
>> + bits per second (default = 115200), which is
>> + predefined by the QCA7000 firmware configuration
> Add this to the slave binding doc with some caveats as to when this
> should or should not be used as we discussed.
>
> Rob



[PATCH RFC v4 09/10] tty: serdev-ttyport: return actual baudrate from ttyport_set_baudrate

2017-03-27 Thread Stefan Wahren
Instead of returning the requested baudrate, we better return the
actual one because it isn't always the same.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/tty/serdev/serdev-ttyport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serdev/serdev-ttyport.c 
b/drivers/tty/serdev/serdev-ttyport.c
index d053935..8a30abe 100644
--- a/drivers/tty/serdev/serdev-ttyport.c
+++ b/drivers/tty/serdev/serdev-ttyport.c
@@ -150,7 +150,7 @@ static unsigned int ttyport_set_baudrate(struct 
serdev_controller *ctrl, unsigne
 
/* tty_set_termios() return not checked as it is always 0 */
tty_set_termios(tty, );
-   return speed;
+   return ktermios.c_ospeed;
 }
 
 static void ttyport_set_flow_control(struct serdev_controller *ctrl, bool 
enable)
-- 
2.1.4



[PATCH RFC v4 02/10] net: qca_debug: use net_device_ops instead of direct call

2017-03-27 Thread Stefan Wahren
There is no need to export qcaspi_netdev_open and qcaspi_netdev_close
because they are also accessible via the net_device_ops.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_debug.c | 5 +++--
 drivers/net/ethernet/qualcomm/qca_spi.h   | 3 ---
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_debug.c 
b/drivers/net/ethernet/qualcomm/qca_debug.c
index d145df9..92b6be9 100644
--- a/drivers/net/ethernet/qualcomm/qca_debug.c
+++ b/drivers/net/ethernet/qualcomm/qca_debug.c
@@ -275,6 +275,7 @@ qcaspi_get_ringparam(struct net_device *dev, struct 
ethtool_ringparam *ring)
 static int
 qcaspi_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
 {
+   const struct net_device_ops *ops = dev->netdev_ops;
struct qcaspi *qca = netdev_priv(dev);
 
if ((ring->rx_pending) ||
@@ -283,13 +284,13 @@ qcaspi_set_ringparam(struct net_device *dev, struct 
ethtool_ringparam *ring)
return -EINVAL;
 
if (netif_running(dev))
-   qcaspi_netdev_close(dev);
+   ops->ndo_stop(dev);
 
qca->txr.count = max_t(u32, ring->tx_pending, TX_RING_MIN_LEN);
qca->txr.count = min_t(u16, qca->txr.count, TX_RING_MAX_LEN);
 
if (netif_running(dev))
-   qcaspi_netdev_open(dev);
+   ops->ndo_open(dev);
 
return 0;
 }
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.h 
b/drivers/net/ethernet/qualcomm/qca_spi.h
index 6e31a0e..064853d 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.h
+++ b/drivers/net/ethernet/qualcomm/qca_spi.h
@@ -108,7 +108,4 @@ struct qcaspi {
u16 burst_len;
 };
 
-int qcaspi_netdev_open(struct net_device *dev);
-int qcaspi_netdev_close(struct net_device *dev);
-
 #endif /* _QCA_SPI_H */
-- 
2.1.4



[PATCH RFC v4 08/10] net: qualcomm: add QCA7000 UART driver

2017-03-27 Thread Stefan Wahren
This patch adds the Ethernet over UART driver for the
Qualcomm QCA7000 HomePlug GreenPHY.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/Kconfig  |  10 +
 drivers/net/ethernet/qualcomm/Makefile |   2 +
 drivers/net/ethernet/qualcomm/qca_common.h |   6 +
 drivers/net/ethernet/qualcomm/qca_uart.c   | 419 +
 4 files changed, 437 insertions(+)
 create mode 100644 drivers/net/ethernet/qualcomm/qca_uart.c

diff --git a/drivers/net/ethernet/qualcomm/Kconfig 
b/drivers/net/ethernet/qualcomm/Kconfig
index b4c369d..ad6b5a4 100644
--- a/drivers/net/ethernet/qualcomm/Kconfig
+++ b/drivers/net/ethernet/qualcomm/Kconfig
@@ -30,6 +30,16 @@ config QCA7000_SPI
  To compile this driver as a module, choose M here. The module
  will be called qcaspi.
 
+config QCA7000_UART
+   tristate "Qualcomm Atheros QCA7000 UART support"
+   select QCA7000
+   depends on SERIAL_DEV_BUS && OF
+   ---help---
+ This UART protocol driver supports the Qualcomm Atheros QCA7000.
+
+ To compile this driver as a module, choose M here. The module
+ will be called qcauart.
+
 config QCOM_EMAC
tristate "Qualcomm Technologies, Inc. EMAC Gigabit Ethernet support"
depends on HAS_DMA && HAS_IOMEM
diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index 00d8729..8847db7 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -5,5 +5,7 @@
 obj-$(CONFIG_QCA7000) += qca_common.o
 obj-$(CONFIG_QCA7000_SPI) += qcaspi.o
 qcaspi-objs := qca_7k.o qca_debug.o qca_spi.o
+obj-$(CONFIG_QCA7000_UART) += qcauart.o
+qcauart-objs := qca_uart.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_common.h 
b/drivers/net/ethernet/qualcomm/qca_common.h
index 431f99d..539399e 100644
--- a/drivers/net/ethernet/qualcomm/qca_common.h
+++ b/drivers/net/ethernet/qualcomm/qca_common.h
@@ -122,6 +122,12 @@ static inline void qcafrm_fsm_init_spi(struct 
qcafrm_handle *handle)
handle->state = handle->init;
 }
 
+static inline void qcafrm_fsm_init_uart(struct qcafrm_handle *handle)
+{
+   handle->init = QCAFRM_WAIT_AA1;
+   handle->state = handle->init;
+}
+
 /*   Gather received bytes and try to extract a full Ethernet frame
  *   by following a simple state machine.
  *
diff --git a/drivers/net/ethernet/qualcomm/qca_uart.c 
b/drivers/net/ethernet/qualcomm/qca_uart.c
new file mode 100644
index 000..81a0353
--- /dev/null
+++ b/drivers/net/ethernet/qualcomm/qca_uart.c
@@ -0,0 +1,419 @@
+/*
+ *   Copyright (c) 2011, 2012, Qualcomm Atheros Communications Inc.
+ *   Copyright (c) 2017, I2SE GmbH
+ *
+ *   Permission to use, copy, modify, and/or distribute this software
+ *   for any purpose with or without fee is hereby granted, provided
+ *   that the above copyright notice and this permission notice appear
+ *   in all copies.
+ *
+ *   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ *   WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ *   WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ *   THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
+ *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ *   LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ *   NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ *   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*   This module implements the Qualcomm Atheros UART protocol for
+ *   kernel-based UART device; it is essentially an Ethernet-to-UART
+ *   serial converter;
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "qca_common.h"
+
+#define QCAUART_DRV_VERSION "0.1.0"
+#define QCAUART_DRV_NAME "qcauart"
+#define QCAUART_TX_TIMEOUT (1 * HZ)
+
+struct qcauart {
+   struct net_device *net_dev;
+   spinlock_t lock;/* transmit lock */
+   struct work_struct tx_work; /* Flushes transmit buffer   */
+
+   struct serdev_device *serdev;
+
+   unsigned char xbuff[QCAFRM_ETHMAXMTU];  /* transmitter buffer*/
+   unsigned char *xhead;   /* pointer to next XMIT byte */
+   int xleft;  /* bytes left in XMIT queue  */
+
+   struct qcafrm_handle frm_handle;
+
+   struct sk_buff *rx_skb;
+};
+
+static int
+qca_tty_receive(struct serdev_device *serdev, const unsigned char *data,
+   size_t count)
+{
+   struct qcauart *qca = serdev_device_get_drvdata(serdev);
+   struct net_device_stats *n_stats = >net_dev->stats;
+   size_t i;
+
+   if (!qca->rx_skb) {
+   qca->rx_skb = ne

[PATCH RFC v4 00/10] net: qualcomm: add QCA7000 UART driver

2017-03-27 Thread Stefan Wahren
The Qualcomm QCA7000 HomePlug GreenPHY supports two interfaces:
UART and SPI. This patch series adds the missing support for UART.

This driver based on the Qualcomm code [1], but contains some changes:
* use random MAC address per default
* use net_device_stats from device
* share frame decoding between SPI and UART driver
* improve error handling
* reimplement tty_wakeup with work queue (based on slcan)
* use new serial device bus instead of ldisc

The patches 1 - 3 are just for clean up and are not related to
the UART support. Patches 4 - 7 prepare the existing QCA7000
code for UART support. Patch 8 contains the new driver. The last
two patches are suggested improvements for serial device bus.

The code itself has been tested on a Freescale i.MX28 board and
a Raspberry Pi Zero.

Changes in v4:
  * rebase to current linux-next
  * use parameter -M for git format-patch
  * change order of local variables where possible
  * implement basic serdev support (without hardware flow control)

Changes in v3:
  * rebase to current net-next

Changes in v2:
  * fix build issue by using netif_trans_update() and dev_trans_start()

[1] - https://github.com/IoE/qca7000

Stefan Wahren (10):
  net: qualcomm: remove unnecessary includes
  net: qca_debug: use net_device_ops instead of direct call
  net: qualcomm: move qcaspi_tx_cmd to qca_spi.c
  net: qualcomm: rename qca_framing.c to qca_common.c
  net: qualcomm: prepare frame decoding for UART driver
  net: qualcomm: make qca_common a separate kernel module
  dt-bindings: net: add binding for QCA7000 UART
  net: qualcomm: add QCA7000 UART driver
  tty: serdev-ttyport: return actual baudrate from ttyport_set_baudrate
  tty: serdev: add functions to retrieve common UART settings

 .../devicetree/bindings/net/qca-qca7000-uart.txt   |  31 ++
 drivers/net/ethernet/qualcomm/Kconfig  |  18 +-
 drivers/net/ethernet/qualcomm/Makefile |   7 +-
 drivers/net/ethernet/qualcomm/qca_7k.c |  28 --
 drivers/net/ethernet/qualcomm/qca_7k.h |   1 -
 .../qualcomm/{qca_framing.c => qca_common.c}   |  24 +-
 .../qualcomm/{qca_framing.h => qca_common.h}   |  14 +-
 drivers/net/ethernet/qualcomm/qca_debug.c  |   5 +-
 drivers/net/ethernet/qualcomm/qca_spi.c|  28 +-
 drivers/net/ethernet/qualcomm/qca_spi.h|   5 +-
 drivers/net/ethernet/qualcomm/qca_uart.c   | 419 +
 drivers/tty/serdev/core.c  |  33 ++
 drivers/tty/serdev/serdev-ttyport.c|  49 ++-
 include/linux/serdev.h |  22 ++
 14 files changed, 634 insertions(+), 50 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/qca-qca7000-uart.txt
 rename drivers/net/ethernet/qualcomm/{qca_framing.c => qca_common.c} (86%)
 rename drivers/net/ethernet/qualcomm/{qca_framing.h => qca_common.h} (90%)
 create mode 100644 drivers/net/ethernet/qualcomm/qca_uart.c

-- 
2.1.4



[PATCH RFC v4 05/10] net: qualcomm: prepare frame decoding for UART driver

2017-03-27 Thread Stefan Wahren
Unfortunately the frame format is not exactly identical between SPI
and UART. In case of SPI there is an additional HW length at the
beginning. So store the initial state to make the decoding state machine
more flexible and easy to extend for UART support.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_common.c | 12 ++--
 drivers/net/ethernet/qualcomm/qca_common.h |  8 ++--
 drivers/net/ethernet/qualcomm/qca_spi.c|  2 +-
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_common.c 
b/drivers/net/ethernet/qualcomm/qca_common.c
index 26453a9..d930524 100644
--- a/drivers/net/ethernet/qualcomm/qca_common.c
+++ b/drivers/net/ethernet/qualcomm/qca_common.c
@@ -83,7 +83,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 
buf_len, u8 recv_by
 
if (recv_byte != 0x00) {
/* first two bytes of length must be 0 */
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
}
break;
case QCAFRM_HW_LEN2:
@@ -97,7 +97,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 
buf_len, u8 recv_by
case QCAFRM_WAIT_AA4:
if (recv_byte != 0xAA) {
ret = QCAFRM_NOHEAD;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state--;
}
@@ -119,7 +119,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
len = handle->offset;
if (len > buf_len || len < QCAFRM_ETHMINLEN) {
ret = QCAFRM_INVLEN;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state = (enum qcafrm_state)(len + 1);
/* Remaining number of bytes. */
@@ -135,7 +135,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
case QCAFRM_WAIT_551:
if (recv_byte != 0x55) {
ret = QCAFRM_NOTAIL;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state = QCAFRM_WAIT_552;
}
@@ -143,11 +143,11 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
case QCAFRM_WAIT_552:
if (recv_byte != 0x55) {
ret = QCAFRM_NOTAIL;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
ret = handle->offset;
/* Frame is fully received. */
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
}
break;
}
diff --git a/drivers/net/ethernet/qualcomm/qca_common.h 
b/drivers/net/ethernet/qualcomm/qca_common.h
index d5e795d..431f99d 100644
--- a/drivers/net/ethernet/qualcomm/qca_common.h
+++ b/drivers/net/ethernet/qualcomm/qca_common.h
@@ -61,6 +61,7 @@
 #define QCAFRM_ERR_BASE -1000
 
 enum qcafrm_state {
+   /* HW length is only available on SPI */
QCAFRM_HW_LEN0 = 0x8000,
QCAFRM_HW_LEN1 = QCAFRM_HW_LEN0 - 1,
QCAFRM_HW_LEN2 = QCAFRM_HW_LEN1 - 1,
@@ -101,6 +102,8 @@ enum qcafrm_state {
 struct qcafrm_handle {
/*  Current decoding state */
enum qcafrm_state state;
+   /* Initial state depends on connection type */
+   enum qcafrm_state init;
 
/* Offset in buffer (borrowed for length too) */
s16 offset;
@@ -113,9 +116,10 @@ u16 qcafrm_create_header(u8 *buf, u16 len);
 
 u16 qcafrm_create_footer(u8 *buf);
 
-static inline void qcafrm_fsm_init(struct qcafrm_handle *handle)
+static inline void qcafrm_fsm_init_spi(struct qcafrm_handle *handle)
 {
-   handle->state = QCAFRM_HW_LEN0;
+   handle->init = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
 }
 
 /*   Gather received bytes and try to extract a full Ethernet frame
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 65adc10..3617bde 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -638,7 +638,7 @@ qcaspi_netdev_open(struct net_device *dev)
qca->intr_req = 1;
qca->intr_svc = 0;
qca->sync = QCASPI_SYNC_UNKNOWN;
-   qcafrm_fsm_init(>frm_handle);
+   qcafrm_fsm_init_spi(>frm_handle);
 
qca->spi_thread = kthread_run((void *)qcaspi_spi_thread,
  qca, "%s", dev->name);
-- 
2.1.4



[PATCH RFC v4 07/10] dt-bindings: net: add binding for QCA7000 UART

2017-03-27 Thread Stefan Wahren
This is the serdev binding for the QCA7000 UART driver (Ethernet over UART).

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---

According to this binding are still some questions:

Where should be the optional hardware flow control defined (at master or slave 
side)?

Is it okay to have two bindings (qca-qca7000-spi and qca-qca7000-uart) or 
should they be merged?


 .../devicetree/bindings/net/qca-qca7000-uart.txt   | 31 ++
 1 file changed, 31 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/qca-qca7000-uart.txt

diff --git a/Documentation/devicetree/bindings/net/qca-qca7000-uart.txt 
b/Documentation/devicetree/bindings/net/qca-qca7000-uart.txt
new file mode 100644
index 000..f2e0450
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/qca-qca7000-uart.txt
@@ -0,0 +1,31 @@
+* Qualcomm QCA7000 (Ethernet over UART protocol)
+
+Note: This binding applies in case the QCA7000 is configured as a
+UART slave device. It is possible to preconfigure the UART settings
+of the QCA7000 firmware, which can't be changed during runtime.
+
+Required properties:
+- compatible: Should be "qca,qca7000-uart"
+
+Optional properties:
+- local-mac-address : 6 bytes, Specifies MAC address
+- current-speed : Specifies the serial device speed in
+ bits per second (default = 115200), which is
+ predefined by the QCA7000 firmware configuration
+
+Example:
+
+/* Freescale i.MX28 UART */
+auart0: serial@8006a000 {
+   compatible = "fsl,imx28-auart", "fsl,imx23-auart";
+   reg = <0x8006a000 0x2000>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_2pins_a>;
+   status = "okay";
+
+   qca7000: ethernet {
+   compatible = "qca,qca7000-uart";
+   local-mac-address = [ A0 B0 C0 D0 E0 F0 ];
+   current-speed = <38400>;
+   };
+};
-- 
2.1.4



[PATCH RFC v4 04/10] net: qualcomm: rename qca_framing.c to qca_common.c

2017-03-27 Thread Stefan Wahren
As preparation for the upcoming UART driver we need a module
which contains common functions for both interfaces. The module
qca_framing is a good candidate but renaming to qca_common would
make it clear.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/Makefile| 2 +-
 drivers/net/ethernet/qualcomm/{qca_framing.c => qca_common.c} | 2 +-
 drivers/net/ethernet/qualcomm/{qca_framing.h => qca_common.h} | 0
 drivers/net/ethernet/qualcomm/qca_spi.c   | 2 +-
 drivers/net/ethernet/qualcomm/qca_spi.h   | 2 +-
 5 files changed, 4 insertions(+), 4 deletions(-)
 rename drivers/net/ethernet/qualcomm/{qca_framing.c => qca_common.c} (99%)
 rename drivers/net/ethernet/qualcomm/{qca_framing.h => qca_common.h} (100%)

diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index aacb0a5..8080570 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -3,6 +3,6 @@
 #
 
 obj-$(CONFIG_QCA7000) += qcaspi.o
-qcaspi-objs := qca_spi.o qca_framing.o qca_7k.o qca_debug.o
+qcaspi-objs := qca_spi.o qca_common.o qca_7k.o qca_debug.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_framing.c 
b/drivers/net/ethernet/qualcomm/qca_common.c
similarity index 99%
rename from drivers/net/ethernet/qualcomm/qca_framing.c
rename to drivers/net/ethernet/qualcomm/qca_common.c
index faa924c..26453a9 100644
--- a/drivers/net/ethernet/qualcomm/qca_framing.c
+++ b/drivers/net/ethernet/qualcomm/qca_common.c
@@ -23,7 +23,7 @@
 
 #include 
 
-#include "qca_framing.h"
+#include "qca_common.h"
 
 u16
 qcafrm_create_header(u8 *buf, u16 length)
diff --git a/drivers/net/ethernet/qualcomm/qca_framing.h 
b/drivers/net/ethernet/qualcomm/qca_common.h
similarity index 100%
rename from drivers/net/ethernet/qualcomm/qca_framing.h
rename to drivers/net/ethernet/qualcomm/qca_common.h
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 4f431bc..65adc10 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -43,8 +43,8 @@
 #include 
 
 #include "qca_7k.h"
+#include "qca_common.h"
 #include "qca_debug.h"
-#include "qca_framing.h"
 #include "qca_spi.h"
 
 #define MAX_DMA_BURST_LEN 5000
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.h 
b/drivers/net/ethernet/qualcomm/qca_spi.h
index 064853d..cce4802 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.h
+++ b/drivers/net/ethernet/qualcomm/qca_spi.h
@@ -32,7 +32,7 @@
 #include 
 #include 
 
-#include "qca_framing.h"
+#include "qca_common.h"
 
 #define QCASPI_DRV_VERSION "0.2.7-i"
 #define QCASPI_DRV_NAME"qcaspi"
-- 
2.1.4



[PATCH RFC v4 03/10] net: qualcomm: move qcaspi_tx_cmd to qca_spi.c

2017-03-27 Thread Stefan Wahren
The function qcaspi_tx_cmd() is only called from qca_spi.c. So we better
move it there.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_7k.c  | 24 
 drivers/net/ethernet/qualcomm/qca_7k.h  |  1 -
 drivers/net/ethernet/qualcomm/qca_spi.c | 24 
 3 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_7k.c 
b/drivers/net/ethernet/qualcomm/qca_7k.c
index 557d53c..aa90a1d 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k.c
@@ -119,27 +119,3 @@ qcaspi_write_register(struct qcaspi *qca, u16 reg, u16 
value)
 
return ret;
 }
-
-int
-qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd)
-{
-   __be16 tx_data;
-   struct spi_message *msg = >spi_msg1;
-   struct spi_transfer *transfer = >spi_xfer1;
-   int ret;
-
-   tx_data = cpu_to_be16(cmd);
-   transfer->len = sizeof(tx_data);
-   transfer->tx_buf = _data;
-   transfer->rx_buf = NULL;
-
-   ret = spi_sync(qca->spi_dev, msg);
-
-   if (!ret)
-   ret = msg->status;
-
-   if (ret)
-   qcaspi_spi_error(qca);
-
-   return ret;
-}
diff --git a/drivers/net/ethernet/qualcomm/qca_7k.h 
b/drivers/net/ethernet/qualcomm/qca_7k.h
index 1cad851..b390b1f 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.h
+++ b/drivers/net/ethernet/qualcomm/qca_7k.h
@@ -67,6 +67,5 @@
 void qcaspi_spi_error(struct qcaspi *qca);
 int qcaspi_read_register(struct qcaspi *qca, u16 reg, u16 *result);
 int qcaspi_write_register(struct qcaspi *qca, u16 reg, u16 value);
-int qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd);
 
 #endif /* _QCA_7K_H */
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 513e6c7..4f431bc 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -193,6 +193,30 @@ qcaspi_read_legacy(struct qcaspi *qca, u8 *dst, u32 len)
 }
 
 static int
+qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd)
+{
+   __be16 tx_data;
+   struct spi_message *msg = >spi_msg1;
+   struct spi_transfer *transfer = >spi_xfer1;
+   int ret;
+
+   tx_data = cpu_to_be16(cmd);
+   transfer->len = sizeof(tx_data);
+   transfer->tx_buf = _data;
+   transfer->rx_buf = NULL;
+
+   ret = spi_sync(qca->spi_dev, msg);
+
+   if (!ret)
+   ret = msg->status;
+
+   if (ret)
+   qcaspi_spi_error(qca);
+
+   return ret;
+}
+
+static int
 qcaspi_tx_frame(struct qcaspi *qca, struct sk_buff *skb)
 {
u32 count;
-- 
2.1.4



[PATCH RFC v4 10/10] tty: serdev: add functions to retrieve common UART settings

2017-03-27 Thread Stefan Wahren
Currently serdev core doesn't provide functions to retrieve common
UART settings like data bits, stop bits or parity. This patch adds
the interface to the core and the necessary implementation for
serdev-ttyport.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/tty/serdev/core.c   | 33 ++
 drivers/tty/serdev/serdev-ttyport.c | 47 +
 include/linux/serdev.h  | 22 +
 3 files changed, 102 insertions(+)

diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c
index 531aa89..7b1e5bf 100644
--- a/drivers/tty/serdev/core.c
+++ b/drivers/tty/serdev/core.c
@@ -173,6 +173,39 @@ void serdev_device_set_flow_control(struct serdev_device 
*serdev, bool enable)
 }
 EXPORT_SYMBOL_GPL(serdev_device_set_flow_control);
 
+int serdev_device_get_data_bits(struct serdev_device *serdev)
+{
+   struct serdev_controller *ctrl = serdev->ctrl;
+
+   if (!ctrl || !ctrl->ops->get_data_bits)
+   return -EINVAL;
+
+   return ctrl->ops->get_data_bits(ctrl);
+}
+EXPORT_SYMBOL_GPL(serdev_device_get_data_bits);
+
+int serdev_device_get_parity(struct serdev_device *serdev)
+{
+   struct serdev_controller *ctrl = serdev->ctrl;
+
+   if (!ctrl || !ctrl->ops->get_parity)
+   return -EINVAL;
+
+   return ctrl->ops->get_parity(ctrl);
+}
+EXPORT_SYMBOL_GPL(serdev_device_get_parity);
+
+int serdev_device_get_stop_bits(struct serdev_device *serdev)
+{
+   struct serdev_controller *ctrl = serdev->ctrl;
+
+   if (!ctrl || !ctrl->ops->get_stop_bits)
+   return -EINVAL;
+
+   return ctrl->ops->get_stop_bits(ctrl);
+}
+EXPORT_SYMBOL_GPL(serdev_device_get_stop_bits);
+
 static int serdev_drv_probe(struct device *dev)
 {
const struct serdev_device_driver *sdrv = 
to_serdev_device_driver(dev->driver);
diff --git a/drivers/tty/serdev/serdev-ttyport.c 
b/drivers/tty/serdev/serdev-ttyport.c
index 8a30abe..5698682 100644
--- a/drivers/tty/serdev/serdev-ttyport.c
+++ b/drivers/tty/serdev/serdev-ttyport.c
@@ -167,6 +167,50 @@ static void ttyport_set_flow_control(struct 
serdev_controller *ctrl, bool enable
tty_set_termios(tty, );
 }
 
+static int ttyport_get_data_bits(struct serdev_controller *ctrl)
+{
+   struct serport *serport = serdev_controller_get_drvdata(ctrl);
+   struct tty_struct *tty = serport->tty;
+   struct ktermios ktermios = tty->termios;
+
+   switch (ktermios.c_cflag & CSIZE) {
+   case CS5:
+   return 5;
+   case CS6:
+   return 6;
+   case CS7:
+   return 7;
+   case CS8:
+   return 8;
+   }
+
+   return 0;
+}
+
+static int ttyport_get_parity(struct serdev_controller *ctrl)
+{
+   struct serport *serport = serdev_controller_get_drvdata(ctrl);
+   struct tty_struct *tty = serport->tty;
+   struct ktermios ktermios = tty->termios;
+
+   if (!(ktermios.c_cflag & PARENB))
+   return SERDEV_PARITY_NONE;
+
+   if (ktermios.c_cflag & PARODD)
+   return SERDEV_PARITY_ODD;
+
+   return SERDEV_PARITY_EVEN;
+}
+
+static int ttyport_get_stop_bits(struct serdev_controller *ctrl)
+{
+   struct serport *serport = serdev_controller_get_drvdata(ctrl);
+   struct tty_struct *tty = serport->tty;
+   struct ktermios ktermios = tty->termios;
+
+   return (ktermios.c_cflag & CSTOPB) ? 2 : 1;
+}
+
 static const struct serdev_controller_ops ctrl_ops = {
.write_buf = ttyport_write_buf,
.write_flush = ttyport_write_flush,
@@ -175,6 +219,9 @@ static const struct serdev_controller_ops ctrl_ops = {
.close = ttyport_close,
.set_flow_control = ttyport_set_flow_control,
.set_baudrate = ttyport_set_baudrate,
+   .get_data_bits = ttyport_get_data_bits,
+   .get_parity = ttyport_get_parity,
+   .get_stop_bits = ttyport_get_stop_bits,
 };
 
 struct device *serdev_tty_port_register(struct tty_port *port,
diff --git a/include/linux/serdev.h b/include/linux/serdev.h
index 5176cdc..6180aa2 100644
--- a/include/linux/serdev.h
+++ b/include/linux/serdev.h
@@ -16,6 +16,10 @@
 #include 
 #include 
 
+#define SERDEV_PARITY_NONE 0
+#define SERDEV_PARITY_ODD  1
+#define SERDEV_PARITY_EVEN 2
+
 struct serdev_controller;
 struct serdev_device;
 
@@ -81,6 +85,9 @@ struct serdev_controller_ops {
void (*close)(struct serdev_controller *);
void (*set_flow_control)(struct serdev_controller *, bool);
unsigned int (*set_baudrate)(struct serdev_controller *, unsigned int);
+   int (*get_data_bits)(struct serdev_controller *);
+   int (*get_parity)(struct serdev_controller *);
+   int (*get_stop_bits)(struct serdev_controller *);
 };
 
 /**
@@ -189,6 +196,9 @@ void serdev_device_set_flow_control(struct serdev_device *, 
bool);
 int serdev_device_write_buf(

[PATCH RFC v4 06/10] net: qualcomm: make qca_common a separate kernel module

2017-03-27 Thread Stefan Wahren
In order to share common functions between QCA7000 SPI and UART protocol
driver the qca_common needs to be a separate kernel module.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/Kconfig  |  8 +++-
 drivers/net/ethernet/qualcomm/Makefile |  5 +++--
 drivers/net/ethernet/qualcomm/qca_common.c | 10 ++
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/Kconfig 
b/drivers/net/ethernet/qualcomm/Kconfig
index d7720bf..b4c369d 100644
--- a/drivers/net/ethernet/qualcomm/Kconfig
+++ b/drivers/net/ethernet/qualcomm/Kconfig
@@ -16,7 +16,13 @@ config NET_VENDOR_QUALCOMM
 if NET_VENDOR_QUALCOMM
 
 config QCA7000
-   tristate "Qualcomm Atheros QCA7000 support"
+   tristate
+   help
+ This enables support for the Qualcomm Atheros QCA7000.
+
+config QCA7000_SPI
+   tristate "Qualcomm Atheros QCA7000 SPI support"
+   select QCA7000
depends on SPI_MASTER && OF
---help---
  This SPI protocol driver supports the Qualcomm Atheros QCA7000.
diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index 8080570..00d8729 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -2,7 +2,8 @@
 # Makefile for the Qualcomm network device drivers.
 #
 
-obj-$(CONFIG_QCA7000) += qcaspi.o
-qcaspi-objs := qca_spi.o qca_common.o qca_7k.o qca_debug.o
+obj-$(CONFIG_QCA7000) += qca_common.o
+obj-$(CONFIG_QCA7000_SPI) += qcaspi.o
+qcaspi-objs := qca_7k.o qca_debug.o qca_spi.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_common.c 
b/drivers/net/ethernet/qualcomm/qca_common.c
index d930524..f2c9e76 100644
--- a/drivers/net/ethernet/qualcomm/qca_common.c
+++ b/drivers/net/ethernet/qualcomm/qca_common.c
@@ -21,7 +21,9 @@
  *   by an atheros frame while transmitted over a serial channel;
  */
 
+#include 
 #include 
+#include 
 
 #include "qca_common.h"
 
@@ -46,6 +48,7 @@ qcafrm_create_header(u8 *buf, u16 length)
 
return QCAFRM_HEADER_LEN;
 }
+EXPORT_SYMBOL_GPL(qcafrm_create_header);
 
 u16
 qcafrm_create_footer(u8 *buf)
@@ -57,6 +60,7 @@ qcafrm_create_footer(u8 *buf)
buf[1] = 0x55;
return QCAFRM_FOOTER_LEN;
 }
+EXPORT_SYMBOL_GPL(qcafrm_create_footer);
 
 /*   Gather received bytes and try to extract a full ethernet frame by
  *   following a simple state machine.
@@ -154,3 +158,9 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
 
return ret;
 }
+EXPORT_SYMBOL_GPL(qcafrm_fsm_decode);
+
+MODULE_DESCRIPTION("Qualcomm Atheros Common");
+MODULE_AUTHOR("Qualcomm Atheros Communications");
+MODULE_AUTHOR("Stefan Wahren <stefan.wah...@i2se.com>");
+MODULE_LICENSE("Dual BSD/GPL");
-- 
2.1.4



[PATCH RFC v4 01/10] net: qualcomm: remove unnecessary includes

2017-03-27 Thread Stefan Wahren
Most of the includes in qca_7k.c are unnecessary so we better remove them.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_7k.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_7k.c 
b/drivers/net/ethernet/qualcomm/qca_7k.c
index f0066fb..557d53c 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k.c
@@ -23,11 +23,7 @@
  *   kernel-based SPI device.
  */
 
-#include 
-#include 
-#include 
 #include 
-#include 
 
 #include "qca_7k.h"
 
-- 
2.1.4



Re: usb/net/hso: WARNING: ungligned urb->setup_dma

2017-03-03 Thread Stefan Wahren
Hi Baruch,

Am 01.03.2017 um 11:54 schrieb Baruch Siach:
> Hi Stefan,
>
> On Tue, Feb 28, 2017 at 07:32:09PM +0100, Stefan Wahren wrote: 
>>> Baruch Siach <bar...@tkos.co.il> hat am 28. Februar 2017 um 19:07 
>>> geschrieben:
>>> On Tue, Feb 28, 2017 at 05:21:18PM +0100, Stefan Wahren wrote:
>>>> Am 28.02.2017 um 13:01 schrieb Baruch Siach:
>>>>> On Tue, Feb 28, 2017 at 10:28:10AM +0200, Baruch Siach wrote:
>>>>>> I'm hitting this warning consistently on my Raspberry Pi 3 running 
>>>>>> kernel
>>>>>> v4.10.1 with some unrelated device tree changes, and a debug print 
>>>>>> (below).
>>>>>> The device identifies as "GlobeTrotter HSDPA Modem", VID: 0af0, PID: 
>>>>>> 6971.
>>>>>> The warning triggers consistently on first write access to /dev/ttyHS0 
>>>>>> that
>>>>>> ModemManager attempts. The first line in the log is my debug print.
>>>>> I tested the same hardware successfully on an i.MX6 CuBox-i (ARM32) using 
>>>>> the
>>>>> same kernel version (4.10.1), and on an x86_64 PC (4.9). So this seems to 
>>>>> be
>>>>> platform specific. I don't have any other ARM64 machine at the moment, 
>>>>> though.
>>>> those platforms usually doesn't use the dwc2 USB host controller. So it
>>>> should be tested with another dwc2 platform.
>>> The code that initializes setup_dma is not under drivers/usb/dwc2/. Though 
>>> the 
>>> problem looks like memory corruption, so its cause might be anywhere.
>> only a suspicion, but could you please try this patch [1]?
>>
>> [1] - https://patchwork.kernel.org/patch/9166771/
> It doesn't change anything.
>
> My guess is that source of the issue is memory corruption that just happens 
> to 
> corrupt also the setup_dma field of struct urb. In other words, it has 
> nothing 
> to do with DMA, IMO.

may you could use

CONFIG_DMA_API_DEBUG

or

CONFIG_SLUB_DEBUG

in order to find the source?

>
> Thanks,
> baruch
>




Re: usb/net/hso: WARNING: ungligned urb->setup_dma

2017-02-28 Thread Stefan Wahren
Hi Baruch,

> Baruch Siach <bar...@tkos.co.il> hat am 28. Februar 2017 um 19:07 geschrieben:
> 
> 
> Hi Stefan,
> 
> On Tue, Feb 28, 2017 at 05:21:18PM +0100, Stefan Wahren wrote:
> > Am 28.02.2017 um 13:01 schrieb Baruch Siach:
> > > On Tue, Feb 28, 2017 at 10:28:10AM +0200, Baruch Siach wrote:
> > > > I'm hitting this warning consistently on my Raspberry Pi 3 running 
> > > > kernel
> > > > v4.10.1 with some unrelated device tree changes, and a debug print 
> > > > (below).
> > > > The device identifies as "GlobeTrotter HSDPA Modem", VID: 0af0, PID: 
> > > > 6971.
> > > > The warning triggers consistently on first write access to /dev/ttyHS0 
> > > > that
> > > > ModemManager attempts. The first line in the log is my debug print.
> > > I tested the same hardware successfully on an i.MX6 CuBox-i (ARM32) using 
> > > the
> > > same kernel version (4.10.1), and on an x86_64 PC (4.9). So this seems to 
> > > be
> > > platform specific. I don't have any other ARM64 machine at the moment, 
> > > though.
> > 
> > those platforms usually doesn't use the dwc2 USB host controller. So it
> > should be tested with another dwc2 platform.
> 
> The code that initializes setup_dma is not under drivers/usb/dwc2/. Though 
> the 
> problem looks like memory corruption, so its cause might be anywhere.

only a suspicion, but could you please try this patch [1]?

[1] - https://patchwork.kernel.org/patch/9166771/


Re: usb/net/hso: WARNING: ungligned urb->setup_dma

2017-02-28 Thread Stefan Wahren

Hi Baruch,

Am 28.02.2017 um 13:01 schrieb Baruch Siach:

Hi linux-usb list,

(Dropped Jan's bouncing address, added Rpi3 platform lists)

On Tue, Feb 28, 2017 at 10:28:10AM +0200, Baruch Siach wrote:

Hi linux-usb list,

I'm hitting this warning consistently on my Raspberry Pi 3 running kernel
v4.10.1 with some unrelated device tree changes, and a debug print (below).
The device identifies as "GlobeTrotter HSDPA Modem", VID: 0af0, PID: 6971.
The warning triggers consistently on first write access to /dev/ttyHS0 that
ModemManager attempts. The first line in the log is my debug print.

I tested the same hardware successfully on an i.MX6 CuBox-i (ARM32) using the
same kernel version (4.10.1), and on an x86_64 PC (4.9). So this seems to be
platform specific. I don't have any other ARM64 machine at the moment, though.


those platforms usually doesn't use the dwc2 USB host controller. So it 
should be tested with another dwc2 platform.


Is the issue reproducible with other USB devices like keyboards?
Are you using arm64 defconfig?
Are you able to bisect this issue?

Stefan


Re: [PATCH v3 net-next 8/8] net: qualcomm: add QCA7000 UART driver

2016-10-21 Thread Stefan Wahren
Am 18.10.2016 um 20:30 schrieb David Miller:
> From: Stefan Wahren <stefan.wah...@i2se.com>
> Date: Tue, 18 Oct 2016 13:27:34 +0200
>
>> +void
>> +qca_tty_receive(struct tty_struct *tty, const unsigned char *cp, char *fp,
>> +int count)
>> +{
>> +struct qcauart *qca = tty->disc_data;
>> +struct net_device_stats *n_stats = >net_dev->stats;
>> +int dropped = 0;
> Please order local variable declarations from longest to shortest line.

Even if the current second init depends on the first one?





[PATCH v3 net-next 8/8] net: qualcomm: add QCA7000 UART driver

2016-10-18 Thread Stefan Wahren
This patch adds the Ethernet over UART driver for the
Qualcomm QCA7000 HomePlug GreenPHY.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/Kconfig  |  12 +
 drivers/net/ethernet/qualcomm/Makefile |   2 +
 drivers/net/ethernet/qualcomm/qca_common.h |   6 +
 drivers/net/ethernet/qualcomm/qca_uart.c   | 447 +
 include/uapi/linux/tty.h   |   1 +
 5 files changed, 468 insertions(+)
 create mode 100644 drivers/net/ethernet/qualcomm/qca_uart.c

diff --git a/drivers/net/ethernet/qualcomm/Kconfig 
b/drivers/net/ethernet/qualcomm/Kconfig
index b4c369d..8c3a5b0 100644
--- a/drivers/net/ethernet/qualcomm/Kconfig
+++ b/drivers/net/ethernet/qualcomm/Kconfig
@@ -30,6 +30,18 @@ config QCA7000_SPI
  To compile this driver as a module, choose M here. The module
  will be called qcaspi.
 
+config QCA7000_UART
+   tristate "Qualcomm Atheros QCA7000 UART support"
+   select QCA7000
+   depends on TTY
+   ---help---
+ This UART protocol driver supports the Qualcomm Atheros QCA7000.
+ The driver implements the tty line discipline N_QCA7K and supports
+ only one netdevice.
+
+ To compile this driver as a module, choose M here. The module
+ will be called qcauart.
+
 config QCOM_EMAC
tristate "Qualcomm Technologies, Inc. EMAC Gigabit Ethernet support"
depends on HAS_DMA && HAS_IOMEM
diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index 00d8729..8847db7 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -5,5 +5,7 @@
 obj-$(CONFIG_QCA7000) += qca_common.o
 obj-$(CONFIG_QCA7000_SPI) += qcaspi.o
 qcaspi-objs := qca_7k.o qca_debug.o qca_spi.o
+obj-$(CONFIG_QCA7000_UART) += qcauart.o
+qcauart-objs := qca_uart.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_common.h 
b/drivers/net/ethernet/qualcomm/qca_common.h
index c93cfdf07..bc38689 100644
--- a/drivers/net/ethernet/qualcomm/qca_common.h
+++ b/drivers/net/ethernet/qualcomm/qca_common.h
@@ -123,6 +123,12 @@ static inline void qcafrm_fsm_init_spi(struct 
qcafrm_handle *handle)
handle->state = handle->init;
 }
 
+static inline void qcafrm_fsm_init_uart(struct qcafrm_handle *handle)
+{
+   handle->init = QCAFRM_WAIT_AA1;
+   handle->state = handle->init;
+}
+
 /*   Gather received bytes and try to extract a full Ethernet frame
  *   by following a simple state machine.
  *
diff --git a/drivers/net/ethernet/qualcomm/qca_uart.c 
b/drivers/net/ethernet/qualcomm/qca_uart.c
new file mode 100644
index 000..0a8dd6d
--- /dev/null
+++ b/drivers/net/ethernet/qualcomm/qca_uart.c
@@ -0,0 +1,447 @@
+/*
+ *   Copyright (c) 2011, 2012, Qualcomm Atheros Communications Inc.
+ *   Copyright (c) 2016, I2SE GmbH
+ *
+ *   Permission to use, copy, modify, and/or distribute this software
+ *   for any purpose with or without fee is hereby granted, provided
+ *   that the above copyright notice and this permission notice appear
+ *   in all copies.
+ *
+ *   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ *   WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ *   WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ *   THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
+ *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ *   LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ *   NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ *   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*   This module implements the Qualcomm Atheros UART protocol for
+ *   kernel-based UART device; it is essentially an Ethernet-to-UART
+ *   serial converter;
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "qca_common.h"
+
+#define QCAUART_DRV_VERSION "0.0.6"
+#define QCAUART_DRV_NAME "qcauart"
+#define QCAUART_TX_TIMEOUT (1 * HZ)
+
+struct qcauart {
+   struct net_device *net_dev;
+   spinlock_t lock;/* transmit lock */
+   struct work_struct tx_work; /* Flushes transmit buffer   */
+
+   struct tty_struct *tty;
+
+   unsigned char xbuff[QCAFRM_ETHMAXMTU];  /* transmitter buffer*/
+   unsigned char *xhead;   /* pointer to next XMIT byte */
+   int xleft;  /* bytes left in XMIT queue  */
+
+   struct qcafrm_handle frm_handle;
+
+   struct sk_buff *rx_skb;
+};
+
+static struct net_device *qcauart_dev;
+
+void
+qca_tty_receive(struct tty_struct *tty, const unsigned char *cp, char *fp,
+   int count)
+{
+   struct qcauart *qca = tty->disc_data;
+   struct net_

[PATCH v3 net-next 4/8] net: qualcomm: rename qca_framing.c to qca_common.c

2016-10-18 Thread Stefan Wahren
As preparation for the upcoming UART driver we need a module
which contains common functions for both interfaces. The module
qca_framing is a good candidate but renaming to qca_common would
make it clear.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/Makefile  |   2 +-
 drivers/net/ethernet/qualcomm/qca_common.c  | 156 
 drivers/net/ethernet/qualcomm/qca_common.h  | 134 
 drivers/net/ethernet/qualcomm/qca_framing.c | 156 
 drivers/net/ethernet/qualcomm/qca_framing.h | 134 
 drivers/net/ethernet/qualcomm/qca_spi.c |   2 +-
 drivers/net/ethernet/qualcomm/qca_spi.h |   2 +-
 7 files changed, 293 insertions(+), 293 deletions(-)
 create mode 100644 drivers/net/ethernet/qualcomm/qca_common.c
 create mode 100644 drivers/net/ethernet/qualcomm/qca_common.h
 delete mode 100644 drivers/net/ethernet/qualcomm/qca_framing.c
 delete mode 100644 drivers/net/ethernet/qualcomm/qca_framing.h

diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index aacb0a5..8080570 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -3,6 +3,6 @@
 #
 
 obj-$(CONFIG_QCA7000) += qcaspi.o
-qcaspi-objs := qca_spi.o qca_framing.o qca_7k.o qca_debug.o
+qcaspi-objs := qca_spi.o qca_common.o qca_7k.o qca_debug.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_common.c 
b/drivers/net/ethernet/qualcomm/qca_common.c
new file mode 100644
index 000..26453a9
--- /dev/null
+++ b/drivers/net/ethernet/qualcomm/qca_common.c
@@ -0,0 +1,156 @@
+/*
+ *   Copyright (c) 2011, 2012, Atheros Communications Inc.
+ *   Copyright (c) 2014, I2SE GmbH
+ *
+ *   Permission to use, copy, modify, and/or distribute this software
+ *   for any purpose with or without fee is hereby granted, provided
+ *   that the above copyright notice and this permission notice appear
+ *   in all copies.
+ *
+ *   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ *   WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ *   WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ *   THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
+ *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ *   LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ *   NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ *   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*   Atheros ethernet framing. Every Ethernet frame is surrounded
+ *   by an atheros frame while transmitted over a serial channel;
+ */
+
+#include 
+
+#include "qca_common.h"
+
+u16
+qcafrm_create_header(u8 *buf, u16 length)
+{
+   __le16 len;
+
+   if (!buf)
+   return 0;
+
+   len = cpu_to_le16(length);
+
+   buf[0] = 0xAA;
+   buf[1] = 0xAA;
+   buf[2] = 0xAA;
+   buf[3] = 0xAA;
+   buf[4] = len & 0xff;
+   buf[5] = (len >> 8) & 0xff;
+   buf[6] = 0;
+   buf[7] = 0;
+
+   return QCAFRM_HEADER_LEN;
+}
+
+u16
+qcafrm_create_footer(u8 *buf)
+{
+   if (!buf)
+   return 0;
+
+   buf[0] = 0x55;
+   buf[1] = 0x55;
+   return QCAFRM_FOOTER_LEN;
+}
+
+/*   Gather received bytes and try to extract a full ethernet frame by
+ *   following a simple state machine.
+ *
+ * Return:   QCAFRM_GATHER   No ethernet frame fully received yet.
+ *   QCAFRM_NOHEAD   Header expected but not found.
+ *   QCAFRM_INVLEN   Atheros frame length is invalid
+ *   QCAFRM_NOTAIL   Footer expected but not found.
+ *   > 0 Number of byte in the fully received
+ *   Ethernet frame
+ */
+
+s32
+qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 buf_len, u8 
recv_byte)
+{
+   s32 ret = QCAFRM_GATHER;
+   u16 len;
+
+   switch (handle->state) {
+   case QCAFRM_HW_LEN0:
+   case QCAFRM_HW_LEN1:
+   /* by default, just go to next state */
+   handle->state--;
+
+   if (recv_byte != 0x00) {
+   /* first two bytes of length must be 0 */
+   handle->state = QCAFRM_HW_LEN0;
+   }
+   break;
+   case QCAFRM_HW_LEN2:
+   case QCAFRM_HW_LEN3:
+   handle->state--;
+   break;
+   /* 4 bytes header pattern */
+   case QCAFRM_WAIT_AA1:
+   case QCAFRM_WAIT_AA2:
+   case QCAFRM_WAIT_AA3:
+   case QCAFRM_WAIT_AA4:
+   if (recv_byte != 0xAA) {
+   ret = QCAFRM_NOHEAD;
+   handle->state = QCAFRM_HW_LEN0;
+   } else {
+   handle->state--;
+   }
+   break;
+   /* 2 bytes length. */
+   /

[PATCH v3 net-next 0/8] net: qualcomm: add QCA7000 UART driver

2016-10-18 Thread Stefan Wahren
The Qualcomm QCA7000 HomePlug GreenPHY supports two interfaces:
UART and SPI. This patch series adds the missing support for UART.

This driver based on the Qualcomm code [1], but contains some changes:
* use random MAC address per default
* use net_device_stats from device
* share frame decoding between SPI and UART driver
* improve error handling
* reimplement tty_wakeup with work queue (based on slcan)

The patches 1 - 3 are just for clean up and are not related to
the UART support. Patches 4 - 7 prepare the existing QCA7000
code for UART support. The last patch contains the new driver.

In order to test the driver a modified slattach in userspace is also
required. A prepared busybox (includes slattach) can be found here [2].

The code itself has been tested on a Freescale i.MX28 board.

Changes in v3:
  * rebase to current net-next

Changes in v2:
  * fix build issue by using netif_trans_update() and dev_trans_start()

[1] - https://github.com/IoE/qca7000
[2] - https://github.com/lategoodbye/busybox/commits/qca7k_support_1_24

Stefan Wahren (8):
  net: qualcomm: remove unnecessary includes
  net: qca_debug: use net_device_ops instead of direct call
  net: qualcomm: move qcaspi_tx_cmd to qca_spi.c
  net: qualcomm: rename qca_framing.c to qca_common.c
  net: qualcomm: move MTU handling to qca_common
  net: qualcomm: prepare frame decoding for UART driver
  net: qualcomm: make qca_common a separate kernel module
  net: qualcomm: add QCA7000 UART driver

 drivers/net/ethernet/qualcomm/Kconfig   |  20 +-
 drivers/net/ethernet/qualcomm/Makefile  |   7 +-
 drivers/net/ethernet/qualcomm/qca_7k.c  |  28 --
 drivers/net/ethernet/qualcomm/qca_7k.h  |   1 -
 drivers/net/ethernet/qualcomm/qca_common.c  | 178 +++
 drivers/net/ethernet/qualcomm/qca_common.h  | 147 +
 drivers/net/ethernet/qualcomm/qca_debug.c   |   5 +-
 drivers/net/ethernet/qualcomm/qca_framing.c | 156 --
 drivers/net/ethernet/qualcomm/qca_framing.h | 134 -
 drivers/net/ethernet/qualcomm/qca_spi.c |  41 ++-
 drivers/net/ethernet/qualcomm/qca_spi.h |   5 +-
 drivers/net/ethernet/qualcomm/qca_uart.c| 447 
 include/uapi/linux/tty.h|   1 +
 13 files changed, 828 insertions(+), 342 deletions(-)
 create mode 100644 drivers/net/ethernet/qualcomm/qca_common.c
 create mode 100644 drivers/net/ethernet/qualcomm/qca_common.h
 delete mode 100644 drivers/net/ethernet/qualcomm/qca_framing.c
 delete mode 100644 drivers/net/ethernet/qualcomm/qca_framing.h
 create mode 100644 drivers/net/ethernet/qualcomm/qca_uart.c

-- 
2.1.4



[PATCH v3 net-next 1/8] net: qualcomm: remove unnecessary includes

2016-10-18 Thread Stefan Wahren
Most of the includes in qca_7k.c are unnecessary so we better remove them.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_7k.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_7k.c 
b/drivers/net/ethernet/qualcomm/qca_7k.c
index f0066fb..557d53c 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k.c
@@ -23,11 +23,7 @@
  *   kernel-based SPI device.
  */
 
-#include 
-#include 
-#include 
 #include 
-#include 
 
 #include "qca_7k.h"
 
-- 
2.1.4



[PATCH v3 net-next 7/8] net: qualcomm: make qca_common a separate kernel module

2016-10-18 Thread Stefan Wahren
In order to share common functions between QCA7000 SPI and UART protocol
driver the qca_common needs to be a separate kernel module.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/Kconfig  |  8 +++-
 drivers/net/ethernet/qualcomm/Makefile |  5 +++--
 drivers/net/ethernet/qualcomm/qca_common.c | 11 +++
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/Kconfig 
b/drivers/net/ethernet/qualcomm/Kconfig
index d7720bf..b4c369d 100644
--- a/drivers/net/ethernet/qualcomm/Kconfig
+++ b/drivers/net/ethernet/qualcomm/Kconfig
@@ -16,7 +16,13 @@ config NET_VENDOR_QUALCOMM
 if NET_VENDOR_QUALCOMM
 
 config QCA7000
-   tristate "Qualcomm Atheros QCA7000 support"
+   tristate
+   help
+ This enables support for the Qualcomm Atheros QCA7000.
+
+config QCA7000_SPI
+   tristate "Qualcomm Atheros QCA7000 SPI support"
+   select QCA7000
depends on SPI_MASTER && OF
---help---
  This SPI protocol driver supports the Qualcomm Atheros QCA7000.
diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index 8080570..00d8729 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -2,7 +2,8 @@
 # Makefile for the Qualcomm network device drivers.
 #
 
-obj-$(CONFIG_QCA7000) += qcaspi.o
-qcaspi-objs := qca_spi.o qca_common.o qca_7k.o qca_debug.o
+obj-$(CONFIG_QCA7000) += qca_common.o
+obj-$(CONFIG_QCA7000_SPI) += qcaspi.o
+qcaspi-objs := qca_7k.o qca_debug.o qca_spi.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_common.c 
b/drivers/net/ethernet/qualcomm/qca_common.c
index 7eefdad..2fa8c18 100644
--- a/drivers/net/ethernet/qualcomm/qca_common.c
+++ b/drivers/net/ethernet/qualcomm/qca_common.c
@@ -21,7 +21,9 @@
  *   by an atheros frame while transmitted over a serial channel;
  */
 
+#include 
 #include 
+#include 
 
 #include "qca_common.h"
 
@@ -46,6 +48,7 @@ qcafrm_create_header(u8 *buf, u16 length)
 
return QCAFRM_HEADER_LEN;
 }
+EXPORT_SYMBOL_GPL(qcafrm_create_header);
 
 u16
 qcafrm_create_footer(u8 *buf)
@@ -57,6 +60,7 @@ qcafrm_create_footer(u8 *buf)
buf[1] = 0x55;
return QCAFRM_FOOTER_LEN;
 }
+EXPORT_SYMBOL_GPL(qcafrm_create_footer);
 
 /*   Gather received bytes and try to extract a full ethernet frame by
  *   following a simple state machine.
@@ -154,6 +158,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
 
return ret;
 }
+EXPORT_SYMBOL_GPL(qcafrm_fsm_decode);
 
 int
 qcacmn_netdev_change_mtu(struct net_device *dev, int new_mtu)
@@ -165,3 +170,9 @@ qcacmn_netdev_change_mtu(struct net_device *dev, int 
new_mtu)
 
return 0;
 }
+EXPORT_SYMBOL_GPL(qcacmn_netdev_change_mtu);
+
+MODULE_DESCRIPTION("Qualcomm Atheros Common");
+MODULE_AUTHOR("Qualcomm Atheros Communications");
+MODULE_AUTHOR("Stefan Wahren <stefan.wah...@i2se.com>");
+MODULE_LICENSE("Dual BSD/GPL");
-- 
2.1.4



[PATCH v3 net-next 3/8] net: qualcomm: move qcaspi_tx_cmd to qca_spi.c

2016-10-18 Thread Stefan Wahren
The function qcaspi_tx_cmd() is only called from qca_spi.c. So we better
move it there.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_7k.c  | 24 
 drivers/net/ethernet/qualcomm/qca_7k.h  |  1 -
 drivers/net/ethernet/qualcomm/qca_spi.c | 24 
 3 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_7k.c 
b/drivers/net/ethernet/qualcomm/qca_7k.c
index 557d53c..aa90a1d 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.c
+++ b/drivers/net/ethernet/qualcomm/qca_7k.c
@@ -119,27 +119,3 @@ qcaspi_write_register(struct qcaspi *qca, u16 reg, u16 
value)
 
return ret;
 }
-
-int
-qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd)
-{
-   __be16 tx_data;
-   struct spi_message *msg = >spi_msg1;
-   struct spi_transfer *transfer = >spi_xfer1;
-   int ret;
-
-   tx_data = cpu_to_be16(cmd);
-   transfer->len = sizeof(tx_data);
-   transfer->tx_buf = _data;
-   transfer->rx_buf = NULL;
-
-   ret = spi_sync(qca->spi_dev, msg);
-
-   if (!ret)
-   ret = msg->status;
-
-   if (ret)
-   qcaspi_spi_error(qca);
-
-   return ret;
-}
diff --git a/drivers/net/ethernet/qualcomm/qca_7k.h 
b/drivers/net/ethernet/qualcomm/qca_7k.h
index 1cad851..b390b1f 100644
--- a/drivers/net/ethernet/qualcomm/qca_7k.h
+++ b/drivers/net/ethernet/qualcomm/qca_7k.h
@@ -67,6 +67,5 @@
 void qcaspi_spi_error(struct qcaspi *qca);
 int qcaspi_read_register(struct qcaspi *qca, u16 reg, u16 *result);
 int qcaspi_write_register(struct qcaspi *qca, u16 reg, u16 value);
-int qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd);
 
 #endif /* _QCA_7K_H */
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 6e2add9..5bcac62 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -192,6 +192,30 @@ qcaspi_read_legacy(struct qcaspi *qca, u8 *dst, u32 len)
return len;
 }
 
+int
+qcaspi_tx_cmd(struct qcaspi *qca, u16 cmd)
+{
+   __be16 tx_data;
+   struct spi_message *msg = >spi_msg1;
+   struct spi_transfer *transfer = >spi_xfer1;
+   int ret;
+
+   tx_data = cpu_to_be16(cmd);
+   transfer->len = sizeof(tx_data);
+   transfer->tx_buf = _data;
+   transfer->rx_buf = NULL;
+
+   ret = spi_sync(qca->spi_dev, msg);
+
+   if (!ret)
+   ret = msg->status;
+
+   if (ret)
+   qcaspi_spi_error(qca);
+
+   return ret;
+}
+
 static int
 qcaspi_tx_frame(struct qcaspi *qca, struct sk_buff *skb)
 {
-- 
2.1.4



[PATCH v3 net-next 2/8] net: qca_debug: use net_device_ops instead of direct call

2016-10-18 Thread Stefan Wahren
There is no need to export qcaspi_netdev_open and qcaspi_netdev_close
because they are also accessible via the net_device_ops.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_debug.c | 5 +++--
 drivers/net/ethernet/qualcomm/qca_spi.h   | 3 ---
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_debug.c 
b/drivers/net/ethernet/qualcomm/qca_debug.c
index 8e28234..851bf07 100644
--- a/drivers/net/ethernet/qualcomm/qca_debug.c
+++ b/drivers/net/ethernet/qualcomm/qca_debug.c
@@ -273,6 +273,7 @@ qcaspi_get_ringparam(struct net_device *dev, struct 
ethtool_ringparam *ring)
 static int
 qcaspi_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
 {
+   const struct net_device_ops *ops = dev->netdev_ops;
struct qcaspi *qca = netdev_priv(dev);
 
if ((ring->rx_pending) ||
@@ -281,13 +282,13 @@ qcaspi_set_ringparam(struct net_device *dev, struct 
ethtool_ringparam *ring)
return -EINVAL;
 
if (netif_running(dev))
-   qcaspi_netdev_close(dev);
+   ops->ndo_stop(dev);
 
qca->txr.count = max_t(u32, ring->tx_pending, TX_RING_MIN_LEN);
qca->txr.count = min_t(u16, qca->txr.count, TX_RING_MAX_LEN);
 
if (netif_running(dev))
-   qcaspi_netdev_open(dev);
+   ops->ndo_open(dev);
 
return 0;
 }
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.h 
b/drivers/net/ethernet/qualcomm/qca_spi.h
index 6e31a0e..064853d 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.h
+++ b/drivers/net/ethernet/qualcomm/qca_spi.h
@@ -108,7 +108,4 @@ struct qcaspi {
u16 burst_len;
 };
 
-int qcaspi_netdev_open(struct net_device *dev);
-int qcaspi_netdev_close(struct net_device *dev);
-
 #endif /* _QCA_SPI_H */
-- 
2.1.4



[PATCH v3 net-next 5/8] net: qualcomm: move MTU handling to qca_common

2016-10-18 Thread Stefan Wahren
The MTU of the QCA7000 is independent from it's host interface (UART,SPI).
So move the change_mtu function to qca_common.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_common.c | 11 +++
 drivers/net/ethernet/qualcomm/qca_common.h |  3 +++
 drivers/net/ethernet/qualcomm/qca_spi.c| 13 +
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_common.c 
b/drivers/net/ethernet/qualcomm/qca_common.c
index 26453a9..9020c57 100644
--- a/drivers/net/ethernet/qualcomm/qca_common.c
+++ b/drivers/net/ethernet/qualcomm/qca_common.c
@@ -154,3 +154,14 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
 
return ret;
 }
+
+int
+qcacmn_netdev_change_mtu(struct net_device *dev, int new_mtu)
+{
+   if ((new_mtu < QCAFRM_ETHMINMTU) || (new_mtu > QCAFRM_ETHMAXMTU))
+   return -EINVAL;
+
+   dev->mtu = new_mtu;
+
+   return 0;
+}
diff --git a/drivers/net/ethernet/qualcomm/qca_common.h 
b/drivers/net/ethernet/qualcomm/qca_common.h
index 8c9b713..0fafaaf 100644
--- a/drivers/net/ethernet/qualcomm/qca_common.h
+++ b/drivers/net/ethernet/qualcomm/qca_common.h
@@ -26,6 +26,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 /* Frame is currently being received */
@@ -131,4 +132,6 @@ static inline void qcafrm_fsm_init(struct qcafrm_handle 
*handle)
 
 s32 qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 buf_len, u8 
recv_byte);
 
+int qcacmn_netdev_change_mtu(struct net_device *dev, int new_mtu);
+
 #endif /* _QCA_COMMON_H */
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 551591d..e0a5020 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -804,24 +804,13 @@ qcaspi_netdev_uninit(struct net_device *dev)
dev_kfree_skb(qca->rx_skb);
 }
 
-static int
-qcaspi_netdev_change_mtu(struct net_device *dev, int new_mtu)
-{
-   if ((new_mtu < QCAFRM_ETHMINMTU) || (new_mtu > QCAFRM_ETHMAXMTU))
-   return -EINVAL;
-
-   dev->mtu = new_mtu;
-
-   return 0;
-}
-
 static const struct net_device_ops qcaspi_netdev_ops = {
.ndo_init = qcaspi_netdev_init,
.ndo_uninit = qcaspi_netdev_uninit,
.ndo_open = qcaspi_netdev_open,
.ndo_stop = qcaspi_netdev_close,
.ndo_start_xmit = qcaspi_netdev_xmit,
-   .ndo_change_mtu = qcaspi_netdev_change_mtu,
+   .ndo_change_mtu = qcacmn_netdev_change_mtu,
.ndo_set_mac_address = eth_mac_addr,
.ndo_tx_timeout = qcaspi_netdev_tx_timeout,
.ndo_validate_addr = eth_validate_addr,
-- 
2.1.4



[PATCH v3 net-next 6/8] net: qualcomm: prepare frame decoding for UART driver

2016-10-18 Thread Stefan Wahren
Unfortunately the frame format is not exactly identical between SPI
and UART. In case of SPI there is an additional HW length at the
beginning. So store the initial state to make the decoding state machine
more flexible and easy to extend for UART support.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_common.c | 12 ++--
 drivers/net/ethernet/qualcomm/qca_common.h |  8 ++--
 drivers/net/ethernet/qualcomm/qca_spi.c|  2 +-
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_common.c 
b/drivers/net/ethernet/qualcomm/qca_common.c
index 9020c57..7eefdad 100644
--- a/drivers/net/ethernet/qualcomm/qca_common.c
+++ b/drivers/net/ethernet/qualcomm/qca_common.c
@@ -83,7 +83,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 
buf_len, u8 recv_by
 
if (recv_byte != 0x00) {
/* first two bytes of length must be 0 */
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
}
break;
case QCAFRM_HW_LEN2:
@@ -97,7 +97,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 
buf_len, u8 recv_by
case QCAFRM_WAIT_AA4:
if (recv_byte != 0xAA) {
ret = QCAFRM_NOHEAD;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state--;
}
@@ -119,7 +119,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
len = handle->offset;
if (len > buf_len || len < QCAFRM_ETHMINLEN) {
ret = QCAFRM_INVLEN;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state = (enum qcafrm_state)(len + 1);
/* Remaining number of bytes. */
@@ -135,7 +135,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
case QCAFRM_WAIT_551:
if (recv_byte != 0x55) {
ret = QCAFRM_NOTAIL;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state = QCAFRM_WAIT_552;
}
@@ -143,11 +143,11 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
case QCAFRM_WAIT_552:
if (recv_byte != 0x55) {
ret = QCAFRM_NOTAIL;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
ret = handle->offset;
/* Frame is fully received. */
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
}
break;
}
diff --git a/drivers/net/ethernet/qualcomm/qca_common.h 
b/drivers/net/ethernet/qualcomm/qca_common.h
index 0fafaaf..c93cfdf07 100644
--- a/drivers/net/ethernet/qualcomm/qca_common.h
+++ b/drivers/net/ethernet/qualcomm/qca_common.h
@@ -62,6 +62,7 @@
 #define QCAFRM_ERR_BASE -1000
 
 enum qcafrm_state {
+   /* HW length is only available on SPI */
QCAFRM_HW_LEN0 = 0x8000,
QCAFRM_HW_LEN1 = QCAFRM_HW_LEN0 - 1,
QCAFRM_HW_LEN2 = QCAFRM_HW_LEN1 - 1,
@@ -102,6 +103,8 @@ enum qcafrm_state {
 struct qcafrm_handle {
/*  Current decoding state */
enum qcafrm_state state;
+   /* Initial state depends on connection type */
+   enum qcafrm_state init;
 
/* Offset in buffer (borrowed for length too) */
s16 offset;
@@ -114,9 +117,10 @@ u16 qcafrm_create_header(u8 *buf, u16 len);
 
 u16 qcafrm_create_footer(u8 *buf);
 
-static inline void qcafrm_fsm_init(struct qcafrm_handle *handle)
+static inline void qcafrm_fsm_init_spi(struct qcafrm_handle *handle)
 {
-   handle->state = QCAFRM_HW_LEN0;
+   handle->init = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
 }
 
 /*   Gather received bytes and try to extract a full Ethernet frame
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index e0a5020..36ac07d 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -638,7 +638,7 @@ qcaspi_netdev_open(struct net_device *dev)
qca->intr_req = 1;
qca->intr_svc = 0;
qca->sync = QCASPI_SYNC_UNKNOWN;
-   qcafrm_fsm_init(>frm_handle);
+   qcafrm_fsm_init_spi(>frm_handle);
 
qca->spi_thread = kthread_run((void *)qcaspi_spi_thread,
  qca, "%s", dev->name);
-- 
2.1.4



Re: [PATCH RFC v2 net-next 0/8] net: qualcomm: add QCA7000 UART driver

2016-10-13 Thread Stefan Wahren

> Stefan Wahren <stefan.wah...@i2se.com> hat am 26. September 2016 um 13:07
> geschrieben:
> 
> 
> The Qualcomm QCA7000 HomePlug GreenPHY supports two interfaces:
> UART and SPI. This patch series adds the missing support for UART.
> 
> This driver based on the Qualcomm code [1], but contains some changes:
> * use random MAC address per default
> * use net_device_stats from device
> * share frame decoding between SPI and UART driver
> * improve error handling
> * reimplement tty_wakeup with work queue (based on slcan)
> 
> The patches 1 - 3 are just for clean up and are not related to
> the UART support. Patches 4 - 7 prepare the existing QCA7000
> code for UART support. The last patch contains the new driver.
> 
> In order to test the driver a modified slattach in userspace is also
> required. A prepared busybox (includes slattach) can be found here [2].
> 
> The code itself has been tested on a Freescale i.MX28 board.
> 
> Changes in v2:
>   * fix build issue by using netif_trans_update() and dev_trans_start()
> 
> [1] - https://github.com/IoE/qca7000
> [2] - https://github.com/lategoodbye/busybox/commits/qca7k_support_1_24
> 

Gently ping, since i didn't receive any comment for this version.


[PATCH RFC v2 net-next 2/8] net: qca_debug: use net_device_ops instead of direct call

2016-09-26 Thread Stefan Wahren
There is no need to export qcaspi_netdev_open and qcaspi_netdev_close
because they are also accessible via the net_device_ops.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_debug.c | 5 +++--
 drivers/net/ethernet/qualcomm/qca_spi.h   | 3 ---
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_debug.c 
b/drivers/net/ethernet/qualcomm/qca_debug.c
index 8e28234..851bf07 100644
--- a/drivers/net/ethernet/qualcomm/qca_debug.c
+++ b/drivers/net/ethernet/qualcomm/qca_debug.c
@@ -273,6 +273,7 @@ qcaspi_get_ringparam(struct net_device *dev, struct 
ethtool_ringparam *ring)
 static int
 qcaspi_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
 {
+   const struct net_device_ops *ops = dev->netdev_ops;
struct qcaspi *qca = netdev_priv(dev);
 
if ((ring->rx_pending) ||
@@ -281,13 +282,13 @@ qcaspi_set_ringparam(struct net_device *dev, struct 
ethtool_ringparam *ring)
return -EINVAL;
 
if (netif_running(dev))
-   qcaspi_netdev_close(dev);
+   ops->ndo_stop(dev);
 
qca->txr.count = max_t(u32, ring->tx_pending, TX_RING_MIN_LEN);
qca->txr.count = min_t(u16, qca->txr.count, TX_RING_MAX_LEN);
 
if (netif_running(dev))
-   qcaspi_netdev_open(dev);
+   ops->ndo_open(dev);
 
return 0;
 }
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.h 
b/drivers/net/ethernet/qualcomm/qca_spi.h
index 6e31a0e..064853d 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.h
+++ b/drivers/net/ethernet/qualcomm/qca_spi.h
@@ -108,7 +108,4 @@ struct qcaspi {
u16 burst_len;
 };
 
-int qcaspi_netdev_open(struct net_device *dev);
-int qcaspi_netdev_close(struct net_device *dev);
-
 #endif /* _QCA_SPI_H */
-- 
2.1.4



[PATCH RFC v2 net-next 6/8] net: qualcomm: prepare frame decoding for UART driver

2016-09-26 Thread Stefan Wahren
Unfortunately the frame format is not exactly identical between SPI
and UART. In case of SPI there is an additional HW length at the
beginning. So store the initial state to make the decoding state machine
more flexible and easy to extend for UART support.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_common.c | 12 ++--
 drivers/net/ethernet/qualcomm/qca_common.h |  8 ++--
 drivers/net/ethernet/qualcomm/qca_spi.c|  2 +-
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_common.c 
b/drivers/net/ethernet/qualcomm/qca_common.c
index 9020c57..7eefdad 100644
--- a/drivers/net/ethernet/qualcomm/qca_common.c
+++ b/drivers/net/ethernet/qualcomm/qca_common.c
@@ -83,7 +83,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 
buf_len, u8 recv_by
 
if (recv_byte != 0x00) {
/* first two bytes of length must be 0 */
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
}
break;
case QCAFRM_HW_LEN2:
@@ -97,7 +97,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 
buf_len, u8 recv_by
case QCAFRM_WAIT_AA4:
if (recv_byte != 0xAA) {
ret = QCAFRM_NOHEAD;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state--;
}
@@ -119,7 +119,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
len = handle->offset;
if (len > buf_len || len < QCAFRM_ETHMINLEN) {
ret = QCAFRM_INVLEN;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state = (enum qcafrm_state)(len + 1);
/* Remaining number of bytes. */
@@ -135,7 +135,7 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
case QCAFRM_WAIT_551:
if (recv_byte != 0x55) {
ret = QCAFRM_NOTAIL;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
handle->state = QCAFRM_WAIT_552;
}
@@ -143,11 +143,11 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
case QCAFRM_WAIT_552:
if (recv_byte != 0x55) {
ret = QCAFRM_NOTAIL;
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
} else {
ret = handle->offset;
/* Frame is fully received. */
-   handle->state = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
}
break;
}
diff --git a/drivers/net/ethernet/qualcomm/qca_common.h 
b/drivers/net/ethernet/qualcomm/qca_common.h
index 0fafaaf..c93cfdf07 100644
--- a/drivers/net/ethernet/qualcomm/qca_common.h
+++ b/drivers/net/ethernet/qualcomm/qca_common.h
@@ -62,6 +62,7 @@
 #define QCAFRM_ERR_BASE -1000
 
 enum qcafrm_state {
+   /* HW length is only available on SPI */
QCAFRM_HW_LEN0 = 0x8000,
QCAFRM_HW_LEN1 = QCAFRM_HW_LEN0 - 1,
QCAFRM_HW_LEN2 = QCAFRM_HW_LEN1 - 1,
@@ -102,6 +103,8 @@ enum qcafrm_state {
 struct qcafrm_handle {
/*  Current decoding state */
enum qcafrm_state state;
+   /* Initial state depends on connection type */
+   enum qcafrm_state init;
 
/* Offset in buffer (borrowed for length too) */
s16 offset;
@@ -114,9 +117,10 @@ u16 qcafrm_create_header(u8 *buf, u16 len);
 
 u16 qcafrm_create_footer(u8 *buf);
 
-static inline void qcafrm_fsm_init(struct qcafrm_handle *handle)
+static inline void qcafrm_fsm_init_spi(struct qcafrm_handle *handle)
 {
-   handle->state = QCAFRM_HW_LEN0;
+   handle->init = QCAFRM_HW_LEN0;
+   handle->state = handle->init;
 }
 
 /*   Gather received bytes and try to extract a full Ethernet frame
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index e0a5020..36ac07d 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -638,7 +638,7 @@ qcaspi_netdev_open(struct net_device *dev)
qca->intr_req = 1;
qca->intr_svc = 0;
qca->sync = QCASPI_SYNC_UNKNOWN;
-   qcafrm_fsm_init(>frm_handle);
+   qcafrm_fsm_init_spi(>frm_handle);
 
qca->spi_thread = kthread_run((void *)qcaspi_spi_thread,
  qca, "%s", dev->name);
-- 
2.1.4



[PATCH RFC v2 net-next 5/8] net: qualcomm: move MTU handling to qca_common

2016-09-26 Thread Stefan Wahren
The MTU of the QCA7000 is independent from it's host interface (UART,SPI).
So move the change_mtu function to qca_common.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/qca_common.c | 11 +++
 drivers/net/ethernet/qualcomm/qca_common.h |  3 +++
 drivers/net/ethernet/qualcomm/qca_spi.c| 13 +
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_common.c 
b/drivers/net/ethernet/qualcomm/qca_common.c
index 26453a9..9020c57 100644
--- a/drivers/net/ethernet/qualcomm/qca_common.c
+++ b/drivers/net/ethernet/qualcomm/qca_common.c
@@ -154,3 +154,14 @@ qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, 
u16 buf_len, u8 recv_by
 
return ret;
 }
+
+int
+qcacmn_netdev_change_mtu(struct net_device *dev, int new_mtu)
+{
+   if ((new_mtu < QCAFRM_ETHMINMTU) || (new_mtu > QCAFRM_ETHMAXMTU))
+   return -EINVAL;
+
+   dev->mtu = new_mtu;
+
+   return 0;
+}
diff --git a/drivers/net/ethernet/qualcomm/qca_common.h 
b/drivers/net/ethernet/qualcomm/qca_common.h
index 8c9b713..0fafaaf 100644
--- a/drivers/net/ethernet/qualcomm/qca_common.h
+++ b/drivers/net/ethernet/qualcomm/qca_common.h
@@ -26,6 +26,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 /* Frame is currently being received */
@@ -131,4 +132,6 @@ static inline void qcafrm_fsm_init(struct qcafrm_handle 
*handle)
 
 s32 qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 buf_len, u8 
recv_byte);
 
+int qcacmn_netdev_change_mtu(struct net_device *dev, int new_mtu);
+
 #endif /* _QCA_COMMON_H */
diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c 
b/drivers/net/ethernet/qualcomm/qca_spi.c
index 551591d..e0a5020 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -804,24 +804,13 @@ qcaspi_netdev_uninit(struct net_device *dev)
dev_kfree_skb(qca->rx_skb);
 }
 
-static int
-qcaspi_netdev_change_mtu(struct net_device *dev, int new_mtu)
-{
-   if ((new_mtu < QCAFRM_ETHMINMTU) || (new_mtu > QCAFRM_ETHMAXMTU))
-   return -EINVAL;
-
-   dev->mtu = new_mtu;
-
-   return 0;
-}
-
 static const struct net_device_ops qcaspi_netdev_ops = {
.ndo_init = qcaspi_netdev_init,
.ndo_uninit = qcaspi_netdev_uninit,
.ndo_open = qcaspi_netdev_open,
.ndo_stop = qcaspi_netdev_close,
.ndo_start_xmit = qcaspi_netdev_xmit,
-   .ndo_change_mtu = qcaspi_netdev_change_mtu,
+   .ndo_change_mtu = qcacmn_netdev_change_mtu,
.ndo_set_mac_address = eth_mac_addr,
.ndo_tx_timeout = qcaspi_netdev_tx_timeout,
.ndo_validate_addr = eth_validate_addr,
-- 
2.1.4



[PATCH RFC v2 net-next 4/8] net: qualcomm: rename qca_framing.c to qca_common.c

2016-09-26 Thread Stefan Wahren
As preparation for the upcoming UART driver we need a module
which contains common functions for both interfaces. The module
qca_framing is a good candidate but renaming to qca_common would
make it clear.

Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com>
---
 drivers/net/ethernet/qualcomm/Makefile  |   2 +-
 drivers/net/ethernet/qualcomm/qca_common.c  | 156 
 drivers/net/ethernet/qualcomm/qca_common.h  | 134 
 drivers/net/ethernet/qualcomm/qca_framing.c | 156 
 drivers/net/ethernet/qualcomm/qca_framing.h | 134 
 drivers/net/ethernet/qualcomm/qca_spi.c |   2 +-
 drivers/net/ethernet/qualcomm/qca_spi.h |   2 +-
 7 files changed, 293 insertions(+), 293 deletions(-)
 create mode 100644 drivers/net/ethernet/qualcomm/qca_common.c
 create mode 100644 drivers/net/ethernet/qualcomm/qca_common.h
 delete mode 100644 drivers/net/ethernet/qualcomm/qca_framing.c
 delete mode 100644 drivers/net/ethernet/qualcomm/qca_framing.h

diff --git a/drivers/net/ethernet/qualcomm/Makefile 
b/drivers/net/ethernet/qualcomm/Makefile
index aacb0a5..8080570 100644
--- a/drivers/net/ethernet/qualcomm/Makefile
+++ b/drivers/net/ethernet/qualcomm/Makefile
@@ -3,6 +3,6 @@
 #
 
 obj-$(CONFIG_QCA7000) += qcaspi.o
-qcaspi-objs := qca_spi.o qca_framing.o qca_7k.o qca_debug.o
+qcaspi-objs := qca_spi.o qca_common.o qca_7k.o qca_debug.o
 
 obj-y += emac/
diff --git a/drivers/net/ethernet/qualcomm/qca_common.c 
b/drivers/net/ethernet/qualcomm/qca_common.c
new file mode 100644
index 000..26453a9
--- /dev/null
+++ b/drivers/net/ethernet/qualcomm/qca_common.c
@@ -0,0 +1,156 @@
+/*
+ *   Copyright (c) 2011, 2012, Atheros Communications Inc.
+ *   Copyright (c) 2014, I2SE GmbH
+ *
+ *   Permission to use, copy, modify, and/or distribute this software
+ *   for any purpose with or without fee is hereby granted, provided
+ *   that the above copyright notice and this permission notice appear
+ *   in all copies.
+ *
+ *   THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ *   WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ *   WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ *   THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
+ *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ *   LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ *   NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ *   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*   Atheros ethernet framing. Every Ethernet frame is surrounded
+ *   by an atheros frame while transmitted over a serial channel;
+ */
+
+#include 
+
+#include "qca_common.h"
+
+u16
+qcafrm_create_header(u8 *buf, u16 length)
+{
+   __le16 len;
+
+   if (!buf)
+   return 0;
+
+   len = cpu_to_le16(length);
+
+   buf[0] = 0xAA;
+   buf[1] = 0xAA;
+   buf[2] = 0xAA;
+   buf[3] = 0xAA;
+   buf[4] = len & 0xff;
+   buf[5] = (len >> 8) & 0xff;
+   buf[6] = 0;
+   buf[7] = 0;
+
+   return QCAFRM_HEADER_LEN;
+}
+
+u16
+qcafrm_create_footer(u8 *buf)
+{
+   if (!buf)
+   return 0;
+
+   buf[0] = 0x55;
+   buf[1] = 0x55;
+   return QCAFRM_FOOTER_LEN;
+}
+
+/*   Gather received bytes and try to extract a full ethernet frame by
+ *   following a simple state machine.
+ *
+ * Return:   QCAFRM_GATHER   No ethernet frame fully received yet.
+ *   QCAFRM_NOHEAD   Header expected but not found.
+ *   QCAFRM_INVLEN   Atheros frame length is invalid
+ *   QCAFRM_NOTAIL   Footer expected but not found.
+ *   > 0 Number of byte in the fully received
+ *   Ethernet frame
+ */
+
+s32
+qcafrm_fsm_decode(struct qcafrm_handle *handle, u8 *buf, u16 buf_len, u8 
recv_byte)
+{
+   s32 ret = QCAFRM_GATHER;
+   u16 len;
+
+   switch (handle->state) {
+   case QCAFRM_HW_LEN0:
+   case QCAFRM_HW_LEN1:
+   /* by default, just go to next state */
+   handle->state--;
+
+   if (recv_byte != 0x00) {
+   /* first two bytes of length must be 0 */
+   handle->state = QCAFRM_HW_LEN0;
+   }
+   break;
+   case QCAFRM_HW_LEN2:
+   case QCAFRM_HW_LEN3:
+   handle->state--;
+   break;
+   /* 4 bytes header pattern */
+   case QCAFRM_WAIT_AA1:
+   case QCAFRM_WAIT_AA2:
+   case QCAFRM_WAIT_AA3:
+   case QCAFRM_WAIT_AA4:
+   if (recv_byte != 0xAA) {
+   ret = QCAFRM_NOHEAD;
+   handle->state = QCAFRM_HW_LEN0;
+   } else {
+   handle->state--;
+   }
+   break;
+   /* 2 bytes length. */
+   /

  1   2   >