msm: ipc: Serialize SMD XPRT CLOSE and OPEN events

When a remote subsystem resets, IPC Router's SMD XPRT Layer queues a CLOSE
event. When the concerned subsytem powers up and the channel is reopened,
SMD XPRT Layer queues a OPEN event. When the remote subsytem resets and
powers up quickly, the following race condition exists:
a) IPC Router is scheduled out while handling the CLOSE event, leaving a
   stale XPRT
b) IPC Router's SMD XPRT Layer queues a OPEN event
c) IPC Router's SMD XPRT Layer reads a HELLO message, finds a stale
   XPRT and queues a DATA event on the stale XPRT
This race condition causes a kernel panic.

Fix this race condition, by not handling any other SMD XPRT event until
the CLOSE event is complete.

CRs-Fixed: 488331
Change-Id: I2283e163413d1896bd6842530b8a6a2b537e22de
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc: Clean-up code redundancy

The receive message operation for the socket interface and the kernel
interface has redundant code.

Clean-up redundant code.

Change-Id: Ibe52816f5b567feab4d6247a3dba1945e209c626
Signed-off-by: Arun Kumar Neelakantam <aneela@codeaurora.org>
msm: ipc: Initialize unused elements of control message to 0

Initialize the entire control message to 0, so that unused elements of
a control message are initialized to 0. This will prevent any uninitialized
elements from leaking information to the remote subsystems.

Change-Id: I910f3956e8f282e614216c45f7af92d741d887f8
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc: Send Resume_Tx from the client/server context

Resume_tx is passed by IPC Router as soon as it detects confirm_rx
field being set in received message. In a scenario where the local port
towards which the confirm_rx is directed is not in a state of accepting
messages, this behavior of IPC Router makes the remote port send more
data towards the local port. In addition, in a multi-hop scenario the
resume_tx message holds the destination node_id as the value of the
neighbouring node_id which is incorrect.

Pass Resume_Tx from the context of the thread to which the local port is
associated. Pass the right node_id as destination node_id in the
Resume_Tx message.

Change-Id: I6a05a85978c38831bd95210b3617c5d015eac5e4
Signed-off-by: Zaheerulla Meer <zmeer@codeaurora.org>
msm: ipc: Fix memory leak

When IPC Router detects a data packet from an unknown remote port,
the router creates a remote port. In case of failure while creating the
remote port, router doesn't free the memory allocated to the data packet.
This leads to memory leak beacuse once the above mentioned failure
occurs, the data packet never gets used.

Fix the memory leak in case of failure while creating the remote port.

Change-Id: I168329db88afb6159b1eda64fbd4bbeb95fbd94f
Signed-off-by: Zaheerulla Meer <zmeer@codeaurora.org>
msm: ipc: Pass the local service events to local clients

When a service gets registered or unregistered locally, the concerned
events are sent only to the remote subsystems.

Pass the local service events to local clients so that clients and
services can be started in any order.

Change-Id: I1f672cb3e7cac2ae2f26922add0320ffd84a38ad
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc: Cleanup a routing table entry under subsystem restart

Currently when a remote subsystem restarts, the routing table entry
corresponding to that remote subsystem is recycled. This causes some
subsystems to be not reachable if the system's network topology is
not meshed.

Remove the routing table entry for a restarting subsystem so that
it gets added again either through HELLO message from that subsystem or
through first NEW_SERVER message from that subsystem.

Change-Id: I2957ebfb2b66610f68e000e42e2c07d463c89eb6
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc: Add support to handle version 2 header

IPC Router Message header is 32 bytes in size since each element uses
4 bytes in size regardless of the data range being represented.

Add a version 2 header format that compacts the header into 16 bytes.

Change-Id: I5e6cfc0672ca1dc3365b31c26d2ce4b3c6230cfc
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc: Return the error codes without modification

The user-space modules perform decisions regarding retransmission etc.
based on the error codes returned by the IPC Router.

So return the error codes as is without any modification to the
user-space.

Change-Id: Ic7012109c446aaeaba74c3a29cffd16c155e7212
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc: Fix SKB ownership for failure case

When a client writes to IPC Router and if the write fails, then in
certain scenarios both the client and IPC Router take up the ownership
of the SKB. These failure scenarios lead to a double-free and
segmentation fault.

Fix these scenarios by resolving the ownership issue. If the write to
IPC Router is successful, then IPC Router will keep the ownership of the
SKBs and free the packets. If the write fails, then the client will keep
the ownership of the SKBs and free the packets.

CRs-Fixed: 530180
Change-Id: Iaba47f5da377cdf0a6b16ae02d99eab91a9a6221
Signed-off-by: Zaheerulla Meer <zmeer@codeaurora.org>
msm: ipc: Append alignment bytes to loopback packet

When messages are looped back to the local port, the sender does not
append the alignment bytes while the receiver is discarding the
alignment bytes. This leads to receiver receiving an incomplete message.

Fix this issue by appending the alignment bytes in the loopback path.

Change-Id: Ie340e5311e15e39558a8fe9c95a54da686df4371
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc: Update the check for minimum packet size

IPC Router checks for the minimum packet size of the incoming message to
be at least 32 bytes. With IPC Router version 2 header, this check is
invalid for some packets.

Update the check for the minimum incoming packet size based on the
transport on which the packet is received.

Change-Id: Iacebfe876db2e5c3513d18fcfae425ea9bd6a7cd
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc: Possible memory corruption due to Sign Conversion

msm_ipc_router_skb_to_buf() takes an unsigned argument and assigns the
same to a signed local variable. This might cause issues when the value
of the argument is too high.

Change the datatype of the local variable to unsigned.

CRs-Fixed: 550606
Change-Id: I257a095681dd82fba05367fd6faf25820e95c719
Signed-off-by: Zaheerulla Meer <zmeer@codeaurora.org>
msm: qmi: Add infrastructure to enable QMI service development

1) Add interface functions to register & unregister a service.
2) Add interface functions to send response and indication messages.
3) Add a control port per endpoint to handle control events like client
removal.
4) Update IPC Router to pass out-of-band data like source address during
notification of events.

Change-Id: I4ed3a06f2646162e73053c858b5269fdd8de436e
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: ipc: Remove usage of modem_notifier

As modem_notifier library is not used by IPC Router, remove any
references to it from IPC Router files.

Change-Id: Id26ed446fada3b932bd23e5b18be24bf82dcbd8c
Signed-off-by: Zaheerulla Meer <zmeer@codeaurora.org>
msm: ipc: Migrate to wakeup sources from wake locks

Wakelock usage has been deprected. Update IPC Router to use wakeup
sources.

Change-Id: I7cf67a2f24241ec96e558478d532fe174abf17d9
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
msm: smem: split out shared memory initialization functionality

For historical reasons, the low level shared memory initialization
functionality exists in a combined driver with the higher level
communication protocols.  Move the low level shared memory functionality
out into its own driver to improve clarity and ease maintenance.

Change-Id: I675db52961df80d6e8e62e771630e562bf1a670c
Signed-off-by: Jeffrey Hugo <jhugo@codeaurora.org>
Signed-off-by: Kostas K <mpokwsths@gmail.com>

[mpokwsths: Adapted hammerhead board]

Conflicts:
	arch/arm/mach-msm/smd.c
msm: smd: add sanity check on platform resources

Add null sanity checks to fix corner cases.

Change-Id: Ic91ca37d74621ad414d23d8756881ee866250745
Signed-off-by: Brent Hronik <bhronik@codeaurora.org>
msm: smd_pkt: add enforcement that array lengths match number of ports

Additional checks are added to enforce that ports are equal in number
to the size of their representative arrays, to provide sanity checks when
ports are added or removed.

Change-Id: I83e7d74b8c21df8e357a817b7e542006b9b675a8
Signed-off-by: Brent Hronik <bhronik@codeaurora.org>
msm: smd_pkt: add additional smdcntl devices

Additional smdcntl devices are added to support Multi RMNET feature.

Change-Id: I6e0661e06af59235cd21ad8d15ee7324c40e8660
Signed-off-by: Brent Hronik <bhronik@codeaurora.org>