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>
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>
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>
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>
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>
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>
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>
This patch defines a new "operation" abstraction. An operation is a
request from by one end of a connection to the function (or AP) on
the other, coupled with a matching response returned to the requestor.
The request indicates some action to be performed by the target of
the request (such as "read some data"). Once the action has
completed the target sends back an operation response message.
Additional data can be supplied by the sender with its request,
and/or by the target with its resposne message.
Each request message has a unique id, generated by the sender.
The sender recognizes the matching response by the presence
of this id value. Each end of a connection is responsible
for creating unique ids for the requests it sends.
An operation also has a type, whose interpretation is dependent on
the function type on the end of the connection opposite the sender.
It is up to the creator of an operation to fill in the data (if any)
to be sent with the request.
Note that not all requests are initiated by the AP. Incoming data
on a module function can result in a request message being sent from
that function to the AP to notify of the data's arrival. Once the
AP has processed this, it sends a response to the sender.
Every operation response contains a status byte. If it's value
is 0, the operation was successful. Any other value indicates
an error.
Add a defintion of U16_MAX to "kernel_ver.h".
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Within a UniPro network a pair of CPorts can be linked to form a
UniPro Connection. This patch creates a new abstraction to
represent an AP CPort that is connected with a CPort used by a
function within a Greybus module.
Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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...
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...
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...
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>