Because the width of our fields is already known, we can use %0Nx (for
hex) to print N bytes and %u (for unsigned decimal), instead of using %h
and %hh, which isn't that readable.
This patch makes following changes:
- s/%hx/%04x
- s/%04hx/%04x
- s/%hhx/%02x
- s/%02hhx/%02x
- s/%hhu/%u
- s/%hu/%u
- s/%x/%02x for u8 value (only at a single place)
Suggested-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
-EIO fits better here, rather than -EINVAL as the arguments to the
routine itself are valid, just that we failed while doing unipro
transfers.
Suggested-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
The order of entries in sysfs-bus-greybus file doesn't match the order
files/directories in sysfs on a real board. More specifically, N-svc
comes at last and ap_interface_id comes before endo_id within the svc.
Fix that.
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Add the bundle id to bundle uevents.
This is needed to identify bundles that are being removed (e.g. at
hot-unplug).
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>
Add the interface id to interface and bundle uevents.
This is needed to identify interfaces that are being removed (e.g. at
hot-unplug).
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Add the bus id to all greybus uevents.
This is needed to identify devices that are being removed (e.g. at
hot-unplug).
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Make sure to flush the workqueue from hotplug and hotunplug events when
the svc connection is tore down.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
At some point we had a statement in a Jira work item to pull out 'bus
level' data from greybus and to have messages to different interfaces be
synchronized with respect to each other. Synchronizing threads with respect
to each other is slow and it turns out we can get the same 'bus level'
stastics by making the user-space test application smarter.
That's great news for the in-kernel code since it means we can cut out a
whole lot of code to-do with calculating 'bus level' aggregate data and we
can stop forcing threads to hit a rendezvous before sending out another
loopback operation.
So this patch drops bus level aggregates in favour of doing that in
user-space. It subtracts a lot of code and cycles that in practice nobody
cares about anyway.
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
start and end aren't used and should be dropped.
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Initializing the bridge specific latency variables is only relevant to the
transfer operation, so make it loopback-transfer specific.
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Currently a per-connection mutex is held during calls to
gb_operation_send_sync. It is not necessary to hold this lock and later
patches supporting multiple-outstanding bi-directional operations need to
take the per-connection lock and the gb_dev level lock. Since gb_dev must
always be taken before per-connection locks, it is both desirable and safe
to drop the lock now.
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
V4l2 flash will return erro ERANGE if val(which is the default value)
is not defined. Just set it to the max value reported by the module.
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
When attaching torch to a flash we release the channel torch resources,
but afterwards we do it again when releasing all the channels.
Just free all the resource at channel release.
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
We do not implement any of the v4l2 flash operations, as the default
ones are ok for now, however the init needs anything define, if not it
will return an error. So, just define it and have an error free v4l2
flash init.
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
endo_id was present in place of the directory N-svc, fix it.
Fixes: 4f7b1833e78f ("Documentation/sysfs-bus-greybus: update the bus ABI documentation")
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Add helper functions calculate the tx and rx size possible that fit a
greybus payload size and change the operation creation to adjust to that.
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
There is no standard way of building a kernel from source in
Android. Each device/SoC can (and do) implement it in their own way.
To that end, let's remove this makefile and let each device define
how they want to build the modules.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Add master and device config operations, one is to merge all the master
operations and the device config will allow to fetch and add devices for
each chip select.
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Add read and/or write field to transfer descriptor to make it possible
to identify the type of transfer.
Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Fix racy hotplug handling by serialising all processing of hot-plug and
unplug requests using a single-threaded dedicated workqueue.
This fixes a reported crash during enumeration when processing multiple
events.
The current svc implementation does not handle concurrency at all (e.g.
no interface list lock or refcounting) so we need to use the big hammer
for now.
Note that we will eventually want to process events for different
interfaces in parallel, but that we'd still need a workqueue in order
not to starve other svc requests (e.g. for timesync).
Reported-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Defer processing also of hot-unplug events.
This is a step towards serialising hot-plug and unplug event processing.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Clean up and generalise deferred request handling by simply storing a
reference-counted pointer to the operation itself in the work context.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Pass the svc rather than its connection to the interface remove helper.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Rename the hotplug request message, and clarify that the message size
has already been verified by the primary handler.
Also add a debug message that includes the interface id.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Clean up hotplug/unplug request handlers somewhat.
Also add a debug message to both handlers that includes the interface id.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
The es2 chip doesn't have VID/PID programmed into the hardware and we
need to hack that up to distinguish different modules and their firmware
packages.
This fetches VID/PID (over firmware protocol) for es2 chip only, when
VID/PID already sent during hotplug are 0.
Since only the bootrom contains a firmware protocol cport, this only
affects bootrom's working and not nuttx.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Drop the control bundle and ignore control descriptors when parsing
manifests.
Every interface has a control connection with a well defined remote
CPort 0 and there's no longer any need to create a bundle for it.
As the control connection is setup and enabled before parsing the
manifest, ignore any legacy descriptors for control cports and bundles
in a manifest.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Add helper function to release cport-descriptors with a given bundle id.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Remove conditional enabling of connections when binding protocols that
served no purpose as a connection either has no bundle or it has an
interface with a valid device id.
Also remove the now unused GB_PROTOCOL_NO_BUNDLE protocol flag.
This is an intermediate step in moving the protocol binding to
connection_init, but is also needed as the control bundle is going away.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
The control bundle is going away so update the code.
Also remove defensive WARN_ON which would not just warn if our
implementation is broken, but also leak further memory unnecessarily.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
The svc connection helper functions should not assume that all dynamic
connections will have a bundle.
This is needed as the control bundle is going away.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Remove the now unused endo and module code.
Note that the never-implemented serial and version attributes of the
endo can be implemented as svc attributes if needed.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Replace reference to "endo0" and generate the raw-latency filename based
on the host-device bus id instead.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Use dev_err and friends with the svc device for messages.
Clean up error messages.
Demote a few warnings to warning level.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Create the svc connection when registering the host-device and
remove the current svc connection hacks that "upgraded" the svc
connection once the endo id and ap interface id was known.
Note that the old implementation was partly based on a misunderstanding
as it was the remote interface id, rather than the local AP interface id,
that used to define a connection (but we also needed the endo_id).
The remote interface is no longer needed as static connections, such as
the svc connection, are now simply defined by the host-device and host
cport id.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Use host-device device and connection name for log messages, as not all
connections have a bundle.
Note that the "initial" svc connection has never had a bundle.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Use the host-device device and connection name for error messages, as
the operation code can not assume that a connection has a bundle.
Note that the "initial" svc connection has never had a bundle.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Use host-device device and connection name for log messages rather than
assume that all connections have a bundle (e.g. not true for static
connections).
Note that the "initial" svc connection has never had a bundle.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Add a name field to connections that can be used in log messages.
A connection always belongs to a host-device (bus) and can be uniquely
identified by its host-device cport id, but include remote interface and
cport id nonetheless on the following format:
<hd_cport_id>/<intf_id>:<cport_id>
The remote interface and cport id will be zero for static connections.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Add helper to determine whether a connection is static, and remove the
protocol flag GB_PROTOCOL_SKIP_SVC_CONNECTION.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Make sure that the interface lookup helper can handle static,
bundle-less connections without oopsing when creating further
connections.
Note that the initial svc-connection has always been bundle-less, but
did not trigger an oops as a bundle was created for it before further
connections were created.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Clean up the connection-creation interface by clearly separating our two
types of connections: static and dynamic.
Add two convenience functions for creating static and dynamic connections.
A static connection is a pre-setup connection that is defined by a host
device and a host-device cport id. Specifically, the remote interface or
cport id need not be known. The SVC connection is a static connection.
A dynamic connection is defined by a host device and a remote interface
and cport id. This is our normal connections where the host-device cport
is (generally) allocated dynamically.
Note that the new generic interface is marked static, but can be
exported later to allow dynamic connections to be created also from
fixed host-device cports (e.g. for CSI).
Also note that a connection of either type is uniquely identified by its
host-device and host-device cport id once created.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Kill gb_create_bundle_connection, which was only used to create the
control bundle and connection, and replace it with a specialised static
helper.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Move endo_id and AP interface id to the svc device.
The endo abstraction is about to be removed, and these attributes are
arguable attributes of the svc anyway.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Register the svc device upon reception of the HELLO request.
The SVC HELLO request contains the endo id and AP interface id, which
will be exposed from the svc device rather than the endo.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Make sure to initialise the svc device fully before adding it to the
host device.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Make the svc object a child device of the host-device device and use
driver core to manage its lifetime.
The svc device name is "<bus_id>-svc", where bus_id is the dynamically
assigned id of the host device.
Note that there is exactly one svc-device per host device (bus).
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Rename bundle devices so that the new device names become
"<bus_id>-<intf_id>.<bundle_id>", where bus_id is the dynamically
allocated host-device bus id and intf_id the svc-allocated interface
id.
Using a period (.) rather than a colon (:) makes dev-messages easier to
read as as those already add a colon after the device name, for example:
greybus 1-4.15: failed to connect cport: -22
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Make interfaces child devices of host devices.
The new interface device name is "<bus_id>-<intf_id>", where bus_id is
the dynamically allocated bus id for the host device and intf_id is the
svc-allocated interface id.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>