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