Commit graph

430 commits

Author SHA1 Message Date
Alex Elder c41b4f1212 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>
2014-10-22 17:22:22 +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
Alex Elder 36561f23a8 greybus: define connection state
Define the state of a connection.  A connection will not be
enabled until it has been successfully set up.  Once it starts
getting torn down its state will move to "being destroyed".

Don't send any operation request messages unless the connection is
enabled.  And drop any incoming messages if if the connection is
not enabled.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-22 17:20:28 +08:00
Alex Elder e1158df063 greybus: define operation_cancel()
Define a new function operation_cancel() that cancels an
outstanding operation.  Use it to clear out any operations that
might be pending at the time a connection is torn down.

Note:  This code isn't really functional yet, partially because
greybus_kill_gbuf() is not implemented.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-22 17:20:28 +08:00
Alex Elder e816e37419 greybus: time out operation requests
Arrange for operation requests that takke too long to time out.
At the moment, nothing happens when that occurs (other than a silly
message getting printed).  When the connection and operation and
interface and module code are cleaned up properly, this event should
most likely cause the affected module to get torn down.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-22 17:20:28 +08:00
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 060b93ddbb 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>
2014-10-22 14:12:17 +08:00
Matt Porter e390b193d6 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>
2014-10-22 14:12:17 +08:00
Matt Porter 6232b073d4 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>
2014-10-22 13:57:49 +08:00
Matt Porter 1a4c013a44 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>
2014-10-22 13:57:49 +08:00
Matt Porter 6271b5bac9 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>
2014-10-22 13:57:49 +08:00
Greg Kroah-Hartman 0369a45998 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>
2014-10-21 16:25:13 +08:00
Greg Kroah-Hartman c9346e19b2 greybus: battery-gb.c: fix memory leak found by Viresh
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 15:51:53 +08:00
Greg Kroah-Hartman cc662399dc greybus: Merge branch 'gregkh_work' into master
This pulls in the battery driver work I did there.
2014-10-21 14:37:44 +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
Alex Elder fb305c335c 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>
2014-10-21 14:36:11 +08:00
Alex Elder 03130a77d5 greybus: fix op_cycle logic
The function that computes the operation id for a connection is
wrongly using MOD rather than AND.  Fix that.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 14:36:11 +08:00
Greg Kroah-Hartman c0855bfdd6 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>
2014-10-21 14:31:24 +08:00
Alex Elder 1ec1d6dd35 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>
2014-10-21 06:32:01 +08:00
Alex Elder 6892537f61 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>
2014-10-21 06:28:24 +08:00
Alex Elder 6ff5e00a17 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>
2014-10-21 06:28:23 +08:00
Alex Elder 09c521dc0a 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>
2014-10-21 06:27:37 +08:00
Alex Elder 5b3db0ddaa 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>
2014-10-21 06:25:54 +08:00
Alex Elder 599dc6aa8e 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>
2014-10-21 06:25:54 +08:00
Viresh Kumar 6813e35a0e greybus: .gitignore: minor updates
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-21 06:22:32 +08:00
Viresh Kumar 8597e6b2b9 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>
2014-10-21 06:22:32 +08:00
Matt Porter ff6e0b9c2f 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>
2014-10-21 06:22:32 +08:00
Greg Kroah-Hartman 42d4a22d6b greybus: add LED protocol numbers 2014-10-20 16:02:56 +08:00
Greg Kroah-Hartman 2bb7eae8be greybus: battery: some hooking up to the greybus core
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-20 15:24:57 +08:00
Matt Porter 47ee0d135e 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>
2014-10-20 15:11:25 +08:00
Greg Kroah-Hartman 43789c319e 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>
2014-10-20 15:09:49 +08:00
Greg Kroah-Hartman 213aefe206 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>
2014-10-20 13:40:02 +08:00
Greg Kroah-Hartman 6ce3e03f71 greybus: greybus_manifest.h: fix up class protocol numbers to match the spec.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-20 13:27:42 +08:00
Alex Elder f012a520e1 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>
2014-10-18 12:38:55 +02:00
Alex Elder bedfdf3056 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>
2014-10-17 18:15:25 +02:00
Alex Elder d75286852b 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>
2014-10-17 18:15:23 +02:00
Alex Elder bb2e1c9626 greybus: initial operations-based GPIO driver
First cut.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:14:11 +02:00
Alex Elder ed8800dc37 greybus: add i2c driver
This patch adds the i2c driver, based on the use of Greybus operations
over Greybus connections.  It basically replaces almost all of what
was previously found in "i2c-gb.c".

When gb_connection_device_init(connection) is called, any connection
that talks the GREYBUS_PROTOCOL_I2C is passed to gb_i2c_device_init()
to be initialized.

Initialization involves verifying the code is able to support the
version of the protocol.  For I2C, we then query the functionality
mask, and set the retry count and timeout to default values.

After that, we set up the i2c device and associate it with the
connection.  The i2c_algorithm methods are then implemented
by translating them into Greybus operations.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:14:11 +02:00
Alex Elder 98d35ba22e 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>
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
Alex Elder 2eb585f8df 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>
2014-10-17 18:13:15 +02:00
Alex Elder d90c25b0a2 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>
2014-10-17 18:13:15 +02:00
Alex Elder 84d148b10e greybus: add gb_operation_find()
Add a red-black tree indexed by operation id to a connection to
allow pending operations (whose requests are in-flight) to be
found when their matching response is recieved.

Assign the id at the time an operation is inserted, and update
the operation's message header(s) to include it.

Rename gb_connection_op_id() to be more consistent with the
naming conventions being used elsewhere.

(Noting now that this may switch to a simple list implementation
based on Greg's assertion that lists are faster than red-black trees
for up to a few hundred entries.)

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-17 18:13:15 +02:00
Alex Elder 22b320f400 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>
2014-10-17 18:13:15 +02:00
Alex Elder 17d265f6a6 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>
2014-10-17 18:13:15 +02:00
Alex Elder 61418b9fd9 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>
2014-10-17 18:13:15 +02:00
Alex Elder a7901d5ef7 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>
2014-10-17 18:12:00 +02:00
Alex Elder 170229d195 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>
2014-10-17 18:12:00 +02:00
Alex Elder a06df4b08c 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>
2014-10-17 18:11:59 +02:00
Alex Elder ad8cd0d643 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>
2014-10-17 18:11:59 +02:00
Alex Elder 051fb04712 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>
2014-10-17 18:11:59 +02:00
Matt Porter 8fd39e3dcb 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>
2014-10-13 10:36:47 +02:00
John Stultz 8218605d20 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>
2014-10-10 18:48:24 -07:00
Greg Kroah-Hartman 9b60aa02ba greybus: greybus_manifest.h: add BSD license so that firmware can share it. 2014-10-06 20:37:53 -07:00
Greg Kroah-Hartman 62e120f599 greybus: svc_msg.h: add bsd license to file so that firmware can use it. 2014-10-06 20:37:18 -07:00
Greg Kroah-Hartman c4f37c62fa greybus: greybus_id.h: checkpatch cleanup 2014-10-06 20:37:08 -07:00
Greg Kroah-Hartman 8faa8da9a6 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>
2014-10-06 20:34:48 -07:00
Greg Kroah-Hartman 25b7b6d04b greybus: connection: properly lock idr
We had a lock, but we never used it, so move it to be per-hd, like the
idr structure is.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-10-06 20:29:40 -07:00
Matt Porter ff8aed5274 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>
2014-10-06 10:50:51 -07:00
Marti Bolivar e86905b6cd greybus: gb_hd_connection_find(): fix "not found" case
Without this, null-testing the return value of this function is
broken.

Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-06 10:39:06 -07:00
Matt Porter 7a13e2f688 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>
2014-10-06 08:57:15 -07:00
Alex Elder e8caf9a31b 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>
2014-10-06 08:56:43 -07:00
Alex Elder fdb594f136 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>
2014-10-06 08:56:43 -07:00
Alex Elder 9a6f6314d1 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>
2014-10-06 08:56:43 -07:00
Alex Elder 6eb3f4bdec 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>
2014-10-06 08:56:43 -07:00
Alex Elder 00d2e7588c 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>
2014-10-06 08:56:42 -07:00
Alex Elder ee9ebe4d0b greybus: add bg_hd_connection_find()
Add a function that looks up a connection given the host device
pointer an the host cport id.  This will be used to determine which
connection an incoming message is associated with.

Replace the list tracking host device connections with a red-black
tree so lookup can scale and be done quickly.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-06 08:56:42 -07:00
Alex Elder 369fb83249 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>
2014-10-06 08:56:42 -07:00
Alex Elder f6aec2516a greybus: fix two misnamed functions
I guess I got a little hd crazy.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-06 08:56:42 -07:00
Greg Kroah-Hartman 2fb5c518fc greybus: manifest.c: minor sparse cleanup 2014-10-04 18:43:41 -07:00
Alex Elder eeeed42250 greybus: define gb_connection_err()
Define a function that prints error information about a Greybus
connection in a standard format.  This adopts the convention that
[M:I:C] represents the "path" the connection represents--specifying
the module id, the interface number on that module, and the
connection id on that interface.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-03 19:02:22 -07:00
Alex Elder 8a30672a52 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>
2014-10-03 19:02:22 -07:00
Alex Elder b0b657555c 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>
2014-10-03 19:02:22 -07:00
Alex Elder 652433f3fe 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>
2014-10-03 19:02:22 -07:00
Alex Elder 937d0da83f 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>
2014-10-03 19:00:10 -07:00
Alex Elder 177404bd20 greybus: use ida for cport id allocation
The ida mechanism for allocating ids may be overkill but it works.

Don't preallocate the id 0 for control.  That should be done
when initializing connections based on the manifest anyway.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-03 19:00:10 -07:00
Alex Elder 063e6ec221 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>
2014-10-03 19:00:10 -07:00
Alex Elder 748e1230cb greybus: fix some hasty bugs
Fix some omissions found in the code.
    - initialize and use the host device connections list
    - rename the interface connections list (was "functions")
    - use the interface connections list
    - define a spinlock protecting the connections lists
    - declare gb_operation_submit() in "operation.h"

And the cport id map lock is per-host device, it's shared across all
host devices.  There's no need for one in struct greybus_host_device.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-03 19:00:10 -07:00
Matt Porter d7f9be4867 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>
2014-10-03 11:52:26 -07:00
Matt Porter 32dff13d21 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>
2014-10-03 11:51:58 -07:00
Greg Kroah-Hartman 2f30d9ffee greybus: manifest: some minor sparse warning fixups. 2014-10-02 21:26:26 -07:00
Greg Kroah-Hartman 322543a335 greybus: operation: fix endian issue in the operation message header size field. 2014-10-02 21:25:21 -07:00
Alex Elder ad1c449eb9 greybus: record connection protocol
Record the protocol association with a connection when it gets
created.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:22:45 -07:00
Alex Elder cd345074bb greybus: get rid of functions now...
We decided yesterday that we would no longer support the notion of a
"function."  Instead, a connection will simply exist between the AP
and an interface on a module (and a CPort Id on each end).  What
was previously considered the "function type" will now be handled
as the "protocol" associated with the connection.

Update gb_connection_create() to take just the interface and a cport
id associated with that interface.

Right now every module points back to a host device, so for now
we'll establish the connection back to that.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:22:45 -07:00
Alex Elder 9e8a6860f5 greybus: allocate connection host cport id
Allocate a cport id from the host device whenever creating a
connection.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:22:45 -07:00
Alex Elder 1bb3c724e8 greybus: create host device cport id map
A Greybus host device has a pool of CPort Ids it can use.  When we
establish a connection with a CPort on another module we will need
to allocate one from those that are available.

This patch adds a bitmap to the greybus host device structure that
allows cport ids to be allocated and freed as needed.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:22:05 -07:00
Alex Elder 63cc932b02 greybus: October 1 updates
Update the definitions in "greybus_manifest.h" to reflect the
changes to the Greybus specification made on October 1.

They are:
    - renaming "device" to be "interface"
    - renumbering greybus descriptor type
    - eliminating the notion of a "function"
    - defining a CPort's protocol in the CPort descriptor
    - having a "class" take on the types previously used for "function"
    - renaming "serial number" to be "unique id" (for now)
    - relying on an interface's maximum cport id to determine how
      much device+cport address space the interface consumes
    - adding a simple class descriptor
    - renaming gb_interface->interface_id to be gb_interface->id

This also reorders some things to match ordering in the document,
and adds some commentary for the various structures.

Since greybus_function_type is gone, we eliminate the "type" field
from a function structure.  (Functions are going away, next.)

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:22:04 -07:00
Alex Elder b05890db5e greybus: fix connection header declarations
Changes to the create/destroy connection functions were not properly
reflected in the header file.  Fix that.  There's also no need to
include anything other than "greybus.h".

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:22:04 -07:00
Alex Elder 459164b1f4 greybus: kill off old manifest code
Now that the new manifest code is in place, delete the old stuff
from "core.c".

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:19:56 -07:00
Alex Elder c095bbcfcb greybus: manifest cport descriptor parsing
Add support for parsing one or more cports descriptors in a module
manifest.  There must be at least one for each interface, but we impose
no limit on the number of interfaces associated with a module.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:19:56 -07:00
Alex Elder d88bfb5b7d greybus: manifest interface descriptor parsing
Add support for parsing one or more interface descriptors in a module
manifest.  There must be at least one, but we impose no limit on the
number of interfaces associated with a module.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:18:41 -07:00
Alex Elder b09c94a1b7 greybus: start improving manifest parsing
Currently the module manifest parsing code is sort of representative
only and is not really very useful.

This patch begins doing "real" parsing of the module manifest.
It scans the module manifest to identify the descriptors it holds.
It then verifies there's only one module descriptor found, and
initializes new some fields in the gb_module structure based on what
it contains (converting what's found to native byte order).
Note that if anything unexpected is found or other errors occur when
parsing the manifest, the parse fails.

Because we now save this converted information when it's parsed we
no longer have a greybus_descriptor_module struct within a struct
gb_module.  And because we've already converted these values, we can
do a little less work displaying values in sysfs.  (We also now show
vendor, product, and version values in the right byte order.)  This
eliminates the need for greybus_string(), so get rid of it.

It also slightly simplifies the greybus module matching code.

Move some existing parsing code into a new file, "manifest.c".

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:18:41 -07:00
Alex Elder e88afa5811 greybus: introduce an operation abstraction
This patch defines a new "operation" abstraction.  An operation is a
request from by one end of a connection to the function (or AP) on
the other, coupled with a matching response returned to the requestor.
The request indicates some action to be performed by the target of
the request (such as "read some data").  Once the action has
completed the target sends back an operation response message.
Additional data can be supplied by the sender with its request,
and/or by the target with its resposne message.

Each request message has a unique id, generated by the sender.
The sender recognizes the matching response by the presence
of this id value.  Each end of a connection is responsible
for creating unique ids for the requests it sends.

An operation also has a type, whose interpretation is dependent on
the function type on the end of the connection opposite the sender.
It is up to the creator of an operation to fill in the data (if any)
to be sent with the request.

Note that not all requests are initiated by the AP.  Incoming data
on a module function can result in a request message being sent from
that function to the AP to notify of the data's arrival.  Once the
AP has processed this, it sends a response to the sender.

Every operation response contains a status byte.  If it's value
is 0, the operation was successful.  Any other value indicates
an error.

Add a defintion of U16_MAX to "kernel_ver.h".

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:18:41 -07:00
Alex Elder c68adb2f2c greybus: introduce a connection abstraction
Within a UniPro network a pair of CPorts can be linked to form a
UniPro Connection.  This patch creates a new abstraction to
represent an AP CPort that is connected with a CPort used by a
function within a Greybus module.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:18:41 -07:00
Alex Elder ef0d2ba201 greybus: define greybus function abstraction
Define new source files "function.h" and "function.c" to contain the
definitions of the Greybus function abstraction.  A Greybus function
represents an active entity connected to a CPort implemented by a
Greybus interface.  A Greybus function has a type, which defines the
protocol to be used to interact with the function.  A Greybus
interface normally has at least two functions, but potentially many
more.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:18:40 -07:00
Alex Elder 8c12cde3c2 greybus: define greybus interface abstraction
Define new source files "interface.h" and "interface.c" to contain
the definitions of the Greybus interface abstraction.  A Greybus
interface represents a UniPro device present in a UniPro module.
For Project Ara, each interface block on a module implements a
UniPro interface.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:17:20 -07:00
Alex Elder e1e9dbddfe greybus: isolate greybus module code
Define new source files "module.h" and "module.c" to separate the
definitions of the Greybus module abstraction from other code.

Rename "greybus_module" to be "gb_module", for brevity.  Do the same
for a few other symbols with "greybus_module" in their names.  A few
(like greybus_module_id) are more visible outside this kernel module
so we'll keep their names more descriptive.

Add a definition for U8_MAX in "kernel_ver.h" (it appeared in 3.14).

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:17:20 -07:00
Alex Elder ecf7d57971 greybus: descriptor type updates
Some more updates to the definition of a manifest descriptor.
    - We get rid of function descriptors.  The type of function is
      easily specified with the CPort it uses.
    - Add a new interface descriptor type.
    - Clean up the CPort descriptor structure, eliminating fields
      that serve no purpose and adding the function id field

The sysfs stuff will be updated a little later to add entries
for the Greybus interfaces associated with modules.

Rearrange the order of a few things in "greybus_manifest.h".

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-02 21:17:20 -07:00
Matt Porter 513c54cb05 greybus: fix error message on parse of cport descriptor size
Fix a simple cut and paste error that was reporting a serial
number header size error rather than a cport descriptor size
error.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-01 12:16:30 -07:00
Matt Porter 7a57479b1d greybus: remove additional unused fields from the cport descriptor
The Greybus spec was updated to remove some unused fields from the
CPort descriptor definition. Remove them from the structure so
we don't fail manifest parsing.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-10-01 12:16:30 -07:00
Alex Elder 9c852d2b8f greybus: clarify device vs module
The Project ARA MDK states that a single module can have more than
one interface block (up to 2 at the moment).  An interface block
consists of two bidirectional UniPro lanes (along with power and
detect lines), and effectively represents a UniPro Device (with
an id in the range 0-127).

The service messages currently use "module_id" everywhere, even
though in a lot of cases we really need to be talking about device
ids.  The easiest case of this to see is the "set route" request
directed at a switch; a switch has no notion of modules, just
UniPro devices.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-30 18:22:27 -07:00
Greg Kroah-Hartman a6cdb3492e greybus: es1: no BUG_ON() code, report an error and recover. 2014-09-30 18:21:36 -07:00
Alex Elder 1cfc667d75 greybus: kill struct gmod_cport
A UniPro (short header) segment has a 5-bit field to represent a
CPort Id.  In addition, the 7-bit L3 short header holds a UniPro
device id.  There can be no more than 128 devices in a UniPro
network, but these two fields can be combined in ways to allow for
over 2000 CPorts within a single device.  As a result, a device id
is represented with one byte, and a CPort Id within a device is
always representable with a two byte value.

This patch changes integral values that reresent CPort Ids so they
use type u16 consistently.

Separately, the contents of the gmod_cport structure were mostly
fabricated, with the cport_id field being the only one that's
meaningful.  This patch gets rid of that structure, putting a
simple u16 to represent the CPort Id everywhere it had been used
before.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-30 18:19:12 -07:00
Matt Porter f0f70916fb greybus: es1-ap-usb: adjust SVC buffer size to handle worst case
The worst case message from the SVC->AP is a hotplug "plugged"
event. It includes the module manifest which may be up to 64KB
in size. Adjust our buffer allocation to allow for this.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-30 15:39:00 -07:00
Alex Elder 51c75fd060 greybus: reorder greybus_svc_in() arguments
The two functions greybus_svc_in() and greybus_cport_in() do
very similar things, but their arguments are in a different order.
Move the greybus_host_device structure argument for greybus_svc_in()
to be first so the functions' prototypes are better aligned.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-29 18:08:14 -07:00
Alex Elder 01e8280150 greybus: fix version check
When we read a module manifest we are required to verify that its
version is compatible with the version the present code is able
to parse.  All that's required is a check of the major version
number.  If the manifest's major version is greater than the
software, the software can't assume it can parse it.  All new
code must be able to parse all old versions of the format.  And
any difference in minor version is supposed to have no effect
on parsability.

Update the version check to enforce this policy, and reword the
error message to do a better job of explaining the situation.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-29 18:07:22 -07:00
Alex Elder 72b0ffc019 greybus: descriptor type is 1 byte
The spec was changed to require only one byte to represent the
type of a module descriptor.  Update our data type and the values
used to reflect that.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-29 18:07:22 -07:00
Alex Elder 1dd7f58f8e greybus: fix the guard in "greybus_manifest.h"
The tag in the #ifndef guard surrounding the content of
"greybus_manifest.h" needs to be updated to reflect the
actual name of the file.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-29 18:06:27 -07:00
Alex Elder cb705e0dd0 greybus: fix document version number
Two spots use the old "0.draft" version number for the Greybus
protocol specification.  We've updated that to be 0.1.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-29 18:01:40 -07:00
Alex Elder 908a85d7dd greybus: update a few header file comments
Add a GPLv2 tag and reword some comments at the top of "greybus_desc.h"
and "svc_msg.h".

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-29 18:01:40 -07:00
Alex Elder 0db32a6d5e greybus: some more renames
This patch renames of symbols, for better clarity and consistency.

    cport -> cport_id (when it represents a cport *number*)
    send_svc_msg -> submit_svc (like submit_gbuf)
    greybus_cport_in_data -> greybus_cport_in
    gb_new_ap_msg -> greybus_svc_in (like greybus_cport_in)
    cport->number -> cport->id (like cport_id)

Making the svc and cport message stuff more similar is done with an
eye toward having SVC messages and messages exchanged with other
modules use some more common communication mechanisms.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-29 18:00:55 -07:00
Alex Elder 877b1ee82e greybus: encapsulate URB status checking
Define a new common function check_urb_status() that looks at the
status in a completed URB (containing incoming data) and issues
warnings in a consistent way.  It returns -EAGAIN to signal an
unrecognized status was seen, so the caller can ignore it and
re-post the URB to receive the next incoming data.  This
consolidates three blocks of code into one.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-29 18:00:10 -07:00
Matt Porter c41a366773 greybus: update descriptor type enums to match renumbering in spec
Greybus spec updated the descriptor type values and added an
additional class descriptor type. Change the enum accordingly.

Signed-off-by: Matt Porter <mporter@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-29 17:58:08 -07:00
Matt Porter cbd0fd7b9b greybus: update string descriptor length field to __u8 type to match spec
Greybus spec was updated to make the length field a single byte. Update
the type and remove endian handling of that field in the core.

Signed-off-by: Matt Porter <mporter@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-29 17:57:33 -07:00
Matt Porter 097724c2fb greybus: remove unused function descriptor fields and change class->function_type
Greybus spec was updated to remove a number of unused function descriptor
fields. In addition, the class field was change to function_type to avoid
confusion with the concept of high-level class drivers.

Signed-off-by: Matt Porter <mporter@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-29 17:57:33 -07:00
Matt Porter 4fc645494f greybus: remove serial number descriptor to match spec
Greybus spec was updated to remove the serial number descriptor and
move the serial number field to the, now mandatory, module descriptor.
Change everything accordingly.

Signed-off-by: Matt Porter <mporter@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-29 17:57:06 -07:00
Matt Porter 6d63ff7a2d greybus: update descriptor module_id->module to match spec
Greybus spec was updated to change the name of the Module ID descriptor
to simply Module descriptor. Change everything accordingly.

Signed-off-by: Matt Porter <mporter@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-29 17:54:08 -07:00
Greg Kroah-Hartman dce745af21 greybus: fix up coding style issue I caused with the last patch... 2014-09-23 20:58:58 -07:00
Alex Elder 2e353685bf greybus: embed workqueue structure in struct gbuf
A Greybus buffer containing outbound data is submitted to to the
underlying driver to be sent over a CPort.  Sending that data could
be deferred, so the submit operation completes asynchronously.  When
the send is done, a callback occurs, and the buffer is "completed",
and the buffer's completion routine is called.  The buffer is then
freed.

If data arrives on the CPort, greybus_cport_in_data() is called
to allocate a Greybus buffer and copy the received data into it.
Once that's done the buffer is completed, again allowing the
buffer's completion routine to finish any final tasks before
freeing the buffer.

We use a workqueue to schedule calling the buffer's completion
function.  This patch does two things related to the work queue:
    - Renames the work queue "gbuf_workqueue" so its name more
      directly describes its purpose
    - Moves the work_struct needed for scheduling completions
      into the struct greybuf.  Previously a separate type
      was used, and dynamically allocated *at interrupt time*
      to hold this work_struct.  We can now do away with that.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-23 20:58:00 -07:00
Alex Elder 217b870e99 greybus: get rid of a weird idiom
It strikes me as strange to add one to a value while checking to see
if it exceeds a maximum.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-23 20:40:29 -07:00
Alex Elder 380f6bddc9 greybus: quick fix for sysfs serial number
Let the serial number attribute have its own is_visible function.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-23 20:40:29 -07:00
Alex Elder 778c69c9e2 greybus: rename struct greybus_device
The greybus_device structure represents an Ara phone module.
It does *not* (necessarily) represent a UniPro device, nor any
device (like an i2c adapter) that might reside on an Ara module.

As such, rename struct greybus_device to be struct greybus_module.
Rename all symbols having that type to be "gmod" rather than "gdev".

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-22 17:33:07 -07:00
Alex Elder 69f93abf11 greybus: simple fixes
A few silly little fixes.
    - Clear out some unnecessary #includes in "debugfs.c"
    - Drop some unneeded parentheses in hd_to_es1()
    - Use &hd->hd_priv in hd_to_es1() to emphasize we are working
      with an embedded array, not a pointer
    - Fix a comment in the header for ap_probe()
    - Drop a duplicate #include in "gpio-gb.c"
    - Fix a use-before-set problem in set_serial_info()

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-22 17:32:08 -07:00
Matt Porter be5064c75b greybus: initialize all fields in an SVC handshake message
Currently only the handshake_type is being initialized when
responding to an SVC handshake request. Update this to
explicitly set all header/payload fields appropriately.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-22 13:23:05 -07:00
Matt Porter 648cb6cb75 greybus: es1-ap-usb: fix svc control pipe flags
The control message flags currently indicate USB_DIR_IN, which
doesn't allow the data phase carrying the SVC message to be
send to the device. Change this to USB_DIR_OUT so our SVC
message buffer reaches the device.

Also, the recipient is USB_RECIP_OTHER but almost all real devices
that handle vendor setup requests seem to set this as
USB_RECIP_INTERFACE. As a result, functionfs-based gadgets don't handle
vendor setup requests with a recipient of OTHER. Change this to
USB_RECIP_INTERFACE to work with the functionfs-based emulator and
this should be no issue for the firmware to implement to match.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-22 13:23:05 -07:00
Greg Kroah-Hartman 4a833fdb7f greybus: core: hook up the hotplug message
We should now try to parse the manifest and create a device based on the
manifest.  Not hooked up to the driver core yet, so removing it isn't
going to do anything except cause problems...
2014-09-21 19:17:55 -07:00
Greg Kroah-Hartman d0cfd109c7 greybus: ap: validate the rest of the svc message buffer sizes 2014-09-21 19:10:39 -07:00
Greg Kroah-Hartman 00c52e4d3e greybus: ap: start validating the message better
We check the type of the message now.

Start to check the size of the payload to match the size of the message
type.  Still more work to do needed here.

Also "hooked up" the hotplug message, but doesn't call anything as the
core doesn't implement that yet...
2014-09-21 18:19:54 -07:00
Greg Kroah-Hartman 6779997d78 greybus: core.c: create empty functions to keep linking working for hotplug/remove 2014-09-21 18:17:36 -07:00
Greg Kroah-Hartman 85e0066c59 greybus: greybus.h: add function prototype for add/remove a module 2014-09-21 18:17:12 -07:00
Greg Kroah-Hartman 798ea88abe greybus: svc_msg.h: add data for hotplug message 2014-09-21 18:16:41 -07:00
Greg Kroah-Hartman 3e7736e5c1 greybus: gbuf: clean up logic of who owns what "part" of the gbuf
Started documenting the gbuf and how a greybus driver and a host
controller driver needs to interact with it, and the rest of the greybus
system.  It's crude documentation, but better than nothing for now...
2014-09-21 17:34:28 -07:00
Greg Kroah-Hartman f036e05600 greybus: gbuf: implement submission logic 2014-09-19 19:13:33 -07:00
Greg Kroah-Hartman 29f000f434 greybus: es1: set buffer sizes for messages based on email discussions
The gbuf sizes are 4k (i.e. PAGE_SIZE) and svc interrupt urb is 2k
2014-09-19 18:37:44 -07:00
Matt Porter 52adb56340 greybus: update GREYBUS_VERSION_[MAJOR|MINOR] to match spec
The Greybus spec was updated to have major=0 and minor=1 so update
this in the code.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-18 20:06:08 -07:00
Matt Porter e94e17143e greybus: move versioning from svc message header to handshake function
The Greybus spec has been updated to improve the efficiency of the
version major/minor information that had been previously carried in
every SVC message header. The version major/minor is now provided
as part of the handshake function.

Update the SVC msg header and handshake function payload definitions
and move the version major/minor validation into the SVC handshake
handling routine.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-18 20:06:08 -07:00
Matt Porter 710ecb0605 greybus: update svc_msg_header fields and users to match spec
The Greybus spec has been updated to clarify some of the original
intent of the SVC message definition. The svc_msg_header was:

struct svc_msg_header {
	__u8 function;
	__u8 message_type;
...
}

and is now

struct svc_msg_header {
	__u8 function_id;
	__u8 message_type;
...
}

to match the spec. The function_id carries enum svc_function_id values
and message_type is now clarified to be a session layer level field
that is simply "data" or "error".

Change all references of function type to function id. For now, don't
parse the message_type field but add the two allowable svc_msg_type enums.

Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-18 20:06:08 -07:00
Greg Kroah-Hartman 772149b6df greybus: fix hd init sequence of setting up parent and driver pointers properly 2014-09-14 12:27:28 -07:00
Greg Kroah-Hartman 13c8d9cd8a greybus: add test_sink driver 2014-09-14 12:27:19 -07:00
Greg Kroah-Hartman 45f3678bcf greybus: gbuf: cport in buffer stream logic 2014-09-14 11:40:35 -07:00
Greg Kroah-Hartman 80e04f0994 greybus: gbuf recieve path work, not done, dinner time... 2014-09-13 18:20:54 -07:00
Greg Kroah-Hartman ee6fb79902 greybus: devices: endpoint description of device 2014-09-13 17:31:27 -07:00
Greg Kroah-Hartman 7f9e05e15b greybus: es1: functionally complete
Have only tested USB device add/remove, the urbs seem to all be queued
up, no data has been tested to flow through yet.

Odds are the hc interface will have to change, but this is a good first
start to build on.
2014-09-13 17:28:33 -07:00
Greg Kroah-Hartman a1dc62b0c8 greybus: core: verify major/minor number of greybus protocol 2014-09-13 17:28:19 -07:00
Greg Kroah-Hartman 543b8ed2fe greybus: uart-gb: let the core dynamically allocate the major number
Don't register the tty_gb_driver, the gb core is not ready for the for
ES1 devices.
2014-09-13 17:02:47 -07:00
Greg Kroah-Hartman 168db1cd29 greybus: tty driver fixes to get init working properly 2014-09-13 16:15:52 -07:00
Greg Kroah-Hartman 082570b0ee greybus: es1 endpoint descriptor: minor fixes to get the config right 2014-09-13 16:15:07 -07:00
Greg Kroah-Hartman ac7171ea26 greybus: Makefile: add 'check' option to run sparse with endian checks enabled 2014-09-13 12:39:23 -07:00
Greg Kroah-Hartman b57b06241b greybus: ap: cleanup of process ap message loop 2014-09-13 12:18:09 -07:00
Greg Kroah-Hartman 88929c593d greybus: ap: convert to workqueue from thread 2014-09-13 11:35:02 -07:00
Greg Kroah-Hartman 9c8d3afdb5 greybus: es1: handle cport data in and out 2014-09-13 11:09:35 -07:00
Greg Kroah-Hartman 0dad95dc37 greybus: es1: allocate cport out urbs properly 2014-09-13 09:54:35 -07:00
Greg Kroah-Hartman 112997324d greybus: es1: add the start of cport urb handling. 2014-09-12 21:17:37 -07:00
Greg Kroah-Hartman 8c53e073f7 greybus: AP: move a bunch of svc message handling logic into ap.c
Add a send_svc_msg() callback to the host driver.
hook up ES1 driver to send control USB messages as it's SVC transport.
2014-09-12 20:47:11 -07:00
Greg Kroah-Hartman ccbb51ed42 greybus: Merge branch 'master' of github.com:gregkh/greybus 2014-09-11 08:22:57 -07:00
Greg Kroah-Hartman f91121b48f greybus: Fix build errors on older kernels.
Thanks to Marti for pointing out the code didn't build properly on 3.10.
Added kernel_ver.h to handle any api mis-matches between the code and
older kernel versions.
2014-09-11 08:22:06 -07:00
Greg Kroah-Hartman a6294fe849 greybus: fix endian issue in sysfs.c 2014-09-10 17:12:20 -07:00
Greg Kroah-Hartman 3d5453261b greybus: pass appropriate type to create function
Based on a patch from Alex Elder <elder@linaro.org>.

Alex's original description:

Every descriptor in a manifest is interpreted by greybus_new_module().
We call a function to do initialization based on descriptor's type.

Since we know the type of the descriptor at that point, we can pass
to the called function the actual sub-type it needs (i.e., the union
member associated with the type).  This allows those functions to
be slightly simplified, and more focused.

Also change some size variables to have size_t type, and simplify a
few spots further by using sizeof(object) in place of sizeof(type).
2014-09-09 17:16:54 -07:00
Alex Elder e82bef42fd greybus: fix manifest parsing size bug
The type-specific "create" routines that get called while parsing
the descriptor entries in the module manifest assume the size they
are provided is the size of their data portion only--not including
the descriptor header.

Compute this value in greybus_new_module(), and pass it to those
functions rather than the full descriptor size.  Move a few
declarations to the innermost block that uses them.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-09 15:16:12 -07:00
Alex Elder 57fc0a1104 greybus: validate descriptor sizes
When interpreting a manifest descriptor header, don't assume there
is enough space in the buffer to hold a descriptor header.  Also,
verify the remaining buffer is at least as big as the reported
descriptor size.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-09 15:15:05 -07:00
Alex Elder a22e15a1fc greybus: interpret descriptor type properly
The type field in a manifest descriptor header is in little endian
format.  Make sure we interpret it that way.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-09 15:09:59 -07:00
Alex Elder a5808add9a greybus: call put_device() on error
As soon as we've called device_initialize() we're required to call
put_device() in order to drop our reference to the device structure.
This was missed in the error path in greybus_new_module().  Fix that.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-09 15:09:06 -07:00
Alex Elder badad68e3a greybus: define struct greybus_manifest
Define a structure that describes the entire greybus manifest.
Adjust greybus_new_module() to use that, making it explicit that
it's not just a header that's being provided to that function.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-09 15:07:42 -07:00
Alex Elder 05ad189c23 greybus: switch to the term "manifest"
We agreed to rename a few things to improve clarity.  This patch
implements one of those changes.  The blob of data that describes
what's relevant to Greybus within an Ara module will now be called
the "module manifest."  In addition, in the context of Greybus we'll
also be calling what's in an Ara module a "module" or "Greybus module."

So this patch renames some structures and updates some comments.  It
also renames "greybus_desc.h" to be "greybus_manifest.h", and renames
greybus_new_device() to be greybus_new_module().

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-09 15:05:25 -07:00
Greg Kroah-Hartman d9d077fdbc greybus: es1: forgot to free our urb on disconnect 2014-09-08 20:11:18 -07:00
Greg Kroah-Hartman 47f6ef12fe greybus: es1: finialized USB device structure
Set up device properly and start up the SVC interrupt in endpoint for
processing data
2014-09-08 20:09:08 -07:00
Greg Kroah-Hartman 8b9951480b greybus: es1_ap_desc.c: updated ES1 USB device descriptor
Interrupt IN endpoint added.
2014-09-08 19:34:30 -07:00
Greg Kroah-Hartman fe3270425f greybus: minor whitespace cleanups to make checkpatch.pl happy 2014-09-07 15:57:07 -07:00
Greg Kroah-Hartman d47aa76161 greybus: battery FIXME added 2014-09-07 15:54:24 -07:00
Greg Kroah-Hartman 33ea3a3f56 greybus: add battery module 2014-09-07 15:39:34 -07:00
Greg Kroah-Hartman 43cc32a2ab greybus: first cut at parsing svc messages sent to the AP 2014-09-07 13:51:12 -07:00
Greg Kroah-Hartman 68f1fc4d2c greybus: more hd work 2014-09-07 13:12:11 -07:00
Greg Kroah-Hartman a39879fc08 greybus: host controller additions
Also some gbuf functions starting to get fleshed out.
2014-09-06 16:57:36 -07:00
Greg Kroah-Hartman d6e0e1c552 greybus: add es1_ap_desc.c to describe the ES1 USB device descriptors 2014-09-06 13:13:13 -07:00
Greg Kroah-Hartman f0e49eb059 greybus: uart-gb: remove unneeded THIS_MODULE setting 2014-09-06 11:42:25 -07:00
Marti Bolivar 7fabc884f9 greybus: uart-gb.c: dynamically allocate device numbers 2014-09-06 11:42:07 -07:00
Marti Bolivar f8089c0c6e greybus: uart-gb.c: replace alloc_tty_driver with tty_alloc_driver
alloc_tty_driver() is deprecated.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2014-09-06 11:41:23 -07:00
Greg Kroah-Hartman 48123e0e1e greybus: add proper packing to all greybus message types 2014-09-02 10:51:56 -07:00
Greg Kroah-Hartman 3be03d42cd greybus: minor checkpatch cleanups 2014-09-01 19:10:06 -07:00
Greg Kroah-Hartman 06340efb7c greybus: split sysfs functions out to separate file. 2014-09-01 19:05:54 -07:00
Greg Kroah-Hartman e24e7257b1 greybus: greybus_string() 2014-09-01 19:01:14 -07:00
Greg Kroah-Hartman 21ee4116fd greybus: module id attributes 2014-09-01 18:57:42 -07:00
Greg Kroah-Hartman 291f3b9e61 greybus: serial number attribute added 2014-09-01 18:41:39 -07:00
Greg Kroah-Hartman b94295e050 greybus: sysfs attributes for functions and more driver core integration. 2014-09-01 18:34:28 -07:00
Greg Kroah-Hartman 526c5c8d23 greybus: start parsing descriptor fields 2014-09-01 16:03:31 -07:00
Greg Kroah-Hartman a239f67c5d greybus: start parsing descriptor structures 2014-09-01 14:39:49 -07:00
Greg Kroah-Hartman d94a44a54e greybus: export gb_new_ap_msg so that the es1 module can use it 2014-09-01 14:39:34 -07:00
Greg Kroah-Hartman ec909874c7 greybus: turn off warnings for es1-ap-usb.c to make it easier to build for now... 2014-09-01 14:39:14 -07:00
Greg Kroah-Hartman 6dca7b97c7 greybus: get field names right for descriptors 2014-09-01 13:42:43 -07:00
Greg Kroah-Hartman 6584c8af70 greybus: s/greybus_device_id/greybus_module_id/g 2014-09-01 13:31:31 -07:00
Greg Kroah-Hartman d58778002b greybus: more changes due to name changes in the greybus document 2014-09-01 10:59:08 -07:00
Greg Kroah-Hartman 712d65915a greybus: greybus.h: tiny movement around 2014-09-01 09:51:51 -07:00
Greg Kroah-Hartman 3772f1610f greybus: header file s/u8/__u8/g 2014-09-01 09:51:33 -07:00
Greg Kroah-Hartman 80ebe8a631 greybus: greybus_desc.h created 2014-08-31 18:08:52 -07:00
Greg Kroah-Hartman b9b2a46265 greybus: split svc msg out into separate header file 2014-08-31 17:43:38 -07:00
Greg Kroah-Hartman 2ecd536de7 greybus: more structure definitions added 2014-08-31 17:25:22 -07:00
Greg Kroah-Hartman be1e2e9cd1 greybus: structures added 2014-08-31 16:21:33 -07:00
Greg Kroah-Hartman de536e3094 greybus: ap message loop added. 2014-08-31 16:17:04 -07:00
Greg Kroah-Hartman 27fb83109a greybus: register the bus with the driver core and add framework for debugfs files. 2014-08-31 13:54:59 -07:00
Greg Kroah-Hartman 6f83ab76b8 greybus: es1-ap-usb: more init framework added. 2014-08-30 17:30:04 -07:00
Greg Kroah-Hartman f1eec30ac8 greybus: first framework for the es1 ap controller 2014-08-30 17:18:14 -07:00
Greg Kroah-Hartman 8bf23e84d7 greybus: actually get the devm() change to build... 2014-08-30 17:18:04 -07:00
Greg Kroah-Hartman e5f167f1df greybus: can't use devm anymore, we aren't tieing into the driver model lifecycle :( 2014-08-30 17:11:41 -07:00
Greg Kroah-Hartman ba4468d464 greybus: initial framework for ES1 usb AP driver 2014-08-30 17:06:54 -07:00
Greg Kroah-Hartman eca17c5203 greybus: uart: tie into gb core properly 2014-08-30 16:54:05 -07:00
Greg Kroah-Hartman 56f10573be greybus: sdio: tie into gb core properly 2014-08-30 16:52:18 -07:00
Greg Kroah-Hartman 426f29d6be greybus: gpio: tie into gb core properly 2014-08-30 16:51:21 -07:00
Greg Kroah-Hartman 3d9efaaea3 greybus: i2c: use same naming convention everywhere 2014-08-30 16:49:59 -07:00
Greg Kroah-Hartman e7e0782c41 greybus: i2c: tie to the proper place on the greybus_device 2014-08-30 16:49:05 -07:00
Greg Kroah-Hartman db6e1fd264 greybus: hook up sdio, gpio, and tty into the greybus core. 2014-08-30 16:47:26 -07:00
Greg Kroah-Hartman 503c1cdbfb greybus: static module_init/exit functions 2014-08-30 16:21:03 -07:00
Greg Kroah-Hartman 199d68d4a8 greybus: start moving the function types into the greybus core 2014-08-30 16:20:22 -07:00
Alex Elder caaa8a838d greybus: uart-gb: a few minor bug fixes
Here are a few small bug fixes in uart-gb.c:
    - In wait_serial_change():
        - Return -EINVAL if *none* of the relevant flags are set in
          the "arg" parameter.
        - Balance the spin_lock_irq() with an unlock call (not
          another lock).
        - Rearrange a nested if structure (not a bug fix).
    - In tty_gb_probe():
        - Reset the greybus_device driver data in case of error.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-08-19 05:10:43 -05:00
Alex Elder ff5f0b3822 greybus: uart-gb: improve minor device number error checking
When alloc_minor() finds an available minor device number it
does not constrain the highest number desired.  Instead, it
relies on its caller, tty_gb_probe() to see if the returned
number indicates all minor numbers have been exhausted.

There are a couple problems with this--or rather with this
code.

First, if an allocation is attempted *after* GB_NUM_MINORS
is returned, a new number greater than (but not equal to)
GB_NUM_MINORS will be allocated, and that won't produce
any error condition.

Second, alloc_minor() can return an error code (like -ENOMEM).  And
its caller is only checking for GB_NUM_MINORS.  If an error code
is returned, tty_gb_probe() simply uses it.

Change alloc_minor() so it requests minor device numbers in the
range 0..(GB_NUM_MINORS-1), and use an error return to detect
when the minor device numbers have been exhausted.

If alloc_minor() returns -ENOSPC (from idr_alloc()), translate that
to -ENODEV.  The only other error we might see is -ENOMEM, and if
we get that, return it.

Finally, zero gb_tty->minor when it's released.  (If this is
actually important a reserved value like GB_NUM_MINORS should
be used instead to signify a gb_tty with no minor assigned.)

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-08-19 05:10:42 -05:00
Greg Kroah-Hartman e68453ed28 greybus: uart-gb: now builds, more framework added 2014-08-15 19:44:32 +08:00
Greg Kroah-Hartman a18e151757 greybus: more uart work 2014-08-15 18:54:11 +08:00
Greg Kroah-Hartman ff45c265f8 greybus: uart-gb: more work on tty functions 2014-08-15 18:33:33 +08:00
Greg Kroah-Hartman 79c822be7b greybus: uart framework added, doesn't build 2014-08-15 16:01:23 +08:00
Greg Kroah-Hartman e9023d227a greybus: gpio-gb.c: it now builds properly 2014-08-12 14:41:49 +08:00
Greg Kroah-Hartman c16854c3bf greybus: gpio driver 2014-08-12 12:00:16 +08:00
Greg Kroah-Hartman d5d1903dcd greybus: add framework for 'struct gbuf'
This is the equlivant of sk_buf or urbs for Greybus.
2014-08-11 19:03:20 +08:00
Greg Kroah-Hartman 83ddaaab01 greybus: Greybus SD/MMC host driver
Need to add specifics, but this should be enough to hook up to the mmc
framework.
2014-08-11 17:27:22 +08:00
Greg Kroah-Hartman 776f136c75 greybus: greybus.h: tiny coding style cleanups 2014-08-11 17:27:07 +08:00
Greg Kroah-Hartman 53419e07cc greybus: i2c-gb: actually add the i2c adapter properly... 2014-08-11 17:01:15 +08:00
Greg Kroah-Hartman 4c009fada1 greybus: update README with info on how to build and contact me. 2014-08-11 15:44:51 +08:00
Greg Kroah-Hartman 06823c3eb9 greybus: README and .gitignore updates 2014-08-11 15:32:12 +08:00
Greg Kroah-Hartman c8a797a98c greybus: Import most recent greybus code to new repo. 2014-08-11 15:30:45 +08:00
Greg Kroah-Hartman cd26f1bd6b greybus: Initial commit 2014-08-11 15:29:23 +08:00