Introduction
============

Upcoming targets such as 7x30 use an eMMC card as its primary storage device
eliminating the usage of NAND. The SD controller and the card are accessible
only by Apps processor. Modem has to depend on apps processor for updating modem
file system partition in the card. This software module provides the
implementation of the RPC server to service requests from modem when modem
file system partition needs to be updated.


Hardware description
====================

No new hardware is required. An eMMC card will have 2 partitions reserved for
modem storage.

Software description
====================

This software implements a remote storage RPC server for a client on the other
processor.  The Filesystem on modem sends RPC requests to server via the
Remote storage RPC client on modem processor.

Remote storage RPC server is registered with RPC infrastruture provided by the
kernel on apps processor.  The server accepts incoming requests from the
modem processor.

The control flow is as follows:

1. Modem processor sends a RPC request to remote storage server running on Apps
processor.

2. All the modem requests will be handled by a user space program and the remote
storage server will provide an interface to the user application to receive
the requests from modem and also to send the status of requests to modem.

Design
======

1. As only one kernel thread monitors the modem requests for all RPC servers
registered in Apps processor, the current design of this RPC server should be light
weight so as to not block other RPC servers.

Alternate designs considered were:
1. Handle all the RPC requests in kernel space without any user space
intervention by uisng VFS APIs.

2. Implement a user space server. User space servers are not currently
supported because of security concerns.

SMP/multi-core
==============

The queue of requests can be accessed concurrently by both user space program
and the RPC server. Hence a spinlock is used to add or remove a request to
the queue. There is no additional protection required to make this module work
on SMP.

Performance
===========

The Filesystem on modem processor syncs the whole data from shared memory
periodically. Considering this small amount of data, there could be an
insignificant amount of increase in access of SD card from apps processor
when flush happens.

Interface
=========

There are no exported kernel APIs.

1. The kernel driver registers itself as a misc driver and hence a device node
"/dev/rmt_storage" will be created for the user space program to open and
interact with kernel using ioctls.

The following ioctls are implemented:

        a. RMT_STORAGE_SHRD_MEM_PARAM - The ioctl to get the remote storage
	shared memory parameters. The user space application maps the
	shared memory by doing mmap() on /dev/rmt_storage.

        b. RMT_STORAGE_WAIT_FOR_REQ - This ioctl waits until an event is
	received by server from client. When an event is received, the driver
	parses the arguments and if they are valid, unblocks the user space
	program and returns success to client. If the parameters are invalid,
	it returns with error code.

        c. RMT_STORAGE_SEND_STATUS - If a client registers for a callback for
	any requets, the user space program after processing that request
	sends this ioctl to server to send the callback to client on modem
	processor.

Config options
==============

Enable the config option MSM_RMT_STORAGE_SERVER to compile the server.

Dependencies
============

The driver depends on the RPC framework provided by the kernel.

The driver interacts with AMSS Remote filesystem client on modem.

The driver interacts with AMSS Remote filesystem client on modem processor
using the standard ONCRPC mechanism.

User space utilities
====================

A user space program is written to process the requests from modem.

The control flow is as follows:

1. Open the device "/dev/rmt_storage".

2. Send the ioctl RMT_STORAGE_SHRD_MEM_PARAM to get the shared memory resource
parameters and mmap() the shared memory.

3. Send the ioctl RMT_STORAGE_WAIT_FOR_REQ to wait for an RPC event from client.
Handles all write requests on a parition in another pthread context.

4. After the processing of current request, it sends RMT_STORAGE_WAIT_FOR_REQ ioctl
and waits for another event.

5. Send RMT_STORAGE_SEND_STATUS to server to notify the status of write request
to server which sends a callback to modem processor with the status.
