intf->interface_id = interface_id;
INIT_LIST_HEAD(&intf->bundles);
INIT_LIST_HEAD(&intf->manifest_descs);
+ mutex_init(&intf->mutex);
/* Invalid device id to start with */
intf->device_id = GB_INTERFACE_DEVICE_ID_BAD;
return intf;
}
+/*
+ * Activate an interface.
+ *
+ * Locking: Caller holds the interface mutex.
+ */
int gb_interface_activate(struct gb_interface *intf)
{
int ret;
+ if (intf->ejected)
+ return -ENODEV;
+
ret = gb_interface_read_dme(intf);
if (ret)
return ret;
return 0;
}
+/*
+ * Deactivate an interface.
+ *
+ * Locking: Caller holds the interface mutex.
+ */
void gb_interface_deactivate(struct gb_interface *intf)
{
gb_interface_route_destroy(intf);
* Enable an interface by enabling its control connection, fetching the
* manifest and other information over it, and finally registering its child
* devices.
+ *
+ * Locking: Caller holds the interface mutex.
*/
int gb_interface_enable(struct gb_interface *intf)
{
return ret;
}
-/* Disable an interface and destroy its bundles. */
+/*
+ * Disable an interface and destroy its bundles.
+ *
+ * Locking: Caller holds the interface mutex.
+ */
void gb_interface_disable(struct gb_interface *intf)
{
struct gb_bundle *bundle;
#include "greybus.h"
+static ssize_t eject_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ struct gb_module *module = to_gb_module(dev);
+ struct gb_interface *intf;
+ size_t i;
+ long val;
+ int ret;
+
+ ret = kstrtol(buf, 0, &val);
+ if (ret)
+ return ret;
+
+ if (!val)
+ return len;
+
+ for (i = 0; i < module->num_interfaces; ++i) {
+ intf = module->interfaces[i];
+
+ mutex_lock(&intf->mutex);
+ /* Set flag to prevent concurrent activation. */
+ intf->ejected = true;
+ gb_interface_disable(intf);
+ gb_interface_deactivate(intf);
+ mutex_unlock(&intf->mutex);
+ }
+
+ /* Tell the SVC to eject the primary interface. */
+ ret = gb_svc_intf_eject(module->hd->svc, module->module_id);
+ if (ret)
+ return ret;
+
+ return len;
+}
+static DEVICE_ATTR_WO(eject);
+
static ssize_t module_id_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
static DEVICE_ATTR_RO(num_interfaces);
static struct attribute *module_attrs[] = {
+ &dev_attr_eject.attr,
&dev_attr_module_id.attr,
&dev_attr_num_interfaces.attr,
NULL,
u8 intf_id = intf->interface_id;
int ret;
+ mutex_lock(&intf->mutex);
+
ret = gb_interface_activate(intf);
if (ret) {
dev_err(&module->dev, "failed to activate interface %u: %d\n",
intf_id, ret);
gb_interface_add(intf);
- return;
+ goto err_unlock;
}
ret = gb_interface_add(intf);
goto err_interface_deactivate;
}
+ mutex_unlock(&intf->mutex);
+
return;
err_interface_deactivate:
gb_interface_deactivate(intf);
+err_unlock:
+ mutex_unlock(&intf->mutex);
}
static void gb_module_deregister_interface(struct gb_interface *intf)
if (intf->module->disconnected)
intf->disconnected = true;
+ mutex_lock(&intf->mutex);
gb_interface_disable(intf);
gb_interface_deactivate(intf);
+ mutex_unlock(&intf->mutex);
gb_interface_del(intf);
}