platform/kernel/linux-rpi.git
8 years agogreybus: define BUNDLE_ID_NONE
Alex Elder [Fri, 3 Jun 2016 20:55:30 +0000 (15:55 -0500)]
greybus: define BUNDLE_ID_NONE

Define a bundle ID that means "no bundle".  This will be used for
tracing connection events during the portion of a connection's
lifetime when it has no bundle associated with it.  Don't allow
any bundle to be created using that ID.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: fix "make check" warnings
Alex Elder [Fri, 3 Jun 2016 20:55:29 +0000 (15:55 -0500)]
greybus: tracing: fix "make check" warnings

Some of the trace buffer fields were defined as Booleans.  This
leads to two problems reported by "make check":
    - the __field() macro (or some descendent macro) performs
      a sizeof(bool) operation, which results in a warning
    - The TP_printk() macro, which specifies a printf() style
      format string, produces a warning when one attempts to
      format a Boolean as an integer.
Fix both problems implicitly converting Boolean values from the data
structures into integers in the trace buffer.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: camera-gb: Implement camera module reference counting as subject.
Evgeniy Borisov [Tue, 31 May 2016 08:33:11 +0000 (11:33 +0300)]
greybus: camera-gb: Implement camera module reference counting as subject.

In explanation:

The main idea for implementing reference counting is to not block exit
until any other modules are in use. Camera responsibility is to handle
properly any additional calls after camera exit and that what this
patch is doing:

1. Free camera module when reference count is zero.
2. After camera cleanup handle properly any additional ongoing
   transaction. Return error if connection is destroyed.

Signed-off-by: Evgeniy Borisov <eborisov@mm-sol.com>
Reviewed-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: camera-gb: Extend gb camera module structure
Evgeniy Borisov [Tue, 31 May 2016 08:33:10 +0000 (11:33 +0300)]
greybus: camera-gb: Extend gb camera module structure

Add additional information in gb camera module.
 - interface ID
 - reference count
 - release handle

Signed-off-by: Evgeniy Borisov <eborisov@mm-sol.com>
Reviewed-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: camera-gb: Add description of interface header
Evgeniy Borisov [Tue, 31 May 2016 08:33:09 +0000 (11:33 +0300)]
greybus: camera-gb: Add description of interface header

Add description for all interface structures in
gb-camera.h.

Signed-off-by: Evgeniy Borisov <eborisov@mm-sol.com>
Reviewed-by: Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: Add comment about the mode_switch_started flag
Viresh Kumar [Mon, 30 May 2016 09:02:09 +0000 (14:32 +0530)]
greybus: Add comment about the mode_switch_started flag

Add a comment to describe the purpose of the flag.

Suggested-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: interface: Mode switch takes over a second
Viresh Kumar [Mon, 30 May 2016 07:35:10 +0000 (13:05 +0530)]
greybus: interface: Mode switch takes over a second

Mode switch takes just over a second to complete and the current timeout
of one second isn't sufficient.

Mode-switch logs from EVT 1.5:

[   56.709082] gb-firmware 1-3.3.1: Requested firmware package 'ara_00000126_00001002_fffe0001_ff980067_03.tftf'
[   57.003968] gb_control_mode_switch_operation: 176
[   58.041616] greybus 1-3.3: mode switch detected

Increase the timeout to two seconds.

Tested with EVT 1.5 with gpbridge-test module.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Karthik Ravi Shankar <karthikrs@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: control: Mode-switch is a 'core' operation
Viresh Kumar [Mon, 30 May 2016 07:35:09 +0000 (13:05 +0530)]
greybus: control: Mode-switch is a 'core' operation

The operation layer allows only the 'core' operations on a connection,
which is in its 'disconnecting' state.

Mode switch is sent at the very end of interface-disable sequence, and
the control connection is already in its 'disconnecting' state at that
time. And so gb_operation_get_active() always fail with error -ENOTCONN.

The operation core already has support for such 'core' operations, just
that we were missing the needed flag while creating the mode switch
operation.

Fix that.

Tested on EVT 1.5 with gpbridge-test module.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Karthik Ravi Shankar <karthikrs@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: fw-mgmt: Add hooks to do mode-switch
Viresh Kumar [Mon, 30 May 2016 07:35:08 +0000 (13:05 +0530)]
greybus: fw-mgmt: Add hooks to do mode-switch

This is the last step to required to finish the mode switch story.  That
is, call the hook provided by Interface layer to accomplish mode switch.

Tested on EVT 1.5 with gpbridge-test module.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Karthik Ravi Shankar <karthikrs@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: gbphy: Remove protocol specific version handling
Viresh Kumar [Mon, 30 May 2016 06:01:53 +0000 (11:31 +0530)]
greybus: gbphy: Remove protocol specific version handling

We should be using the generic version handling at bundle level, instead
of at protocol level for bridged PHY devices as well.

The bundle version handling is already in place, though it is *not* used
today as we haven't bumped the version of control protocol yet.

Remove protocol specific handling for bridged PHY devices.

Tested on EVT 1.5 with gpbridge-test module. No nuttx changes are
required with this.

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>
8 years agogreybus: Remove unused VERSION specific macros
Viresh Kumar [Mon, 30 May 2016 06:01:52 +0000 (11:31 +0530)]
greybus: Remove unused VERSION specific macros

We don't use these anymore. Drop them.

Note that some macro's specific to bridged PHY devices aren't removed in
the patch, as gbsim will break otherwise. They will be removed
separately.

Compile tested.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: uart: wait for credits on shutdown
Axel Haslam [Tue, 31 May 2016 12:36:13 +0000 (14:36 +0200)]
greybus: uart: wait for credits on shutdown

We should try to wait until all credits are accounted
for before returning from shutdown.

For this purpose add a helper function that will
wait on completion, and call it form the shutdown.
This helper will also be useful when "wait until sent" is
implemented.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: uart: Implement flush_buffer
Axel Haslam [Tue, 31 May 2016 12:36:12 +0000 (14:36 +0200)]
greybus: uart: Implement flush_buffer

Data may be held pening in the hardware because of flow
control mechanisms. When the port is closed, we need to flush
all data that was not sent.

For this, use the greybus message GB_UART_TYPE_FLUSH_FIFOS
which will flush all data queued on the module but not
yet sent on the data line.

Suggested-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: uart: Add credits based tracking for transmit path
Axel Haslam [Tue, 31 May 2016 12:36:11 +0000 (14:36 +0200)]
greybus: uart: Add credits based tracking for transmit path

To avoid polling the firmware for space, a credit based system
is implemented.

The host will keep track of how many credits (bytes) it has
sent to the firmware, and stop sending data when the quota
is filled.

The host will be informed that the firmware has more
room for data when it handles the receive_credits request
message from the firmware, and will continue to write data
as credits become available.

The firmware and the host may implement an algorithm to aggregate
credits, and avoid extra greybus traffic.

Suggested-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: uart: Use a fifo to send data to the modules
Axel Haslam [Tue, 31 May 2016 12:36:10 +0000 (14:36 +0200)]
greybus: uart: Use a fifo to send data to the modules

The firmware now buffers data instead of blocking while the transfer
is sent, and the write operation cannot sleep.

Instead of using gb_transfer_sync (which sleeps) in the write callback,
buffer data in a fifo and send it from from a work queue.

The write_room callback will will report 1 byte less that what is really
available in the fifo, to leave space for extra characters that may
be added by the tty layer.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: uart: Implement dtr_rts callback.
Axel Haslam [Tue, 31 May 2016 12:36:09 +0000 (14:36 +0200)]
greybus: uart: Implement dtr_rts callback.

Dtr_dts allows the tty layer to set the flow control lines
to the correct state during open and close.

Note that locking for newctrl is missing throughout the
driver and will be addressed on a separate patch.

Suggested-and-reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: uart: Handle CRTSCTS flag in termios
Axel Haslam [Tue, 31 May 2016 12:36:08 +0000 (14:36 +0200)]
greybus: uart: Handle CRTSCTS flag in termios

Handle the CRTSCTS flag in set_termios, so that auto
flow control can be turned off. For this, add a new flag
in the line coding request specifically for this purpose.

Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: hd: fix gb_hd_release tracepoint
Johan Hovold [Fri, 27 May 2016 16:23:01 +0000 (18:23 +0200)]
greybus: hd: fix gb_hd_release tracepoint

The recently added gb_hd_release tracepoint was added to the wrong
function.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: fix tracepoint-related whitespace issues
Johan Hovold [Fri, 27 May 2016 16:23:02 +0000 (18:23 +0200)]
greybus: fix tracepoint-related whitespace issues

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>
8 years agogreybus: svc: remove deprecated hotplug operations
Johan Hovold [Fri, 27 May 2016 15:26:41 +0000 (17:26 +0200)]
greybus: svc: remove deprecated hotplug operations

Now that firmware has made the switch to the new interface boot
sequence, we can remove support for the deprecated hotplug and
hot-unplug operations.

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>
8 years agogreybus: interface: implement generic mode-switch functionality
Johan Hovold [Fri, 27 May 2016 15:26:40 +0000 (17:26 +0200)]
greybus: interface: implement generic mode-switch functionality

Add a generic interface for bundle drivers to use to request that a
mode switch is carried out on its behalf.

Mode switching involves tearing down all connections to an interface,
sending a unidirectional mode-switch request, and waiting for a mailbox
event that triggers deferred control connection reset and re-enumeration
of the interface. In case of a timeout waiting for the interface mailbox
event, or on other errors, the interface is powered off.

All of this needs to be done by core from work-queue context in order
not to block incoming SVC requests and bundle-device tear down. Care
must also be taken to serialise against concurrent module removal events
and eject requests.

Special handling of legacy mode-switching is also added in order to
continue to support the ES3 bootrom.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: control: add error message to mode-switch helper
Johan Hovold [Fri, 27 May 2016 15:26:39 +0000 (17:26 +0200)]
greybus: control: add error message to mode-switch helper

Print an informative error message in case sending the mode-switch
request fails.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: kernel_ver: backport reinit_completion to pre-3.13
Johan Hovold [Fri, 27 May 2016 15:26:38 +0000 (17:26 +0200)]
greybus: kernel_ver: backport reinit_completion to pre-3.13

Backport upstream reinit_completion() to pre-3.13 kernels.

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>
8 years agogreybus: connection: add flush host-device callback
Johan Hovold [Fri, 27 May 2016 15:26:37 +0000 (17:26 +0200)]
greybus: connection: add flush host-device callback

Add a new host-device callback to flush any host-device queues,
including any ongoing transfers, as part of connection tear down.

The host-device buffers are flushed after the disconnecting operation
have completed and the AP queues have been emptied.

This can be used to flush already queued messages which upon reception
would have been discarded by the remote end anyway.

Note that this does not remove the need to flush any host-device queues
as part of CPort disable which needs to make the CPort ready for reuse
after deallocating all associated state and resetting the port.

Suggested-by: Mitchell Tasman <tasman@leaflabs.com>
Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: connection: implement proper connection closure
Johan Hovold [Fri, 27 May 2016 15:26:36 +0000 (17:26 +0200)]
greybus: connection: implement proper connection closure

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>
8 years agogreybus: operation: add helper for creating core operations
Johan Hovold [Fri, 27 May 2016 15:26:35 +0000 (17:26 +0200)]
greybus: operation: add helper for creating core operations

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>
8 years agogreybus: operation: restructure activation state handling
Johan Hovold [Fri, 27 May 2016 15:26:34 +0000 (17:26 +0200)]
greybus: operation: restructure activation state handling

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>
8 years agogreybus: operation: clean up early connection-state check
Johan Hovold [Fri, 27 May 2016 15:26:33 +0000 (17:26 +0200)]
greybus: operation: clean up early connection-state check

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>
8 years agogreybus: connection: remove unused invalid state
Johan Hovold [Fri, 27 May 2016 15:26:32 +0000 (17:26 +0200)]
greybus: connection: remove unused invalid state

Remove the unused legacy INVALID connection state.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: connection: move CPort Buffer configuration out of svc helpers
Johan Hovold [Fri, 27 May 2016 15:26:31 +0000 (17:26 +0200)]
greybus: connection: move CPort Buffer configuration out of svc helpers

The CPort Buffer configuration in the host-device needs to match the
CPort feature flags set by the SVC, but they need not always be
configured at the same point in time.

This will be used when implementing proper connection tear down.

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>
8 years agogreybus: connection: rename an error label
Johan Hovold [Fri, 27 May 2016 15:26:30 +0000 (17:26 +0200)]
greybus: connection: rename an error label

Rename an error label to make it more descriptive.

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>
8 years agogreybus: es2: reset cports at disable
Johan Hovold [Fri, 27 May 2016 15:26:29 +0000 (17:26 +0200)]
greybus: es2: reset cports at disable

Make sure to reset CPorts at disable rather than enable as per
specification.

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>
8 years agogreybus: connection: log cport-enable error messages
Johan Hovold [Fri, 27 May 2016 15:26:28 +0000 (17:26 +0200)]
greybus: connection: log cport-enable error messages

Log failures to disable a host cport, and include the connection name in
cport enable/disable error messages.

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>
8 years agogreybus: svc: add stub connection-quiescing operation
Johan Hovold [Fri, 27 May 2016 15:26:27 +0000 (17:26 +0200)]
greybus: svc: add stub connection-quiescing operation

Add stubbed out connection-quiescing operation that is needed for proper
connection tear down.

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>
8 years agogreybus: control: implement disconnecting operation
Johan Hovold [Fri, 27 May 2016 15:26:26 +0000 (17:26 +0200)]
greybus: control: implement disconnecting operation

Implement the new disconnecting control operation needed for proper
connection tear down.

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>
8 years agogreybus: connection: add control connection flag
Johan Hovold [Fri, 27 May 2016 15:26:25 +0000 (17:26 +0200)]
greybus: connection: add control connection flag

Add control connection flag which will be set for control connections.

Also add a helper function to test if the flag is set.

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>
8 years agogreybus: interface: avoid I/O to bootrom during removal
Johan Hovold [Fri, 27 May 2016 15:26:24 +0000 (17:26 +0200)]
greybus: interface: avoid I/O to bootrom during removal

Add an interface quirk flag to suppress I/O during interface disable.

This is needed to prevent I/O to the bootrom during controlled
connection tear down (e.g. eject or driver unbind). This will be more
obvious with the new connection tear-down procedure.

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>
8 years agogreybus: interface: clean up bootrom quirk handling
Johan Hovold [Fri, 27 May 2016 15:26:23 +0000 (17:26 +0200)]
greybus: interface: clean up bootrom quirk handling

Clean up bootrom quirk handling in preparation for addition of further
flags.

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>
8 years agogreybus: core: avoid I/O to disconnected interfaces
Johan Hovold [Fri, 27 May 2016 15:26:22 +0000 (17:26 +0200)]
greybus: core: avoid I/O to disconnected interfaces

Add new helper to disable connections to interfaces that have already
been disconnected (e.g. forcibly removed).

The connection tear-down procedure differs enough depending on whether
the interface is still present or already gone to warrant a dedicated
helper. This will become more obvious with the new tear-down procedure,
which involves I/O on the connection being tore down.

This also simplifies handling of the legacy bootrom, which does not
support the new tear-down operations.

Specifically, this allows us to remove the early control-connection
tear down during interface disable, and also avoids some error messages
currently printed during legacy mode switch (i.e. bootrom
boot-over-UniPro) and forcible removal.

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>
8 years agogreybus: drop a bogus semicolon
Alex Elder [Tue, 24 May 2016 18:34:52 +0000 (13:34 -0500)]
greybus: drop a bogus semicolon

Coccinelle reports that gb_svc_pwrmon_debugfs_init() has a block of
a for loop which is followed by an unnecessary semicolon.  Get rid
of that semicolon.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: use PTR_ERR_OR_ZERO()
Alex Elder [Tue, 24 May 2016 18:34:51 +0000 (13:34 -0500)]
greybus: use PTR_ERR_OR_ZERO()

Coccinelle points out that the macro PTR_ERR_OR_ZERO() handles the
frequent case of converting a pointer into either error code (if its
value is an encoded error value) or 0 (otherwise).  Switch some code
in gb_power_supply_register() to use that macro.  I have verified
this is true of the kernel we're now working with (arche-6.0).

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: fix pointless null check
Alex Elder [Tue, 24 May 2016 18:34:50 +0000 (13:34 -0500)]
greybus: fix pointless null check

Coccinelle points out that a call in gb_lights_channel_free() to
flush_work() is passed which is always non-null.   Prior to the
call, there is an unnecessary check to see if that address is null.
Get rid of the test.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: eliminate unneeded null check
Alex Elder [Tue, 24 May 2016 18:34:49 +0000 (13:34 -0500)]
greybus: eliminate unneeded null check

Coccinelle points out that debugfs_remove_recursive() handles a null
argument properly, so there's no need to check for NULL before
making the call.  I have verified this is true of the kernel we're
now working with (arche-6.0).

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: fix unbalanced mutex
Alex Elder [Tue, 24 May 2016 18:34:48 +0000 (13:34 -0500)]
greybus: fix unbalanced mutex

Running "make coccicheck" on the Greybus code reports that
gb_mmc_get_ro() and gb_mmc_get_cd() can return without releasing
the mutex it acquired if there's an error.  Fix this.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: report right error value
Alex Elder [Tue, 24 May 2016 18:34:47 +0000 (13:34 -0500)]
greybus: report right error value

Running "make coccicheck" on the Greybus code discovered that
an error message in gb_camera_debugfs_init() was interpreting
the wrong value in reporting the error code.  Fix that.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: es2: Release reserved cports CDSI0 and CDSI1
Vaibhav Agarwal [Fri, 27 May 2016 05:19:24 +0000 (10:49 +0530)]
greybus: es2: Release reserved cports CDSI0 and CDSI1

Unique ids were reserved for CDSI0 and CDSI1 during _probe, however
missed to release those ids during disconnect. This causes a memory leak
of 128 bytes for each iteration of unipro_reset. Fix this.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: hd: Add API to release reserved CPorts
Vaibhav Agarwal [Fri, 27 May 2016 05:19:23 +0000 (10:49 +0530)]
greybus: hd: Add API to release reserved CPorts

It is required to release all unique ids registered via ida_get_simple
to avoid any possible memory leak. cport_release() already exists with
special handling for ES2_CPORT_CDSI1, i.e. updating in_use flag without
removing associated ida.

So, added another API to release reserved cports CDSI0 and CDSI1. This
is intended to  be used only during es2_destroy().

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: define interface traces
Alex Elder [Tue, 24 May 2016 04:05:32 +0000 (23:05 -0500)]
greybus: tracing: define interface traces

Define a new gb_module trace point event class, used to trace events
associated with the interface abstraction.  Define four basic trace
points for this--creation time, drop of last reference, before
registring interfaces and after de-registering them.  In addition,
define traces for activating and deactivating, and enabling and
disabling an interface.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: add module traces
Alex Elder [Tue, 24 May 2016 04:05:31 +0000 (23:05 -0500)]
greybus: tracing: add module traces

Define a new gb_module trace point event class, used to trace events
associated with the module abstraction.  Define four basic trace
points for this--creation time, drop of last reference, before
registring interfaces and after de-registering them.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: fix hd traces
Alex Elder [Tue, 24 May 2016 04:05:30 +0000 (23:05 -0500)]
greybus: tracing: fix hd traces

Currently there are two trace points defined for the Greybus host
device structure.  One records information when a message gets sent,
and another when it gets received.  Neither of these is really a
host device event.

We have trace points defined for messages that dump information
about all sent and received messages.  As a result, the information
about sending messages over a host is redundant, and can go away.
(Note that the message traces may need a little refinement so they
produce all desired information.)

Instead of these trace points, define some that are directly
related to the host device abstraction: when one is created,
added, deleted, or released (destroyed).  These do not require
a CPort ID or payload size, so eliminate those two parameters
from the host device trace point prototype.  Change the trace
information recorded for a host device to be just a subset of
interesting fields in a host device.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: fix a bad tracepoint
Alex Elder [Tue, 24 May 2016 04:05:29 +0000 (23:05 -0500)]
greybus: tracing: fix a bad tracepoint

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>
8 years agogreybus: remove redundant latency-tag sanity checks
Johan Hovold [Wed, 25 May 2016 20:18:15 +0000 (22:18 +0200)]
greybus: remove redundant latency-tag sanity checks

Core will never call host-device callbacks with invalid arguments (and
that would still need to be verified in bridge firmware anyway), so
remove the redundant and insufficient sanity check from the callbacks.

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>
8 years agogreybus: interface: fix svc-resource error messages
Johan Hovold [Wed, 25 May 2016 20:18:14 +0000 (22:18 +0200)]
greybus: interface: fix svc-resource error messages

The interface svc-resource helper are used to enable as well as disable
the corresponding SVC resources so make sure the error messages reflect
that.

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>
8 years agogreybus: Documentation/sysfs: gbphy0 is an invalid name
Viresh Kumar [Wed, 25 May 2016 07:19:26 +0000 (12:49 +0530)]
greybus: Documentation/sysfs: gbphy0 is an invalid name

The numbering of gbphy devices is going to start from 1 and not 0.
Reflect the same in sysfs hierarchy.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: Documentation/sysfs: Rename gpbridge to gbphy
Viresh Kumar [Wed, 25 May 2016 07:16:24 +0000 (12:46 +0530)]
greybus: Documentation/sysfs: Rename gpbridge to gbphy

These were left in the earlier renaming series, fix them as well.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: Fix loopback app after rename to gpphy
Axel Haslam [Tue, 24 May 2016 14:21:29 +0000 (16:21 +0200)]
greybus: Fix loopback app after rename to gpphy

commit 6d94670 gpbridge: rename 'gpbridge' to 'gbphy' everywhere
missed renaming the loopback test app. So do it too.

Testing done: complie and run loopback test

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Enable SVC clock during FW_FLASHING state
Vaibhav Hiremath [Tue, 24 May 2016 13:02:04 +0000 (18:32 +0530)]
greybus: arche-platform: Enable SVC clock during FW_FLASHING state

The issue is, as part of kernel-only build we started seeing
failures in SVC FW flashing. It was reproducible easily in kernel-only
build, but never observed on Android build.

During debugging, there were couple of observations,

1. If SVC clock enabled and disables (which is REFCLK_MAIN), then SVC FW
   flashing works.
2. If we do not switch SVC to HSE (external clock source) it works.
   Recently, SVC code has been updated to switch HSE clock, so removing
   it (remove/skip rcc_switch_ara_pll() fn) would use internal clock only.

As per STM32 spec, for flashing through USART we do not need
to enable HSE, but the above observation contradicts with it.

There is still something missing in terms of understanding of how STM32
device functions as far as Flashing is concerned. There is something
hidden in HW, which probably still need to identify.

So as a interim solution we will enable clock for FW_FLASHING state,
which seems to be fixing the issue here.

Testing Done: Tested on EVT1.5 with arche6.0 and kernel-only build.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Enter ACTIVE state only from OFF state
Vaibhav Hiremath [Tue, 24 May 2016 13:02:03 +0000 (18:32 +0530)]
greybus: arche-platform: Enter ACTIVE state only from OFF state

Make sure that, transition to active state happens only from OFF state.
Instead of imposing the restriction to user-space, driver internally
switches to OFF state and then to ACTIVE state.

Testing Done: Tested on EVT1.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Make fw_flashing_seq() return error
Vaibhav Hiremath [Tue, 24 May 2016 13:02:02 +0000 (18:32 +0530)]
greybus: arche-platform: Make fw_flashing_seq() return error

Make arche_platform_fw_flashing_seq() return error value, needed
later when we add clock enable support for FW flashing.

Testing Done: Tested on EVT1.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Tested-by: Michael Scott <michael.scott@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: Revert "update UniPro Set Interface Power Mode operation to match spec"
Jeffrey Carlyle [Wed, 25 May 2016 23:38:47 +0000 (16:38 -0700)]
greybus: Revert "update UniPro Set Interface Power Mode operation to match spec"

This reverts commit 29fee8c55b59bb6ac59b99a0563c89c514cba42b.

This change and its companion NuttX changes seem to be triggering a
storm of POWERMODEIND switch interrupts on the SVC.

Signed-off-by: Jeffrey Carlyle <jcarlyle@google.com>
Acked-by: Sandeep Patil <sspatil@google.com>
8 years agogreybus: update UniPro Set Interface Power Mode operation to match spec
Eli Sennesh [Mon, 16 May 2016 18:55:17 +0000 (14:55 -0400)]
greybus: update UniPro Set Interface Power Mode operation to match spec

Bring the gb_svc_intf_set_power_mode() up-to-date with the current Greybus
specification.  This largely involves adding more members to the structure
sent across the wire.  Also change the camera code to use the new
operation properly, with default values passed for the new necessary
arguments.  The correctness of these default values is confirmed via testing
and by asking Rob Johnson.

Testing Done: Took a picture with a camera module, received error code
when passing deliberately incorrect values for new parameters, got proper
-EIO and Greybus result code printed when operation stopped halfway
through.

Associated Firmware Changes: 6810-6812 on Gerrit for SW-1239, 6870 and
5612-5613 on Gerrit for SW-2945

Signed-off-by: Eli Sennesh <esennesh@leaflabs.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: Fix unbalanced irq_enable() backtrace
Bryan O'Donoghue [Mon, 23 May 2016 14:01:08 +0000 (15:01 +0100)]
greybus: Fix unbalanced irq_enable() backtrace

Tip-of-tree is exhibiting a backtrace when loading-up the set of greybus
kernel modules due to calling arche_platform_wd_irq_en() directly after a
call to devm_request_threaded_irq().

At the point we call arch_platform_wd_irq_en() the relevant IRQ will
already be enabled. What we want to do in this situation is configure the
GPIO line as an input. This patch fixes the backtrace by supplanting
arche_platform_wd_irq_en() with
gpio_direction_input(arche_pdata->wake_detect_gpio) in
arche_platform_probe().

WARNING: at msm-ara-3.10/kernel/irq/manage.c:457 __enable_irq+0x74/0xc0()
Unbalanced enable for IRQ 687
Modules linked in: gb_arche(O+) gb_camera(O) gb_es2(O) gb_vibrator(O)
gb_raw(O) gb_power_supply(O) gb_loopback(O) gb_light(O) gb_hid(O)
greybus(O)
CPU: 0 PID: 415 Comm: insmod Tainted: G        W  O 3.10.78-g2a4dec8 #65
Call trace:
[<ffffffc000206adc>] dump_backtrace+0x0/0x248
[<ffffffc000206d34>] show_stack+0x10/0x1c
[<ffffffc000c6c698>] dump_stack+0x1c/0x28
[<ffffffc00021c95c>] warn_slowpath_common+0x74/0x9c
[<ffffffc00021c9d0>] warn_slowpath_fmt+0x4c/0x58
[<ffffffc000269d7c>] __enable_irq+0x70/0xc0
[<ffffffc000269e34>] enable_irq+0x68/0x7c
[<ffffffbffc0609b4>] arche_platform_probe+0x3b4/0x4f4 [gb_arche]
[<ffffffc0005ace30>] platform_drv_probe+0x14/0x20
[<ffffffc0005ab980>] driver_probe_device+0x160/0x374
[<ffffffc0005abc40>] __driver_attach+0x60/0x90
[<ffffffc0005aa768>] bus_for_each_dev+0x74/0x94
[<ffffffc0005ab2c4>] driver_attach+0x1c/0x28
[<ffffffc0005aae74>] bus_add_driver+0x124/0x248
[<ffffffc0005ac270>] driver_register+0x94/0x110
[<ffffffc0005ad3c4>] platform_driver_register+0x58/0x64
[<ffffffbffc065020>] $x+0x20/0x58 [gb_arche]
[<ffffffc0002007dc>] do_one_initcall+0xb0/0x14c
[<ffffffc00028252c>] load_module+0x19d0/0x1b18
[<ffffffc00028278c>] SyS_init_module+0x118/0x130

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiermath@linaro.org>
Tested-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: audio: Fix memory leak
Vaibhav Agarwal [Mon, 23 May 2016 18:01:14 +0000 (23:31 +0530)]
greybus: audio: Fix memory leak

Topology data pointer was mistakenly set to NULL before freeing it. Fix
this.

Fixes: 64a86d9ba850 ("audio: Add module specific driver")
Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: legacy: remove protocol.o from the makefile
David Lin [Sat, 21 May 2016 01:37:02 +0000 (18:37 -0700)]
greybus: legacy: remove protocol.o from the makefile

Commit 0917cba11 ("legacy: remove legacy driver support")
removed protocol.c, however, the corresponding target in the Makefile
was not removed therefore broken the build.

Testing Done:
- Build & boot on EVT1.5

Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: refine comments
Alex Elder [Fri, 20 May 2016 16:44:57 +0000 (11:44 -0500)]
greybus: tracing: refine comments

I believe that duplicating the tracepoint name in comments prior to
the tracepoint is redundant, and doesn't add a lot of value.

I also believe that we can provide a little more information about
what exactly an event means, or when exactly it is called.

I don't claim this is a huge improvement, but it's a proposal.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Jeffrey Carlyle <jcarlyle@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: eliminate "location" comments
Alex Elder [Fri, 20 May 2016 16:44:56 +0000 (11:44 -0500)]
greybus: tracing: eliminate "location" comments

Each message event has a set of comments preceeding its definition.
One of them, "location", indicates where that event is used.  I
am certain that this comment will become out of date very easily.
Hopefully just the name of the event is a good enough suggestion
about where it will be used.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Jeffrey Carlyle <jcarlyle@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: tracing: define events using macros
Alex Elder [Fri, 20 May 2016 16:44:55 +0000 (11:44 -0500)]
greybus: tracing: define events using macros

A tracepoint event is defined with TP_PROTO() and TP_ARGS macros
that match that of the event's class.  A lot of repetition (and
opportunity for inadvertent errors) in tracepoint event definitions
can be eliminated by using a macro.  Define and use class-specific
event definition macros for gb_message and gb_host_device class
events.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Jeffrey Carlyle <jcarlyle@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: add operation traces
Alex Elder [Fri, 20 May 2016 16:59:57 +0000 (11:59 -0500)]
greybus: add operation traces

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>
8 years agogreybus: legacy: remove legacy driver support
David Lin [Fri, 20 May 2016 11:33:36 +0000 (14:33 +0300)]
greybus: legacy: remove legacy driver support

This patch removes the greybus legacy driver support

Signed-off-by: David Lin <dtwlin@google.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: camera: Convert to bundle driver
Laurent Pinchart [Fri, 20 May 2016 11:33:35 +0000 (14:33 +0300)]
greybus: camera: Convert to bundle driver

Convert the legacy camera protocol driver to a bundle driver.

Modules now can (and must) declare the camera data cport in their
manifest as the data connection isn't hardcoded anymore.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: fw-management: Fix error message's text
Viresh Kumar [Thu, 19 May 2016 12:56:27 +0000 (18:26 +0530)]
greybus: fw-management: Fix error message's text

Just reword it to make it sound better.

Compile tested.

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>
8 years agogreybus: fw-core: destroy connections on error
Viresh Kumar [Thu, 19 May 2016 12:57:25 +0000 (18:27 +0530)]
greybus: fw-core: destroy connections on error

In one of the error cases we aren't destroying the connections created
earlier. Fix it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: svc: use EREMOTEIO for remote errors
Johan Hovold [Thu, 19 May 2016 14:20:16 +0000 (16:20 +0200)]
greybus: svc: use EREMOTEIO for remote errors

Return -EREMOTEIO consistently for unspecified remote errors (e.g. a
failed DME attribute read due to a remote UniPro error).

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>
8 years agogreybus: audio_apbridgea: fix two return values
Johan Hovold [Thu, 19 May 2016 14:20:15 +0000 (16:20 +0200)]
greybus: audio_apbridgea: fix two return values

Errno -ENOSYS is reserved for missing syscalls, replace it with
-EOPNOTSUPP for the the two stub operations that used it.

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>
8 years agogreybus: svc: fix another pwrmon return value
Johan Hovold [Thu, 19 May 2016 14:20:14 +0000 (16:20 +0200)]
greybus: svc: fix another pwrmon return value

Errno -ENOSYS is reserved for missing syscalls, replace it with -ENOMSG.

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>
8 years agogreybus: arche-platform: Rename assert_wakedetect=>arche_platform_wd_irq_en
Vaibhav Hiremath [Tue, 17 May 2016 17:09:47 +0000 (22:39 +0530)]
greybus: arche-platform: Rename assert_wakedetect=>arche_platform_wd_irq_en

Now, since AP module does not send any signal to SVC, so it
automatically restricts the wake/detect gpio to input.
So rename assert_wakedetect() fn to arche_platform_wd_irq_en(),
as per implementation.

Testing Done: Tested on EVT1.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: arche-platform: Do not assert wake/detect signal to SVC
Vaibhav Hiremath [Tue, 17 May 2016 17:09:46 +0000 (22:39 +0530)]
greybus: arche-platform: Do not assert wake/detect signal to SVC

With new definition of AP module boot flow (from HotPlug camp),
AP is not supposed to send any wake/detect signal to SVC, instead,
during boot SVC would straight away send wake_out pulse on wake/detect
line.
Note that, pin configuration of wake/detect line would be set to
active-high by default, so wake/detect line would always stay high,
unless SVC drives it. AP module uses wake/detect line strictly in input
mode.

Testing Done: Tested on EVT1.5 platform.

Note: We are yet to decide on PM support for APBx, so we may need to
generate/handshake with SVC over wake/detect line in the future. As of
now, follow the implementation and add stuff as and when they come.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: gpbridge: rename 'gpbridge' to 'gbphy' everywhere
Sandeep Patil [Thu, 19 May 2016 15:52:39 +0000 (08:52 -0700)]
greybus: gpbridge: rename 'gpbridge' to 'gbphy' everywhere

The 'gpbridge' name didn't relaly reflect what the bus is; which
is a bus for bridged-phy devices. So, rename all instances
of 'gpbridge' to more appropriate 'gbphy'

Testing Done:
Build and boot tested. 'lsgb' will stop displaying 'GPBridge' devices
until I change the library to reflect this change.

Signed-off-by: Sandeep Patil <patil_sandeep@projectara.com>
Suggested-by: Greg Kroah-Hartman <gregkh@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: interface: retry enumeration of UniPro-only modules
Jeffrey Carlyle [Thu, 19 May 2016 01:55:13 +0000 (18:55 -0700)]
greybus: interface: retry enumeration of UniPro-only modules

Greybus modules will sometimes fail to send the mailbox poke and
erroneously be enumerated as UniPro-only modules. The root cause for
this on the module side is not fully understand, but it seems that this
may be due to "the bootrom bug:" a known problem with the bootrom where
linkup will occasionally fail because of a race condition.

Before the new hotplug code was implemented in the firmware, the SVC
would retry enumeration of modules that did not send the mailbox poke;
this patch ports that functionality to the AP.

Signed-off-by: Jeffrey Carlyle <jcarlyle@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: uart fix missing negation on DTR setting
Axel Haslam [Mon, 16 May 2016 15:39:32 +0000 (17:39 +0200)]
greybus: uart fix missing negation on DTR setting

The unset the DTR flag is missing "~"

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: connection: verify disabled when destroyed
Alex Elder [Tue, 17 May 2016 14:13:16 +0000 (09:13 -0500)]
greybus: connection: verify disabled when destroyed

A connection must be in DISABLED state before it gets destroyed.
Warn if this is ever not the case (and do the disconnect) before
proceeding with connection destruction.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: audio: gb_manager: Use valid argument while removing ida allocated id.
Vaibhav Agarwal [Tue, 17 May 2016 16:59:08 +0000 (22:29 +0530)]
greybus: audio: gb_manager: Use valid argument while removing ida allocated id.

module->id is used as an argument to ida_simple_remove(). Since module
is already dereferenced, module->id might contain invalid data. So fix
this.

Fixes: da4cc2d0b066 ("audio:gb_manager: Use proper locking around kobject_xxx")
Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: operation: fix broken activation logic
Johan Hovold [Wed, 18 May 2016 13:47:48 +0000 (15:47 +0200)]
greybus: operation: fix broken activation logic

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>
8 years agogreybus: operation: rate-limit dev_err printing on the receive path
Eli Sennesh [Fri, 13 May 2016 17:27:40 +0000 (13:27 -0400)]
greybus: operation: rate-limit dev_err printing on the receive path

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>
8 years agogreybus: spi: add inprogress bit to xfer_flags
Rui Miguel Silva [Mon, 16 May 2016 09:33:21 +0000 (10:33 +0100)]
greybus: spi: add inprogress bit to xfer_flags

When a SPI transfer needs to be split by more than one greybus spi
transfer operation, we need to indicate it so the controller can handle
the chip select lines correctly.

Add a new bit to indicate it, GB_SPI_XFER_INPROGRESS, and create an
helper function to calculate when the transfer is done. As we need this
information also in other places.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: spi: rename rdwr field to xfer_flags
Rui Miguel Silva [Mon, 16 May 2016 09:33:20 +0000 (10:33 +0100)]
greybus: spi: rename rdwr field to xfer_flags

As more bits will be added to the field, let's make the field more
generic and name it accordingly. So, rename it from rdwr to xfer_flags.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: fw-management: Update header's license
Viresh Kumar [Mon, 16 May 2016 15:24:53 +0000 (20:54 +0530)]
greybus: fw-management: Update header's license

The header should include both BSD and GPLv2 licenses and so should have
been a copy of greybus_protocols.h. This file had only the GPLv2 bits
earlier, update it to include BSD bits as well.

Reported-by: Greg Kroah-Hartman <gregkh@google.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: fw-management: Fix 'make check' warnings
Viresh Kumar [Mon, 16 May 2016 02:19:43 +0000 (07:49 +0530)]
greybus: fw-management: Fix 'make check' warnings

Fix below warnings observed with 'make check'.

~/ara/greybus/fw-management.c:438:33: warning: incorrect type in assignment (different base types)
~/ara/greybus/fw-management.c:438:33:    expected unsigned short [unsigned] [addressable] [assigned] [usertype] major
~/ara/greybus/fw-management.c:438:33:    got restricted __le16 [usertype] <noident>
~/ara/greybus/fw-management.c:439:33: warning: incorrect type in assignment (different base types)
~/ara/greybus/fw-management.c:439:33:    expected unsigned short [unsigned] [addressable] [assigned] [usertype] minor
~/ara/greybus/fw-management.c:439:33:    got restricted __le16 [usertype] <noident>

Reported-by: Greg Kroah-Hartman <gregkh@google.com>
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>
8 years agogreybus: fw-management: Replace double-tabs with space for structures
Viresh Kumar [Mon, 16 May 2016 02:19:45 +0000 (07:49 +0530)]
greybus: fw-management: Replace double-tabs with space for structures

Reformat structures to use a single space instead of multiple tabs.

Reported-by: Greg Kroah-Hartman <gregkh@google.com>
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>
8 years agogreybus: es2.c: Declare local __le64 not u64
Bryan O'Donoghue [Sun, 15 May 2016 22:34:51 +0000 (23:34 +0100)]
greybus: es2.c: Declare local __le64 not u64

The value passed to le64_to_cpu wants to be an __le64 not a u64.
Note to self - remember to run "make check"

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reported-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: interface: Extract and store Interface feature byte
Bryan O'Donoghue [Sun, 15 May 2016 18:37:49 +0000 (19:37 +0100)]
greybus: interface: Extract and store Interface feature byte

The Interface description in the Greybus specification contains a
'features' field which is currently not implemented on the AP side. The
Interface features field provides information on optional attributes of an
Interface as a bitmask. Currently only GREYBUS_INTERFACE_FEATURE_TIMESYNC
is implemented in the specification but, the expectation is that other
feature flags will be added over time.

This patch adds support to extract the feature byte communicated in the
features field of the Interface Descriptor header and extends struct
interface to contain a features field through which any user with a pointer
to struct interface may interrogate the features of an Interface.

This is a necessary pre-cursor for TimeSync to ensure only Interfaces which
declare GREYBUS_INTERFACE_FEATURE_TIMESYNC will be included when we go
through the process of FrameTime synchronization.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: hd: Add TimeSync APBridge commands
Bryan O'Donoghue [Sun, 15 May 2016 18:37:48 +0000 (19:37 +0100)]
greybus: hd: Add TimeSync APBridge commands

This patch adds a number of USB Vendor commands to es2.c to enable TimeSync
in the bridge.

Adds:
- es2.c::timesync_enable(u8 count, u64 frame_time, u32 strobe_delay,
 u32 refclk);
  Commands APBx to enable timers and clocks to track a pulse-train of
  incoming TIME_SYNC strobes with strobe_delay microseconds between each.
  Provides the reference clock the AP is using to track FrameTime. It is
  the responsibility of APBx to adequately track the FrameTime based on
  the indicated AP refclk. Once this command has succeeded APBx may not
  transition to a low-power state were FrameTime counters stop.

  This function is initiated from the timesync worker thread logic when
  re-synchronizing frame-time throughout the system.

  TimeSync is at this time enabled for all APBx active in the system i.e.
  currently APB2 will not receive TimeSync commands until it becomes a
  registered host-device in Greybus.

- es2.c::timesync_disable(void)
  Commands APBx to discontinue tracking of FrameTime. After this operation
  completes APBx may transition to a low-power state where timer-clocks
  stop operating.

- es2.c::timesync_authoritative(u64 *frame_time)
  Provides an authoritative time for each TIME_SYNC strobe to APBx.
  APBx must align its local FrameTime to the authoritative clock.

- es2.c::timesync_get_last_event(u64 *frame_time)
  Returns the FrameTime at the last SVC_TIMESYNC_PING to the AP Module.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: Documentation: Document firmware-management interfaces
Viresh Kumar [Sat, 14 May 2016 18:12:25 +0000 (23:42 +0530)]
greybus: Documentation: Document firmware-management interfaces

This patch adds a new 'firmware' folder in Documentation, which contains
two files:

- firmware-management: This describes the userspace interface for
  interacting with firmware-management bundle.

- firmware.c: Sample application to test firmware load for Interface
  Firmware and firmware updates to Backend Interface Firmware.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Jun Li <li_jun@projectara.com>
Tested-by: Karthik Ravi Shankar <karthikrs@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: firmware: Add SPI protocol support
Viresh Kumar [Sat, 14 May 2016 18:12:24 +0000 (23:42 +0530)]
greybus: firmware: Add SPI protocol support

This patch adds SPI Protocol support to firmware core, which allows the
AP to access an SPI flash memory present with an Interface.

Tested by using the API from fw-management driver and compiling it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: fw-management: Free fw-mgmt only after all users are gone
Viresh Kumar [Sat, 14 May 2016 18:12:23 +0000 (23:42 +0530)]
greybus: fw-management: Free fw-mgmt only after all users are gone

The fw-management driver rightly destroys the char device on
connection-exit, but that doesn't guarantee that all of the users of the
device are gone.

Userspace may still be holding file-descriptor of the char device and
can initiate new ioctl operations. And that *will* lead to kernel crash.

To avoid this issue, manage struct users with kref, manage a list of
'struct fw-mgmt' and start using the structure only after getting its
kref incremented.

The important part is the routine get_fw_mgmt(), which increments the
reference to the struct before returning it to the caller. The list of
fw-mgmt structs in protected with a mutex to avoid any races around
that.

The kref is incremented once the char device is opened and dropped only
when it is closed.

Reported-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: fw-management: Add ioctl to initiate mode-switch
Viresh Kumar [Sat, 14 May 2016 18:12:22 +0000 (23:42 +0530)]
greybus: fw-management: Add ioctl to initiate mode-switch

Once the interface firmware is loaded successfully to a module,
userspace can ask it to mode switch to the newly loaded firmware.

This patch provides a new ioctl to initiate mode switch.

Userspace can initiate a mode switch if it has previously loaded the
interface firmware successfully, otherwise the firmware core rejects it.

Also, once the mode-switch is initiated, disallow any more interactions
from the userspace.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Karthik Ravi Shankar <karthikrs@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: fw-management: Add firmware-management protocol driver
Viresh Kumar [Sat, 14 May 2016 18:12:21 +0000 (23:42 +0530)]
greybus: fw-management: Add firmware-management protocol driver

This patch adds Firmware Management Protocol support to firmware core,
which allows the AP to manage firmware on an Interface.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Jun Li <li_jun@projectara.com>
Tested-by: Karthik Ravi Shankar <karthikrs@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: make greybus_gpbdev_type static
Greg Kroah-Hartman [Sat, 14 May 2016 17:22:24 +0000 (19:22 +0200)]
greybus: make greybus_gpbdev_type static

'make check' correctly complains that this should be static, so make it
so.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: spi: Separate out spilib from spi bridged PHY bundle driver
Viresh Kumar [Sat, 14 May 2016 18:12:20 +0000 (23:42 +0530)]
greybus: spi: Separate out spilib from spi bridged PHY bundle driver

spilib can be used by multiple bridge drivers implementing different
bundle classes. Separate out bridged PHY bundle drivers parts.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: spi: Restructure spi.c to share it with other bundle drivers
Viresh Kumar [Sat, 14 May 2016 18:12:19 +0000 (23:42 +0530)]
greybus: spi: Restructure spi.c to share it with other bundle drivers

This patch restructures spi.c as spilib core, so that the same logic can
be reused for SPI connections implemented as part of different bundle
types. This is required for Firmware Management Bundle.

Note that the 'struct gb_protocol' and its callback aren't moved to
a separate file in this commit to make its reviews easier. That will be
done by a following patch.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>