23 Commits

Author SHA1 Message Date
Deepak Kumar Singh
1f4cfcf9ec rpmsg: glink: spi: increment channel ref count before intent request
Releasing the glink spi channel while a client is waiting on
intent request queue can result in use after free case.

To avoid channel release in this case, first incrementing
channel ref count and then waiting for intent response.

In ssr case  waking up threads waiting for intent to decrement
the channel ref count, so that channel release operation is not delayed.

CR-Fixed: 2400497
Change-Id: I109db54e0203d47ba897a95d426082dab5d1bc23
Signed-off-by: Deepak Kumar Singh <deesin@codeaurora.org>
2019-02-25 16:05:57 +05:30
Deepak Kumar Singh
ba3270bd4a rpmsg: glink: spi: wakeup thread waiting on intent
Releasing the glink spi channel while a client is waiting
on intent request queue can result in use after free case.

Waking up the waiting thread before channel release.

Change-Id: I697f53e6e91b67c1ef3bc310f0a29dfd28ae7826
Signed-off-by: Deepak Kumar Singh <deesin@codeaurora.org>
2019-02-04 09:49:16 -08:00
Arun Kumar Neelakantam
90ffd4bd7b rpmsg: glink: spi: Use mutex lock for idr_lock
Using glink structure idr_lock as spinlock and channel structure
intent_lock as mutexlock cause problem when last reference to channel
is put during cleanup by holding idr_lock spinlock.

Convert the idr_lock to mutex lock to avoid lock hierarchy issues.

CRs-Fixed: 2389162
Change-Id: I68e2e3646f80171f67f922418204052888eefa78
Signed-off-by: Arun Kumar Neelakantam <aneela@codeaurora.org>
2019-01-30 18:09:39 +05:30
Chris Lew
80930678aa rpmsg: glink: spi: Fix reuseable intent leak
Reusuable intents are not freed on channel release, add handling to
free the local intents and destroy the intent idr structures in the
channel release work.

Change-Id: I4b314513737815d60eae2079c3c53828638ab372
Signed-off-by: Chris Lew <clew@codeaurora.org>
2019-01-10 16:12:04 -08:00
vkakani
a9290e39d1 msm: arm64: remove print formatting warnings
Resolve all warnings related to printk across drivers.

Change-Id: I5c6829943edd65c658b28c8275757a58ba28e942
Signed-off-by: vkakani <vkakani@codeaurora.org>
2018-12-20 15:09:22 +05:30
Chris Lew
9c5ac25799 rpmsg: glink: spi: Reduce tx sleep
The glink spi use case have strict latency requirements. Reduce the tx
wait time to improve latency during high throughput usecases.

Change-Id: Ief636ecd0def50ab59df1f190a7dd735e89c8344
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-10-31 14:33:11 -07:00
Chris Lew
c8856cdf11 rpmsg: glink: spi: Ensure rx_done is sent before data
The WDSP processor has limited memory for intents. It is important that
intents are returned before sending additional requests. This change
removes the rx_intent workqueue and sends the rx done cmd while holding
the intent lock to prevent sends from happening before the rx done cmd
is sent.

Send the rx done cmd before calling the client's rx cb. This ensures
the spi send work is done before the client can signal its next send.
Free the local intent after the the rx cb. This sequence should reduce
the intent lock contention.

Change-Id: Icb91b5ab9171275a4ed1cb0fffd70dab11d9f526
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-10-31 14:32:58 -07:00
Chris Lew
1eed7f11e5 rpmsg: glink: spi: Rename structs
Rename structs that have the same identifier as native glink. This will
help debugging glink from ramdumps and prevent collisions in the
debugger. Fix alignment issues caused from name changes.

Change-Id: I922133e45681bdbefba7b5e81a6ab3da9dd1ddc0
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-10-30 15:14:54 -07:00
Chris Lew
3c0655f130 rpmsg: glink: spi: Update intent before sending cmd
There is a race between updating the intent offset and writing the data
cmd onto the spi bus. If the remote side reads the data cmd and
responds with a rx_done cmd, the intent for that data cmd will be freed
before the offset is updated in glink_spi_send_data.

Move the offset update above the cmd write so all local state updates
are finished before the remote receives any cmds.

Change-Id: I453b7c464a33743fbcb9efee56505b872f2ab804
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-09-14 11:26:32 -07:00
Chris Lew
be9e06a7f2 rpmsg: glink: spi: Rework glink spi bus voting logic
The spi suspend callback should be used when a driver would like to
suspend the bus, it does not act as a voting mechanism. Instead of the
suspend callback, GLINK should respond to the SUSPEND_EVENT with EBUSY
if there are transactions in flight. Change the activity flag to a
counter to keep track of the different active threads.

Before sending any data on the spi bus, GLINK should call the resume
callback. Increment the activity count on each thread before command
processing.

Change-Id: Iefbbac78bdd9d171bdfd2fdb3a339f040eb4347a
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-08-29 15:51:21 -07:00
Chris Lew
dcf44293cd rpmsg: glink: spi: Use irq safe spinlocks
The glink spi command handler is done from the wcd spi component
context which is not necessarily a true interrupt. Use the irqsave and
irqrestore APIs to avoid any spinlock issues.

Change-Id: Id1857d44f8bf2da4550ece30284dd6890851e686
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-08-29 11:00:46 -07:00
Chris Lew
83e8c3e951 rpmsg: glink: spi: Change in_reset to atomic
The reset status variable can be changed from different threads. Use
atomic_t for implicit ordering while checking the values.

Change-Id: I489f276288076f5a9ec2fb64f537824bc8d1f6dd
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-08-29 11:00:46 -07:00
Chris Lew
7ec1605a1d rpmsg: glink: spi: Try to send rx done immediately
Some remote processors and usecases such as audio playback are
sensitive to the response time of rx done. Try to send the rx done cmd
from rx context. If trysend fails, defer the rx done work like before.

Change-Id: I299cc30920d1a6adfe597001d84a052f886141d0
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-08-29 11:00:45 -07:00
Chris Lew
0f798a6530 rpmsg: glink: spi: Cancel intent work in remove
The remote may not get a chance to send a close command during reset.
Cancel any intent work in transport remove to fully cleanup the channel
resources before freeing the channel structure.

Change-Id: I895f5bcc26bd1727e8a2277d2965597dae5a425b
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-08-29 10:59:38 -07:00
Chris Lew
8cf25cc13d rpmsg: glink: spi: Fix idr and channel refcounts
Each kref_put represents a cleanup for an open function. Remove the
extra kref put and rely on transport remove to cleanup any defunct
channels. Remove the idr from the lcid and rcid lists since the idr is
added on the open calls. This prevents any references to the dangling
pointers after cleanup.

Change-Id: I5c78ab17b716f5dea36b5d23ed2888ad5743edbf
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-08-29 10:55:40 -07:00
Chris Lew
0eaf889c36 Revert "rpmsg: glink: spi: unregister rpdev during ept destroy"
This reverts commit 3f896899a34b48a4a058df7f892f5e24a531ef18.
There is an incorrect kref_put loop in this change. It results in a
use after free during ssr.

Change-Id: I6620248002db1f2bb71b7325576c95e19d31b6ea
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-08-28 13:15:11 -07:00
Chris Lew
3f896899a3 rpmsg: glink: spi: unregister rpdev during ept destroy
Rpmsg device unregister is not happening if channel close is triggered
from local side and causing re-registration of device failures.

Unregister rpmsg device for local close in endpoint destroy path.

Change-Id: Ic0c66346577cf63546c13b341c6313a8d478d8e5
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-07-29 17:03:16 -07:00
Chris Lew
467a83db0b rpmsg: glink: spi: Write unaligned data with short pkt
Writes on the SPI bus must be aligned to 4 bytes. If the data is not 4
byte aligned, first send an aligned chunk and then the rest of the data
as part of a short data pkt.

Change-Id: Ib9eea28d6c6e598aa7f7981bdb237c1305cce0d3
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-07-29 17:03:15 -07:00
Chris Lew
d9956e8005 rpmsg: glink: spi: Hold channel reference during send
Hold a refcount while clients are sending so the channel is not freed
during the send. This is important for when glink spi is waiting for
an intent but the wdsp processor crashes.

Change-Id: I0cb8dac6f12694441b24e804d86bbfeb3ec9eb6a
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-07-27 17:49:00 -07:00
Chris Lew
57e36b7db1 rpmsg: glink: spi: Cancel work threads during remove
Ensure all queued work is finished before cleaning up and freeing the
channel structures. This prevents any use after frees that can happen
when an event occurs and the wdsp crashes at the same time.

Change-Id: I6e95dae835492e4bc854fe5fb110badba79dc1ad
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-07-27 17:49:00 -07:00
Chris Lew
6da83f9df5 rpmsg: glink: spi: Fix use after free of channel refcount
Channel reference count is used after free in case of channel
is not fully opened due to errors and SSR happens.

Remove the channel ID from glink LCID list for last reference to
avoid re-using the stale pointer from LCID list.

Change-Id: If038dd4d09440b925537ef2dab86fc80a07b203c
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-07-23 10:30:53 -07:00
Chris Lew
f961f2e666 rpmsg: glink: spi: Set tail pointer to 0 at end of FIFO
When wrapping around the FIFO, the remote expects the tail pointer to
be reset to 0 on the edge case where the tail equals the FIFO length.

Change-Id: If6d43ce481f28a46a344abe8eaf3ba476a3933ed
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-07-23 10:27:14 -07:00
Chris Lew
3a63e37c1d rpmsg: Introduce GLINK SPI driver
Add support for the GLINK SPI driver to communicate to the codec
processor. This driver uses the wdsp spi interface to send and receive
messages on a SPI bus.

Change-Id: I50c0f0023d26e547afa9baf64d0715002ced7347
Signed-off-by: Chris Lew <clew@codeaurora.org>
2018-04-24 11:32:25 -07:00