summaryrefslogtreecommitdiffstats
path: root/drivers/staging
diff options
context:
space:
mode:
authorJohan Hovold <johan@hovoldconsulting.com>2016-07-20 16:40:23 +0200
committerGreg Kroah-Hartman <gregkh@google.com>2016-07-20 10:16:54 -0700
commit62491622db9c9b6a51630f4c8c653f59c2c834f9 (patch)
tree2b6c0ac80f4922f44036450a177a325e56957d99 /drivers/staging
parent3e93cb6abbc023aebf311618481263e000bf26fb (diff)
downloadlinux-62491622db9c9b6a51630f4c8c653f59c2c834f9.tar.gz
linux-62491622db9c9b6a51630f4c8c653f59c2c834f9.tar.bz2
linux-62491622db9c9b6a51630f4c8c653f59c2c834f9.zip
greybus: interface: make sure type is invariant during reactivation
An interface is not expected to change its type after a power down and reactivation so make sure to treat that as a fatal error. This is complicated by the current Toshiba ES3 hack which requires us to retry activation as Greybus interfaces are sometimes misdetected as UniPro interfaces. Handle that by only retrying activation the first time an interface is activated, and for interfaces already detected as having Greybus type. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Reviewed-by: Alex Elder <elder@linaro.org> Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org> Reviewed-by: Sandeep Patil <sspatil@google.com> Reviewed-by: Patrick Titiano <ptitiano@baylibre.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Diffstat (limited to 'drivers/staging')
-rw-r--r--drivers/staging/greybus/interface.c75
1 files changed, 55 insertions, 20 deletions
diff --git a/drivers/staging/greybus/interface.c b/drivers/staging/greybus/interface.c
index 8e1b6c017c81..01cefced7b69 100644
--- a/drivers/staging/greybus/interface.c
+++ b/drivers/staging/greybus/interface.c
@@ -822,7 +822,8 @@ static int gb_interface_unipro_set(struct gb_interface *intf, bool enable)
return 0;
}
-static int gb_interface_activate_operation(struct gb_interface *intf)
+static int gb_interface_activate_operation(struct gb_interface *intf,
+ enum gb_interface_type *intf_type)
{
struct gb_svc *svc = intf->hd->svc;
u8 type;
@@ -838,20 +839,20 @@ static int gb_interface_activate_operation(struct gb_interface *intf)
switch (type) {
case GB_SVC_INTF_TYPE_DUMMY:
- intf->type = GB_INTERFACE_TYPE_DUMMY;
+ *intf_type = GB_INTERFACE_TYPE_DUMMY;
/* FIXME: handle as an error for now */
return -ENODEV;
case GB_SVC_INTF_TYPE_UNIPRO:
- intf->type = GB_INTERFACE_TYPE_UNIPRO;
+ *intf_type = GB_INTERFACE_TYPE_UNIPRO;
dev_err(&intf->dev, "interface type UniPro not supported\n");
/* FIXME: handle as an error for now */
return -ENODEV;
case GB_SVC_INTF_TYPE_GREYBUS:
- intf->type = GB_INTERFACE_TYPE_GREYBUS;
+ *intf_type = GB_INTERFACE_TYPE_GREYBUS;
break;
default:
dev_err(&intf->dev, "unknown interface type: %u\n", type);
- intf->type = GB_INTERFACE_TYPE_UNKNOWN;
+ *intf_type = GB_INTERFACE_TYPE_UNKNOWN;
return -ENODEV;
}
@@ -865,10 +866,13 @@ static int gb_interface_hibernate_link(struct gb_interface *intf)
return gb_svc_intf_set_power_mode_hibernate(svc, intf->interface_id);
}
-static int _gb_interface_activate(struct gb_interface *intf)
+static int _gb_interface_activate(struct gb_interface *intf,
+ enum gb_interface_type *type)
{
int ret;
+ *type = GB_INTERFACE_TYPE_UNKNOWN;
+
if (intf->ejected)
return -ENODEV;
@@ -884,7 +888,7 @@ static int _gb_interface_activate(struct gb_interface *intf)
if (ret)
goto err_refclk_disable;
- ret = gb_interface_activate_operation(intf);
+ ret = gb_interface_activate_operation(intf, type);
if (ret)
goto err_unipro_disable;
@@ -915,26 +919,21 @@ err_vsys_disable:
}
/*
- * Activate an interface.
+ * At present, we assume a UniPro-only module to be a Greybus module that
+ * failed to send its mailbox poke. There is some reason to believe that this
+ * is because of a bug in the ES3 bootrom.
*
- * Locking: Caller holds the interface mutex.
+ * FIXME: Check if this is a Toshiba bridge before retrying?
*/
-int gb_interface_activate(struct gb_interface *intf)
+static int _gb_interface_activate_es3_hack(struct gb_interface *intf,
+ enum gb_interface_type *type)
{
int retries = 3;
int ret;
- /*
- * At present, we assume a UniPro-only module
- * to be a Greybus module that failed to send its mailbox
- * poke. There is some reason to believe that this is
- * because of a bug in the ES3 bootrom.
- *
- * FIXME: Check if this is a Toshiba bridge before retrying?
- */
while (retries--) {
- ret = _gb_interface_activate(intf);
- if (ret == -ENODEV && intf->type == GB_SVC_INTF_TYPE_UNIPRO)
+ ret = _gb_interface_activate(intf, type);
+ if (ret == -ENODEV && *type == GB_INTERFACE_TYPE_UNIPRO)
continue;
break;
@@ -944,6 +943,42 @@ int gb_interface_activate(struct gb_interface *intf)
}
/*
+ * Activate an interface.
+ *
+ * Locking: Caller holds the interface mutex.
+ */
+int gb_interface_activate(struct gb_interface *intf)
+{
+ enum gb_interface_type type;
+ int ret;
+
+ switch (intf->type) {
+ case GB_INTERFACE_TYPE_INVALID:
+ case GB_INTERFACE_TYPE_GREYBUS:
+ ret = _gb_interface_activate_es3_hack(intf, &type);
+ break;
+ default:
+ ret = _gb_interface_activate(intf, &type);
+ }
+
+ /* Make sure type is detected correctly during reactivation. */
+ if (intf->type != GB_INTERFACE_TYPE_INVALID) {
+ if (type != intf->type) {
+ dev_err(&intf->dev, "failed to detect interface type\n");
+
+ if (!ret)
+ gb_interface_deactivate(intf);
+
+ return -EIO;
+ }
+ } else {
+ intf->type = type;
+ }
+
+ return ret;
+}
+
+/*
* Deactivate an interface.
*
* Locking: Caller holds the interface mutex.