[PATCH v2] net: Add Qualcomm IPC router

2016-04-26 Thread Bjorn Andersson
From: Courtney Cavin 

Add an implementation of Qualcomm's IPC router protocol, used to
communicate with service providing remote processors.

Signed-off-by: Courtney Cavin 
Signed-off-by: Bjorn Andersson 
[bjorn: Cope with 0 being a valid node id and implement RTM_NEWADDR]
Signed-off-by: Bjorn Andersson 
---

Changes since v1:
- Made node 0 (normally the Qualcomm modem) a valid node
- Implemented RTM_NEWADDR for specifying the local node id

 include/linux/socket.h|4 +-
 include/uapi/linux/qrtr.h |   12 +
 net/Kconfig   |1 +
 net/Makefile  |1 +
 net/qrtr/Kconfig  |   24 ++
 net/qrtr/Makefile |2 +
 net/qrtr/qrtr.c   | 1007 +
 net/qrtr/qrtr.h   |   31 ++
 net/qrtr/smd.c|  117 ++
 9 files changed, 1198 insertions(+), 1 deletion(-)
 create mode 100644 include/uapi/linux/qrtr.h
 create mode 100644 net/qrtr/Kconfig
 create mode 100644 net/qrtr/Makefile
 create mode 100644 net/qrtr/qrtr.c
 create mode 100644 net/qrtr/qrtr.h
 create mode 100644 net/qrtr/smd.c

diff --git a/include/linux/socket.h b/include/linux/socket.h
index 73bf6c6a833b..b5cc5a6d7011 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -201,8 +201,9 @@ struct ucred {
 #define AF_NFC 39  /* NFC sockets  */
 #define AF_VSOCK   40  /* vSockets */
 #define AF_KCM 41  /* Kernel Connection Multiplexor*/
+#define AF_QIPCRTR 42  /* Qualcomm IPC Router  */
 
-#define AF_MAX 42  /* For now.. */
+#define AF_MAX 43  /* For now.. */
 
 /* Protocol families, same as address families. */
 #define PF_UNSPEC  AF_UNSPEC
@@ -249,6 +250,7 @@ struct ucred {
 #define PF_NFC AF_NFC
 #define PF_VSOCK   AF_VSOCK
 #define PF_KCM AF_KCM
+#define PF_QIPCRTR AF_QIPCRTR
 #define PF_MAX AF_MAX
 
 /* Maximum queue length specifiable by listen.  */
diff --git a/include/uapi/linux/qrtr.h b/include/uapi/linux/qrtr.h
new file mode 100644
index ..66c0748d26e2
--- /dev/null
+++ b/include/uapi/linux/qrtr.h
@@ -0,0 +1,12 @@
+#ifndef _LINUX_QRTR_H
+#define _LINUX_QRTR_H
+
+#include 
+
+struct sockaddr_qrtr {
+   __kernel_sa_family_t sq_family;
+   __u32 sq_node;
+   __u32 sq_port;
+};
+
+#endif /* _LINUX_QRTR_H */
diff --git a/net/Kconfig b/net/Kconfig
index a8934d8c8fda..b841c42e5c9b 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -236,6 +236,7 @@ source "net/mpls/Kconfig"
 source "net/hsr/Kconfig"
 source "net/switchdev/Kconfig"
 source "net/l3mdev/Kconfig"
+source "net/qrtr/Kconfig"
 
 config RPS
bool
diff --git a/net/Makefile b/net/Makefile
index 81d14119eab5..bdd14553a774 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -78,3 +78,4 @@ endif
 ifneq ($(CONFIG_NET_L3_MASTER_DEV),)
 obj-y  += l3mdev/
 endif
+obj-$(CONFIG_QRTR) += qrtr/
diff --git a/net/qrtr/Kconfig b/net/qrtr/Kconfig
new file mode 100644
index ..f053cc25f621
--- /dev/null
+++ b/net/qrtr/Kconfig
@@ -0,0 +1,24 @@
+# Qualcomm IPC Router configuration
+#
+
+config QRTR
+   bool "Qualcomm IPC Router support"
+   depends on ARCH_QCOM || COMPILE_TEST
+   ---help---
+ Say Y if you intend to use Qualcomm IPC router protocol.  The
+ protocol is used to communicate with services provided by other
+ hardware blocks in the system.
+
+ In order to do service lookups, a userspace daemon is required to
+ maintain a service listing.
+
+if QRTR
+
+config QRTR_SMD
+   tristate "SMD IPC Router channels"
+   depends on QRTR && QCOM_SMD && OF
+   ---help---
+ Say Y here to support SMD based ipcrouter channels.  SMD is the
+ most common transport for IPC Router.
+
+endif # QRTR
diff --git a/net/qrtr/Makefile b/net/qrtr/Makefile
new file mode 100644
index ..e282a84ffc5c
--- /dev/null
+++ b/net/qrtr/Makefile
@@ -0,0 +1,2 @@
+obj-y := qrtr.o
+obj-$(CONFIG_QRTR_SMD) += smd.o
diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c
new file mode 100644
index ..c985ecbe9bd6
--- /dev/null
+++ b/net/qrtr/qrtr.c
@@ -0,0 +1,1007 @@
+/*
+ * Copyright (c) 2015, Sony Mobile Communications Inc.
+ * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+#include 
+#include 
+#include 
+#include  /* For TIOCINQ/OUTQ */
+
+#include 
+
+#include "qrtr.h"
+
+#define QRTR_PROTO_VER 1
+
+/* auto-bind range */
+#define QRTR_MIN_

Re: [PATCH v2] net: Add Qualcomm IPC router

2016-04-27 Thread David Miller
From: Bjorn Andersson 
Date: Tue, 26 Apr 2016 22:48:05 -0700

> + rc = qcom_smd_send(qdev->channel, skb->data, skb->len);

I truly dislike adding networking protocols that depend upon some
piece of infrastructure that only some platforms can enable, it's even
worse when that set of platforms doesn't intersect with x86-64.

When you do things like this, it's quite hard to make protocol wide
changes to APIs because build testing becomes an issue.

This code can now only be build tested on ARCH_QCOM architectures, and
that's a serious negative downside.


Re: [PATCH v2] net: Add Qualcomm IPC router

2016-04-27 Thread Bjorn Andersson
On Wed 27 Apr 09:22 PDT 2016, David Miller wrote:

> From: Bjorn Andersson 
> Date: Tue, 26 Apr 2016 22:48:05 -0700
> 
> > +   rc = qcom_smd_send(qdev->channel, skb->data, skb->len);
> 
> I truly dislike adding networking protocols that depend upon some
> piece of infrastructure that only some platforms can enable, it's even
> worse when that set of platforms doesn't intersect with x86-64.
> 
> When you do things like this, it's quite hard to make protocol wide
> changes to APIs because build testing becomes an issue.
> 

That's a very valid concern.

> This code can now only be build tested on ARCH_QCOM architectures, and
> that's a serious negative downside.

For normal usage the QRTR_SMD doesn't make much sense to be selectable
unless QCOM_SMD is compiled in, but I can fix up the QCOM_SMD exports
and slap a COMPILE_TEST on it.


Looking at it again, we already have the conditional for QRTR and the OF
code in the driver went away a while back, so we're down to something
like:

depends on QCOM_SMD || COMPILE_TEST

Regards,
Bjorn


Re: [PATCH v2] net: Add Qualcomm IPC router

2016-04-27 Thread David Miller
From: Bjorn Andersson 
Date: Wed, 27 Apr 2016 10:14:45 -0700

> On Wed 27 Apr 09:22 PDT 2016, David Miller wrote:
> 
>> This code can now only be build tested on ARCH_QCOM architectures, and
>> that's a serious negative downside.
> 
> For normal usage the QRTR_SMD doesn't make much sense to be selectable
> unless QCOM_SMD is compiled in, but I can fix up the QCOM_SMD exports
> and slap a COMPILE_TEST on it.
> 
> 
> Looking at it again, we already have the conditional for QRTR and the OF
> code in the driver went away a while back, so we're down to something
> like:
> 
>   depends on QCOM_SMD || COMPILE_TEST

If that's enough to make it work, feel free to spin as a series a patch that
does the Kconfig bits and then the patch that adds the IPC protocol.