1
0
Fork 0
Commit Graph

177 Commits (accad1ba7d62543ab3bcf08813726ea87d237bb6)

Author SHA1 Message Date
Alex Elder f9b0366f16 greybus: connection: un-abstract host cport id allocation
I did this recently for the endo id allocation code.

It's clearer now that the allocation of a CPort ID to use for
the AP side of a connection is not very complicated, and it
happens in a pretty controlled environment.  The functions that
abstract getting and releasing those ids don't really add that
much value.

This patch removes gb_connection_hd_cport_id_alloc() and
gb_connection_hd_cport_id_free(), and just open-codes their
activity in the few places they are called.

It is obvious now that the CPort ID allocation isn't done in
atomic context, so we can change the ida_simple_get() call to
use GFP_KERNEL.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-12 12:13:01 -07:00
Alex Elder deb58ca829 greybus: connection: drop unneeded gb_protocol_put() calls
Although a connection records its protocol id when it gets
created, its protocol handler doesn't actually get assigned
until gb_connection_bind_protocol() is called.

In gb_connection_create() there are some error paths in
which a reference to the connection's protocol is released
before the protocol handler has been associated with the
connection.

Get rid of those calls.

As a result, we will never pass a null protocol pointer to
gb_protocol_put().  Add a precautionary warning in that
function in the event that ever occurs.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-12 12:13:01 -07:00
Alex Elder 856618f3fb greybus: connection: remove extra kfree() call
When an error occurs in the device_add() call for a connection, the
device reference is dropped as required.  Because that's the device's
only reference, that will also lead to gb_connection_release() being
called, which frees the connection structure.

Right now we're then making an extra request to free the connection,
which is wrong.  Fix that.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-12 12:13:01 -07:00
Alex Elder f5c2be9e9b greybus: connection: check for duplicate cport ids
Check at connection creation time for an attempt to create a
connection with an interface CPort ID that's the same as one that's
already been created.

Define a new helper function to look for such a duplicate.  The
check for a duplicate is only performed at initialization time,
and CPorts are initialized serially for each bundle, so there's
no need to acquire the list lock for this search.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-10 10:38:23 -07:00
Alex Elder 190241a362 greybus: drop some unnecessary headers
There's no need to include anything other than "greybus.h" in
"connection.c".  Same thing in "core.c" and "manifest.c" and
"svc.c".  Some files need headers included, but most come along
with "greybus.h".

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-10 10:38:23 -07:00
Viresh Kumar 928f2abd5f greybus: Tear down devices in the reverse order
Normally, its a good practice to free resources in the reverse order in
which they are allocated, so that all the dependencies can be sorted out
properly.

This is true while creating/destroying devices as well. For example
consider this scenario (I faced a crash with control protocol due to
this). For a new module, we will first create a bundle+connection for
the control cport and then create other bundles/connections after
parsing manifest.

And while destroying interface on module hot unplug, we are removing the
devices in the order they are added. And so the bundle/connection for
the control cport are destroyed first. But, control cport was still
required while destroying other bundles/connections.

To solve this problem, lets destroy the resources in the reverse order
in which they are added.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-09 13:31:23 -07:00
Alex Elder 8bd0ae6e72 greybus: connection: make gb_connection_hd_find() private
Give gb_connection_hd_find() static scope; it's never used
outside "connection.c".

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-08 15:19:56 -07:00
Viresh Kumar d7353ceada greybus: s/bundle_cport_id/intf_cport_id
This isn't unique just for the bundle but the complete interface. Its
wrong to call it bundle_cport_id. Lets name it intf_cport_id to make
things clear.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-06-04 14:15:29 +09:00
Viresh Kumar 12eba9f8ef greybus: connection: name routines consistently
Routines should be named this way: gb_<object>_<operation>. Fix all
routines that don't match this.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-05-20 22:39:18 -07:00
Greg Kroah-Hartman 5bd5f00c30 greybus: connection: remove lock around ida_simple_* functions
ida_simple_* has a built-in spinlock, no need to grab another lock when
accessing it.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Reviewed-by: Alex Elder <elder@linaro.org>
2015-05-14 13:35:10 -07:00
Viresh Kumar 2352a73212 greybus: Unregister devices to get them freed
Devices registered with the device-core needs to be freed by calling
device_unregister(). For module we are calling just put_device() and for
bundle, connection and interface we are calling device_del().

All of these are incomplete and so none of them get freed, i.e. the
.release() routine is never called for their devices.

Module being a special case that it needs to maintain a refcount or a
list of interfaces to trace its usage count. I have chosen refcount.

And so once the refcount is zero, we can Unregister the device and
module will get free as well.

Because of this bug in freeing devices, their sysfs directories were not
getting removed properly and after a manifest is parsed with the help of
gbsim, removing modules was creating problems. The sysfs directory
'greybus' wasn't getting removed. And inserting the modules again
resulted in warnings and insmod failure.

WARNING: CPU: 3 PID: 4277 at
/build/buildd/linux-3.13.0/fs/sysfs/dir.c:486
sysfs_warn_dup+0x86/0xa0()

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-04-05 16:23:22 +02:00
Johan Hovold 25eb732954 greybus: connection: replace custom error function with dev_err
Remove custom connection error function and replace it with dev_err.

The standard error function provides more information in the message
prefix (e.g. includes the interface id), has a well-known semantics
(e.g. does does not add newlines to messages), and is even somewhat
shorter to type.

Note that some uses of the custom function were already adding double
newlines due to the non-standard semantics.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-19 17:28:19 +01:00
Johan Hovold 44538397e7 greybus: connection: fix oops after failed init
Make sure not to call connection_exit for connections that have never
been initialised (e.g. due to failure to init).

This fixes oopses due to null-dereferences and use-after-free in
connection_exit callbacks (e.g. trying to remove a gpio-chip that has
never been added) when the bundle and interface are ultimately
destroyed.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-17 22:32:58 +01:00
Johan Hovold 8f5eadb7ea greybus: connection: fix locking in gb_hd_connection_find
Fix unconditional re-enabling of interrupts in gb_hd_connection_find,
which can be called with local interrupts disabled from the USB
completion handler.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-02 21:03:19 -08:00
Johan Hovold 067f3b6bfa greybus: connection: fix non-atomic allocations under spin lock
Use GFP_ATOMIC for IDA memory allocations under spin lock, which must
not sleep.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-02-12 11:42:26 +08:00
Greg Kroah-Hartman 88e70a6846 greybus: sysfs: put a \n at the end of all sysfs files
Right now some sysfs attributes have \n and some do not, so fix that and
put \n at the end of all of them to make it easier to parse things
properly in userspace.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-01-02 13:08:03 -08:00
Greg Kroah-Hartman 1b6ea0db01 greybus: bundle: create GB_DEVICE_ID_BAD
Use a "name" for when we don't have a valid device id yet, instead of a
magic value of 0xff.

Reported-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
2015-01-02 13:05:42 -08:00
Greg Kroah-Hartman fb69cb506c greybus: protocol: split binding of prototcols to connections out of init
When adding a new protocol to the system, walk all bundles and try to
hook up any connections that do not have a protocol already.  This sets
the stage to allow for protocols to be loaded at any time, not just
before the device is seen in the system.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-12-23 21:04:02 -08:00
Greg Kroah-Hartman df469a9423 greybus: export needed symbols for protocols
Protocol handlers need some greybus symbols, so export them so that they
can be built outside of the greybus core.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-12-23 21:03:35 -08:00
Greg Kroah-Hartman df671553cb greybus: add module support
Modules in the greybus system sit above the interface, so insert them
early in the sysfs tree.  We dynamically create them when we have an
interface that references a module, as we don't get a "module create"
message directly.  They also dynamically go away when the last interface
associated with a module is removed.

Naming scheme for modules/interfaces/bundles/connections is bumped up by
one ':', and now looks like the following:

/sys/bus/greybus $ tree
.
├── devices
│   ├── 7 -> ../../../devices/pci0000:00/0000:00:14.0/usb1/1-1/7
│   ├── 7:7 -> ../../../devices/pci0000:00/0000:00:14.0/usb1/1-1/7/7:7
│   ├── 7:7:0 -> ../../../devices/pci0000:00/0000:00:14.0/usb1/1-1/7/7:7/7:7:0
│   └── 7:7:0:1 -> ../../../devices/pci0000:00/0000:00:14.0/usb1/1-1/7/7:7/7:7:0/7:7:0:1
├── drivers
├── drivers_autoprobe
├── drivers_probe
└── uevent

6 directories, 3 files
/sys/bus/greybus $ grep . devices/*/uevent
devices/7/uevent:DEVTYPE=greybus_module
devices/7:7/uevent:DEVTYPE=greybus_interface
devices/7:7:0/uevent:DEVTYPE=greybus_bundle
devices/7:7:0:1/uevent:DEVTYPE=greybus_connection

We still have some "confusion" about interface ids and module ids, which
will be cleaned up later when the svc control protocol changes die down,
right now we just name a module after the interface as we don't have any
modules that have multiple interfaces in our systems.

This has been tested with gbsim.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-12-23 15:30:00 -08:00
Greg Kroah-Hartman 4ab9b3c24b greybus: interface: s/gb_interface_block/gb_interface/g
Rename struct gb_interface_block to struct gb_interface

Lots of renaming, and variable renames as well (gb_ib->intf), but all
should be sane with regards to the new naming scheme we are using.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-12-19 15:35:44 -08:00
Greg Kroah-Hartman 1db0a5ff3a greybus: bundle: s/gb_interface/gb_bundle/g
Rename struct gb_interface to struct gb_bundle

It's a lot of renaming, some structures got renamed and also some
fields, but the goal was to rename things to make sense with the new
naming of how the system is put together in the 'driver model' view.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-12-13 13:37:49 -05:00
Alex Elder a46e96719d greybus: add Linaro copyrights
I was asked to add a Linaro copyright to all Greybus source files
that anyone at Linaro has modified.  This patch does that.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-12-12 14:15:55 -05:00
Greg Kroah-Hartman 4ec7b07915 greybus: interface_block: s/gb_module/gb_interface_block/
Rename struct gb_module to struct gb_interface_block

It's a complex rename, some functions got their name changed where
needed, but primarily this change is focused on the structure and where
it is used.  Future changes will clean up the remaining usages of the
term "module" in individual changes, this one spanned the whole
subsystem so do it all at once.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-12-11 19:53:59 -05:00
Alex Elder 4afb7fd015 greybus: make op_cycle atomic (again)
There's no need to protect updating a connections operation id cycle
counter with the operations spinlock.   That spinlock protects
connection lists, which do not interact with the cycle counter.
All that we require is that it gets updated atomically, and we
can express that requirement in its type.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-12-03 15:05:58 -08:00
Alex Elder afb2e1342e greybus: get rid of pending operations list
A connection has two lists of operations, and an operation is always
on one or the other of them.  One of them contains the operations
that are currently "in flight".

We really don't expect to have very many in-flight operations on any
given connection (in fact, at the moment it's always exactly one).
So there's no significant performance benefit to keeping these in a
separate list.  An in-flight operation can also be distinguished by
its errno field holding -EINPROGRESS.

Get rid of the pending list, and search all operations rather than
the pending list when looking up a response message's operation.
Rename gb_pending_operation_find() accordingly.

There's no longer any need to remove operations from the pending
list, and the insertion function no longer has anything to do with a
pending list.  Just open code what was the insertion function (it
now has only to do with assigning the operation id).

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-12-03 15:05:58 -08:00
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
Alex Elder c68adb2f2c greybus: introduce a connection abstraction
Within a UniPro network a pair of CPorts can be linked to form a
UniPro Connection.  This patch creates a new abstraction to
represent an AP CPort that is connected with a CPort used by a
function within a Greybus module.

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