aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/greybus/operation.c
AgeCommit message (Collapse)Author
2017-11-21treewide: setup_timer() -> timer_setup()Kees Cook
This converts all remaining cases of the old setup_timer() API into using timer_setup(), where the callback argument is the structure already holding the struct timer_list. These should have no behavioral changes, since they just change which pointer is passed into the callback with the same available pointers after conversion. It handles the following examples, in addition to some other variations. Casting from unsigned long: void my_callback(unsigned long data) { struct something *ptr = (struct something *)data; ... } ... setup_timer(&ptr->my_timer, my_callback, ptr); and forced object casts: void my_callback(struct something *ptr) { ... } ... setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr); become: void my_callback(struct timer_list *t) { struct something *ptr = from_timer(ptr, t, my_timer); ... } ... timer_setup(&ptr->my_timer, my_callback, 0); Direct function assignments: void my_callback(unsigned long data) { struct something *ptr = (struct something *)data; ... } ... ptr->my_timer.function = my_callback; have a temporary cast added, along with converting the args: void my_callback(struct timer_list *t) { struct something *ptr = from_timer(ptr, t, my_timer); ... } ... ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback; And finally, callbacks without a data assignment: void my_callback(unsigned long data) { ... } ... setup_timer(&ptr->my_timer, my_callback, 0); have their argument renamed to verify they're unused during conversion: void my_callback(struct timer_list *unused) { ... } ... timer_setup(&ptr->my_timer, my_callback, 0); The conversion is done with the following Coccinelle script: spatch --very-quiet --all-includes --include-headers \ -I ./arch/x86/include -I ./arch/x86/include/generated \ -I ./include -I ./arch/x86/include/uapi \ -I ./arch/x86/include/generated/uapi -I ./include/uapi \ -I ./include/generated/uapi --include ./include/linux/kconfig.h \ --dir . \ --cocci-file ~/src/data/timer_setup.cocci @fix_address_of@ expression e; @@ setup_timer( -&(e) +&e , ...) // Update any raw setup_timer() usages that have a NULL callback, but // would otherwise match change_timer_function_usage, since the latter // will update all function assignments done in the face of a NULL // function initialization in setup_timer(). @change_timer_function_usage_NULL@ expression _E; identifier _timer; type _cast_data; @@ ( -setup_timer(&_E->_timer, NULL, _E); +timer_setup(&_E->_timer, NULL, 0); | -setup_timer(&_E->_timer, NULL, (_cast_data)_E); +timer_setup(&_E->_timer, NULL, 0); | -setup_timer(&_E._timer, NULL, &_E); +timer_setup(&_E._timer, NULL, 0); | -setup_timer(&_E._timer, NULL, (_cast_data)&_E); +timer_setup(&_E._timer, NULL, 0); ) @change_timer_function_usage@ expression _E; identifier _timer; struct timer_list _stl; identifier _callback; type _cast_func, _cast_data; @@ ( -setup_timer(&_E->_timer, _callback, _E); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, &_callback, _E); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, _callback, (_cast_data)_E); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, &_callback, (_cast_data)_E); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, (_cast_func)_callback, _E); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, (_cast_func)&_callback, _E); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E._timer, _callback, (_cast_data)_E); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, _callback, (_cast_data)&_E); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, &_callback, (_cast_data)_E); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, &_callback, (_cast_data)&_E); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E); +timer_setup(&_E._timer, _callback, 0); | _E->_timer@_stl.function = _callback; | _E->_timer@_stl.function = &_callback; | _E->_timer@_stl.function = (_cast_func)_callback; | _E->_timer@_stl.function = (_cast_func)&_callback; | _E._timer@_stl.function = _callback; | _E._timer@_stl.function = &_callback; | _E._timer@_stl.function = (_cast_func)_callback; | _E._timer@_stl.function = (_cast_func)&_callback; ) // callback(unsigned long arg) @change_callback_handle_cast depends on change_timer_function_usage@ identifier change_timer_function_usage._callback; identifier change_timer_function_usage._timer; type _origtype; identifier _origarg; type _handletype; identifier _handle; @@ void _callback( -_origtype _origarg +struct timer_list *t ) { ( ... when != _origarg _handletype *_handle = -(_handletype *)_origarg; +from_timer(_handle, t, _timer); ... when != _origarg | ... when != _origarg _handletype *_handle = -(void *)_origarg; +from_timer(_handle, t, _timer); ... when != _origarg | ... when != _origarg _handletype *_handle; ... when != _handle _handle = -(_handletype *)_origarg; +from_timer(_handle, t, _timer); ... when != _origarg | ... when != _origarg _handletype *_handle; ... when != _handle _handle = -(void *)_origarg; +from_timer(_handle, t, _timer); ... when != _origarg ) } // callback(unsigned long arg) without existing variable @change_callback_handle_cast_no_arg depends on change_timer_function_usage && !change_callback_handle_cast@ identifier change_timer_function_usage._callback; identifier change_timer_function_usage._timer; type _origtype; identifier _origarg; type _handletype; @@ void _callback( -_origtype _origarg +struct timer_list *t ) { + _handletype *_origarg = from_timer(_origarg, t, _timer); + ... when != _origarg - (_handletype *)_origarg + _origarg ... when != _origarg } // Avoid already converted callbacks. @match_callback_converted depends on change_timer_function_usage && !change_callback_handle_cast && !change_callback_handle_cast_no_arg@ identifier change_timer_function_usage._callback; identifier t; @@ void _callback(struct timer_list *t) { ... } // callback(struct something *handle) @change_callback_handle_arg depends on change_timer_function_usage && !match_callback_converted && !change_callback_handle_cast && !change_callback_handle_cast_no_arg@ identifier change_timer_function_usage._callback; identifier change_timer_function_usage._timer; type _handletype; identifier _handle; @@ void _callback( -_handletype *_handle +struct timer_list *t ) { + _handletype *_handle = from_timer(_handle, t, _timer); ... } // If change_callback_handle_arg ran on an empty function, remove // the added handler. @unchange_callback_handle_arg depends on change_timer_function_usage && change_callback_handle_arg@ identifier change_timer_function_usage._callback; identifier change_timer_function_usage._timer; type _handletype; identifier _handle; identifier t; @@ void _callback(struct timer_list *t) { - _handletype *_handle = from_timer(_handle, t, _timer); } // We only want to refactor the setup_timer() data argument if we've found // the matching callback. This undoes changes in change_timer_function_usage. @unchange_timer_function_usage depends on change_timer_function_usage && !change_callback_handle_cast && !change_callback_handle_cast_no_arg && !change_callback_handle_arg@ expression change_timer_function_usage._E; identifier change_timer_function_usage._timer; identifier change_timer_function_usage._callback; type change_timer_function_usage._cast_data; @@ ( -timer_setup(&_E->_timer, _callback, 0); +setup_timer(&_E->_timer, _callback, (_cast_data)_E); | -timer_setup(&_E._timer, _callback, 0); +setup_timer(&_E._timer, _callback, (_cast_data)&_E); ) // If we fixed a callback from a .function assignment, fix the // assignment cast now. @change_timer_function_assignment depends on change_timer_function_usage && (change_callback_handle_cast || change_callback_handle_cast_no_arg || change_callback_handle_arg)@ expression change_timer_function_usage._E; identifier change_timer_function_usage._timer; identifier change_timer_function_usage._callback; type _cast_func; typedef TIMER_FUNC_TYPE; @@ ( _E->_timer.function = -_callback +(TIMER_FUNC_TYPE)_callback ; | _E->_timer.function = -&_callback +(TIMER_FUNC_TYPE)_callback ; | _E->_timer.function = -(_cast_func)_callback; +(TIMER_FUNC_TYPE)_callback ; | _E->_timer.function = -(_cast_func)&_callback +(TIMER_FUNC_TYPE)_callback ; | _E._timer.function = -_callback +(TIMER_FUNC_TYPE)_callback ; | _E._timer.function = -&_callback; +(TIMER_FUNC_TYPE)_callback ; | _E._timer.function = -(_cast_func)_callback +(TIMER_FUNC_TYPE)_callback ; | _E._timer.function = -(_cast_func)&_callback +(TIMER_FUNC_TYPE)_callback ; ) // Sometimes timer functions are called directly. Replace matched args. @change_timer_function_calls depends on change_timer_function_usage && (change_callback_handle_cast || change_callback_handle_cast_no_arg || change_callback_handle_arg)@ expression _E; identifier change_timer_function_usage._timer; identifier change_timer_function_usage._callback; type _cast_data; @@ _callback( ( -(_cast_data)_E +&_E->_timer | -(_cast_data)&_E +&_E._timer | -_E +&_E->_timer ) ) // If a timer has been configured without a data argument, it can be // converted without regard to the callback argument, since it is unused. @match_timer_function_unused_data@ expression _E; identifier _timer; identifier _callback; @@ ( -setup_timer(&_E->_timer, _callback, 0); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, _callback, 0L); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, _callback, 0UL); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E._timer, _callback, 0); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, _callback, 0L); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, _callback, 0UL); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_timer, _callback, 0); +timer_setup(&_timer, _callback, 0); | -setup_timer(&_timer, _callback, 0L); +timer_setup(&_timer, _callback, 0); | -setup_timer(&_timer, _callback, 0UL); +timer_setup(&_timer, _callback, 0); | -setup_timer(_timer, _callback, 0); +timer_setup(_timer, _callback, 0); | -setup_timer(_timer, _callback, 0L); +timer_setup(_timer, _callback, 0); | -setup_timer(_timer, _callback, 0UL); +timer_setup(_timer, _callback, 0); ) @change_callback_unused_data depends on match_timer_function_unused_data@ identifier match_timer_function_unused_data._callback; type _origtype; identifier _origarg; @@ void _callback( -_origtype _origarg +struct timer_list *unused ) { ... when != _origarg } Signed-off-by: Kees Cook <keescook@chromium.org>
2017-11-11staging: greybus: Remove redundant license textGreg Kroah-Hartman
Now that the SPDX tag is in all greybus files, that identifies the license in a specific and legally-defined manner. So the extra GPL text wording can be removed as it is no longer needed at all. This is done on a quest to remove the 700+ different ways that files in the kernel describe the GPL license text. And there's unneeded stuff like the address (sometimes incorrect) for the FSF which is never needed. No copyright headers or other non-license-description text was removed. Cc: Vaibhav Hiremath <hvaibhav.linux@gmail.com> Reviewed-by: Alex Elder <elder@linaro.org> Acked-by: Vaibhav Agarwal <vaibhav.sr@gmail.com> Acked-by: David Lin <dtwlin@gmail.com> Acked-by: Johan Hovold <johan@kernel.org> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Acked-by: Mark Greer <mgreer@animalcreek.com> Acked-by: Rui Miguel Silva <rmfrfs@gmail.com> Acked-by: "Bryan O'Donoghue" <pure.logic@nexus-software.ie> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-11staging: greybus: add SPDX identifiers to all greybus driver filesGreg Kroah-Hartman
It's good to have SPDX identifiers in all files to make it easier to audit the kernel tree for correct licenses. Update the drivers/staging/greybus files files with the correct SPDX license identifier based on the license text in the file itself. The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. This work is based on a script and data from Thomas Gleixner, Philippe Ombredanne, and Kate Stewart. Cc: Vaibhav Hiremath <hvaibhav.linux@gmail.com> Cc: "Bryan O'Donoghue" <pure.logic@nexus-software.ie> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Kate Stewart <kstewart@linuxfoundation.org> Cc: Philippe Ombredanne <pombredanne@nexb.com> Acked-by: Vaibhav Agarwal <vaibhav.sr@gmail.com> Acked-by: David Lin <dtwlin@gmail.com> Reviewed-by: Alex Elder <elder@linaro.org> Acked-by: Johan Hovold <johan@kernel.org> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Acked-by: Mark Greer <mgreer@animalcreek.com> Acked-by: Rui Miguel Silva <rmfrfs@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-02-09staging: greybus: operation: add generic timeout supportJohan Hovold
Add a struct timer_list to struct gb_operation and use that to implement generic operation timeouts. This simplifies the synchronous operation handling somewhat while also providing a generic timeout mechanism that drivers can use for asynchronous operations. Signed-off-by: Johan Hovold <johan@kernel.org> Acked-by: Bryan O'Donoghue <pure.logic@nexus-software.ie> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-07-26greybus: operation: clean up request handlerJohan Hovold
Clean up the incoming request handler somewhat by passing a properly aligned header and dropping the now redundant id and type parameters. Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org> Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Reviewed-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-26greybus: operation: fix broken response tracepointJohan Hovold
The response-received tracepoint is currently broken. Instead of parsing the received message header it was tracing a bunch of zeroed fields from an uninitialised response buffer. Fix this by moving the tracepoint after were the response buffer is initialised. Fixes: 7cb496e6890e ("greybus: tracing: fix message traces") Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org> Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Reviewed-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-26greybus: operation: fix broken response error messagesJohan Hovold
The operation type included in the error message printed for malformed responses has never been correct. An uninitialised buffer was used to retrieve the type, resulting in the type always being reported as 0. Fix this by passing a properly aligned header to the response handler, and drop the now redundant id and result parameters. Fixes: cb0ef0c019ab ("operation: print message type on errors") Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org> Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Reviewed-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-07-22greybus: operation: print id when synchronous operation timeoutDavid Lin
In case of a synchronous operation timeout error, it's helpful for purpose of debugging to print the operation id in the error message, so that we know if the response is received at a later time after operation time out. Testing Done: - Observe the error message below when response comes later after operation timeout: [ 792.973978] greybus greybus1: 0/0:0: synchronous operation id 0x0005 of type 0x21 failed: -110 [ 800.646694] greybus greybus1: 0/0:0: unexpected response id 0x0005 received Signed-off-by: David Lin <dtwlin@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-23greybus: Revert "greybus: ratelimit errors usually seen on unipro_reset"Viresh Kumar
This reverts commit 9b891f4fda8dfd6c1d8dc16479c5f6d418a9ccc7. We discussed this over the other thread, [PATCH 0/2] Improve watchdog's implementation a bit, and decided that we shouldn't be trying to hide the watchdog reboot problem by using such patches, rather we should make sure they occur consistently so that the real problem can be fixed. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-06-21greybus: ratelimit errors usually seen on unipro_resetVaibhav Hiremath
It is believed that excessive serial messages from greybus on suspend/resume is leading to watchdog bite. There is still discussion going on whether ratelimiting prints would really fix anything, except it may reduce traffic on serial console and probably bring out real issues in the front. So in order to meet the alpha requirement, we all decided to get ratelimit change "as a TEMP fix" and decide later whether we should revert back once we get proper suspend/resume implementation. Please follow the discussion on Jira card SW-6261. Testing Done: Build tested against ara/main branch. Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org> Reviewed-by: Konstantin Buhchev <buhchev_konstantin@projectara.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-27greybus: fix tracepoint-related whitespace issuesJohan Hovold
Fix some whitespace issues introduced by the recent tracepoint changes. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-27greybus: connection: implement proper connection closureJohan Hovold
Implement proper connection closure, which includes sending ping requests on the connection being tore down while coordinating with the remote interface as well as the SVC. This specifically implements the new ping operation, which in case of offloaded connections is handled by the host-device driver in an implementation-defined manner through a new callback. Note that the normal connection tear-down procedure is executed in case of failed connection establishment due to failed connected operation. Specifically, the disconnecting request is sent also in case the connected operation never succeeded. This is needed since the interface may have enabled FCT flow upon receiving the connected request. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-27greybus: operation: add helper for creating core operationsJohan Hovold
Add a new core operation flag and a helper that core can use to create core operations. This will be used to implement the ping operations that core sends as part of connection tear down. Note that a new trace point is also added. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-27greybus: operation: restructure activation state handlingJohan Hovold
Restructure the operation activation state handling in preparation for a new disconnecting state. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-27greybus: operation: clean up early connection-state checkJohan Hovold
Now that the legacy invalid state is gone, clean up the early connection-state check in the receive path and explicitly drop incoming messages for disabled connection. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-26greybus: tracing: fix a bad tracepointAlex Elder
In gb_operation_put_active(), the wrong trace point is being called. Fix that. Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-20greybus: add operation tracesAlex Elder
Define a new gb_operation event class, and define and use trace events that record when an operation is created, finally destroyed, and when its active count changes. Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-18greybus: operation: fix broken activation logicJohan Hovold
An operation should only be added to the connection active list if the connection is in the enabled state, or if it is in the enabled_tx state and the operation is not incoming. This fixes a race where an early or late incoming request could be added to the active list while the connection is being enabled or disabled, something which could lead to use-after-free issues or worse. Note that the early connection-state checks in the receive path limited the impact of this bug. Fixes: e903a2ce7379 ("connection: add unidirectional enabled state") Reported-by: Alex Elder <elder@linaro.org> Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-17greybus: operation: rate-limit dev_err printing on the receive pathEli Sennesh
When we receive Greybus operations we don't recognize, requests or responses, en masse, we can pile up a lot of dev_err() printk messages. Doing so along the gb_connection_recv() code path can delay receive processing by up to seven milliseconds, starving the system of bulk-IN urbs. Rate limit those printk messages, ensuring that after too many repeated errors at the same place in the code-path, we'll stop printing to the console at all and let the urbs get returned. This will help prevent denial-of-service attacks on the AP through the UniPro network from malicious or malfunctioning modules. Testing Done: 7 msec recv-to-resubmit-urb processing times go down to <20 usecs Signed-off-by: Eli Sennesh <esennesh@leaflabs.com> Reviewed-by: Johan Hovold <johan@hovoldconsulting.com> Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> Reviewed-by: Mitchell Tasman <tasman@leaflabs.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-05-13greybus: connection: add offloaded connection flagJohan Hovold
Add an offloaded connection flag, which is used to mark a connection as offloaded and prevent drivers from initiating operation over it. This will be used for the audio and camera data connections. 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>
2016-05-09greybus: operation: fix an inconsistent indentDavid Lin
This patch fixes an inconsistent indent. Testing Done: - Build & boot Signed-off-by: David Lin <dtwlin@google.com> Acked-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-04-29greybus: operation: fix definition of the invalid typeJohan Hovold
The invalid request type has been redefined as 0x7f. Also remove the redundant redefinition of the invalid type from the operation header. Note that operation type 0x00 has been repurposed for the new generic ping operation, which will be used to implement proper connection tear down. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-04-29greybus: operation: add helper functions for unidirectional operationsJohan Hovold
Add helper functions for initiating unidirectional operations and waiting for them to have been acknowledged as sent by the host device. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-04-29greybus: operation: add support for initiating unidirectional operationsJohan Hovold
Add support for initiating unidirectional operations, that is, sending requests that do not require responses. Note that we already handle incoming unidirectional operations. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-04-29greybus: operation: update gb_operation_request_send() documentationJohan Hovold
Fix and update gb_operation_request_send() documentation and add kernel-doc formatting. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-04-29greybus: fix outdated kernel-doc commentJohan Hovold
Update the function name, which has gained a timeout suffix. Also fix the kernel-doc formatting. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-02-25greybus: operation: add support for short responsesJohan Hovold
Add support for operations with short responses. So far we have assumed that the initiator of an operation always knows the exact size of the expected response. This is however not always the case and we've worked around this limitation in a couple of places by, for example, first requesting the size of a resource before fetching the actual data. To avoid such workarounds and simplify our protocols, add a short-response flag that can be set when allocating an operation. When this flag is set on an operation, core will accept a response that is shorter than the size of the (pre-allocated) response payload buffer. For now, we update the response-message payload_size field to reflect the actual length of the response received. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-02-25greybus: operation: add temporary pointer to response handlerJohan Hovold
As a preparatory clean up, add a temporary variable to point to the response message header. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-02-11greybus: core: add device prefix to error messagesJohan Hovold
Use dev_err and dev_warn where appropriate and remove now unused pr_fmt defines. Testing Done: Tested on DB3.5 with the generic bridge firmware on APB2. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-01-19greybus: connection: add unidirectional enabled stateJohan Hovold
Add a new connection state ENABLED_TX in which only outgoing operations are allowed. This allows drivers to query the device during probe before allocating their state containers without having to worry about racing incoming requests. Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2016-01-19greybus: connection: add per-connection request handlersJohan Hovold
Add a connection request-handler field to struct gb_connection that is set when the connection is enabled. This is a step towards removing the legacy protocol abstraction from core, and will also be used to implement unidirectional connection states (e.g. only outgoing operations are allowed). Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-12-04greybus: don't use %h and %hh for printing short and char variablesViresh Kumar
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>
2015-11-25greybus: operation: handle static connectionsJohan Hovold
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>
2015-11-04greybus: hd: rename host-device structureJohan Hovold
Rename host-device structure gb_host_device to match our other structures. 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>
2015-10-15greybus: operation: use the bundle struct device instead of the connectorGreg Kroah-Hartman
We are removing struct device from the gb_connection structure in the near future. The gb_bundle structure's struct device should be used as a replacement. This patch moves the operation code to use to use the bundle pointer instead of the connection pointer when printing out error messages. Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Reviewed-by: Alex Elder <elder@linaro.org>
2015-10-14greybus: operation: clean up error messagesJohan Hovold
Clean up and improve error messages. Demote a warning message to warning level. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-10-14greybus: operation: drop OOM-response FIXMEJohan Hovold
Drop FIXME about sending responses in OOM situations. If we fail to allocate an operation for an incoming request, we have bigger problems than to worry about sending a response. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-09-29greybus: operation: remove gb_operation_destroyJohan Hovold
Remove legacy interface to "destroy" operations, which is now just a wrapper for gb_operation_put. The old interface name hides the fact that all operations are refcounted and may live on even after having "destroyed" them. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-09-18greybus: operation, core: hook tracepoints into message opertionsBryan O'Donoghue
This patch hooks tracepoints for greybus messages - trace_gb_message_send - trace_gb_message_recv_request - trace_gb_message_recv_response - trace_gb_message_cancel_outgoing - trace_gb_message_cancel_incoming It provides standard tracepoints at /sys/kernel/debug/tracing/events/greybus/gb_message_send /sys/kernel/debug/tracing/events/greybus/gb_message_recv_response /sys/kernel/debug/tracing/events/greybus/gb_message_recv_request /sys/kernel/debug/tracing/events/greybus/gb_message_cancel_outgoing /sys/kernel/debug/tracing/events/greybus/gb_message_cancel_incoming Giving outputs like gb_message_recv_request: greybus:1-1.1:0 op=0001 if_id=0000 hd_id=0000 l=2 gb_message_send: greybus:1-1.1:0 op=0001 if_id=0000 hd_id=0000 l=2 Similarly perf events can be viewed with standard perf tools e.g. root@beaglebone:~# perf list 'greybus:*' greybus:gb_message_send [Tracepoint event] greybus:gb_message_recv_request [Tracepoint event] greybus:gb_message_recv_response [Tracepoint event] greybus:gb_message_cancel_outgoing [Tracepoint event] greybus:gb_message_cancel_incoming [Tracepoint event] Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-08-18greybus: operation: Fix wrong order of argumentsViresh Kumar
The order of arguments is wrong and that shows up as a warning only on 64 bit machines. Fixes: cb0ef0c019ab ("operation: print message type on errors") Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-08-14greybus: operation: print message type on errorsViresh Kumar
This can be very useful debug information, print it. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-23greybus: operation: add completion work queueJohan Hovold
Add dedicated bound work queue for operation completions and use the connection work queues for incoming requests only. There is no need to keep responses ordered internally or with respect to requests. Instead allow operations to complete as soon as possible when a response arrives (or the operation is cancelled). Note that this also allows synchronous requests to be submitted from request handlers as responses will no longer be blocked on the same single-threaded work queue. Similarly, operations can now also be cancelled from a request handler. Tested-by: Rui Miguel Silva <rui.silva@linaro.org> 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>
2015-07-23greybus: operation: use per-connection work queuesJohan Hovold
Replace the global operation work queue with per-connection work queues. There is no need to keep operations strictly ordered across connections, something which only adds unnecessary latency. Tested-by: Rui Miguel Silva <rui.silva@linaro.org> 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>
2015-07-22greybus: operation: clean up greybus_message_sentJohan Hovold
Add connection variable to greybus_message_sent. This will be put to more use by a follow-up up patch. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Tested-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-22greybus: operation: fix operation orderingJohan Hovold
Make the operation work queue single threaded. The operation work queue was meant to be single threaded, but due to a missing flag instead allowed one active task per CPU, something which could lead to requests being processed out of order on SMP systems. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Tested-by: Rui Miguel Silva <rui.silva@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-20greybus: operation: fix atomic message submissionJohan Hovold
The recently added GFP-flags argument to gb_message_send was never used. Fixes: 9218fac2a24d ("operation: allow atomic request submissions") Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-20greybus: operation: fix atomic response allocationJohan Hovold
Response allocation also needs a GFP-flags argument as a response is allocated as part of an outgoing operation. Fixes: 9aa174d202e5 ("operation: allow atomic operation allocations") Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-15greybus: operation: add gb_operation_sync_timeout helperJohan Hovold
Add gb_operation_sync_timeout convenience function, which allows drivers to configure the operation timeout. Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-15greybus: operation: allow drivers to define custom timeoutsJohan Hovold
Add new interface gb_operation_request_send_sync_timeout, which allows drivers to define a custom operation timeout instead of the default one-second timeout. The timeout is expected to depend on protocol and operation and therefore needs to be configurable. Note that that a timeout of zero is used to wait indefinitely. Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-07-15greybus: operation: split incoming and outgoing cancellationJohan Hovold
Split incoming and outgoing operation-cancellation helpers. Incoming operations are only cancelled as part of connection tear down and is specifically not needed in the driver API. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>