The artifical timeout of 10 seconds on select() seems to be a
development remnant and causes a system in sleep to wake up
unnecessarily. Remove this and rely on the registered wake events.
Reported-by: Sreelakshmi Gownipalli <sgownipa@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Introduce a flow control context per peripheral and pass this to
dm_broadcast() for data channels in order for any queued messages to be
accounted for in the flow control context.
Associate the same flow control context with the read watcher for the
peripheral's incoming data descriptors to make the watch runner
selectively read from the given peripheral only when the number of
outstanding, queued, messages are below the threshold.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Allow users of dm_broadcast() to pass a flow context, which will
associate the created mbufs with the given flow.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Allow a flow context to be associated to a read queue and consider the
flow blockage when deciding to evaluate the associated file descriptor
for incoming data.
This allows clients to associate a read queue with the same flow context
as they will associate mbufs to be flow controlled with.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Introduce helpers for creating flow control object and allow these to be
associated with mbufs. The flow is incremented as the object is added to
a queue and decremented as the object is transmitted off the queue.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
The writeq needs to be removed when the remote goes away, so that we're
not trying to operate on stale queues.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
diag_ffs_recv copies mbuf->offset bytes into a fixed 16k buffer.
watch_handle_eventfd sets pending_aio->offset to ev->res, assuming
that ev->res represents the number of bytes read. But res can be
negative in error cases. This causes diag_ffs_recv to copy a very
large amount into a 16k buffer, smashing the stack.
Avoid populating pending_aio->offset if the result is failure.
Also, it appears that if the status code is EAGAIN, the I/O is
actually still in the system, and comes back later.
Signed-off-by: Evan Green <evangreen86@gmail.com>
Our compiler complains about the following:
router/common_cmds.c:142:49: warning: taking address of
packed member 'num_items' of class or structure 'diag_log_cmd_mask' may
result in an unaligned pointer value [-Waddress-of-packed-member]
Avoid directly passing the address of this member to a subroutine, and
instead do the passing via a local.
Signed-off-by: Evan Green <evangreen86@gmail.com>
This commit has following changes
1) Add version number command support.
2) Set the event mask state correctly.
3) Check for packet header for the packets received on
data channel.
4) Send mask update control packets after sending feature mask to
peripheral.
Signed-off-by: Sreelakshmi Gownipalli <sgownipa@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
The DIAG client is supposed to register the DCI, while the remote will
register DCI_CMD. Update this to trigger the SDM845 modem to actually
initiate the communication, something that 8996 isn't so picky about.
Also add a comment describing the unusual handling of instance
identifier in DIAG.
Fixes: c96d6445c7 ("qrtr: Introduce initial qrtr support")
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Include needed headers to fix following errors
| router/dm.h:41:1: error: unknown type name 'ssize_t'; did you mean 'size_t'?
| ssize_t dm_send(struct diag_client *dm, const void *ptr, size_t len);
| ^~~~~~~
tools/send_data.c:55:9: error: variable 'tv' has initializer but
incomplete type
struct timeval tv = {5, 0};
^~~~~~~
Signed-off-by: Khem Raj <raj.khem@gmail.com>
The USB DM will be registered as diag starts, but the FunctionFS is
bound dynamically so allow the DM to be enabled and disabled; which will
ensure that we don't enqueue messages on an outbound queue that won't be
drained.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
The fallback commands should only be executed in the case that no remote
handler was registered, so move these to their own list and execute only
if no other handler did so.
Reported-by: Eyal Ilsar <eilsar@codeaurora.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
The keep alive response is not identical to the request, so create a new
(empty) message rather than looping the invalid sized message back.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
USB support is implemented using FunctionFS, which requires that one
uses AIO in order to support non-blocking operation. The previously
introduced change in watch.c takes care of the IN ep, but OUT is now
moved to use the new AIO read support.
Also remove all traces of Gadget ConfigFS configuration, as this belongs
in the system configuration, rather than in the diag tool itself.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Transition all writers to use aio and provide a new function for async
read. This is necessary in order to implement non-blocking USB support.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Sometimes the Windows client sends messages starting with 0x7e,
resulting in msglen being -2 and a valid pointer being returned. Handle
this case by returning NULL, to indicate that we did not decode a proper
message.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
With the upcoming USB changes we acquire data from the host using async
io and as such can't use the common read function, so allow the input fd
to be omitted.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
In order for the usb code to be able to post messages on the DM return
the handle to the newly created object.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Rather than initiating the opening of a peripheral on any channel on a
new remoteproc we look only for the primary channels (DIAG or
APPS_RIVA_DATA). This solves a problem seen on MSM8996 where the DIAG
channels somtimes are created with a significant delay from the first
channels appearing, causing the 1 second delay to not be enough.
We keep the 1 second timer before trying to open the peripheral as this
forms a wait for the seconday channels to be registered. An alternative
would be to retry until the channels are present, but as the CMD channel
is optional there isn't a good way to detect if this is absent of not
yet registered - potentially this could be solved by opening it lazily
if the remote reports REQ_RSP support.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
On MSM8996 communication is required to go over the CMD channel, even if
we don't set the REQ_RSP feature flag when negotiating features.
So implement support for sending and receiving commands on this channel.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
To launch diag providing the unix socket no arguments should be
specified, so support this.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Move router code into "router" and move send_data into "tools", in order
to make things cleaner as the implementation gains further components.
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>