Commit graph

51 commits

Author SHA1 Message Date
Alex Elder f68c05c021 greybus: cancel operation on timeout
If an operation times out, we need to cancel whatever message it
has in-flight.  Do that instead of completing the operation, in the
timeout handler.  When the in-flight request message is canceled its
completion function will lead to the proper completion of the
operation.

Change gb_operation_cancel() so it takes the errno that it's
supposed to assign as the result of the operation.

Note that we want to preserve the original -ETIMEDOUT error, so
don't overwrite the operation result value if it has already been
set.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-21 19:36:42 -08:00
Alex Elder de3557d927 greybus: rename greybus_cport_in()
This function is associated with a host device (interface), not a
CPort.  Change its name to reflect that, and to match its "sent"
callback counterpart.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-21 12:24:48 -08:00
Alex Elder 61089e89e5 greybus: rework receve handling
Rework gb_connection_operation_recv() to be more oriented toward an
operation message, and to no longer use a struct gbuf local variable.
Rename it to be a little more wieldy.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-18 12:50:34 -08:00
Alex Elder 374e6a269c greybus: kill off the last of gbuf.c
Only three functions remain in "gbuf.c".  Move one of them into
"connection.c" and the other two into "operation.c".

Some more cleanup is coming that will further straighten out gbufs
but for now there's no sense in drawing this out any longer.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-17 17:19:20 -08:00
Alex Elder 1e776f3183 greybus: get rid of cport_id_map_lock
The only time we get a cport id is when setting up a new connection.
We already have a (coarser-grained) spin lock that's used to protect
the connection lists, and we can use that same lock for protecting
the hd's connection id map.

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 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
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
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 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 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 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
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 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 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
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
Greg Kroah-Hartman a25f375cf7 greybus: Merge branch 'master' into driver_model_rework 2014-10-28 10:30:18 +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 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 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
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 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 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
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 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 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
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 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 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
Greg Kroah-Hartman 25b7b6d04b greybus: connection: properly lock idr
We had a lock, but we never used it, so move it to be per-hd, like the
idr structure is.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-10-06 20:29:40 -07:00
Marti Bolivar e86905b6cd greybus: gb_hd_connection_find(): fix "not found" case
Without this, null-testing the return value of this function is
broken.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-06 10:39:06 -07:00
Alex Elder ee9ebe4d0b greybus: add bg_hd_connection_find()
Add a function that looks up a connection given the host device
pointer an the host cport id.  This will be used to determine which
connection an incoming message is associated with.

Replace the list tracking host device connections with a red-black
tree so lookup can scale and be done quickly.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-06 08:56:42 -07:00
Alex Elder f6aec2516a greybus: fix two misnamed functions
I guess I got a little hd crazy.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-06 08:56:42 -07:00
Alex Elder eeeed42250 greybus: define gb_connection_err()
Define a function that prints error information about a Greybus
connection in a standard format.  This adopts the convention that
[M:I:C] represents the "path" the connection represents--specifying
the module id, the interface number on that module, and the
connection id on that interface.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-03 19:02:22 -07:00
Alex Elder 177404bd20 greybus: use ida for cport id allocation
The ida mechanism for allocating ids may be overkill but it works.

Don't preallocate the id 0 for control.  That should be done
when initializing connections based on the manifest anyway.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-03 19:00:10 -07:00
Alex Elder 748e1230cb greybus: fix some hasty bugs
Fix some omissions found in the code.
    - initialize and use the host device connections list
    - rename the interface connections list (was "functions")
    - use the interface connections list
    - define a spinlock protecting the connections lists
    - declare gb_operation_submit() in "operation.h"

And the cport id map lock is per-host device, it's shared across all
host devices.  There's no need for one in struct greybus_host_device.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-03 19:00:10 -07:00
Alex Elder ad1c449eb9 greybus: record connection protocol
Record the protocol association with a connection when it gets
created.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:22:45 -07:00
Alex Elder cd345074bb greybus: get rid of functions now...
We decided yesterday that we would no longer support the notion of a
"function."  Instead, a connection will simply exist between the AP
and an interface on a module (and a CPort Id on each end).  What
was previously considered the "function type" will now be handled
as the "protocol" associated with the connection.

Update gb_connection_create() to take just the interface and a cport
id associated with that interface.

Right now every module points back to a host device, so for now
we'll establish the connection back to that.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:22:45 -07:00
Alex Elder 9e8a6860f5 greybus: allocate connection host cport id
Allocate a cport id from the host device whenever creating a
connection.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:22:45 -07:00
Alex Elder e88afa5811 greybus: introduce an operation abstraction
This patch defines a new "operation" abstraction.  An operation is a
request from by one end of a connection to the function (or AP) on
the other, coupled with a matching response returned to the requestor.
The request indicates some action to be performed by the target of
the request (such as "read some data").  Once the action has
completed the target sends back an operation response message.
Additional data can be supplied by the sender with its request,
and/or by the target with its resposne message.

Each request message has a unique id, generated by the sender.
The sender recognizes the matching response by the presence
of this id value.  Each end of a connection is responsible
for creating unique ids for the requests it sends.

An operation also has a type, whose interpretation is dependent on
the function type on the end of the connection opposite the sender.
It is up to the creator of an operation to fill in the data (if any)
to be sent with the request.

Note that not all requests are initiated by the AP.  Incoming data
on a module function can result in a request message being sent from
that function to the AP to notify of the data's arrival.  Once the
AP has processed this, it sends a response to the sender.

Every operation response contains a status byte.  If it's value
is 0, the operation was successful.  Any other value indicates
an error.

Add a defintion of U16_MAX to "kernel_ver.h".

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