Add wrapper structure for legacy connections and add helpers to create
and destroy legacy connections.
This is a step in removing legacy connection fields from the core
structures.
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>
Return an ERR_PTR on errors when creating connections.
This allows driver probe to fail with a more informative error message
as not all connection creation errors are due to memory exhaustion.
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>
Drop the _dynamic suffix from the exported interface that drivers use to
create connections.
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>
Simplify the exported generic interface for creating dynamic
connections.
Since all driver connections will have a bundle we can drop the
redundant interface parameter.
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>
The protocol-id parameter is only used by the legacy driver so remove
it from the generic interface and move it to the legacy driver until it
can be removed completely.
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 dedicated helper to create control connections.
This will allow us to simplify the generic (dynamic) interface.
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>
Now that connection creation has been separated from interface
initialisation, we should explicitly check for duplicate CPort
descriptors when parsing the manifest.
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>
Defer connection creation to bundle driver probe instead of creating
them when initialising the interface and parsing the manifest.
Store copies of the CPorts descriptors in the bundle for the drivers to
use, and update the legacy driver.
This is needed for drivers that need more control over host-device
resource management, for example, when a protocol needs to use a
dedicated host CPort for traffic offloading (e.g. camera data).
This also avoids allocating host CPorts for bundles that are not bound
to a driver or for remote CPorts that a driver does not need.
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>
When bundles are added and then removed, we have a race where we go to
read the sysfs file, but it is now for a different bundle than the
uevent was originally for. So add the bundle class to the uevent so we
"know" what the correct bundle class was.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This implements the SVC "ping" command. It's tiny and simple, but we
need something like this in order for us to "know" if all is working
well.
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
People are getting confused as to what the firmware file name is for
their module, so log it to make it easier to find modules with "blank"
vid/pid values and let people know what to name their firmware files.
Because we are now logging this, turn the debug message after the
firmware request into an error message if something fails.
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Add a new input device associated with the SVC to handle key events.
This new events are transfer over a new greybus svc operation which is
unidirectional.
It was selected the KEY_A for representing the KEY_ARA_BUTTON key code.
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
With the recent changes by Johan to the driver model of the greybus
code, the audio_codec no longer should need to provide a "dummy" driver
when registering the codec. In fact, having it there causes the greybus
core to crash when inserting the module. Removing it all fixes the
crash.
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Allocate private data structure at probe and release at disconnect.
The private data will be used to track the connections managed by the
driver, but for now only holds a count of the number of cports the
bundle has.
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>
Use the gb_connection_mutex when making sure a remote CPort is
available.
This is needed when moving to driver-managed connections that can be
created and destroyed at any time.
Also check for duplicate bundle-less connections.
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>
Serialise connection creation against concurrent creation and
destruction using a global mutex.
This is needed to prevent two drivers from attempting to create a
connection to the same interface CPort and to cope with a racing
connection destroy when moving to driver managed connections.
Note that the locking can not (easily) be made more fine-grained as not
all connections have an interface, but these are not hot paths anyway.
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>
Fix longstanding race that could lead to a connection being destroyed
while processing an incoming message due to missing reference counting
when looking up the connection.
Add helpers to manipulate the connection kref.
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>
Drop the useless connection_mutex that did not, and can not be used to
prevent connection lookup races in atomic context and therefore serves
no purpose.
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>
Destroy the work queue when the connection is destroyed/deregistered
instead of when the last reference is dropped.
The work queue is not needed once the connection has been deregistered,
and no operations will ever be added to it again (handled by checking
connection->state) even if the connection object may not be deallocated
until the final reference is dropped.
The work-queue name is set based on the host-device name and host-device
cport id, something which guarantees a unique name. This would no longer
be true if the work queue was not destroyed at connection deregistration
as a new connection could then be created for that very same host cport.
This is not necessarily a problem unless some work queue features are
used that require unique work-queue names, but let's try to be well
behaved.
Also update an obsolete comment and make explicit that a connection must
be disabled before being destroyed.
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>
Remove WARN_ON from connection destroy testing for a NULL-connection
when destroying a connection.
This will allow for simpler driver code when releasing driver-managed
connections.
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 bundle-version operation to fetch the version of the bundle class.
Retrieve the bundle version of all bundles when initialising the
interface in case the control-protocol version is greater than 0.1.
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>
Remove the broken legacy protocol-version handling from core and move it
to the legacy driver instead.
Note that version handling has always been broken as legacy protocols
were looked up and bound to connections before the connections were
enabled and version negotiation could take place (over that very
connection). Document that in the legacy driver as well.
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>
Store the "negotiated" protocol version to use in the svc state
struct instead of the connection struct.
The generic concept of a connection version is going away in favour of
bundle-class versions.
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>
Disable bundle connections in core before calling driver disconnect in
case the interface is already gone.
This avoids unnecessary timeouts on hot-unplug when a driver does I/O in
its disconnect callback.
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>
Use the protocol pointer to determine the legacy connection state.
This is needed to allow core disable connections when an interface has
been hot-unplugged without the legacy protocols leaking its resources.
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>
Move legacy protocol and connection handling to the legacy driver.
Rename the former global functions using a common legacy_ prefix.
Note that all legacy protocols suffer from a connection initialisation
race in that the protocol-specific initialisation, which includes
allocation of protocol-specific state containers, can not happen until
*after* the connection has been enabled. This is a major flaw in the
original design that we can now finally address by converting the legacy
protocol drivers into proper bundle (class) drivers.
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>
Drop dependency on the legacy protocol abstraction.
Remove the now unused and last legacy-protocol flag
GB_PROTOCOL_SKIP_VERSION along with the protocol-flag feature.
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>
Drop dependency on the legacy protocol abstraction.
Instead implement the protocol-specific version request directly, and
use the new interface for managing the control connection.
Note that the version request is being removed from most protocols, but
we need to keep the current request for the control protocol as-is
indefinitely to maintain backwards compatibility (e.g. with the ES2/ES3
bootrom).
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>
Remove control-protocol version from the exported protocol definitions
as it is an implementation detail that makes no sense to export.
Currently gbsim uses the kernel's control-protocol version definitions
directly instead of reporting the version of the protocol it actually
implements.
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>
Remove the legacy protocol flags that were used to suppress the
connected and disconnected events.
Instead send the connected and disconnected event for all bundle
connections and explicitly exclude static connections and control
connections.
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>
Remove the legacy protocol flag that was used to suppress sending the
control disconnected operation.
Instead rely on the fact that no control operations will be sent by
core to an interface that has been removed (e.g. after having received a
new hotplug event after the bootrom has jumped to the new image).
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>
Bundle drivers *must* disable their connections in the disconnect
callback, but add a defensive test and warn about buggy drivers
nonetheless.
Note that bundle drivers would generally release their state containers
in disconnect so a failure stop I/O could potentially lead to
use-after-free bugs in any late operation completion callbacks.
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>
Disable and flush incoming operations before calling driver disconnect.
Bundle drivers are still responsible for disabling their connections
in their disconnect callback.
Note that specifically the legacy protocols must have incoming
operations disabled when their connection_exit callback is called as
that is where their state is deallocated.
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 helper to disable and flush incoming operations.
This is intended to be used by core to flush any incoming requests
before calling driver disconnect, but could potentially later be
exported for driver use as well.
Note that we currently flush all incoming operation and allow the
request handlers to run, but cancel any responses sent. This may need to
be refined later.
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 new connection state ENABLED_TX in which only outgoing operations
are allowed.
This allows drivers to query the device during probe before allocating
their state containers without having to worry about racing incoming
requests.
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 connection mutex to protect connection enabling and disabling.
This is needed to eventually allow drivers to manage the state of their
connections during operation (i.e. post probe and pre disconnect).
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 cancel all (incoming) operations when failing to enable a
connection.
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>
Always cancel all operations on connection disable and remove the now
unused DESTROYING state.
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 connection request-handler field to struct gb_connection that is
set when the connection is enabled.
This is a step towards removing the legacy protocol abstraction from
core, and will also be used to implement unidirectional connection
states (e.g. only outgoing operations are allowed).
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>
Remove implicit disable of legacy connections from the destructor.
This is a step towards removing the legacy-protocol handling from core.
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 legacy connection init and exit functions.
This is a step towards removing the legacy-protocol handling from core.
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 the first Greybus bundle driver that will be used when transitioning
from legacy Greybus protocols to bundle drivers.
The legacy-protocol driver initially binds to all current bundle classes.
In order to avoid having to update current module-loading scripts, keep
this driver internal to greybus core at least until modalias support is
added. Note that this prevents unloading any protocol drivers without
first tearing down the host device due to a circular module dependency.
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>
Interface has been changed.
return code will not return number of configured streams but
just error code.
Number of streams is passed as pointer and if operation result
is changed number of streams will be updated.
Flags are also used for information regarding configure stream
operation result.
Signed-off-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Acked-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Update gb interface and export flags needed for latest
protocol version. Number of streams also can be changed
based on operation result.
Caller sets input flags, end fucntion return output
flags
Input flags supported:
- GB_CAMERA_IN_FLAG_TEST - Need to be set when operation
is not actually applied.
Output flags supported:
- GB_CAMERA_OUT_FLAG_ADJUSTED - This is result of the operation
if this flag is set, result is adjusted and operation
need to be repeat.
Signed-off-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Acked-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Due to some issues with handling colons in Android (and possibly
future exposure to other problems) we should remove the colons from
the firmware file request. Replacing them with underscores.
Specifically, we copy firmware into the Android build using a line
similar to this:
PRODUCT_COPY_FILES += \
source-repo/ara:00000126:00001000:00000001:00000001:02.tftf:system/etc/firmware/ara:00000126:00001000:00000001:00000001:02.tftf
There is a colon delimiter between the source and destination in the
PRODUCT_COPY_FILES format. The greybus naming logic breaks the parsing
routine and generates an Android build break.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This reverts commit 48cc91e52dba9abad4c9b56f911994c65071bfc4 as the
caller should be changed instead.
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Configure streams ret code should be number of streams in
gb operation exported to HOST camera.
Until gb operation is migrated to new interface return
number of streams in ret code.
Signed-off-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
And return the response num_streams field through a pointer variable
instead of using the return value of the function as both an error code
and a positive number of streams, it makes the API more consistent.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>