diff options
author | INSUN PYO <insun.pyo@samsung.com> | 2020-03-12 16:03:07 +0900 |
---|---|---|
committer | Hyotaek Shim <hyotaek.shim@samsung.com> | 2020-03-12 08:03:23 +0000 |
commit | 5dfba120d733b52bfc75dff4014b24acd90d78f7 (patch) | |
tree | 283c28c090dfb8bb694e6dd7512bf13a8c34b584 | |
parent | 5676a19fc24ca9b01f692c98ea3156d6e7505947 (diff) | |
download | libdevice-node-5dfba120d733b52bfc75dff4014b24acd90d78f7.tar.gz libdevice-node-5dfba120d733b52bfc75dff4014b24acd90d78f7.tar.bz2 libdevice-node-5dfba120d733b52bfc75dff4014b24acd90d78f7.zip |
Refactoring: replace ffs_service to is_functionfs
Change-Id: Ibb74b5627ef1376be141fb23e56787e45b34c142
(cherry picked from commit c1ef88b5dc9a2e8014ebf290e802fb57c34fd5f0)
-rw-r--r-- | hw/usb_cfs_client_common.c | 32 | ||||
-rw-r--r-- | hw/usb_client_common.c | 16 | ||||
-rw-r--r-- | hw/usb_gadget.h | 19 | ||||
-rw-r--r-- | hw/usb_gadget_common.c | 46 |
4 files changed, 46 insertions, 67 deletions
diff --git a/hw/usb_cfs_client_common.c b/hw/usb_cfs_client_common.c index 6d3595f..39dfca2 100644 --- a/hw/usb_cfs_client_common.c +++ b/hw/usb_cfs_client_common.c @@ -497,7 +497,7 @@ static bool cfs_is_function_supported(struct usb_client *usb, bool res; int ret; - if (!func->ffs_service) { + if (!func->is_functionfs) { ret = usbg_lookup_function_type(func->name); res = ret >= 0; } else { @@ -730,7 +730,7 @@ static int cfs_set_gadget_config(struct cfs_client *cfs_client, int type; usbg_function *func; - if (!usb_func->ffs_service) { + if (!usb_func->is_functionfs) { type = usbg_lookup_function_type(usb_func->name); if (strlen(usb_func->instance) >= MAX_INSTANCE_LEN) return -ENAMETOOLONG; @@ -760,11 +760,11 @@ static int cfs_set_gadget_config(struct cfs_client *cfs_client, if (usbg_get_function_type(func) == USBG_F_RNDIS) (void)cfs_set_rndis_mac_addr(cfs_client->gadget, func); /* A random value is used if fails */ - if (usb_func->ffs_service) { + if (usb_func->is_functionfs) { ret = cfs_prep_ffs_service(usb_func->name, usb_func->instance, instance, - usb_func->ffs_service); + usb_func->service); if (ret) return ret; } @@ -863,10 +863,9 @@ static int cfs_enable(struct usb_client *usb) if (func->handler) func->handler(1); - if (func->service) + /* functionfs service is automatically started by socket activation */ + if (!func->is_functionfs && func->service) (void)systemd_start_unit_wait_started(func->service, ".service", -1); - - /* func->ffs_service is automatically started by socket activation */ } cfs_free_gadget(gadget); @@ -892,7 +891,7 @@ static int cfs_disable(struct usb_client *usb) for (i = 0; gadget->funcs[i]; ++i) { func = gadget->funcs[i]; - if (func->service) + if (!func->is_functionfs && func->service) (void)systemd_stop_unit_wait_stopped(func->service, ".service", -1); if (func->handler) @@ -903,15 +902,15 @@ static int cfs_disable(struct usb_client *usb) ret = usbg_disable_gadget(cfs_client->gadget); /* ignore error checking */ /* - * Since ffs_service works with socket activation, you must stop it after disabling gadget. - * If usb data may come in after stopping ffs_service and before disabling gadget, - * ffs_service wakes up again by socket activation. + * Since functionfs service works with socket activation, you must stop it after disabling gadget. + * If usb data may come in after stopping functionfs service and before disabling gadget, + * functionfs service wakes up again by socket activation. */ for (i = 0; gadget->funcs[i]; ++i) { func = gadget->funcs[i]; - if (func->ffs_service) - (void)systemd_stop_unit_wait_stopped(func->ffs_service, ".service", -1); + if (func->is_functionfs && func->service) + (void)systemd_stop_unit_wait_stopped(func->service, ".service", -1); } cfs_free_gadget(gadget); @@ -994,9 +993,10 @@ int hw_cfs_gadget_close(struct hw_common *common) continue; usb_func = _available_funcs[ret]; - if (usb_func->ffs_service) { - systemd_stop_unit_wait_stopped(usb_func->ffs_service, ".socket", -1); - systemd_stop_unit_wait_stopped(usb_func->ffs_service, ".service", -1); + + if (usb_func->is_functionfs && usb_func->service) { + (void)systemd_stop_unit_wait_stopped(usb_func->service, ".socket", -1); + (void)systemd_stop_unit_wait_stopped(usb_func->service, ".service", -1); } } diff --git a/hw/usb_client_common.c b/hw/usb_client_common.c index d008485..9968821 100644 --- a/hw/usb_client_common.c +++ b/hw/usb_client_common.c @@ -557,14 +557,6 @@ static int legacy_enable(struct usb_client *usb) if (func->handler) func->handler(1); - /* - * Reuse configfs data structure to simplify design. - * Configfs has a special service for functionfs. (E.g. sdbd and mtp-responder) - * The legacy usb gadget must handle both services. - */ - if (func->ffs_service) - (void)systemd_start_unit_wait_started(func->ffs_service, ".service", -1); - if (func->service) (void)systemd_start_unit_wait_started(func->service, ".service", -1); } @@ -591,17 +583,9 @@ static int legacy_disable(struct usb_client *usb) for (i = 0; gadget->funcs[i]; ++i) { func = gadget->funcs[i]; - /* - * Reuse configfs data structure to simplify design. - * Configfs has a special service for functionfs. (E.g. sdbd and mtp-responder) - * The legacy usb gadget must handle both services. - */ if (func->service) (void)systemd_stop_unit_wait_stopped(func->service, ".service", -1); - if (func->ffs_service) - (void)systemd_stop_unit_wait_stopped(func->ffs_service, ".service", -1); - if (func->handler) func->handler(0); } diff --git a/hw/usb_gadget.h b/hw/usb_gadget.h index dc4b539..ad53d0e 100644 --- a/hw/usb_gadget.h +++ b/hw/usb_gadget.h @@ -62,23 +62,24 @@ typedef enum { /* - * legacy enable(usb plug) : enable gadget -> handler(1) -> ffs_service start -> service start - * legacy disable(usb unplug) : service stop -> ffs_service stop -> handler(0) -> disable gadget + * legacy enable(usb plug) : enable gadget -> handler(1) -> service start + * legacy disable(usb unplug) : service stop -> handler(0) -> disable gadget * - * configfs init(booting) : ffs_service.socket start - * configfs enable(usb plug)* : enable gadget -> handler(1) -> service start - * configfs disable(usb unplug) : service stop -> handler(0) -> disable gadget -> ffs_service.service stop - * configfs deinit : ffs_service.socket stop + * configfs init(booting) : service.socket start + * configfs enable(usb plug)* : enable gadget -> handler(1) + * configfs disable(usb unplug) : handler(0) -> disable gadget -> service.service stop + * configfs deinit : service.socket stop * - * Since ffs_service works by socket activation, it will be started automatically when data is enqueued to the usb socket. - * So when enabling configfs gadget, it doesn't start ffs_service. + * Since functionfs of configfs works by socket activation, + * it will be started automatically when data is enqueued to the usb socket. + * So when enabling configfs gadget, it doesn't start the service for functionfs. */ struct usb_function { int id; const char *name; const char *instance; - const char *ffs_service; /* only used in configfs */ + int is_functionfs; const char *service; void (*handler)(int enable); diff --git a/hw/usb_gadget_common.c b/hw/usb_gadget_common.c index a061084..c6ea9cd 100644 --- a/hw/usb_gadget_common.c +++ b/hw/usb_gadget_common.c @@ -381,7 +381,6 @@ static void free_simple_func(struct usb_function *func) if (func) { free((void *)func->name); free((void *)func->instance); - free((void *)func->ffs_service); free((void *)func->service); free(func); } @@ -406,12 +405,6 @@ static int clone_simple_func(struct usb_function *func, if (!other->name || !other->instance) goto out_nomem; - if (func->ffs_service) { - other->ffs_service = strdup(func->ffs_service); - if (!other->ffs_service) - goto out_nomem; - } - if (func->service) { other->service = strdup(func->service); if (!other->service) @@ -426,26 +419,27 @@ out_nomem: return -ENOMEM; } -#define DEFINE_USB_FUNCTION(_id, _name, _ffs_service, _service, _handler) \ - static struct usb_function _##_name##_function = { \ - .id = _id, \ - .name = #_name, \ - .instance = "default", \ - .ffs_service = _ffs_service, \ - .service = _service, \ - .handler = _handler, \ - .clone = clone_simple_func, \ - .free_func = free_simple_func, \ +#define DEFINE_USB_FUNCTION(_id, _name, _is_functionfs, _service, _handler) \ + static struct usb_function _##_name##_function = { \ + .id = _id, \ + .name = #_name, \ + .instance = "default", \ + .is_functionfs = _is_functionfs, \ + .service = _service, \ + .handler = _handler, \ + .clone = clone_simple_func, \ + .free_func = free_simple_func, \ } -DEFINE_USB_FUNCTION(USB_FUNCTION_DIAG, diag, NULL, NULL, NULL); -DEFINE_USB_FUNCTION(USB_FUNCTION_RMNET, rmnet, NULL, NULL, NULL); -DEFINE_USB_FUNCTION(USB_FUNCTION_DM, dm, NULL, NULL, NULL); -DEFINE_USB_FUNCTION(USB_FUNCTION_CONN_GADGET, conn_gadget, NULL, NULL, NULL); -DEFINE_USB_FUNCTION(USB_FUNCTION_SDB, sdb, "sdbd", NULL, NULL); -DEFINE_USB_FUNCTION(USB_FUNCTION_MTP, mtp, "mtp-responder", NULL, NULL); -DEFINE_USB_FUNCTION(USB_FUNCTION_ACM, acm, NULL, "data-router", NULL); -DEFINE_USB_FUNCTION(USB_FUNCTION_RNDIS, rndis, NULL, "sshd", rndis_handler); +DEFINE_USB_FUNCTION(USB_FUNCTION_MTP, mtp, 1, "mtp-responder", NULL); +DEFINE_USB_FUNCTION(USB_FUNCTION_ACM, acm, 0, "data-router", NULL); +DEFINE_USB_FUNCTION(USB_FUNCTION_SDB, sdb, 1, "sdbd", NULL); +DEFINE_USB_FUNCTION(USB_FUNCTION_RNDIS, rndis, 0, "sshd", rndis_handler); +DEFINE_USB_FUNCTION(USB_FUNCTION_DIAG, diag, 0, NULL, NULL); +DEFINE_USB_FUNCTION(USB_FUNCTION_CONN_GADGET, conn_gadget, 0, NULL, NULL); +DEFINE_USB_FUNCTION(USB_FUNCTION_DM, dm, 0, NULL, NULL); +DEFINE_USB_FUNCTION(USB_FUNCTION_RMNET, rmnet, 0, NULL, NULL); + #undef DEFINE_USB_FUNCTION /* Caution: index order of arrary is important, because simple_id_to_gadget() uses it. */ @@ -486,7 +480,7 @@ int simple_translator_open(struct hw_info *info, * So in environments that mtp doesn't support, use dummy mtp. */ if (access("/usr/lib/systemd/system/mtp-responder.socket", F_OK)) { - _available_funcs[USB_FUNCTION_IDX_MTP]->ffs_service = "mtp-responder-dummy"; + _available_funcs[USB_FUNCTION_IDX_MTP]->service = "mtp-responder-dummy"; } *common = &simple_translator->common; |