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