#if 0 cleanups

Remove some #if 0 chunks for the old-style greybus driver macros

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Remove id_table usages

We aren't using an id_table for "drivers" at this moment, as the whole
driver model interaction is under heavy rework.  So remove these for now
to keep things easier to understand for future patches.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
es1-ap-usb: document the lack of callback for the outgoing bulk urbs

We don't need a callback for bulk out urbs to do anything except put the
urb back in the pool.  Document why we do this and what is involved.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: module: set device_id when initializing an interface

gb_module_interface_init() looks for the interface corresponding
to the supplied interface_id, but fails to configure the
device_id that goes with it. This results in a set route command
being set with an uninitialized and bogus value. Fix it.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: connection: call connection_init hook after setting the handler

In gb_connection_init() we set the connection_handler for each supported
protocol, but we never call the connection_init hook after doing so. This
results in a failure being returned so fix it by calling the connection_init
hook to get a good return and the associated driver initialized.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: drop the cport id on error

In gb_connection_create(), if an error occurs adding a connection's
device, the cport id assigned to the AP end of the connection is not
getting freed.  Fix that.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: use protocol_id for numeric values

Switch to using "protocol_id" to refer to a byte-sized numeric
protocol number.  A "protocol" will represent a protocol structure
(created in the next patch).

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: introduce protocol abstraction

Define a protocol structure that will allow protocols to be
registered dynamically.  For now we just introduce a bookkeeping
data structure.  Upcoming patches will move protocol-related methods
into the protocol structure, and will start registering protocol
handlers dynamically.

A list of connections using a given protocol is maintained so we can
tell when a protocol is no longer in use.  This may not be necessary
(we could use a kref instead) but it may turn out to be a good way
to clean things up.

The interface is gb_protocol_get() and gb_protocol_put() for a
connection, allowing the protocol to be looked up and the connection
structure to be inserted into its list.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
connection: fix up error patch logic in gb_connection_create()

Once you have called device_initialize() you have to call put_device()
on the structure to clean it up on an error path, otherwise you will
leak memory.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: build: Add -fno-pic for 32bit arm as well

In order for 32bit arm devices using the android toolchain
to load the greybus module, I need to add -fno-pic in the
build arguments as well.

Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: fix a bug in gb_operation_gbuf_complete()

The gbuf completion routine was using the request payload pointers
(which point at the area *past* the message header) rather than the
header.  This didn't matter much for now, it was only used in the
error path.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: drop a redundant assignment

Get rid of a duplicate assignment of an interface's device id.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: make _gb_protocol_find() static

This function should have private scope.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: control printing message

There's a message that gets printed in gb_manifest_parse() if excess
descriptors are found in the manifest.  This should only be printed
if the parse was successful.  If it was not successful it's not
really very helpful.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: improve some error messages

Add a few error messages to help explain the reason for failures.
Add a missing space in a message in svc_management().

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: identify protocol by id *and* version

Right now we only look up a protocol based on its protocol id.
Add support for maintaining a major and minor version as well, and
use them when looking up a protocol.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: count rather than list protocol users

We don't really need a list of protocol users, we can just keep
track of how many there are.  Get rid of the list and use a count
instead.

Also, have gb_protocol_get() return the protocol rather than assigning
a passed-in connection pointer's protocol.  Make a comparable change
to the gb_protocol_put() interface.

Get rid of gb_protocol_find() (the version that locks), because it
is no longer needed.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: order the protocols list

Add protocols to the global list in sorted order, based on their
protocol id, and then their major and minor version number.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: register preallocated protocols

Set up protocol structures as static objects in each protocol source
file.  Pass the address of that in--rather than the protocol id and
version information--to the protocol registration routine.  Call a
central routine to register all our pre-defined protocols.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
greybus: move methods into protocol

Get rid of the connection handler structure, and instead put the
methods that were there into the protocol structure.

Eliminate the big switch statement in connection_init() and just
call the connection's protocol's init function there directly.

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