Commit graph

430 commits

Author SHA1 Message Date
Alex Elder 2c43ce4967 greybus: use a simple list of hd connections
First of all, there's a bug in _gb_hd_connection_insert, which
Viresh found.  But pointing out that problem just called attention
to the fact that I have planning to to remove the affected block of
code.

The set of connections associated with a host device is currently
maintained in a red-black tree.  The number of connections we're
likely to have is on the order of a hundred, and at least for now
isn't even going to approach that.  When this code first went in,
Greg asserted that using a list is speedier than a red-black tree
for smallish numbers of elements (maybe up to a few hundred?).

So this patch just removes the host device's red-black tree of
connections, using a simple list instead.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-17 10:41:19 -08:00
Alex Elder ba99346828 greybus: record the host device in a gbuf
The only thing we now use the gbuf->operation pointer for is
to get access to its connection's host device.

Record the host device pointer directly in the gbuf, rather
than keeping a pointer to the operation.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-17 10:41:19 -08:00
Alex Elder 6af29086bf greybus: use gbuf's destination cport id
If the buffer allocated in the ES1 alloc_gbuf_data() routine is for
outbound data, we are getting the destination CPort id from the
connection.  Switch to using the copy of the destination cport id
we now have in the gbuf instead.

Check for a valid CPort id there only if we're inserting it into
the buffer.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-17 10:41:19 -08:00
Alex Elder 63921d8872 greybus: record a gbuf's destination CPort id
Rather than indicating whether a gbuf is intended for outbound data,
record its destination CPort id.  That's what's really needed by
the ES1 host driver.  Use CPORT_ID_BAD when the buffer is intended
for inbound data.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-17 10:41:19 -08:00
Alex Elder c7d0f258fb greybus: reference count operations
Add a reference counter to the operations structure.  We'll
need this when operations are actually allowed to complete
asynchronously.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-17 10:41:19 -08:00
Alex Elder 78496db012 greybus: clean up gb_connection_operation_recv()
This patch does some cleanup of gb_connection_operation_recv().
    - Improve the header comments
    - Verify message is big enough for header before interpreting
      beginning of the message as a header
    - Verify at buffer creation time rather than receive time that
      no operation buffer is bigger than the maximum allowed.  We
      can then compare the incoming data size against the buffer.
    - When a response message arrives, record its status in the
      operation result, not in the buffer status.
    - Record a buffer overflow as an operation error.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-17 10:41:19 -08:00
Alex Elder b37716f672 greybus: kill gb_operation_gbuf_complete()
It's possible this function was destined to do something important,
but at this point it's pretty pointless.  Get rid of it.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-17 10:41:19 -08:00
Alex Elder ea590d5cbd greybus: delete some lines in "greybus.h"
This gets rid of a block of unnecessary forward declarations in
"greybus.h".

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-17 10:41:19 -08:00
Alex Elder 19363a2ca1 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>
2014-11-17 10:41:19 -08:00
Greg Kroah-Hartman b4be404352 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>
2014-11-15 19:00:49 -08:00
Greg Kroah-Hartman 0ac5a83881 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>
2014-11-15 12:12:16 -08:00
Greg Kroah-Hartman 86bf33afa3 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>
2014-11-14 14:37:56 -08:00
Greg Kroah-Hartman b7be8d2eb3 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>
2014-11-14 14:37:32 -08:00
Viresh Kumar 2206ea9cf8 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>
2014-11-14 13:49:04 -08:00
Viresh Kumar 676daaf458 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>
2014-11-14 13:49:04 -08:00
Viresh Kumar 9ca4d62f15 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>
2014-11-14 13:49:04 -08:00
Viresh Kumar 577f5f974c 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>
2014-11-14 13:49:04 -08:00
Viresh Kumar ab34291da5 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>
2014-11-14 13:49:04 -08:00
Viresh Kumar 1dd90df403 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>
2014-11-14 13:32:27 -08:00
Viresh Kumar 38d61ddf95 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>
2014-11-14 13:32:27 -08:00
Viresh Kumar f66832dae0 greybus: nullify dangling pointers
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-14 13:32:27 -08:00
Viresh Kumar 837b3b7c04 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>
2014-11-14 13:32:27 -08:00
Viresh Kumar 95bd99def5 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>
2014-11-14 13:32:27 -08:00
Viresh Kumar 3dc05f1871 greybus: core: remove unnecessary braces
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-14 13:32:27 -08:00
Viresh Kumar 219871e252 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>
2014-11-14 13:19:16 -08:00
Viresh Kumar 85f3aeeda6 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>
2014-11-14 13:19:16 -08:00
Viresh Kumar a68bd742c0 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>
2014-11-14 13:18:26 -08:00
Viresh Kumar b97c46ecaf 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>
2014-11-14 13:18:26 -08:00
Viresh Kumar 0a68a16b91 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>
2014-11-14 13:17:55 -08:00
Viresh Kumar 132d03ea89 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>
2014-11-14 13:17:55 -08:00
Viresh Kumar 37d8afc42b 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>
2014-11-14 13:16:05 -08:00
Viresh Kumar 669f5faf84 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>
2014-11-14 13:16:05 -08:00
Viresh Kumar 35a52cafbc 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>
2014-11-14 13:16:05 -08:00
Viresh Kumar 50fc08f8c0 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>
2014-11-14 13:16:05 -08:00
Viresh Kumar 4ed16a81c1 greybus: manifest: initialize variable during definition
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-14 13:14:37 -08:00
Viresh Kumar 43d9431f6b 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>
2014-11-14 13:14:37 -08:00
Viresh Kumar e2f345ab40 greybus: gitignore: few more additions
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-14 13:14:37 -08:00
Matt Porter 437caa8a0c 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>
2014-11-14 13:12:57 -08:00
Alex Elder c3cf278533 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>
2014-11-14 13:11:35 -08:00
Alex Elder 360a8779d9 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>
2014-11-14 13:11:35 -08:00
Alex Elder b8616da875 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>
2014-11-14 13:11:35 -08:00
Alex Elder 8350e7a011 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>
2014-11-14 13:11:35 -08:00
Alex Elder 10520528fe 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>
2014-11-14 13:11:35 -08:00
Alex Elder 3e9cb4a118 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>
2014-11-14 13:11:35 -08:00
Matt Porter 34c6507ca8 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>
2014-11-14 13:10:21 -08:00
Alex Elder 5d2207e704 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>
2014-11-06 08:03:36 -08:00
Alex Elder 3a0e3c3efd 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>
2014-11-06 08:03:35 -08:00
Alex Elder eecf6deb57 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>
2014-11-06 08:03:35 -08:00
Alex Elder a77b06809b 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>
2014-11-06 08:03:35 -08:00
Alex Elder ef45fa33a4 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>
2014-11-06 08:03:35 -08:00
Alex Elder c69a50f2ce 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>
2014-11-06 08:03:35 -08:00
Alex Elder 7a0eed065d 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>
2014-11-06 08:03:35 -08:00
Alex Elder 8d59897978 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>
2014-11-06 08:03:35 -08:00
Alex Elder f8fb05e2b8 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>
2014-11-05 14:23:50 -08:00
Alex Elder 5d9fd7e1ba 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>
2014-11-05 14:23:50 -08:00
Alex Elder 19d03decd3 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>
2014-11-05 14:23:50 -08:00
Alex Elder dbb8894e0c 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>
2014-11-05 14:21:24 -08:00
Alex Elder 0e44765743 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>
2014-11-05 14:21:24 -08:00
Alex Elder 6ae7fa4520 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>
2014-11-05 14:21:24 -08:00
Alex Elder 6b09938a48 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>
2014-11-05 14:12:26 -08:00
Alex Elder 545a697512 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>
2014-11-05 14:12:26 -08:00
Alex Elder 0570afcf24 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>
2014-11-05 14:12:25 -08:00
Alex Elder 00ace97390 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>
2014-11-05 14:12:25 -08:00
Alex Elder 96fd8c2bfd 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>
2014-11-05 14:12:25 -08:00
John Stultz 2dcf6871dd 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>
2014-10-30 15:33:38 -07:00
Greg Kroah-Hartman 4b640bb135 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>
2014-10-29 09:57:08 +08:00
Alex Elder 4ccb6b7abb 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>
2014-10-29 08:42:44 +08:00
Alex Elder 7fba0079ad 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>
2014-10-29 08:42:17 +08:00
Alex Elder b29699602d 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>
2014-10-29 08:42:17 +08:00
Matt Porter 755a21a9bf 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>
2014-10-29 07:47:56 +08:00
Matt Porter 53cbb00933 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>
2014-10-29 07:47:56 +08:00
Greg Kroah-Hartman f9ab34c2bf 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>
2014-10-28 18:20:24 +08:00
Greg Kroah-Hartman cea54c12f7 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>
2014-10-28 17:49:59 +08:00
Greg Kroah-Hartman c7a90cb599 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>
2014-10-28 17:09:35 +08:00
Greg Kroah-Hartman a25f375cf7 greybus: Merge branch 'master' into driver_model_rework 2014-10-28 10:30:18 +08:00
Greg Kroah-Hartman a2f4763f48 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>
2014-10-28 10:17:09 +08:00
Greg Kroah-Hartman 5e8e8ff6d0 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>
2014-10-28 09:50:56 +08:00
Greg Kroah-Hartman 059b093616 greybus: uart-gb: mark some functions static
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-28 09:49:33 +08:00
Alex Elder 3689f9744a 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>
2014-10-28 09:47:09 +08:00
Greg Kroah-Hartman f348964c26 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>
2014-10-28 09:27:50 +08:00
Greg Kroah-Hartman eec5883f51 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>
2014-10-27 18:00:13 +08:00
Greg Kroah-Hartman 6507cced6b 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>
2014-10-27 17:58:54 +08:00
Greg Kroah-Hartman 4d98098942 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>
2014-10-27 17:42:45 +08:00
Greg Kroah-Hartman aed0bc6e68 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>
2014-10-27 17:32:34 +08:00
Alex Elder 81f4e22732 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>
2014-10-27 16:53:10 +08:00
Alex Elder 81d631cae8 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>
2014-10-27 16:53:10 +08:00
Greg Kroah-Hartman 708971e43c 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>
2014-10-27 15:40:09 +08:00
Greg Kroah-Hartman 4afbba0703 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>
2014-10-27 15:05:03 +08:00
Greg Kroah-Hartman 724b619dfb 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.
2014-10-27 13:45:24 +08:00
Greg Kroah-Hartman d81448849a 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>
2014-10-27 13:45:24 +08:00
Greg Kroah-Hartman d4c8247b56 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>
2014-10-27 12:33:47 +08:00
Greg Kroah-Hartman f9624ded90 greybus: operation: fix some sparse warnings
One of which was "real".

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-27 12:30:15 +08:00
Greg Kroah-Hartman 066799c18f 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>
2014-10-24 19:00:21 +08:00
Greg Kroah-Hartman 3e6d5f3a61 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>
2014-10-24 18:36:24 +08:00
Greg Kroah-Hartman 44dd970be9 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>
2014-10-24 18:36:24 +08:00
Alex Elder c4a432d3db 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>
2014-10-24 18:36:24 +08:00
Greg Kroah-Hartman f0f61b9042 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>
2014-10-24 17:40:59 +08:00
Alex Elder 2d5e4fa9dc 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>
2014-10-22 18:46:21 +08:00
Alex Elder 65e50f95f1 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>
2014-10-22 18:46:21 +08:00
Matt Porter 8a9bf8a996 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>
2014-10-22 18:29:35 +08:00
Alex Elder c41b4f1212 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>
2014-10-22 17:22:22 +08:00
Alex Elder 525f1467bc 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>
2014-10-22 17:20:28 +08:00
Alex Elder 36561f23a8 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>
2014-10-22 17:20:28 +08:00
Alex Elder e1158df063 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>
2014-10-22 17:20:28 +08:00
Alex Elder e816e37419 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>
2014-10-22 17:20:28 +08:00
Greg Kroah-Hartman 63e4a8ee8f 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>
2014-10-22 16:38:07 +08:00
Matt Porter 060b93ddbb 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>
2014-10-22 14:12:17 +08:00
Matt Porter e390b193d6 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>
2014-10-22 14:12:17 +08:00
Matt Porter 6232b073d4 greybus: ap: process the UniPro link up message
The link up message is the event that tells the AP what device ID
has been assigned to a particular interface on a module during
enumeration. The link up is sent *only* after the hotplug event
for a particular module has been sent to the AP.

The link up payload must carry the Module ID and Interface ID
to uniquely identify the struct gb_interface to which the
Device ID has been assigned.

After processing of the link up message, the interface's device_id
field will contain the assigned Device ID so that the AP has the
information necessary to issue network route commands.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-22 13:57:49 +08:00
Matt Porter 1a4c013a44 greybus: interface: add gb_interface_find()
Add support for getting a struct gb_interface from an
Interface ID.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-22 13:57:49 +08:00
Matt Porter 6271b5bac9 greybus: module: add gb_module_find()
Add support for getting a struct gb_module from a
Module ID.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-22 13:57:49 +08:00
Greg Kroah-Hartman 0369a45998 greybus: battery-gb: Allow kernel values to get out of sync with greybus spec
We can't know that the greybus values and the kernel values for a number
of battery enumerated types will remain in sync.  And as theses are sent
by an external device from the kernel, we have to explicitly check these
values.

Reported-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 16:25:13 +08:00
Greg Kroah-Hartman c9346e19b2 greybus: battery-gb.c: fix memory leak found by Viresh
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 15:51:53 +08:00
Greg Kroah-Hartman cc662399dc greybus: Merge branch 'gregkh_work' into master
This pulls in the battery driver work I did there.
2014-10-21 14:37:44 +08:00
Matt Porter 98f4ab2df9 greybus: ap: add support for the AP Device ID unipro management function message
The AP needs to know its assigned Device ID in order to establish
Greybus connections between CPorts. We could have pulled the Device
ID from the controller hardware in a driver specific manner, but
instead we define one generic message from the SVC to let the
AP know this information. Add this additional unipro management
message and handle it by setting the supplied Device ID in the
struct greybus_host_device. The greybus core will use this to
populate the source Device ID when establishing a connection
between the AP and another module's CPort.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 14:37:21 +08:00
Alex Elder 697e55d35d greybus: improve module cleanup code
When a module gets destroyed all of its state and the state of its
interfaces and connections (etc.) need to be torn down.  This is
not now being done properly.  Add this teardown code.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 14:36:11 +08:00
Alex Elder fb305c335c greybus: stash power supply pointer in connection
The battery code was not stashing a copy of its private data
pointer.  It'll be needed in the next patch.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 14:36:11 +08:00
Alex Elder 03130a77d5 greybus: fix op_cycle logic
The function that computes the operation id for a connection is
wrongly using MOD rather than AND.  Fix that.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 14:36:11 +08:00
Greg Kroah-Hartman c0855bfdd6 greybus: battery-gb: Add battery communication with the module
This adds support to talk to the battery to get the various requests
made to it, based on the battery protocol defined in the Greybus
Specification.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 14:31:24 +08:00
Alex Elder 1ec1d6dd35 greybus: leverage ap_disconnect() in ap_probe()
With a few minor changes, ap_disconnect() can correctly handle
cleaning up even a partially initialized USB interface.  Make those
changes, and then use ap_disconnect() to simplify cleanup for all
the error paths in ap_probe().  Reset all fields as they're cleaned
up to facilitate debugging.

Signed-off-by: Alex Elder <elder@linaro.org>
2014-10-21 06:32:01 +08:00
Alex Elder 6892537f61 greybus: move ap_disconnect()
The next patch has ap_probe() reference ap_disconnect().  To prepare
for that, move ap_disconnect() up in the file.

This is done as a separate commit to make it easier to see this move
involves no other change to that function.  This and the next commit
can be squashed if desired.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 06:28:24 +08:00
Alex Elder 6ff5e00a17 greybus: remove cports and strings from gb_module
We no longer keep copies of strings found in the manifuest in
a module's strings array, so we can get rid of the strings array.
Similarly, the new manifest parsing code sets up connections for
each cport id advertised for a module, so the cport array is
no longer needed either.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 06:28:23 +08:00
Alex Elder 09c521dc0a greybus: drop gb_* device fields from gb_module
A struct gb_module has a bunch of fields from the earlier skeleton
code, where a module was assumed to possibly have one of every
type of device available on the GP Bridge.  The manifest parsing
code changed it so these things will be related to connection
endpoints, so these gb_module fields are no longer needed.

A few of these (battery and sdio) haven't been implemented the "new
way" yet, so just leave a bit of the code that was there commented
out for now.

Also, gb_tty seems to be partially implemented and I don't want to
remove that without knowing where it's headed, so that one stays.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 06:27:37 +08:00
Alex Elder 5b3db0ddaa greybus: create a slab cache for operations
Everything we do on greybus will involve an operation, so create a
slab cache for that frequently-allocated data structure.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 06:25:54 +08:00
Alex Elder 599dc6aa8e greybus: properly drop device reference
Drop the USB device reference taken at the top of ap_probe() in the
event greybus_create_hd() fails.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 06:25:54 +08:00
Viresh Kumar 6813e35a0e greybus: .gitignore: minor updates
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 06:22:32 +08:00
Viresh Kumar 8597e6b2b9 greybus: Fix parameters of core_param()
core_param() takes four parameters instead of three and so results in this
compilation error:

greybus/core.c:25:33: error: macro "core_param" requires 4 arguments, but only 3 given
 core_param(nogreybus, bool, 0444);
                                 ^

Fix this by adding proper arguments to it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 06:22:32 +08:00
Matt Porter ff6e0b9c2f greybus: gpio-gb: fix offset error checking and usage
Offset (or hwgpio num) is the offset within a gpiochip, not the
unique gpio namespace number. Adjust the error checking and use
of offset in our operation calls to fix this.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 06:22:32 +08:00
Greg Kroah-Hartman 42d4a22d6b greybus: add LED protocol numbers 2014-10-20 16:02:56 +08:00
Greg Kroah-Hartman 2bb7eae8be greybus: battery: some hooking up to the greybus core
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-20 15:24:57 +08:00
Matt Porter 47ee0d135e greybus: gpio-gb: remove unused status field from struct gb_gpio_get_value_request
probably a cut and paste error got this unused status field. remove it.

Signed-off-by: Matt Porter <mporter@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-20 15:11:25 +08:00
Greg Kroah-Hartman 43789c319e greybus: battery-gb: provide accessors for a few more functions
Put the hard coded values in a function to make it easier to see what
needs to be done here.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-20 15:09:49 +08:00
Greg Kroah-Hartman 213aefe206 greybus: gpio-gb: allow it to build properly for all current kernel versions.
GPIO remove changed the api for 3.17 to try to make up for some
previously foolish design decisions.  Handle that in kernel_ver.h to
make the code simple.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-20 13:40:02 +08:00
Greg Kroah-Hartman 6ce3e03f71 greybus: greybus_manifest.h: fix up class protocol numbers to match the spec.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-20 13:27:42 +08:00
Alex Elder f012a520e1 greybus: report gbuf errors
If a gbuf completion indicates an error has occurred, report it.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-18 12:38:55 +02:00
Alex Elder bedfdf3056 greybus: update gbuf status for completion handlers
Currently, if a USB urb completes with an error, that error status
is not transferred back to the gbuf that it's associated with.  For
inbound data there's not a lot we can do about an error, but for
outbound data, this means there is no notification to the submitter
that something went wrong.

For outbound data copy the urb status directly back to the gbuf as
its status.  Follow USB's lead and set the status to -EINPROGRESS
while a gbuf is "in flight."  Assign a gbuf an initial status value
of -EBADR to help identify use of never-set status values.

When an inbound urb fails (SVC or CPort), currently the urb is just
leaked, more or less (i.e., we lose an urb posted to receive
incoming data).  Change that so such an error is reported, but
then re-submitted.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:15:25 +02:00
Alex Elder d75286852b greybus: add write retry support for i2c
It is expected that i2c writes may fail, and in that case the driver
simply retries some number of times before actually treating it as a
failure.  Define a GB_OP_RETRY status, which is interpreted by the
i2c driver as an indication a retry is in order.  We just translate
that into an EAGAIN error passed back to the i2c core.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:15:23 +02:00
Alex Elder bb2e1c9626 greybus: initial operations-based GPIO driver
First cut.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:14:11 +02:00
Alex Elder ed8800dc37 greybus: add i2c driver
This patch adds the i2c driver, based on the use of Greybus operations
over Greybus connections.  It basically replaces almost all of what
was previously found in "i2c-gb.c".

When gb_connection_device_init(connection) is called, any connection
that talks the GREYBUS_PROTOCOL_I2C is passed to gb_i2c_device_init()
to be initialized.

Initialization involves verifying the code is able to support the
version of the protocol.  For I2C, we then query the functionality
mask, and set the retry count and timeout to default values.

After that, we set up the i2c device and associate it with the
connection.  The i2c_algorithm methods are then implemented
by translating them into Greybus operations.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:14:11 +02:00
Alex Elder 98d35ba22e greybus: kill old cport handlers
The original CPort message handlers are not needed.  All incoming
data is passed to handlers based on the protocol used over the
connection over which the data was transferred.  So get rid of the
old CPort handler code.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:14:11 +02:00
Alex Elder c149f8ffb2 greybus: kill off gbuf work queue
At this point all incoming messages are handled by the operation
code, so this obviates the need for the gbuf workqueue.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:14:11 +02:00
Alex Elder 574341c672 greybus: add device initialization
Set up the infrastructure for initializing connections based on
their protocol.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:14:11 +02:00
Alex Elder 2eb585f8df greybus: move receive handling to operation layer
Create a work queue to do the bulk of processing of received
operation request or response messages.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:13:15 +02:00
Alex Elder d90c25b0a2 greybus: let operation layer examine incoming data
Give the operation layer a chance to examine incoming data so that
it can handle it appropriately.

Treat the data as an operation message header.  If it's a response,
look up the operation it's associated with.  If it's not, create a
new operation.  Copy the incoming data into the request or response
buffer.  The next patch adds a work queue to pick up handling
the request or response from there.

Get rid of gb_operation_submit().  Instead, we have two functions,
one for sending an operation's request message, the other for
sending an operation's response message.

Not fully functional yet, still just filling things in...

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:13:15 +02:00
Alex Elder 84d148b10e greybus: add gb_operation_find()
Add a red-black tree indexed by operation id to a connection to
allow pending operations (whose requests are in-flight) to be
found when their matching response is recieved.

Assign the id at the time an operation is inserted, and update
the operation's message header(s) to include it.

Rename gb_connection_op_id() to be more consistent with the
naming conventions being used elsewhere.

(Noting now that this may switch to a simple list implementation
based on Greg's assertion that lists are faster than red-black trees
for up to a few hundred entries.)

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:13:15 +02:00
Alex Elder 22b320f400 greybus: add response buffer to an operation
We need to track both request messages and response messages in
operations.  So add another gbuf (and payload pointer) field to
the operation structure, and rename them to indicate which one
is which.  Allow the creator specify the size of the response
buffer; just leave it a null pointer if the size is 0.

Define a new helper function gb_operation_gbuf_create() to
encapsulate creating either a request or a response buffer.

Any buffer associated with a connection will (eventually) have been
created as part of an operation.  So stash the operation pointer in
the gbuf as the context pointer.  Whether a buffer is for the
request or the response can be determined by pointer comparison.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:13:15 +02:00
Alex Elder 17d265f6a6 greybus: stop init_subdevs stuff
Upcoming patches are going to set up devices based on what is
discovered in the module manifest.  Get rid of the hard-coded
initialization done by gb_init_subdevs(), along with other related
code.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:13:15 +02:00
Alex Elder 61418b9fd9 greybus: drop hd arg from submit_gbuf method
Every gbuf is associated with a connection when it is created.  And
a connection contains a pointer to the host device that will carry
messages.  So there's no need for the submit_gbuf() method to have
the host device pointer passed to it, the function can get it from
the gbuf's connection.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:13:15 +02:00
Alex Elder a7901d5ef7 greybus: zero all data buffers
Don't assume the buffer data area will all be overwritten.  Zero all
buffer space, to avoid sending crap over the wire.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:12:00 +02:00
Alex Elder 170229d195 greybus: don't restrict input buffer size
Don't assume that input buffers have any particular content.  The
only thing the gbuf layer needs to be concerned with is the presence
of the cport_id byte at the beginning of a transfer.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:12:00 +02:00