platform/kernel/linux-rpi.git
9 years agogreybus: operation: allow drivers to define custom timeouts
Johan Hovold [Tue, 14 Jul 2015 13:43:36 +0000 (15:43 +0200)]
greybus: operation: allow drivers to define custom timeouts

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>
9 years agogreybus: operation: split incoming and outgoing cancellation
Johan Hovold [Tue, 14 Jul 2015 13:43:35 +0000 (15:43 +0200)]
greybus: operation: split incoming and outgoing cancellation

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>
9 years agogreybus: operation: fix response-cancellation race
Johan Hovold [Tue, 14 Jul 2015 13:43:34 +0000 (15:43 +0200)]
greybus: operation: fix response-cancellation race

Make sure the request handler has submitted the response before
cancelling it during operation cancellation.

This prevents cancelling not-yet-submitted messages. It currently also
avoids us ending up with an active message on a stalled connection (e.g.
due to E2EFC).

Note that the call to gb_operation_result_set() is now redundant but is
kept as a precaution to guarantee that a response has indeed been
allocated as part of response submission.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: fix operation look-up race
Johan Hovold [Tue, 14 Jul 2015 13:43:33 +0000 (15:43 +0200)]
greybus: operation: fix operation look-up race

Make sure to fully initialise the operation before adding it to the
active list when sending a request.

The operation should be fully initialised before adding it to the active
list to avoid racing with operation look up when receiving a response,
something which could potentially lead to a match against some earlier
(or intermediate) value of the id field.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: connection: fix protocol tear-down race
Johan Hovold [Tue, 14 Jul 2015 13:43:32 +0000 (15:43 +0200)]
greybus: connection: fix protocol tear-down race

Make sure to cancel all active operations before calling protocol
connection_exit to prevent use-after-free issues when the protocol state
is being deallocated (e.g. late processing of already-queued requests or
completions).

Note that already-queued requests or completions will be processed as
part of cancellation.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: fix connection tear down
Johan Hovold [Tue, 14 Jul 2015 13:43:31 +0000 (15:43 +0200)]
greybus: operation: fix connection tear down

Fix connection tear down, which was done in an unsafe way that could
result in use-after-free as the per-connection list of operations was
iterated without any locking or refcounting.

Specifically, the operations list was iterated without holding any locks or
operation refcounts even though operations were being both removed from
the list and deallocated during per-operation cancellation. Any
operation completing during tear down could also cause corruption.

Change the per-connection operation list to only contain active
operations and use the recently introduced active counter to maintain
the list.

Add new helper that is called on connection tear down to cancel all
outstanding operations in a safe way by using proper locks and making
sure to hold a reference to any operation being cancelled.

Note that by verifying the connection state before incrementing the
active count we can make sure that all active operations have been
cancelled and that no new ones have been started when the helper
returns.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: connection: add connection-state locking
Johan Hovold [Tue, 14 Jul 2015 13:43:30 +0000 (15:43 +0200)]
greybus: connection: add connection-state locking

Add locking, and the implied barriers, to connection-state updates.

This will be used to fix a number of races in the operations and
connection-tear-down implementations.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: suppress response submission on connection tear down
Johan Hovold [Tue, 14 Jul 2015 13:43:29 +0000 (15:43 +0200)]
greybus: operation: suppress response submission on connection tear down

Suppress response submission on connection tear down as we do with
requests.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: clean up operation work function
Johan Hovold [Tue, 14 Jul 2015 13:43:28 +0000 (15:43 +0200)]
greybus: operation: clean up operation work function

Call request handler helper explicitly from the work function rather
than overload the operation completion callback.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: complete operations on cancellation
Johan Hovold [Tue, 14 Jul 2015 13:43:27 +0000 (15:43 +0200)]
greybus: operation: complete operations on cancellation

Make sure to call the operation completion callback also when the
operation is being cancelled.

The completion callback may need to release resources allocated at
submission and the driver should be informed that the operation has
failed due to cancellation.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: make cancellation synchronous
Johan Hovold [Tue, 14 Jul 2015 13:43:26 +0000 (15:43 +0200)]
greybus: operation: make cancellation synchronous

Make sure to wait for the operation to become inactive before returning
after having cancelled an operation.

This makes sure that any ongoing operation completion callbacks have
finished.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: add active counter
Johan Hovold [Tue, 14 Jul 2015 13:43:25 +0000 (15:43 +0200)]
greybus: operation: add active counter

Add active counter to track operations that are in use.

Note that the active count is always less than the reference count.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: clean up create-incoming error path
Johan Hovold [Tue, 14 Jul 2015 13:43:24 +0000 (15:43 +0200)]
greybus: operation: clean up create-incoming error path

Clean up gb_operation_create_incoming error path by returning
immediately on allocation failures.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: fix another cancellation use-after-free
Johan Hovold [Tue, 14 Jul 2015 13:43:23 +0000 (15:43 +0200)]
greybus: operation: fix another cancellation use-after-free

An incoming operation could already be scheduled even if
gb_operation_result_set succeeds as its initial status is -EINPROGRESS.

Avoid potential use-after-free by never dropping the reference count for
incoming operations as part of cancellation.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: uart: fix typo in defintion
Bryan O'Donoghue [Tue, 14 Jul 2015 01:10:18 +0000 (02:10 +0100)]
greybus: uart: fix typo in defintion

Fixing needless redefinition of operation types in gbsim reveals this typo
GB_UART_TYPE_SET_BREAK -> GB_UART_TYPE_SEND_BREAK. This patch should be
applied in lock-step to the patch to gbsim 'gbsim/uart: remove unnecessary
redefinition of operation types' since gbsim does not contain the typo.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: loopback: fix 64bit printf format error
Bryan O'Donoghue [Mon, 13 Jul 2015 23:53:13 +0000 (00:53 +0100)]
greybus: loopback: fix 64bit printf format error

Last patchset missed compilation on 64 bit contained warning.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: loopback: fix broken tabs in greybus_protocols.h
Bryan O'Donoghue [Mon, 13 Jul 2015 23:53:12 +0000 (00:53 +0100)]
greybus: loopback: fix broken tabs in greybus_protocols.h

Copy/paste of code from one file to another missed inappropriate use of tab
after define.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: loopback: update throughput metrics to improve granularity
Bryan O'Donoghue [Mon, 13 Jul 2015 19:20:51 +0000 (20:20 +0100)]
greybus: loopback: update throughput metrics to improve granularity

Throughput capture should account for the entire size of the data going out
on the wire. In addition throughput should be captured for each supported
loopback operation.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: loopback: truncate maximum loop data to link size
Bryan O'Donoghue [Mon, 13 Jul 2015 19:20:50 +0000 (20:20 +0100)]
greybus: loopback: truncate maximum loop data to link size

Get maximum payload by way of gb_operation_get_payload_size_max() and
truncate any requested loopback size greater than this value. RX of data
from firmware over the specified size will not be accepted.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: loopback: add sink to loopback protocol
Bryan O'Donoghue [Mon, 13 Jul 2015 19:20:49 +0000 (20:20 +0100)]
greybus: loopback: add sink to loopback protocol

Loopback sink command will operate as an amalgam of the ping and tranfer
operations. Sink will send an ACK'd variable size operation over greybus.
Unlike the transfer type which transmits the received data back, the sink
type will simply ACK without sending the received data back.

This patch adds the kernel side of the sink command.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: loopback: make loopback type input equivalent to protocol type
Bryan O'Donoghue [Mon, 13 Jul 2015 19:20:48 +0000 (20:20 +0100)]
greybus: loopback: make loopback type input equivalent to protocol type

Sepcifying loopback operation type with a type value that is internal to
the loopback driver is non-intunitive and requires reading code to
understand. Remove confusing duplicate definitions and update code to
accept the greybus-specification function identity defintiions as the
appropriate type values for initiating loopback operations.

See greybus-spec section 10.16.1 'Greybus Loopback Message Types' for a
full list of valid messages to set this type field to.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: loopback: remove spurious pr_err in sysfs store
Bryan O'Donoghue [Mon, 13 Jul 2015 19:20:47 +0000 (20:20 +0100)]
greybus: loopback: remove spurious pr_err in sysfs store

Dangling debug code removed.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: loopback: remove magic number in state-machine
Bryan O'Donoghue [Mon, 13 Jul 2015 19:20:46 +0000 (20:20 +0100)]
greybus: loopback: remove magic number in state-machine

Magic number 2 used instead of define GB_LOOPBACK_TYPE_PING, remove and and
use the define instead.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: loopback: Move loopback operation definitions
Bryan O'Donoghue [Mon, 13 Jul 2015 19:20:45 +0000 (20:20 +0100)]
greybus: loopback: Move loopback operation definitions

In order to have one point of type definition for gbsim move the loopback
operation definitions to greybus_protocols.h.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: Cleanup connection leftovers
Viresh Kumar [Thu, 9 Jul 2015 05:26:30 +0000 (10:56 +0530)]
greybus: Cleanup connection leftovers

This wouldn't happen normally, but in a buggy corner case it is possible
that all the connections aren't removed properly and they are still
present after the interfaces and endo are removed.

Warn in such a case and cleanup connections, so that /sys/bus/greybus/
can be removed while removing greybus modules.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: fix incoming-response corruption
Johan Hovold [Thu, 9 Jul 2015 13:18:01 +0000 (15:18 +0200)]
greybus: operation: fix incoming-response corruption

Make sure not to update the response message buffer for an operation
that is already scheduled for completion.

Currently if we get two incoming responses with the same id, the second
one would overwrite the response message buffer.

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>
9 years agogreybus: operation: fix outgoing-response corruption
Johan Hovold [Thu, 9 Jul 2015 13:18:00 +0000 (15:18 +0200)]
greybus: operation: fix outgoing-response corruption

Fix potential corruption of outgoing responses by verifying that the
operations is indeed outgoing when receiving a response.

Failure to do so could lead to an incoming response corrupting an
outgoing response that uses the same operation id.

Reported-by: Viresh Kumar <viresh.kumar@linaro.org>
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>
9 years agogreybus: operation: fix use-after-free in response receive path
Johan Hovold [Thu, 9 Jul 2015 13:17:59 +0000 (15:17 +0200)]
greybus: operation: fix use-after-free in response receive path

Fix potential use-after-free in response receive path, due to lack of
reference counting when looking up operations on a connection.

Make sure to acquire a reference to the operation while holding the
connection-list lock.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: fix operation-destroy race
Johan Hovold [Thu, 9 Jul 2015 13:17:58 +0000 (15:17 +0200)]
greybus: operation: fix operation-destroy race

Make sure to acquire the connection-list lock atomically when releasing
the final reference.

This allows the list to be traversed and references to be acquired
(while holding the lock) without racing with the destructor.

Suggested-by: Greg Kroah-Hartman <gregkh@google.com>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: properly cleanup ida and idr structures when shutting down
Greg Kroah-Hartman [Wed, 8 Jul 2015 17:44:09 +0000 (10:44 -0700)]
greybus: properly cleanup ida and idr structures when shutting down

idr and ida structures have internal memory allocated that needs to be
freed when modules are removed.  So call the proper idr_destroy() or
ida_destroy() functions on the module exit path to free the memory.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Alex Elder <elder@linaro.org>
9 years agogreybus: svc: save pointer to struct gb_svc in struct gb_interface
Viresh Kumar [Fri, 3 Jul 2015 11:30:30 +0000 (17:00 +0530)]
greybus: svc: save pointer to struct gb_svc in struct gb_interface

Its another special protocol (just like control protocol) and is
required to be accessed from other files, lets save a pointer to it in
interface structure.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: svc: SVC is part of greybus core
Viresh Kumar [Fri, 3 Jul 2015 11:30:29 +0000 (17:00 +0530)]
greybus: svc: SVC is part of greybus core

Its an essential part of greybus core and shouldn't be present as a
separate module. Make it part of greybus.ko module.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: connection: Use connection->dev for printing messages
Viresh Kumar [Fri, 3 Jul 2015 11:30:27 +0000 (17:00 +0530)]
greybus: connection: Use connection->dev for printing messages

We failed to bind a protocol for the connection, not for bundle. And so
connection's 'dev' must be used for printing message.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: interface: Fix comment mistake (s/add/init)
Viresh Kumar [Fri, 3 Jul 2015 11:30:26 +0000 (17:00 +0530)]
greybus: interface: Fix comment mistake (s/add/init)

Function's name is gb_interface_init(), not gb_interface_add().

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: connection: Exit connection before destroying it
Viresh Kumar [Fri, 3 Jul 2015 11:30:25 +0000 (17:00 +0530)]
greybus: connection: Exit connection before destroying it

gb_connection_create() can initialize a connection if bundle->device id
is valid. And so the connection must be destroyed by calling
gb_connection_exit() before gb_connection_destroy(). This wasn't done in
the code that is parsing the manifest.

Fix it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: sdio: fix transfer buffer handling and blocks counting
Rui Miguel Silva [Thu, 2 Jul 2015 18:11:37 +0000 (19:11 +0100)]
greybus: sdio: fix transfer buffer handling and blocks counting

Fix copy to/from scatterlist destination buffer offset, fix
calculation of blocks to be transfer and make a more verbose out of
error when the blocks receive/send do not match.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: sdio: add need poll to host caps
Rui Miguel Silva [Thu, 2 Jul 2015 18:11:36 +0000 (19:11 +0100)]
greybus: sdio: add need poll to host caps

As we do not have, yet, a event callback to notify core about changes
we add the MMC_CAP_NEEDS_POLL capability to the rest of the caps
received from the module.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: sdio: check number of blocks in transfer
Rui Miguel Silva [Thu, 2 Jul 2015 18:11:35 +0000 (19:11 +0100)]
greybus: sdio: check number of blocks in transfer

Before initiating a transfers, check if the command (for single block)
match the number of blocks in the request.

While at it, fix also a missing break.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: sdio: pass only data pointer to tranfer funtion
Rui Miguel Silva [Thu, 2 Jul 2015 18:11:34 +0000 (19:11 +0100)]
greybus: sdio: pass only data pointer to tranfer funtion

No need to pass the all request to the transfer related funtctions.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: sdio: fix call to stop command if no data exist
Rui Miguel Silva [Thu, 2 Jul 2015 18:11:33 +0000 (19:11 +0100)]
greybus: sdio: fix call to stop command if no data exist

If data is not available the stop command could dereference NULL.
Fetch the stop command directly from the request instead.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: sdio: fix return of get_cd and get_ro
Rui Miguel Silva [Thu, 2 Jul 2015 18:11:32 +0000 (19:11 +0100)]
greybus: sdio: fix return of get_cd and get_ro

Functions were returning the wrong flag for the expected value. Swap
them.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: sdio: rework of event handler
Rui Miguel Silva [Thu, 2 Jul 2015 18:11:31 +0000 (19:11 +0100)]
greybus: sdio: rework of event handler

Between the time connection with module is up and the host is added,
we can receive events (card inserted/removed, write protection
switch), so until the setup is complete we queue the events received
and handle them after.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: sdio: split cmd_flags to there meaning
Rui Miguel Silva [Thu, 2 Jul 2015 18:11:30 +0000 (19:11 +0100)]
greybus: sdio: split cmd_flags to there meaning

Instead of using values in the command cmd_flags field use the real
flags in a bit mask.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: Revert "examples: add manifest file for sdio"
Greg Kroah-Hartman [Mon, 6 Jul 2015 01:11:21 +0000 (18:11 -0700)]
greybus: Revert "examples: add manifest file for sdio"

This reverts commit 22690d72ae145cf12ae3df033670ed8ad7ecdde7.

It was meant for the gbsim repo, not this one :(

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: examples: add manifest file for sdio
Rui Miguel Silva [Thu, 2 Jul 2015 18:32:05 +0000 (19:32 +0100)]
greybus: examples: add manifest file for sdio

Add example manifest file for sdio.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: makefile: fix unused cflags
Perry Hung [Fri, 3 Jul 2015 04:27:12 +0000 (00:27 -0400)]
greybus: makefile: fix unused cflags

The ccflags variable was spelled wrong, so no extra compilation flags
could be specified.

The proper flag is 'ccflags-y.'

Signed-off-by: Perry Hung <perry@leaflabs.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: fix cancellation of responses
Johan Hovold [Wed, 1 Jul 2015 10:37:31 +0000 (12:37 +0200)]
greybus: operation: fix cancellation of responses

An operation with a response in-flight will already have set the
operation result and would therefore never be cancelled by the current
implementation.

Note that the reference taken when sending the result will be dropped
in the message completion callback.

Also note that an incoming, non-unidirectional messages will always have
an allocated response if its result has been set.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: allocate response before setting result
Johan Hovold [Wed, 1 Jul 2015 10:37:30 +0000 (12:37 +0200)]
greybus: operation: allocate response before setting result

Make sure to allocate a response message before setting the operation
result.

This is needed to handle cancellation of incoming operations.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: drop redundant oom message
Johan Hovold [Wed, 1 Jul 2015 10:37:29 +0000 (12:37 +0200)]
greybus: operation: drop redundant oom message

Drop redundant OOM message, which would already have been logged by the
memory subsystem.

Also remove a FIXME about possibly sending a pre-allocated response,
which is neither possible or desirable. If we ever run out of memory we
have bigger problems then getting a response back to firmware.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: remove obsolete operation-field comments
Johan Hovold [Wed, 1 Jul 2015 10:37:28 +0000 (12:37 +0200)]
greybus: operation: remove obsolete operation-field comments

Remove obsolete operation-field comments.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: add unidirectional-operation flag
Johan Hovold [Wed, 1 Jul 2015 10:37:27 +0000 (12:37 +0200)]
greybus: operation: add unidirectional-operation flag

Add flag to identify unidirectional operations.

Use convenience helper rather than open coding the identification when
suppressing response messages.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: add incoming-operation flag
Johan Hovold [Wed, 1 Jul 2015 10:37:26 +0000 (12:37 +0200)]
greybus: operation: add incoming-operation flag

Add flag field to struct gb_operation, and a first flag
GB_OPERATION_FLAG_INCOMING to identify incoming operations.

Pass an initial set of flags when allocating new operations, and use
these to identify incoming operations rather than overloading the
meaning of GB_OPERATION_TYPE_INVALID. This also allows us to set the
type for all operations during allocation.

Also add convenience helper to identify incoming operations.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: fix cancellation use-after-free
Johan Hovold [Wed, 1 Jul 2015 10:37:25 +0000 (12:37 +0200)]
greybus: operation: fix cancellation use-after-free

The final reference of an operation will be put after its completion
handler has run, so we must not drop the reference if it has already
been scheduled to avoid use-after-free.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: make response helper static
Johan Hovold [Wed, 1 Jul 2015 10:37:24 +0000 (12:37 +0200)]
greybus: operation: make response helper static

Since commit 46ce118a2678 ("operation: refactor response handling")
sending operation responses is handled by greybus core so there is
currently no need to export the response helper.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: allow atomic request submissions
Johan Hovold [Wed, 1 Jul 2015 10:37:23 +0000 (12:37 +0200)]
greybus: operation: allow atomic request submissions

Add gfp mask argument to gb_operation_request_send in order to allow
submissions from atomic context.

Note that responses are currently always sent from non-atomic context as
incoming requests are processed in a work queue.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation: allow atomic operation allocations
Johan Hovold [Wed, 1 Jul 2015 10:37:22 +0000 (12:37 +0200)]
greybus: operation: allow atomic operation allocations

Add gfp mask argument to gb_operation_create to allow operations to be
allocated in atomic context.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: operation/esx: fix message-cancellation lifetime bugs
Johan Hovold [Wed, 1 Jul 2015 10:37:21 +0000 (12:37 +0200)]
greybus: operation/esx: fix message-cancellation lifetime bugs

The current host-controller message-cancellation implementation suffer
from a lifetime bug as dynamically allocated URBs would complete and be
deallocated while being unlinked as part of cancellation.

The current locking is also insufficient to prevent the related race
where the URB is deallocated before being unlinked.

Fix this by pushing the cancellation implementation from greybus core
down to the host-controller drivers, and replace the "cookie" pointer
with a hcpriv field that those drivers can use to maintain their state
with the required locking and reference counting in place.

Specifically the drivers need to acquire a reference to the URB under a
lock before calling usb_kill_urb as part of cancellation.

Note that this also removes the insufficient gb_message_mutex, which
also effectively prevented us from implementing support for submissions
from atomic context.

Instead the host-controller drivers must now explicitly make sure that
the pre-allocated URBs are not reused while cancellation is in progress.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: bundles: remove gb_bundle(s)_init()
Viresh Kumar [Wed, 1 Jul 2015 06:43:59 +0000 (12:13 +0530)]
greybus: bundles: remove gb_bundle(s)_init()

They aren't used anymore, remove them. This also gets rid of
gb_bundle_connections_init().

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>
9 years agogreybus: interface: device_id belongs to the interface
Viresh Kumar [Wed, 1 Jul 2015 06:43:58 +0000 (12:13 +0530)]
greybus: interface: device_id belongs to the interface

While introducing bundles, the device_id also got moved to the bundle,
whereas it identifies an interface block to the AP.

Move it back to interface instead of bundle.

Calls to gb_bundle(s)_init() are dropped as connections will be
initialized while they are created now, as device_id will be valid.

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>
9 years agogreybus: svc: Drop svc_set_route_send()
Viresh Kumar [Wed, 1 Jul 2015 06:43:57 +0000 (12:13 +0530)]
greybus: svc: Drop svc_set_route_send()

The responsibility of this routine is to configure ARA switch to
establish a connection between a cport on the AP and a cport on an
interface.

The SVC protocol is responsible for such requests and we already have
connection_{create|destroy}_operation() to take care of this.

Moreover, this request is not served by the firmware or gbsim today and
they just print a debug message on this request. And so it is safe to
drop svc_set_route_send() function and fix the required functionality of
configuring the switch in svc protocol driver later.

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>
9 years agogreybus: connection: intf_cport_id is local to an interface
Viresh Kumar [Wed, 1 Jul 2015 06:43:56 +0000 (12:13 +0530)]
greybus: connection: intf_cport_id is local to an interface

intf_cport_id is local to an interface and same intf_cport_id can be
used for two separate interface blocks. For finding a connection for an
interface, we are matching intf_cport_id of the connection with
cport_id, passed as argument. This is wrong, as it can match for a
connection on a different interface block.

Fix it by also comparing interface block for which connection is
requested.

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>
9 years agogreybus: connection: bind protocol after the connection is operational
Viresh Kumar [Wed, 1 Jul 2015 06:43:54 +0000 (12:13 +0530)]
greybus: connection: bind protocol after the connection is operational

We may bind protocol with a connection from gb_connection_create(), if
bundle's device_id is already set. That's not the case until now.

But if the protocol is initialized with a call to
protocol->connection_init() from this place, kernel will crash.

This will happen because the connection isn't fully initialized yet, for
example its operation list isn't initialized yet. And as soon as the
protocol driver tries to send a request to the module from its
connection_init() callback, we will add an operation to this
uninitialized list. And it will crash while doing:

        prev->next = new;

Try to bind the connection with a protocol only after the connection is
ready for operations.

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>
9 years agogreybus: control: Use gb_builtin_protocol_driver()
Viresh Kumar [Wed, 1 Jul 2015 06:43:53 +0000 (12:13 +0530)]
greybus: control: Use gb_builtin_protocol_driver()

No need to write simple init/exit routines, use
gb_builtin_protocol_driver().

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>
9 years agogreybus: Rename gb_gpbridge_protocol_driver() as gb_builtin_protocol_driver()
Viresh Kumar [Wed, 1 Jul 2015 06:43:52 +0000 (12:13 +0530)]
greybus: Rename gb_gpbridge_protocol_driver() as gb_builtin_protocol_driver()

This macro is also required by core protocols like control and svc, and
hence the 'gpbridge' name doesn't fit anymore.

Lets call this macro gb_builtin_protocol_driver().

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>
9 years agogreybus: svc: Use macro's for major/minor numbers
Viresh Kumar [Wed, 1 Jul 2015 06:43:51 +0000 (12:13 +0530)]
greybus: svc: Use macro's for major/minor numbers

We have already defined macro's for SVC's major/minor numbers, lets use
them.

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>
9 years agogreybus: svc: Fix doc-style comment
Viresh Kumar [Wed, 1 Jul 2015 06:43:50 +0000 (12:13 +0530)]
greybus: svc: Fix doc-style comment

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>
9 years agogreybus: uart: Update UART to reflect field size changes
Bryan O'Donoghue [Mon, 29 Jun 2015 17:09:15 +0000 (18:09 +0100)]
greybus: uart: Update UART to reflect field size changes

The greybus UART protocol specification was updated to reduce the size of
the control field in serial-state-request and line-state-request. This
patch updates the kernel protocol driver to reflect the specification
changes. Once applied gbsim changes will be also be updated automatically
since gbsim depends on the header being modified directly.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: uart: Add support for UART error signals
Bryan O'Donoghue [Mon, 29 Jun 2015 17:09:14 +0000 (18:09 +0100)]
greybus: uart: Add support for UART error signals

After reviewing the UART specification for greybus break, parity, framing
and over-run errors were moved to the receive-data message. This patch
implements that specification change in the UART protocol driver. Matching
code in gbsim has been tested with this change.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: uart: Relocate UART parity/overrun/framing/break signals
Bryan O'Donoghue [Mon, 29 Jun 2015 17:09:13 +0000 (18:09 +0100)]
greybus: uart: Relocate UART parity/overrun/framing/break signals

Parity/overrun/framing and break signals have been moved to the
receive-data message to more easily associate the signals with the TTY API.
Update the definitions in the protocol header and add a flags field to the
receive-data structure to facilitate transmission of those signal with the
receive-data message.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: define more greybus classes
Viresh Kumar [Tue, 30 Jun 2015 06:10:18 +0000 (11:40 +0530)]
greybus: define more greybus classes

There are new protocols defined which don't belong to any existing
class, add more classes to support them.

Reported-by: Alexandre Bailon <abailon@baylibre.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: sdio: correct the usage of mmc request in work queues handler
Phong Tran [Fri, 26 Jun 2015 14:05:13 +0000 (21:05 +0700)]
greybus: sdio: correct the usage of mmc request in work queues handler

The mmc request should assigned before use. Then
It should avoid freeing before using in mmc_request_done().

Signed-off-by: Phong Tran <tranmanphong@gmail.com>
Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Reviewed-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: sdio: change the order of remove and free mmc host
Phong Tran [Fri, 26 Jun 2015 14:05:12 +0000 (21:05 +0700)]
greybus: sdio: change the order of remove and free mmc host

The mmc host should be removed frist. Then it
will be freed.

Signed-off-by: Phong Tran <tranmanphong@gmail.com>
Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Reviewed-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: sdio: remove the redefine of sdio major and minor
Phong Tran [Fri, 26 Jun 2015 14:05:11 +0000 (21:05 +0700)]
greybus: sdio: remove the redefine of sdio major and minor

The macro of sdio version major and minor is defined twice.
This patch remove the redundant one.

Signed-off-by: Phong Tran <tranmanphong@gmail.com>
Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Reviewed-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: gb-audio: Ensure i2c adapter struct exists before using
Mark Greer [Fri, 26 Jun 2015 23:38:46 +0000 (16:38 -0700)]
greybus: gb-audio: Ensure i2c adapter struct exists before using

The current audio code uses i2c_get_adapter() without checking
that a non-NULL pointer is returned (i.e., that the i2c device
actually exists).  When that happens, the system panics.
Fix the potential panic by erroring out with -ENODEV when
i2c_get_adapter() returns NULL.

CC: John Stultz <john.stultz@linaro.com>
Signed-off-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: esx: fix null-deref on hotplug events
Johan Hovold [Tue, 23 Jun 2015 12:17:41 +0000 (14:17 +0200)]
greybus: esx: fix null-deref on hotplug events

We must be prepared to receive hotplug events as soon as we submit the
SVC URB. Since commit 2eb8a6a947d7 ("core: don't set up endo until host
device is initialized") this is no longer the case as the endo would not
have been setup, something which may lead to a null-pointer dereference
in endo_get_module_id() when the interface is created (see oops below
with an added dev_dbg for hd->endo).

Fix this by setting up the endo before submitting the SVC URB.

[   28.810610] gb_interface_create - hd->endo =   (null)
[   28.816020] Unable to handle kernel NULL pointer dereference at virtual address 0000022b
[   28.824952] pgd = c0004000
[   28.827880] [0000022b] *pgd=00000000
[   28.831913] Internal error: Oops: 17 [#1] PREEMPT ARM
[   28.837183] Modules linked in: gb_es1(O+) greybus(O) netconsole
[   28.843419] CPU: 0 PID: 21 Comm: kworker/u2:1 Tainted: G           O    4.1.0-rc7 #12
[   28.851576] Hardware name: Generic AM33XX (Flattened Device Tree)
[   28.857978] Workqueue: greybus_ap ap_process_event [greybus]
[   28.863890] task: cf2961c0 ti: cf29c000 task.ti: cf29c000
[   28.869529] PC is at endo_get_module_id+0x18/0x88 [greybus]
[   28.875355] LR is at gb_interface_add+0x88/0x204 [greybus]
[   28.881070] pc : [<bf0052d4>]    lr : [<bf005dac>]    psr: 20070013
[   28.881070] sp : cf29de08  ip : cf29de18  fp : cf29de14
[   28.893021] r10: 00000001  r9 : 0000005a  r8 : cd813ec6
[   28.898461] r7 : 00000058  r6 : cf7fa200  r5 : 00000001  r4 : cf7fa20c
[   28.905261] r3 : 00000000  r2 : cf2961c0  r1 : 00000001  r0 : 00000000
[   28.912067] Flags: nzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment kernel
[   28.919677] Control: 10c5387d  Table: 8f508019  DAC: 00000015
[   28.925663] Process kworker/u2:1 (pid: 21, stack limit = 0xcf29c210)
[   28.932279] Stack: (0xcf29de08 to 0xcf29e000)
[   28.936823] de00:                   cf29de44 cf29de18 bf005dac bf0052c8 00000058 cd813ec0
[   28.945349] de20: cf58b60c bf00afe0 cf7fa200 cf58b600 0000005a 00000001 cf29de84 cf29de48
[   28.953865] de40: bf004844 bf005d30 00000000 cf02d800 cf29de6c cf29de60 c00759a0 cf58b60c
[   28.962389] de60: cf2742c0 cf02d800 cf0c6000 cf29dea8 c07b745c 00000000 cf29dee4 cf29de88
[   28.970908] de80: c005943c bf004560 00000001 00000000 c0059354 cf02d800 c0059c0c 00000001
[   28.979426] dea0: 00000000 00000000 bf00b314 00000000 00000000 bf009144 c04e3710 cf02d800
[   28.987945] dec0: cf2742d8 cf02d830 00000088 c0059bd0 00000000 cf2742c0 cf29df24 cf29dee8
[   28.996464] dee0: c0059b78 c0059248 cf29c000 cf245d40 c0776890 c07b6bf3 00000000 00000000
[   29.004983] df00: cf245d40 cf2742c0 c0059b20 00000000 00000000 00000000 cf29dfac cf29df28
[   29.013502] df20: c005fe90 c0059b2c c07812d0 00000000 cf29df4c cf2742c0 00000000 00000001
[   29.022025] df40: dead4ead ffffffff ffffffff c07c86b0 00000000 00000000 c05fd8e8 cf29df5c
[   29.030542] df60: cf29df5c 00000000 00000001 dead4ead ffffffff ffffffff c07c86b0 00000000
[   29.039062] df80: 00000000 c05fd8e8 cf29df88 cf29df88 cf245d40 c005fd98 00000000 00000000
[   29.047581] dfa0: 00000000 cf29dfb0 c00108f8 c005fda4 00000000 00000000 00000000 00000000
[   29.056105] dfc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[   29.064623] dfe0: 00000000 00000000 00000000 00000000 00000013 00000000 ffff0000 ffff0000
[   29.073178] [<bf0052d4>] (endo_get_module_id [greybus]) from [<bf005dac>] (gb_interface_add+0x88/0x204 [greybus])
[   29.083887] [<bf005dac>] (gb_interface_add [greybus]) from [<bf004844>] (ap_process_event+0x2f0/0x4d8 [greybus])
[   29.094527] [<bf004844>] (ap_process_event [greybus]) from [<c005943c>] (process_one_work+0x200/0x8e4)
[   29.104228] [<c005943c>] (process_one_work) from [<c0059b78>] (worker_thread+0x58/0x500)
[   29.112668] [<c0059b78>] (worker_thread) from [<c005fe90>] (kthread+0xf8/0x110)
[   29.120295] [<c005fe90>] (kthread) from [<c00108f8>] (ret_from_fork+0x14/0x3c)
[   29.127825] Code: e24cb004 e52de004 e8bd4000 e3510000 (e5d0c22b)
[   29.137481] ---[ end trace ad95c3c26bdc98ce ]---

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: kernel_ver: add sg copy operations for kernel < 3.11
Rui Miguel Silva [Wed, 24 Jun 2015 22:20:27 +0000 (23:20 +0100)]
greybus: kernel_ver: add sg copy operations for kernel < 3.11

For older kernel, < 3.11, no copy to/from buffer with skip support was
defined. This could break builds for this versions of kernel.
Add them here.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Tested-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: sdio: fix defines for older kernels
Rui Miguel Silva [Wed, 24 Jun 2015 22:20:26 +0000 (23:20 +0100)]
greybus: sdio: fix defines for older kernels

Some of the options for mmc host, are not defined in older kernels.
MMC_CAP2_HS400_1_2V, MMC_CAP2_HS400_1_8V, MMC_TIMING_MMC_DDR52 and
MMC_TIMING_MMC_HS400.

To not use them for older versions.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Tested-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: control: Warn if non-control cport/bundles have control protocol/classes
Viresh Kumar [Mon, 22 Jun 2015 11:12:30 +0000 (16:42 +0530)]
greybus: control: Warn if non-control cport/bundles have control protocol/classes

It is possible that (by mistake) the manifest contains non-control
cports with their protocol set as control-protocol or non-control bundle
with their class set as control-class.

Catch such cases, WARN for them and finally ignore them.

Also WARN if the control cport doesn't have its protocol as
control-protocol and control bundle doesn't have its class as
control-class.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: connection: send [dis]connected events over control CPort
Viresh Kumar [Mon, 22 Jun 2015 11:12:29 +0000 (16:42 +0530)]
greybus: connection: send [dis]connected events over control CPort

The AP needs to send connected and disconnection events to all
interfaces, before a CPort (other than control CPort) can be used.

For now do it which we initialize the connection, but it should be moved
to operations code later.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: hotplug function doesn't need to contain manifest now
Viresh Kumar [Mon, 22 Jun 2015 11:12:28 +0000 (16:42 +0530)]
greybus: hotplug function doesn't need to contain manifest now

Manifest is fetched with control protocol now and so we don't need space
for it in hotplug data.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: interface: Get manifest using Control protocol
Viresh Kumar [Mon, 22 Jun 2015 11:12:27 +0000 (16:42 +0530)]
greybus: interface: Get manifest using Control protocol

Control protocol is ready to be used for fetching manifest. Lets do it.

This changes few things:
- Creates/initializes bundle/connection for control protocol initially
  and skips doing the same later.
- Manifest is parsed at link-up now, instead of hotplug which was the
  case earlier. This is because we need device_id (provided during
  link-up) for registering bundle.
- Manifest is fetched using control protocol.

So the sequence of events is:

Event                 Previously       Now
-----                 ----------       ---
Interface Hotplug     create intf      create intf
                      parse mfst

Interface Link Up     init bundles     create control conn
                                       get mfst size
                                       get mfst
                                       parse mfst
                                       init bundles

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: Add control protocol support
Viresh Kumar [Mon, 22 Jun 2015 11:12:26 +0000 (16:42 +0530)]
greybus: Add control protocol support

Add control protocol driver that is responsible for handling operations
on control CPort. The AP also needs to support incoming requests on its
control port. Features not implemented yet are marked as TODO for now.

NOTE: This also fixes cport-bundle-id to 0 and cport-id to 2 for control
protocol.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: manifest: Allow bundles/connections list to be non-empty at manifest parsing
Viresh Kumar [Mon, 22 Jun 2015 11:06:47 +0000 (16:36 +0530)]
greybus: manifest: Allow bundles/connections list to be non-empty at manifest parsing

A connection and a bundle will be created for interfaces at the very
beginning for control protocol's functioning. And so the list of bundles
and connections for a interface will be non-empty by the time manifest
is parsed.

Currently we are firing a WARN when these lists are found to be
non-empty. Lets fix that to contain single bundle and connection for
control protocol.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: sdio: extend sdio implementation
Rui Miguel Silva [Mon, 22 Jun 2015 13:03:52 +0000 (14:03 +0100)]
greybus: sdio: extend sdio implementation

Extend sdio implementation, as it for now it was basically stubs.

This implementation is compile tested only since there is no fw or
simulation support yet.
Next step is to add sdio support to gbsim and test it with success
using the mmc_test facility.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: makefile: add MMC to the required option list
Rui Miguel Silva [Mon, 22 Jun 2015 13:03:51 +0000 (14:03 +0100)]
greybus: makefile: add MMC to the required option list

Add MMC to the list of options that shall be enable.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: uart: Fix sparse warning
Bryan O'Donoghue [Thu, 18 Jun 2015 15:41:58 +0000 (16:41 +0100)]
greybus: uart: Fix sparse warning

Greg reported sparse picked up the following warning:
/home/gregkh/ara/greybus/uart.c:105:34: warning: cast to restricted __le16

This is due to the control variable in gb_uart_serial_state_request which
needs to be declared __le16 not __u16.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reported-by: Greg Kroah-Hartman <gregkh@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: uart: Latch modem control signals for tciomget
Bryan O'Donoghue [Tue, 16 Jun 2015 10:28:11 +0000 (11:28 +0100)]
greybus: uart: Latch modem control signals for tciomget

Latch signals coming from UART module for
- GB_UART_CTRL_DCD
- GB_UART_CTRL_DSR
- GB_UART_CTRL_RI

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: Revert "greybus: reserve host cport id 0"
Greg Kroah-Hartman [Wed, 17 Jun 2015 02:43:05 +0000 (19:43 -0700)]
greybus: Revert "greybus: reserve host cport id 0"

This reverts commit 698d4bd3e7541a660a3c3665f0af9e787650a239 as Alex
says it is broken.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: Merge branch alex into Alexandre
Greg Kroah-Hartman [Mon, 15 Jun 2015 23:53:23 +0000 (16:53 -0700)]
greybus: Merge branch alex into Alexandre

This resolves a conflict with es2.c that I fixed up.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: es2.c: add a control request for endpoints mapping
Alexandre Bailon [Mon, 15 Jun 2015 16:08:14 +0000 (18:08 +0200)]
greybus: es2.c: add a control request for endpoints mapping

ES2 give us more endpoints. Use them to map one cport to two endpoints
(in and out). Because there is more cports than endpoints, we still
need to mux other cports traffic on 2 endpoints.
Firmware currently assumes these endpoints are 2 and 3.

By default, all cports are muxed.
To map one cport to 2 endpoints, use map_cport_to_ep().

Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: es2.c: Increase the number of bulk endpoints
Alexandre Bailon [Mon, 15 Jun 2015 16:08:13 +0000 (18:08 +0200)]
greybus: es2.c: Increase the number of bulk endpoints

ES2 support 16 endpoints. Update es2.c to allocate endpoints, urbs
and buffers for these new endpoints.

Currently, they are not yet used and es2.c is working in legacy mode
(only original endpoints are used).

Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: es2.c: create dedicated struct for cport_in and cport_out
Alexandre Bailon [Mon, 15 Jun 2015 16:08:12 +0000 (18:08 +0200)]
greybus: es2.c: create dedicated struct for cport_in and cport_out

Instead of keep cport buffers, urbs and endpoints in es1_ap_dev,
move them in two dedicated struct (es1_cport_in and es1_cport_out),
in order to ease the migration to es2 (increase the number of endpoint).

Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: es2.c: Don't use magic value for USB control request
Alexandre Bailon [Mon, 15 Jun 2015 16:08:11 +0000 (18:08 +0200)]
greybus: es2.c: Don't use magic value for USB control request

Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: es1.c: Don't use magic value for USB control request
Alexandre Bailon [Mon, 15 Jun 2015 16:08:10 +0000 (18:08 +0200)]
greybus: es1.c: Don't use magic value for USB control request

Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: esX: use one byte to encode cport ids in header
Alex Elder [Sat, 13 Jun 2015 16:02:11 +0000 (11:02 -0500)]
greybus: esX: use one byte to encode cport ids in header

We now limit the maximum value for both host and module CPort ids,
and we know they can always be represented in a single byte.

Make use of this by using only one of the two pad bytes for encoding
the CPort id in a message header.

(Note that we have never used a CPort higher than 255.  Encoding
such a small CPort id in little endian 2-byte format has the same
result as what is done here.)

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: reserve host cport id 0
Alex Elder [Sat, 13 Jun 2015 16:02:10 +0000 (11:02 -0500)]
greybus: reserve host cport id 0

For ES1 and ES2, we use pad bytes in an operation message header to
encode the CPort ID used for transferring the message.  The pad
bytes should otherwise be zero, and we ensure this as the message
is passed to or from the upper layer.

If host-side CPort ID 0 is used, we have no way of knowing whether
the CPort field has been "packed" into the header.

To allow detection of this, reserve host CPort id 0.  Update
cport_id_valid() to treat 0 as invalid.

(CPort ID 0 is reserved by one of the UniPro standards.  We'll
assume for now that we never use it for Greybus.)

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: rename HOST_DEV_CPORT_ID_MAX
Alex Elder [Sat, 13 Jun 2015 16:02:09 +0000 (11:02 -0500)]
greybus: rename HOST_DEV_CPORT_ID_MAX

We limit the number of host-side CPorts to a fixed maximum (which
is less than the 4096 that UniPro allows).  This patch imposes a
similar limit on the CPort IDs defined by modules (signaling an
error if one too large is found in a manifest).

It seems reasonable to use the same value for both limits.  Change
the name of the constant that defines the host limit and use it for
both.  Update cport_id_valid() to enforce the maximum.

(Ultimately we should impose a limit like this; this change is being
made in preparation for supporting multiple connections over a
single CPort.)

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: esX: encapsulate packing cport id into header
Alex Elder [Sat, 13 Jun 2015 16:02:08 +0000 (11:02 -0500)]
greybus: esX: encapsulate packing cport id into header

For the ES1 and ES2 host interfaces we encode the CPort ID over
which the message should be sent within the message itself.  The
CPort ID is recorded in unused pad bytes found in the operation
message header in order to avoid introducing misaligned messages.

This patch defines some helper routines to abstract this activity.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: introduce cport_id_valid()
Alex Elder [Sat, 13 Jun 2015 16:02:07 +0000 (11:02 -0500)]
greybus: introduce cport_id_valid()

Define a public predicate that defines whether a CPort ID is valid.

Use it in the message_send() routine, and make the message reported
more accurately reflect the error.  Also use it to check whether the
CPort ID in a received message is valid; if it is not, just drop the
message.

Get rid of local variable "buffer" in message_send(); it adds no
value.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
9 years agogreybus: manifest: clean up properly when parsing bundles
Alex Elder [Fri, 12 Jun 2015 15:21:12 +0000 (10:21 -0500)]
greybus: manifest: clean up properly when parsing bundles

Currently, if an error occurs creating a bundle, we simply
return an error without cleaning up any of the bundles that
had already been successfully set up.

Add code to destroy bundles that have been created in the event
an error occurs.  Add a check to ensure the interface's list of
bundles was empty before parsing for bundles begins.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>