linux-2.6-microblaze.git
10 years agogreybus: move operation timeout teardown
Alex Elder [Mon, 17 Nov 2014 14:08:36 +0000 (08:08 -0600)]
greybus: move operation timeout teardown

Move the cancel_delayed_work() call so it's done separate from the
removing the operation from the pending list.

This should have been part of this commit:
    d3809f7 greybus: move timeout out of gb_operation_insert()

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: Greybus UART connection driver
Greg Kroah-Hartman [Sun, 16 Nov 2014 02:30:00 +0000 (18:30 -0800)]
greybus: Greybus UART connection driver

Flush out the Greybus UART driver to actually implement greybus
requests.  The number of Greybus Protocol operations has been reduced
down to a managable number, and, if you look closely, you will notice it
follows the CDC ACM USB specification, which can drive UART devices
quite well, no need for complex UART state changes, leave all of that
logic up to the firmware, if it wants/needs it.

The Greybus Protocol spec has been updated to match the driver.

TODO: There are 2 requests from the device to the host that need to be
implemented.  As this isn't fully hooked up in the Greybus core, that is
not implemented here yet either.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: skeleton for future uevents.
Greg Kroah-Hartman [Sat, 15 Nov 2014 20:12:16 +0000 (12:12 -0800)]
greybus: skeleton for future uevents.

Implement a skeleton for the uevent framework, to be filled in later
when we figure out what type of module "matching" we want to do for
things (connections, interfaces, modules, etc.)

Based on a patch from Viresh Kumar <viresh.kumar@linaro.org>

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: Revert "manifest: remove extra loop for finding module descriptor"
Greg Kroah-Hartman [Fri, 14 Nov 2014 22:37:56 +0000 (14:37 -0800)]
greybus: Revert "manifest: remove extra loop for finding module descriptor"

This reverts commit 4d1529e6687d53878b71cdcd646e28e10d62c2e8.

Alex reports that this causes problems.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: Revert "manifest: improve print message"
Greg Kroah-Hartman [Fri, 14 Nov 2014 22:37:32 +0000 (14:37 -0800)]
greybus: Revert "manifest: improve print message"

This reverts commit b8ba855506906de71df5b12b50cdbbf7259a930c.

needed to revert an older change.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: interface: move gb_module_interface_init() to interface.c
Viresh Kumar [Fri, 14 Nov 2014 11:55:08 +0000 (17:25 +0530)]
greybus: interface: move gb_module_interface_init() to interface.c

That's where it belong to. Also rename it in a similar way to:
gb_interface_create() and gb_interface_destroy().

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: module: move module specific code to module.c
Viresh Kumar [Fri, 14 Nov 2014 11:55:07 +0000 (17:25 +0530)]
greybus: module: move module specific code to module.c

Some of module specific routines were present in core.c instead of module.c.
Move them to the right place.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: module: move gb_module_find() to a more logical location
Viresh Kumar [Fri, 14 Nov 2014 11:55:06 +0000 (17:25 +0530)]
greybus: module: move gb_module_find() to a more logical location

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: core: re-use gb_module_find() in gb_remove_module()
Viresh Kumar [Fri, 14 Nov 2014 11:55:05 +0000 (17:25 +0530)]
greybus: core: re-use gb_module_find() in gb_remove_module()

Also fix print message.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: connection: fix duplicating naming in _gb_hd_connection_insert()
Viresh Kumar [Fri, 14 Nov 2014 11:55:04 +0000 (17:25 +0530)]
greybus: connection: fix duplicating naming in _gb_hd_connection_insert()

Though this doesn't cause any logical issues as far as the behavior of the
routine is concerned as the local variable would be considered inside the
'while' loop.

But its better not to use the same name for variables at different levels.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: manifest: make sure manifest_descs list is empty before parsing manifest
Viresh Kumar [Fri, 14 Nov 2014 11:55:03 +0000 (17:25 +0530)]
greybus: manifest: make sure manifest_descs list is empty before parsing manifest

Just an extra check to make sure the list isn't corrupted.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: connection: try cancelling operations only if list isn't empty
Viresh Kumar [Fri, 14 Nov 2014 11:55:02 +0000 (17:25 +0530)]
greybus: connection: try cancelling operations only if list isn't empty

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: nullify dangling pointers
Viresh Kumar [Fri, 14 Nov 2014 11:55:01 +0000 (17:25 +0530)]
greybus: nullify dangling pointers

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: operation: free resources in the reverse order of allocation
Viresh Kumar [Fri, 14 Nov 2014 11:55:00 +0000 (17:25 +0530)]
greybus: operation: free resources in the reverse order of allocation

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: core: use 'drv' instead of dev->driver
Viresh Kumar [Fri, 14 Nov 2014 11:54:59 +0000 (17:24 +0530)]
greybus: core: use 'drv' instead of dev->driver

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: core: remove unnecessary braces
Viresh Kumar [Fri, 14 Nov 2014 11:54:58 +0000 (17:24 +0530)]
greybus: core: remove unnecessary braces

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: manifest: improve print message
Viresh Kumar [Fri, 14 Nov 2014 04:17:39 +0000 (09:47 +0530)]
greybus: manifest: improve print message

Suggested-by: Alex Elder <elder@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: manifest: remove extra loop for finding module descriptor
Viresh Kumar [Thu, 13 Nov 2014 12:44:40 +0000 (18:14 +0530)]
greybus: manifest: remove extra loop for finding module descriptor

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: connection: free resources properly on failures
Viresh Kumar [Thu, 13 Nov 2014 12:44:39 +0000 (18:14 +0530)]
greybus: connection: free resources properly on failures

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: interface: free resources properly on failures
Viresh Kumar [Thu, 13 Nov 2014 12:44:38 +0000 (18:14 +0530)]
greybus: interface: free resources properly on failures

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: module: free resources properly on failures
Viresh Kumar [Thu, 13 Nov 2014 12:44:37 +0000 (18:14 +0530)]
greybus: module: free resources properly on failures

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: sysfs: generalize gb_module_attr() to capture more cases
Viresh Kumar [Thu, 13 Nov 2014 12:44:36 +0000 (18:14 +0530)]
greybus: sysfs: generalize gb_module_attr() to capture more cases

Most of the attribute routines are created with gb_module_attr() and few are
left out because they weren't printing 32 bit hexadecimal values.

Extend gb_module_attr() to cover more cases.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: debug: mark debug messages with pr_debug() instead of printk
Viresh Kumar [Thu, 13 Nov 2014 12:44:35 +0000 (18:14 +0530)]
greybus: debug: mark debug messages with pr_debug() instead of printk

Also fix indentation.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: don't set ->dev.driver to NULL when it is already NULL
Viresh Kumar [Thu, 13 Nov 2014 12:44:34 +0000 (18:14 +0530)]
greybus: don't set ->dev.driver to NULL when it is already NULL

Parent objects of 'dev' are allocated with kzalloc() and so all of their fields
are initialized with 0. Hence no need of marking them NULL again.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: Fix missing gb_protocol_exit() on gb_exit()
Viresh Kumar [Thu, 13 Nov 2014 12:44:33 +0000 (18:14 +0530)]
greybus: Fix missing gb_protocol_exit() on gb_exit()

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: manifest: don't free unallocated resources
Viresh Kumar [Thu, 13 Nov 2014 12:44:32 +0000 (18:14 +0530)]
greybus: manifest: don't free unallocated resources

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: manifest: initialize variable during definition
Viresh Kumar [Thu, 13 Nov 2014 12:44:31 +0000 (18:14 +0530)]
greybus: manifest: initialize variable during definition

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: manifest: no need to initialize 'result'
Viresh Kumar [Thu, 13 Nov 2014 12:44:30 +0000 (18:14 +0530)]
greybus: manifest: no need to initialize 'result'

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: gitignore: few more additions
Viresh Kumar [Thu, 13 Nov 2014 12:44:29 +0000 (18:14 +0530)]
greybus: gitignore: few more additions

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: remove unused gb_connection_handler externs
Matt Porter [Wed, 12 Nov 2014 20:59:32 +0000 (15:59 -0500)]
greybus: remove unused gb_connection_handler externs

Remove some leftover cruft from recent refactoring of
connection handlers.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: pass operation type on request receive
Alex Elder [Wed, 12 Nov 2014 21:17:55 +0000 (15:17 -0600)]
greybus: pass operation type on request receive

When an incoming request is received, the operation type is encoded
in the header and is not available in the payload.  Add the
operation type as a parameter to the request_recv method so the
request handler knows what to do.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agogreybus: op_cycle doesn't need to be atomic
Alex Elder [Wed, 12 Nov 2014 21:17:54 +0000 (15:17 -0600)]
greybus: op_cycle doesn't need to be atomic

We can update a connection's operation id counter under spinlock,
and thereby avoid the need to maintain it in an atomic variable.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agogreybus: simplify pending operations tracking
Alex Elder [Wed, 12 Nov 2014 21:17:53 +0000 (15:17 -0600)]
greybus: simplify pending operations tracking

Greg raised the alarm when I first put in the red-black tree for
tracking pending operations.  The reality as that we're not likely
to have that many operations in flight at any one time, so the
complexity of the red-black tree is most likely unwarranted.  I
already

This pulls out the red-black tree and uses a simple list instead.  A
connection maintains two lists of operations.  An operation starts
on its connection's operations list.  It is moved to the pending
list when its request message is sent.  And it is moved back to
the operations list when the response message arrives.  It is
removed from whatever list it's in when the operation is destroyed.
We reuse the single operation->links field for both lists.

Only outgoing requests are ever "pending."  Incoming requests are
transient--we receive them, process them, send the response, and
then we're done.

Change a few function names so it's clear we're working with the
pending list.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agogreybus: move timeout out of gb_operation_insert()
Alex Elder [Wed, 12 Nov 2014 21:17:52 +0000 (15:17 -0600)]
greybus: move timeout out of gb_operation_insert()

Currently, gb_operation_insert() arranges to time out a request if
it takes too long.  Move this out of that function and into
gb_operation_request_send(), so we know it's getting set up after
the request has actually be sent.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agogreybus: fix request timeout bug
Alex Elder [Wed, 12 Nov 2014 21:17:51 +0000 (15:17 -0600)]
greybus: fix request timeout bug

This commit changed the timeout behavior for operations:
    6a8732e operation: make the timeout a per-operation thing...

It unfortunately left in place some code that was only
appropriate for per-connection timeouts.  In particular,
the timer for an operation is currently getting started
only if no existing operations are in flight.

Fix that oversight, and schedule an operation's timer
unconditionally.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agogreybus: don't assume PAGE_SIZE for URB size
Alex Elder [Wed, 12 Nov 2014 21:17:50 +0000 (15:17 -0600)]
greybus: don't assume PAGE_SIZE for URB size

The buffers allocated for CPort URBS are ES1_GBUF_MSG_SIZE bytes.
But usb_fill_bulk_urb() passes PAGE_SIZE as its size.  They happen
to be the same, but the code is wrong, so fix it.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agogreybus: add pwm protocol driver
Matt Porter [Thu, 13 Nov 2014 14:14:13 +0000 (09:14 -0500)]
greybus: add pwm protocol driver

Add a PWM driver that implements the Greybus PWM protocol.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: kill gbuf->complete
Alex Elder [Thu, 6 Nov 2014 13:01:06 +0000 (07:01 -0600)]
greybus: kill gbuf->complete

The gbuf complete method is a callback that allows the creator of a
gbuf to know when all processing on a gbuf is done.

We now only ever allocate gbufs for use in Greybus operations, and
in that case we only ever supply gb_operation_gbuf_complete() as the
completion callback.  Furthermore, the only place gbuf->complete()
is called is in gb_operation_recv_work().

Knowing this, we can just call gb_operation_gbuf_complete() directly
from gb_operation_recv_work(), and get rid of the gbuf->complete()
method entirely.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: move gb_operation_gbuf_complete()
Alex Elder [Thu, 6 Nov 2014 13:01:05 +0000 (07:01 -0600)]
greybus: move gb_operation_gbuf_complete()

Simple move of a block of code, done as a separate commit to make it
easier to see that's all that's going on.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: get rid of greybus_gbuf_finished()
Alex Elder [Thu, 6 Nov 2014 13:01:04 +0000 (07:01 -0600)]
greybus: get rid of greybus_gbuf_finished()

All greybus_gbuf_finished() does is call the gbuf's complete method.
Currently, greybus_gbuf_finished() is only ever called in one place,
and that place can call the complete method directly instead.  That
allows us to eliminate greybus_gbuf_finished().

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: remove gbuf->context
Alex Elder [Thu, 6 Nov 2014 13:01:03 +0000 (07:01 -0600)]
greybus: remove gbuf->context

A gbuf now records a pointer to its operation.   The only thing ever
stored in a gbuf context pointer is the gbuf's operation.  Therefore
there's no longer any need to maintain the context pointer, so get
rid of it.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: record gbuf->operation
Alex Elder [Thu, 6 Nov 2014 13:01:02 +0000 (07:01 -0600)]
greybus: record gbuf->operation

Currently a gbuf records a pointer to the connection it's associated
with.  We now know only use gbufs in operation messages, so we can
point a gbuf at its operation instead.  This still gives access to
the connection where needed, but it also will provide all the
context we'll ever need for a gbuf, and this allows us (in the next
patch) to remove the gbuf->context field as well.

So switch to recording in a gbuf the operation rather than the
connection it is associated with.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: get rid of gbuf->actual_length
Alex Elder [Thu, 6 Nov 2014 13:01:01 +0000 (07:01 -0600)]
greybus: get rid of gbuf->actual_length

Right now, the actual_length field of a gbuf is only ever assigned,
never used.  We now fill gbufs only with operation messages, and
they encode within them the amount of space "actually used" in a
buffer in a request-specific way.  As a result, there's no need
for the gbuf->actual_length field, so we can remove it.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: kill old cport handler code
Alex Elder [Thu, 6 Nov 2014 13:01:00 +0000 (07:01 -0600)]
greybus: kill old cport handler code

Handling of incoming requests has been moved into the Greybus
connection and protocol layers.  As a result, the original cport
oriented handler code is no longer used.  So get rid of it.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: kill test_sink.c
Alex Elder [Thu, 6 Nov 2014 13:00:59 +0000 (07:00 -0600)]
greybus: kill test_sink.c

This file is an artifact of some early testing, but it is otherwise
unused.  So get rid of it.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: add an incoming request receive method
Alex Elder [Wed, 5 Nov 2014 22:12:55 +0000 (16:12 -0600)]
greybus: add an incoming request receive method

Define a new protocol method intended to handle the receipt of an
incoming operation request.  Most protocols have no expected
incoming requests and can leave this null.  If a request arrives for
a protocol with no request receive handler an error is reported and
the request fails.

Get rid of the previous fixed array of receive handlers, it's
no longer needed.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: move methods into protocol
Alex Elder [Wed, 5 Nov 2014 22:12:54 +0000 (16:12 -0600)]
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>
10 years agogreybus: register preallocated protocols
Alex Elder [Wed, 5 Nov 2014 22:12:53 +0000 (16:12 -0600)]
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>
10 years agogreybus: order the protocols list
Alex Elder [Wed, 5 Nov 2014 22:12:52 +0000 (16:12 -0600)]
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>
10 years agogreybus: count rather than list protocol users
Alex Elder [Wed, 5 Nov 2014 22:12:51 +0000 (16:12 -0600)]
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>
10 years agogreybus: identify protocol by id *and* version
Alex Elder [Wed, 5 Nov 2014 22:12:50 +0000 (16:12 -0600)]
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>
10 years agogreybus: improve some error messages
Alex Elder [Wed, 5 Nov 2014 22:03:12 +0000 (16:03 -0600)]
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>
10 years agogreybus: control printing message
Alex Elder [Wed, 5 Nov 2014 22:03:11 +0000 (16:03 -0600)]
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>
10 years agogreybus: make _gb_protocol_find() static
Alex Elder [Wed, 5 Nov 2014 22:03:10 +0000 (16:03 -0600)]
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>
10 years agogreybus: drop a redundant assignment
Alex Elder [Wed, 5 Nov 2014 22:03:09 +0000 (16:03 -0600)]
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>
10 years agogreybus: fix a bug in gb_operation_gbuf_complete()
Alex Elder [Wed, 5 Nov 2014 22:03:08 +0000 (16:03 -0600)]
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>
10 years agogreybus: build: Add -fno-pic for 32bit arm as well
John Stultz [Thu, 30 Oct 2014 22:28:18 +0000 (15:28 -0700)]
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>
10 years agogreybus: connection: fix up error patch logic in gb_connection_create()
Greg Kroah-Hartman [Wed, 29 Oct 2014 01:57:08 +0000 (09:57 +0800)]
greybus: 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>
10 years agogreybus: introduce protocol abstraction
Alex Elder [Wed, 29 Oct 2014 00:36:00 +0000 (19:36 -0500)]
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>
10 years agogreybus: use protocol_id for numeric values
Alex Elder [Wed, 29 Oct 2014 00:35:59 +0000 (19:35 -0500)]
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>
10 years agogreybus: drop the cport id on error
Alex Elder [Wed, 29 Oct 2014 00:35:58 +0000 (19:35 -0500)]
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>
10 years agogreybus: connection: call connection_init hook after setting the handler
Matt Porter [Tue, 28 Oct 2014 14:08:13 +0000 (10:08 -0400)]
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>
10 years agogreybus: module: set device_id when initializing an interface
Matt Porter [Tue, 28 Oct 2014 14:08:12 +0000 (10:08 -0400)]
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>
10 years agogreybus: es1-ap-usb: document the lack of callback for the outgoing bulk urbs
Greg Kroah-Hartman [Tue, 28 Oct 2014 10:20:24 +0000 (18:20 +0800)]
greybus: 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>
10 years agogreybus: Remove id_table usages
Greg Kroah-Hartman [Tue, 28 Oct 2014 09:49:59 +0000 (17:49 +0800)]
greybus: 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>
10 years agogreybus: #if 0 cleanups
Greg Kroah-Hartman [Tue, 28 Oct 2014 09:09:35 +0000 (17:09 +0800)]
greybus:  #if 0 cleanups

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

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: Merge branch 'master' into driver_model_rework
Greg Kroah-Hartman [Tue, 28 Oct 2014 02:30:18 +0000 (10:30 +0800)]
greybus: Merge branch 'master' into driver_model_rework

10 years agogreybus: sdio-gb: convert to the connection interface.
Greg Kroah-Hartman [Tue, 28 Oct 2014 02:17:09 +0000 (10:17 +0800)]
greybus: sdio-gb: convert to the connection interface.

No one is using sdio yet, but convert to the connection interface to
remove the last user of the "old" module interface.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: battery-gb: remove some #if 0 code
Greg Kroah-Hartman [Tue, 28 Oct 2014 01:50:56 +0000 (09:50 +0800)]
greybus: battery-gb: remove some #if 0 code

We aren't going to have individual modules for the gb protocols, so just
remove this useless code, it was throwing up warnings in sparse.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: uart-gb: mark some functions static
Greg Kroah-Hartman [Tue, 28 Oct 2014 01:49:33 +0000 (09:49 +0800)]
greybus: uart-gb: mark some functions static

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: begin abstracting connection operations
Alex Elder [Mon, 27 Oct 2014 11:04:30 +0000 (06:04 -0500)]
greybus: begin abstracting connection operations

This is part 1 of abstracting the connection operations into a set
of methods.  This will avoid some big switch statements, but more
importantly this will be needed for supporting multiple versions of
each protocol.

For now only two methods are defined.  The init method is used
to set up the device (or whatever the CPort represents) and the exit
method tears it down.  There may need to be additional operations
added in the future, and once versioning is used we might stash
the version number in this structure as well.

The next patch adds dynamic registratration of these protocol
handlers, and will do away with the switch statement now found
in gb_connection_init().

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: kernel_ver.h: add ATTRIBUTE_GROUPS() macro for older kernels
Greg Kroah-Hartman [Tue, 28 Oct 2014 01:27:50 +0000 (09:27 +0800)]
greybus: kernel_ver.h: add ATTRIBUTE_GROUPS() macro for older kernels

This was added in 3.11, and we need it for 3.10

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: module: remove unneeded XXX comment about module id values
Greg Kroah-Hartman [Mon, 27 Oct 2014 10:00:13 +0000 (18:00 +0800)]
greybus: module: remove unneeded XXX comment about module id values

We do properly check for duplicate module ids, as fixed in
008d85d90ae1ab31f1f7b80f245f6ee2eb5aed49 "module: don't create duplicate
module ids", so remove the XXX marker.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agogreybus: FIXME/XXX removals: We have proper reference counting now
Greg Kroah-Hartman [Mon, 27 Oct 2014 09:58:54 +0000 (17:58 +0800)]
greybus: FIXME/XXX removals: We have proper reference counting now

Now that we have proper reference counting for modules, interfaces, and
connections, no need to worry about grabbing a pointer to your "parent"
structure, all is good.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: uart-gb: remove global init functions
Greg Kroah-Hartman [Mon, 27 Oct 2014 09:42:45 +0000 (17:42 +0800)]
greybus: uart-gb: remove global init functions

The uart-gb code needs to init the tty core before it can add devices.
Previously we hard-coded this in the greybus core, move this to be
"dynamic" and self-contained within the uart-gb.c file.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: uart-gb: convert over to the connection interface
Greg Kroah-Hartman [Mon, 27 Oct 2014 09:32:34 +0000 (17:32 +0800)]
greybus: uart-gb: convert over to the connection interface

Move the uart code over to use the "new" connection interface, instead
of the "old" module interface.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: embed the i2c adapter struct
Alex Elder [Mon, 27 Oct 2014 08:48:32 +0000 (03:48 -0500)]
greybus: embed the i2c adapter struct

We don't need to dynamically allocate the i2c adapter structure, we
can just embed it right in struct gb_i2c_device.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: gpio: kill gpio_controller->gpio
Alex Elder [Mon, 27 Oct 2014 08:48:31 +0000 (03:48 -0500)]
greybus: gpio: kill gpio_controller->gpio

This field is never used (and not needed) so get rid of it.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: operation: make the timeout a per-operation thing, not per-connection
Greg Kroah-Hartman [Mon, 27 Oct 2014 07:40:09 +0000 (15:40 +0800)]
greybus: operation: make the timeout a per-operation thing, not per-connection

An operation is what can timeout, not a connection itself.  So notify
the operation timedout, and the connection can then do with it as it
sees fit, if necessary.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: core: make greybus_kill_gbuf not return a value
Greg Kroah-Hartman [Mon, 27 Oct 2014 06:01:06 +0000 (14:01 +0800)]
greybus: core: make greybus_kill_gbuf not return a value

We can't do anything if killing a gbuf fails, so just make this function
"always" be successful.

At the same time, make the host controller function also be called
"kill_gbuf" to keep the terminology in sync.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
10 years agogreybus: core: check for valid hcd callbacks
Greg Kroah-Hartman [Mon, 27 Oct 2014 05:32:27 +0000 (13:32 +0800)]
greybus: core: check for valid hcd callbacks

When registering a host controller, verify that all of the needed
callbacks are present, so we don't have to do the testing on any "hot"
paths when we want to send real data.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org.
10 years agogreybus: gbuf: implement gbuf_kill_gbuf()
Greg Kroah-Hartman [Mon, 27 Oct 2014 05:31:01 +0000 (13:31 +0800)]
greybus: gbuf: implement gbuf_kill_gbuf()

Hook up gbuf_kill_gbuf() by implementing yet-another-host-controller
callback and a gbuf-specific pointer to hold the tracking data the hcd
needs in order to be able to abort a transfer.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
10 years agogreybus: gpio-gb: fix some endian sparse warnings that were real.
Greg Kroah-Hartman [Mon, 27 Oct 2014 04:33:47 +0000 (12:33 +0800)]
greybus: gpio-gb: fix some endian sparse warnings that were real.

Not like we are ever going to use a BE cpu, but it's good to be
"correct"...

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: operation: fix some sparse warnings
Greg Kroah-Hartman [Mon, 27 Oct 2014 04:30:15 +0000 (12:30 +0800)]
greybus: operation: fix some sparse warnings

One of which was "real".

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: module: don't create duplicate module ids
Greg Kroah-Hartman [Fri, 24 Oct 2014 10:46:15 +0000 (18:46 +0800)]
greybus: module: don't create duplicate module ids

If we somehow get a hotplug event for a module id that we already have
created[1], don't try to create it again, or sysfs will complain loudly.
Instead, abort the creation properly.

[1] If, for example, you happened to run a script on a greybus emulator
twice in a row...

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
10 years agogreybus: i2c: point to the proper parent device
Greg Kroah-Hartman [Fri, 24 Oct 2014 10:33:59 +0000 (18:33 +0800)]
greybus: i2c: point to the proper parent device

Use the connection, not the host controller, as the parent device of the
i2c device.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: module: enable all sysfs attributes
Greg Kroah-Hartman [Fri, 24 Oct 2014 09:54:02 +0000 (17:54 +0800)]
greybus: module: enable all sysfs attributes

We were thinking that module attributes were known at the time the
device was created in the system, so we could query them to know if the
sysfs file was present or not.  Unfortunatly that's not the case, we
create the device before we parse the values, so just always show the
sysfs attributes.  If there is no such attribute, the sysfs file will be
empty (i.e. for the string attributes.)

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: fix repeated input errors
Alex Elder [Fri, 24 Oct 2014 10:02:02 +0000 (05:02 -0500)]
greybus: fix repeated input errors

I screwed up the error handling in a patch the other day.  If we get
an error on an input URB we should not re-submit it.

Signed-off-by: Alex Elder <elder@linaro.org>
10 years agogreybus: hook up greybus to the driver model
Greg Kroah-Hartman [Fri, 24 Oct 2014 09:34:46 +0000 (17:34 +0800)]
greybus: hook up greybus to the driver model

This patch hooks up modules, interfaces, and connections to the driver
model.  Now we have a correct hierarchy, and drivers can be correctly
bound to the proper portions in the future.  Devices are correctly
reference counted and torn down in the proper order on removal of a
module.

Some basic sysfs attributes have been created for interfaces and
connections.  Module attributes are not working properly, but that will
be fixed in future changes.

This has been tested on Alex's machine, with multiple hotplug and unplug
operations of a module working correctly.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agogreybus: update AP id service message
Alex Elder [Wed, 22 Oct 2014 10:36:18 +0000 (05:36 -0500)]
greybus: update AP id service message

Rename and renumber the values for the AP ID service message
and related symbols to match the recently-updated spec.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: set route before sending packets
Alex Elder [Wed, 22 Oct 2014 10:36:17 +0000 (05:36 -0500)]
greybus: set route before sending packets

The route for a connection needs to be set *before* we initialize
the connection.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: svc: remove the DDB function message support
Matt Porter [Wed, 22 Oct 2014 07:22:48 +0000 (03:22 -0400)]
greybus: svc: remove the DDB function message support

We removed the DDB function messages from the spec as they are
not needed. Now remove it from the code.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: only initialize interfaces when up
Alex Elder [Wed, 22 Oct 2014 07:04:32 +0000 (02:04 -0500)]
greybus: only initialize interfaces when up

Rather than bringing up all interfaces described in the manifest,
wait until we get a link up message, and at that time go initialize
the link.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: make svc_set_route_send() public
Alex Elder [Wed, 22 Oct 2014 07:04:31 +0000 (02:04 -0500)]
greybus: make svc_set_route_send() public

Give svc_set_route_send() non-private scope so it can be used by a
function outside "ap.c" in the next patch.  Change its type so it
can tell its caller if an error occurs.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: define connection state
Alex Elder [Wed, 22 Oct 2014 07:04:30 +0000 (02:04 -0500)]
greybus: define connection state

Define the state of a connection.  A connection will not be
enabled until it has been successfully set up.  Once it starts
getting torn down its state will move to "being destroyed".

Don't send any operation request messages unless the connection is
enabled.  And drop any incoming messages if if the connection is
not enabled.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: define operation_cancel()
Alex Elder [Wed, 22 Oct 2014 07:04:29 +0000 (02:04 -0500)]
greybus: define operation_cancel()

Define a new function operation_cancel() that cancels an
outstanding operation.  Use it to clear out any operations that
might be pending at the time a connection is torn down.

Note:  This code isn't really functional yet, partially because
greybus_kill_gbuf() is not implemented.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: time out operation requests
Alex Elder [Wed, 22 Oct 2014 07:04:28 +0000 (02:04 -0500)]
greybus: time out operation requests

Arrange for operation requests that takke too long to time out.
At the moment, nothing happens when that occurs (other than a silly
message getting printed).  When the connection and operation and
interface and module code are cleaned up properly, this event should
most likely cause the affected module to get torn down.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: module: fix double free of module
Greg Kroah-Hartman [Wed, 22 Oct 2014 08:38:07 +0000 (16:38 +0800)]
greybus: module: fix double free of module

Also properly clean up all modules when you remove a host driver

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
10 years agogreybus: ap: add svc_set_route_send() command and use it on a link up event
Matt Porter [Wed, 22 Oct 2014 06:06:09 +0000 (02:06 -0400)]
greybus: ap: add svc_set_route_send() command and use it on a link up event

When the AP receives a link up event, request that the SVC set a
route to the interface's device id (this device id has been
previously reported to the AP). In the future, we may not always
immediately set a route upon receiving a link up event but this
is sufficient for the known use cases at this time.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
10 years agogreybus: svc: remove unneeded fields from the unipro set route message payload
Matt Porter [Wed, 22 Oct 2014 06:06:08 +0000 (02:06 -0400)]
greybus: svc: remove unneeded fields from the unipro set route message payload

CPort connections are being handled in the application layer connection
protocol and the layer 3 switch doesn't care about them. Also, the
switch doesn't care about a source device id when setting up the route
table. Reduce the message to just the necessary destination device ID.

As the SVC is aware of which switch port it found the module/interface
and assigned the device ID, we can simply tell the SVC to set a route
to the device ID it has reported to the AP as being active.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>