cascardo/linux.git
7 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>
7 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>
7 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>
7 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>
7 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>
7 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>
7 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>
7 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>
7 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>
7 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>
7 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>
7 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>
7 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>
7 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>
7 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>
7 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>
7 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>
7 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>
7 years agogreybus: Remove bridge PHY protocol specific classes
Viresh Kumar [Tue, 10 May 2016 03:20:13 +0000 (08:50 +0530)]
greybus: Remove bridge PHY protocol specific classes

These protocols are managed under the bridged PHY class and doesn't need
protocol specific classes anymore.

Remove their entries from gb_gpbridge_id_table array and remove the now
unused macro's and mark their values as unused.

Tested on EVT 1.5 with generic-test module.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Acked-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: gpbridge: Remove (now) unused macro gb_gpbridge_builtin_driver()
Viresh Kumar [Mon, 9 May 2016 12:45:14 +0000 (18:15 +0530)]
greybus: gpbridge: Remove (now) unused macro gb_gpbridge_builtin_driver()

gb_gpbridge_builtin_driver() isn't used anymore, remove it.

Tested on EVT 1.5 by inserting GP test module, all the devices were
enumerated correctly.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: gpbridge: Rename gb-phy.ko module
Viresh Kumar [Mon, 9 May 2016 12:45:13 +0000 (18:15 +0530)]
greybus: gpbridge: Rename gb-phy.ko module

Rename gb-phy.ko module as gb-gpbridge.ko.

Tested on EVT 1.5 by inserting GP test module, all the devices were
enumerated correctly.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: usb: Create separate module
Viresh Kumar [Mon, 9 May 2016 12:45:12 +0000 (18:15 +0530)]
greybus: usb: Create separate module

Create separate module for usb gpbridge driver.

Tested on EVT 1.5 by inserting GP test module, all the devices were
enumerated correctly.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: uart: Create separate module
Viresh Kumar [Mon, 9 May 2016 12:45:11 +0000 (18:15 +0530)]
greybus: uart: Create separate module

Create separate module for uart gpbridge driver.

Tested on EVT 1.5 by inserting GP test module, all the devices were
enumerated correctly.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: spi: Create separate module
Viresh Kumar [Mon, 9 May 2016 12:45:10 +0000 (18:15 +0530)]
greybus: spi: Create separate module

Create separate module for spi gpbridge driver.

Tested on EVT 1.5 by inserting GP test module, all the devices were
enumerated correctly.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: sdio: Create separate module
Viresh Kumar [Mon, 9 May 2016 12:45:09 +0000 (18:15 +0530)]
greybus: sdio: Create separate module

Create separate module for sdio gpbridge driver.

Tested on EVT 1.5 by inserting GP test module, all the devices were
enumerated correctly.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: pwm: Create separate module
Viresh Kumar [Mon, 9 May 2016 12:45:08 +0000 (18:15 +0530)]
greybus: pwm: Create separate module

Create separate module for pwm gpbridge driver.

Tested on EVT 1.5 by inserting GP test module, all the devices were
enumerated correctly.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: i2c : Create separate module
Viresh Kumar [Mon, 9 May 2016 12:45:07 +0000 (18:15 +0530)]
greybus: i2c : Create separate module

Create separate module for i2c gpbridge driver.

Tested on EVT 1.5 by inserting GP test module, all the devices were
enumerated correctly.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: gpio: Create separate module
Viresh Kumar [Mon, 9 May 2016 12:45:06 +0000 (18:15 +0530)]
greybus: gpio: Create separate module

Create separate module for gpio gpbridge driver.

Tested on EVT 1.5 by inserting GP test module, all the devices were
enumerated correctly.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: gpbridge: Create module_gpbridge_driver()
Viresh Kumar [Mon, 9 May 2016 12:45:05 +0000 (18:15 +0530)]
greybus: gpbridge: Create module_gpbridge_driver()

Create module_gpbridge_driver() for registering gpbridge module drivers.

Tested on EVT 1.5 by inserting GP test module, all the devices were
enumerated correctly.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: gpbridge: Export few routines
Viresh Kumar [Mon, 9 May 2016 12:45:04 +0000 (18:15 +0530)]
greybus: gpbridge: Export few routines

In order to separate protocol specific drivers into their own modules,
some of the gpbridge routines need to be exported.

Tested on EVT 1.5 by inserting GP test module, all the devices were
enumerated correctly.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: control: Drop unused parameter from timesync_authoritative
Bryan O'Donoghue [Thu, 12 May 2016 11:43:52 +0000 (12:43 +0100)]
greybus: control: Drop unused parameter from timesync_authoritative

The count field is redundant and unused. Drop it from the control
timesync_authoritative command.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: control: Add TimeSync get-last-event logic
Bryan O'Donoghue [Thu, 12 May 2016 11:43:51 +0000 (12:43 +0100)]
greybus: control: Add TimeSync get-last-event logic

gb_control_timesync_get_last_event() sends a request asking for the
FrameTime at the last SVC strobe event. The responding entity returns the
FrameTime in the response phase of the request. Performing this operation
to an Interface after previously:

1. Synchronizing time using timesync-enable/timesync-authoritative
2. Sending an SVC_TIMESYNC_PING

will return the FrameTime of the responding entity at the SVC-ping. If
this command is sent before synchronization has been initiated or
successfully completed the responding entity should return an error
code.

- control.c::gb_control_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>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: svc: Add TimeSync SVC commands
Bryan O'Donoghue [Thu, 12 May 2016 11:43:50 +0000 (12:43 +0100)]
greybus: svc: Add TimeSync SVC commands

Simple addition of the TimeSync commands defined in the specification.

Adds:
- svc.c::timesync_enable(u8 count, u64 frame_time, u32 strobe_delay,
                         u32 refclk)
  Commands the SVC to initiate count TimeSync strobe pulses with
  strobe_delay microseconds delay between each strobe to the specified
  bit-mask of Interface IDs indicated in a previous
  timesync_wake_pins_acquire command. The frame_time parameter indicates
  the initial time the SVC should base the first strobe from. The refclk
  parameter indicates the APs clock rate, the SVC should ensure its own
  clock ticks at this rate. Once enabled the SVC may not enter a low-power
  mode which will result in the reference timer used to track time
  switching off. The SVC will capture the authoritative FrameTime at each
  strobe and store these values for later propagation to the AP with the
  timesync_authoritative request.

- svc.c::timesync_disable(void)
  Commands the SVC to immediately halt TimeSync logic. This will allow
  the SVC to transition into low-power modes where the reference timer
  being used for TimeSync may switch off.

- svc.c::timesync_authoritative(u64 *frame_time)
  Used by the AP Module to ask the SVC for the authoritative FrameTime
  as captured at each TimeSync strobe.

- svc.c::timesync_ping(u64 *frame_time)
  Used by the AP Module to command the SVC to initiate a single strobe on
  a specified bit-mask of Interface IDs communicated in a previous
  timesync_wake_pins_acquire command. SVC will latch the FrameTime on the
  rising edge of the outbound pulse and will return the FrameTime to the
  AP Module in the response phase of the greybus transaction.

- svc::timesync_wake_pins_acquire(u32 strobe_mask)
  Used by the AP to tell the SVC to set a bit-mask of wake lines associated
  with a bit-mask of Interface IDs to a known initial state prior to the
  SVC generating a TimeSync related pulse such as timesync-enable or
  timesync-ping.

- svc::timesync_wake_pins_release(void)
  Used by the AP to tell the SVC to release all wake-detect lines in the
  timesync active state as previously specified in the
  timesync_wake_pins_acquire operation.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: arche-platform: Fix the MODULE_LICENSE to match with header
Sandeep Patil [Fri, 13 May 2016 19:00:56 +0000 (12:00 -0700)]
greybus: arche-platform: Fix the MODULE_LICENSE to match with header

The header calls out the license to be GPL v2, while the module declares
itself as "GPL"

Testing Done: Trivial

Signed-off-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: gpbridge: add uevent vars for gpbridge devices
Sandeep Patil [Fri, 13 May 2016 18:51:05 +0000 (11:51 -0700)]
greybus: gpbridge: add uevent vars for gpbridge devices

The uevent vars now include module, interface, greybus_id,
bundle id, class and gpbridge device specific properties.

This make it consistent with how we are reporting uevents for
all other greybus devices.

Testing Done:
Tested by reading uevent from gpbridge devices that enumerate
using gpb module

Signed-off-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: gpbridge: make gpbridge device ids start with 1
Sandeep Patil [Fri, 13 May 2016 18:51:04 +0000 (11:51 -0700)]
greybus: gpbridge: make gpbridge device ids start with 1

Making gpb device ids consistent with all other devices on
greybus

Testing Done:
Tested using gpb module to make sure the first gpbX/ device
starts with 1.

Signed-off-by: Sandeep Patil <sspatil@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: gpbridge: add gpbridge device type
Sandeep Patil [Fri, 13 May 2016 18:51:03 +0000 (11:51 -0700)]
greybus: gpbridge: add gpbridge device type

Right now, there is no way to know the device type of gpbridge
(bridged-phy) devices in userspace. So, add that.

Testing Done:
Tested by reading the 'uevent' for gpb device of gpbridge
module

Signed-off-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: camera: fix data-connection handling
Johan Hovold [Wed, 11 May 2016 08:18:06 +0000 (10:18 +0200)]
greybus: camera: fix data-connection handling

Now that core supports offloaded connections, we can remove the hack
that was used to setup the data connection.

Note that offloaded-resource management may need to be refined later,
but the current minimal implementation is enough to allow core to manage
the connections (e.g. needed for proper connection tear down and power
management).

This will also allow the camera driver to be converted to a bundle
driver.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: connection: add camera-data connected workaround
Johan Hovold [Wed, 11 May 2016 08:18:05 +0000 (10:18 +0200)]
greybus: connection: add camera-data connected workaround

Firmware currently lacks a representation of the offloaded CDSI
connections and connected requests sent for these ports therefore fails.

Add a temporary work-around until this has been resolved in firmware.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: es2: add support for CDSI1 allocation
Johan Hovold [Wed, 11 May 2016 08:18:04 +0000 (10:18 +0200)]
greybus: es2: add support for CDSI1 allocation

Use the new CPort-allocation callbacks to allow for rudimentary resource
management of the CDSI CPorts.

How to manage offloaded resources in a generic fashion is yet to be
determined, but this minimal implementation will allow core to manage
the camera data connection so that the current camera-driver hacks can
be removed. This is specifically required to be able to implement proper
connection closing and for power management.

Note that the CDSI CPorts can not (currently) be reset through the
USB vendor request.

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>
7 years agogreybus: es2: clean up cport-reset handling
Johan Hovold [Wed, 11 May 2016 08:18:03 +0000 (10:18 +0200)]
greybus: es2: clean up cport-reset handling

Move handling of CPort-reset exceptions to the reset handler.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: hd: generalise cport allocation
Johan Hovold [Wed, 11 May 2016 08:18:02 +0000 (10:18 +0200)]
greybus: hd: generalise cport allocation

Generalise CPort allocation by allowing host-device drivers to override
the default implementation.

Also pass the connection flags down the stack as such information is
needed for proper CPort allocation. Specifically, this will initially be
used to allow the camera driver to allocate the dedicated CDSI CPorts.

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>
7 years agogreybus: es2: clean up CDSI CPort reservation
Johan Hovold [Wed, 11 May 2016 08:18:01 +0000 (10:18 +0200)]
greybus: es2: clean up CDSI CPort reservation

Clean up the CDSI CPort reservation by adding a host-device helper and
CPort defines.

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>
7 years agogreybus: es2: fix probe error handling
Johan Hovold [Wed, 11 May 2016 08:18:00 +0000 (10:18 +0200)]
greybus: es2: fix probe error handling

Make sure to return -ENODEV when the expected endpoints are missing and
stop relying on a default 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>
7 years agogreybus: hd: move CPort allocation to host-device code
Johan Hovold [Wed, 11 May 2016 08:17:59 +0000 (10:17 +0200)]
greybus: hd: move CPort allocation to host-device code

Move host-device CPort allocation to the host-device code.

Proper CPort allocation requires knowledge of the hardware and must be
handled by the host-device driver. This is an intermediate step that
moves the generic CPort-allocation code to the host-device code.

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>
7 years agogreybus: audio: mark the data connection as offloaded
Johan Hovold [Wed, 11 May 2016 08:17:58 +0000 (10:17 +0200)]
greybus: audio: mark the data connection as offloaded

Mark the data-connection as offloaded, that is, under control of the
host device (AP-bridge).

This prevents messages from being sent from or forwarded to the AP.

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>
7 years agogreybus: connection: add helper for creating offloaded connection
Johan Hovold [Wed, 11 May 2016 08:17:57 +0000 (10:17 +0200)]
greybus: connection: add helper for creating offloaded connection

Add helper for creating offloaded connection.

This can later be extended to support more elaborate resource
management.

Also fix a minor white space issue.

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>
7 years agogreybus: connection: add offloaded connection flag
Johan Hovold [Wed, 11 May 2016 08:17:56 +0000 (10:17 +0200)]
greybus: connection: add offloaded connection flag

Add an offloaded connection flag, which is used to mark a connection as
offloaded and prevent drivers from initiating operation over it.

This will be used for the audio and camera data connections.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: connection: add no-flow-control connection flag
Johan Hovold [Wed, 11 May 2016 08:17:55 +0000 (10:17 +0200)]
greybus: connection: add no-flow-control connection flag

Add a no-flow-control connection flag, which is set for connection that
should not have any flow-control feature enabled.

This flag is specifically set for all connections to the legacy ES3
bootrom, and will also be used by the camera driver eventually.

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>
7 years agogreybus: Fix probing of gpbridge devices
Viresh Kumar [Thu, 12 May 2016 05:56:48 +0000 (11:26 +0530)]
greybus: Fix probing of gpbridge devices

The gpbridge core tries to match the driver's id-table against all
CPorts available within the bundle for which the gpbridge bus was
created. The gpbdev here is unique for a cport_desc and only a single
cport_desc->protocol_id should be matched with the driver's id-table.

Fix it.

Tested on EVT 1.5 with a special manifest for GP module, where multiple
CPorts are part of the same Bridged PHY bundle.

Fixes: 75223f666687 ("gpbridge: implement gpbridge "bus" logic")
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: core: Rename greybus_module_match()
Viresh Kumar [Thu, 12 May 2016 06:04:05 +0000 (11:34 +0530)]
greybus: core: Rename greybus_module_match()

greybus_module_match() doesn't match modules anymore but bundle devices
and should be named correctly.

Though we can use greybus_bundle_match() as well, rest of the kernel
uses terminology like 'greybus_match_device' and so choosing that
instead.

Compile tested.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: gpbridge: Expose protocol_id in sysfs
Viresh Kumar [Thu, 12 May 2016 06:50:02 +0000 (12:20 +0530)]
greybus: gpbridge: Expose protocol_id in sysfs

Right now, userspace doesn't have any way to find what protocol does a
gpbridge device implement. And this is essential for the scripts to
know, to expect what kind of device will be present inside the gpbN
directory.

Expose 'protocol_id' in sysfs to fix that.

Tested by checking that the field appears with GP module on EVT 1.5.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: interface: remove unused interface-version quirk
Johan Hovold [Mon, 9 May 2016 12:40:10 +0000 (14:40 +0200)]
greybus: interface: remove unused interface-version quirk

The interface-version request was just removed so remove the now unused
interface-version quirk.

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>
7 years agogreybus: interface: fix type in enable error message
Johan Hovold [Mon, 9 May 2016 12:40:09 +0000 (14:40 +0200)]
greybus: interface: fix type in enable error message

Fix type of PTR_ERR in an interface-enable error message.

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>
7 years agogreybus: svc: support status in svc_intf_activate response
Jeffrey Carlyle [Wed, 11 May 2016 17:08:55 +0000 (10:08 -0700)]
greybus: svc: support status in svc_intf_activate response

Update per Greybus spec. Status attribute added to activate
response to return more detailed information about errors during
activate. If the Greybus response is GB_OP_SUCCESS, the caller
must also check the status attribute in the response to determine
if any other errors occurred.

Testing done: along with matchine firmware change, verified that modules
              were detected and enumerated as expected.

Signed-off-by: Jeffrey Carlyle <jcarlyle@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
7 years agogreybus: operation: fix an inconsistent indent
David Lin [Sat, 7 May 2016 01:16:24 +0000 (18:16 -0700)]
greybus: operation: fix an inconsistent indent

This patch fixes an inconsistent indent.

Testing Done:
- Build & boot

Signed-off-by: David Lin <dtwlin@google.com>
Acked-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: fw-download: Replace timer with delayed-work
Viresh Kumar [Mon, 9 May 2016 05:29:01 +0000 (10:59 +0530)]
greybus: fw-download: Replace timer with delayed-work

The timeout-handlers need to call routines that can sleep and those
can't be called from interrupt context. The timer-handler is called in
interrupt context and so will hit a BUG() in vmalloc.c.

This patch moves away from timers to delayed-work, whose timeout handler
gets called in process context and can call the sleep-able routines
safely.

Note that this issue wasn't hit earlier when the initial patch for
timeouts was implemented due to some issues in the build arche_420. But
with the new build arche_440, the BUG started crashing the phone on
timeouts and so this fix is required.

Tested on EVT 1.5 by triggering fake timeouts, by not sending
release-firmware request for example. This is tested with build
arche_440.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: bootrom: Implement timeouts to detect Module failures
Viresh Kumar [Mon, 9 May 2016 05:29:00 +0000 (10:59 +0530)]
greybus: bootrom: Implement timeouts to detect Module failures

Its possible that the Module may fail to download the next stage
firmware, or to jump into it and boot into the new personality.

We have already seen examples of both of these cases on EVT 1.5.

This patch implements timeouts in the bootrom bundle driver, which now
expects the next request from the Module to be received at the AP within
1 second of the previous request/response. The time interval can be
increased later if required.

The timeouts are added between:
- AP_READY and FIRMWARE_SIZE operations
- FIRMWARE_SIZE and GET_FIRMWARE operations
- Two GET_FIRMWARE operations
- GET_FIRMWARE and READY_TO_BOOT operations
- READY_TO_BOOT operation and the call to the ->disconnect() event of
  the bootrom bundle (once the new hotplug request is received).

The timeout for the last case is kept at 5 seconds right now (random
value), as it may take a bit longer.

Because 'bootrom->fw' can be accessed simultaneously (from timeout
handler and incoming requests) and one of them can potentially free the
'->fw' structure, a mutex is also added to take care of such races while
accessing 'bootrom->fw' structure.

Also note that the '!bootrom->fw' check is moved to free_firmware()
routine.

Note that this version uses delayed-work (instead of timers used in
earlier attempt), as we need to call routines that can sleep from the
timeout handler.

Tested on EVT 1.5, by faking errors on certain requests, so that the
bootrom doesn't send any more requests. Normal case is working just fine
for audio and GP modules. This is tested with build arche_440.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: svc: implement svc_intf_activate
Jeffrey Carlyle [Fri, 6 May 2016 19:43:53 +0000 (12:43 -0700)]
greybus: svc: implement svc_intf_activate

With upcoming firmware changes we will switch from an SVC-driven module
boot sequence to an AP-driven module sequence. This operation allows the
AP to request the SVC to boot a module to which the AP has previouslt
requested power be applied. This operation will also determine if the
remote interface is a dummy module, UniPro-only module, or full Greybus
module.

Testing done: Tested together with "new" firmware boot sequence to
              verify that modules are detected and booted as expected.

Signed-off-by: Jeffrey Carlyle <jcarlyle@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: svc: implement svc_intf_{vsys,refclk,unipro}_{enable,disable} operations
Jeffrey Carlyle [Fri, 6 May 2016 19:43:52 +0000 (12:43 -0700)]
greybus: svc: implement svc_intf_{vsys,refclk,unipro}_{enable,disable} operations

Add SVC operations for fine grain control over vsys, refclk, and unipro
port power.

Testing done: used "new" firmware boot sequence to verify that modules
              were correctly detected and booted.

Signed-off-by: Jeffrey Carlyle <jcarlyle@google.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: Revert "bootrom: Implement timeouts to detect Module failures"
Jeffrey Carlyle [Fri, 6 May 2016 18:29:37 +0000 (11:29 -0700)]
greybus: Revert "bootrom: Implement timeouts to detect Module failures"

This reverts commit 571348253032a86e4f0102d4dfadd390d0ea7e64.

With this patch gb_bootrom_timedout was getting called in interrupt
context and then proceeding to call functions that might block. In
practical terms, this was leading to a kernel BUG at mm/vmalloc.c:1650.

Signed-off-by: Jeffrey Carlyle <jcarlyle@google.com>
Acked-by: Johan Hovold <johan@hovoldconsulting.com>
7 years agogreybus: fw-download: Introduce timeouts for firmware downloads
Viresh Kumar [Thu, 5 May 2016 10:03:20 +0000 (15:33 +0530)]
greybus: fw-download: Introduce timeouts for firmware downloads

As per greybus specification, the AP can apply, implementation
dependent, timeouts for:

- The time interval between the Find Firmware Response and the first
  Fetch Firmware Request.
- The time interval between a Fetch Firmware Response and the next Fetch
  Firmware Request.
- The time interval between a Fetch Firmware Response and the Release
  Firmware Request.
- The time interval between the Find Firmware Response and the Release
  Firmware Request.

This patch implements those timeouts.

The timeout period for the first three cases is fixed to one-second and
the timeout for the last one is finalized at runtime, dependent on the
total size of the firmware.

There can be two possible paths now, which may race for freeing or
getting the 'struct fw_request'. They are:
- Request handler: initiated from the Module side.
- Timeout handler: initiated on timeout of the programmed timer.

And so a mutex is added to avoid races.

Every caller which needs to access the 'struct fw_request' increments
the reference count, so that the structure doesn't get freed in
parallel. Once the structure is freed and reference is put by all the
users, the structure is freed.

If we timeout while waiting for a request from the Module, the AP frees
the 'struct fw_request', but does *not* free the request-id. This is
done to guarantee that a delayed request from the Module for the expired
id, doesn't get access to a new 'struct fw_request' allocated later with
the same id.

Tested with gbsim by hacking its code to delay the release request and
indefinitely fetch the same section of the firmware package. Both timed
out on the AP side and the 'struct fw_request' is free properly. Further
requests work fine after few are timed out. And rmmod (followed by more
similar testing) works just fine.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: fw-download: Manage firmware requests with kref
Viresh Kumar [Thu, 5 May 2016 10:03:19 +0000 (15:33 +0530)]
greybus: fw-download: Manage firmware requests with kref

This patch updates the fw-download core to manage firmware requests with
kref. This is required for the next patch, which will introduce timeouts
for firmware downloads.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: arche-platform: Rework platform/wd-line state transition logic
Bryan O'Donoghue [Thu, 5 May 2016 14:34:59 +0000 (15:34 +0100)]
greybus: arche-platform: Rework platform/wd-line state transition logic

This patch simplifies and improves the readability of the internal state
transition logic of arche platform driver state transition logic by:

1. Making a dedicated function to state-transition the platform code.
2. Condense the decision to swtich states down to a single switch
   statement instead of four separate if/else clauses.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Suggested-by: Alex Elder <elder@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: arche-platform: Export fn to allow timesync driver to change the state
Vaibhav Hiremath [Thu, 5 May 2016 14:34:58 +0000 (15:34 +0100)]
greybus: arche-platform: Export fn to allow timesync driver to change the state

With the addition of the timesync driver and looking at the hardware
interfaces we have, its clear we need to add a new arche-platform state.

This patch adds ARCHE_PLATFORM_STATE_TIME_SYNC to the arche-platform driver
to facilitate transition to the TIME_SYNC state if-and-only-if the
arche-platform driver is in the ACTIVE state.

This is mainly needed as wake/detect lines are shared between TIMESYNC
operation and basic control functionality of APBs. So during TIMESYNC
we want to make sure that the events on wake/detect lines are
ignored by the arche-platform APB reset logic.

This patch adds one exported function, which can be invoked from
timesync driver code, allowing, switching between
ARCHE_PLATFORM_STATE_TIME_SYNC <=> ARCHE_PLATFORM_STATE_ACTIVE states.

[ bryan.odonoghue@linaro.org: Added mutex, massaged commit text ]

Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Suggested-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: arche-platform: Rename spinlock variable lock => wake_detect_lock
Vaibhav Hiremath [Thu, 5 May 2016 14:34:57 +0000 (15:34 +0100)]
greybus: arche-platform: Rename spinlock variable lock => wake_detect_lock

With addition of exported function, required for TIMESYNC operation,
we need more locking mechanism for driver state, so to avoid confusion
rename existing spinlock variable to its appropriate name.

Testing Done: Tested on DB3.5 platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: greybus_protocols.h Add SVC_TIMESYNC_PING
Bryan O'Donoghue [Thu, 5 May 2016 14:34:56 +0000 (15:34 +0100)]
greybus: greybus_protocols.h Add SVC_TIMESYNC_PING

In order to verify TimeSync functionality we require a TimeSync-ping
operation where the AP can command the SVC to initiate a single strobe of
downstream TimeSync slaves, and report the FrameTime at the strobe. Ping
will only be valid after the system has transitioned to a TIMESYNC_ACTIVE
state.

In the active state each TimeSync slave will graph a single incoming SVC
strobe as a ping and will store its frame time. The AP will then gather
each last-event FrameTime for presentation to user-space in the AP and/or
further automation based on the reported FrameTimes at the SVC ping.

This patch adds the SVC ping command definition to greybus_protocols.h.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: greybus_protocols.h Add SVC_TIMESYNC_WAKE_PINS_ACQUIRE/RELEASE
Bryan O'Donoghue [Thu, 5 May 2016 14:34:55 +0000 (15:34 +0100)]
greybus: greybus_protocols.h Add SVC_TIMESYNC_WAKE_PINS_ACQUIRE/RELEASE

Its necessary to establish an initial state on the wake-detect lines before
enabling timesync on APB/GPB in order to ensure all GPIO edge-transitions are
correctly interpreted by the receiving processor.

This patch adds the operations defined in the Greybus specification to
greybus_protocols.h, this involves adding the
SVC_TIMESYNC_WAKE_PINS_ACQUIRE and SVC_TIMESYNC_WAKE_PINS_RELEASE commands
and moving the 'strobe_mask' parameter from 'struct
gb_svc_timesync_enable_request' to 'struct
gb_svc_timesync_wd_pins_acquire_request' since the communication of the
strobe_mask will be communicated before preparing any of the bridges to
receive the TimeSync pulses.

A separate patch to the greybus specification describes the transition
between the wake sub-state and the timesync sub-state.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: greybus_trace.h: Fix dodgy indentation
Bryan O'Donoghue [Thu, 5 May 2016 14:34:54 +0000 (15:34 +0100)]
greybus: greybus_trace.h: Fix dodgy indentation

We should use tabs not spaces when indenting multi-line macros and ensure
that the relevant '\' characters are aligned to each-other.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: uart: Kill reference_count hack
Viresh Kumar [Thu, 5 May 2016 09:02:38 +0000 (14:32 +0530)]
greybus: uart: Kill reference_count hack

This was done long back and was probably the best bet then, but it looks
really bad to have it this way now.

Kill the hack and implement proper driver init()/exit() routines to do
the same thing.

Tested using gbsim by hotplugging uart manifest and removing it later.
Also tried removing the gb-phy module to test the exit path properly.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: Documentation: Add sysfs information about bridged-phy device
Vaibhav Hiremath [Thu, 5 May 2016 09:02:37 +0000 (14:32 +0530)]
greybus: Documentation: Add sysfs information about bridged-phy device

Update the documentation (sysfs-bus-greybus) for recent conversion of
bridged-phy drivers to real drivers.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: USB: convert to a gpbridge driver
Greg Kroah-Hartman [Thu, 5 May 2016 09:02:36 +0000 (14:32 +0530)]
greybus: USB: convert to a gpbridge driver

This converts the USB driver to be a gpbridge driver, moving it away
from the "legacy" interface.

It's not like this code even does anything at the moment, how much
trouble could we cause with this change?  :)

Testing Done: Tested on gbsim.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
[vaibhav.hiremath@linaro.org: 1.Changed code to retain init/exit fns of
drivers. 2.Exit path fix. 3. Fixed review comments]
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: SPI: convert to a gpbridge driver
Greg Kroah-Hartman [Thu, 5 May 2016 09:02:35 +0000 (14:32 +0530)]
greybus: SPI: convert to a gpbridge driver

This converts the SPI driver to be a gpbridge driver, moving it away
from the "legacy" interface.

Testing Done: Tested on gbsim.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
[vaibhav.hiremath@linaro.org: 1.Changed code to retain init/exit fns of
drivers. 2.Exit path fix. 3. Fixed review comments]
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: SDIO: convert to a gpbridge driver
Greg Kroah-Hartman [Thu, 5 May 2016 09:02:34 +0000 (14:32 +0530)]
greybus: SDIO: convert to a gpbridge driver

This converts the SDIO driver to be a gpbridge driver, moving it away
from the "legacy" interface.

Testing Done: Tested on gbsim.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
[vaibhav.hiremath@linaro.org: 1.Changed code to retain init/exit fns of
drivers. 2.Exit path fix. 3. Fixed review comments]
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: GPIO: convert to a gpbridge driver
Greg Kroah-Hartman [Thu, 5 May 2016 09:02:33 +0000 (14:32 +0530)]
greybus: GPIO: convert to a gpbridge driver

This converts the GPIO driver to be a gpbridge driver, moving it away
from the "legacy" interface.

Testing Done: Tested on gbsim.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
[vaibhav.hiremath@linaro.org: 1.Changed code to retain init/exit fns of
drivers. 2.Exit path fix. 3. Fixed review comments]
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: I2C: convert to a gpbridge driver
Greg Kroah-Hartman [Thu, 5 May 2016 09:02:32 +0000 (14:32 +0530)]
greybus: I2C: convert to a gpbridge driver

This converts the I2C driver to be a gpbridge driver, moving it away
from the "legacy" interface.

Testing Done: Tested on gbsim.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
[vaibhav.hiremath@linaro.org: 1.Changed code to retain init/exit fns of
drivers. 2.Exit path fix. 3. Fixed review comments]
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: PWM: convert to a gpbridge driver
Greg Kroah-Hartman [Thu, 5 May 2016 09:02:31 +0000 (14:32 +0530)]
greybus: PWM: convert to a gpbridge driver

This converts the PWM driver to be a gpbridge driver, moving it away
from the "legacy" interface.

Testing Done: Tested on gbsim.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
[vaibhav.hiremath@linaro.org: 1.Changed code to retain init/exit fns of
drivers. 2.Exit path fix. 3. Fixed review comments]
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: UART: convert to a gpbridge driver
Greg Kroah-Hartman [Thu, 5 May 2016 09:02:30 +0000 (14:32 +0530)]
greybus: UART: convert to a gpbridge driver

This converts the UART driver to be a gpbridge driver, moving it away
from the "legacy" interface.

Testing Done: Tested on gbsim.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
[vaibhav.hiremath@linaro.org: 1.Changed code to retain init/exit fns of
drivers. 2.Exit path fix. 3. Fixed review comments]
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: connection: export gb_connection_disable_rx() fn
Vaibhav Hiremath [Thu, 5 May 2016 09:02:29 +0000 (14:32 +0530)]
greybus: connection: export gb_connection_disable_rx() fn

gb_connection_disable_rx() fn is required to be used by other modules
(e.g. bridged-phy drivers) and so export it.

Testing Done: Tested on gbsim.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: gpbridge: Add gpbridge driver init/exit helper macros
Vaibhav Hiremath [Thu, 5 May 2016 09:02:28 +0000 (14:32 +0530)]
greybus: gpbridge: Add gpbridge driver init/exit helper macros

In order to help bridged-phy drivers to define init()/exit()
functions, define helper macro in gpbridge.h file.

Testing Done: Tested on gbsim.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: gpbridge: implement gpbridge "bus" logic
Greg Kroah-Hartman [Thu, 5 May 2016 09:02:27 +0000 (14:32 +0530)]
greybus: gpbridge: implement gpbridge "bus" logic

This creates a gpbridge "bus" that will be used to create devices that
are the bridged phy devices that correspond to the protocols being
implemented.

Testing Done: Tested on gbsim.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
[vaibhav.hiremath@linaro.org: 1.Changed code to retain init/exit fns of
drivers. 2.Exit path fix. 3. Fixed review comments]
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: Revert "interface: Fetch and expose version of interface's firmware"
Viresh Kumar [Thu, 5 May 2016 03:19:58 +0000 (08:49 +0530)]
greybus: Revert "interface: Fetch and expose version of interface's firmware"

This reverts commit b957ade7b3e4ab8c149c53346dbf02e977b7f3a7.

The interface version is now managed as part of the firmware-management
protocol. This operation is already removed from the greybus
specifications.

Drop interface version support from greybus.

Tested with gbsim (sysfs file not available after this patch).

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Acked-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: audio: Fix incorrect counting of 'ida'
Dinko Mironov [Thu, 5 May 2016 16:58:22 +0000 (19:58 +0300)]
greybus: audio: Fix incorrect counting of 'ida'

Function gb_audio_manager_remove_all() to remove all audio modules,
doesn't control correctly 'ida' counting.

Signed-off-by: Dinko Mironov <dmironov@mm-sol.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: svc: reconfig APBridgeA-Switch link to handle required load
Mitchell Tasman [Wed, 4 May 2016 21:30:23 +0000 (17:30 -0400)]
greybus: svc: reconfig APBridgeA-Switch link to handle required load

SW-4894, SW-4389, and share a common root cause, namely that
the power-on reset configuration of the APBridgeA-Switch link of PWM
Gear 1, 1 Lane, Slow Auto, is insufficient to handle some required
traffic loads, such as 3 audio streams plus boot-over-UniPro or 4 audio
streams.

The correct long-term solution is to implement a UniPro Power Mode
Manager as in that considers the demands placed on the network,
and adjusts power modes accordingly.

The present commit implements a short-term, brute-force hack to allow
continued system testing:
- Upon receiving an SVC HELLO request, schedule deferred work to
  reconfigure the APB1-Switch link to PWM G2, 1 lane, Slow Auto
- When the Camera driver transitions a White Camera module from active to
  inactive, return the APB1-Switch link to PWM G2, 1 lane, Slow Auto

The Camera driver already steps up the APBridgeA-Camera link speed while a
camera module is active, which affords sufficient margin for simultaneous
audio and hotplug activity, and the Camera driver already steps down the
link speed thereafter: the change made by the present patch is simply to
tweak the stepped-down power mode to match the new baseline configuration.

Signed-off-by: Mitchell Tasman <tasman@leaflabs.com>
Tested-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: core: add MODULE uevent var for all control devices
Sandeep Patil [Wed, 4 May 2016 23:21:29 +0000 (16:21 -0700)]
greybus: core: add MODULE uevent var for all control devices

The new ctrl device under interface is missing a MODULE uevent var,
add it.

Testing Done:
cat 'uevent' from ctrl device.
$ cat 1-3.3.ctrl/uevent
DEVTYPE=greybus_control
BUS=1
MODULE=3
INTERFACE=3
GREYBUS_ID=fffe0001/ffee0011

Signed-off-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: bootrom: Implement timeouts to detect Module failures
Viresh Kumar [Tue, 3 May 2016 10:43:12 +0000 (16:13 +0530)]
greybus: bootrom: Implement timeouts to detect Module failures

Its possible that the Module may fail to download the next stage
firmware, or to jump into it and boot into the new personality.

We have already seen examples of both of these cases on EVT 1.5.

This patch implements timeouts in the bootrom bundle driver, which now
expects the next request from the Module to be received at the AP within
1 second of the previous request/response. The time interval can be
increased later if required.

The timeouts are added between:
- AP_READY and FIRMWARE_SIZE operations
- FIRMWARE_SIZE and GET_FIRMWARE operations
- Two GET_FIRMWARE operations
- GET_FIRMWARE and READY_TO_BOOT operations
- READY_TO_BOOT operation and the call to the ->disconnect() event of
  the bootrom bundle (once the new hotplug request is received).

The timeout for the last case is kept at 5 seconds right now (random
value), as it may take a bit longer.

Because 'bootrom->fw' can be accessed simultaneously (from timeout
handler and incoming requests) and one of them can potentially free the
'->fw' structure, a mutex is also added to take care of such races while
accessing 'bootrom->fw' structure.

Also note that the '!bootrom->fw' check is moved to free_firmware()
routine.

Tested on EVT 1.5, by faking errors on certain requests, so that the
bootrom doesn't send any more requests. Normal case is working just
fine for audio and GP modules.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: audio: Use standard API to set connections' private data
Vaibhav Agarwal [Wed, 4 May 2016 10:59:24 +0000 (16:29 +0530)]
greybus: audio: Use standard API to set connections' private data

Use standard API greybus_set_drvdata() while setting private
data pointers for mgmt & data connection.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: audio: Reduce codec->lock granularity
Vaibhav Agarwal [Wed, 4 May 2016 10:59:23 +0000 (16:29 +0530)]
greybus: audio: Reduce codec->lock granularity

Earlier codec->lock protects almost complete register/unregister
module function. This can be reduced to specific operations.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: audio: Reorganize sequence in GB audio bundle & codec driver
Vaibhav Agarwal [Wed, 4 May 2016 10:59:22 +0000 (16:29 +0530)]
greybus: audio: Reorganize sequence in GB audio bundle & codec driver

Modify sequence of register_module & unregister_module in bundle
driver. This would affect the uevent generated for above user
space. Accordingly, we need to modify snd_soc_xxx sequence in
register_module() in codec driver.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: audio: Remove redundant lock protection & is_connected field
Vaibhav Agarwal [Wed, 4 May 2016 10:59:21 +0000 (16:29 +0530)]
greybus: audio: Remove redundant lock protection & is_connected field

Each module maintains connected status & a lock to protect it.
Using codec->lock we can safely serialize ASoC specific callbacks
(in response to mixer_ctl update or dai_ops) and gb module
disconnect. Thus is_connected field can be removed.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: audio: Cleanup GB Audio bundle driver.
Vaibhav Agarwal [Wed, 4 May 2016 10:59:20 +0000 (16:29 +0530)]
greybus: audio: Cleanup GB Audio bundle driver.

Remove unnecessary lock & list maintained in GB audio bundle
driver

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: audio:gb_manager: Use proper locking around kobject_xxx
Vaibhav Agarwal [Wed, 4 May 2016 10:59:19 +0000 (16:29 +0530)]
greybus: audio:gb_manager: Use proper locking around kobject_xxx

read/write_lock_irqsave mechanism was used to protect modules
list & kobject_xxx() in gb_audio_manager. Since kobject_xxx calls
can sleep spin_lock variants can't be used there. So use rw_sem
for protecting modules_list.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
7 years agogreybus: fw-download: Create a macro for length of firmware file's name
Viresh Kumar [Mon, 2 May 2016 05:21:49 +0000 (10:51 +0530)]
greybus: fw-download: Create a macro for length of firmware file's name

Create a macro representing the length of the firmware file's name and
use that instead of using magic number in the code.

Suggested-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: firmware: Add firmware-download protocol driver
Viresh Kumar [Thu, 28 Apr 2016 04:36:38 +0000 (10:06 +0530)]
greybus: firmware: Add firmware-download protocol driver

This patch adds Firmware Download Protocol support to firmware core,
which allows an Interface to download a firmware package over Unipro.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Jun Li <li_jun@projectara.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: operation: fix definition of the invalid type
Johan Hovold [Fri, 29 Apr 2016 15:08:37 +0000 (17:08 +0200)]
greybus: operation: fix definition of the invalid type

The invalid request type has been redefined as 0x7f.

Also remove the redundant redefinition of the invalid type from the
operation header.

Note that operation type 0x00 has been repurposed for the new generic
ping operation, which will be used to implement proper connection tear
down.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: svc: define the version request
Johan Hovold [Fri, 29 Apr 2016 15:08:36 +0000 (17:08 +0200)]
greybus: svc: define the version request

Define the SVC version request, which need not need to stay the same as
the legacy version request.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: loopback: remove unsupported version request
Johan Hovold [Fri, 29 Apr 2016 15:08:35 +0000 (17:08 +0200)]
greybus: loopback: remove unsupported version request

Remove the unsupported version request from the loopback-driver request
handler.

Unsupported requests are already handled and logged using the default
case.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: control: implement mode-switch operation
Johan Hovold [Fri, 29 Apr 2016 15:08:34 +0000 (17:08 +0200)]
greybus: control: implement mode-switch operation

Implement the unidirectional mode-switch operation.

This operation will be used in the implementation of the new generic
mode-switch functionality.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: operation: add helper functions for unidirectional operations
Johan Hovold [Fri, 29 Apr 2016 15:08:33 +0000 (17:08 +0200)]
greybus: operation: add helper functions for unidirectional operations

Add helper functions for initiating unidirectional operations and
waiting for them to have been acknowledged as sent by the host device.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
8 years agogreybus: operation: add support for initiating unidirectional operations
Johan Hovold [Fri, 29 Apr 2016 15:08:32 +0000 (17:08 +0200)]
greybus: operation: add support for initiating unidirectional operations

Add support for initiating unidirectional operations, that is, sending
requests that do not require responses.

Note that we already handle incoming unidirectional operations.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>