From 7388901528411cbda3f5e0d121ae3797f4397ded Mon Sep 17 00:00:00 2001 From: Andrzej Pietrasiewicz Date: Wed, 9 Oct 2013 10:08:25 +0200 Subject: [PATCH] usb: gadget: multi: convert to new interface of f_ecm Convert the legacy multi gadget to the new interface of f_ecm, so that later the compatibility layer in f_ecm can be removed. Signed-off-by: Andrzej Pietrasiewicz Signed-off-by: Kyungmin Park Signed-off-by: Felipe Balbi --- drivers/usb/gadget/Kconfig | 1 + drivers/usb/gadget/multi.c | 68 +++++++++++++++++++++++++++++++++----- 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 886db6a7d4d..92a896653cd 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -1070,6 +1070,7 @@ config USB_G_MULTI_CDC bool "CDC Ethernet + CDC Serial + Storage configuration" depends on USB_G_MULTI default n + select USB_F_ECM help This option enables a configuration with CDC Ethernet (ECM), CDC Serial and Mass Storage functions available in the Multifunction diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c index 42a5bed7538..7dd554481dd 100644 --- a/drivers/usb/gadget/multi.c +++ b/drivers/usb/gadget/multi.c @@ -15,6 +15,7 @@ #include #include +#include #include "u_serial.h" #if defined USB_ETH_RNDIS @@ -44,8 +45,7 @@ MODULE_LICENSE("GPL"); #define USB_FMS_INCLUDED #include "f_mass_storage.c" -#define USBF_ECM_INCLUDED -#include "f_ecm.c" +#include "u_ecm.h" #ifdef USB_ETH_RNDIS # define USB_FRNDIS_INCLUDED # include "f_rndis.c" @@ -151,14 +151,14 @@ FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data); static struct fsg_common fsg_common; -static u8 host_mac[ETH_ALEN]; - static struct usb_function_instance *fi_acm; static struct eth_dev *the_dev; /********** RNDIS **********/ #ifdef USB_ETH_RNDIS +static u8 host_mac[ETH_ALEN]; + static struct usb_function *f_acm_rndis; static __init int rndis_do_config(struct usb_configuration *c) @@ -220,7 +220,9 @@ static __ref int rndis_config_register(struct usb_composite_dev *cdev) /********** CDC ECM **********/ #ifdef CONFIG_USB_G_MULTI_CDC +static struct usb_function_instance *fi_ecm; static struct usb_function *f_acm_multi; +static struct usb_function *f_ecm; static __init int cdc_do_config(struct usb_configuration *c) { @@ -231,14 +233,20 @@ static __init int cdc_do_config(struct usb_configuration *c) c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; } - ret = ecm_bind_config(c, host_mac, the_dev); + f_ecm = usb_get_function(fi_ecm); + if (IS_ERR(f_ecm)) + return PTR_ERR(f_ecm); + + ret = usb_add_function(c, f_ecm); if (ret < 0) - return ret; + goto err_func_ecm; /* implicit port_num is zero */ f_acm_multi = usb_get_function(fi_acm); - if (IS_ERR(f_acm_multi)) - return PTR_ERR(f_acm_multi); + if (IS_ERR(f_acm_multi)) { + ret = PTR_ERR(f_acm_multi); + goto err_func_acm; + } ret = usb_add_function(c, f_acm_multi); if (ret) @@ -253,6 +261,10 @@ err_fsg: usb_remove_function(c, f_acm_multi); err_conf: usb_put_function(f_acm_multi); +err_func_acm: + usb_remove_function(c, f_ecm); +err_func_ecm: + usb_put_function(f_ecm); return ret; } @@ -285,6 +297,9 @@ static __ref int cdc_config_register(struct usb_composite_dev *cdev) static int __ref multi_bind(struct usb_composite_dev *cdev) { struct usb_gadget *gadget = cdev->gadget; +#ifdef CONFIG_USB_G_MULTI_CDC + struct f_ecm_opts *ecm_opts; +#endif int status; if (!can_support_ecm(cdev->gadget)) { @@ -293,11 +308,39 @@ static int __ref multi_bind(struct usb_composite_dev *cdev) return -EINVAL; } +#ifdef CONFIG_USB_G_MULTI_CDC + fi_ecm = usb_get_function_instance("ecm"); + if (IS_ERR(fi_ecm)) + return PTR_ERR(fi_ecm); + + ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst); + + gether_set_qmult(ecm_opts->net, qmult); + if (!gether_set_host_addr(ecm_opts->net, host_addr)) + pr_info("using host ethernet address: %s", host_addr); + if (!gether_set_dev_addr(ecm_opts->net, dev_addr)) + pr_info("using self ethernet address: %s", dev_addr); + + the_dev = netdev_priv(ecm_opts->net); + +#elif defined USB_ETH_RNDIS + /* set up network link layer */ the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, host_mac, qmult); if (IS_ERR(the_dev)) return PTR_ERR(the_dev); +#endif + +#if (defined CONFIG_USB_G_MULTI_CDC && defined USB_ETH_RNDIS) + gether_set_gadget(ecm_opts->net, cdev->gadget); + status = gether_register_netdev(ecm_opts->net); + if (status) + goto fail0; + ecm_opts->bound = true; + + gether_get_host_addr_u8(ecm_opts->net, host_mac); +#endif /* set up serial link layer */ fi_acm = usb_get_function_instance("acm"); @@ -345,7 +388,11 @@ fail2: fail1: usb_put_function_instance(fi_acm); fail0: +#ifdef CONFIG_USB_G_MULTI_CDC + usb_put_function_instance(fi_ecm); +#else gether_cleanup(the_dev); +#endif return status; } @@ -358,7 +405,12 @@ static int __exit multi_unbind(struct usb_composite_dev *cdev) usb_put_function(f_acm_rndis); #endif usb_put_function_instance(fi_acm); +#ifdef CONFIG_USB_G_MULTI_CDC + usb_put_function(f_ecm); + usb_put_function_instance(fi_ecm); +#else gether_cleanup(the_dev); +#endif return 0; } -- 2.46.0