Re: [PATCH v17 3/3] bus: mhi: Add userspace client interface driver

2020-12-14 Thread Daniele Palmas
Hello,

Il giorno dom 13 dic 2020 alle ore 15:22 Manivannan Sadhasivam
 ha scritto:
>
> On Fri, Dec 11, 2020 at 08:08:16PM -0800, Jakub Kicinski wrote:
> > On Fri, 11 Dec 2020 11:37:34 -0600 Dan Williams wrote:
> > > Just to re-iterate: QMI ~= AT commands ~= MBIM (not quite, but same
> > > level)
> > >
> > > We already do QMI-over-USB, or AT-over-CDC-ACM. This is QMI-over-MHI.
> >
> > Why do we need a different QMI-over-X for every X? If you say there
> > are already chardev interfaces to configure WWAN why not provide one
> > of those?
> >
>
> Just because the underlying PHY is different and it offers more services than
> just configuring the modem (downloading crash dump, firmware download etc...)
>
> The existing chardev nodes are closely tied to the physical interfaces. For
> instance, /dev/cdc_wdm is used by the USB based WWAN devices. So we really 
> can't
> reuse it for MHI/PCIe.
>

let me also add that the current MHI UCI approach makes sense because
it makes the switch USB -> PCIe smooth, since all the current
open-source userspace tools (e.g. libqmi and qmicli), according to my
testing until now, properly works without any need for a change,
behaving the UCI QMI char device like cdc-wdm.

While a different solution (which one?) would maybe cause to re-think
the userspace side for having the same high-level behavior.

Thanks,
Daniele

> > > It's not networking data plane. It's WWAN device configuration.
> >
> > Ack. Not that network config doesn't fall under networking, but eh.
> > I wonder - did DaveM ever ack this, or was it just out of his sight
> > enough, behind the cdev, to never trigger a nack?
> >
> > > There are no current kernel APIs for this, and I really don't think we
> > > want there to be. The API surface is *huge* and we definitely don't
> > > want that in-kernel.
> >
> > It is what it is today for WWAN. I don't think anyone in the
> > development community or among users is particularly happy about
> > the situation. Which makes it rather self evident why there is
> > so much apprehension about this patch set. It's going to be
> > a user space channel for everything Qualcomm - AI accelerator etc.
> > Widening the WWAN status quo to more device types.
>
> Well not everything Qualcomm but for just the subsystems where there is no
> standardization right now. I think we went too far ahead for standardizing
> the modems.
>
> Thanks,
> Mani
>


Re: [PATCH v17 3/3] bus: mhi: Add userspace client interface driver

2020-12-11 Thread Manivannan Sadhasivam
On Fri, Dec 11, 2020 at 08:08:16PM -0800, Jakub Kicinski wrote:
> On Fri, 11 Dec 2020 11:37:34 -0600 Dan Williams wrote:
> > Just to re-iterate: QMI ~= AT commands ~= MBIM (not quite, but same
> > level)
> > 
> > We already do QMI-over-USB, or AT-over-CDC-ACM. This is QMI-over-MHI.
> 
> Why do we need a different QMI-over-X for every X? If you say there 
> are already chardev interfaces to configure WWAN why not provide one 
> of those?
> 

Just because the underlying PHY is different and it offers more services than
just configuring the modem (downloading crash dump, firmware download etc...)

The existing chardev nodes are closely tied to the physical interfaces. For
instance, /dev/cdc_wdm is used by the USB based WWAN devices. So we really can't
reuse it for MHI/PCIe.

> > It's not networking data plane. It's WWAN device configuration.
> 
> Ack. Not that network config doesn't fall under networking, but eh.
> I wonder - did DaveM ever ack this, or was it just out of his sight
> enough, behind the cdev, to never trigger a nack?
> 
> > There are no current kernel APIs for this, and I really don't think we
> > want there to be. The API surface is *huge* and we definitely don't
> > want that in-kernel.
> 
> It is what it is today for WWAN. I don't think anyone in the
> development community or among users is particularly happy about
> the situation. Which makes it rather self evident why there is 
> so much apprehension about this patch set. It's going to be 
> a user space channel for everything Qualcomm - AI accelerator etc.
> Widening the WWAN status quo to more device types.

Well not everything Qualcomm but for just the subsystems where there is no
standardization right now. I think we went too far ahead for standardizing
the modems.

Thanks,
Mani



Re: [PATCH v17 3/3] bus: mhi: Add userspace client interface driver

2020-12-11 Thread Jakub Kicinski
On Fri, 11 Dec 2020 11:37:34 -0600 Dan Williams wrote:
> Just to re-iterate: QMI ~= AT commands ~= MBIM (not quite, but same
> level)
> 
> We already do QMI-over-USB, or AT-over-CDC-ACM. This is QMI-over-MHI.

Why do we need a different QMI-over-X for every X? If you say there 
are already chardev interfaces to configure WWAN why not provide one 
of those?

> It's not networking data plane. It's WWAN device configuration.

Ack. Not that network config doesn't fall under networking, but eh.
I wonder - did DaveM ever ack this, or was it just out of his sight
enough, behind the cdev, to never trigger a nack?

> There are no current kernel APIs for this, and I really don't think we
> want there to be. The API surface is *huge* and we definitely don't
> want that in-kernel.

It is what it is today for WWAN. I don't think anyone in the
development community or among users is particularly happy about
the situation. Which makes it rather self evident why there is 
so much apprehension about this patch set. It's going to be 
a user space channel for everything Qualcomm - AI accelerator etc.
Widening the WWAN status quo to more device types.


Re: [PATCH v17 3/3] bus: mhi: Add userspace client interface driver

2020-12-11 Thread Dan Williams
On Fri, 2020-12-11 at 08:44 +0100, Greg KH wrote:
> On Thu, Dec 10, 2020 at 11:04:11PM -0800, Hemant Kumar wrote:
> > This MHI client driver allows userspace clients to transfer
> > raw data between MHI device and host using standard file
> > operations.
> > Driver instantiates UCI device object which is associated to device
> > file node. UCI device object instantiates UCI channel object when
> > device
> > file node is opened. UCI channel object is used to manage MHI
> > channels
> > by calling MHI core APIs for read and write operations. MHI
> > channels
> > are started as part of device open(). MHI channels remain in start
> > state until last release() is called on UCI device file node.
> > Device
> > file node is created with format
> > 
> > /dev/
> > 
> > Currently it supports QMI channel. libqmi is userspace MHI client
> > which
> > communicates to a QMI service using QMI channel. libqmi is a glib-
> > based
> > library for talking to WWAN modems and devices which speaks QMI
> > protocol.
> > For more information about libqmi please refer
> > https://www.freedesktop.org/wiki/Software/libqmi/
> 
> This says _what_ this is doing, but not _why_.
> 
> Why do you want to circumvent the normal user/kernel apis for this
> type
> of device and move the normal network handling logic out to
> userspace?
> What does that help with?  What does the current in-kernel api lack
> that
> this userspace interface is going to solve, and why can't the in-
> kernel
> api solve it instead?
> 
> You are pushing a common user/kernel api out of the kernel here, to
> become very device-specific, with no apparent justification as to why
> this is happening.
> 
> Also, because you are going around the existing network api, I will
> need
> the networking maintainers to ack this type of patch.

Just to re-iterate: QMI ~= AT commands ~= MBIM (not quite, but same
level)

We already do QMI-over-USB, or AT-over-CDC-ACM. This is QMI-over-MHI.

It's not networking data plane. It's WWAN device configuration.

There are no current kernel APIs for this, and I really don't think we
want there to be. The API surface is *huge* and we definitely don't
want that in-kernel.

Dan



Re: [PATCH v17 3/3] bus: mhi: Add userspace client interface driver

2020-12-11 Thread 殷张成
Hi,
Maybe it is a good idea to take QMI as example. QMI is QUALCOMM private 
protocol, maybe lots of people do not know what is QMI?
MHI device can be WIFI device or WWAN device, if it is WIFI device, it 
is a pure network device, and maybe do not need this driver.
But for WWAN devices, it support AT/NMEA/QMI/MBIM etc. protocol. And 
this driver is work for these functions.

There are similar drivers in the kernel for WWAN devices base on USB 
interface.
Like drivers/usb/class/cdc-wdm.c (for QMI & MBIM), and 
drivers/usb/serial/usb_wwan.c (for AT/NMEA)
For USB WWAN devices, open source softwares 
libqmi/libmbim/ModemManager/LVFS want to commutate with WWAN devices via above 
2 drivers.
For MHI WWAN devices, these open source software also need such driver.


On 11 Dec 2020 08:44:29, Greg KH wrote:

> On Thu, Dec 10, 2020 at 11:04:11PM -0800, Hemant Kumar wrote:
> > This MHI client driver allows userspace clients to transfer raw data
> > between MHI device and host using standard file operations.
> > Driver instantiates UCI device object which is associated to device
> > file node. UCI device object instantiates UCI channel object when
> > device file node is opened. UCI channel object is used to manage MHI
> > channels by calling MHI core APIs for read and write operations. MHI
> > channels are started as part of device open(). MHI channels remain in
> > start state until last release() is called on UCI device file node.
> > Device file node is created with format
> >
> > /dev/
> >
> > Currently it supports QMI channel. libqmi is userspace MHI client
> > which communicates to a QMI service using QMI channel. libqmi is a
> > glib-based library for talking to WWAN modems and devices which speaks QMI
> protocol.
> > For more information about libqmi please refer
> > https://www.freedesktop.org/wiki/Software/libqmi/
> 
> This says _what_ this is doing, but not _why_.
> 
> Why do you want to circumvent the normal user/kernel apis for this type of
> device and move the normal network handling logic out to userspace?
> What does that help with?  What does the current in-kernel api lack that this
> userspace interface is going to solve, and why can't the in-kernel api solve 
> it
> instead?
> 
> You are pushing a common user/kernel api out of the kernel here, to become
> very device-specific, with no apparent justification as to why this is 
> happening.
> 
> Also, because you are going around the existing network api, I will need the
> networking maintainers to ack this type of patch.
> 
> thanks,
> 
> greg k-h
> 
> 
>


Re: [PATCH v17 3/3] bus: mhi: Add userspace client interface driver

2020-12-11 Thread Loic Poulain
On Fri, 11 Dec 2020 at 08:44, Greg KH  wrote:
>
> On Thu, Dec 10, 2020 at 11:04:11PM -0800, Hemant Kumar wrote:
> > This MHI client driver allows userspace clients to transfer
> > raw data between MHI device and host using standard file operations.
> > Driver instantiates UCI device object which is associated to device
> > file node. UCI device object instantiates UCI channel object when device
> > file node is opened. UCI channel object is used to manage MHI channels
> > by calling MHI core APIs for read and write operations. MHI channels
> > are started as part of device open(). MHI channels remain in start
> > state until last release() is called on UCI device file node. Device
> > file node is created with format
> >
> > /dev/
> >
> > Currently it supports QMI channel. libqmi is userspace MHI client which
> > communicates to a QMI service using QMI channel. libqmi is a glib-based
> > library for talking to WWAN modems and devices which speaks QMI protocol.
> > For more information about libqmi please refer
> > https://www.freedesktop.org/wiki/Software/libqmi/
>
> This says _what_ this is doing, but not _why_.
>
> Why do you want to circumvent the normal user/kernel apis for this type
> of device and move the normal network handling logic out to userspace?
> What does that help with?  What does the current in-kernel api lack that
> this userspace interface is going to solve, and why can't the in-kernel
> api solve it instead?
>
> You are pushing a common user/kernel api out of the kernel here, to
> become very device-specific, with no apparent justification as to why
> this is happening.

That would probably deserve re-wording indeed. This interface offers
access to the modem control channel(s), which can be QMI (added in
this patch), MBIM, or the old known AT protocol. Because there is no
WWAN subsystem, these control pipes are directly exposed to userspace
and accessed by tools like libqmi, ModemManager, minicom (for AT)
etc... However, the data path, transporting the network payload (IP)
is well routed to the Linux network via the mhi-net driver.

>
> Also, because you are going around the existing network api, I will need
> the networking maintainers to ack this type of patch.


Re: [PATCH v17 3/3] bus: mhi: Add userspace client interface driver

2020-12-11 Thread Manivannan Sadhasivam
Hi Greg,

On Fri, Dec 11, 2020 at 08:44:29AM +0100, Greg KH wrote:
> On Thu, Dec 10, 2020 at 11:04:11PM -0800, Hemant Kumar wrote:
> > This MHI client driver allows userspace clients to transfer
> > raw data between MHI device and host using standard file operations.
> > Driver instantiates UCI device object which is associated to device
> > file node. UCI device object instantiates UCI channel object when device
> > file node is opened. UCI channel object is used to manage MHI channels
> > by calling MHI core APIs for read and write operations. MHI channels
> > are started as part of device open(). MHI channels remain in start
> > state until last release() is called on UCI device file node. Device
> > file node is created with format
> > 
> > /dev/
> > 
> > Currently it supports QMI channel. libqmi is userspace MHI client which
> > communicates to a QMI service using QMI channel. libqmi is a glib-based
> > library for talking to WWAN modems and devices which speaks QMI protocol.
> > For more information about libqmi please refer
> > https://www.freedesktop.org/wiki/Software/libqmi/
> 
> This says _what_ this is doing, but not _why_.
> 
> Why do you want to circumvent the normal user/kernel apis for this type
> of device and move the normal network handling logic out to userspace?
> What does that help with?  What does the current in-kernel api lack that
> this userspace interface is going to solve, and why can't the in-kernel
> api solve it instead?
> 

Well, this driver is not moving the network handling logic out. Instead
this driver just exposes a channel which can be used to configure the
modem using the existing userspace library like libqmi. Then the networking
logic is handled by a separate in kernel driver called mhi-net which is queued
for v5.11.

This is same for most of the Qualcomm USB modems as well. They expose a chardev
node like /dev/cdc_wdm0 for configuration and once configured the networking
logic is handled by usual network interface wwan0.

The difference here is that the underlying physical layer is PCIe and there is
this MHI bus which sits on top of it.

> You are pushing a common user/kernel api out of the kernel here, to
> become very device-specific, with no apparent justification as to why
> this is happening.
> 
> Also, because you are going around the existing network api, I will need
> the networking maintainers to ack this type of patch.
> 

No, this driver is not at all touching the networking part. As said, the
networking logic is all handled by mhi-net driver.

Thanks,
Mani
> thanks,
> 
> greg k-h


Re: [PATCH v17 3/3] bus: mhi: Add userspace client interface driver

2020-12-10 Thread Greg KH
On Thu, Dec 10, 2020 at 11:04:11PM -0800, Hemant Kumar wrote:
> This MHI client driver allows userspace clients to transfer
> raw data between MHI device and host using standard file operations.
> Driver instantiates UCI device object which is associated to device
> file node. UCI device object instantiates UCI channel object when device
> file node is opened. UCI channel object is used to manage MHI channels
> by calling MHI core APIs for read and write operations. MHI channels
> are started as part of device open(). MHI channels remain in start
> state until last release() is called on UCI device file node. Device
> file node is created with format
> 
> /dev/
> 
> Currently it supports QMI channel. libqmi is userspace MHI client which
> communicates to a QMI service using QMI channel. libqmi is a glib-based
> library for talking to WWAN modems and devices which speaks QMI protocol.
> For more information about libqmi please refer
> https://www.freedesktop.org/wiki/Software/libqmi/

This says _what_ this is doing, but not _why_.

Why do you want to circumvent the normal user/kernel apis for this type
of device and move the normal network handling logic out to userspace?
What does that help with?  What does the current in-kernel api lack that
this userspace interface is going to solve, and why can't the in-kernel
api solve it instead?

You are pushing a common user/kernel api out of the kernel here, to
become very device-specific, with no apparent justification as to why
this is happening.

Also, because you are going around the existing network api, I will need
the networking maintainers to ack this type of patch.

thanks,

greg k-h


[PATCH v17 3/3] bus: mhi: Add userspace client interface driver

2020-12-10 Thread Hemant Kumar
This MHI client driver allows userspace clients to transfer
raw data between MHI device and host using standard file operations.
Driver instantiates UCI device object which is associated to device
file node. UCI device object instantiates UCI channel object when device
file node is opened. UCI channel object is used to manage MHI channels
by calling MHI core APIs for read and write operations. MHI channels
are started as part of device open(). MHI channels remain in start
state until last release() is called on UCI device file node. Device
file node is created with format

/dev/

Currently it supports QMI channel. libqmi is userspace MHI client which
communicates to a QMI service using QMI channel. libqmi is a glib-based
library for talking to WWAN modems and devices which speaks QMI protocol.
For more information about libqmi please refer
https://www.freedesktop.org/wiki/Software/libqmi/

Signed-off-by: Hemant Kumar 
Reviewed-by: Manivannan Sadhasivam 
Reviewed-by: Jeffrey Hugo 
Tested-by: Loic Poulain 
---
 drivers/bus/mhi/Kconfig  |  13 +
 drivers/bus/mhi/Makefile |   3 +
 drivers/bus/mhi/uci.c| 664 +++
 3 files changed, 680 insertions(+)
 create mode 100644 drivers/bus/mhi/uci.c

diff --git a/drivers/bus/mhi/Kconfig b/drivers/bus/mhi/Kconfig
index da5cd0c..5194e8e 100644
--- a/drivers/bus/mhi/Kconfig
+++ b/drivers/bus/mhi/Kconfig
@@ -29,3 +29,16 @@ config MHI_BUS_PCI_GENERIC
  This driver provides MHI PCI controller driver for devices such as
  Qualcomm SDX55 based PCIe modems.
 
+config MHI_UCI
+   tristate "MHI UCI"
+   depends on MHI_BUS
+   help
+ MHI based Userspace Client Interface (UCI) driver is used for
+ transferring raw data between host and device using standard file
+ operations from userspace. Open, read, write, poll and close
+ operations are supported by this driver. Please check
+ mhi_uci_match_table for all supported channels that are exposed to
+ userspace.
+
+ To compile this driver as a module, choose M here: the module will be
+ called mhi_uci.
diff --git a/drivers/bus/mhi/Makefile b/drivers/bus/mhi/Makefile
index 0a2d778..69f2111 100644
--- a/drivers/bus/mhi/Makefile
+++ b/drivers/bus/mhi/Makefile
@@ -4,3 +4,6 @@ obj-y += core/
 obj-$(CONFIG_MHI_BUS_PCI_GENERIC) += mhi_pci_generic.o
 mhi_pci_generic-y += pci_generic.o
 
+# MHI client
+mhi_uci-y := uci.o
+obj-$(CONFIG_MHI_UCI) += mhi_uci.o
diff --git a/drivers/bus/mhi/uci.c b/drivers/bus/mhi/uci.c
new file mode 100644
index 000..1df2377
--- /dev/null
+++ b/drivers/bus/mhi/uci.c
@@ -0,0 +1,664 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.*/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MHI_UCI_DRIVER_NAME "mhi_uci"
+#define MHI_MAX_UCI_MINORS 128
+
+static DEFINE_IDR(uci_idr);
+static DEFINE_MUTEX(uci_drv_mutex);
+static struct class *uci_dev_class;
+static int uci_dev_major;
+
+/**
+ * struct uci_chan - MHI channel for a UCI device
+ * @udev: associated UCI device object
+ * @ul_wq: wait queue for writer
+ * @write_lock: mutex write lock for ul channel
+ * @dl_wq: wait queue for reader
+ * @read_lock: mutex read lock for dl channel
+ * @dl_pending_lock: spin lock for dl_pending list
+ * @dl_pending: list of dl buffers userspace is waiting to read
+ * @cur_buf: current buffer userspace is reading
+ * @dl_size: size of the current dl buffer userspace is reading
+ * @ref_count: uci_chan reference count
+ */
+struct uci_chan {
+   struct uci_dev *udev;
+   wait_queue_head_t ul_wq;
+
+   /* ul channel lock to synchronize multiple writes */
+   struct mutex write_lock;
+
+   wait_queue_head_t dl_wq;
+
+   /* dl channel lock to synchronize multiple reads */
+   struct mutex read_lock;
+
+   /*
+* protects pending list in bh context, channel release, read and
+* poll
+*/
+   spinlock_t dl_pending_lock;
+
+   struct list_head dl_pending;
+   struct uci_buf *cur_buf;
+   size_t dl_size;
+   struct kref ref_count;
+};
+
+/**
+ * struct uci_buf - UCI buffer
+ * @data: data buffer
+ * @len: length of data buffer
+ * @node: list node of the UCI buffer
+ */
+struct uci_buf {
+   void *data;
+   size_t len;
+   struct list_head node;
+};
+
+/**
+ * struct uci_dev - MHI UCI device
+ * @minor: UCI device node minor number
+ * @mhi_dev: associated mhi device object
+ * @uchan: UCI uplink and downlink channel object
+ * @mtu: max TRE buffer length
+ * @enabled: Flag to track the state of the UCI device
+ * @lock: mutex lock to manage uchan object
+ * @ref_count: uci_dev reference count
+ */
+struct uci_dev {
+   unsigned int minor;
+   struct mhi_device *mhi_dev;
+   struct uci_chan *uchan;
+   size_t mtu;
+   bool enabled;
+
+   /* synchronize open, release and driver remove */
+   struct mutex lock;
+