Commit Graph

109 Commits

Author SHA1 Message Date
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 2f0c8aa4e6 greybus: driver matching: Greybus drivers bind to interface blocks, not modules
Because of this, rename greybus_module_id to greybus_interface_block_id.

We still need to add a way for a "class" driver to be bound to an
interface, but for now, all we really need is the vendor/product pair as
the GP Bridge interface block is going to be our main user.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-12-11 19:53:59 -05:00
Greg Kroah-Hartman ab88eb58c7 greybus: interface_block: move sysfs files into the interface_block.c file
No need to keep these out in sysfs.c, move them into the
interface_block.c file so that we can see them easier, and remove some
variable definitions by taking advantage of the attribute group macro.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-12-11 19:53:59 -05:00
Greg Kroah-Hartman 8ede6e36df greybus: interface_block: rename the sysfs files to not have 'module' in them
The sysfs files for an interface block should not have 'module' in them.
This was a hold-over from when we thought we were going to have
all attributes of a "module" in one directory.  Remove the prefix as
it's not needed, and is confusing considering modules can not have
strings or any of these attributes.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-12-11 19:53:59 -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
Greg Kroah-Hartman e50522209a greybus: interface_block: rename module.[c|h] to interface_block.[c|h]
"modules" in the driver model here, are really "interface blocks" as
that is what they are physically tied to.  So rename the files before we
start changing the code to make it obvious what is going on.

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 835fb5e498 greybus: enforce a buffer headroom maximum size
Define a maximum size that a host device can use for its private
area ahead of the payload space used by Greybus in a message buffer.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-12-02 14:39:42 -08:00
Alex Elder 8b337308e7 greybus: have greybus allocate its own buffers
Rather than having the host driver allocate the buffers that the
Greybus core uses to hold its data for sending or receiving, have
the host driver define what it requires those buffers to look like.

Two constraints define what the host driver requires: the maximum
number of bytes that the host device can send in a single request;
and a statement of the "headroom" that needs to be present for
use by the host device.

The direct description of the headroom is that it's the extra byte
the host device needs at the beginning of the "data" portion of
the buffer so the ES1 driver can insert the destination CPort id.
But more generally, the host driver could put other data in there
as well.

By stating these two parameters, Greybus can allocate the buffers it
uses by itself.  The host driver still allocates the buffers it uses
for receiving data--the content of those are copied as needed into
Greybus buffers when data arrives.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-21 12:23:34 -08:00
Alex Elder e238e641ee greybus: kill the last gbuf remnants
All the code has now been adjusted such that we can do away with the
old gbuf structure.

Three unused references remained in "greybus.h", so those are deleted.

Other than that most of the changes were done by simple global
substitution.  The gb_message structure incorporates the fields that
were previously found its embedded gbuf structure.  A few names have
been changed in the process:
    gbuf->transfer_buffer       message->buffer
    gbuf->transfer_buffer_size  message->buffer_size
    gbuf->hcd_data;             message->cookie

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-18 12:53:37 -08:00
Alex Elder 58a5bdc735 greybus: send buffers without gbufs
Change the method that sends messages so that it sends "raw" buffers
rather than gbufs.  To do this, we supply the host device and
destination CPort when sending.  As with other recent patches,
change the name of the method to reflect that we're no longer
dealing with gbufs.

The interface has changed as well.  Now this routine will return a
"cookie" value.  The cookie is used to represent the outgoing
request, and is supplied by the caller if necessary to cancel a
previously-sent buffer.  We'll store the result in gbuf->hcd_data
for now (which produces the same result as before...).

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 a9163b2c30 greybus: cancel buffers via magic cookie
Change the interface for canceling in-flight buffers to take a magic
cookie value as argument rather than a gbuf.  Right now we pass the
gbuf->hcd_data pointer that's assumed to have been set by the submit
routine.  But the next patch will change the submit routine to
return the cookie to be used, and the caller will be responsible for
keeping track of it.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-18 12:48:53 -08:00
Alex Elder 9ec5411adf greybus: free space without gbufs
Switch the host driver free routine to take a pointer to the
previously-allocated buffer that should be freed.

Rename the method to reflect it's no longer tied to a gbuf.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-18 12:48:53 -08:00
Alex Elder d2a259f213 greybus: allocate space without gbufs
This begins the transition to buffer allocation that does not rely
on the gbuf construct.

The host driver allocation routine will return a pointer to the
buffer to be used, and the caller will be responsible for keeping
track of that pointer, as well as the requested buffer size.

Rename the allocation method to reflect it's no longer tied to a
gbuf.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-18 12:48:53 -08:00
Alex Elder 06a4a061f1 greybus: improve data buffer alignment
For ES1 we need to insert the destination CPort id in whatever we
supply for sending over UniPro.  Currently we allocate one extra
byte supply the caller with an address that's offset by one from
the beginning of the allocated space.

As a result we always return a poorly-aligned buffer pointer.

Instead, allocate enough space so that we can return a better
aligned buffer to the caller.

Notes:
    - It may be that it's more important to supply an aligned
      address to the hardware.
    - We probably need to be more careful about writing into
      these buffers at unaligned offsets anyway.  (E.g., writing
      a 2-byte value at an odd offset can't be assumed to work.)

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-11-18 12:46:15 -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 4e5007e5c2 greybus: kill the gbuf slab cache
Nobody dynamically allocates gbufs any more, so we can get rid of
the allocation and free routines, as as the slab cache and its
related code.

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 bb88896eaf greybus: move gbuf initialization to caller
Change greybus_alloc_gbuf() so all it does is allocate the gbuf data
structure.  Move all of the initialization of the gbuf structure in
the caller.  Do the inverse in the caller prior to freeing the gbuf
structure via greybus_free_gbuf().  Use a null gbuf->transfer_buffer
pointer rather than a null gbuf pointer to indicate an unused gbuf.

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 3c3cef400e greybus: move the definition of struct gbuf
We no longer need struct gbuf defined in "greybus.h".  An upcoming
patch will embed a gbuf struct (not a pointer) into the operation
structure, and to do that we'll need the struct defined prior to the
operation.  Just move the gbuf definition into "operation.h".

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 2f528c8bf7 greybus: kill gbuf->kref
Since there is only ever one reference to a gbuf, we don't need a
kref to figure out when it can be freed.  Get rid of the kref and
its supporting code.

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 6e5dd0bbbb greybus: kill greybus_{get,put}_gbuf()
These functions are never used, so we can get rid of them.
Since there's no reference-getting function any more, we no
longer need "gbuf_mutex" to avoid racing gets and puts, so
get rid of that too.

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
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 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 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
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 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
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 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 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 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
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
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 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
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 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 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 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
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 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
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 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