mbox series

[v14,0/4] userspace MHI client interface driver

Message ID 1606877991-26368-1-git-send-email-hemantk@codeaurora.org
Headers show
Series userspace MHI client interface driver | expand

Message

Hemant Kumar Dec. 2, 2020, 2:59 a.m. UTC
This patch series adds support for UCI driver. UCI driver enables userspace
clients to communicate to external MHI devices like modem and WLAN. UCI driver
probe creates standard character device file nodes for userspace clients to
perform open, read, write, poll and release file operations. These file
operations call MHI core layer APIs to perform data transfer using MHI bus
to communicate with MHI device. Patch is tested using arm64 and x86 based
platform.

V14:
- Fixed device file node format to /dev/<mhi_dev_name> instead of
  /dev/mhi_<mhi_dev_name> because "mhi" is already part of mhi device name.
  For example old format: /dev/mhi_mhi0_QMI new format: /dev/mhi0_QMI.
- Updated MHI documentation to reflect index mhi controller name in
  QMI usage example.

V13:
- Removed LOOPBACK channel from mhi_device_id table from this patch series.
  Pushing a new patch series to add support for LOOPBACK channel and the user
  space test application. Also removed the description from kernel documentation.
- Added QMI channel to mhi_device_id table. QMI channel has existing libqmi
  support from user space.
- Updated kernel Documentation for QMI channel and provided external reference
  for libqmi.
- Updated device file node name by appending mhi device name only, which already
  includes mhi controller device name.

V12:
- Added loopback test driver under selftest/drivers/mhi. Updated kernel
  documentation for the usage of the loopback test application.
- Addressed review comments for renaming variable names, updated inline
  comments and removed two redundant dev_dbg.

V11:
- Fixed review comments for UCI documentation by expanding TLAs and rewording
  some sentences.

V10:
- Replaced mutex_lock with mutex_lock_interruptible in read() and write() file
  ops call back.

V9:
- Renamed dl_lock to dl_pending _lock and pending list to dl_pending for
  clarity.
- Used read lock to protect cur_buf.
- Change transfer status check logic and only consider 0 and -EOVERFLOW as
  only success.
- Added __int to module init function.
- Print channel name instead of minor number upon successful probe.

V8:
- Fixed kernel test robot compilation error by changing %lu to %zu for
  size_t.
- Replaced uci with UCI in Kconfig, commit text, and comments in driver
  code.
- Fixed minor style related comments.

V7:
- Decoupled uci device and uci channel objects. uci device is
  associated with device file node. uci channel is associated
  with MHI channels. uci device refers to uci channel to perform
  MHI channel operations for device file operations like read()
  and write(). uci device increments its reference count for
  every open(). uci device calls mhi_uci_dev_start_chan() to start
  the MHI channel. uci channel object is tracking number of times
  MHI channel is referred. This allows to keep the MHI channel in
  start state until last release() is called. After that uci channel
  reference count goes to 0 and uci channel clean up is performed
  which stops the MHI channel. After the last call to release() if
  driver is removed uci reference count becomes 0 and uci object is
  cleaned up.
- Use separate uci channel read and write lock to fine grain locking
  between reader and writer.
- Use uci device lock to synchronize open, release and driver remove.
- Optimize for downlink only or uplink only UCI device.

V6:
- Moved uci.c to mhi directory.
- Updated Kconfig to add module information.
- Updated Makefile to rename uci object file name as mhi_uci
- Removed kref for open count

V5:
- Removed mhi_uci_drv structure.
- Used idr instead of creating global list of uci devices.
- Used kref instead of local ref counting for uci device and
  open count.
- Removed unlikely macro.

V4:
- Fix locking to protect proper struct members.
- Updated documentation describing uci client driver use cases.
- Fixed uci ref counting in mhi_uci_open for error case.
- Addressed style related review comments.

V3: Added documentation for MHI UCI driver.

V2:
- Added mutex lock to prevent multiple readers to access same
- mhi buffer which can result into use after free.

Hemant Kumar (4):
  bus: mhi: core: Add helper API to return number of free TREs
  bus: mhi: core: Move MHI_MAX_MTU to external header file
  docs: Add documentation for userspace client interface
  bus: mhi: Add userspace client interface driver

 Documentation/mhi/index.rst     |   1 +
 Documentation/mhi/uci.rst       |  94 ++++++
 drivers/bus/mhi/Kconfig         |  13 +
 drivers/bus/mhi/Makefile        |   3 +
 drivers/bus/mhi/core/internal.h |   1 -
 drivers/bus/mhi/core/main.c     |  12 +
 drivers/bus/mhi/uci.c           | 664 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mhi.h             |  12 +
 8 files changed, 799 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/mhi/uci.rst
 create mode 100644 drivers/bus/mhi/uci.c

Comments

Jeffrey Hugo Dec. 3, 2020, 8:38 p.m. UTC | #1
On 2020-12-01 19:59, Hemant Kumar wrote:
> MHI userspace client driver is creating device file node
> for user application to perform file operations. File
> operations are handled by MHI core driver. Currently
> QMI MHI channel is supported by this driver.
> 
> Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>

Two minor nits below.  With those -
Reviewed-by: Jeffrey Hugo <jhugo@codeaurora.org>

> ---
>  Documentation/mhi/index.rst |  1 +
>  Documentation/mhi/uci.rst   | 94 
> +++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 95 insertions(+)
>  create mode 100644 Documentation/mhi/uci.rst
> 
> diff --git a/Documentation/mhi/index.rst b/Documentation/mhi/index.rst
> index 1d8dec3..c75a371 100644
> --- a/Documentation/mhi/index.rst
> +++ b/Documentation/mhi/index.rst
> @@ -9,6 +9,7 @@ MHI
> 
>     mhi
>     topology
> +   uci
> 
>  .. only::  subproject and html
> 
> diff --git a/Documentation/mhi/uci.rst b/Documentation/mhi/uci.rst
> new file mode 100644
> index 0000000..9603f92
> --- /dev/null
> +++ b/Documentation/mhi/uci.rst
> @@ -0,0 +1,94 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +=================================
> +Userspace Client Interface (UCI)
> +=================================
> +
> +UCI driver enables userspace clients to communicate to external MHI 
> devices
> +like modem and WLAN. UCI driver probe creates standard character 
> device file
> +nodes for userspace clients to perform open, read, write, poll and 
> release file
> +operations. UCI device object represents UCI device file node which 
> gets
> +instantiated as part of MHI UCI driver probe. UCI channel object 
> represents
> +MHI uplink or downlink channel.
> +
> +Operations
> +==========
> +
> +open
> +----
> +
> +Instantiates UCI channel object and starts MHI channels to move it to 
> running
> +state. Inbound buffers are queued to downlink channel transfer ring. 
> Every
> +subsequent open() increments UCI device reference count as well as UCI 
> channel
> +reference count.
> +
> +read
> +----
> +
> +When data transfer is completed on downlink channel, transfer ring 
> element
> +buffer is copied to pending list. Reader is unblocked and data is 
> copied to
> +userspace buffer. Transfer ring element buffer is queued back to 
> downlink
> +channel transfer ring.
> +
> +write
> +-----
> +
> +Write buffer is queued to uplink channel transfer ring if ring is not
> full. Upon
> +uplink transfer completion buffer is freed.
> +
> +poll
> +----
> +
> +Returns EPOLLIN | EPOLLRDNORM mask if pending list has buffers to be 
> read by
> +userspace. Returns EPOLLOUT | EPOLLWRNORM mask if MHI uplink channel 
> transfer
> +ring is not empty. Returns EPOLLERR when UCI driver is removed.

ring is not empty.  When the uplink channel transfer ring is non-empty, 
more
data may be sent to the device. Returns EPOLLERR when UCI driver is 
removed.

> +
> +release
> +-------
> +
> +Decrements UCI device reference count and UCI channel reference count 
> upon last
> +release(). UCI channel clean up is performed. MHI channel moves to 
> disable
> +state and inbound buffers are freed.

Decrements UCI device reference count and UCI channel reference count. 
Upon last
release() UCI channel clean up is performed. MHI channel moves to 
disable
state and inbound buffers are freed.

> +
> +Usage
> +=====
> +
> +Device file node is created with format:-
> +
> +/dev/<mhi_device_name>
> +
> +mhi_device_name includes mhi controller name and the name of the MHI 
> channel
> +being used by MHI client in userspace to send or receive data using 
> MHI
> +protocol.
> +
> +There is a separate character device file node created for each 
> channel
> +specified in MHI device id table. MHI channels are statically defined 
> by MHI
> +specification. The list of supported channels is in the channel list 
> variable
> +of mhi_device_id table in UCI driver.
> +
> +Qualcomm MSM Interface(QMI) Channel
> +-----------------------------------
> +
> +Qualcomm MSM Interface(QMI) is a modem control messaging protocol used 
> to
> +communicate between software components in the modem and other 
> peripheral
> +subsystems. QMI communication is of request/response type or an 
> unsolicited
> +event type. libqmi is userspace MHI client which communicates to a QMI 
> service
> +using UCI device. It sends a QMI request to a QMI service using MHI 
> channel 14
> +or 16. QMI response is received using MHI channel 15 or 17 
> respectively. 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/
> +
> +Usage Example
> +~~~~~~~~~~~~~
> +
> +QMI command to retrieve device mode
> +$ sudo qmicli -d /dev/mhi0_QMI --dms-get-model
> +[/dev/mhi0_QMI] Device model retrieved:
> +    Model: 'FN980m'
> +
> +Other Use Cases
> +---------------
> +
> +Getting MHI device specific diagnostics information to userspace MHI 
> diagnostic
> +client using DIAG channel 4 (Host to device) and 5 (Device to Host).
Hemant Kumar Dec. 3, 2020, 9:37 p.m. UTC | #2
Hi Jeff

On 12/3/20 12:38 PM, jhugo@codeaurora.org wrote:
> On 2020-12-01 19:59, Hemant Kumar wrote:

>> MHI userspace client driver is creating device file node

>> for user application to perform file operations. File

>> operations are handled by MHI core driver. Currently

>> QMI MHI channel is supported by this driver.

>>

>> Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>

> 

> Two minor nits below.  With those -

> Reviewed-by: Jeffrey Hugo <jhugo@codeaurora.org>

> 

>> ---

>>  Documentation/mhi/index.rst |  1 +

>>  Documentation/mhi/uci.rst   | 94 

>> +++++++++++++++++++++++++++++++++++++++++++++

>>  2 files changed, 95 insertions(+)

>>  create mode 100644 Documentation/mhi/uci.rst

>>

>> diff --git a/Documentation/mhi/index.rst b/Documentation/mhi/index.rst

>> index 1d8dec3..c75a371 100644

>> --- a/Documentation/mhi/index.rst

>> +++ b/Documentation/mhi/index.rst

>> @@ -9,6 +9,7 @@ MHI

>>

>>     mhi

>>     topology

>> +   uci

>>

>>  .. only::  subproject and html

>>

>> diff --git a/Documentation/mhi/uci.rst b/Documentation/mhi/uci.rst

>> new file mode 100644

>> index 0000000..9603f92

>> --- /dev/null

>> +++ b/Documentation/mhi/uci.rst

>> @@ -0,0 +1,94 @@

>> +.. SPDX-License-Identifier: GPL-2.0

>> +

>> +=================================

>> +Userspace Client Interface (UCI)

>> +=================================

>> +

>> +UCI driver enables userspace clients to communicate to external MHI 

>> devices

>> +like modem and WLAN. UCI driver probe creates standard character 

>> device file

>> +nodes for userspace clients to perform open, read, write, poll and 

>> release file

>> +operations. UCI device object represents UCI device file node which gets

>> +instantiated as part of MHI UCI driver probe. UCI channel object 

>> represents

>> +MHI uplink or downlink channel.

>> +

>> +Operations

>> +==========

>> +

>> +open

>> +----

>> +

>> +Instantiates UCI channel object and starts MHI channels to move it to 

>> running

>> +state. Inbound buffers are queued to downlink channel transfer ring. 

>> Every

>> +subsequent open() increments UCI device reference count as well as 

>> UCI channel

>> +reference count.

>> +

>> +read

>> +----

>> +

>> +When data transfer is completed on downlink channel, transfer ring 

>> element

>> +buffer is copied to pending list. Reader is unblocked and data is 

>> copied to

>> +userspace buffer. Transfer ring element buffer is queued back to 

>> downlink

>> +channel transfer ring.

>> +

>> +write

>> +-----

>> +

>> +Write buffer is queued to uplink channel transfer ring if ring is not

>> full. Upon

>> +uplink transfer completion buffer is freed.

>> +

>> +poll

>> +----

>> +

>> +Returns EPOLLIN | EPOLLRDNORM mask if pending list has buffers to be 

>> read by

>> +userspace. Returns EPOLLOUT | EPOLLWRNORM mask if MHI uplink channel 

>> transfer

>> +ring is not empty. Returns EPOLLERR when UCI driver is removed.

> 

> ring is not empty.  When the uplink channel transfer ring is non-empty, 

> more

> data may be sent to the device. Returns EPOLLERR when UCI driver is 

> removed.

Done
> 

>> +

>> +release

>> +-------

>> +

>> +Decrements UCI device reference count and UCI channel reference count 

>> upon last

>> +release(). UCI channel clean up is performed. MHI channel moves to 

>> disable

>> +state and inbound buffers are freed.

> 

> Decrements UCI device reference count and UCI channel reference count. 

> Upon last

> release() UCI channel clean up is performed. MHI channel moves to disable

> state and inbound buffers are freed.

Done.
> 

>> +

>> +Usage

>> +=====

>> +

>> +Device file node is created with format:-

>> +

>> +/dev/<mhi_device_name>

>> +

>> +mhi_device_name includes mhi controller name and the name of the MHI 

>> channel

>> +being used by MHI client in userspace to send or receive data using MHI

>> +protocol.

>> +

>> +There is a separate character device file node created for each channel

>> +specified in MHI device id table. MHI channels are statically defined 

>> by MHI

>> +specification. The list of supported channels is in the channel list 

>> variable

>> +of mhi_device_id table in UCI driver.

>> +

>> +Qualcomm MSM Interface(QMI) Channel

>> +-----------------------------------

>> +

>> +Qualcomm MSM Interface(QMI) is a modem control messaging protocol 

>> used to

>> +communicate between software components in the modem and other 

>> peripheral

>> +subsystems. QMI communication is of request/response type or an 

>> unsolicited

>> +event type. libqmi is userspace MHI client which communicates to a 

>> QMI service

>> +using UCI device. It sends a QMI request to a QMI service using MHI 

>> channel 14

>> +or 16. QMI response is received using MHI channel 15 or 17 

>> respectively. 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/

>> +

>> +Usage Example

>> +~~~~~~~~~~~~~

>> +

>> +QMI command to retrieve device mode

>> +$ sudo qmicli -d /dev/mhi0_QMI --dms-get-model

>> +[/dev/mhi0_QMI] Device model retrieved:

>> +    Model: 'FN980m'

>> +

>> +Other Use Cases

>> +---------------

>> +

>> +Getting MHI device specific diagnostics information to userspace MHI 

>> diagnostic

>> +client using DIAG channel 4 (Host to device) and 5 (Device to Host).


Thanks,
Hemant
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project