Alex Elder [Mon, 27 Oct 2014 08:48:32 +0000 (03:48 -0500)]
greybus: embed the i2c adapter struct
We don't need to dynamically allocate the i2c adapter structure, we
can just embed it right in struct gb_i2c_device.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Mon, 27 Oct 2014 08:48:31 +0000 (03:48 -0500)]
greybus: gpio: kill gpio_controller->gpio
This field is never used (and not needed) so get rid of it.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Greg Kroah-Hartman [Mon, 27 Oct 2014 06:01:06 +0000 (14:01 +0800)]
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>
Greg Kroah-Hartman [Mon, 27 Oct 2014 05:32:27 +0000 (13:32 +0800)]
greybus: core: check for valid hcd callbacks
When registering a host controller, verify that all of the needed
callbacks are present, so we don't have to do the testing on any "hot"
paths when we want to send real data.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org.
Greg Kroah-Hartman [Mon, 27 Oct 2014 05:31:01 +0000 (13:31 +0800)]
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>
Greg Kroah-Hartman [Mon, 27 Oct 2014 04:33:47 +0000 (12:33 +0800)]
greybus: gpio-gb: fix some endian sparse warnings that were real.
Not like we are ever going to use a BE cpu, but it's good to be
"correct"...
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Greg Kroah-Hartman [Mon, 27 Oct 2014 04:30:15 +0000 (12:30 +0800)]
greybus: operation: fix some sparse warnings
One of which was "real".
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Greg Kroah-Hartman [Fri, 24 Oct 2014 10:46:15 +0000 (18:46 +0800)]
greybus: module: don't create duplicate module ids
If we somehow get a hotplug event for a module id that we already have
created[1], don't try to create it again, or sysfs will complain loudly.
Instead, abort the creation properly.
[1] If, for example, you happened to run a script on a greybus emulator
twice in a row...
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Greg Kroah-Hartman [Fri, 24 Oct 2014 10:33:59 +0000 (18:33 +0800)]
greybus: i2c: point to the proper parent device
Use the connection, not the host controller, as the parent device of the
i2c device.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Greg Kroah-Hartman [Fri, 24 Oct 2014 09:54:02 +0000 (17:54 +0800)]
greybus: module: enable all sysfs attributes
We were thinking that module attributes were known at the time the
device was created in the system, so we could query them to know if the
sysfs file was present or not. Unfortunatly that's not the case, we
create the device before we parse the values, so just always show the
sysfs attributes. If there is no such attribute, the sysfs file will be
empty (i.e. for the string attributes.)
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Fri, 24 Oct 2014 10:02:02 +0000 (05:02 -0500)]
greybus: fix repeated input errors
I screwed up the error handling in a patch the other day. If we get
an error on an input URB we should not re-submit it.
Signed-off-by: Alex Elder <elder@linaro.org>
Greg Kroah-Hartman [Fri, 24 Oct 2014 09:34:46 +0000 (17:34 +0800)]
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>
Alex Elder [Wed, 22 Oct 2014 10:36:18 +0000 (05:36 -0500)]
greybus: update AP id service message
Rename and renumber the values for the AP ID service message
and related symbols to match the recently-updated spec.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Wed, 22 Oct 2014 10:36:17 +0000 (05:36 -0500)]
greybus: set route before sending packets
The route for a connection needs to be set *before* we initialize
the connection.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Matt Porter [Wed, 22 Oct 2014 07:22:48 +0000 (03:22 -0400)]
greybus: svc: remove the DDB function message support
We removed the DDB function messages from the spec as they are
not needed. Now remove it from the code.
Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Wed, 22 Oct 2014 07:04:32 +0000 (02:04 -0500)]
greybus: only initialize interfaces when up
Rather than bringing up all interfaces described in the manifest,
wait until we get a link up message, and at that time go initialize
the link.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Wed, 22 Oct 2014 07:04:31 +0000 (02:04 -0500)]
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>
Alex Elder [Wed, 22 Oct 2014 07:04:30 +0000 (02:04 -0500)]
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>
Alex Elder [Wed, 22 Oct 2014 07:04:29 +0000 (02:04 -0500)]
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>
Alex Elder [Wed, 22 Oct 2014 07:04:28 +0000 (02:04 -0500)]
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>
Greg Kroah-Hartman [Wed, 22 Oct 2014 08:38:07 +0000 (16:38 +0800)]
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>
Matt Porter [Wed, 22 Oct 2014 06:06:09 +0000 (02:06 -0400)]
greybus: ap: add svc_set_route_send() command and use it on a link up event
When the AP receives a link up event, request that the SVC set a
route to the interface's device id (this device id has been
previously reported to the AP). In the future, we may not always
immediately set a route upon receiving a link up event but this
is sufficient for the known use cases at this time.
Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Matt Porter [Wed, 22 Oct 2014 06:06:08 +0000 (02:06 -0400)]
greybus: svc: remove unneeded fields from the unipro set route message payload
CPort connections are being handled in the application layer connection
protocol and the layer 3 switch doesn't care about them. Also, the
switch doesn't care about a source device id when setting up the route
table. Reduce the message to just the necessary destination device ID.
As the SVC is aware of which switch port it found the module/interface
and assigned the device ID, we can simply tell the SVC to set a route
to the device ID it has reported to the AP as being active.
Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Matt Porter [Wed, 22 Oct 2014 02:43:31 +0000 (22:43 -0400)]
greybus: ap: process the UniPro link up message
The link up message is the event that tells the AP what device ID
has been assigned to a particular interface on a module during
enumeration. The link up is sent *only* after the hotplug event
for a particular module has been sent to the AP.
The link up payload must carry the Module ID and Interface ID
to uniquely identify the struct gb_interface to which the
Device ID has been assigned.
After processing of the link up message, the interface's device_id
field will contain the assigned Device ID so that the AP has the
information necessary to issue network route commands.
Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Matt Porter [Wed, 22 Oct 2014 02:43:30 +0000 (22:43 -0400)]
greybus: interface: add gb_interface_find()
Add support for getting a struct gb_interface from an
Interface ID.
Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Matt Porter [Wed, 22 Oct 2014 02:43:29 +0000 (22:43 -0400)]
greybus: module: add gb_module_find()
Add support for getting a struct gb_module from a
Module ID.
Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Greg Kroah-Hartman [Tue, 21 Oct 2014 08:25:13 +0000 (16:25 +0800)]
greybus: battery-gb: Allow kernel values to get out of sync with greybus spec
We can't know that the greybus values and the kernel values for a number
of battery enumerated types will remain in sync. And as theses are sent
by an external device from the kernel, we have to explicitly check these
values.
Reported-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Greg Kroah-Hartman [Tue, 21 Oct 2014 07:51:53 +0000 (15:51 +0800)]
greybus: battery-gb.c: fix memory leak found by Viresh
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Greg Kroah-Hartman [Tue, 21 Oct 2014 06:37:44 +0000 (14:37 +0800)]
greybus: Merge branch 'gregkh_work' into master
This pulls in the battery driver work I did there.
Matt Porter [Tue, 21 Oct 2014 05:52:27 +0000 (01:52 -0400)]
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>
Alex Elder [Tue, 21 Oct 2014 04:01:04 +0000 (23:01 -0500)]
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>
Alex Elder [Tue, 21 Oct 2014 04:01:03 +0000 (23:01 -0500)]
greybus: stash power supply pointer in connection
The battery code was not stashing a copy of its private data
pointer. It'll be needed in the next patch.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Tue, 21 Oct 2014 04:01:02 +0000 (23:01 -0500)]
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>
Greg Kroah-Hartman [Tue, 21 Oct 2014 06:31:24 +0000 (14:31 +0800)]
greybus: battery-gb: Add battery communication with the module
This adds support to talk to the battery to get the various requests
made to it, based on the battery protocol defined in the Greybus
Specification.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Mon, 20 Oct 2014 15:28:00 +0000 (10:28 -0500)]
greybus: leverage ap_disconnect() in ap_probe()
With a few minor changes, ap_disconnect() can correctly handle
cleaning up even a partially initialized USB interface. Make those
changes, and then use ap_disconnect() to simplify cleanup for all
the error paths in ap_probe(). Reset all fields as they're cleaned
up to facilitate debugging.
Signed-off-by: Alex Elder <elder@linaro.org>
Alex Elder [Mon, 20 Oct 2014 15:27:59 +0000 (10:27 -0500)]
greybus: move ap_disconnect()
The next patch has ap_probe() reference ap_disconnect(). To prepare
for that, move ap_disconnect() up in the file.
This is done as a separate commit to make it easier to see this move
involves no other change to that function. This and the next commit
can be squashed if desired.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Mon, 20 Oct 2014 15:27:58 +0000 (10:27 -0500)]
greybus: remove cports and strings from gb_module
We no longer keep copies of strings found in the manifuest in
a module's strings array, so we can get rid of the strings array.
Similarly, the new manifest parsing code sets up connections for
each cport id advertised for a module, so the cport array is
no longer needed either.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Mon, 20 Oct 2014 15:27:57 +0000 (10:27 -0500)]
greybus: drop gb_* device fields from gb_module
A struct gb_module has a bunch of fields from the earlier skeleton
code, where a module was assumed to possibly have one of every
type of device available on the GP Bridge. The manifest parsing
code changed it so these things will be related to connection
endpoints, so these gb_module fields are no longer needed.
A few of these (battery and sdio) haven't been implemented the "new
way" yet, so just leave a bit of the code that was there commented
out for now.
Also, gb_tty seems to be partially implemented and I don't want to
remove that without knowing where it's headed, so that one stays.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Mon, 20 Oct 2014 15:27:56 +0000 (10:27 -0500)]
greybus: create a slab cache for operations
Everything we do on greybus will involve an operation, so create a
slab cache for that frequently-allocated data structure.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Mon, 20 Oct 2014 15:27:55 +0000 (10:27 -0500)]
greybus: properly drop device reference
Drop the USB device reference taken at the top of ap_probe() in the
event greybus_create_hd() fails.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Viresh Kumar [Mon, 20 Oct 2014 11:16:18 +0000 (16:46 +0530)]
greybus: .gitignore: minor updates
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Viresh Kumar [Mon, 20 Oct 2014 11:15:50 +0000 (16:45 +0530)]
greybus: Fix parameters of core_param()
core_param() takes four parameters instead of three and so results in this
compilation error:
greybus/core.c:25:33: error: macro "core_param" requires 4 arguments, but only 3 given
core_param(nogreybus, bool, 0444);
^
Fix this by adding proper arguments to it.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Matt Porter [Mon, 20 Oct 2014 10:39:45 +0000 (06:39 -0400)]
greybus: gpio-gb: fix offset error checking and usage
Offset (or hwgpio num) is the offset within a gpiochip, not the
unique gpio namespace number. Adjust the error checking and use
of offset in our operation calls to fix this.
Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Greg Kroah-Hartman [Mon, 20 Oct 2014 08:02:56 +0000 (16:02 +0800)]
greybus: add LED protocol numbers
Greg Kroah-Hartman [Mon, 20 Oct 2014 07:24:57 +0000 (15:24 +0800)]
greybus: battery: some hooking up to the greybus core
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Matt Porter [Mon, 20 Oct 2014 05:51:18 +0000 (01:51 -0400)]
greybus: gpio-gb: remove unused status field from struct gb_gpio_get_value_request
probably a cut and paste error got this unused status field. remove it.
Signed-off-by: Matt Porter <mporter@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Greg Kroah-Hartman [Mon, 20 Oct 2014 07:09:49 +0000 (15:09 +0800)]
greybus: battery-gb: provide accessors for a few more functions
Put the hard coded values in a function to make it easier to see what
needs to be done here.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Greg Kroah-Hartman [Mon, 20 Oct 2014 05:40:02 +0000 (13:40 +0800)]
greybus: gpio-gb: allow it to build properly for all current kernel versions.
GPIO remove changed the api for 3.17 to try to make up for some
previously foolish design decisions. Handle that in kernel_ver.h to
make the code simple.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Greg Kroah-Hartman [Mon, 20 Oct 2014 05:27:42 +0000 (13:27 +0800)]
greybus: greybus_manifest.h: fix up class protocol numbers to match the spec.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Sat, 18 Oct 2014 02:03:49 +0000 (21:03 -0500)]
greybus: report gbuf errors
If a gbuf completion indicates an error has occurred, report it.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Fri, 17 Oct 2014 10:18:22 +0000 (05:18 -0500)]
greybus: update gbuf status for completion handlers
Currently, if a USB urb completes with an error, that error status
is not transferred back to the gbuf that it's associated with. For
inbound data there's not a lot we can do about an error, but for
outbound data, this means there is no notification to the submitter
that something went wrong.
For outbound data copy the urb status directly back to the gbuf as
its status. Follow USB's lead and set the status to -EINPROGRESS
while a gbuf is "in flight." Assign a gbuf an initial status value
of -EBADR to help identify use of never-set status values.
When an inbound urb fails (SVC or CPort), currently the urb is just
leaked, more or less (i.e., we lose an urb posted to receive
incoming data). Change that so such an error is reported, but
then re-submitted.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Fri, 17 Oct 2014 10:09:21 +0000 (05:09 -0500)]
greybus: add write retry support for i2c
It is expected that i2c writes may fail, and in that case the driver
simply retries some number of times before actually treating it as a
failure. Define a GB_OP_RETRY status, which is interpreted by the
i2c driver as an indication a retry is in order. We just translate
that into an EAGAIN error passed back to the i2c core.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Thu, 16 Oct 2014 11:35:39 +0000 (06:35 -0500)]
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>
Alex Elder [Thu, 16 Oct 2014 11:35:38 +0000 (06:35 -0500)]
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>
Alex Elder [Thu, 16 Oct 2014 11:35:37 +0000 (06:35 -0500)]
greybus: kill old cport handlers
The original CPort message handlers are not needed. All incoming
data is passed to handlers based on the protocol used over the
connection over which the data was transferred. So get rid of the
old CPort handler code.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Thu, 16 Oct 2014 11:35:36 +0000 (06:35 -0500)]
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>
Alex Elder [Thu, 16 Oct 2014 11:35:35 +0000 (06:35 -0500)]
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>
Alex Elder [Thu, 16 Oct 2014 11:35:34 +0000 (06:35 -0500)]
greybus: move receive handling to operation layer
Create a work queue to do the bulk of processing of received
operation request or response messages.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Thu, 16 Oct 2014 11:35:33 +0000 (06:35 -0500)]
greybus: let operation layer examine incoming data
Give the operation layer a chance to examine incoming data so that
it can handle it appropriately.
Treat the data as an operation message header. If it's a response,
look up the operation it's associated with. If it's not, create a
new operation. Copy the incoming data into the request or response
buffer. The next patch adds a work queue to pick up handling
the request or response from there.
Get rid of gb_operation_submit(). Instead, we have two functions,
one for sending an operation's request message, the other for
sending an operation's response message.
Not fully functional yet, still just filling things in...
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Thu, 16 Oct 2014 11:35:32 +0000 (06:35 -0500)]
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>
Alex Elder [Thu, 16 Oct 2014 11:35:31 +0000 (06:35 -0500)]
greybus: add response buffer to an operation
We need to track both request messages and response messages in
operations. So add another gbuf (and payload pointer) field to
the operation structure, and rename them to indicate which one
is which. Allow the creator specify the size of the response
buffer; just leave it a null pointer if the size is 0.
Define a new helper function gb_operation_gbuf_create() to
encapsulate creating either a request or a response buffer.
Any buffer associated with a connection will (eventually) have been
created as part of an operation. So stash the operation pointer in
the gbuf as the context pointer. Whether a buffer is for the
request or the response can be determined by pointer comparison.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Thu, 16 Oct 2014 11:35:30 +0000 (06:35 -0500)]
greybus: stop init_subdevs stuff
Upcoming patches are going to set up devices based on what is
discovered in the module manifest. Get rid of the hard-coded
initialization done by gb_init_subdevs(), along with other related
code.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Thu, 16 Oct 2014 11:35:29 +0000 (06:35 -0500)]
greybus: drop hd arg from submit_gbuf method
Every gbuf is associated with a connection when it is created. And
a connection contains a pointer to the host device that will carry
messages. So there's no need for the submit_gbuf() method to have
the host device pointer passed to it, the function can get it from
the gbuf's connection.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Thu, 16 Oct 2014 11:35:28 +0000 (06:35 -0500)]
greybus: zero all data buffers
Don't assume the buffer data area will all be overwritten. Zero all
buffer space, to avoid sending crap over the wire.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Thu, 16 Oct 2014 11:35:27 +0000 (06:35 -0500)]
greybus: don't restrict input buffer size
Don't assume that input buffers have any particular content. The
only thing the gbuf layer needs to be concerned with is the presence
of the cport_id byte at the beginning of a transfer.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Thu, 16 Oct 2014 11:35:26 +0000 (06:35 -0500)]
greybus: unlock hd mutex on free
When free_hd() is called, hd_mutex is held. It is the
responsibility of free_hd() to drop that mutex.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Thu, 16 Oct 2014 11:35:25 +0000 (06:35 -0500)]
greybus: unlock gbuf mutex on free
To drop a reference on a gbuf, greybus_free_gbuf() is called. That
uses kref_put_mutex() to drop the refernce under protection of
gbuf_mutex. However the release routine, free_gbuf(), never
releases the mutex as it should. Fix that.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Thu, 16 Oct 2014 11:35:24 +0000 (06:35 -0500)]
greybus: don't assume subdevs are valid
Most of the disconnect routines for the "subdevs" of a module
blindly assume that initialization of the subdev was successful.
Fix this by checking for null pointers.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Matt Porter [Mon, 13 Oct 2014 07:00:53 +0000 (03:00 -0400)]
greybus: es1-ap-usb: handle -EPROTO in check_urb_status()
On a disconnect we can also have a status of -EPROTO. This results in
a flood of error messages due to the -EAGAIN handling of unsupported
status results. Fix this by also returning status when we have -EPROTO.
Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
John Stultz [Fri, 10 Oct 2014 21:42:33 +0000 (14:42 -0700)]
greybus: Changes required for integrating into the Android build
In order to easily integrate into the Android build, include
an Android.mk.
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Greg Kroah-Hartman [Tue, 7 Oct 2014 03:37:53 +0000 (20:37 -0700)]
greybus: greybus_manifest.h: add BSD license so that firmware can share it.
Greg Kroah-Hartman [Tue, 7 Oct 2014 03:37:18 +0000 (20:37 -0700)]
greybus: svc_msg.h: add bsd license to file so that firmware can use it.
Greg Kroah-Hartman [Tue, 7 Oct 2014 03:37:08 +0000 (20:37 -0700)]
greybus: greybus_id.h: checkpatch cleanup
Greg Kroah-Hartman [Tue, 7 Oct 2014 03:34:48 +0000 (20:34 -0700)]
greybus: greybus.h: remove transfer_flags
We didn't use them, so drop it.
Also some other checkpatch cleanups while I was in there.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Greg Kroah-Hartman [Tue, 7 Oct 2014 03:29:40 +0000 (20:29 -0700)]
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>
Matt Porter [Mon, 6 Oct 2014 17:46:36 +0000 (13:46 -0400)]
greybus: fix gb_manifest_parse() successful return path
Even if we successfully parse a manifest we are returning
failure. Instead, we now proudly proclaim success.
Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Marti Bolivar [Mon, 6 Oct 2014 17:26:02 +0000 (13:26 -0400)]
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>
Matt Porter [Mon, 6 Oct 2014 13:58:44 +0000 (09:58 -0400)]
greybus: fix manifest parsing problem with descriptor payload
The internal struct manifest_desc needs the data payload, rather
than the entire descriptor with header to be populated into the
data field. Also fix two places where the parser was trying to
extract the entire descriptor with header for the data payload
field.
Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Mon, 6 Oct 2014 11:53:13 +0000 (06:53 -0500)]
greybus: get rid of gbuf->hdpriv
Last time I tried to kill off gbuf->context my efforts were shot
down. Now that I've got the connection infrastructure in place,
maybe I'll have more luck getting rid of gbuf->hdpriv.
The only place it's used is to stash the es1_ap_dev structure
pointer in the buffer. But that information is now available
through the buffer's connection, so we don't need to use the
hdpriv field any more.
So get rid of it, and use hd_to_es1(gbuf->connection->hd) to
get at what we need.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Mon, 6 Oct 2014 11:53:12 +0000 (06:53 -0500)]
greybus: kill __alloc_gbuf()
GEt rid of __alloc_gbuf(), now that it's used in only one place.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Mon, 6 Oct 2014 11:53:11 +0000 (06:53 -0500)]
greybus: use alloc_gbuf_data() for both directions
Change the "direction" flag field of a gbuf to be a Boolean called
"outbound".
Add a Boolean outbound flag to alloc_gbuf_data(), and use it for
allocating the data buffer for gbufs for data being transferred in
either direction.
Update free_gbuf_data() accordingly--letting the host device
driver's gbuf data free function handle all of them.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Mon, 6 Oct 2014 11:53:10 +0000 (06:53 -0500)]
greybus: allocate gbufs using the connection
Switch to using the connection rather than the host device as
the locus for doing Greybus buffer allocation. A connection
encapsulates both the host device (whose driver is what's required
for allocation) and the *destination* cport id. Record the
connection a gbuf is associated with rather than the host module and
(unspecified) cport id.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Mon, 6 Oct 2014 11:53:09 +0000 (06:53 -0500)]
greybus: look up connection for recevied messages
Look up the connection that an incoming message is associated with.
This is the start of making message handling oriented toward the
the connection rather than the cport.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Mon, 6 Oct 2014 11:53:08 +0000 (06:53 -0500)]
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>
Alex Elder [Mon, 6 Oct 2014 11:53:07 +0000 (06:53 -0500)]
greybus: bury some dead code
One data structure and a few fields in another one are no longer
used, and were not removed when they should have been.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Mon, 6 Oct 2014 11:53:06 +0000 (06:53 -0500)]
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>
Greg Kroah-Hartman [Sun, 5 Oct 2014 01:43:41 +0000 (18:43 -0700)]
greybus: manifest.c: minor sparse cleanup
Alex Elder [Fri, 3 Oct 2014 20:05:22 +0000 (15:05 -0500)]
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>
Alex Elder [Fri, 3 Oct 2014 20:05:21 +0000 (15:05 -0500)]
greybus: add a connection->private field
This will be used for driver-specific data for whatever drives the
other end of the connection.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Fri, 3 Oct 2014 20:05:20 +0000 (15:05 -0500)]
greybus: specify type when creating an operation
The type of an operation belongs in the operation header, which
shouldn't be touched by users of the interface. So specify it
at operation creation time.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Fri, 3 Oct 2014 20:05:19 +0000 (15:05 -0500)]
greybus: gbuf: have caller set actual_length
A Greybus buffer has both a transfer_buffer_size field, which is the
size in bytes of the transfer buffer, and an actual_length field,
which is the number of bytes in that buffer that are actually
consumed. The user of the buffer--and not the buffer allocation
method--should be setting the actual_length field.
Stop setting the actual length on the es1-ap-usb alloc_gbuf_data
method. And *do* set it in gb_operation_create(), where we can
presume the operation being allocated will consume all the bytes
requested.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Fri, 3 Oct 2014 19:14:25 +0000 (14:14 -0500)]
greybus: fix module setup
The code that was setting up a module was not properly initializing
the module data structure. Fixing this required a little rework.
Now gb_add_module() (which the host device pointer and module id)
allocates and initializes the structure, and passes it to
gb_manifest_parse() for populating it further.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Fri, 3 Oct 2014 19:14:24 +0000 (14:14 -0500)]
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>
Alex Elder [Fri, 3 Oct 2014 19:14:23 +0000 (14:14 -0500)]
greybus: fix greybus_class_type symbol names
These were inadvertently not fixed when the type name was changed.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Alex Elder [Fri, 3 Oct 2014 19:14:22 +0000 (14:14 -0500)]
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>
Matt Porter [Fri, 3 Oct 2014 18:32:35 +0000 (14:32 -0400)]
greybus: implement core module removal path
Implement gb_remove_module() by finding the gb_module to
be removed via the supplied module_id. Add support for
removing the actual device into greybus_remove_device()
after all the subdevs are disconnected.
Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Matt Porter [Fri, 3 Oct 2014 17:38:24 +0000 (13:38 -0400)]
greybus: fix gb_add_module() by enabling the device_add()
Without the gb_module device being added, we have no parent
device for any of the greybus subdevs to be added. Do the
device_add() before creating subdevs as we need it then
to register any children in the various greybus protocol
drivers.
Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Greg Kroah-Hartman [Fri, 3 Oct 2014 04:26:26 +0000 (21:26 -0700)]
greybus: manifest: some minor sparse warning fixups.
Greg Kroah-Hartman [Fri, 3 Oct 2014 04:25:21 +0000 (21:25 -0700)]
greybus: operation: fix endian issue in the operation message header size field.
Alex Elder [Thu, 2 Oct 2014 17:30:06 +0000 (12:30 -0500)]
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>