greybus: svc: remove deprecated hotplug operations
[cascardo/linux.git] / drivers / staging / greybus / svc.c
index 96b3027..b41d262 100644 (file)
@@ -15,7 +15,8 @@
 
 #define SVC_KEY_ARA_BUTTON     KEY_A
 
-#define SVC_INTF_EJECT_TIMEOUT 9000
+#define SVC_INTF_EJECT_TIMEOUT         9000
+#define SVC_INTF_ACTIVATE_TIMEOUT      6000
 
 struct gb_svc_deferred_request {
        struct work_struct work;
@@ -23,6 +24,8 @@ struct gb_svc_deferred_request {
 };
 
 
+static int gb_svc_queue_deferred_request(struct gb_operation *operation);
+
 static ssize_t endo_id_show(struct device *dev,
                        struct device_attribute *attr, char *buf)
 {
@@ -163,7 +166,7 @@ static int gb_svc_pwrmon_sample_get(struct gb_svc *svc, u8 rail_id,
                case GB_SVC_PWRMON_GET_SAMPLE_NOSUPP:
                        return -ENOMSG;
                default:
-                       return -EIO;
+                       return -EREMOTEIO;
                }
        }
 
@@ -199,9 +202,9 @@ int gb_svc_pwrmon_intf_sample_get(struct gb_svc *svc, u8 intf_id,
                case GB_SVC_PWRMON_GET_SAMPLE_INVAL:
                        return -EINVAL;
                case GB_SVC_PWRMON_GET_SAMPLE_NOSUPP:
-                       return -ENOSYS;
+                       return -ENOMSG;
                default:
-                       return -EIO;
+                       return -EREMOTEIO;
                }
        }
 
@@ -253,6 +256,101 @@ int gb_svc_intf_eject(struct gb_svc *svc, u8 intf_id)
        return 0;
 }
 
+int gb_svc_intf_vsys_set(struct gb_svc *svc, u8 intf_id, bool enable)
+{
+       struct gb_svc_intf_vsys_request request;
+       struct gb_svc_intf_vsys_response response;
+       int type, ret;
+
+       request.intf_id = intf_id;
+
+       if (enable)
+               type = GB_SVC_TYPE_INTF_VSYS_ENABLE;
+       else
+               type = GB_SVC_TYPE_INTF_VSYS_DISABLE;
+
+       ret = gb_operation_sync(svc->connection, type,
+                       &request, sizeof(request),
+                       &response, sizeof(response));
+       if (ret < 0)
+               return ret;
+       if (response.result_code != GB_SVC_INTF_VSYS_OK)
+               return -EREMOTEIO;
+       return 0;
+}
+
+int gb_svc_intf_refclk_set(struct gb_svc *svc, u8 intf_id, bool enable)
+{
+       struct gb_svc_intf_refclk_request request;
+       struct gb_svc_intf_refclk_response response;
+       int type, ret;
+
+       request.intf_id = intf_id;
+
+       if (enable)
+               type = GB_SVC_TYPE_INTF_REFCLK_ENABLE;
+       else
+               type = GB_SVC_TYPE_INTF_REFCLK_DISABLE;
+
+       ret = gb_operation_sync(svc->connection, type,
+                       &request, sizeof(request),
+                       &response, sizeof(response));
+       if (ret < 0)
+               return ret;
+       if (response.result_code != GB_SVC_INTF_REFCLK_OK)
+               return -EREMOTEIO;
+       return 0;
+}
+
+int gb_svc_intf_unipro_set(struct gb_svc *svc, u8 intf_id, bool enable)
+{
+       struct gb_svc_intf_unipro_request request;
+       struct gb_svc_intf_unipro_response response;
+       int type, ret;
+
+       request.intf_id = intf_id;
+
+       if (enable)
+               type = GB_SVC_TYPE_INTF_UNIPRO_ENABLE;
+       else
+               type = GB_SVC_TYPE_INTF_UNIPRO_DISABLE;
+
+       ret = gb_operation_sync(svc->connection, type,
+                       &request, sizeof(request),
+                       &response, sizeof(response));
+       if (ret < 0)
+               return ret;
+       if (response.result_code != GB_SVC_INTF_UNIPRO_OK)
+               return -EREMOTEIO;
+       return 0;
+}
+
+int gb_svc_intf_activate(struct gb_svc *svc, u8 intf_id, u8 *intf_type)
+{
+       struct gb_svc_intf_activate_request request;
+       struct gb_svc_intf_activate_response response;
+       int ret;
+
+       request.intf_id = intf_id;
+
+       ret = gb_operation_sync_timeout(svc->connection,
+                       GB_SVC_TYPE_INTF_ACTIVATE,
+                       &request, sizeof(request),
+                       &response, sizeof(response),
+                       SVC_INTF_ACTIVATE_TIMEOUT);
+       if (ret < 0)
+               return ret;
+       if (response.status != GB_SVC_OP_SUCCESS) {
+               dev_err(&svc->dev, "failed to activate interface %u: %u\n",
+                               intf_id, response.status);
+               return -EREMOTEIO;
+       }
+
+       *intf_type = response.intf_type;
+
+       return 0;
+}
+
 int gb_svc_dme_peer_get(struct gb_svc *svc, u8 intf_id, u16 attr, u16 selector,
                        u32 *value)
 {
@@ -278,7 +376,7 @@ int gb_svc_dme_peer_get(struct gb_svc *svc, u8 intf_id, u16 attr, u16 selector,
        if (result) {
                dev_err(&svc->dev, "UniPro error while getting DME attribute (%u 0x%04x %u): %u\n",
                                intf_id, attr, selector, result);
-               return -EIO;
+               return -EREMOTEIO;
        }
 
        if (value)
@@ -314,7 +412,7 @@ int gb_svc_dme_peer_set(struct gb_svc *svc, u8 intf_id, u16 attr, u16 selector,
        if (result) {
                dev_err(&svc->dev, "UniPro error while setting DME attribute (%u 0x%04x %u %u): %u\n",
                                intf_id, attr, selector, value, result);
-               return -EIO;
+               return -EREMOTEIO;
        }
 
        return 0;
@@ -340,6 +438,16 @@ int gb_svc_connection_create(struct gb_svc *svc,
 }
 EXPORT_SYMBOL_GPL(gb_svc_connection_create);
 
+void gb_svc_connection_quiescing(struct gb_svc *svc, u8 intf1_id, u16 cport1_id,
+                                       u8 intf2_id, u16 cport2_id)
+{
+       /* FIXME: implement */
+
+       dev_dbg(&svc->dev, "%s - (%u:%u %u:%u)\n", __func__,
+                               intf1_id, cport1_id, intf2_id, cport2_id);
+}
+EXPORT_SYMBOL_GPL(gb_svc_connection_quiescing);
+
 void gb_svc_connection_destroy(struct gb_svc *svc, u8 intf1_id, u16 cport1_id,
                               u8 intf2_id, u16 cport2_id)
 {
@@ -361,6 +469,91 @@ void gb_svc_connection_destroy(struct gb_svc *svc, u8 intf1_id, u16 cport1_id,
 }
 EXPORT_SYMBOL_GPL(gb_svc_connection_destroy);
 
+int gb_svc_timesync_enable(struct gb_svc *svc, u8 count, u64 frame_time,
+                          u32 strobe_delay, u32 refclk)
+{
+       struct gb_connection *connection = svc->connection;
+       struct gb_svc_timesync_enable_request request;
+
+       request.count = count;
+       request.frame_time = cpu_to_le64(frame_time);
+       request.strobe_delay = cpu_to_le32(strobe_delay);
+       request.refclk = cpu_to_le32(refclk);
+       return gb_operation_sync(connection,
+                                GB_SVC_TYPE_TIMESYNC_ENABLE,
+                                &request, sizeof(request), NULL, 0);
+}
+EXPORT_SYMBOL_GPL(gb_svc_timesync_enable);
+
+int gb_svc_timesync_disable(struct gb_svc *svc)
+{
+       struct gb_connection *connection = svc->connection;
+
+       return gb_operation_sync(connection,
+                                GB_SVC_TYPE_TIMESYNC_DISABLE,
+                                NULL, 0, NULL, 0);
+}
+EXPORT_SYMBOL_GPL(gb_svc_timesync_disable);
+
+int gb_svc_timesync_authoritative(struct gb_svc *svc, u64 *frame_time)
+{
+       struct gb_connection *connection = svc->connection;
+       struct gb_svc_timesync_authoritative_response response;
+       int ret, i;
+
+       ret = gb_operation_sync(connection,
+                               GB_SVC_TYPE_TIMESYNC_AUTHORITATIVE, NULL, 0,
+                               &response, sizeof(response));
+       if (ret < 0)
+               return ret;
+
+       for (i = 0; i < GB_TIMESYNC_MAX_STROBES; i++)
+               frame_time[i] = le64_to_cpu(response.frame_time[i]);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(gb_svc_timesync_authoritative);
+
+int gb_svc_timesync_ping(struct gb_svc *svc, u64 *frame_time)
+{
+       struct gb_connection *connection = svc->connection;
+       struct gb_svc_timesync_ping_response response;
+       int ret;
+
+       ret = gb_operation_sync(connection,
+                               GB_SVC_TYPE_TIMESYNC_PING,
+                               NULL, 0,
+                               &response, sizeof(response));
+       if (ret < 0)
+               return ret;
+
+       *frame_time = le64_to_cpu(response.frame_time);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(gb_svc_timesync_ping);
+
+int gb_svc_timesync_wake_pins_acquire(struct gb_svc *svc, u32 strobe_mask)
+{
+       struct gb_connection *connection = svc->connection;
+       struct gb_svc_timesync_wake_pins_acquire_request request;
+
+       request.strobe_mask = cpu_to_le32(strobe_mask);
+       return gb_operation_sync(connection,
+                                GB_SVC_TYPE_TIMESYNC_WAKE_PINS_ACQUIRE,
+                                &request, sizeof(request),
+                                NULL, 0);
+}
+EXPORT_SYMBOL_GPL(gb_svc_timesync_wake_pins_acquire);
+
+int gb_svc_timesync_wake_pins_release(struct gb_svc *svc)
+{
+       struct gb_connection *connection = svc->connection;
+
+       return gb_operation_sync(connection,
+                                GB_SVC_TYPE_TIMESYNC_WAKE_PINS_RELEASE,
+                                NULL, 0, NULL, 0);
+}
+EXPORT_SYMBOL_GPL(gb_svc_timesync_wake_pins_release);
+
 /* Creates bi-directional routes between the devices */
 int gb_svc_route_create(struct gb_svc *svc, u8 intf1_id, u8 dev1_id,
                               u8 intf2_id, u8 dev2_id)
@@ -435,8 +628,8 @@ static int gb_svc_version_request(struct gb_operation *op)
 {
        struct gb_connection *connection = op->connection;
        struct gb_svc *svc = gb_connection_get_data(connection);
-       struct gb_protocol_version_request *request;
-       struct gb_protocol_version_response *response;
+       struct gb_svc_version_request *request;
+       struct gb_svc_version_response *response;
 
        if (op->request->payload_size < sizeof(*request)) {
                dev_err(&svc->dev, "short version request (%zu < %zu)\n",
@@ -551,38 +744,40 @@ static void gb_svc_pwrmon_debugfs_init(struct gb_svc *svc)
        int i;
        size_t bufsize;
        struct dentry *dent;
+       struct gb_svc_pwrmon_rail_names_get_response *rail_names;
+       u8 rail_count;
 
        dent = debugfs_create_dir("pwrmon", svc->debugfs_dentry);
        if (IS_ERR_OR_NULL(dent))
                return;
 
-       if (gb_svc_pwrmon_rail_count_get(svc, &svc->rail_count))
+       if (gb_svc_pwrmon_rail_count_get(svc, &rail_count))
                goto err_pwrmon_debugfs;
 
-       if (!svc->rail_count || svc->rail_count > GB_SVC_PWRMON_MAX_RAIL_COUNT)
+       if (!rail_count || rail_count > GB_SVC_PWRMON_MAX_RAIL_COUNT)
                goto err_pwrmon_debugfs;
 
-       bufsize = GB_SVC_PWRMON_RAIL_NAME_BUFSIZE * svc->rail_count;
+       bufsize = GB_SVC_PWRMON_RAIL_NAME_BUFSIZE * rail_count;
 
-       svc->rail_names = kzalloc(bufsize, GFP_KERNEL);
-       if (!svc->rail_names)
+       rail_names = kzalloc(bufsize, GFP_KERNEL);
+       if (!rail_names)
                goto err_pwrmon_debugfs;
 
-       svc->pwrmon_rails = kcalloc(svc->rail_count, sizeof(*svc->pwrmon_rails),
+       svc->pwrmon_rails = kcalloc(rail_count, sizeof(*svc->pwrmon_rails),
                                    GFP_KERNEL);
        if (!svc->pwrmon_rails)
                goto err_pwrmon_debugfs_free;
 
-       if (gb_svc_pwrmon_rail_names_get(svc, svc->rail_names, bufsize))
+       if (gb_svc_pwrmon_rail_names_get(svc, rail_names, bufsize))
                goto err_pwrmon_debugfs_free;
 
-       for (i = 0; i < svc->rail_count; i++) {
+       for (i = 0; i < rail_count; i++) {
                struct dentry *dir;
                struct svc_debugfs_pwrmon_rail *rail = &svc->pwrmon_rails[i];
                char fname[GB_SVC_PWRMON_RAIL_NAME_BUFSIZE];
 
                snprintf(fname, sizeof(fname), "%s",
-                        (char *)&svc->rail_names->name[i]);
+                        (char *)&rail_names->name[i]);
 
                rail->id = i;
                rail->svc = svc;
@@ -594,13 +789,13 @@ static void gb_svc_pwrmon_debugfs_init(struct gb_svc *svc)
                                    &pwrmon_debugfs_current_fops);
                debugfs_create_file("power_now", S_IRUGO, dir, rail,
                                    &pwrmon_debugfs_power_fops);
-       };
+       }
+
+       kfree(rail_names);
        return;
 
 err_pwrmon_debugfs_free:
-       kfree(svc->rail_names);
-       svc->rail_names = NULL;
-
+       kfree(rail_names);
        kfree(svc->pwrmon_rails);
        svc->pwrmon_rails = NULL;
 
@@ -618,7 +813,8 @@ static void gb_svc_debugfs_init(struct gb_svc *svc)
 static void gb_svc_debugfs_exit(struct gb_svc *svc)
 {
        debugfs_remove_recursive(svc->debugfs_dentry);
-       kfree(svc->rail_names);
+       kfree(svc->pwrmon_rails);
+       svc->pwrmon_rails = NULL;
 }
 
 static int gb_svc_hello(struct gb_operation *op)
@@ -662,7 +858,28 @@ static int gb_svc_hello(struct gb_operation *op)
 
        gb_svc_debugfs_init(svc);
 
-       return 0;
+       return gb_svc_queue_deferred_request(op);
+}
+
+static struct gb_interface *gb_svc_interface_lookup(struct gb_svc *svc,
+                                                       u8 intf_id)
+{
+       struct gb_host_device *hd = svc->hd;
+       struct gb_module *module;
+       size_t num_interfaces;
+       u8 module_id;
+
+       list_for_each_entry(module, &hd->modules, hd_node) {
+               module_id = module->module_id;
+               num_interfaces = module->num_interfaces;
+
+               if (intf_id >= module_id &&
+                               intf_id < module_id + num_interfaces) {
+                       return module->interfaces[intf_id - module_id];
+               }
+       }
+
+       return NULL;
 }
 
 static struct gb_module *gb_svc_module_lookup(struct gb_svc *svc, u8 module_id)
@@ -678,54 +895,69 @@ static struct gb_module *gb_svc_module_lookup(struct gb_svc *svc, u8 module_id)
        return NULL;
 }
 
-static void gb_svc_intf_reenable(struct gb_svc *svc, struct gb_interface *intf)
+static void gb_svc_process_hello_deferred(struct gb_operation *operation)
 {
+       struct gb_connection *connection = operation->connection;
+       struct gb_svc *svc = gb_connection_get_data(connection);
        int ret;
 
-       mutex_lock(&intf->mutex);
-
-       /* Mark as disconnected to prevent I/O during disable. */
-       intf->disconnected = true;
-       gb_interface_disable(intf);
-       intf->disconnected = false;
-
-       ret = gb_interface_enable(intf);
-       if (ret) {
-               dev_err(&svc->dev, "failed to enable interface %u: %d\n",
-                               intf->interface_id, ret);
-
-               gb_interface_deactivate(intf);
-       }
+       /*
+        * XXX This is a hack/work-around to reconfigure the APBridgeA-Switch
+        * link to PWM G2, 1 Lane, Slow Auto, so that it has sufficient
+        * bandwidth for 3 audio streams plus boot-over-UniPro of a hot-plugged
+        * module.
+        *
+        * The code should be removed once SW-2217, Heuristic for UniPro
+        * Power Mode Changes is resolved.
+        */
+       ret = gb_svc_intf_set_power_mode(svc, svc->ap_intf_id,
+                                       GB_SVC_UNIPRO_HS_SERIES_A,
+                                       GB_SVC_UNIPRO_SLOW_AUTO_MODE,
+                                       2, 1,
+                                       GB_SVC_UNIPRO_SLOW_AUTO_MODE,
+                                       2, 1,
+                                       0, 0);
 
-       mutex_unlock(&intf->mutex);
+       if (ret)
+               dev_warn(&svc->dev,
+                       "power mode change failed on AP to switch link: %d\n",
+                       ret);
 }
 
-static void gb_svc_process_intf_hotplug(struct gb_operation *operation)
+static void gb_svc_process_module_inserted(struct gb_operation *operation)
 {
-       struct gb_svc_intf_hotplug_request *request;
+       struct gb_svc_module_inserted_request *request;
        struct gb_connection *connection = operation->connection;
        struct gb_svc *svc = gb_connection_get_data(connection);
-       struct gb_host_device *hd = connection->hd;
+       struct gb_host_device *hd = svc->hd;
        struct gb_module *module;
-       u8 intf_id;
+       size_t num_interfaces;
+       u8 module_id;
+       u16 flags;
        int ret;
 
        /* The request message size has already been verified. */
        request = operation->request->payload;
-       intf_id = request->intf_id;
+       module_id = request->primary_intf_id;
+       num_interfaces = request->intf_count;
+       flags = le16_to_cpu(request->flags);
 
-       dev_dbg(&svc->dev, "%s - id = %u\n", __func__, intf_id);
+       dev_dbg(&svc->dev, "%s - id = %u, num_interfaces = %zu, flags = 0x%04x\n",
+                       __func__, module_id, num_interfaces, flags);
 
-       /* All modules are considered 1x2 for now */
-       module = gb_svc_module_lookup(svc, intf_id);
-       if (module) {
-               dev_info(&svc->dev, "mode switch detected on interface %u\n",
-                               intf_id);
+       if (flags & GB_SVC_MODULE_INSERTED_FLAG_NO_PRIMARY) {
+               dev_warn(&svc->dev, "no primary interface detected on module %u\n",
+                               module_id);
+       }
 
-               return gb_svc_intf_reenable(svc, module->interfaces[0]);
+       module = gb_svc_module_lookup(svc, module_id);
+       if (module) {
+               dev_warn(&svc->dev, "unexpected module-inserted event %u\n",
+                               module_id);
+               return;
        }
 
-       module = gb_module_create(hd, intf_id, 1);
+       module = gb_module_create(hd, module_id, num_interfaces);
        if (!module) {
                dev_err(&svc->dev, "failed to create module\n");
                return;
@@ -740,24 +972,24 @@ static void gb_svc_process_intf_hotplug(struct gb_operation *operation)
        list_add(&module->hd_node, &hd->modules);
 }
 
-static void gb_svc_process_intf_hot_unplug(struct gb_operation *operation)
+static void gb_svc_process_module_removed(struct gb_operation *operation)
 {
-       struct gb_svc *svc = gb_connection_get_data(operation->connection);
-       struct gb_svc_intf_hot_unplug_request *request;
+       struct gb_svc_module_removed_request *request;
+       struct gb_connection *connection = operation->connection;
+       struct gb_svc *svc = gb_connection_get_data(connection);
        struct gb_module *module;
-       u8 intf_id;
+       u8 module_id;
 
        /* The request message size has already been verified. */
        request = operation->request->payload;
-       intf_id = request->intf_id;
+       module_id = request->primary_intf_id;
 
-       dev_dbg(&svc->dev, "%s - id = %u\n", __func__, intf_id);
+       dev_dbg(&svc->dev, "%s - id = %u\n", __func__, module_id);
 
-       /* All modules are considered 1x2 for now */
-       module = gb_svc_module_lookup(svc, intf_id);
+       module = gb_svc_module_lookup(svc, module_id);
        if (!module) {
-               dev_warn(&svc->dev, "could not find hot-unplug interface %u\n",
-                               intf_id);
+               dev_warn(&svc->dev, "unexpected module-removed event %u\n",
+                               module_id);
                return;
        }
 
@@ -768,6 +1000,34 @@ static void gb_svc_process_intf_hot_unplug(struct gb_operation *operation)
        gb_module_put(module);
 }
 
+static void gb_svc_process_intf_mailbox_event(struct gb_operation *operation)
+{
+       struct gb_svc_intf_mailbox_event_request *request;
+       struct gb_connection *connection = operation->connection;
+       struct gb_svc *svc = gb_connection_get_data(connection);
+       struct gb_interface *intf;
+       u8 intf_id;
+       u16 result_code;
+       u32 mailbox;
+
+       /* The request message size has already been verified. */
+       request = operation->request->payload;
+       intf_id = request->intf_id;
+       result_code = le16_to_cpu(request->result_code);
+       mailbox = le32_to_cpu(request->mailbox);
+
+       dev_dbg(&svc->dev, "%s - id = %u, result = 0x%04x, mailbox = 0x%08x\n",
+                       __func__, intf_id, result_code, mailbox);
+
+       intf = gb_svc_interface_lookup(svc, intf_id);
+       if (!intf) {
+               dev_warn(&svc->dev, "unexpected mailbox event %u\n", intf_id);
+               return;
+       }
+
+       gb_interface_mailbox_event(intf, result_code, mailbox);
+}
+
 static void gb_svc_process_deferred_request(struct work_struct *work)
 {
        struct gb_svc_deferred_request *dr;
@@ -781,11 +1041,17 @@ static void gb_svc_process_deferred_request(struct work_struct *work)
        type = operation->request->header->type;
 
        switch (type) {
-       case GB_SVC_TYPE_INTF_HOTPLUG:
-               gb_svc_process_intf_hotplug(operation);
+       case GB_SVC_TYPE_SVC_HELLO:
+               gb_svc_process_hello_deferred(operation);
                break;
-       case GB_SVC_TYPE_INTF_HOT_UNPLUG:
-               gb_svc_process_intf_hot_unplug(operation);
+       case GB_SVC_TYPE_MODULE_INSERTED:
+               gb_svc_process_module_inserted(operation);
+               break;
+       case GB_SVC_TYPE_MODULE_REMOVED:
+               gb_svc_process_module_removed(operation);
+               break;
+       case GB_SVC_TYPE_INTF_MAILBOX_EVENT:
+               gb_svc_process_intf_mailbox_event(operation);
                break;
        default:
                dev_err(&svc->dev, "bad deferred request type: 0x%02x\n", type);
@@ -814,51 +1080,6 @@ static int gb_svc_queue_deferred_request(struct gb_operation *operation)
        return 0;
 }
 
-/*
- * Bringing up a module can be time consuming, as that may require lots of
- * initialization on the module side. Over that, we may also need to download
- * the firmware first and flash that on the module.
- *
- * In order not to make other svc events wait for all this to finish,
- * handle most of module hotplug stuff outside of the hotplug callback, with
- * help of a workqueue.
- */
-static int gb_svc_intf_hotplug_recv(struct gb_operation *op)
-{
-       struct gb_svc *svc = gb_connection_get_data(op->connection);
-       struct gb_svc_intf_hotplug_request *request;
-
-       if (op->request->payload_size < sizeof(*request)) {
-               dev_warn(&svc->dev, "short hotplug request received (%zu < %zu)\n",
-                               op->request->payload_size, sizeof(*request));
-               return -EINVAL;
-       }
-
-       request = op->request->payload;
-
-       dev_dbg(&svc->dev, "%s - id = %u\n", __func__, request->intf_id);
-
-       return gb_svc_queue_deferred_request(op);
-}
-
-static int gb_svc_intf_hot_unplug_recv(struct gb_operation *op)
-{
-       struct gb_svc *svc = gb_connection_get_data(op->connection);
-       struct gb_svc_intf_hot_unplug_request *request;
-
-       if (op->request->payload_size < sizeof(*request)) {
-               dev_warn(&svc->dev, "short hot unplug request received (%zu < %zu)\n",
-                               op->request->payload_size, sizeof(*request));
-               return -EINVAL;
-       }
-
-       request = op->request->payload;
-
-       dev_dbg(&svc->dev, "%s - id = %u\n", __func__, request->intf_id);
-
-       return gb_svc_queue_deferred_request(op);
-}
-
 static int gb_svc_intf_reset_recv(struct gb_operation *op)
 {
        struct gb_svc *svc = gb_connection_get_data(op->connection);
@@ -927,6 +1148,62 @@ static int gb_svc_key_event_recv(struct gb_operation *op)
        return 0;
 }
 
+static int gb_svc_module_inserted_recv(struct gb_operation *op)
+{
+       struct gb_svc *svc = gb_connection_get_data(op->connection);
+       struct gb_svc_module_inserted_request *request;
+
+       if (op->request->payload_size < sizeof(*request)) {
+               dev_warn(&svc->dev, "short module-inserted request received (%zu < %zu)\n",
+                               op->request->payload_size, sizeof(*request));
+               return -EINVAL;
+       }
+
+       request = op->request->payload;
+
+       dev_dbg(&svc->dev, "%s - id = %u\n", __func__,
+                       request->primary_intf_id);
+
+       return gb_svc_queue_deferred_request(op);
+}
+
+static int gb_svc_module_removed_recv(struct gb_operation *op)
+{
+       struct gb_svc *svc = gb_connection_get_data(op->connection);
+       struct gb_svc_module_removed_request *request;
+
+       if (op->request->payload_size < sizeof(*request)) {
+               dev_warn(&svc->dev, "short module-removed request received (%zu < %zu)\n",
+                               op->request->payload_size, sizeof(*request));
+               return -EINVAL;
+       }
+
+       request = op->request->payload;
+
+       dev_dbg(&svc->dev, "%s - id = %u\n", __func__,
+                       request->primary_intf_id);
+
+       return gb_svc_queue_deferred_request(op);
+}
+
+static int gb_svc_intf_mailbox_event_recv(struct gb_operation *op)
+{
+       struct gb_svc *svc = gb_connection_get_data(op->connection);
+       struct gb_svc_intf_mailbox_event_request *request;
+
+       if (op->request->payload_size < sizeof(*request)) {
+               dev_warn(&svc->dev, "short mailbox request received (%zu < %zu)\n",
+                               op->request->payload_size, sizeof(*request));
+               return -EINVAL;
+       }
+
+       request = op->request->payload;
+
+       dev_dbg(&svc->dev, "%s - id = %u\n", __func__, request->intf_id);
+
+       return gb_svc_queue_deferred_request(op);
+}
+
 static int gb_svc_request_handler(struct gb_operation *op)
 {
        struct gb_connection *connection = op->connection;
@@ -945,7 +1222,7 @@ static int gb_svc_request_handler(struct gb_operation *op)
         * need to protect 'state' for any races.
         */
        switch (type) {
-       case GB_REQUEST_TYPE_PROTOCOL_VERSION:
+       case GB_SVC_TYPE_PROTOCOL_VERSION:
                if (svc->state != GB_SVC_STATE_RESET)
                        ret = -EINVAL;
                break;
@@ -966,7 +1243,7 @@ static int gb_svc_request_handler(struct gb_operation *op)
        }
 
        switch (type) {
-       case GB_REQUEST_TYPE_PROTOCOL_VERSION:
+       case GB_SVC_TYPE_PROTOCOL_VERSION:
                ret = gb_svc_version_request(op);
                if (!ret)
                        svc->state = GB_SVC_STATE_PROTOCOL_VERSION;
@@ -976,14 +1253,16 @@ static int gb_svc_request_handler(struct gb_operation *op)
                if (!ret)
                        svc->state = GB_SVC_STATE_SVC_HELLO;
                return ret;
-       case GB_SVC_TYPE_INTF_HOTPLUG:
-               return gb_svc_intf_hotplug_recv(op);
-       case GB_SVC_TYPE_INTF_HOT_UNPLUG:
-               return gb_svc_intf_hot_unplug_recv(op);
        case GB_SVC_TYPE_INTF_RESET:
                return gb_svc_intf_reset_recv(op);
        case GB_SVC_TYPE_KEY_EVENT:
                return gb_svc_key_event_recv(op);
+       case GB_SVC_TYPE_MODULE_INSERTED:
+               return gb_svc_module_inserted_recv(op);
+       case GB_SVC_TYPE_MODULE_REMOVED:
+               return gb_svc_module_removed_recv(op);
+       case GB_SVC_TYPE_INTF_MAILBOX_EVENT:
+               return gb_svc_intf_mailbox_event_recv(op);
        default:
                dev_warn(&svc->dev, "unsupported request 0x%02x\n", type);
                return -EINVAL;