To avoid polling the firmware for space, a credit based system
is implemented.
The host will keep track of how many credits (bytes) it has
sent to the firmware, and stop sending data when the quota
is filled.
The host will be informed that the firmware has more
room for data when it handles the receive_credits request
message from the firmware, and will continue to write data
as credits become available.
The firmware and the host may implement an algorithm to aggregate
credits, and avoid extra greybus traffic.
Suggested-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
The firmware now buffers data instead of blocking while the transfer
is sent, and the write operation cannot sleep.
Instead of using gb_transfer_sync (which sleeps) in the write callback,
buffer data in a fifo and send it from from a work queue.
The write_room callback will will report 1 byte less that what is really
available in the fifo, to leave space for extra characters that may
be added by the tty layer.
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Dtr_dts allows the tty layer to set the flow control lines
to the correct state during open and close.
Note that locking for newctrl is missing throughout the
driver and will be addressed on a separate patch.
Suggested-and-reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Handle the CRTSCTS flag in set_termios, so that auto
flow control can be turned off. For this, add a new flag
in the line coding request specifically for this purpose.
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
The recently added gb_hd_release tracepoint was added to the wrong
function.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Fix some whitespace issues introduced by the recent tracepoint changes.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Now that firmware has made the switch to the new interface boot
sequence, we can remove support for the deprecated hotplug and
hot-unplug operations.
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Add a generic interface for bundle drivers to use to request that a
mode switch is carried out on its behalf.
Mode switching involves tearing down all connections to an interface,
sending a unidirectional mode-switch request, and waiting for a mailbox
event that triggers deferred control connection reset and re-enumeration
of the interface. In case of a timeout waiting for the interface mailbox
event, or on other errors, the interface is powered off.
All of this needs to be done by core from work-queue context in order
not to block incoming SVC requests and bundle-device tear down. Care
must also be taken to serialise against concurrent module removal events
and eject requests.
Special handling of legacy mode-switching is also added in order to
continue to support the ES3 bootrom.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Print an informative error message in case sending the mode-switch
request fails.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Add a new host-device callback to flush any host-device queues,
including any ongoing transfers, as part of connection tear down.
The host-device buffers are flushed after the disconnecting operation
have completed and the AP queues have been emptied.
This can be used to flush already queued messages which upon reception
would have been discarded by the remote end anyway.
Note that this does not remove the need to flush any host-device queues
as part of CPort disable which needs to make the CPort ready for reuse
after deallocating all associated state and resetting the port.
Suggested-by: Mitchell Tasman <tasman@leaflabs.com>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Implement proper connection closure, which includes sending ping
requests on the connection being tore down while coordinating with the
remote interface as well as the SVC.
This specifically implements the new ping operation, which in case of
offloaded connections is handled by the host-device driver in an
implementation-defined manner through a new callback.
Note that the normal connection tear-down procedure is executed in case
of failed connection establishment due to failed connected operation.
Specifically, the disconnecting request is sent also in case the
connected operation never succeeded. This is needed since the interface
may have enabled FCT flow upon receiving the connected request.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Add a new core operation flag and a helper that core can use to create
core operations.
This will be used to implement the ping operations that core sends as
part of connection tear down.
Note that a new trace point is also added.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Restructure the operation activation state handling in preparation for a
new disconnecting state.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Now that the legacy invalid state is gone, clean up the early
connection-state check in the receive path and explicitly drop incoming
messages for disabled connection.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
The CPort Buffer configuration in the host-device needs to match the
CPort feature flags set by the SVC, but they need not always be
configured at the same point in time.
This will be used when implementing proper connection tear down.
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Rename an error label to make it more descriptive.
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Make sure to reset CPorts at disable rather than enable as per
specification.
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Log failures to disable a host cport, and include the connection name in
cport enable/disable error messages.
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Add stubbed out connection-quiescing operation that is needed for proper
connection tear down.
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Implement the new disconnecting control operation needed for proper
connection tear down.
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Add control connection flag which will be set for control connections.
Also add a helper function to test if the flag is set.
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Add an interface quirk flag to suppress I/O during interface disable.
This is needed to prevent I/O to the bootrom during controlled
connection tear down (e.g. eject or driver unbind). This will be more
obvious with the new connection tear-down procedure.
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Clean up bootrom quirk handling in preparation for addition of further
flags.
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Add new helper to disable connections to interfaces that have already
been disconnected (e.g. forcibly removed).
The connection tear-down procedure differs enough depending on whether
the interface is still present or already gone to warrant a dedicated
helper. This will become more obvious with the new tear-down procedure,
which involves I/O on the connection being tore down.
This also simplifies handling of the legacy bootrom, which does not
support the new tear-down operations.
Specifically, this allows us to remove the early control-connection
tear down during interface disable, and also avoids some error messages
currently printed during legacy mode switch (i.e. bootrom
boot-over-UniPro) and forcible removal.
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Coccinelle reports that gb_svc_pwrmon_debugfs_init() has a block of
a for loop which is followed by an unnecessary semicolon. Get rid
of that semicolon.
Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Coccinelle points out that the macro PTR_ERR_OR_ZERO() handles the
frequent case of converting a pointer into either error code (if its
value is an encoded error value) or 0 (otherwise). Switch some code
in gb_power_supply_register() to use that macro. I have verified
this is true of the kernel we're now working with (arche-6.0).
Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Coccinelle points out that a call in gb_lights_channel_free() to
flush_work() is passed which is always non-null. Prior to the
call, there is an unnecessary check to see if that address is null.
Get rid of the test.
Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Coccinelle points out that debugfs_remove_recursive() handles a null
argument properly, so there's no need to check for NULL before
making the call. I have verified this is true of the kernel we're
now working with (arche-6.0).
Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Running "make coccicheck" on the Greybus code reports that
gb_mmc_get_ro() and gb_mmc_get_cd() can return without releasing
the mutex it acquired if there's an error. Fix this.
Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Running "make coccicheck" on the Greybus code discovered that
an error message in gb_camera_debugfs_init() was interpreting
the wrong value in reporting the error code. Fix that.
Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Unique ids were reserved for CDSI0 and CDSI1 during _probe, however
missed to release those ids during disconnect. This causes a memory leak
of 128 bytes for each iteration of unipro_reset. Fix this.
Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
It is required to release all unique ids registered via ida_get_simple
to avoid any possible memory leak. cport_release() already exists with
special handling for ES2_CPORT_CDSI1, i.e. updating in_use flag without
removing associated ida.
So, added another API to release reserved cports CDSI0 and CDSI1. This
is intended to be used only during es2_destroy().
Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Define a new gb_module trace point event class, used to trace events
associated with the interface abstraction. Define four basic trace
points for this--creation time, drop of last reference, before
registring interfaces and after de-registering them. In addition,
define traces for activating and deactivating, and enabling and
disabling an interface.
Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Define a new gb_module trace point event class, used to trace events
associated with the module abstraction. Define four basic trace
points for this--creation time, drop of last reference, before
registring interfaces and after de-registering them.
Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Currently there are two trace points defined for the Greybus host
device structure. One records information when a message gets sent,
and another when it gets received. Neither of these is really a
host device event.
We have trace points defined for messages that dump information
about all sent and received messages. As a result, the information
about sending messages over a host is redundant, and can go away.
(Note that the message traces may need a little refinement so they
produce all desired information.)
Instead of these trace points, define some that are directly
related to the host device abstraction: when one is created,
added, deleted, or released (destroyed). These do not require
a CPort ID or payload size, so eliminate those two parameters
from the host device trace point prototype. Change the trace
information recorded for a host device to be just a subset of
interesting fields in a host device.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
In gb_operation_put_active(), the wrong trace point is being called.
Fix that.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Core will never call host-device callbacks with invalid arguments (and
that would still need to be verified in bridge firmware anyway), so
remove the redundant and insufficient sanity check from the callbacks.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
The interface svc-resource helper are used to enable as well as disable
the corresponding SVC resources so make sure the error messages reflect
that.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
The numbering of gbphy devices is going to start from 1 and not 0.
Reflect the same in sysfs hierarchy.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
These were left in the earlier renaming series, fix them as well.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
commit 6d94670 gpbridge: rename 'gpbridge' to 'gbphy' everywhere
missed renaming the loopback test app. So do it too.
Testing done: complie and run loopback test
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
The issue is, as part of kernel-only build we started seeing
failures in SVC FW flashing. It was reproducible easily in kernel-only
build, but never observed on Android build.
During debugging, there were couple of observations,
1. If SVC clock enabled and disables (which is REFCLK_MAIN), then SVC FW
flashing works.
2. If we do not switch SVC to HSE (external clock source) it works.
Recently, SVC code has been updated to switch HSE clock, so removing
it (remove/skip rcc_switch_ara_pll() fn) would use internal clock only.
As per STM32 spec, for flashing through USART we do not need
to enable HSE, but the above observation contradicts with it.
There is still something missing in terms of understanding of how STM32
device functions as far as Flashing is concerned. There is something
hidden in HW, which probably still need to identify.
So as a interim solution we will enable clock for FW_FLASHING state,
which seems to be fixing the issue here.
Testing Done: Tested on EVT1.5 with arche6.0 and kernel-only build.
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Make sure that, transition to active state happens only from OFF state.
Instead of imposing the restriction to user-space, driver internally
switches to OFF state and then to ACTIVE state.
Testing Done: Tested on EVT1.5 platform.
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Make arche_platform_fw_flashing_seq() return error value, needed
later when we add clock enable support for FW flashing.
Testing Done: Tested on EVT1.5 platform.
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This reverts commit 29fee8c55b59bb6ac59b99a0563c89c514cba42b.
This change and its companion NuttX changes seem to be triggering a
storm of POWERMODEIND switch interrupts on the SVC.
Signed-off-by: Jeffrey Carlyle <jcarlyle@google.com>
Acked-by: Sandeep Patil <sspatil@google.com>
Bring the gb_svc_intf_set_power_mode() up-to-date with the current Greybus
specification. This largely involves adding more members to the structure
sent across the wire. Also change the camera code to use the new
operation properly, with default values passed for the new necessary
arguments. The correctness of these default values is confirmed via testing
and by asking Rob Johnson.
Testing Done: Took a picture with a camera module, received error code
when passing deliberately incorrect values for new parameters, got proper
-EIO and Greybus result code printed when operation stopped halfway
through.
Associated Firmware Changes: 6810-6812 on Gerrit for SW-1239, 6870 and
5612-5613 on Gerrit for SW-2945
Signed-off-by: Eli Sennesh <esennesh@leaflabs.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Tip-of-tree is exhibiting a backtrace when loading-up the set of greybus
kernel modules due to calling arche_platform_wd_irq_en() directly after a
call to devm_request_threaded_irq().
At the point we call arch_platform_wd_irq_en() the relevant IRQ will
already be enabled. What we want to do in this situation is configure the
GPIO line as an input. This patch fixes the backtrace by supplanting
arche_platform_wd_irq_en() with
gpio_direction_input(arche_pdata->wake_detect_gpio) in
arche_platform_probe().
WARNING: at msm-ara-3.10/kernel/irq/manage.c:457 __enable_irq+0x74/0xc0()
Unbalanced enable for IRQ 687
Modules linked in: gb_arche(O+) gb_camera(O) gb_es2(O) gb_vibrator(O)
gb_raw(O) gb_power_supply(O) gb_loopback(O) gb_light(O) gb_hid(O)
greybus(O)
CPU: 0 PID: 415 Comm: insmod Tainted: G W O 3.10.78-g2a4dec8 #65
Call trace:
[<ffffffc000206adc>] dump_backtrace+0x0/0x248
[<ffffffc000206d34>] show_stack+0x10/0x1c
[<ffffffc000c6c698>] dump_stack+0x1c/0x28
[<ffffffc00021c95c>] warn_slowpath_common+0x74/0x9c
[<ffffffc00021c9d0>] warn_slowpath_fmt+0x4c/0x58
[<ffffffc000269d7c>] __enable_irq+0x70/0xc0
[<ffffffc000269e34>] enable_irq+0x68/0x7c
[<ffffffbffc0609b4>] arche_platform_probe+0x3b4/0x4f4 [gb_arche]
[<ffffffc0005ace30>] platform_drv_probe+0x14/0x20
[<ffffffc0005ab980>] driver_probe_device+0x160/0x374
[<ffffffc0005abc40>] __driver_attach+0x60/0x90
[<ffffffc0005aa768>] bus_for_each_dev+0x74/0x94
[<ffffffc0005ab2c4>] driver_attach+0x1c/0x28
[<ffffffc0005aae74>] bus_add_driver+0x124/0x248
[<ffffffc0005ac270>] driver_register+0x94/0x110
[<ffffffc0005ad3c4>] platform_driver_register+0x58/0x64
[<ffffffbffc065020>] $x+0x20/0x58 [gb_arche]
[<ffffffc0002007dc>] do_one_initcall+0xb0/0x14c
[<ffffffc00028252c>] load_module+0x19d0/0x1b18
[<ffffffc00028278c>] SyS_init_module+0x118/0x130
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiermath@linaro.org>
Tested-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Topology data pointer was mistakenly set to NULL before freeing it. Fix
this.
Fixes: 64a86d9ba850 ("audio: Add module specific driver")
Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>