String descriptors are padded towards the end to align them to 4 byte
boundaries. Take that into account while calculating expected size.
Reviewed-by: Alex Elder <elder@linaro.org>
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>
These structures are already marked as __packed, as these are enclosed
within:
#pragma pack(push, 1)
#pragma pack(pop)
Lets mark them __packed explicitly.
Reviewed-by: Alex Elder <elder@linaro.org>
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>
There can be three Endo types: mini, medium and large. And that's what
Endo 'type' should refer to.
But we have named the 16 bit number that uniquely represents a valid
endo, as its type. 'id' seems to be a more suitable name to that instead
of 'type'. Lets rename it.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
0x0555 isn't a valid endo id, use a real one.
0x4755 should be the Endo id for the (medium) Spiral 2 prototype. Lets
use that.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
These are all GPLv2-only kernel modules, so properly set the correct
MODULE_LICENSE string to make static checkers happy.
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
A bundle has a state file, that is managed by the endo userspace
process. This file can be written to and any process that is polling on
the file will be woken up and can read the new value. It's a "cheap"
IPC for programs that are not allowed to do anything other than
read/write to kernel sysfs files.
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
The code uses 64-bit divisions, which should be avoided, and also
prevents the module from loading on 32-bit systems:
gb_loopback: Unknown symbol __aeabi_uldivmod (err 0)
Fix by using the kernel's 64-bit by 32-bit division implementation
do_div.
Compile tested only. I did not look very closely at the code itself.
Perhaps this could be worked around in some other way, but this silences
the linker warning and allows the module to be loaded.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
It's up to other files to define this if it's not present, not this
file.
Reported-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Replace #define<TAB> with #define<SPACE>.
Also move the #ifdef block to below the initial comment block, like
other .h files are.
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
In order to facilitate re-use of the gpio, i2c, pwm and i2s
structures, split them out of independent files and add
them into a shared gpbridge.h
This will be a prereq to sharing these headers w/ gbsim.
Cc: Alex Elder <alex.elder@linaro.org>
Cc: Greg Kroah-Hartman <gregkh@google.com>
CC: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This documents the module slot sysfs files "epm", "power_control", and
"present".
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Alex Elder <elder@linaro.org>
This documents the endo device, and the SVC specific files that are
present in the sysfs device tree.
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Alex Elder <elder@linaro.org>
The kernel is now on the 4.XX numbering scheme, and it's going to be a
while before we merge this code, so pick a date sometime in the future
to be safe.
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Alex Elder <elder@linaro.org>
This hooks up the endo, and modules, into the device tree. All modules
for a specific endo are created when the host device is initialized.
When an interface is registered, the correct module for it is found and
that module is used for the sysfs tree. When the interface is removed,
the reference on the module is dropped.
When the host device goes away, the whole endo and modules are removed
at once.
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Alex Elder <elder@linaro.org>
This adds endo.c and endo.h and provides functions to create an endo and
the initial 0x0555 set of modules.
But, it doesn't hook this logic up into the running code yet, that comes
next.
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Alex Elder <elder@linaro.org>
This adds the attributes power_control and present to a module. It also
removes the unneeded module_id attribute, as that comes from the name of
the module itself.
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Drop the host-driver buffer headroom that was used to transfer the cport
id on ES1 and ES2.
Rather than transferring additional bytes on the wire and having to deal
with buffer-alignment issues (e.g. requiring the headroom to be a
multiple of 8 bytes) simply drop the headroom functionality.
Host drivers are expected set up their transfer descriptors separately
from the data buffers and any intermediate drivers (e.g. for Greybus
over USB) can (ab)use the operation message pad bytes for now.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Fix transfer-buffer alignment of es2 as well.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Fix transfer-buffer alignment of outgoing transfers which are currently
byte aligned.
Some USB host drivers cannot handle byte-aligned buffers and will
allocate temporary buffers, which the data is copied to or from on every
transfer. This affects for example musb (e.g. Beaglebone Black) and
ehci-tegra (e.g. Jetson).
Instead of transferring pad bytes on the wire, let's (ab)use the pad
bytes of the operation message header to transfer the cport id. This
gives us properly aligned buffers and more efficient transfers in both
directions.
By using both pad bytes, we can also remove the arbitrary limitation of
256 cports.
Note that the protocol between the host driver and the UniPro bridge is
not necessarily Greybus. As long as the firmware clears the pad bytes
before forwarding the data, and the host driver does the same before
passing received data up the stack, this should be considered "legal"
use.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Add explicit pad bytes to the message header.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Make sure to allocate the message transfer-buffer separately from the
containing message structure to avoid data corruption on systems without
DMA-coherent caches.
The message structure contains state that is updated while the buffer
may be used for DMA, something which could lead to data corruption due
to cache-line sharing on some architectures.
Use the (renamed) message cache for the message structure itself and
allocate the buffer separately.
If the additional allocation is a concern, the message structures
could eventually be allocated as part of the operation structure.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Pass structured greybus messages rather than buffers to the host
drivers.
This will allow us to separate the transfer buffers from the message
structures.
Rename the related functions to reflect the new interface.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Move operation message-header to operation.h so that it can be used
by host drivers.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Remove unused and unnecessary buffer-alignment define that host driver
were supposed to use.
We can handle unaligned incoming buffers just fine by accessing the
operation-message header via a copy in the receive path, rather than
requiring host drivers to make sure the alignment is correct.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
The buffer received from our current host driver is 1-byte aligned and
will therefore cause unaligned memory accesses if simply cast to an
operation-message header.
Fix this by making a properly aligned copy of the header in
gb_connection_recv_response before accessing its fields.
Note that this does not affect protocol drivers as the whole buffer is
copied when creating the corresponding request or response before being
forwarded.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Fix two bugs in es2 and do some minor clean up.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
The maximum buffer size does not include the headroom, so subtract the
headroom size from the actual buffer size.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
A stack-allocated buffer is not generally DMA-able and must not be used
for USB control transfers.
Note that the memset and extra buffer byte were redundant as no more
than the bytes actually transferred was ever added to the fifo.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Alex suggested to name it class instead of class type.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
A Greybus driver will bind to a bundle, not an interface. Lets follow
this rule in code.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
A module can have more than one interfaces and we get hotplug events or
manifests for interfaces, not modules. Details like version, vendor,
product id, etc. can be different for different interfaces within the
same module and so shall be fetched from interface descriptor instead of
module descriptor.
So what we have been doing for module descriptors until now must be done
for interface descriptors. There can only be one interface descriptor in
the manifest. Module descriptor isn't used anymore and probably most of
its fields can be removed now.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
An interface can have 1 or more bundles. On link-up event, we must initialize
all the bundles associated with the interface.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Currently we are creating bundles based on interface descriptors. An interface
can have one or more bundles associated with it and so a bundle must be created
based on a bundle descriptor.
Also get class_type from bundle descriptor.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Report size isn't passed as first two bytes of the report according to
USB-HID spec. Get it from payload-size.
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>
A bundle corresponds to a device and a greybus driver binds to it. This patch
adds a type and descriptor for bundle.
This also shuffles the values of 'enum greybus_descriptor_type' to align
them with Greybus Specifications.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
There can be more than one interface on a module and we need to know the
interface for which the event has occurred.
But at the same time we may not need the module id at all. During initial phase
when AP is probed, the AP will receive the unique Endo id which shall be enough
to draw relationships between interface and module ids.
Code for that isn't available today and so lets create another routine to get
module id (which needs to be fixed separately), which will simply return
interface id passed to it.
Now that we have interface id, update rest of the code to use it.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Devices registered with the device-core needs to be freed by calling
device_unregister(). For module we are calling just put_device() and for
bundle, connection and interface we are calling device_del().
All of these are incomplete and so none of them get freed, i.e. the
.release() routine is never called for their devices.
Module being a special case that it needs to maintain a refcount or a
list of interfaces to trace its usage count. I have chosen refcount.
And so once the refcount is zero, we can Unregister the device and
module will get free as well.
Because of this bug in freeing devices, their sysfs directories were not
getting removed properly and after a manifest is parsed with the help of
gbsim, removing modules was creating problems. The sysfs directory
'greybus' wasn't getting removed. And inserting the modules again
resulted in warnings and insmod failure.
WARNING: CPU: 3 PID: 4277 at
/build/buildd/linux-3.13.0/fs/sysfs/dir.c:486
sysfs_warn_dup+0x86/0xa0()
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
These are definitions from Mark that I've consolidated into
one header file. I'd like to get these merged at some point
soon, so the audio driver and gbsim work can avoid having
out-of-tree dependencies.
Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This adds a proposed sysfs layout for greybus to Documentation to make
it easier for people to discuss / test things. It includes a module, an
interface, a bundle, and a gpbridge binding to that bundle.
This was discussed on the projectara software mailing list.
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
These functions showed up in 3.12 or so, and we are stuck on 3.10 for
various reasons, so provide backports in kernel_ver.h so that we can
rely on these functions.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
We should use the attribute groups, not group, for the device, so
add and remove it. No one should ever be updating a sysfs group for a
device, as that can be pretty dangerous if you don't duplicate _all_
existing attribute for that device, and I don't think we were doing that
here.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Add a simple Greybus protocol in order to stress USB and Greybus.
This protocol currently support 2 requests: ping and transfer.
ping request is useful to measure latency.
Kernel send a ping request and firmware should respond with a ping.
The transfer request request is useful to stress Greybus and USB.
Kernel can send data from 0 to 4k and the firmware must send back the data to kernel.
This behaviour of gb-loopback module is controlled via sysfs.
Curently, connection sysfs folder is updated with new entries:
- type: Type of loopback message to send
* 0 => Don't send message
* 1 => Send ping message continuously (message without payload)
* 2 => Send transer message continuously (message with payload)
- size: Size of transfer message payload: 0-4096 bytes
- ms_wait: Time to wait between two messages: 0-1024 ms
Module also export some statistics about connection:
- latency: Time to send and receive one message
- frequency: Number of packet sent per second on this cport
- throughput: Quantity of data sent and received on this cport
- error
All this statistics are cleared everytime type, size or ms_wait entries are updated.
Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
When usb_log_enable() is called, the global apb1_log_task is used to
hold the result of kthread_run(). It is possible for kthread_run()
to return an error pointer, so tests of apb_log_task against NULL
are insufficient to determine its validity.
Note that kthread_run() never returns NULL so we don't have to check
for that. But apb1_log_task is initially NULL, so that global must
be both non-null and not an error in order to be considered valid.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
When usb_log_enable() is called, the global apb1_log_task is used to
hold the result of kthread_run(). It is possible for kthread_run()
to return an error pointer, so tests of apb_log_task against NULL
are insufficient to determine its validity.
Note that kthread_run() never returns NULL so we don't have to check
for that. But apb1_log_task is initially NULL, so that global must
be both non-null and not an error in order to be considered valid.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
In identify_descriptor(), the variable desc_size represents the size
of a memory object. So change its type from int to size_t.
The return value for this function can be desc_size cast to int.
One can verify by inspection this will never exceed INT_MAX.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Send response to incoming requests from the operation request handler
rather than in every protocol request_recv callback.
This simplifies request_recv error handling and allows for further code
reuse.
Note that if we ever get protocols that need to hold off sending
responses we could implement this by letting them return a special
value (after acquiring the necessary operation references) to suppress
the response from being sent by greybus core.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Send response also to incoming requests that cannot be fulfilled.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Add minimal verification of incoming report size, before using it to
determine what buffer and size to pass on to HID core.
Add comment about protocol needing to be revisited. If we are going to
be parsing the report data received, then those fields have to be
defined in the Greybus specification at least.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Make sure to verify the length of incoming requests before trying to
parse the request buffer, which can even be NULL on empty requests.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Make sure to only send a success response if we did not detect any
errors.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Replace pr_err with dev_err and clean up error messages somewhat.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Send response also to incoming requests that cannot be fulfilled.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Fix null-pointer dereference on failure to look up irq due to missing
error handling.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Make sure to verify the length of incoming requests before trying to
parse the request buffer, which can even be NULL on empty requests.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Include the operation id as well as the received and expected size
(from header) when reporting incomplete messages.
This information is useful when debugging communication errors.
Also invert the size test to match the error message and increase
readability.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Use dev_err whenever we have a connection for more informative error
messages.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Fix the payload size of incoming requests, which should not include the
operation message-header size.
When creating requests we pass the sizes of request and response
payloads and greybus core allocates buffers and adds the required
headers. Specifically, the payload sizes do not include the
message-header size.
This is currently not the case for incoming requests however, something
which prevents protocol drivers from implementing appropriate input
verification and could lead to random data being treated as a valid
message in case of a short request.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Incoming operations are created without a response message. If a
protocol driver fails to send a response, or if the operation were to be
cancelled before it has been fully processed, we get a null-pointer
dereference when the operation is released.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Incoming operations are created without a response message. If an
operation were to be cancelled before it has been fully processed (e.g.
on connection destroy), we would get a null-pointer dereference in
gb_operation_cancel.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Make sure to return a proper response in case we get a request we do not
recognise.
This fixes an infinite loop and use-after-free bug, where the freed
operations structure would get re-added to the work queue indefinitely.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Make sure to drop the operation reference when sending the request fails
to avoid leaking the operation structures.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Fix use-after-free when sending responses due to reference imbalance.
Make sure to take a reference to the operation when sending responses.
This reference is dropped in greybus_data_sent when the message has been
sent, while the initial reference is dropped in gb_operation_work after
processing the corresponding request.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Fix up obsolete comments referring to null callback pointers for
synchronous operations, and make sure a callback is always provided when
sending a request.
Also document that the callback is responsible for dropping the initial
(and not necessarily final) reference to the operation.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Add missing EXPORT_SYMBOL_GPL for gb_operation_response_alloc,
gb_operation_result, gb_operation_get, gb_operation_request_send and
gb_operation_cancel, which are all supposed to be accessible from
protocol handlers.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
And this is the warning I was getting on kernel version > 3.14
CC [M] greybus/connection.o
In file included from
include/asm-generic/gpio.h:4:0,
from arch/arm/include/asm/gpio.h:9,
from include/linux/gpio.h:48,
from greybus/kernel_ver.h:59,
from greybus/connection.c:12:
include/linux/kernel.h:35:0: warning: "U16_MAX" redefined
kernel_ver.h is taking care of defining U16_MAX only if is not defined earlier,
but it is often included as the first .h file. <linux/kernel.h> might be
included later, which always defines it, unconditionally. And so this warning.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This brings the debug log functionality of es1.c to es2.c, along with
some other minor cleanups.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
This removes the error checking for debugfs initialization as we really
don't care if it failed or not.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
These clever macros were fine for early development, but they're
more of a distraction now.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This is an old patch that I neglected to send out. It's cleaning
up a couple things that got committed before I had a chance to
comment on them.
In operation.c there is a "FIXME" comment that is easily proven
wrong by inspection.
In gb_protocol_put(), there is another wrong "FIXME" comment as
well. We can also use our cached copies of the protocol major
and minor version number in another spot. And balance that
out by using a cached copy of the protocol id.
Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
In order to decrement the reference count of module on failures, we must call
put_device(module->dev). This was missing for one of the error cases, fix it.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
identify_descriptor() doesn't return 0 anymore and so we don't need to check the
returned value against 0.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
We are calculating descriptors expected size differently based on the type of
descriptor, that's fine but at few places we aren't taking size of the header
into account. And that looks wrong.
Lets make sure it is atleast as big as descriptor's header.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
One function shouldn't do two different things depending on a parameter
passed to it, so split usb_log_enable() into usb_log_disable()
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Add a blank line in apb1_log_enable_read() to make checkpatch happy.
Oh, and it makes the code more readable too...
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
No need to duplicate built-in functions that the kernel has, so have the
core kernel parse the userspace string. Saves us an allocation and
makes the logic simpler.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
On AP module (form factor), we don't have access to APBridge JTAG or UART.
But sometime, we still need to get log from APBridge. Add a new request in control endpoint
to get APBridge logs.
Logs can be accessed using debugfs (greybus/apb1_log).
Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Add error messages on failures to deactivate, set and get operation
handlers as any errors would not be detected by the upper layers (either
because the callbacks are declared void or expected to return a boolean
value).
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Add warning and refuse to set output value for pin configured as input,
as the result of such an operation is undefined.
Remove incorrect todo-comment suggesting that the driver could
implicitly switch direction as part of the call.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Use the more informative dev_err and dev_warn for messages, and make the
messages more uniform.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Make sure to propagate any errors detected up the call chain.
This specifically means that we will detect failed connection init,
something which is now handled more gracefully by greybus core.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Rename all struct gb_gpio_controller-pointer variables "ggc" for
consistency and readability reason.
This also fixes a bunch of lines that exceeded the 80 columns limit.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Remove unnecessary explicit cast of line value.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Remove overly defensive argument verification in gpio-chip callbacks. We
should trust gpiolib to get this right (or we would not even get any
callback) just like the other gpio drivers do.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Remove redundant verification of gpio numbers (which have already been
verified in the gpio-chip callbacks) from greybus-operation helpers.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
The module reference count is incremented by gpiolib when a gpio is
requested, and the driver callbacks certainly do sleep.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Fix set_debounce, which silently truncated the time argument to 255us
even though we support 16-bit values.
Also remove the unnecessary explicit cast when verifying the argument.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Remove unnecessary cast of the message size in gb_connection_recv.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Use the more informative dev_err in gb_operation_sync, which includes
the connection device name in the error message (which in turn encodes
the module, interface, bundle and cport ids).
Add missing braces to conditional-construct branches while at it.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Remove custom connection error function and replace it with dev_err.
The standard error function provides more information in the message
prefix (e.g. includes the interface id), has a well-known semantics
(e.g. does does not add newlines to messages), and is even somewhat
shorter to type.
Note that some uses of the custom function were already adding double
newlines due to the non-standard semantics.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Return immediately on bundle-init failure when processing SVC link up.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Fix incorrect SVC handshake protocol check, which would only bail out if
both major and minor protocol versions supported by the SVC differed.
Since we currently only support one version of the protocol, upgrade the
debug message to warning and bail unless the protocol versions match
perfectly for now.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This driver is being rewritten, but let's silence a pointer-to-int-cast
compiler warning meanwhile.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
There is no interrupt channel as such and so no need to support
->output_report().
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Add gb_debugfs_get method to access to gb_debug_root dentry,
in order to use it from other greybus modules.
Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Remove packed-attribute from line-coding struct, whose members are all
naturally aligned.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Fix alignment of the duty and period-fields in the config request,
which should follow the which-field without any inserted padding.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Fix alignment of the usec-field in the set-debounce request, which
should follow the which-field without any inserted padding.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Make sure not to call connection_exit for connections that have never
been initialised (e.g. due to failure to init).
This fixes oopses due to null-dereferences and use-after-free in
connection_exit callbacks (e.g. trying to remove a gpio-chip that has
never been added) when the bundle and interface are ultimately
destroyed.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This adds HID transport layer driver for Greybus. Most of the stuff is
implemented, but is untested.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Fix unconditional re-enabling of interrupts in gb_hd_connection_find,
which can be called with local interrupts disabled from the USB
completion handler.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
When it receive an interrupt, the function gb_gpio_request_recv doesn't
use the good gpio number to get the irq number. Then, the expected irq is never fired.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Fix unconditional re-enabling of interrupts in various operation
functions that can all be called with local interrupts disabled from USB
completion handlers.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Fix three related memory leaks in the init an exit callbacks, where the
gpio-lines array was never freed at all and the controller data wasn't
freed in the init error path.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Adds gpio interrupt handling support using an irqchip/irqdomain
instantiation inside the GB GPIO driver. This implementation works
on older kernels such as 3.10 that do not have the gpiolib irqchip
helpers. Any line on a Greybus gpiochip may be configured as an
interrupt. Once configured, IRQ event messages received from a
module fire off the registered interrupt handler.
Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Make sure to release the spin lock protecting the interface bundle lists
before tearing down the connections and removing the bundle device,
which are operations that may sleep.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Use GFP_ATOMIC for IDA memory allocations under spin lock, which must
not sleep.
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Export gb_operation_response_send() for other modules
Signed-off-by: Matt Porter <mporter@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
- Fixed incorrect use of $$GREYBUS_SRC_PATH variable
- Added quotes around find pattern to stop shell expansion of "*"
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
When initializing the USB device, we were starting up the svc message
queue before the cport urbs were allocated. This might not be an issue
for "slower" machines, but not having any allocated urbs for a cport
might be an issue if we were to handle svc messages.
So wait until everything is properly initialized and allocated before
starting the svc urb.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
SVC messages come in in an "order", so don't mess them up by processing
them out of order. Fix this by making our work queue ordered, which
should keep everything in line.
Reported-by: Perry Hung <perry@leaflabs.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
We now have several modules generated by the greybus build.
Let's add any *.ko files we find to the buid.
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Make sure destination for greybus modules is consistent and easier to maintain
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This reverts commit 241b5fefc54eae95239b0f7dc4e2b0db49457729 as it's
wrong, we want to insert into the correct place in the list.
Reported-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This reverts commit 57131bf309d34568dd3b8f8e9da7a7ba25e9495e, it isn't
going to be needed as the patch this fixes will be reverted.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
'gb_i2c_transfer_request' is the name given to a function and a struct. Though
we don't get any compilation errors/warnings about it, but the names should be
unique.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
'gb_i2c_transfer_response' is the name given to a function and a struct. Though
we don't get any compilation errors/warnings about it, but the names should be
unique.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
__gb_protocol_register check if the protocol is not already registred,
and then register it. It register in existing->lists but at this point,
existing is always NULL (we exist just before if not).
Use gb_protocols instead.
Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
These aren't used anymore and so can be removed.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This gets rid of lots of duplication of code.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Request type for all other protocols is defined like: GB_<protocol>_TYPE_<operation>,
but for UART is like: GB_<protocol>_REQ_<operation>.
Replace REQ with TYPE to make it consistent. It will also be useful in a later
patch that creates get_version() routines with the help of a macro.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Some files are still prefixed with "gb-" with the reasoning that the modules
would be named so, i.e. gb-*.ko. But this can be done by playing a bit in
Makefile instead and keep uniform naming of .c files.
Lets try it.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Some files are prefixed with "gb-" and some are suffixed with "-gb". The
rationale behind the first one is that the modules would be named so, i.e.
gb-*.ko. But there is no reason to keep the "-gb" suffix in the second case.
Remove the unnecessary suffix.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This is just a copy of ES1 for now, things will start to diverge soon.
Any common functionality will be factored out over time.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
In next_free_urb(), just return usb_alloc_urb(), don't waste the time
assigning it to a local variable that we then return.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
in protocol register replace the protocol find code with the call to the already
existing function.
Signed-off-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
if error is return when submiting the urb, we need to make sure to release the
urb from the pool, or from the dinamicly allocated. As in it, factor out the free
code and create the free_urb function.
Signed-off-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
just return the result of usb_alloc_urb up, no need to rededunt check for NULL
Signed-off-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
An extra reference is taken out on an operation in
gb_operation_request_send(). If the response never arrives, we need to
put back the reference.
Signed-off-by: Perry Hung <perry@leaflabs.com>
Tested-by: Mitchell Tasman <tasman@leaflabs.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
If an operation is issued and the response never comes back,
gb_operation_timeout() cancels the operation but never wakes up the
waiter in gb_operation_request_send().
This patch removes the timeout workqueue and changes the request wait to
wait_for_completion_interruptible_timeout(), with timeout set to
OPERATION_TIMEOUT_DEFAULT.
Signed-off-by: Perry Hung <perry@leaflabs.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
offset is defined as unsigned so there is no point checking for
negative values of offset.
Signed-off-by: Bill Pemberton <wfp5p@worldbroken.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
val is an unsigned long so there is no point in checking if it is less
than zero.
Signed-off-by: Bill Pemberton <wfp5p@worldbroken.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This .c file isn't needed by the kernel driver, it's there for firmware
developers only, so just move it into the Documentation directory to
reduce confusion.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
This module provides the Bridged PHY protocols, so name the thing
properly.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Provide an install Makefile target for those that want to install the
kernel modules.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
--
v3: resend to list, somehow this thread got taken private and v2 never
made it there.
v2: add -a option to depmod, thanks to Mitchell
The data_in_size variable was set to 1 for the status byte.
But now, the status byte has move to header. Then, the status byte
is "allocated" twice and cause bad message size error.
Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Right now some sysfs attributes have \n and some do not, so fix that and
put \n at the end of all of them to make it easier to parse things
properly in userspace.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
When removing a connection with no protocol assigned to it, the kernel
oopses as we always thought protocols were always there.
Fix that problem, oopses are bad.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
We want to be able to "blame" a protocol for things at times, so give
them a name we can refer to them by. Announce when they are added or
removed from the system so we have a chance to know what is going on
in the kernel logs.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Use the list that the driver core keeps of our structure, no need to
duplicate it with a local list as well. This gets rid of a static lock
too, always a nice thing to do.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
The i2c protocol belongs in the gpbridge driver, so move it
there.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
This bundles together the existing GP Bridged PHY protocols that were
part of the Greybus core: USB, UART, SDIO, PWM, and GPIO. This is now a
stand-alone kernel module. More logic will be moving here in the future
to handle bridged devices.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
This moves the battery class protocol to be a stand-alone kernel module.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
We can't use the gb_protocol_driver() macro here as we need to do some
init and exit logic when loading and removing, so "open code" the module
init and exit functions.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Now that protocols can be in a module, we need to reference count them
to lock them into memory so they can't be removed while in use. So add
a module owner structure, and have it automatically be assigned when
registering the protocol.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Use a "name" for when we don't have a valid device id yet, instead of a
magic value of 0xff.
Reported-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
This splits the i2c-gb protocol into a stand-alone kernel module.
It's not going to stay in this fashion for long, this was done to test
the "can a protcol be loaded later" logic. Future refactoring is going
to move the gpbridge protocols to a separate kernel module, where this
protocol is going to live.
But for now, split it out, it is good to test with, and shows a bug in
gbsim at the moment.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
When adding a new protocol to the system, walk all bundles and try to
hook up any connections that do not have a protocol already. This sets
the stage to allow for protocols to be loaded at any time, not just
before the device is seen in the system.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Protocol handlers need some greybus symbols, so export them so that they
can be built outside of the greybus core.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
We will want to return this value as a return value for module_init()
and bool does not play well with module_init(). So make it a "real"
error value and return int and fix up all callers of the function.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
The list was global and had no locking. It's not like we were ever
parsing more than one manifest at the same time right now, but we might
in the future. And we really want this to be local to the interface
itself, for future work redoing how to bind protocols to bundles, so
move the list to the interface structure.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Modules in the greybus system sit above the interface, so insert them
early in the sysfs tree. We dynamically create them when we have an
interface that references a module, as we don't get a "module create"
message directly. They also dynamically go away when the last interface
associated with a module is removed.
Naming scheme for modules/interfaces/bundles/connections is bumped up by
one ':', and now looks like the following:
/sys/bus/greybus $ tree
.
├── devices
│ ├── 7 -> ../../../devices/pci0000:00/0000:00:14.0/usb1/1-1/7
│ ├── 7:7 -> ../../../devices/pci0000:00/0000:00:14.0/usb1/1-1/7/7:7
│ ├── 7:7:0 -> ../../../devices/pci0000:00/0000:00:14.0/usb1/1-1/7/7:7/7:7:0
│ └── 7:7:0:1 -> ../../../devices/pci0000:00/0000:00:14.0/usb1/1-1/7/7:7/7:7:0/7:7:0:1
├── drivers
├── drivers_autoprobe
├── drivers_probe
└── uevent
6 directories, 3 files
/sys/bus/greybus $ grep . devices/*/uevent
devices/7/uevent:DEVTYPE=greybus_module
devices/7:7/uevent:DEVTYPE=greybus_interface
devices/7:7:0/uevent:DEVTYPE=greybus_bundle
devices/7:7:0:1/uevent:DEVTYPE=greybus_connection
We still have some "confusion" about interface ids and module ids, which
will be cleaned up later when the svc control protocol changes die down,
right now we just name a module after the interface as we don't have any
modules that have multiple interfaces in our systems.
This has been tested with gbsim.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
It's a local interface lock, not a modules lock, so rename it.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This is really a list of interfaces, not modules, so rename it so that
we don't get confused when we really do add modules to the whole system
later on.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
rename gb_add_module -> gb_add_interface
rename gb_remove_modules -> gb_remove_interfaces
rename gb_remove_module -> gb_remove_interface
And move the function prototypes to interface.h, where they belong.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Align up the BIT() #defines and properly comment the include block
define.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
MAX_CPORTS_PER_MODULE and MAX_STRINGS_PER_MODULE are not used anywhere
anymore, so remove them lest someone thing we have limits.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
This moves the id structure name to not have "block" in it, as that
doesn't make sense anymore with the renaming of the gb_interface
structure.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Rename struct gb_interface_block to struct gb_interface
Lots of renaming, and variable renames as well (gb_ib->intf), but all
should be sane with regards to the new naming scheme we are using.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Interface_block is being renamed to interface, so move the file first.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex pointed out one rename I missed previously, this fixes up the
interface_block list of bundles name.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Rename struct gb_interface to struct gb_bundle
It's a lot of renaming, some structures got renamed and also some
fields, but the goal was to rename things to make sense with the new
naming of how the system is put together in the 'driver model' view.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
-EPROTO happens when devices are starting to go away in a system, or
there is something wrong on the USB connection. Either way, it's safe
to resubmit the urb for this error, don't complain to userspace about
this, as the user will see this for every device removed, which looks
scary, but means nothing.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
We are renameing the "interface" term to "bundle" so rename the files
before we start changing structure names to make it easier for people to
see what really is happening in the changes.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
I was asked to add a Linaro copyright to all Greybus source files
that anyone at Linaro has modified. This patch does that.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Because of this, rename greybus_module_id to greybus_interface_block_id.
We still need to add a way for a "class" driver to be bound to an
interface, but for now, all we really need is the vendor/product pair as
the GP Bridge interface block is going to be our main user.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Yes, an interface has a device id sysfs file, so we need to document it.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Document what the sysfs files are for connections, so that people have a
chance to understand what they can be used for.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
No need to keep these out in sysfs.c, move them into the
interface_block.c file so that we can see them easier, and remove some
variable definitions by taking advantage of the attribute group macro.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
The sysfs files for an interface block should not have 'module' in them.
This was a hold-over from when we thought we were going to have
all attributes of a "module" in one directory. Remove the prefix as
it's not needed, and is confusing considering modules can not have
strings or any of these attributes.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Rename struct gb_module to struct gb_interface_block
It's a complex rename, some functions got their name changed where
needed, but primarily this change is focused on the structure and where
it is used. Future changes will clean up the remaining usages of the
term "module" in individual changes, this one spanned the whole
subsystem so do it all at once.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
"modules" in the driver model here, are really "interface blocks" as
that is what they are physically tied to. So rename the files before we
start changing the code to make it obvious what is going on.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
We aren't using this anymore, so remove gb_tty from struct gb_module.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
We removed the module version from the spec, so remove them from the
code as well. It's still in the manifest as we need to sync with gbsim
/ firmware when we do that, which will happen sometime in the next
weeks.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
No need to specifically include the greybus module.h here, greybus.h
already does so and we will be renaming it soon.
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
In talking with Perry today I learned that the CPort id expected to
supplied over the HSIC interface to the APB is different from the
way I understood it.
My understanding was that the CPort id to supply always specified
the CPort id on the other end of a connection. However, Perry says
the mapping between local CPort id and remote CPort id (and device
id) is done by the host UniPro interface.
So whether sending or receiving data, the CPort id that the Greybus
code should supply to the AP Bridge is the one representing the AP
side of a connection.
This patch fixes this. The receive side already used that CPort id;
it's only the sending code that needed to be changed.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
When probing for i2c devices, a read transfer operation can be used.
In this case, it is expected that some devices will not be found, so
ENODEV is an expected failure. Don't issue a warning if the return
value is -ENODEV.
Note: I anticipate we might have to be more precise in identifying
this specific case, but for now this eliminates a bogus warning when
probing i2c devices.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
The i2c protocol needs a way to indicate an i2c device doesn't exist
(which is not necessarily an error). Define GB_OP_NONEXISTENT to
indicate this, and updating the status<->errno mapping functions
accordingly.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
The version field is going to go away, but after the demo, not before.
Note that in the header file.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
I've gone back and forth on this, but now that I'm looking at
asynchronous operations I know that the asynchronous callback will
want to know what type of operation it is handling, and right now
that's only available in the message header.
So record an operation's type in the operation structure, and use
it in a few spots where the header type was being used previously.
Pass the type to gb_operation_create_incoming() so it can fill
it in after the operation has been created.
Clean up the crap comments above the definition of the operation
structure.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Currently message->payload always points to the address immediately
following the header in a message. If the payload length is 0, this
is not a valid pointer.
Change the code to assign a null pointer to the payload in this
case. I have verified that no code dereferences the payload pointer
unless the payload is known to have non-zero size.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
An asynchronous operation will want to know how big the response
message it receives is. Rather than require the sender to record
that information, expose a new field "payload_size" available to
the protocol code for this purpose.
An operation message consists of a header and a payload. The size
of the message can be derived from the size of the payload, so
record only the payload size and not the size of the whole message.
Reorder the fields in a message structure.
Update the description of the message header structure.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This is in preparation for an upcoming patch, which makes the
payload pointer be NULL when a message has zero bytes of payload.
It ensures a null payload pointer never gets dereferenced. To do
this we pass the response structure to gb_i2c_transfer_response()
rather than just its data, and if it's null, returning immediately.
Rearrange the logic in gb_i2c_transfer_operation() a bit.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
The connection->private pointer should refer to a protocol-specific
data structure. Change two protocol drivers (USB and vibrator) so
they now set this.
In addition, because the setup routine may need access to the
data structure, the private pointer should be set early--as
early as possible. Make the UART, i2c, and GPIO protocol drivers
set the private pointer earlier.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
The error message printed by gb_operation_sync() if the operation
fails is wrong. Fix it.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Define a new function used to initiate a synchronous operation.
It sends the operation request message and doesn't return until
the response has been received and/or the operation's result
has been set.
This gets rid of the convention that a null callback pointer
signifies a synchronous operation.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
There's no need to protect updating a connections operation id cycle
counter with the operations spinlock. That spinlock protects
connection lists, which do not interact with the cycle counter.
All that we require is that it gets updated atomically, and we
can express that requirement in its type.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
A connection has two lists of operations, and an operation is always
on one or the other of them. One of them contains the operations
that are currently "in flight".
We really don't expect to have very many in-flight operations on any
given connection (in fact, at the moment it's always exactly one).
So there's no significant performance benefit to keeping these in a
separate list. An in-flight operation can also be distinguished by
its errno field holding -EINPROGRESS.
Get rid of the pending list, and search all operations rather than
the pending list when looking up a response message's operation.
Rename gb_pending_operation_find() accordingly.
There's no longer any need to remove operations from the pending
list, and the insertion function no longer has anything to do with a
pending list. Just open code what was the insertion function (it
now has only to do with assigning the operation id).
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Stop allowing 0x0000 to be used as an operation id. That id will be
reserved for use by operations that will return no response message.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Use a symbolic constant (rather than just "0") to represent an
explicitly invalid operation type. The protocols have all reserved
that value for that purpose--this just makes it explicit in the core
code (since we now leverage its existence). Fix the code so it uses
the new symbolic value.
Define it in "operation.h" for all to see. Move the common
definition of the GB_OPERATION_TYPE_RESPONSE flag mask there
as well.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
The memcpy of request data into the request payload was
copying the data into the wrong location. Fix that.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
The PWM config request defines two 32-bit values using u32. All
over-the-wire values have to be in little-endian format. Fix this.
Signed-off-by: Alex Elder <elder@linaro.org>
Acked-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Define a helper function gb_operation_response_alloc() and use it
to allocate the response buffer for outgoing operations in
gb_operation_create_common(.
Use it also in gb_operation_response_send() if the caller has not
allocated a response buffer.
Once a response buffer is allocated, fill in its result code and
send it.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Define gb_operation_errno_map(), which maps an operation->errno
into the u8 value that represents it in the status field of an
operation response header. It'll be used in an upcoming patch.
Make gb_operation_status_map() a private function. It's not used
outside "operation.c" and I don't believe it ever should be.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Un-comment gb_operation_request_handle(), which was recently
disabled to avoid distraction.
In gb_connection_recv_request(), activate handling incoming
requests by defining gb_operation_request_handle() as an
incoming operation's callback function.
Incoming operation requests have
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Change gb_operation_response_send() so it takes an errno to assign
as an operation's result. This emphasizes that setting the result
should be the last thing done to an incoming operation before
sending its response.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
A large number of request and response message types have no payload.
Such "simple" messages have a known, fixed maximum size, so we can
preallocate and use a pool (slab cache) of them.
Here are two benefits to doing this:
- There can be (small) performance and memory utilization
benefits to using a slab cache.
- Error responses can be sent with no payload; the cache is
likely to have a free entry to use for an error response even
in a low memory situation.
The plan here is that an incoming request handler that has no
response payload to fill will not need to allocate a response
message. If no message has been allocated when a response is to be
sent, one will be allocated from the cache by the core code.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Define a maximum size that a host device can use for its private
area ahead of the payload space used by Greybus in a message buffer.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Separate the allocation of a message structure from its basic
initialization. This will allow very common fixed-size operation
response buffers to be allocated from a slab cache.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
When incoming data is going to be handled as a request, we create a
new operation whose request buffer will hold the received data.
There is no need to initialize the message header in such a request
buffer because it will be immediately overwritten.
Use operation type value of 0x00 in gb_operation_create_common()
to signal that we are creating an incoming operation, and therefore
do not need to initialize the request message header. This allows
us to get rid of the Boolean "outgoing" parameter.
As a result, we can stop supplying the "type" parameter to both
gb_operation_create_incoming() and gb_connection_recv_request().
Update the header comments for gb_operation_message_alloc() and
gb_operation_create_common().
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
The operation type 0x00 is reserved as an explicitly invalid
operation type in all protocols. Enforce this.
Add a check for callers who erroneously have the RESPONSE message
type flag set in the operation type passed in gb_operation_create().
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Pass the operation result to gb_connection_recv_response() as a
parameter.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
We enforce a rule that a response message must completely fill the
buffer that's been allocated to hold it. However, if an error
occurs, the payload is off limits, so we should allow a short
message to convey an error result.
Change gb_connection_recv_response() to require the right message
size only if there's no error.
One other thing: The arriving data is only being copied into the
response buffer if the request was successful. That means the
response message header is assumed to have been initialized. That
isn't a valid assumption. So change it so that if an error is
seen, the header portion of the message is copied into the
response buffer--but only the header.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Currently incoming request data is copied into a request message
buffer in gb_connection_recv_request(). Move that--along with the
assignment of the message id--into gb_operation_create_incoming().
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Currently we issue a warning in gb_operation_work() if an operation
has no callback function defined. But we return without dropping
the reference to the operation as we should.
Stop warning if there's no callback, call it only if it's defined,
and always drop the operation reference before returning.
This means we're now treating a NULL callback pointer as a normal
condition.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
We will only send messages from process context. Drop the gfp_mask
parameter from gb_message_send(), and just supply GFP_KERNEL to the
host driver's buffer_send method.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Define a new operation status GB_OP_MALFUNCTION, which will be used
to represent that something unexpected happened while handling an
operation. This is intended as an indication similar to a BUG()
call--whatever went wrong should *never* happen and because it's
unexpected we need to treat it as a fatal error.
Define another new operation status GB_OP_UNKNOWN_ERROR, which
will represent the case where an operation ended in error, but
the error was not recognized to be properly represented by one
of the other status values.
Renumber the operation status values, defining those that are
produced by core operations code ahead of those that are more
likely to come from operation handlers. Represent the values in
hexadecimal to emphasize that they must be represented with 8 bits.
The Use 0xff for GB_OP_MALFUNCTION instead of GB_OP_TIMEOUT; the
latter is special, but a malfunction is in a class by itself.
Reorder the cases in gb_operation_status_map() to match their
numeric order.
Map GB_OP_UNKNOWN_ERROR to -EIO in gb_operation_status_map(). Map
GB_OP_MALFUNCTION to -EILSEQ in gb_operation_status_map(), since
that value is used to represent an implementation error.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reserve operation result code -EILSEQ to represent that the code
that implements an operation is broken. This is used (initially)
for any attempt to set the result to -EBADR (which is reserved for
an operation in initial state), or for an attempt to set the result
of an operation that is *not* in initial state to -EINPROGRESS.
Note that we still use -EIO gb_operation_status_map() to represent a
gb_operation_result value that isn't recognized.
In gb_operation_result(), warn if operation->errno is -EBADR. That
is another value that indicates the operation is not in a state
where it's valid to query an operation's result.
Update a bunch of comments above gb_operation_result_set() to
explain constraints on operation->errno.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
We represent the size of a message using a 16-bit field. It's
possible for a host driver to advertise a maximum message size
that's bigger than that. If that happens, reduce the host device's
maximum buffer size to the maximum we can represent the first time
a message is allocated.
This information is actually only used by the Greybus code, but
because we're modifying a value that's "owned" by the host driver,
issue a warning when this limit is being imposed
Ensure (at build time) that our own definition is sane as well.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
In gb_operation_create_common(), a zero response size is still
being used to determine whether to use GFP_KERNEL or GFP_ATOMIC
when allocating a message. Use the value of the "outgoing"
parameter to decide this instead.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Based on Fabien's original driver, this version is converted (mostly) to
the new greybus operation apis. Lots of things still to do, not the
least being hooking up proper responses...
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
When a Greybus message is sent, the host driver supplies a cookie
for Greybus to use to identify the sent message in the event it
needs to be canceled. The cookie will be non-null while the message
is in flight, and a null pointer otherwise.
There are two problems with this, which arise out of the fact that a
message can be canceled at any time--even concurrent with it getting
sent (such as when Greybus is getting shut down).
First, the host driver's buffer_send method can return an error
value, which is non-null but not a valid cookie. So we need to
ensure such a bogus cookie is never used to cancel a message.
Second, we can't resolve that problem by assigning message->cookie
only after we've determined it's not an error. The instant
buffer_send() returns, the message may well be in flight and *should*
be canceled at shutdown, so we need the cookie value to reflect
that.
In order to avoid these problems, protect access to a message's
cookie value with a mutex. A spin lock can't be used because the
window that needs protecting covers code that can block. We
reset the cookie value to NULL as soon as the host driver has
notified us it has been sent (or failed to).
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
It's possible for an in-flight buffer to be recorded as sent *after*
a thread has begin the process of canceling it. In that case the
Greybus message cookie will be set to NULL, and that value can end
up getting passed to buffer_cancel(). Change buffer_cancel() so
it properly handles (ignores) a null cookie pointer.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
An operation result can be set both in and out of interrupt context.
For example, a response message could be arriving at the same time a
timeout of the operation is getting processed. We therefore need to
ensure the result is accessed atomically.
Protect updates to the errno field using the operations spinlock.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
When an operation is created its receive buffer size is specified.
In all current cases, the size supplied for the receive buffer is
exactly the size that should be returned. In other words, if
any fewer than that many bytes arrived in a response, it would be
an error.
So tighten the check on the number of bytes arriving for a response
message, ensuring that the number of bytes received is *exactly the
same* as the number of bytes available (rather than just less than).
We'll expand our interpretation of of -EMSGSIZE to mean "wrong
message size" rather than just "message too long."
If we someday encounter an actual case where we want to be able to
successfully receive something less than the full receive buffer we
can adjust the code to handle that (and give it a way to tell the
receiver how many bytes are present).
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Change the message result values used in two cases.
First, use -EMSGSIZE rather than -E2BIG to represent a message
that is larger than the buffer intended to hold it. That is
the proper code for this situation.
Second, use -ECANCELED rather than -EINTR for an operation that
has been canceled. The definition of that error is literally
"Operation Canceled" so it seems like the right thing to do.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
This is more or less re-implementing this commit:
96f95d4 greybus: update gbuf status for completion handlers
But this time we're doing this for an operation, not the gbuf.
Define an initial operation result value (-EBADR) to signify that no
valid result has been set. Nobody should ever set that value after
the operation is initially created. Since only the operation core
code sets the result, an attempt to set -EBADR would be a bug.
Define another known operation result value (-EINPROGRESS) for an
outgoing operation whose request has been sent but whose response
has not yet been successfully received. This should the first
(non-initial) result value set, and it should happen exactly once.
Any other attempt to set this value once set would be a bug.
Finally, once the request message is in flight, the result value
will be set exactly once more, to indicate the final result of
the operation.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>