Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1487323 > unrolled thread
| Started by | Stefan Wahren <stefan.wahren@i2se.com> |
|---|---|
| First post | 2016-09-20 15:10 +0200 |
| Last post | 2016-09-20 15:10 +0200 |
| Articles | 8 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH net-next 0/8] net: qualcomm: add QCA7000 UART driver Stefan Wahren <stefan.wahren@i2se.com> - 2016-09-20 15:10 +0200
[PATCH net-next 8/8] net: qualcomm: add QCA7000 UART driver Stefan Wahren <stefan.wahren@i2se.com> - 2016-09-20 15:10 +0200
Re: [PATCH net-next 8/8] net: qualcomm: add QCA7000 UART driver Marcel Holtmann <marcel@holtmann.org> - 2016-09-20 17:40 +0200
Re: [PATCH net-next 8/8] net: qualcomm: add QCA7000 UART driver Stefan Wahren <stefan.wahren@i2se.com> - 2016-09-21 09:50 +0200
Re: [PATCH net-next 8/8] net: qualcomm: add QCA7000 UART driver Stefan Wahren <stefan.wahren@i2se.com> - 2016-09-20 18:50 +0200
[PATCH net-next 6/8] net: qualcomm: prepare frame decoding for UART driver Stefan Wahren <stefan.wahren@i2se.com> - 2016-09-20 15:10 +0200
[PATCH net-next 5/8] net: qualcomm: move MTU handling to qca_common Stefan Wahren <stefan.wahren@i2se.com> - 2016-09-20 15:10 +0200
[PATCH net-next 3/8] net: qualcomm: move qcaspi_tx_cmd to qca_spi.c Stefan Wahren <stefan.wahren@i2se.com> - 2016-09-20 15:10 +0200
| From | Stefan Wahren <stefan.wahren@i2se.com> |
|---|---|
| Date | 2016-09-20 15:10 +0200 |
| Subject | [PATCH net-next 0/8] net: qualcomm: add QCA7000 UART driver |
| Message-ID | <sjsY9-3nb-3@gated-at.bofh.it> |
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. [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
[toc] | [next] | [standalone]
| From | Stefan Wahren <stefan.wahren@i2se.com> |
|---|---|
| Date | 2016-09-20 15:10 +0200 |
| Subject | [PATCH net-next 8/8] net: qualcomm: add QCA7000 UART driver |
| Message-ID | <sjsYa-3nb-13@gated-at.bofh.it> |
| In reply to | #1487323 |
This patch adds the Ethernet over UART driver for the
Qualcomm QCA7000 HomePlug GreenPHY.
Signed-off-by: Stefan Wahren <stefan.wahren@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 0d33728..0ede46e 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"
select CRC32
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 0000000..f956c83
--- /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 <linux/errno.h>
+#include <linux/etherdevice.h>
+#include <linux/if_arp.h>
+#include <linux/if_ether.h>
+#include <linux/init.h>
+#include <linux/jiffies.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/netdevice.h>
+#include <linux/sched.h>
+#include <linux/skbuff.h>
+#include <linux/tty.h>
+#include <linux/types.h>
+
+#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_device_stats *n_stats = &qca->net_dev->stats;
+ int dropped = 0;
+
+ if (!qca->rx_skb) {
+ qca->rx_skb = netdev_alloc_skb(qca->net_dev, qca->net_dev->mtu +
+ VLAN_ETH_HLEN);
+ if (!qca->rx_skb) {
+ n_stats->rx_errors++;
+ n_stats->rx_dropped++;
+ return;
+ }
+ }
+
+ while (count--) {
+ s32 retcode;
+
+ if (fp && *fp++) {
+ n_stats->rx_errors++;
+ cp++;
+ dropped++;
+ continue;
+ }
+
+ retcode = qcafrm_fsm_decode(&qca->frm_handle,
+ qca->rx_skb->data,
+ skb_tailroom(qca->rx_skb),
+ *cp);
+
+ cp++;
+ switch (retcode) {
+ case QCAFRM_GATHER:
+ case QCAFRM_NOHEAD:
+ break;
+ case QCAFRM_NOTAIL:
+ netdev_dbg(qca->net_dev, "recv: no RX tail\n");
+ n_stats->rx_errors++;
+ n_stats->rx_dropped++;
+ break;
+ case QCAFRM_INVLEN:
+ netdev_dbg(qca->net_dev, "recv: invalid RX length\n");
+ n_stats->rx_errors++;
+ n_stats->rx_dropped++;
+ break;
+ default:
+ qca->rx_skb->dev = qca->net_dev;
+ n_stats->rx_packets++;
+ n_stats->rx_bytes += retcode;
+ skb_put(qca->rx_skb, retcode);
+ qca->rx_skb->protocol = eth_type_trans(
+ 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(qca->net_dev,
+ qca->net_dev->mtu +
+ VLAN_ETH_HLEN);
+ if (!qca->rx_skb) {
+ netdev_dbg(qca->net_dev, "recv: out of RX resources\n");
+ n_stats->rx_errors++;
+ break;
+ }
+ }
+ }
+
+ if (dropped)
+ dev_dbg_ratelimited(&qca->net_dev->dev, "recv: invalid %d bytes\n",
+ dropped);
+}
+
+/* Write out any remaining transmit buffer. Scheduled when tty is writable */
+static void qcauart_transmit(struct work_struct *work)
+{
+ struct qcauart *qca = container_of(work, struct qcauart, tx_work);
+ struct net_device_stats *n_stats = &qca->net_dev->stats;
+ int written;
+
+ spin_lock_bh(&qca->lock);
+ /* First make sure we're connected. */
+ if (!qca->tty || !netif_running(qca->net_dev)) {
+ spin_unlock_bh(&qca->lock);
+ return;
+ }
+
+ if (qca->xleft <= 0) {
+ /* Now serial buffer is almost free & we can start
+ * transmission of another packet
+ */
+ n_stats->tx_packets++;
+ clear_bit(TTY_DO_WRITE_WAKEUP, &qca->tty->flags);
+ spin_unlock_bh(&qca->lock);
+ netif_wake_queue(qca->net_dev);
+ return;
+ }
+
+ written = qca->tty->ops->write(qca->tty, qca->xhead, qca->xleft);
+ qca->xleft -= written;
+ qca->xhead += written;
+ spin_unlock_bh(&qca->lock);
+}
+
+/* Called by the driver when there's room for more data.
+ * Schedule the transmit.
+ */
+static void qca_tty_wakeup(struct tty_struct *tty)
+{
+ struct qcauart *qca = tty->disc_data;
+
+ schedule_work(&qca->tx_work);
+}
+
+int
+qca_tty_open(struct tty_struct *tty)
+{
+ struct qcauart *qca;
+
+ if (!capable(CAP_NET_ADMIN))
+ return -EPERM;
+
+ if (!tty->ops->write)
+ return -EOPNOTSUPP;
+
+ if (tty->disc_data)
+ return -EEXIST;
+
+ qca = netdev_priv(qcauart_dev);
+ qca->tty = tty;
+ tty->disc_data = qca;
+ tty->receive_room = 4096;
+ netif_carrier_on(qca->net_dev);
+
+ return 0;
+}
+
+void
+qca_tty_close(struct tty_struct *tty)
+{
+ struct qcauart *qca = (void *)tty->disc_data;
+
+ if (!qca)
+ return;
+
+ netif_carrier_off(qca->net_dev);
+ qca->tty = NULL;
+
+ /* Detach from the tty */
+ tty->disc_data = NULL;
+}
+
+static struct tty_ldisc_ops qca_ldisc = {
+ .owner = THIS_MODULE,
+ .magic = TTY_LDISC_MAGIC,
+ .name = "qca",
+ .open = qca_tty_open,
+ .close = qca_tty_close,
+ .ioctl = n_tty_ioctl_helper,
+ .receive_buf = qca_tty_receive,
+ .write_wakeup = qca_tty_wakeup,
+};
+
+int
+qcauart_netdev_open(struct net_device *dev)
+{
+ struct qcauart *qca = netdev_priv(dev);
+
+ qcafrm_fsm_init_uart(&qca->frm_handle);
+ netif_start_queue(qca->net_dev);
+
+ return 0;
+}
+
+int
+qcauart_netdev_close(struct net_device *dev)
+{
+ struct qcauart *qca = netdev_priv(dev);
+
+ spin_lock_bh(&qca->lock);
+ if (qca->tty) {
+ /* TTY discipline is running. */
+ clear_bit(TTY_DO_WRITE_WAKEUP, &qca->tty->flags);
+ }
+ netif_stop_queue(dev);
+ qca->xleft = 0;
+ spin_unlock_bh(&qca->lock);
+
+ return 0;
+}
+
+netdev_tx_t
+qcauart_netdev_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+ struct qcauart *qca = netdev_priv(dev);
+ struct net_device_stats *n_stats = &dev->stats;
+ u8 *pos;
+ u8 pad_len = 0;
+ int written;
+
+ spin_lock(&qca->lock);
+
+ if (!netif_running(dev)) {
+ spin_unlock(&qca->lock);
+ netdev_warn(qca->net_dev, "xmit: iface is down\n");
+ goto out;
+ }
+ if (!qca->tty) {
+ spin_unlock(&qca->lock);
+ goto out;
+ }
+
+ pos = qca->xbuff;
+
+ if (skb->len < QCAFRM_ETHMINLEN)
+ pad_len = QCAFRM_ETHMINLEN - skb->len;
+
+ pos += qcafrm_create_header(pos, skb->len + pad_len);
+
+ memcpy(pos, skb->data, skb->len);
+ pos += skb->len;
+
+ if (pad_len) {
+ memset(pos, 0, pad_len);
+ pos += pad_len;
+ }
+
+ pos += qcafrm_create_footer(pos);
+
+ netif_stop_queue(qca->net_dev);
+
+ set_bit(TTY_DO_WRITE_WAKEUP, &qca->tty->flags);
+ written = qca->tty->ops->write(qca->tty, qca->xbuff, pos - qca->xbuff);
+ qca->xleft = (pos - qca->xbuff) - written;
+ qca->xhead = qca->xbuff + written;
+ n_stats->tx_bytes += written;
+ spin_unlock(&qca->lock);
+
+ dev->trans_start = jiffies;
+out:
+ kfree_skb(skb);
+ return NETDEV_TX_OK;
+}
+
+void
+qcauart_netdev_tx_timeout(struct net_device *dev)
+{
+ struct qcauart *qca = netdev_priv(dev);
+
+ netdev_info(qca->net_dev, "Transmit timeout at %ld, latency %ld\n",
+ jiffies, jiffies - dev->trans_start);
+ dev->stats.tx_errors++;
+ dev->stats.tx_dropped++;
+
+ clear_bit(TTY_DO_WRITE_WAKEUP, &qca->tty->flags);
+}
+
+static int
+qcauart_netdev_init(struct net_device *dev)
+{
+ struct qcauart *qca = netdev_priv(dev);
+
+ /* Finish setting up the device info. */
+ dev->mtu = QCAFRM_ETHMAXMTU;
+ dev->type = ARPHRD_ETHER;
+
+ qca->rx_skb = netdev_alloc_skb(qca->net_dev,
+ qca->net_dev->mtu + VLAN_ETH_HLEN);
+ if (!qca->rx_skb)
+ return -ENOMEM;
+
+ return 0;
+}
+
+static void
+qcauart_netdev_uninit(struct net_device *dev)
+{
+ struct qcauart *qca = netdev_priv(dev);
+
+ if (qca->rx_skb)
+ dev_kfree_skb(qca->rx_skb);
+}
+
+static const struct net_device_ops qcauart_netdev_ops = {
+ .ndo_init = qcauart_netdev_init,
+ .ndo_uninit = qcauart_netdev_uninit,
+ .ndo_open = qcauart_netdev_open,
+ .ndo_stop = qcauart_netdev_close,
+ .ndo_start_xmit = qcauart_netdev_xmit,
+ .ndo_change_mtu = qcacmn_netdev_change_mtu,
+ .ndo_set_mac_address = eth_mac_addr,
+ .ndo_tx_timeout = qcauart_netdev_tx_timeout,
+ .ndo_validate_addr = eth_validate_addr,
+};
+
+static void
+qcauart_netdev_setup(struct net_device *dev)
+{
+ struct qcauart *qca;
+
+ dev->netdev_ops = &qcauart_netdev_ops;
+ dev->watchdog_timeo = QCAUART_TX_TIMEOUT;
+ dev->priv_flags &= ~IFF_TX_SKB_SHARING;
+ dev->tx_queue_len = 100;
+
+ qca = netdev_priv(dev);
+ memset(qca, 0, sizeof(struct qcauart));
+}
+
+static int __init qcauart_mod_init(void)
+{
+ struct qcauart *qca;
+ int ret;
+
+ ret = tty_register_ldisc(N_QCA7K, &qca_ldisc);
+ if (ret) {
+ pr_err("qca_uart: Can't register line discipline (ret %d)\n",
+ ret);
+ return ret;
+ }
+
+ qcauart_dev = alloc_etherdev(sizeof(struct qcauart));
+ if (!qcauart_dev)
+ return -ENOMEM;
+
+ qcauart_netdev_setup(qcauart_dev);
+
+ qca = netdev_priv(qcauart_dev);
+ if (!qca) {
+ pr_err("qca_uart: Fail to retrieve private structure\n");
+ free_netdev(qcauart_dev);
+ return -ENOMEM;
+ }
+ qca->net_dev = qcauart_dev;
+ spin_lock_init(&qca->lock);
+ INIT_WORK(&qca->tx_work, qcauart_transmit);
+
+ eth_hw_addr_random(qca->net_dev);
+ pr_info("qca_uart: ver=%s, using random MAC address: %pM\n",
+ QCAUART_DRV_VERSION, qca->net_dev->dev_addr);
+
+ netif_carrier_off(qca->net_dev);
+
+ if (register_netdev(qcauart_dev)) {
+ pr_err("qca_uart: Unable to register net device %s\n",
+ qcauart_dev->name);
+ free_netdev(qcauart_dev);
+ return -EFAULT;
+ }
+
+ return 0;
+}
+
+static void __exit qcauart_mod_exit(void)
+{
+ struct qcauart *qca;
+ int ret;
+
+ qca = netdev_priv(qcauart_dev);
+ spin_lock_bh(&qca->lock);
+ if (qca->tty)
+ tty_hangup(qca->tty);
+ spin_unlock_bh(&qca->lock);
+
+ unregister_netdev(qcauart_dev);
+
+ free_netdev(qcauart_dev);
+ qcauart_dev = NULL;
+
+ ret = tty_unregister_ldisc(N_QCA7K);
+ if (ret)
+ pr_err("qca_uart: can't unregister line discipline (ret %d)\n",
+ ret);
+}
+
+module_init(qcauart_mod_init);
+module_exit(qcauart_mod_exit);
+
+MODULE_DESCRIPTION("Qualcomm Atheros UART Driver");
+MODULE_AUTHOR("Qualcomm Atheros Communications");
+MODULE_AUTHOR("Stefan Wahren <stefan.wahren@i2se.com>");
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_VERSION(QCAUART_DRV_VERSION);
+MODULE_ALIAS_LDISC(N_QCA7K);
diff --git a/include/uapi/linux/tty.h b/include/uapi/linux/tty.h
index 01c4410..53c2760 100644
--- a/include/uapi/linux/tty.h
+++ b/include/uapi/linux/tty.h
@@ -35,5 +35,6 @@
#define N_TRACESINK 23 /* Trace data routing for MIPI P1149.7 */
#define N_TRACEROUTER 24 /* Trace data routing for MIPI P1149.7 */
#define N_NCI 25 /* NFC NCI UART */
+#define N_QCA7K 26 /* Qualcomm QCA7000 Ethernet to UART */
#endif /* _UAPI_LINUX_TTY_H */
--
2.1.4
[toc] | [prev] | [next] | [standalone]
| From | Marcel Holtmann <marcel@holtmann.org> |
|---|---|
| Date | 2016-09-20 17:40 +0200 |
| Subject | Re: [PATCH net-next 8/8] net: qualcomm: add QCA7000 UART driver |
| Message-ID | <sjvjk-4Q2-3@gated-at.bofh.it> |
| In reply to | #1487325 |
Hi Stefan, > This patch adds the Ethernet over UART driver for the > Qualcomm QCA7000 HomePlug GreenPHY. > > Signed-off-by: Stefan Wahren <stefan.wahren@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 0d33728..0ede46e 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. > + this seems to be another candidate for having a proper UART or serial bus. Instead of adding one line discipline after another, I think we need to get quickly to having an enumerable bus here. Regards Marcel
[toc] | [prev] | [next] | [standalone]
| From | Stefan Wahren <stefan.wahren@i2se.com> |
|---|---|
| Date | 2016-09-21 09:50 +0200 |
| Subject | Re: [PATCH net-next 8/8] net: qualcomm: add QCA7000 UART driver |
| Message-ID | <sjKs2-68g-15@gated-at.bofh.it> |
| In reply to | #1487440 |
Hi Marcel, Am 20.09.2016 um 17:32 schrieb Marcel Holtmann: > Hi Stefan, > >> This patch adds the Ethernet over UART driver for the >> Qualcomm QCA7000 HomePlug GreenPHY. >> >> Signed-off-by: Stefan Wahren <stefan.wahren@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 0d33728..0ede46e 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. >> + > this seems to be another candidate for having a proper UART or serial bus. Instead of adding one line discipline after another, I think we need to get quickly to having an enumerable bus here. i noticed Rob's thread about the UART slave device bus and i like the idea. Stefan > > Regards > > Marcel >
[toc] | [prev] | [next] | [standalone]
| From | Stefan Wahren <stefan.wahren@i2se.com> |
|---|---|
| Date | 2016-09-20 18:50 +0200 |
| Subject | Re: [PATCH net-next 8/8] net: qualcomm: add QCA7000 UART driver |
| Message-ID | <sjwp4-5wd-13@gated-at.bofh.it> |
| In reply to | #1487325 |
> kbuild test robot <lkp@intel.com> hat am 20. September 2016 um 16:44 > geschrieben: > > > Hi Stefan, > > [auto build test ERROR on net-next/master] > > url: > https://github.com/0day-ci/linux/commits/Stefan-Wahren/net-qualcomm-add-QCA7000-UART-driver/20160920-210908 > config: i386-allmodconfig (attached as .config) > compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 > reproduce: > # save the attached .config to linux build tree > make ARCH=i386 > > All errors (new ones prefixed by >>): > > drivers/net/ethernet/qualcomm/qca_uart.c: In function > 'qcauart_netdev_xmit': > >> drivers/net/ethernet/qualcomm/qca_uart.c:302:5: error: 'struct net_device' > >> has no member named 'trans_start'; did you mean 'mem_start'? > dev->trans_start = jiffies; This should be replaced by netif_trans_update(dev) > ^~ > drivers/net/ethernet/qualcomm/qca_uart.c: In function > 'qcauart_netdev_tx_timeout': > drivers/net/ethernet/qualcomm/qca_uart.c:314:29: error: 'struct net_device' > has no member named 'trans_start'; did you mean 'mem_start'? > jiffies, jiffies - dev->trans_start); and this by dev_trans_start(dev) in the next version. Sorry about that :-(
[toc] | [prev] | [next] | [standalone]
| From | Stefan Wahren <stefan.wahren@i2se.com> |
|---|---|
| Date | 2016-09-20 15:10 +0200 |
| Subject | [PATCH net-next 6/8] net: qualcomm: prepare frame decoding for UART driver |
| Message-ID | <sjsYa-3nb-33@gated-at.bofh.it> |
| In reply to | #1487323 |
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.wahren@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(&qca->frm_handle);
+ qcafrm_fsm_init_spi(&qca->frm_handle);
qca->spi_thread = kthread_run((void *)qcaspi_spi_thread,
qca, "%s", dev->name);
--
2.1.4
[toc] | [prev] | [next] | [standalone]
| From | Stefan Wahren <stefan.wahren@i2se.com> |
|---|---|
| Date | 2016-09-20 15:10 +0200 |
| Subject | [PATCH net-next 5/8] net: qualcomm: move MTU handling to qca_common |
| Message-ID | <sjsYa-3nb-35@gated-at.bofh.it> |
| In reply to | #1487323 |
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.wahren@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 <linux/if_ether.h>
#include <linux/if_vlan.h>
+#include <linux/netdevice.h>
#include <linux/types.h>
/* 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
[toc] | [prev] | [next] | [standalone]
| From | Stefan Wahren <stefan.wahren@i2se.com> |
|---|---|
| Date | 2016-09-20 15:10 +0200 |
| Subject | [PATCH net-next 3/8] net: qualcomm: move qcaspi_tx_cmd to qca_spi.c |
| Message-ID | <sjsYa-3nb-43@gated-at.bofh.it> |
| In reply to | #1487323 |
The function qcaspi_tx_cmd() is only called from qca_spi.c. So we better
move it there.
Signed-off-by: Stefan Wahren <stefan.wahren@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 = &qca->spi_msg1;
- struct spi_transfer *transfer = &qca->spi_xfer1;
- int ret;
-
- tx_data = cpu_to_be16(cmd);
- transfer->len = sizeof(tx_data);
- transfer->tx_buf = &tx_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 = &qca->spi_msg1;
+ struct spi_transfer *transfer = &qca->spi_xfer1;
+ int ret;
+
+ tx_data = cpu_to_be16(cmd);
+ transfer->len = sizeof(tx_data);
+ transfer->tx_buf = &tx_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
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web