Commit Graph

120 Commits

Author SHA1 Message Date
Jami Kettunen
d06e599d19 unix: Include string.h
This fixes a bunch of implicit function declaration issues under musl
libc.
2021-03-29 14:39:07 -07:00
Khem Raj
048dc8e78d Disable use of __NR_io_getevents when not defined
Architectures like riscv32 do not define this syscall, therefore return
ENOSYS on such architectures

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2021-01-21 09:04:25 -08:00
Bjorn Andersson
1716a44f82 watch: Don't wake up every 10 seconds
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>
2020-09-15 12:25:33 -05:00
Bjorn Andersson
cc5dc0dec3 peripherals: Create and use flow context
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>
2020-03-20 12:25:24 -07:00
Bjorn Andersson
040982dbda dm: Allow broadcasters to pass a flow context
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>
2020-02-19 16:00:01 -08:00
Bjorn Andersson
a3395140dd watch: Allow flow context to be associated with readq
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>
2020-02-19 15:59:46 -08:00
Bjorn Andersson
d2c595e988 mbuf/watch: Introduce flow control context
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>
2020-02-19 15:59:33 -08:00
Bjorn Andersson
3eaf16dd4f qrtr: Remove writeq when remote goes away
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>
2019-05-30 06:26:28 -07:00
Evan Green
bf8035f68b watch: Fix buffer overflow
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>
2019-01-24 10:29:16 -08:00
Evan Green
2861875311 README: Configuration string should be diag_dun
For some reason, this string seems to need to be set to diag_dun rather
than DIAG to get QXDM and other tools fired up.

Signed-off-by: Evan Green <evangreen86@gmail.com>
2019-01-19 12:29:42 -08:00
Evan Green
29db5d80b0 common_cmds: Fix warning about address of packed member
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>
2019-01-19 12:29:42 -08:00
Evan Green
73ca38f017 build: Honor CFLAGS
If CFLAGS is set in the environment, it should be used. The Makefile
was previously clobbering it. Now it adds -Wall -g -O2 only if CFLAGS
was not specified.

Signed-off-by: Evan Green <evangreen86@gmail.com>
2019-01-19 12:29:42 -08:00
Sreelakshmi Gownipalli
f46fe32948 diag: Add support for version number command
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>
2019-01-12 23:33:16 -08:00
Bjorn Andersson
5ef6b6b0c5 qrtr: Register the DCI and not DCI_CMD instance
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>
2018-10-02 09:29:21 -07:00
Khem Raj
54375d90a4 Fix build with musl
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>
2018-09-25 14:01:54 -07:00
Bjorn Andersson
9de0697ec5 readme: Add initial version
Add initial version with some notes on how to set up USB ConfigFS
GadgetFS and launch diag-router.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-08-06 14:59:30 -07:00
Bjorn Andersson
17b41035f8 make: Enable QRTR and UDEV by default
Default to support both QRTR based and RPMSG based communication, rather
than none. This default configuration allow us to run the binary on both
SDM845 and DB820c; but still make it possible to disable the RPMSG based
peripheral support when the host doesn't have the cross compile
environment for libudev.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-08-01 23:56:11 -07:00
Bjorn Andersson
4790df98ce list: Add guard check for container_of
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-08-01 23:55:41 -07:00
Bjorn Andersson
91b04bc233 dm: Allow DM to be enabled and disabled
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>
2018-08-01 23:53:40 -07:00
Bjorn Andersson
4bbcd83015 router: Only execute fallback commands as fallback
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>
2018-07-26 15:49:14 -07:00
Bjorn Andersson
cedf29f2c7 app_cmds: Correct keep alive response
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>
2018-07-26 15:39:51 -07:00
Bjorn Andersson
6c9f923e5a usb: Tidy up USB descriptors
Clean up the descriptor definition and define the whole thing in one
static constant blob.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-19 23:20:43 -07:00
Bjorn Andersson
6e31a2c088 usb: Tidy up error handling in ffs_diag_init()
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-19 21:40:09 -07:00
Bjorn Andersson
b670c41521 usb: Fix USB implementation
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>
2018-07-19 21:32:31 -07:00
Bjorn Andersson
ddea8e0856 watch: Transition to aio
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>
2018-07-19 21:30:17 -07:00
Bjorn Andersson
ab6edce12a hdlc: Fail when message starts with a 0x7e
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>
2018-07-19 21:28:35 -07:00
Bjorn Andersson
e87fd83231 dm: Make input fd optional
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>
2018-07-19 21:26:59 -07:00
Bjorn Andersson
c3beba72f7 dm: Return newly created dm object
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>
2018-07-19 21:25:23 -07:00
Bjorn Andersson
6a96be0210 list: Update list.h to add some additional helpers
Add convenience helpers for iterating over entries, rather than list
heads.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-19 21:24:21 -07:00
Bjorn Andersson
4592a78022 perif-rpmsg: Only initialize on primary channel
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>
2018-07-12 22:04:18 -07:00
Bjorn Andersson
0aa4b06c85 perif-rpmsg: Support dedicated cmd channel
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>
2018-07-12 21:56:45 -07:00
Bjorn Andersson
386b41ab01 perif-rpmsg: Don't use newline in warn()
warn() will append strerror to the log line, so don't end it with
newline.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:56:45 -07:00
Bjorn Andersson
28694ca39b diag_cntl: Only set REQ_RSP feature if we have cmd channel
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:56:45 -07:00
Bjorn Andersson
6762698d92 send_data: Decode "bad command" response
If the response is a "bad commad", print that rather than expecting the
user to know what command 19 is.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:56:45 -07:00
Bjorn Andersson
3904f57521 diag-router: Allow diag to be launched without arguments
To launch diag providing the unix socket no arguments should be
specified, so support this.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:56:45 -07:00
Bjorn Andersson
de16f5e2a7 diag: Restructure repository
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>
2018-07-12 21:56:44 -07:00
Bjorn Andersson
58bfbbf8fc dm: Add missing include
read(2) needs unistd.h to be included, do so.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:56:11 -07:00
Bjorn Andersson
c96d6445c7 qrtr: Introduce initial qrtr support
In recent platforms the previous SMD based transport is replaced by QRTR
sockets, introduce the initial support for this.

This has been tested by booting the modem and sending loopback messages
and retrieving the associated responses. More work is needed to handle
dying remotes etc.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:56:11 -07:00
Bjorn Andersson
efb3693fe1 diag_cntl: Support setting buffering mode
Introduce support for configuring the buffering mode of a peripheral.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:56:11 -07:00
Bjorn Andersson
88228a1a61 diag_cntl: Add support for setting diag_mode
The diag_mode command is used to configure the buffering mode of the
peripheral.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:56:11 -07:00
Bjorn Andersson
8df718b766 diag_cntl: Add some missing feature flags
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:56:11 -07:00
Bjorn Andersson
789a9a8fc4 send_data: Introduce crude "send_data" util
Provide a crude tool called "send_data", which can be used to send
single DIAG commands, over the newly added local UNIX socket, and wait
for the responses.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:56:07 -07:00
Bjorn Andersson
fa22fef49e unix: Implement UNIX socket based local server
In order to interact with the DIAG router locally this introduces a
crude UNIX socket based DM.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:52:06 -07:00
Bjorn Andersson
047c7fa5ed watch: Take failing readers off the readers list
As a temporary hack we take failing read callbacks off the readers list.

When this happens proper cleanup of the read watcher should be done, so
this needs to be revised further. This is necessary when implementing a
UNIX socket server, as the read operation will fail when the clients
disconnect.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:52:06 -07:00
Bjorn Andersson
a385beb7a9 diag_cntl: Signal support for sockets
For peripherals with support for sockets (instead of SMD/GLINK) signal
this in the feature set.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:52:06 -07:00
Bjorn Andersson
37ff687eda diag_cntl: Negotiate features
Instead of blindly sending a feature mask back to the remote we keep the
bits of the remote's mask that we support and send the result back.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:52:06 -07:00
Bjorn Andersson
9c2295cca5 diag_cntl: Fix feature mask representation
The feature mask is transmitted as little endian and the function
sending the feature mask got this backwards. Simplify this by just
putting a little endian uint32_t in the struct.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:52:06 -07:00
Bjorn Andersson
68652d818b diag_cntl: Pass read buffer to diag_cntl recv function
In order to support reading control packets from QRTR we need to use
recvfrom(), so make the caller of diag_cntl_recv() read the data off the
fd and pass the read buffer.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:52:06 -07:00
Bjorn Andersson
dd140248bf watch: Push queue initialization out to clients
Make the clients initialize the queue instead, this allows to lazily add
the watch of a write queue as the remote comes up.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:48:12 -07:00
Bjorn Andersson
804371251a dm: Add support for non-HDLC encoded frames
For certain transports it doesn't make sense to HDLC encode the frames,
so make it possible to specify if a DM should operate using HDLC encoded
frames or not.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-07-12 21:47:31 -07:00