1
0
Fork 0
Commit Graph

632 Commits (c9d9d0d443afab6c4c1ce295c283f0caab56db16)

Author SHA1 Message Date
Viresh Kumar c9d9d0d443 greybus: interface: Fetch interface id instead of module id during setup
There can be more than one interface on a module and we need to know the
interface for which the event has occurred.

But at the same time we may not need the module id at all. During initial phase
when AP is probed, the AP will receive the unique Endo id which shall be enough
to draw relationships between interface and module ids.

Code for that isn't available today and so lets create another routine to get
module id (which needs to be fixed separately), which will simply return
interface id passed to it.

Now that we have interface id, update rest of the code to use it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-04-05 18:04:38 +02:00
Viresh Kumar 2352a73212 greybus: Unregister devices to get them freed
Devices registered with the device-core needs to be freed by calling
device_unregister(). For module we are calling just put_device() and for
bundle, connection and interface we are calling device_del().

All of these are incomplete and so none of them get freed, i.e. the
.release() routine is never called for their devices.

Module being a special case that it needs to maintain a refcount or a
list of interfaces to trace its usage count. I have chosen refcount.

And so once the refcount is zero, we can Unregister the device and
module will get free as well.

Because of this bug in freeing devices, their sysfs directories were not
getting removed properly and after a manifest is parsed with the help of
gbsim, removing modules was creating problems. The sysfs directory
'greybus' wasn't getting removed. And inserting the modules again
resulted in warnings and insmod failure.

WARNING: CPU: 3 PID: 4277 at
/build/buildd/linux-3.13.0/fs/sysfs/dir.c:486
sysfs_warn_dup+0x86/0xa0()

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-04-05 16:23:22 +02:00
Mark Greer 045235f118 greybus: Initial I2S definitions
These are definitions from Mark that I've consolidated into
one header file. I'd like to get these merged at some point
soon, so the audio driver and gbsim work can avoid having
out-of-tree dependencies.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-04-04 20:31:30 +02:00
Greg Kroah-Hartman 6023629d36 greybus: Documentation/sysfs: add a proposed sysfs tree for greybus
This adds a proposed sysfs layout for greybus to Documentation to make
it easier for people to discuss / test things.  It includes a module, an
interface, a bundle, and a gpbridge binding to that bundle.

This was discussed on the projectara software mailing list.

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2015-04-04 10:54:25 +02:00
Alex Elder e4c4b4dce6 greybus: reduce the ranting
Cut out some comments that are no longer operative.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-04-02 11:29:58 +02:00
Greg Kroah-Hartman 66c98986c9 greybus: kernel_ver.h: add sysfs_create_groups() and sysfs_remove_groups()
These functions showed up in 3.12 or so, and we are stuck on 3.10 for
various reasons, so provide backports in kernel_ver.h so that we can
rely on these functions.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-04-01 01:36:23 +02:00
Greg Kroah-Hartman 7a51b9362b greybus: loopback: use the attribute groups, not group
We should use the attribute groups, not group, for the device, so
add and remove it.  No one should ever be updating a sysfs group for a
device, as that can be pretty dangerous if you don't duplicate _all_
existing attribute for that device, and I don't think we were doing that
here.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-31 23:02:34 +02:00
Greg Kroah-Hartman 5679f783b1 greybus: loopback: fix build breakage about SZ_4K
x86 doesn't include SZ_4K somehow so explicitly include <linux/sizes.h>
to fix the build breakage.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-31 23:01:45 +02:00
Alexandre Bailon 355a705815 greybus: Add loopback protocol
Add a simple Greybus protocol in order to stress USB and Greybus.
This protocol currently support 2 requests: ping and transfer.

ping request is useful to measure latency.
Kernel send a ping request and firmware should respond with a ping.

The transfer request request is useful to stress Greybus and USB.
Kernel can send data from 0 to 4k and the firmware must send back the data to kernel.

This behaviour of gb-loopback module is controlled via sysfs.
Curently, connection sysfs folder is updated with new entries:
- type: Type of loopback message to send
  * 0 => Don't send message
  * 1 => Send ping message continuously (message without payload)
  * 2 => Send transer message continuously (message with payload)
- size: Size of transfer message payload: 0-4096 bytes
- ms_wait: Time to wait between two messages: 0-1024 ms

Module also export some statistics about connection:
- latency: Time to send and receive one message
- frequency: Number of packet sent per second on this cport
- throughput: Quantity of data sent and received on this cport
- error
All this statistics are cleared everytime type, size or ms_wait entries are updated.

Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-31 22:53:59 +02:00
Alex Elder e0feaf14b1 greybus: es2: test apb1_log_task safely
When usb_log_enable() is called, the global apb1_log_task is used to
hold the result of kthread_run().  It is possible for kthread_run()
to return an error pointer, so tests of apb_log_task against NULL
are insufficient to determine its validity.

Note that kthread_run() never returns NULL so we don't have to check
for that.  But apb1_log_task is initially NULL, so that global must
be both non-null and not an error in order to be considered valid.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:29:02 +02:00
Alex Elder dada3b02a3 greybus: es1: test apb1_log_task safely
When usb_log_enable() is called, the global apb1_log_task is used to
hold the result of kthread_run().  It is possible for kthread_run()
to return an error pointer, so tests of apb_log_task against NULL
are insufficient to determine its validity.

Note that kthread_run() never returns NULL so we don't have to check
for that.  But apb1_log_task is initially NULL, so that global must
be both non-null and not an error in order to be considered valid.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:28:13 +02:00
Alex Elder d8187aa224 greybus: manifest: use size_t for a size variable
In identify_descriptor(), the variable desc_size represents the size
of a memory object.  So change its type from int to size_t.

The return value for this function can be desc_size cast to int.
One can verify by inspection this will never exceed INT_MAX.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:28:13 +02:00
Johan Hovold 973ccfd626 greybus: operation: refactor response handling
Send response to incoming requests from the operation request handler
rather than in every protocol request_recv callback.

This simplifies request_recv error handling and allows for further code
reuse.

Note that if we ever get protocols that need to hold off sending
responses we could implement this by letting them return a special
value (after acquiring the necessary operation references) to suppress
the response from being sent by greybus core.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:20:34 +02:00
Johan Hovold d0eb755aee greybus: hid: fix missing response on request errors
Send response also to incoming requests that cannot be fulfilled.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:20:33 +02:00
Johan Hovold 382145beb4 greybus: hid: fix missing input verification of report events
Add minimal verification of incoming report size, before using it to
determine what buffer and size to pass on to HID core.

Add comment about protocol needing to be revisited. If we are going to
be parsing the report data received, then those fields have to be
defined in the Greybus specification at least.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:20:33 +02:00
Johan Hovold 36257f6b4e greybus: hid: fix null-deref on short report requests
Make sure to verify the length of incoming requests before trying to
parse the request buffer, which can even be NULL on empty requests.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:20:33 +02:00
Johan Hovold ecf47ab9c5 greybus: hid: fix success response being sent on errors
Make sure to only send a success response if we did not detect any
errors.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:17:37 +02:00
Johan Hovold b67f2d13db greybus: hid: replace pr_err with dev_err
Replace pr_err with dev_err and clean up error messages somewhat.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:17:37 +02:00
Johan Hovold fef96a226e greybus: gpio: fix missing response on request errors
Send response also to incoming requests that cannot be fulfilled.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:17:37 +02:00
Johan Hovold 244b5a2344 greybus: gpio: fix null-deref on unexpected irq requests
Fix null-pointer dereference on failure to look up irq due to missing
error handling.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:17:37 +02:00
Johan Hovold 1842dd8b7b greybus: gpio: fix null-deref on short irq requests
Make sure to verify the length of incoming requests before trying to
parse the request buffer, which can even be NULL on empty requests.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:17:37 +02:00
Johan Hovold 0150bd7f23 greybus: operation: make incomplete-message errors more informative
Include the operation id as well as the received and expected size
(from header) when reporting incomplete messages.

This information is useful when debugging communication errors.

Also invert the size test to match the error message and increase
readability.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:13:01 +02:00
Johan Hovold e1baa3f0a9 greybus: operation: replace pr_err with dev_err
Use dev_err whenever we have a connection for more informative error
messages.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:13:01 +02:00
Johan Hovold cfa79699cd greybus: operation: fix incoming request payload size
Fix the payload size of incoming requests, which should not include the
operation message-header size.

When creating requests we pass the sizes of request and response
payloads and greybus core allocates buffers and adds the required
headers. Specifically, the payload sizes do not include the
message-header size.

This is currently not the case for incoming requests however, something
which prevents protocol drivers from implementing appropriate input
verification and could lead to random data being treated as a valid
message in case of a short request.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:13:01 +02:00
Johan Hovold 9489667684 greybus: operation: fix null-deref on operation destroy
Incoming operations are created without a response message. If a
protocol driver fails to send a response, or if the operation were to be
cancelled before it has been fully processed, we get a null-pointer
dereference when the operation is released.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:13:01 +02:00
Johan Hovold 772f3e9060 greybus: operation: fix null-deref on operation cancel
Incoming operations are created without a response message. If an
operation were to be cancelled before it has been fully processed (e.g.
on connection destroy), we would get a null-pointer dereference in
gb_operation_cancel.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:13:01 +02:00
Johan Hovold ff65be7a58 greybus: operation: fix use-after-free and infinite loop on unhandled requests
Make sure to return a proper response in case we get a request we do not
recognise.

This fixes an infinite loop and use-after-free bug, where the freed
operations structure would get re-added to the work queue indefinitely.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:13:01 +02:00
Johan Hovold ea2c2ee805 greybus: operation: fix memory leak in request_send error path
Make sure to drop the operation reference when sending the request fails
to avoid leaking the operation structures.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:13:01 +02:00
Johan Hovold 0fb5acc401 greybus: operation: fix use-after-free when sending responses
Fix use-after-free when sending responses due to reference imbalance.

Make sure to take a reference to the operation when sending responses.
This reference is dropped in greybus_data_sent when the message has been
sent, while the initial reference is dropped in gb_operation_work after
processing the corresponding request.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:10:06 +02:00
Johan Hovold 37754030b0 greybus: operation: fix callback handling and documentation
Fix up obsolete comments referring to null callback pointers for
synchronous operations, and make sure a callback is always provided when
sending a request.

Also document that the callback is responsible for dropping the initial
(and not necessarily final) reference to the operation.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:10:06 +02:00
Johan Hovold d506283491 greybus: operation: fix typo in comment
Fix typo in comment.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:10:06 +02:00
Johan Hovold 1dad6b3515 greybus: operation: fix missing symbol exports
Add missing EXPORT_SYMBOL_GPL for gb_operation_response_alloc,
gb_operation_result, gb_operation_get, gb_operation_request_send and
gb_operation_cancel, which are all supposed to be accessible from
protocol handlers.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:10:06 +02:00
Viresh Kumar e2cb6cacad greybus: kernel_ver.h: include <linux/kernel.h> to fix warning
And this is the warning I was getting on kernel version > 3.14

  CC [M]  greybus/connection.o
  In file included from
  include/asm-generic/gpio.h:4:0,
	from arch/arm/include/asm/gpio.h:9,
	from include/linux/gpio.h:48,
	from greybus/kernel_ver.h:59,
	from greybus/connection.c:12:
  include/linux/kernel.h:35:0: warning: "U16_MAX" redefined

kernel_ver.h is taking care of defining U16_MAX only if is not defined earlier,
but it is often included as the first .h file. <linux/kernel.h> might be
included later, which always defines it, unconditionally. And so this warning.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-30 15:03:36 +02:00
Greg Kroah-Hartman ca3ec299c2 greybus: es2: sync up with recent es1.c changes
This brings the debug log functionality of es1.c to es2.c, along with
some other minor cleanups.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
2015-03-30 15:01:56 +02:00
Greg Kroah-Hartman 48f70474f4 greybus: debugfs: we shouldn't care if debugfs is working or not
This removes the error checking for debugfs initialization as we really
don't care if it failed or not.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
2015-03-30 15:01:56 +02:00
Alex Elder 142f8ddf71 greybus: get rid of {conceal,reveal}_urb()
These clever macros were fine for early development, but they're
more of a distraction now.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-27 11:16:35 +01:00
Alex Elder d3d2bea161 greybus: clean up some small messes
This is an old patch that I neglected to send out.  It's cleaning
up a couple things that got committed before I had a chance to
comment on them.

In operation.c there is a "FIXME" comment that is easily proven
wrong by inspection.

In gb_protocol_put(), there is another wrong "FIXME" comment as
well.  We can also use our cached copies of the protocol major
and minor version number in another spot.  And balance that
out by using a cached copy of the protocol id.

Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-27 11:16:35 +01:00
Greg Kroah-Hartman 938451f184 greybus: Merge branch 'es1-fixes' into master
Merge the es1 log file fixes into master.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-25 09:26:33 +01:00
Viresh Kumar 71e4938012 greybus: interface: put module->dev on failures
In order to decrement the reference count of module on failures, we must call
put_device(module->dev). This was missing for one of the error cases, fix it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-24 21:00:24 +01:00
Viresh Kumar 0d34be7587 greybus: Greybus: Place module_init/exit() right after respective routines
As mentioned in kernel coding guidelines.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-24 21:00:24 +01:00
Viresh Kumar 13fe6a9af3 greybus: manifest: don't need to check for desc_size == 0 anymore
identify_descriptor() doesn't return 0 anymore and so we don't need to check the
returned value against 0.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-24 20:59:03 +01:00
Viresh Kumar 19b3b2c2ae greybus: manifest: descriptor size should be >= header size
We are calculating descriptors expected size differently based on the type of
descriptor, that's fine but at few places we aren't taking size of the header
into account. And that looks wrong.

Lets make sure it is atleast as big as descriptor's header.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-24 20:59:03 +01:00
Greg Kroah-Hartman 25d1c37798 greybus: es1: allow the debug log to be stopped
If you write 0 to the debugfs file, the log will stop being updated.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-24 20:47:24 +01:00
Greg Kroah-Hartman 0c264c6fc2 greybus: es1: separate usb_log enable/disable logic into different functions
One function shouldn't do two different things depending on a parameter
passed to it, so split usb_log_enable() into usb_log_disable()

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-24 20:45:31 +01:00
Greg Kroah-Hartman efdc43130c greybus: es1: fix checkpatch warning about blank lines needed
Add a blank line in apb1_log_enable_read() to make checkpatch happy.

Oh, and it makes the code more readable too...

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-24 20:34:02 +01:00
Greg Kroah-Hartman 64b8a16f44 greybus: es1: move debugfs function to use kstrotoint_from_user()
No need to duplicate built-in functions that the kernel has, so have the
core kernel parse the userspace string.  Saves us an allocation and
makes the logic simpler.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-24 20:32:40 +01:00
Greg Kroah-Hartman d52f9973e2 greybus: es1: decimal modes are not what are wanted for debugfs
decimal is not octal, so use the proper mode settings for the debugfs
files.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-24 20:10:58 +01:00
Greg Kroah-Hartman 4600d03f80 greybus: es1: struct file_operations needs to be const
We aren't changing these pointers, so mark them read-only as that is the
preferred way.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-24 20:08:12 +01:00
Greg Kroah-Hartman 26164edb8f greybus: es1: no need to check for NULL on debugfs_remove()
The function can, and even expects NULL, so don't check.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-24 20:06:41 +01:00
Greg Kroah-Hartman cd674c8d4c greybus: es1: use <linux/uaccess.h> and not <asm/uaccess.h>
Asm is only for when you are doing arch-specific stuff, which we aren't
doing here.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
2015-03-24 20:04:49 +01:00